[PATCH Part2 RFC v3 00/37] Add AMD Secure Nested Paging (SEV-SNP) Hypervisor Support

Brijesh Singh
2021-06-02T14:12:57Z

This part of the Secure Encrypted Paging (SEV-SNP) series focuses on the
changes required in a host OS for SEV-SNP support. The series builds upon
SEV-SNP Part-1.

This series provides the basic building blocks to support booting the SEV-SNP
VMs, it does not cover all the security enhancement introduced by the SEV-SNP
such as interrupt protection.

The CCP driver is enhanced to provide new APIs that use the SEV-SNP
specific commands defined in the SEV-SNP firmware specification. The KVM
driver uses those APIs to create and managed the SEV-SNP guests.

The GHCB specification version 2 introduces new set of NAE's that is
used by the SEV-SNP guest to communicate with the hypervisor. The series
provides support to handle the following new NAE events:
- Register GHCB GPA
- Page State Change Request
- Hypevisor feature
- Guest message request

The RMP check is enforced as soon as SEV-SNP is enabled. Not every memory
access requires an RMP check. In particular, the read accesses from the
hypervisor do not require RMP checks because the data confidentiality is
already protected via memory encryption. When hardware encounters an RMP
checks failure, it raises a page-fault exception. If RMP check failure
is due to the page-size mismatch, then split the large page to resolve
the fault.

The series does not provide support for the following SEV-SNP specific
NAE's yet:

* Extended guest request
* Interrupt security

The series is based on the commit:
a4345a7cecfb (origin/queue, origin/next, next) Merge tag 'kvmarm-fixes-5.13-1'
3bf0fcd75434 (tag: kvm-5.13-1, origin/next, next) KVM: selftests: Speed up set_memory_region_test

Changes since v2:
* Add AP creation support.
* Drop the patch to handle the RMP fault for the kernel address.
* Add functions to track the write access from the hypervisor.
* Do not enable the SNP feature when IOMMU is disabled or is in passthrough mode.
* Dump the RMP entry on RMP violation for the debug.
* Shorten the GHCB macro names.
* Start the SNP_INIT command id from 255 to give some gap for the legacy SEV.
* Sync the header with the latest 0.9 SNP spec.

Changes since v1:
* Add AP reset MSR protocol VMGEXIT NAE.
* Add Hypervisor features VMGEXIT NAE.
* Move the RMP table initialization and RMPUPDATE/PSMASH helper in
arch/x86/kernel/sev.c.
* Add support to map/unmap SEV legacy command buffer to firmware state when
SNP is active.
* Enhance PSP driver to provide helper to allocate/free memory used for the
firmware context page.
* Add support to handle RMP fault for the kernel address.
* Add support to handle GUEST_REQUEST NAE event for attestation.
* Rename RMP table lookup helper.
* Drop typedef from rmpentry struct definition.
* Drop SNP static key and use cpu_feature_enabled() to check whether SEV-SNP
is active.
* Multiple cleanup/fixes to address Boris review feedback.

Brijesh Singh (34):
KVM: SVM: Provide the Hypervisor Feature support VMGEXIT
x86/cpufeatures: Add SEV-SNP CPU feature
x86/sev: Add the host SEV-SNP initialization support
x86/sev: Add RMP entry lookup helpers
x86/sev: Add helper functions for RMPUPDATE and PSMASH instruction
x86/sev: Split the physmap when adding the page in RMP table
x86/traps: Define RMP violation #PF error code
x86/fault: Add support to dump RMP entry on fault
x86/fault: Add support to handle the RMP fault for user address
crypto:ccp: Define the SEV-SNP commands
crypto: ccp: Add support to initialize the AMD-SP for SEV-SNP
crypto: ccp: Shutdown SNP firmware on kexec
crypto:ccp: Provide APIs to issue SEV-SNP commands
crypto: ccp: Handle the legacy TMR allocation when SNP is enabled
crypto: ccp: Handle the legacy SEV command when SNP is enabled
KVM: SVM: make AVIC backing, VMSA and VMCB memory allocation SNP safe
KVM: SVM: Add initial SEV-SNP support
KVM: SVM: Add KVM_SNP_INIT command
KVM: SVM: Add KVM_SEV_SNP_LAUNCH_START command
KVM: SVM: Add KVM_SEV_SNP_LAUNCH_UPDATE command
KVM: SVM: Reclaim the guest pages when SEV-SNP VM terminates
KVM: SVM: Add KVM_SEV_SNP_LAUNCH_FINISH command
KVM: X86: Add kvm_x86_ops to get the max page level for the TDP
KVM: X86: Introduce kvm_mmu_map_tdp_page() for use by SEV
KVM: X86: Introduce kvm_mmu_get_tdp_walk() for SEV-SNP use
KVM: X86: Define new RMP check related #NPF error bits
KVM: X86: update page-fault trace to log the 64-bit error code
KVM: SVM: Add support to handle GHCB GPA register VMGEXIT
KVM: SVM: Add support to handle MSR based Page State Change VMGEXIT
KVM: SVM: Add support to handle Page State Change VMGEXIT
KVM: Add arch hooks to track the host write to guest memory
KVM: X86: Export the kvm_zap_gfn_range() for the SNP use
KVM: SVM: Add support to handle the RMP nested page fault
KVM: SVM: Provide support for SNP_GUEST_REQUEST NAE event

Tom Lendacky (3):
KVM: SVM: Add support to handle AP reset MSR protocol
KVM: SVM: Use a VMSA physical address variable for populating VMCB
KVM: SVM: Support SEV-SNP AP Creation NAE event

arch/x86/include/asm/cpufeatures.h | 1 +
arch/x86/include/asm/disabled-features.h | 8 +-
arch/x86/include/asm/kvm_host.h | 24 +
arch/x86/include/asm/msr-index.h | 6 +
arch/x86/include/asm/sev-common.h | 17 +
arch/x86/include/asm/sev.h | 4 +-
arch/x86/include/asm/svm.h | 8 +
arch/x86/include/asm/trap_pf.h | 18 +-
arch/x86/include/uapi/asm/svm.h | 2 +
arch/x86/kernel/cpu/amd.c | 3 +-
arch/x86/kernel/sev.c | 189 ++++
arch/x86/kvm/lapic.c | 5 +-
arch/x86/kvm/mmu.h | 5 +-
arch/x86/kvm/mmu/mmu.c | 76 +-
arch/x86/kvm/svm/sev.c | 1162 +++++++++++++++++++++-
arch/x86/kvm/svm/svm.c | 37 +-
arch/x86/kvm/svm/svm.h | 39 +-
arch/x86/kvm/trace.h | 6 +-
arch/x86/kvm/vmx/vmx.c | 8 +
arch/x86/kvm/x86.c | 89 +-
arch/x86/mm/fault.c | 148 +++
drivers/crypto/ccp/sev-dev.c | 666 ++++++++++++-
drivers/crypto/ccp/sev-dev.h | 14 +
drivers/crypto/ccp/sp-pci.c | 12 +
include/linux/kvm_host.h | 3 +
include/linux/mm.h | 6 +-
include/linux/psp-sev.h | 323 ++++++
include/linux/sev.h | 76 ++
include/uapi/linux/kvm.h | 43 +
include/uapi/linux/psp-sev.h | 44 +
mm/memory.c | 13 +
tools/arch/x86/include/asm/cpufeatures.h | 1 +
virt/kvm/kvm_main.c | 21 +-
33 files changed, 2992 insertions(+), 85 deletions(-)
create mode 100644 include/linux/sev.h

--
2.17.1