An error occurred fetching the project authors.
  1. 11 Apr, 2024 3 commits
  2. 09 Mar, 2024 1 commit
    • Paolo Bonzini's avatar
      SEV: disable SEV-ES DebugSwap by default · 5abf6dce
      Paolo Bonzini authored
      The DebugSwap feature of SEV-ES provides a way for confidential guests to use
      data breakpoints.  However, because the status of the DebugSwap feature is
      recorded in the VMSA, enabling it by default invalidates the attestation
      signatures.  In 6.10 we will introduce a new API to create SEV VMs that
      will allow enabling DebugSwap based on what the user tells KVM to do.
      Contextually, we will change the legacy KVM_SEV_ES_INIT API to never
      enable DebugSwap.
      
      For compatibility with kernels that pre-date the introduction of DebugSwap,
      as well as with those where KVM_SEV_ES_INIT will never enable it, do not enable
      the feature by default.  If anybody wants to use it, for now they can enable
      the sev_es_debug_swap_enabled module parameter, but this will result in a
      warning.
      
      Fixes: d1f85fbe ("KVM: SEV: Enable data breakpoints in SEV-ES")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      5abf6dce
  3. 23 Feb, 2024 1 commit
    • Sean Christopherson's avatar
      KVM: SVM: Flush pages under kvm->lock to fix UAF in svm_register_enc_region() · 5ef1d8c1
      Sean Christopherson authored
      Do the cache flush of converted pages in svm_register_enc_region() before
      dropping kvm->lock to fix use-after-free issues where region and/or its
      array of pages could be freed by a different task, e.g. if userspace has
      __unregister_enc_region_locked() already queued up for the region.
      
      Note, the "obvious" alternative of using local variables doesn't fully
      resolve the bug, as region->pages is also dynamically allocated.  I.e. the
      region structure itself would be fine, but region->pages could be freed.
      
      Flushing multiple pages under kvm->lock is unfortunate, but the entire
      flow is a rare slow path, and the manual flush is only needed on CPUs that
      lack coherency for encrypted memory.
      
      Fixes: 19a23da5 ("Fix unsynchronized access to sev members through svm_register_enc_region")
      Reported-by: default avatarGabe Kirkpatrick <gkirkpatrick@google.com>
      Cc: Josh Eads <josheads@google.com>
      Cc: Peter Gonda <pgonda@google.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20240217013430.2079561-1-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      5ef1d8c1
  4. 06 Feb, 2024 4 commits
  5. 29 Jan, 2024 2 commits
    • Brijesh Singh's avatar
      KVM: SEV: Make AVIC backing, VMSA and VMCB memory allocation SNP safe · 75253db4
      Brijesh Singh authored
      Implement a workaround for an SNP erratum where the CPU will incorrectly
      signal an RMP violation #PF if a hugepage (2MB or 1GB) collides with the
      RMP entry of a VMCB, VMSA or AVIC backing page.
      
      When SEV-SNP is globally enabled, the CPU marks the VMCB, VMSA, and AVIC
      backing pages as "in-use" via a reserved bit in the corresponding RMP
      entry after a successful VMRUN. This is done for _all_ VMs, not just
      SNP-Active VMs.
      
      If the hypervisor accesses an in-use page through a writable
      translation, the CPU will throw an RMP violation #PF. On early SNP
      hardware, if an in-use page is 2MB-aligned and software accesses any
      part of the associated 2MB region with a hugepage, the CPU will
      incorrectly treat the entire 2MB region as in-use and signal a an RMP
      violation #PF.
      
      To avoid this, the recommendation is to not use a 2MB-aligned page for
      the VMCB, VMSA or AVIC pages. Add a generic allocator that will ensure
      that the page returned is not 2MB-aligned and is safe to be used when
      SEV-SNP is enabled. Also implement similar handling for the VMCB/VMSA
      pages of nested guests.
      
        [ mdr: Squash in nested guest handling from Ashish, commit msg fixups. ]
      
      Reported-by: Alper Gun <alpergun@google.com> # for nested VMSA case
      Signed-off-by: default avatarBrijesh Singh <brijesh.singh@amd.com>
      Co-developed-by: default avatarMarc Orr <marcorr@google.com>
      Signed-off-by: default avatarMarc Orr <marcorr@google.com>
      Co-developed-by: default avatarAshish Kalra <ashish.kalra@amd.com>
      Signed-off-by: default avatarAshish Kalra <ashish.kalra@amd.com>
      Signed-off-by: default avatarMichael Roth <michael.roth@amd.com>
      Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
      Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
      Acked-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Link: https://lore.kernel.org/r/20240126041126.1927228-22-michael.roth@amd.com
      75253db4
    • Brijesh Singh's avatar
      crypto: ccp: Add support to initialize the AMD-SP for SEV-SNP · 1ca5614b
      Brijesh Singh authored
      Before SNP VMs can be launched, the platform must be appropriately
      configured and initialized via the SNP_INIT command.
      
      During the execution of SNP_INIT command, the firmware configures
      and enables SNP security policy enforcement in many system components.
      Some system components write to regions of memory reserved by early
      x86 firmware (e.g. UEFI). Other system components write to regions
      provided by the operation system, hypervisor, or x86 firmware.
      Such system components can only write to HV-fixed pages or Default
      pages. They will error when attempting to write to pages in other page
      states after SNP_INIT enables their SNP enforcement.
      
      Starting in SNP firmware v1.52, the SNP_INIT_EX command takes a list of
      system physical address ranges to convert into the HV-fixed page states
      during the RMP initialization. If INIT_RMP is 1, hypervisors should
      provide all system physical address ranges that the hypervisor will
      never assign to a guest until the next RMP re-initialization.
      
      For instance, the memory that UEFI reserves should be included in the
      range list. This allows system components that occasionally write to
      memory (e.g. logging to UEFI reserved regions) to not fail due to
      RMP initialization and SNP enablement.
      
      Note that SNP_INIT(_EX) must not be executed while non-SEV guests are
      executing, otherwise it is possible that the system could reset or hang.
      The psp_init_on_probe module parameter was added for SEV/SEV-ES support
      and the init_ex_path module parameter to allow for time for the
      necessary file system to be mounted/available.
      
      SNP_INIT(_EX) does not use the file associated with init_ex_path. So, to
      avoid running into issues where SNP_INIT(_EX) is called while there are
      other running guests, issue it during module probe regardless of the
      psp_init_on_probe setting, but maintain the previous deferrable handling
      for SEV/SEV-ES initialization.
      
        [ mdr: Squash in psp_init_on_probe changes from Tom, reduce
          proliferation of 'probe' function parameter where possible.
          bp: Fix 32-bit allmodconfig build. ]
      Signed-off-by: default avatarBrijesh Singh <brijesh.singh@amd.com>
      Co-developed-by: default avatarAshish Kalra <ashish.kalra@amd.com>
      Signed-off-by: default avatarAshish Kalra <ashish.kalra@amd.com>
      Co-developed-by: default avatarJarkko Sakkinen <jarkko@profian.com>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@profian.com>
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Signed-off-by: default avatarMichael Roth <michael.roth@amd.com>
      Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
      Link: https://lore.kernel.org/r/20240126041126.1927228-14-michael.roth@amd.com
      1ca5614b
  6. 13 Dec, 2023 1 commit
    • Michael Roth's avatar
      KVM: SEV: Do not intercept accesses to MSR_IA32_XSS for SEV-ES guests · a26b7cd2
      Michael Roth authored
      When intercepts are enabled for MSR_IA32_XSS, the host will swap in/out
      the guest-defined values while context-switching to/from guest mode.
      However, in the case of SEV-ES, vcpu->arch.guest_state_protected is set,
      so the guest-defined value is effectively ignored when switching to
      guest mode with the understanding that the VMSA will handle swapping
      in/out this register state.
      
      However, SVM is still configured to intercept these accesses for SEV-ES
      guests, so the values in the initial MSR_IA32_XSS are effectively
      read-only, and a guest will experience undefined behavior if it actually
      tries to write to this MSR. Fortunately, only CET/shadowstack makes use
      of this register on SEV-ES-capable systems currently, which isn't yet
      widely used, but this may become more of an issue in the future.
      
      Additionally, enabling intercepts of MSR_IA32_XSS results in #VC
      exceptions in the guest in certain paths that can lead to unexpected #VC
      nesting levels. One example is SEV-SNP guests when handling #VC
      exceptions for CPUID instructions involving leaf 0xD, subleaf 0x1, since
      they will access MSR_IA32_XSS as part of servicing the CPUID #VC, then
      generate another #VC when accessing MSR_IA32_XSS, which can lead to
      guest crashes if an NMI occurs at that point in time. Running perf on a
      guest while it is issuing such a sequence is one example where these can
      be problematic.
      
      Address this by disabling intercepts of MSR_IA32_XSS for SEV-ES guests
      if the host/guest configuration allows it. If the host/guest
      configuration doesn't allow for MSR_IA32_XSS, leave it intercepted so
      that it can be caught by the existing checks in
      kvm_{set,get}_msr_common() if the guest still attempts to access it.
      
      Fixes: 376c6d28 ("KVM: SVM: Provide support for SEV-ES vCPU creation/loading")
      Cc: Alexey Kardashevskiy <aik@amd.com>
      Suggested-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Signed-off-by: default avatarMichael Roth <michael.roth@amd.com>
      Message-Id: <20231016132819.1002933-4-michael.roth@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      a26b7cd2
  7. 30 Nov, 2023 1 commit
  8. 23 Sep, 2023 2 commits
    • Tom Lendacky's avatar
      KVM: SVM: Fix TSC_AUX virtualization setup · e0096d01
      Tom Lendacky authored
      The checks for virtualizing TSC_AUX occur during the vCPU reset processing
      path. However, at the time of initial vCPU reset processing, when the vCPU
      is first created, not all of the guest CPUID information has been set. In
      this case the RDTSCP and RDPID feature support for the guest is not in
      place and so TSC_AUX virtualization is not established.
      
      This continues for each vCPU created for the guest. On the first boot of
      an AP, vCPU reset processing is executed as a result of an APIC INIT
      event, this time with all of the guest CPUID information set, resulting
      in TSC_AUX virtualization being enabled, but only for the APs. The BSP
      always sees a TSC_AUX value of 0 which probably went unnoticed because,
      at least for Linux, the BSP TSC_AUX value is 0.
      
      Move the TSC_AUX virtualization enablement out of the init_vmcb() path and
      into the vcpu_after_set_cpuid() path to allow for proper initialization of
      the support after the guest CPUID information has been set.
      
      With the TSC_AUX virtualization support now in the vcpu_set_after_cpuid()
      path, the intercepts must be either cleared or set based on the guest
      CPUID input.
      
      Fixes: 296d5a17 ("KVM: SEV-ES: Use V_TSC_AUX if available instead of RDTSC/MSR_TSC_AUX intercepts")
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <4137fbcb9008951ab5f0befa74a0399d2cce809a.1694811272.git.thomas.lendacky@amd.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      e0096d01
    • Paolo Bonzini's avatar
      KVM: SVM: INTERCEPT_RDTSCP is never intercepted anyway · e8d93d5d
      Paolo Bonzini authored
      svm_recalc_instruction_intercepts() is always called at least once
      before the vCPU is started, so the setting or clearing of the RDTSCP
      intercept can be dropped from the TSC_AUX virtualization support.
      
      Extracted from a patch by Tom Lendacky.
      
      Cc: stable@vger.kernel.org
      Fixes: 296d5a17 ("KVM: SEV-ES: Use V_TSC_AUX if available instead of RDTSC/MSR_TSC_AUX intercepts")
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      e8d93d5d
  9. 25 Aug, 2023 3 commits
    • Sean Christopherson's avatar
      KVM: SVM: Require nrips support for SEV guests (and beyond) · 80d0f521
      Sean Christopherson authored
      Disallow SEV (and beyond) if nrips is disabled via module param, as KVM
      can't read guest memory to partially emulate and skip an instruction.  All
      CPUs that support SEV support NRIPS, i.e. this is purely stopping the user
      from shooting themselves in the foot.
      
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Link: https://lore.kernel.org/r/20230825013621.2845700-3-seanjc@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
      80d0f521
    • Sean Christopherson's avatar
      KVM: SVM: Skip VMSA init in sev_es_init_vmcb() if pointer is NULL · 1952e74d
      Sean Christopherson authored
      Skip initializing the VMSA physical address in the VMCB if the VMSA is
      NULL, which occurs during intrahost migration as KVM initializes the VMCB
      before copying over state from the source to the destination (including
      the VMSA and its physical address).
      
      In normal builds, __pa() is just math, so the bug isn't fatal, but with
      CONFIG_DEBUG_VIRTUAL=y, the validity of the virtual address is verified
      and passing in NULL will make the kernel unhappy.
      
      Fixes: 6defa24d ("KVM: SEV: Init target VMCBs in sev_migrate_from")
      Cc: stable@vger.kernel.org
      Cc: Peter Gonda <pgonda@google.com>
      Reviewed-by: default avatarPeter Gonda <pgonda@google.com>
      Reviewed-by: default avatarPankaj Gupta <pankaj.gupta@amd.com>
      Link: https://lore.kernel.org/r/20230825022357.2852133-3-seanjc@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
      1952e74d
    • Sean Christopherson's avatar
      KVM: SVM: Get source vCPUs from source VM for SEV-ES intrahost migration · f1187ef2
      Sean Christopherson authored
      Fix a goof where KVM tries to grab source vCPUs from the destination VM
      when doing intrahost migration.  Grabbing the wrong vCPU not only hoses
      the guest, it also crashes the host due to the VMSA pointer being left
      NULL.
      
        BUG: unable to handle page fault for address: ffffe38687000000
        #PF: supervisor read access in kernel mode
        #PF: error_code(0x0000) - not-present page
        PGD 0 P4D 0
        Oops: 0000 [#1] SMP NOPTI
        CPU: 39 PID: 17143 Comm: sev_migrate_tes Tainted: GO       6.5.0-smp--fff2e47e6c3b-next #151
        Hardware name: Google, Inc. Arcadia_IT_80/Arcadia_IT_80, BIOS 34.28.0 07/10/2023
        RIP: 0010:__free_pages+0x15/0xd0
        RSP: 0018:ffff923fcf6e3c78 EFLAGS: 00010246
        RAX: 0000000000000000 RBX: ffffe38687000000 RCX: 0000000000000100
        RDX: 0000000000000100 RSI: 0000000000000000 RDI: ffffe38687000000
        RBP: ffff923fcf6e3c88 R08: ffff923fcafb0000 R09: 0000000000000000
        R10: 0000000000000000 R11: ffffffff83619b90 R12: ffff923fa9540000
        R13: 0000000000080007 R14: ffff923f6d35d000 R15: 0000000000000000
        FS:  0000000000000000(0000) GS:ffff929d0d7c0000(0000) knlGS:0000000000000000
        CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        CR2: ffffe38687000000 CR3: 0000005224c34005 CR4: 0000000000770ee0
        PKRU: 55555554
        Call Trace:
         <TASK>
         sev_free_vcpu+0xcb/0x110 [kvm_amd]
         svm_vcpu_free+0x75/0xf0 [kvm_amd]
         kvm_arch_vcpu_destroy+0x36/0x140 [kvm]
         kvm_destroy_vcpus+0x67/0x100 [kvm]
         kvm_arch_destroy_vm+0x161/0x1d0 [kvm]
         kvm_put_kvm+0x276/0x560 [kvm]
         kvm_vm_release+0x25/0x30 [kvm]
         __fput+0x106/0x280
         ____fput+0x12/0x20
         task_work_run+0x86/0xb0
         do_exit+0x2e3/0x9c0
         do_group_exit+0xb1/0xc0
         __x64_sys_exit_group+0x1b/0x20
         do_syscall_64+0x41/0x90
         entry_SYSCALL_64_after_hwframe+0x63/0xcd
         </TASK>
        CR2: ffffe38687000000
      
      Fixes: 6defa24d ("KVM: SEV: Init target VMCBs in sev_migrate_from")
      Cc: stable@vger.kernel.org
      Cc: Peter Gonda <pgonda@google.com>
      Reviewed-by: default avatarPeter Gonda <pgonda@google.com>
      Reviewed-by: default avatarPankaj Gupta <pankaj.gupta@amd.com>
      Link: https://lore.kernel.org/r/20230825022357.2852133-2-seanjc@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
      f1187ef2
  10. 04 Aug, 2023 3 commits
    • Paolo Bonzini's avatar
      KVM: SEV: remove ghcb variable declarations · 63dbc67c
      Paolo Bonzini authored
      To avoid possible time-of-check/time-of-use issues, the GHCB should
      almost never be accessed outside dump_ghcb, sev_es_sync_to_ghcb
      and sev_es_sync_from_ghcb.  The only legitimate uses are to set the
      exitinfo fields and to find the address of the scratch area embedded
      in the ghcb.  Accessing ghcb_usage also goes through svm->sev_es.ghcb
      in sev_es_validate_vmgexit(), but that is because anyway the value is
      not used.
      
      Removing a shortcut variable that contains the value of svm->sev_es.ghcb
      makes these cases a bit more verbose, but it limits the chance of someone
      reading the ghcb by mistake.
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      63dbc67c
    • Paolo Bonzini's avatar
      KVM: SEV: only access GHCB fields once · 7588dbce
      Paolo Bonzini authored
      A KVM guest using SEV-ES or SEV-SNP with multiple vCPUs can trigger
      a double fetch race condition vulnerability and invoke the VMGEXIT
      handler recursively.
      
      sev_handle_vmgexit() maps the GHCB page using kvm_vcpu_map() and then
      fetches the exit code using ghcb_get_sw_exit_code().  Soon after,
      sev_es_validate_vmgexit() fetches the exit code again. Since the GHCB
      page is shared with the guest, the guest is able to quickly swap the
      values with another vCPU and hence bypass the validation. One vmexit code
      that can be rejected by sev_es_validate_vmgexit() is SVM_EXIT_VMGEXIT;
      if sev_handle_vmgexit() observes it in the second fetch, the call
      to svm_invoke_exit_handler() will invoke sev_handle_vmgexit() again
      recursively.
      
      To avoid the race, always fetch the GHCB data from the places where
      sev_es_sync_from_ghcb stores it.
      
      Exploiting recursions on linux kernel has been proven feasible
      in the past, but the impact is mitigated by stack guard pages
      (CONFIG_VMAP_STACK).  Still, if an attacker manages to call the handler
      multiple times, they can theoretically trigger a stack overflow and
      cause a denial-of-service, or potentially guest-to-host escape in kernel
      configurations without stack guard pages.
      
      Note that winning the race reliably in every iteration is very tricky
      due to the very tight window of the fetches; depending on the compiler
      settings, they are often consecutive because of optimization and inlining.
      
      Tested by booting an SEV-ES RHEL9 guest.
      
      Fixes: CVE-2023-4155
      Fixes: 291bd20d ("KVM: SVM: Add initial support for a VMGEXIT VMEXIT")
      Cc: stable@vger.kernel.org
      Reported-by: default avatarAndy Nguyen <theflow@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      7588dbce
    • Paolo Bonzini's avatar
      KVM: SEV: snapshot the GHCB before accessing it · 4e15a0dd
      Paolo Bonzini authored
      Validation of the GHCB is susceptible to time-of-check/time-of-use vulnerabilities.
      To avoid them, we would like to always snapshot the fields that are read in
      sev_es_validate_vmgexit(), and not use the GHCB anymore after it returns.
      
      This means:
      
      - invoking sev_es_sync_from_ghcb() before any GHCB access, including before
        sev_es_validate_vmgexit()
      
      - snapshotting all fields including the valid bitmap and the sw_scratch field,
        which are currently not caching anywhere.
      
      The valid bitmap is the first thing to be copied out of the GHCB; then,
      further accesses will use the copy in svm->sev_es.
      
      Fixes: 291bd20d ("KVM: SVM: Add initial support for a VMGEXIT VMEXIT")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      4e15a0dd
  11. 28 Jul, 2023 7 commits
  12. 13 Jun, 2023 1 commit
  13. 06 Jun, 2023 1 commit
  14. 21 Apr, 2023 1 commit
  15. 17 Mar, 2023 1 commit
  16. 07 Feb, 2023 1 commit
  17. 24 Jan, 2023 1 commit
  18. 29 Dec, 2022 1 commit
    • Sean Christopherson's avatar
      KVM: x86: Unify pr_fmt to use module name for all KVM modules · 8d20bd63
      Sean Christopherson authored
      Define pr_fmt using KBUILD_MODNAME for all KVM x86 code so that printks
      use consistent formatting across common x86, Intel, and AMD code.  In
      addition to providing consistent print formatting, using KBUILD_MODNAME,
      e.g. kvm_amd and kvm_intel, allows referencing SVM and VMX (and SEV and
      SGX and ...) as technologies without generating weird messages, and
      without causing naming conflicts with other kernel code, e.g. "SEV: ",
      "tdx: ", "sgx: " etc.. are all used by the kernel for non-KVM subsystems.
      
      Opportunistically move away from printk() for prints that need to be
      modified anyways, e.g. to drop a manual "kvm: " prefix.
      
      Opportunistically convert a few SGX WARNs that are similarly modified to
      WARN_ONCE; in the very unlikely event that the WARNs fire, odds are good
      that they would fire repeatedly and spam the kernel log without providing
      unique information in each print.
      
      Note, defining pr_fmt yields undesirable results for code that uses KVM's
      printk wrappers, e.g. vcpu_unimpl().  But, that's a pre-existing problem
      as SVM/kvm_amd already defines a pr_fmt, and thankfully use of KVM's
      wrappers is relatively limited in KVM x86 code.
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Reviewed-by: default avatarPaul Durrant <paul@xen.org>
      Message-Id: <20221130230934.1014142-35-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      8d20bd63
  19. 01 Dec, 2022 1 commit
  20. 09 Nov, 2022 3 commits
    • Carlos Bilbao's avatar
      KVM: SVM: Name and check reserved fields with structs offset · d08b4858
      Carlos Bilbao authored
      Rename reserved fields on all structs in arch/x86/include/asm/svm.h
      following their offset within the structs. Include compile time checks for
      this in the same place where other BUILD_BUG_ON for the structs are.
      
      This also solves that fields of struct sev_es_save_area are named by their
      order of appearance, but right now they jump from reserved_5 to reserved_7.
      
      Link: https://lkml.org/lkml/2022/10/22/376Signed-off-by: default avatarCarlos Bilbao <carlos.bilbao@amd.com>
      Message-Id: <20221024164448.203351-1-carlos.bilbao@amd.com>
      [Use ASSERT_STRUCT_OFFSET + fix a couple wrong offsets. - Paolo]
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      d08b4858
    • Peter Gonda's avatar
      KVM: SVM: Only dump VMSA to klog at KERN_DEBUG level · 0bd8bd2f
      Peter Gonda authored
      Explicitly print the VMSA dump at KERN_DEBUG log level, KERN_CONT uses
      KERNEL_DEFAULT if the previous log line has a newline, i.e. if there's
      nothing to continuing, and as a result the VMSA gets dumped when it
      shouldn't.
      
      The KERN_CONT documentation says it defaults back to KERNL_DEFAULT if the
      previous log line has a newline. So switch from KERN_CONT to
      print_hex_dump_debug().
      
      Jarkko pointed this out in reference to the original patch. See:
      https://lore.kernel.org/all/YuPMeWX4uuR1Tz3M@kernel.org/
      print_hex_dump(KERN_DEBUG, ...) was pointed out there, but
      print_hex_dump_debug() should similar.
      
      Fixes: 6fac42f1 ("KVM: SVM: Dump Virtual Machine Save Area (VMSA) to klog")
      Signed-off-by: default avatarPeter Gonda <pgonda@google.com>
      Reviewed-by: default avatarSean Christopherson <seanjc@google.com>
      Cc: Jarkko Sakkinen <jarkko@kernel.org>
      Cc: Harald Hoyer <harald@profian.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: x86@kernel.org
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: kvm@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Cc: stable@vger.kernel.org
      Message-Id: <20221104142220.469452-1-pgonda@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      0bd8bd2f
    • Paolo Bonzini's avatar
      KVM: SVM: do not allocate struct svm_cpu_data dynamically · 73412dfe
      Paolo Bonzini authored
      The svm_data percpu variable is a pointer, but it is allocated via
      svm_hardware_setup() when KVM is loaded.  Unlike hardware_enable()
      this means that it is never NULL for the whole lifetime of KVM, and
      static allocation does not waste any memory compared to the status quo.
      It is also more efficient and more easily handled from assembly code,
      so do it and don't look back.
      Reviewed-by: default avatarSean Christopherson <seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      73412dfe
  21. 10 Aug, 2022 1 commit
    • Sean Christopherson's avatar
      KVM: SVM: Disable SEV-ES support if MMIO caching is disable · 0c29397a
      Sean Christopherson authored
      Disable SEV-ES if MMIO caching is disabled as SEV-ES relies on MMIO SPTEs
      generating #NPF(RSVD), which are reflected by the CPU into the guest as
      a #VC.  With SEV-ES, the untrusted host, a.k.a. KVM, doesn't have access
      to the guest instruction stream or register state and so can't directly
      emulate in response to a #NPF on an emulated MMIO GPA.  Disabling MMIO
      caching means guest accesses to emulated MMIO ranges cause #NPF(!PRESENT),
      and those flavors of #NPF cause automatic VM-Exits, not #VC.
      
      Adjust KVM's MMIO masks to account for the C-bit location prior to doing
      SEV(-ES) setup, and document that dependency between adjusting the MMIO
      SPTE mask and SEV(-ES) setup.
      
      Fixes: b09763da ("KVM: x86/mmu: Add module param to disable MMIO caching (for testing)")
      Reported-by: default avatarMichael Roth <michael.roth@amd.com>
      Tested-by: default avatarMichael Roth <michael.roth@amd.com>
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20220803224957.1285926-4-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      0c29397a