An error occurred fetching the project authors.
  1. 19 Apr, 2021 1 commit
    • Tom Lendacky's avatar
      KVM: SVM: Make sure GHCB is mapped before updating · a3ba26ec
      Tom Lendacky authored
      Access to the GHCB is mainly in the VMGEXIT path and it is known that the
      GHCB will be mapped. But there are two paths where it is possible the GHCB
      might not be mapped.
      
      The sev_vcpu_deliver_sipi_vector() routine will update the GHCB to inform
      the caller of the AP Reset Hold NAE event that a SIPI has been delivered.
      However, if a SIPI is performed without a corresponding AP Reset Hold,
      then the GHCB might not be mapped (depending on the previous VMEXIT),
      which will result in a NULL pointer dereference.
      
      The svm_complete_emulated_msr() routine will update the GHCB to inform
      the caller of a RDMSR/WRMSR operation about any errors. While it is likely
      that the GHCB will be mapped in this situation, add a safe guard
      in this path to be certain a NULL pointer dereference is not encountered.
      
      Fixes: f1c6366e ("KVM: SVM: Add required changes to support intercepts under SEV-ES")
      Fixes: 647daca2 ("KVM: SVM: Add support for booting APs in an SEV-ES guest")
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Cc: stable@vger.kernel.org
      Message-Id: <a5d3ebb600a91170fc88599d5a575452b3e31036.1617979121.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      a3ba26ec
  2. 17 Apr, 2021 4 commits
    • Sean Christopherson's avatar
      KVM: x86: Account a variety of miscellaneous allocations · eba04b20
      Sean Christopherson authored
      Switch to GFP_KERNEL_ACCOUNT for a handful of allocations that are
      clearly associated with a single task/VM.
      
      Note, there are a several SEV allocations that aren't accounted, but
      those can (hopefully) be fixed by using the local stack for memory.
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20210331023025.2485960-3-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      eba04b20
    • Sean Christopherson's avatar
      KVM: SVM: Do not allow SEV/SEV-ES initialization after vCPUs are created · 8727906f
      Sean Christopherson authored
      Reject KVM_SEV_INIT and KVM_SEV_ES_INIT if they are attempted after one
      or more vCPUs have been created.  KVM assumes a VM is tagged SEV/SEV-ES
      prior to vCPU creation, e.g. init_vmcb() needs to mark the VMCB as SEV
      enabled, and svm_create_vcpu() needs to allocate the VMSA.  At best,
      creating vCPUs before SEV/SEV-ES init will lead to unexpected errors
      and/or behavior, and at worst it will crash the host, e.g.
      sev_launch_update_vmsa() will dereference a null svm->vmsa pointer.
      
      Fixes: 1654efcb ("KVM: SVM: Add KVM_SEV_INIT command")
      Fixes: ad73109a ("KVM: SVM: Provide support to launch and run an SEV-ES guest")
      Cc: stable@vger.kernel.org
      Cc: Brijesh Singh <brijesh.singh@amd.com>
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20210331031936.2495277-4-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      8727906f
    • Sean Christopherson's avatar
      KVM: SVM: Do not set sev->es_active until KVM_SEV_ES_INIT completes · 9fa1521d
      Sean Christopherson authored
      Set sev->es_active only after the guts of KVM_SEV_ES_INIT succeeds.  If
      the command fails, e.g. because SEV is already active or there are no
      available ASIDs, then es_active will be left set even though the VM is
      not fully SEV-ES capable.
      
      Refactor the code so that "es_active" is passed on the stack instead of
      being prematurely shoved into sev_info, both to avoid having to unwind
      sev_info and so that it's more obvious what actually consumes es_active
      in sev_guest_init() and its helpers.
      
      Fixes: ad73109a ("KVM: SVM: Provide support to launch and run an SEV-ES guest")
      Cc: stable@vger.kernel.org
      Cc: Brijesh Singh <brijesh.singh@amd.com>
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20210331031936.2495277-3-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      9fa1521d
    • Sean Christopherson's avatar
      KVM: SVM: Use online_vcpus, not created_vcpus, to iterate over vCPUs · c36b16d2
      Sean Christopherson authored
      Use the kvm_for_each_vcpu() helper to iterate over vCPUs when encrypting
      VMSAs for SEV, which effectively switches to use online_vcpus instead of
      created_vcpus.  This fixes a possible null-pointer dereference as
      created_vcpus does not guarantee a vCPU exists, since it is updated at
      the very beginning of KVM_CREATE_VCPU.  created_vcpus exists to allow the
      bulk of vCPU creation to run in parallel, while still correctly
      restricting the max number of max vCPUs.
      
      Fixes: ad73109a ("KVM: SVM: Provide support to launch and run an SEV-ES guest")
      Cc: stable@vger.kernel.org
      Cc: Brijesh Singh <brijesh.singh@amd.com>
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20210331031936.2495277-2-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      c36b16d2
  3. 15 Mar, 2021 1 commit
  4. 04 Feb, 2021 4 commits
    • Michael Roth's avatar
      KVM: SVM: use .prepare_guest_switch() to handle CPU register save/setup · a7fc06dd
      Michael Roth authored
      Currently we save host state like user-visible host MSRs, and do some
      initial guest register setup for MSR_TSC_AUX and MSR_AMD64_TSC_RATIO
      in svm_vcpu_load(). Defer this until just before we enter the guest by
      moving the handling to kvm_x86_ops.prepare_guest_switch() similarly to
      how it is done for the VMX implementation.
      
      Additionally, since handling of saving/restoring host user MSRs is the
      same both with/without SEV-ES enabled, move that handling to common
      code.
      Suggested-by: default avatarSean Christopherson <seanjc@google.com>
      Signed-off-by: default avatarMichael Roth <michael.roth@amd.com>
      Message-Id: <20210202190126.2185715-4-michael.roth@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      a7fc06dd
    • Michael Roth's avatar
      KVM: SVM: remove uneeded fields from host_save_users_msrs · 553cc15f
      Michael Roth authored
      Now that the set of host user MSRs that need to be individually
      saved/restored are the same with/without SEV-ES, we can drop the
      .sev_es_restored flag and just iterate through the list unconditionally
      for both cases. A subsequent patch can then move these loops to a
      common path.
      Signed-off-by: default avatarMichael Roth <michael.roth@amd.com>
      Message-Id: <20210202190126.2185715-3-michael.roth@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      553cc15f
    • Sean Christopherson's avatar
      KVM: SVM: Use asm goto to handle unexpected #UD on SVM instructions · 35a78319
      Sean Christopherson authored
      Add svm_asm*() macros, a la the existing vmx_asm*() macros, to handle
      faults on SVM instructions instead of using the generic __ex(), a.k.a.
      __kvm_handle_fault_on_reboot().  Using asm goto generates slightly
      better code as it eliminates the in-line JMP+CALL sequences that are
      needed by __kvm_handle_fault_on_reboot() to avoid triggering BUG()
      from fixup (which generates bad stack traces).
      
      Using SVM specific macros also drops the last user of __ex() and the
      the last asm linkage to kvm_spurious_fault(), and adds a helper for
      VMSAVE, which may gain an addition call site in the future (as part
      of optimizing the SVM context switching).
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20201231002702.22237077-8-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      35a78319
    • Brijesh Singh's avatar
      KVM/SVM: add support for SEV attestation command · 2c07ded0
      Brijesh Singh authored
      The SEV FW version >= 0.23 added a new command that can be used to query
      the attestation report containing the SHA-256 digest of the guest memory
      encrypted through the KVM_SEV_LAUNCH_UPDATE_{DATA, VMSA} commands and
      sign the report with the Platform Endorsement Key (PEK).
      
      See the SEV FW API spec section 6.8 for more details.
      
      Note there already exist a command (KVM_SEV_LAUNCH_MEASURE) that can be
      used to get the SHA-256 digest. The main difference between the
      KVM_SEV_LAUNCH_MEASURE and KVM_SEV_ATTESTATION_REPORT is that the latter
      can be called while the guest is running and the measurement value is
      signed with PEK.
      
      Cc: James Bottomley <jejb@linux.ibm.com>
      Cc: Tom Lendacky <Thomas.Lendacky@amd.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: John Allen <john.allen@amd.com>
      Cc: Herbert Xu <herbert@gondor.apana.org.au>
      Cc: linux-crypto@vger.kernel.org
      Reviewed-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Acked-by: default avatarDavid Rientjes <rientjes@google.com>
      Tested-by: default avatarJames Bottomley <jejb@linux.ibm.com>
      Signed-off-by: default avatarBrijesh Singh <brijesh.singh@amd.com>
      Message-Id: <20210104151749.30248-1-brijesh.singh@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      2c07ded0
  5. 28 Jan, 2021 1 commit
    • Peter Gonda's avatar
      Fix unsynchronized access to sev members through svm_register_enc_region · 19a23da5
      Peter Gonda authored
      Grab kvm->lock before pinning memory when registering an encrypted
      region; sev_pin_memory() relies on kvm->lock being held to ensure
      correctness when checking and updating the number of pinned pages.
      
      Add a lockdep assertion to help prevent future regressions.
      
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Joerg Roedel <joro@8bytes.org>
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Cc: Brijesh Singh <brijesh.singh@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: x86@kernel.org
      Cc: kvm@vger.kernel.org
      Cc: stable@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Fixes: 1e80fdc0 ("KVM: SVM: Pin guest memory when SEV is active")
      Signed-off-by: default avatarPeter Gonda <pgonda@google.com>
      
      V2
       - Fix up patch description
       - Correct file paths svm.c -> sev.c
       - Add unlock of kvm->lock on sev_pin_memory error
      
      V1
       - https://lore.kernel.org/kvm/20210126185431.1824530-1-pgonda@google.com/
      
      Message-Id: <20210127161524.2832400-1-pgonda@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      19a23da5
  6. 25 Jan, 2021 1 commit
    • Sean Christopherson's avatar
      KVM: SVM: Unconditionally sync GPRs to GHCB on VMRUN of SEV-ES guest · 25009140
      Sean Christopherson authored
      Drop the per-GPR dirty checks when synchronizing GPRs to the GHCB, the
      GRPs' dirty bits are set from time zero and never cleared, i.e. will
      always be seen as dirty.  The obvious alternative would be to clear
      the dirty bits when appropriate, but removing the dirty checks is
      desirable as it allows reverting GPR dirty+available tracking, which
      adds overhead to all flavors of x86 VMs.
      
      Note, unconditionally writing the GPRs in the GHCB is tacitly allowed
      by the GHCB spec, which allows the hypervisor (or guest) to provide
      unnecessary info; it's the guest's responsibility to consume only what
      it needs (the hypervisor is untrusted after all).
      
        The guest and hypervisor can supply additional state if desired but
        must not rely on that additional state being provided.
      
      Cc: Brijesh Singh <brijesh.singh@amd.com>
      Cc: Tom Lendacky <thomas.lendacky@amd.com>
      Fixes: 291bd20d ("KVM: SVM: Add initial support for a VMGEXIT VMEXIT")
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20210122235049.3107620-2-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      25009140
  7. 07 Jan, 2021 2 commits
    • Tom Lendacky's avatar
      KVM: SVM: Add support for booting APs in an SEV-ES guest · 647daca2
      Tom Lendacky authored
      Typically under KVM, an AP is booted using the INIT-SIPI-SIPI sequence,
      where the guest vCPU register state is updated and then the vCPU is VMRUN
      to begin execution of the AP. For an SEV-ES guest, this won't work because
      the guest register state is encrypted.
      
      Following the GHCB specification, the hypervisor must not alter the guest
      register state, so KVM must track an AP/vCPU boot. Should the guest want
      to park the AP, it must use the AP Reset Hold exit event in place of, for
      example, a HLT loop.
      
      First AP boot (first INIT-SIPI-SIPI sequence):
        Execute the AP (vCPU) as it was initialized and measured by the SEV-ES
        support. It is up to the guest to transfer control of the AP to the
        proper location.
      
      Subsequent AP boot:
        KVM will expect to receive an AP Reset Hold exit event indicating that
        the vCPU is being parked and will require an INIT-SIPI-SIPI sequence to
        awaken it. When the AP Reset Hold exit event is received, KVM will place
        the vCPU into a simulated HLT mode. Upon receiving the INIT-SIPI-SIPI
        sequence, KVM will make the vCPU runnable. It is again up to the guest
        to then transfer control of the AP to the proper location.
      
        To differentiate between an actual HLT and an AP Reset Hold, a new MP
        state is introduced, KVM_MP_STATE_AP_RESET_HOLD, which the vCPU is
        placed in upon receiving the AP Reset Hold exit event. Additionally, to
        communicate the AP Reset Hold exit event up to userspace (if needed), a
        new exit reason is introduced, KVM_EXIT_AP_RESET_HOLD.
      
      A new x86 ops function is introduced, vcpu_deliver_sipi_vector, in order
      to accomplish AP booting. For VMX, vcpu_deliver_sipi_vector is set to the
      original SIPI delivery function, kvm_vcpu_deliver_sipi_vector(). SVM adds
      a new function that, for non SEV-ES guests, invokes the original SIPI
      delivery function, kvm_vcpu_deliver_sipi_vector(), but for SEV-ES guests,
      implements the logic above.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <e8fbebe8eb161ceaabdad7c01a5859a78b424d5e.1609791600.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      647daca2
    • Nathan Chancellor's avatar
      KVM: SVM: Add register operand to vmsave call in sev_es_vcpu_load · f65cf84e
      Nathan Chancellor authored
      When using LLVM's integrated assembler (LLVM_IAS=1) while building
      x86_64_defconfig + CONFIG_KVM=y + CONFIG_KVM_AMD=y, the following build
      error occurs:
      
       $ make LLVM=1 LLVM_IAS=1 arch/x86/kvm/svm/sev.o
       arch/x86/kvm/svm/sev.c:2004:15: error: too few operands for instruction
               asm volatile(__ex("vmsave") : : "a" (__sme_page_pa(sd->save_area)) : "memory");
                            ^
       arch/x86/kvm/svm/sev.c:28:17: note: expanded from macro '__ex'
       #define __ex(x) __kvm_handle_fault_on_reboot(x)
                       ^
       ./arch/x86/include/asm/kvm_host.h:1646:10: note: expanded from macro '__kvm_handle_fault_on_reboot'
               "666: \n\t"                                                     \
                       ^
       <inline asm>:2:2: note: instantiated into assembly here
               vmsave
               ^
       1 error generated.
      
      This happens because LLVM currently does not support calling vmsave
      without the fixed register operand (%rax for 64-bit and %eax for
      32-bit). This will be fixed in LLVM 12 but the kernel currently supports
      LLVM 10.0.1 and newer so this needs to be handled.
      
      Add the proper register using the _ASM_AX macro, which matches the
      vmsave call in vmenter.S.
      
      Fixes: 86137773 ("KVM: SVM: Provide support for SEV-ES vCPU loading")
      Link: https://reviews.llvm.org/D93524
      Link: https://github.com/ClangBuiltLinux/linux/issues/1216Signed-off-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Message-Id: <20201219063711.3526947-1-natechancellor@gmail.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      f65cf84e
  8. 16 Dec, 2020 1 commit
  9. 15 Dec, 2020 15 commits
    • Tom Lendacky's avatar
      KVM: SVM: Add AP_JUMP_TABLE support in prep for AP booting · 8640ca58
      Tom Lendacky authored
      The GHCB specification requires the hypervisor to save the address of an
      AP Jump Table so that, for example, vCPUs that have been parked by UEFI
      can be started by the OS. Provide support for the AP Jump Table set/get
      exit code.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      8640ca58
    • Tom Lendacky's avatar
      KVM: SVM: Provide support to launch and run an SEV-ES guest · ad73109a
      Tom Lendacky authored
      An SEV-ES guest is started by invoking a new SEV initialization ioctl,
      KVM_SEV_ES_INIT. This identifies the guest as an SEV-ES guest, which is
      used to drive the appropriate ASID allocation, VMSA encryption, etc.
      
      Before being able to run an SEV-ES vCPU, the vCPU VMSA must be encrypted
      and measured. This is done using the LAUNCH_UPDATE_VMSA command after all
      calls to LAUNCH_UPDATE_DATA have been performed, but before LAUNCH_MEASURE
      has been performed. In order to establish the encrypted VMSA, the current
      (traditional) VMSA and the GPRs are synced to the page that will hold the
      encrypted VMSA and then LAUNCH_UPDATE_VMSA is invoked. The vCPU is then
      marked as having protected guest state.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <e9643245adb809caf3a87c09997926d2f3d6ff41.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      ad73109a
    • Tom Lendacky's avatar
      KVM: SVM: Provide support for SEV-ES vCPU loading · 86137773
      Tom Lendacky authored
      An SEV-ES vCPU requires additional VMCB vCPU load/put requirements. SEV-ES
      hardware will restore certain registers on VMEXIT, but not save them on
      VMRUN (see Table B-3 and Table B-4 of the AMD64 APM Volume 2), so make the
      following changes:
      
      General vCPU load changes:
        - During vCPU loading, perform a VMSAVE to the per-CPU SVM save area and
          save the current values of XCR0, XSS and PKRU to the per-CPU SVM save
          area as these registers will be restored on VMEXIT.
      
      General vCPU put changes:
        - Do not attempt to restore registers that SEV-ES hardware has already
          restored on VMEXIT.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <019390e9cb5e93cd73014fa5a040c17d42588733.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      86137773
    • Tom Lendacky's avatar
      KVM: SVM: Provide support for SEV-ES vCPU creation/loading · 376c6d28
      Tom Lendacky authored
      An SEV-ES vCPU requires additional VMCB initialization requirements for
      vCPU creation and vCPU load/put requirements. This includes:
      
      General VMCB initialization changes:
        - Set a VMCB control bit to enable SEV-ES support on the vCPU.
        - Set the VMCB encrypted VM save area address.
        - CRx registers are part of the encrypted register state and cannot be
          updated. Remove the CRx register read and write intercepts and replace
          them with CRx register write traps to track the CRx register values.
        - Certain MSR values are part of the encrypted register state and cannot
          be updated. Remove certain MSR intercepts (EFER, CR_PAT, etc.).
        - Remove the #GP intercept (no support for "enable_vmware_backdoor").
        - Remove the XSETBV intercept since the hypervisor cannot modify XCR0.
      
      General vCPU creation changes:
        - Set the initial GHCB gpa value as per the GHCB specification.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <3a8aef366416eddd5556dfa3fdc212aafa1ad0a2.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      376c6d28
    • Tom Lendacky's avatar
      KVM: SVM: Update ASID allocation to support SEV-ES guests · 80675b3a
      Tom Lendacky authored
      SEV and SEV-ES guests each have dedicated ASID ranges. Update the ASID
      allocation routine to return an ASID in the respective range.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <d7aed505e31e3954268b2015bb60a1486269c780.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      80675b3a
    • Tom Lendacky's avatar
      KVM: SVM: Set the encryption mask for the SVM host save area · 85ca8be9
      Tom Lendacky authored
      The SVM host save area is used to restore some host state on VMEXIT of an
      SEV-ES guest. After allocating the save area, clear it and add the
      encryption mask to the SVM host save area physical address that is
      programmed into the VM_HSAVE_PA MSR.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <b77aa28af6d7f1a0cb545959e08d6dc75e0c3cba.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      85ca8be9
    • Tom Lendacky's avatar
      KVM: SVM: Add NMI support for an SEV-ES guest · 4444dfe4
      Tom Lendacky authored
      The GHCB specification defines how NMIs are to be handled for an SEV-ES
      guest. To detect the completion of an NMI the hypervisor must not
      intercept the IRET instruction (because a #VC while running the NMI will
      issue an IRET) and, instead, must receive an NMI Complete exit event from
      the guest.
      
      Update the KVM support for detecting the completion of NMIs in the guest
      to follow the GHCB specification. When an SEV-ES guest is active, the
      IRET instruction will no longer be intercepted. Now, when the NMI Complete
      exit event is received, the iret_interception() function will be called
      to simulate the completion of the NMI.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <5ea3dd69b8d4396cefdc9048ebc1ab7caa70a847.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      4444dfe4
    • Tom Lendacky's avatar
      KVM: SVM: Support string IO operations for an SEV-ES guest · 7ed9abfe
      Tom Lendacky authored
      For an SEV-ES guest, string-based port IO is performed to a shared
      (un-encrypted) page so that both the hypervisor and guest can read or
      write to it and each see the contents.
      
      For string-based port IO operations, invoke SEV-ES specific routines that
      can complete the operation using common KVM port IO support.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <9d61daf0ffda496703717218f415cdc8fd487100.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      7ed9abfe
    • Tom Lendacky's avatar
      KVM: SVM: Support MMIO for an SEV-ES guest · 8f423a80
      Tom Lendacky authored
      For an SEV-ES guest, MMIO is performed to a shared (un-encrypted) page
      so that both the hypervisor and guest can read or write to it and each
      see the contents.
      
      The GHCB specification provides software-defined VMGEXIT exit codes to
      indicate a request for an MMIO read or an MMIO write. Add support to
      recognize the MMIO requests and invoke SEV-ES specific routines that
      can complete the MMIO operation. These routines use common KVM support
      to complete the MMIO operation.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <af8de55127d5bcc3253d9b6084a0144c12307d4d.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      8f423a80
    • Tom Lendacky's avatar
      KVM: SVM: Create trace events for VMGEXIT MSR protocol processing · 59e38b58
      Tom Lendacky authored
      Add trace events for entry to and exit from VMGEXIT MSR protocol
      processing. The vCPU will be common for the trace events. The MSR
      protocol processing is guided by the GHCB GPA in the VMCB, so the GHCB
      GPA will represent the input and output values for the entry and exit
      events, respectively. Additionally, the exit event will contain the
      return code for the event.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <c5b3b440c3e0db43ff2fc02813faa94fa54896b0.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      59e38b58
    • Tom Lendacky's avatar
      KVM: SVM: Create trace events for VMGEXIT processing · d523ab6b
      Tom Lendacky authored
      Add trace events for entry to and exit from VMGEXIT processing. The vCPU
      id and the exit reason will be common for the trace events. The exit info
      fields will represent the input and output values for the entry and exit
      events, respectively.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <25357dca49a38372e8f483753fb0c1c2a70a6898.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      d523ab6b
    • Tom Lendacky's avatar
      KVM: SVM: Add support for SEV-ES GHCB MSR protocol function 0x100 · e1d71116
      Tom Lendacky authored
      The GHCB specification defines a GHCB MSR protocol using the lower
      12-bits of the GHCB MSR (in the hypervisor this corresponds to the
      GHCB GPA field in the VMCB).
      
      Function 0x100 is a request for termination of the guest. The guest has
      encountered some situation for which it has requested to be terminated.
      The GHCB MSR value contains the reason for the request.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <f3a1f7850c75b6ea4101e15bbb4a3af1a203f1dc.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      e1d71116
    • Tom Lendacky's avatar
      KVM: SVM: Add support for SEV-ES GHCB MSR protocol function 0x004 · d3694667
      Tom Lendacky authored
      The GHCB specification defines a GHCB MSR protocol using the lower
      12-bits of the GHCB MSR (in the hypervisor this corresponds to the
      GHCB GPA field in the VMCB).
      
      Function 0x004 is a request for CPUID information. Only a single CPUID
      result register can be sent per invocation, so the protocol defines the
      register that is requested. The GHCB MSR value is set to the CPUID
      register value as per the specification via the VMCB GHCB GPA field.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <fd7ee347d3936e484c06e9001e340bf6387092cd.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      d3694667
    • Tom Lendacky's avatar
      KVM: SVM: Add support for SEV-ES GHCB MSR protocol function 0x002 · 1edc1459
      Tom Lendacky authored
      The GHCB specification defines a GHCB MSR protocol using the lower
      12-bits of the GHCB MSR (in the hypervisor this corresponds to the
      GHCB GPA field in the VMCB).
      
      Function 0x002 is a request to set the GHCB MSR value to the SEV INFO as
      per the specification via the VMCB GHCB GPA field.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <c23c163a505290a0d1b9efc4659b838c8c902cbc.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      1edc1459
    • Tom Lendacky's avatar
      KVM: SVM: Add initial support for a VMGEXIT VMEXIT · 291bd20d
      Tom Lendacky authored
      SEV-ES adds a new VMEXIT reason code, VMGEXIT. Initial support for a
      VMGEXIT includes mapping the GHCB based on the guest GPA, which is
      obtained from a new VMCB field, and then validating the required inputs
      for the VMGEXIT exit reason.
      
      Since many of the VMGEXIT exit reasons correspond to existing VMEXIT
      reasons, the information from the GHCB is copied into the VMCB control
      exit code areas and KVM register areas. The standard exit handlers are
      invoked, similar to standard VMEXIT processing. Before restarting the
      vCPU, the GHCB is updated with any registers that have been updated by
      the hypervisor.
      Signed-off-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Message-Id: <c6a4ed4294a369bd75c44d03bd7ce0f0c3840e50.1607620209.git.thomas.lendacky@amd.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      291bd20d
  10. 14 Dec, 2020 3 commits
  11. 03 Dec, 2020 1 commit
  12. 16 Nov, 2020 1 commit
  13. 28 Sep, 2020 2 commits
  14. 19 Sep, 2020 1 commit
  15. 11 Sep, 2020 1 commit
    • David Rientjes's avatar
      KVM: SVM: Periodically schedule when unregistering regions on destroy · 7be74942
      David Rientjes authored
      There may be many encrypted regions that need to be unregistered when a
      SEV VM is destroyed.  This can lead to soft lockups.  For example, on a
      host running 4.15:
      
      watchdog: BUG: soft lockup - CPU#206 stuck for 11s! [t_virtual_machi:194348]
      CPU: 206 PID: 194348 Comm: t_virtual_machi
      RIP: 0010:free_unref_page_list+0x105/0x170
      ...
      Call Trace:
       [<0>] release_pages+0x159/0x3d0
       [<0>] sev_unpin_memory+0x2c/0x50 [kvm_amd]
       [<0>] __unregister_enc_region_locked+0x2f/0x70 [kvm_amd]
       [<0>] svm_vm_destroy+0xa9/0x200 [kvm_amd]
       [<0>] kvm_arch_destroy_vm+0x47/0x200
       [<0>] kvm_put_kvm+0x1a8/0x2f0
       [<0>] kvm_vm_release+0x25/0x30
       [<0>] do_exit+0x335/0xc10
       [<0>] do_group_exit+0x3f/0xa0
       [<0>] get_signal+0x1bc/0x670
       [<0>] do_signal+0x31/0x130
      
      Although the CLFLUSH is no longer issued on every encrypted region to be
      unregistered, there are no other changes that can prevent soft lockups for
      very large SEV VMs in the latest kernel.
      
      Periodically schedule if necessary.  This still holds kvm->lock across the
      resched, but since this only happens when the VM is destroyed this is
      assumed to be acceptable.
      Signed-off-by: default avatarDavid Rientjes <rientjes@google.com>
      Message-Id: <alpine.DEB.2.23.453.2008251255240.2987727@chino.kir.corp.google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      7be74942
  16. 02 Aug, 2020 1 commit