Add AMD Secure Nested Paging (SEV-SNP) Guest Support
Subsystems (8)
v7 cover Add AMD Secure Nested Paging (SEV-SNP) Guest Support
This part of Secure Encrypted Paging (SEV-SNP) series focuses on the changes required in a guest OS for SEV-SNP support.
SEV-SNP builds upon existing SEV and SEV-ES functionality while adding new hardware-based memory protections. SEV-SNP adds strong memory integrity protection to help prevent malicious hypervisor-based attacks like data replay, memory re-mapping and more in order to create an isolated memory encryption environment.
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.
Many of the integrity guarantees of SEV-SNP are enforced through a new structure called the Reverse Map Table (RMP). Adding a new page to SEV-SNP VM requires a 2-step process. First, the hypervisor assigns a page to the guest using the new RMPUPDATE instruction. This transitions the page to guest-invalid. Second, the guest validates the page using the new PVALIDATE instruction. The SEV-SNP VMs can use the new "Page State Change Request NAE" defined in the GHCB specification to ask hypervisor to add or remove page from the RMP table.
Each page assigned to the SEV-SNP VM can either be validated or unvalidated, as indicated by the Validated flag in the page's RMP entry. There are two approaches that can be taken for the page validation: Pre-validation and Lazy Validation.
Under pre-validation, the pages are validated prior to first use. And under lazy validation, pages are validated when first accessed. An access to a unvalidated page results in a #VC exception, at which time the exception handler may validate the page. Lazy validation requires careful tracking of the validated pages to avoid validating the same GPA more than once. The recently introduced "Unaccepted" memory type can be used to communicate the unvalidated memory ranges to the Guest OS.
At this time we only sypport the pre-validation, the OVMF guest BIOS validates the entire RAM before the control is handed over to the guest kernel. The early_set_memory_{encrypt,decrypt} and set_memory_{encrypt,decrypt} are enlightened to perform the page validation or invalidation while setting or clearing the encryption attribute from the page table.
This series does not provide support for the Interrupt security yet which will be added after the base support.
The series is based on tip/master
ea79c24a30aa (origin/master, origin/HEAD, master) Merge branch 'timers/urgent'
Additional resources
---------------------
SEV-SNP whitepaper
https://www.amd.com/system/files/TechDocs/SEV-SNP-strengthening-vm-isolation-with-integrity-protection-and-more.pdf
APM 2: https://www.amd.com/system/files/TechDocs/24593.pdf
(section 15.36)
GHCB spec:
https://developer.amd.com/wp-content/resources/56421.pdf
SEV-SNP firmware specification:
https://developer.amd.com/sev/
v6: https://lore.kernel.org/linux-mm/[email protected]/
v5: https://lore.kernel.org/lkml/[email protected]/
Changes since v6:
* Add rmpadjust() helper to be used by AP creation and vmpl0 detect function.
* Clear the VM communication key if guest detects that hypervisor is modifying the SNP_GUEST_REQ response header.
* Move the per-cpu GHCB registration from first #VC to idt setup.
* Consolidate initial SEV/SME setup into a common entry point that gets called early enough to also be used for SEV-SNP CPUID table setup.
* SNP CPUID: separate initial SEV-SNP feature detection out into standalone snp_init() routines, then add CPUID table setup to it as a separate patch.
* SNP CPUID: fix boot issue with Seabios due to ACPI relying on certain EFI config table lookup failures as fallthrough cases rather than error cases.
* SNP CPUID: drop the use of a separate init routines to handle pointer fixups after switching to kernel virtual addresses, instead use a helper that uses RIP-relative addressing to access CPUID table when either on identity mapping or kernel virtual addresses.
Changes since v5:
* move the seqno allocation in the sevguest driver.
* extend snp_issue_guest_request() to accept the exit_info to simplify the logic.
* use smaller structure names based on feedback.
* explicitly clear the memory after the SNP guest request is completed.
* cpuid validation: use a local copy of cpuid table instead of keeping firmware table mapped throughout boot.
* cpuid validation: coding style fix-ups and refactor cpuid-related helpers as suggested.
* cpuid validation: drop a number of BOOT_COMPRESSED-guarded defs/declarations by moving things like snp_cpuid_init*() out of sev-shared.c and keeping only the common bits there.
* Break up EFI config table helpers and related acpi.c changes into separate patches.
* re-enable stack protection for 32-bit kernels as well, not just 64-bit
Changes since v4:
* Address the cpuid specific review comment
* Simplified the macro based on the review feedback
* Move macro definition to the patch that needs it
* Fix the issues reported by the checkpath
* Address the AP creation specific review comment
Changes since v3:
* Add support to use the PSP filtered CPUID.
* Add support for the extended guest request.
* Move sevguest driver in driver/virt/coco.
* Add documentation for sevguest ioctl.
* Add support to check the vmpl0.
* Pass the VM encryption key and id to be used for encrypting guest messages through the platform drv data.
* Multiple cleanup and fixes to address the review feedbacks.
Changes since v2:
* Add support for AP startup using SNP specific vmgexit.
* Add snp_prep_memory() helper.
* Drop sev_snp_active() helper.
* Add sev_feature_enabled() helper to check which SEV feature is active.
* Sync the SNP guest message request header with latest SNP FW spec.
* Multiple cleanup and fixes to address the review feedbacks.
Changes since v1:
* Integerate the SNP support in sev.{ch}.
* Add support to query the hypervisor feature and detect whether SNP is supported.
* Define Linux specific reason code for the SNP guest termination.
* Extend the setup_header provide a way for hypervisor to pass secret and cpuid page.
* Add support to create a platform device and driver to query the attestation report and the derive a key.
* Multiple cleanup and fixes to address Boris's review fedback.
Borislav Petkov (3):
x86/sev: Get rid of excessive use of defines x86/head64: Carve out the guest encryption postprocessing into a
helper
x86/sev: Remove do_early_exception() forward declarations
Brijesh Singh (22):
x86/mm: Extend cc_attr to include AMD SEV-SNP
x86/sev: Shorten GHCB terminate macro names
x86/sev: Define the Linux specific guest termination reasons x86/sev: Save the negotiated GHCB version
x86/sev: Add support for hypervisor feature VMGEXIT x86/sev: Check SEV-SNP features support
x86/sev: Add a helper for the PVALIDATE instruction x86/sev: Check the vmpl level
x86/compressed: Add helper for validating pages in the decompression
stage
x86/compressed: Register GHCB memory when SEV-SNP is active x86/sev: Register GHCB memory when SEV-SNP is active x86/sev: Add helper for validating pages in early enc attribute
changes
x86/kernel: Make the bss.decrypted section shared in RMP table x86/kernel: Validate rom memory before accessing when SEV-SNP is
active
x86/mm: Add support to validate memory when changing C-bit
KVM: SVM: Define sev_features and vmpl field in the VMSA x86/boot: Add Confidential Computing type to setup_data x86/sev: Provide support for SNP guest request NAEs x86/sev: Register SNP guest request platform device
virt: Add SEV-SNP guest driver
virt: sevguest: Add support to derive key
virt: sevguest: Add support to get extended report
Michael Roth (16):
x86/compressed/64: detect/setup SEV/SME features earlier in boot x86/sev: detect/setup SEV/SME features earlier in boot x86/head: re-enable stack protection for 32/64-bit builds x86/sev: move MSR-based VMGEXITs for CPUID to helper
KVM: x86: move lookup of indexed CPUID leafs to helper x86/compressed/acpi: move EFI system table lookup to helper x86/compressed/acpi: move EFI config table lookup to helper x86/compressed/acpi: move EFI vendor table lookup to helper
KVM: SEV: Add documentation for SEV-SNP CPUID Enforcement x86/compressed/64: add support for SEV-SNP CPUID table in #VC handlers x86/boot: add a pointer to Confidential Computing blob in bootparams x86/compressed: add SEV-SNP feature detection/setup x86/compressed: use firmware-validated CPUID for SEV-SNP guests x86/compressed/64: add identity mapping for Confidential Computing
blob
x86/sev: add SEV-SNP feature detection/setup
x86/sev: use firmware-validated CPUID for SEV-SNP guests
Tom Lendacky (4):
KVM: SVM: Create a separate mapping for the SEV-ES save area
KVM: SVM: Create a separate mapping for the GHCB save area
KVM: SVM: Update the SEV-ES save area mapping x86/sev: Use SEV-SNP AP creation to start secondary CPUs
Documentation/virt/coco/sevguest.rst | 117 +++ .../virt/kvm/amd-memory-encryption.rst | 28 + arch/x86/boot/compressed/Makefile | 1 + arch/x86/boot/compressed/acpi.c | 129 +-- arch/x86/boot/compressed/efi.c | 178 ++++ arch/x86/boot/compressed/head_64.S | 8 +- arch/x86/boot/compressed/ident_map_64.c | 44 +- arch/x86/boot/compressed/mem_encrypt.S | 36 - arch/x86/boot/compressed/misc.h | 44 +- arch/x86/boot/compressed/sev.c | 243 ++++- arch/x86/include/asm/bootparam_utils.h | 1 + arch/x86/include/asm/cpuid.h | 26 + arch/x86/include/asm/msr-index.h | 2 + arch/x86/include/asm/setup.h | 2 +- arch/x86/include/asm/sev-common.h | 137 ++- arch/x86/include/asm/sev.h | 96 +- arch/x86/include/asm/svm.h | 171 +++- arch/x86/include/uapi/asm/bootparam.h | 4 +- arch/x86/include/uapi/asm/svm.h | 13 + arch/x86/kernel/Makefile | 1 - arch/x86/kernel/cc_platform.c | 2 + arch/x86/kernel/cpu/common.c | 5 + arch/x86/kernel/head64.c | 78 +- arch/x86/kernel/head_64.S | 24 + arch/x86/kernel/probe_roms.c | 13 +- arch/x86/kernel/sev-shared.c | 554 +++++++++++- arch/x86/kernel/sev.c | 838 ++++++++++++++++-- arch/x86/kernel/smpboot.c | 3 + arch/x86/kvm/cpuid.c | 17 +- arch/x86/kvm/svm/sev.c | 24 +- arch/x86/kvm/svm/svm.c | 4 +- arch/x86/kvm/svm/svm.h | 2 +- arch/x86/mm/mem_encrypt.c | 55 +- arch/x86/mm/mem_encrypt_identity.c | 8 + arch/x86/mm/pat/set_memory.c | 15 + drivers/virt/Kconfig | 3 + drivers/virt/Makefile | 1 + drivers/virt/coco/sevguest/Kconfig | 9 + drivers/virt/coco/sevguest/Makefile | 2 + drivers/virt/coco/sevguest/sevguest.c | 743 ++++++++++++++++ drivers/virt/coco/sevguest/sevguest.h | 98 ++ include/linux/cc_platform.h | 8 + include/linux/efi.h | 1 + include/uapi/linux/sev-guest.h | 81 ++ 44 files changed, 3524 insertions(+), 345 deletions(-) create mode 100644 Documentation/virt/coco/sevguest.rst create mode 100644 arch/x86/boot/compressed/efi.c create mode 100644 arch/x86/include/asm/cpuid.h create mode 100644 drivers/virt/coco/sevguest/Kconfig create mode 100644 drivers/virt/coco/sevguest/Makefile create mode 100644 drivers/virt/coco/sevguest/sevguest.c create mode 100644 drivers/virt/coco/sevguest/sevguest.h create mode 100644 include/uapi/linux/sev-guest.h
Signature · 1 line
2.25.1
PATCH v7 1/45 x86/compressed/64: detect/setup SEV/SME features earlier in boot
From: Michael Roth <[email protected]>
With upcoming SEV-SNP support, SEV-related features need to be initialized earlier in boot, at the same point the initial #VC handler is set up, so that the SEV-SNP CPUID table can be utilized during the initial feature checks. Also, SEV-SNP feature detection will rely on EFI helper functions to scan the EFI config table for the Confidential Computing blob, and so would need to be implemented at least partially in C.
Currently set_sev_encryption_mask() is used to initialize the sev_status and sme_me_mask globals that advertise what SEV/SME features are available in a guest. Rename it to sev_enable() to better reflect that (SME is only enabled in the case of SEV guests in the boot/compressed kernel), and move it to just after the stage1 #VC handler is set up so that it can be used to initialize SEV-SNP as well in future patches.
While at it, re-implement it as C code so that all SEV feature detection can be better consolidated with upcoming SEV-SNP feature detection, which will also be in C.
The 32-bit entry path remains unchanged, as it never relied on the set_sev_encryption_mask() initialization to begin with, possibly due to the normal rva() helper for accessing globals only being usable by code in .head.text. Either way, 32-bit entry for SEV-SNP would likely only be supported for non-EFI boot paths, and so wouldn't rely on existing EFI helper functions, and so could be handled by a separate/simpler 32-bit initializer in the future if needed.
--- arch/x86/boot/compressed/head_64.S | 8 ++++- arch/x86/boot/compressed/mem_encrypt.S | 36 --------------------- arch/x86/boot/compressed/misc.h | 4 +-- arch/x86/boot/compressed/sev.c | 45 ++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 39 deletions(-)
arch/x86/boot/compressed/head_64.S +7 -1
@@ -447,6 +447,13 @@ SYM_CODE_START(startup_64) call load_stage1_idt popq %rsi +#ifdef CONFIG_AMD_MEM_ENCRYPT + pushq %rsi + movq %rsi, %rdi /* real mode address */ + call sev_enable + popq %rsi +#endif + /* * paging_prepare() sets up the trampoline and checks if we need to * enable 5-level paging.
@@ -569,7 +576,6 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) * page-table. */ pushq %rsi - call set_sev_encryption_mask call load_stage2_idt /* Pass boot_params to initialize_identity_maps() */
arch/x86/boot/compressed/mem_encrypt.S +0 -36
@@ -187,42 +187,6 @@ SYM_CODE_END(startup32_vc_handler) .code64 #include "../../kernel/sev_verify_cbit.S" -SYM_FUNC_START(set_sev_encryption_mask) -#ifdef CONFIG_AMD_MEM_ENCRYPT - push %rbp - push %rdx - - movq %rsp, %rbp /* Save current stack pointer */ - - call get_sev_encryption_bit /* Get the encryption bit position */ - testl %eax, %eax - jz .Lno_sev_mask - - bts %rax, sme_me_mask(%rip) /* Create the encryption mask */ - - /* - * Read MSR_AMD64_SEV again and store it to sev_status. Can't do this in - * get_sev_encryption_bit() because this function is 32-bit code and - * shared between 64-bit and 32-bit boot path. - */ - movl $MSR_AMD64_SEV, %ecx /* Read the SEV MSR */ - rdmsr - - /* Store MSR value in sev_status */ - shlq $32, %rdx - orq %rdx, %rax - movq %rax, sev_status(%rip) - -.Lno_sev_mask: - movq %rbp, %rsp /* Restore original stack pointer */ - - pop %rdx - pop %rbp -#endif - - xor %rax, %rax - ret -SYM_FUNC_END(set_sev_encryption_mask) .data
arch/x86/boot/compressed/misc.h +2 -2
@@ -120,12 +120,12 @@ static inline void console_init(void) { }#endif -void set_sev_encryption_mask (void ); -#ifdef CONFIG_AMD_MEM_ENCRYPT +void sev_enable (struct boot_params *bp);void sev_es_shutdown_ghcb (void );extern bool sev_es_check_ghcb_fault (unsigned long address);#else +static inline void sev_enable (struct boot_params *bp) { }static inline void sev_es_shutdown_ghcb (void ) { }static inline bool sev_es_check_ghcb_fault (unsigned long address) {
arch/x86/boot/compressed/sev.c +45 -0
48 lines not on this page · raw message
Signature · 1 line
2.25.1
Borislav Petkov
maintainerRe: [PATCH v7 01/45] x86/compressed/64: detect/setup SEV/SME features earlier in boot
Quoted 21 lines · Brijesh Singh
arch/x86/boot/compressed/sev.c +21
-0+void sev_enable (struct boot_params *bp) +{ +unsigned int eax, ebx, ecx, edx; + +/* Check for the SME/SEV support leaf */ + eax =0x80000000 ; + ecx =0 ; +native_cpuid (&eax, &ebx, &ecx, &edx); +if (eax <0x8000001f ) +return ; + +/* +* Check for the SME/SEV feature: +* CPUID Fn8000_001F[EAX] +* - Bit 0 - Secure Memory Encryption support +* - Bit 1 - Secure Encrypted Virtualization support +* CPUID Fn8000_001F[EBX] +* - Bits 5:0 - Pagetable bit position used to indicate encryption +*/ + eax =0x8000001f ; + ecx =0 ;
arch/x86/boot/compressed/sev.c void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code) · line 248
Quoted 10 lines
arch/x86/boot/compressed/sev.c +10
-0+native_cpuid (&eax, &ebx, &ecx, &edx); +/* Check whether SEV is supported */ +if (!(eax &BIT (1 ))) +return ; + +/* Check the SEV MSR whether SEV or SME is enabled */ + sev_status =rd_sev_status_msr (); + +if (!(sev_status &MSR_AMD64_SEV_ENABLED )) +error ("SEV support indicated by CPUID, but not SEV status MSR." );
What is the practical purpose of this test?
arch/x86/boot/compressed/sev.c void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code) · line 250
Quoted 1 line
arch/x86/boot/compressed/sev.c +1
-0+ sme_me_mask =1UL << (ebx &0x3f );
sme_me_mask = BIT_ULL(ebx & 0x3f);
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v7 01/45] x86/compressed/64: detect/setup SEV/SME features earlier in boot
Quoted 26 lines · Borislav Petkov
Quoted 25 lines · Brijesh Singh
arch/x86/boot/compressed/sev.c +25
-0+void sev_enable (struct boot_params *bp) +{ +unsigned int eax, ebx, ecx, edx; + +/* Check for the SME/SEV support leaf */ + eax =0x80000000 ; + ecx =0 ; +native_cpuid (&eax, &ebx, &ecx, &edx); +if (eax <0x8000001f ) +return ; + +/* +* Check for the SME/SEV feature: +* CPUID Fn8000_001F[EAX] +* - Bit 0 - Secure Memory Encryption support +* - Bit 1 - Secure Encrypted Virtualization support +* CPUID Fn8000_001F[EBX] +* - Bits 5:0 - Pagetable bit position used to indicate encryption +*/ + eax =0x8000001f ; + ecx =0 ; +native_cpuid (&eax, &ebx, &ecx, &edx); +/* Check whether SEV is supported */ +if (!(eax &BIT (1 ))) +return ;
Quoted 8 lines
arch/x86/boot/compressed/sev.c void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code) · line 248
Quoted 6 lines
arch/x86/boot/compressed/sev.c +6
-0+ +/* Check the SEV MSR whether SEV or SME is enabled */ + sev_status =rd_sev_status_msr (); + +if (!(sev_status &MSR_AMD64_SEV_ENABLED )) +error ("SEV support indicated by CPUID, but not SEV status MSR." );What is the practical purpose of this test?
In the current QEMU/KVM implementation the SEV* CPUID bits are only exposed for SEV guests, so this was more of a sanity check on that. But looking at things more closely: that's more of a VMM-specific behavior and isn't necessarily an invalid guest configuration as far as the spec is concerned, so I think this check should be dropped.
Quoted 4 lines
arch/x86/boot/compressed/sev.c void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code) · line 250
Quoted 2 lines
arch/x86/boot/compressed/sev.c +1
-0+ sme_me_mask =1UL << (ebx &0x3f );sme_me_mask = BIT_ULL(ebx & 0x3f);
Will do.
Thanks,
Mike
Quoted 8 lines
Thx.
Signature · 4 lines
Regards/Gruss, Boris. https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpeople.kernel.org%2Ftglx%2Fnotes-about-netiquette&data=04%7C01%7Cmichael.roth%40amd.com%7Ca6bf3479fffa4b5eee8b08d9a5fce2e2%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637723327924654730%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=SRy8YSe8a2njNc6IT8CGKv0hUefSOW55DJV%2Fi2Lhkic%3D&reserved=0
Re: [PATCH v7 01/45] x86/compressed/64: detect/setup SEV/SME features earlier in boot
Quoted 43 lines · Michael Roth
Quoted 26 lines · Borislav Petkov
Quoted 25 lines · Brijesh Singh
arch/x86/boot/compressed/sev.c +25
-0+void sev_enable (struct boot_params *bp) +{ +unsigned int eax, ebx, ecx, edx; + +/* Check for the SME/SEV support leaf */ + eax =0x80000000 ; + ecx =0 ; +native_cpuid (&eax, &ebx, &ecx, &edx); +if (eax <0x8000001f ) +return ; + +/* +* Check for the SME/SEV feature: +* CPUID Fn8000_001F[EAX] +* - Bit 0 - Secure Memory Encryption support +* - Bit 1 - Secure Encrypted Virtualization support +* CPUID Fn8000_001F[EBX] +* - Bits 5:0 - Pagetable bit position used to indicate encryption +*/ + eax =0x8000001f ; + ecx =0 ; +native_cpuid (&eax, &ebx, &ecx, &edx); +/* Check whether SEV is supported */ +if (!(eax &BIT (1 ))) +return ;Quoted 8 lines
arch/x86/boot/compressed/sev.c void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code) · line 248
Quoted 6 lines
arch/x86/boot/compressed/sev.c +6
-0+ +/* Check the SEV MSR whether SEV or SME is enabled */ + sev_status =rd_sev_status_msr (); + +if (!(sev_status &MSR_AMD64_SEV_ENABLED )) +error ("SEV support indicated by CPUID, but not SEV status MSR." );What is the practical purpose of this test?
In the current QEMU/KVM implementation the SEV* CPUID bits are only exposed for SEV guests, so this was more of a sanity check on that. But looking at things more closely: that's more of a VMM-specific behavior and isn't necessarily an invalid guest configuration as far as the spec is concerned, so I think this check should be dropped.
Quoted 1 line
Quoted 5 lines
Quoted 3 lines
arch/x86/boot/compressed/sev.c void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code) · line 250
Quoted 1 line
arch/x86/boot/compressed/sev.c +1
-0+ sme_me_mask =1UL << (ebx &0x3f );sme_me_mask = BIT_ULL(ebx & 0x3f);Will do.
Also, could you please remove the references to set_sev_encryption_mask() at lines 195 and 572? And perhaps reword those comments too?
Thanks,
Venu
Quoted 12 lines
Thanks,
Mike
Quoted 8 lines
Thx.
Signature · 4 lines
Regards/Gruss, Boris. https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpeople.kernel.org%2Ftglx%2Fnotes-about-netiquette&data=04%7C01%7Cmichael.roth%40amd.com%7Ca6bf3479fffa4b5eee8b08d9a5fce2e2%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637723327924654730%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=SRy8YSe8a2njNc6IT8CGKv0hUefSOW55DJV%2Fi2Lhkic%3D&reserved=0
PATCH v7 2/45 x86/sev: detect/setup SEV/SME features earlier in boot
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
sme_enable() handles feature detection for both SEV and SME. Future patches will also use it for SEV-SNP feature detection/setup, which will need to be done immediately after the first #VC handler is set up. Move it now in preparation.
--- arch/x86/include/asm/setup.h | 2 +- arch/x86/kernel/head64.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
arch/x86/include/asm/setup.h +1 -1
@@ -50,7 +50,7 @@ extern void reserve_standard_io_resources(void);extern void i386_reserve_resources (void );extern unsigned long __startup_64 (unsigned long physaddr,struct boot_params *bp);extern unsigned long __startup_secondary_64 (void ); -extern void startup_64_setup_env (unsigned long physbase); +extern void startup_64_setup_env (unsigned long physbase,struct boot_params *bp);extern void early_setup_idt (void );extern void __init do_early_exception (struct pt_regs *regs,int trapnr);
arch/x86/kernel/head64.c +4 -4
@@ -163,9 +163,6 @@ unsigned long __head __startup_64(unsigned long physaddr,if (load_delta & ~PMD_PAGE_MASK )for (;;); -/* Activate Secure Memory Encryption (SME) if supported and enabled */ -sme_enable (bp); -/* Include the SME encryption mask in the fixup value */ load_delta +=sme_get_me_mask ();
@@ -594,7 +591,7 @@ void early_setup_idt(void)/* * Setup boot CPU state needed before kernel switches to virtual addresses. */ -void __head startup_64_setup_env(unsigned long physbase) +void __head startup_64_setup_env(unsigned long physbase, struct boot_params *bp) {/* Load GDT */ startup_gdt_descr.address = (unsigned long )fixup_pointer (startup_gdt, physbase);
@@ -606,4 +603,7 @@ void __head startup_64_setup_env(unsigned long physbase) "movl %%eax, %%es\n" : : "a"(__KERNEL_DS) : "memory"); startup_64_load_idt(physbase); + +/* Activate SEV/SME memory encryption if supported/enabled. */ +sme_enable (bp); }
Signature · 1 line
2.25.1
Borislav Petkov
maintainerRe: [PATCH v7 02/45] x86/sev: detect/setup SEV/SME features earlier in boot
Quoted 6 lines · Brijesh Singh
From: Michael Roth <[email protected]>
sme_enable()handles feature detection for both SEV and SME. Future patches will also use it for SEV-SNP feature detection/setup, which will need to be done immediately after the first #VC handler is set up. Move it now in preparation.
I don't mind the move - what I miss is the reason why you're moving it up.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v7 02/45] x86/sev: detect/setup SEV/SME features earlier in boot
Quoted 10 lines · Borislav Petkov
Quoted 6 lines · Brijesh Singh
From: Michael Roth <[email protected]>
sme_enable()handles feature detection for both SEV and SME. Future patches will also use it for SEV-SNP feature detection/setup, which will need to be done immediately after the first #VC handler is set up. Move it now in preparation.I don't mind the move - what I miss is the reason why you're moving it up.
The early #VC handlers are needed mainly so that early cpuid instructions can be handled for SEV-ES. In the case of SNP, the cpuid table needs to be set up at the same time so those #VC handlers can handle cpuid lookups for SEV-SNP guests. Previously in v6, that CPUID table setup was done with a separate routine, snp_cpuid_init(), which was awkward because between the point snp_cpuid_init() was called, and sme_enable() was called, we were in an in-between state where some SEV-ES/SEV-SNP features were in use, but they weren't actually sanity-checked against SEV status MSR and CPUID bits until later in sme_enable(). I tried adding some of those checks from sme_enable() into snp_cpuid_init(), but you'd suggested instead moving the CPUID table setup into sme_enable() to avoid the duplication:
https://lore.kernel.org/linux-mm/[email protected]/
but in order for that to happen soon enough to make use of the CPUID table for all CPUID intructions, it needs to be moved to just after the first #VC handler is setup (where snp_cpuid_init() used to be in v6).
As for why CPUID table needs to be used for all CPUID, it's mainly so that the CPUID values used throughout boot can be attested to later if the guest owner validates the CPUID values in the CPUID page. I added some documentation for why this is the case in:
[PATCH 33/45] KVM: SEV: Add documentation for SEV-SNP CPUID Enforcement
Quoted 8 lines
Thx.
Signature · 4 lines
Regards/Gruss, Boris. https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpeople.kernel.org%2Ftglx%2Fnotes-about-netiquette&data=04%7C01%7Cmichael.roth%40amd.com%7C29ab37203c1a4c796bdc08d9a86bd7a4%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637726003477466910%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=xxIMC4PM7kJ2O79gQKK7I%2BhnOsuEbckVPA9Gicz0S9w%3D&reserved=0
Borislav Petkov
maintainerRe: [PATCH v7 02/45] x86/sev: detect/setup SEV/SME features earlier in boot
Quoted 3 lines · Michael Roth
but in order for that to happen soon enough to make use of the CPUID table for all CPUID intructions, it needs to be moved to just after the first #VC handler is setup (where
snp_cpuid_init()used to be in v6).
So, it needs to happen after the initial IDT is loaded on the BSP in startup_64_setup_env().
So why don't you call sme_enable() right after the startup_64_setup_env() call and add a comment above it to explain why this call needs to happen there?
Instead of sticking that call in startup_64_setup_env() where it doesn't belong conceptually - enabling SME doesn't really have anything to do with setting up early environment...
Hmm.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v7 02/45] x86/sev: detect/setup SEV/SME features earlier in boot
In reply to Brijesh SinghQuoted 6 lines · Brijesh Singh
From: Michael Roth <[email protected]>
sme_enable()handles feature detection for both SEV and SME. Future patches will also use it for SEV-SNP feature detection/setup, which will need to be done immediately after the first #VC handler is set up. Move it now in preparation.
The previous patch added the function sev_enable(), which has most of its code duplicated in sme_enable(). Can sme_enable() be changed (and maybe sev_enable() a bit) to call sev_enable() and avoid all the duplicate code?
Venu
Quoted 55 lines
Signed-off-by Michael Roth <[email protected]>Signed-off-by Brijesh Singh <[email protected]>--- arch/x86/include/asm/setup.h | 2 +- arch/x86/kernel/head64.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)arch/x86/include/asm/setup.h +1
-1@@ -50,7 +50,7 @@ extern void reserve_standard_io_resources(void);extern void i386_reserve_resources (void );extern unsigned long __startup_64 (unsigned long physaddr,struct boot_params *bp);extern unsigned long __startup_secondary_64 (void ); -extern void startup_64_setup_env (unsigned long physbase); +extern void startup_64_setup_env (unsigned long physbase,struct boot_params *bp);extern void early_setup_idt (void );extern void __init do_early_exception (struct pt_regs *regs,int trapnr);arch/x86/kernel/head64.c +4
-4@@ -163,9 +163,6 @@ unsigned long __head __startup_64(unsigned long physaddr,if (load_delta & ~PMD_PAGE_MASK )for (;;); -/* Activate Secure Memory Encryption (SME) if supported and enabled */ -sme_enable (bp); -/* Include the SME encryption mask in the fixup value */ load_delta +=sme_get_me_mask ();@@ -594,7 +591,7 @@ void early_setup_idt(void)/* * Setup boot CPU state needed before kernel switches to virtual addresses. */ -void __head startup_64_setup_env(unsigned long physbase) +void __head startup_64_setup_env(unsigned long physbase, struct boot_params *bp) {/* Load GDT */ startup_gdt_descr.address = (unsigned long )fixup_pointer (startup_gdt, physbase);@@ -606,4 +603,7 @@ void __head startup_64_setup_env(unsigned long physbase) "movl %%eax, %%es\n" : : "a"(__KERNEL_DS) : "memory"); startup_64_load_idt(physbase); + +/* Activate SEV/SME memory encryption if supported/enabled. */ +sme_enable (bp); }Signature · 1 line
2.25.1
PATCH v7 3/45 x86/mm: Extend cc_attr to include AMD SEV-SNP
In reply to Brijesh SinghThe CC_ATTR_SEV_SNP can be used by the guest to query whether the SNP - Secure Nested Paging feature is active.
--- arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/kernel/cc_platform.c | 2 ++ arch/x86/mm/mem_encrypt.c | 4 ++++ include/linux/cc_platform.h | 8 ++++++++ 4 files changed, 16 insertions(+)
arch/x86/include/asm/msr-index.h +2 -0
@@ -481,8 +481,10 @@#define MSR_AMD64_SEV 0xc0010131#define MSR_AMD64_SEV_ENABLED_BIT 0#define MSR_AMD64_SEV_ES_ENABLED_BIT 1 +#define MSR_AMD64_SEV_SNP_ENABLED_BIT 2#define MSR_AMD64_SEV_ENABLED BIT_ULL(MSR_AMD64_SEV_ENABLED_BIT)#define MSR_AMD64_SEV_ES_ENABLED BIT_ULL(MSR_AMD64_SEV_ES_ENABLED_BIT) +#define MSR_AMD64_SEV_SNP_ENABLED BIT_ULL(MSR_AMD64_SEV_SNP_ENABLED_BIT)#define MSR_AMD64_VIRT_SPEC_CTRL 0xc001011f
arch/x86/kernel/cc_platform.c +2 -0
@@ -50,6 +50,8 @@ static bool amd_cc_platform_has(enum cc_attr attr)case CC_ATTR_GUEST_STATE_ENCRYPT :return sev_status &MSR_AMD64_SEV_ES_ENABLED ; +case CC_ATTR_SEV_SNP : +return sev_status &MSR_AMD64_SEV_SNP_ENABLED ;default :return false; }
arch/x86/mm/mem_encrypt.c +4 -0
@@ -433,6 +433,10 @@ static void print_mem_encrypt_feature_info(void)if (cc_platform_has (CC_ATTR_GUEST_STATE_ENCRYPT ))pr_cont (" SEV-ES" ); +/* Secure Nested Paging */ +if (cc_platform_has (CC_ATTR_SEV_SNP )) +pr_cont (" SEV-SNP" ); +pr_cont ("\n" ); }
include/linux/cc_platform.h +8 -0
@@ -61,6 +61,14 @@ enum cc_attr {* Examples include SEV-ES. */ CC_ATTR_GUEST_STATE_ENCRYPT , + +/** +* @CC_ATTR_SEV_SNP: Guest SNP is active. +* +* The platform/OS is running as a guest/virtual machine and actively +* using AMD SEV-SNP features. +*/ + CC_ATTR_SEV_SNP = 0x100, };#ifdef CONFIG_ARCH_HAS_CC_PLATFORM
Signature · 1 line
2.25.1
PATCH v7 4/45 x86/sev: Shorten GHCB terminate macro names
In reply to Brijesh SinghShorten macro names for improved readability.
--- arch/x86/boot/compressed/sev.c | 6 +++--- arch/x86/include/asm/sev-common.h | 4 ++-- arch/x86/kernel/sev-shared.c | 2 +- arch/x86/kernel/sev.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)
arch/x86/boot/compressed/sev.c +3 -3
@@ -122,7 +122,7 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,static bool early_setup_sev_es (void ) {if (!sev_es_negotiate_protocol ()) -sev_es_terminate (GHCB_SEV_ES_REASON_PROTOCOL_UNSUPPORTED ); +sev_es_terminate (GHCB_SEV_ES_PROT_UNSUPPORTED );if (set_page_decrypted ((unsigned long )&boot_ghcb_page))return false;
@@ -175,7 +175,7 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)enum es_result result;if (!boot_ghcb && !early_setup_sev_es ()) -sev_es_terminate (GHCB_SEV_ES_REASON_GENERAL_REQUEST ); +sev_es_terminate (GHCB_SEV_ES_GEN_REQ );vc_ghcb_invalidate (boot_ghcb); result =vc_init_em_ctxt (&ctxt, regs, exit_code);
@@ -202,7 +202,7 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)if (result ==ES_OK )vc_finish_insn (&ctxt);else if (result !=ES_RETRY ) -sev_es_terminate (GHCB_SEV_ES_REASON_GENERAL_REQUEST ); +sev_es_terminate (GHCB_SEV_ES_GEN_REQ ); }static inline u64 rd_sev_status_msr (void )
arch/x86/include/asm/sev-common.h +2 -2
@@ -68,8 +68,8 @@ (((((u64 )reason_set) &GHCB_MSR_TERM_REASON_SET_MASK ) <<GHCB_MSR_TERM_REASON_SET_POS ) | \ ((((u64)reason_val) & GHCB_MSR_TERM_REASON_MASK) << GHCB_MSR_TERM_REASON_POS)) -#define GHCB_SEV_ES_REASON_GENERAL_REQUEST 0 -#define GHCB_SEV_ES_REASON_PROTOCOL_UNSUPPORTED 1 +#define GHCB_SEV_ES_GEN_REQ 0 +#define GHCB_SEV_ES_PROT_UNSUPPORTED 1#define GHCB_RESP_CODE (v) ((v) & GHCB_MSR_INFO_MASK)
arch/x86/kernel/sev-shared.c +1 -1
@@ -221,7 +221,7 @@ void __init do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code) fail:/* Terminate the guest */ -sev_es_terminate (GHCB_SEV_ES_REASON_GENERAL_REQUEST ); +sev_es_terminate (GHCB_SEV_ES_GEN_REQ ); } static enum es_result vc_insn_string_read(struct es_em_ctxt *ctxt,
arch/x86/kernel/sev.c +2 -2
@@ -1411,7 +1411,7 @@ DEFINE_IDTENTRY_VC_KERNEL(exc_vmm_communication)show_regs (regs);/* Ask hypervisor to sev_es_terminate */ -sev_es_terminate (GHCB_SEV_ES_REASON_GENERAL_REQUEST ); +sev_es_terminate (GHCB_SEV_ES_GEN_REQ );/* If that fails and we get here - just panic */ panic ("Returned from Terminate-Request to Hypervisor\n" );
@@ -1459,7 +1459,7 @@ bool __init handle_vc_boot_ghcb(struct pt_regs *regs)/* Do initial setup or terminate the guest */ if (unlikely (boot_ghcb ==NULL && !sev_es_setup_ghcb ())) -sev_es_terminate (GHCB_SEV_ES_REASON_GENERAL_REQUEST ); +sev_es_terminate (GHCB_SEV_ES_GEN_REQ );vc_ghcb_invalidate (boot_ghcb);
Signature · 1 line
2.25.1
[tip: x86/sev] x86/sev: Shorten GHCB terminate macro names
The following commit has been merged into the x86/sev branch of tip:
The following commit has been merged into the x86/sev branch of tip:
Commit-ID: 18c3933c1983157df9dc06d4f3bfc764f161ed7a Gitweb: https://git.kernel.org/tip/18c3933c1983157df9dc06d4f3bfc764f161ed7a Author: Brijesh Singh <[email protected]> AuthorDate: Wed, 10 Nov 2021 16:06:50 -06:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 15 Nov 2021 20:31:16 +01:00
x86/sev: Shorten GHCB terminate macro names
Shorten macro names for improved readability.
--- arch/x86/boot/compressed/sev.c | 6 +++--- arch/x86/include/asm/sev-common.h | 4 ++-- arch/x86/kernel/sev-shared.c | 2 +- arch/x86/kernel/sev.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)
arch/x86/boot/compressed/sev.c +3 -3
@@ -122,7 +122,7 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,static bool early_setup_sev_es (void ) {if (!sev_es_negotiate_protocol ()) -sev_es_terminate (GHCB_SEV_ES_REASON_PROTOCOL_UNSUPPORTED ); +sev_es_terminate (GHCB_SEV_ES_PROT_UNSUPPORTED );if (set_page_decrypted ((unsigned long )&boot_ghcb_page))return false;
@@ -175,7 +175,7 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)enum es_result result;if (!boot_ghcb && !early_setup_sev_es ()) -sev_es_terminate (GHCB_SEV_ES_REASON_GENERAL_REQUEST ); +sev_es_terminate (GHCB_SEV_ES_GEN_REQ );vc_ghcb_invalidate (boot_ghcb); result =vc_init_em_ctxt (&ctxt, regs, exit_code);
@@ -202,5 +202,5 @@ finish:if (result ==ES_OK )vc_finish_insn (&ctxt);else if (result !=ES_RETRY ) -sev_es_terminate (GHCB_SEV_ES_REASON_GENERAL_REQUEST ); +sev_es_terminate (GHCB_SEV_ES_GEN_REQ ); }
arch/x86/include/asm/sev-common.h +2 -2
@@ -68,8 +68,8 @@ (((((u64 )reason_set) &GHCB_MSR_TERM_REASON_SET_MASK ) <<GHCB_MSR_TERM_REASON_SET_POS ) | \ ((((u64)reason_val) & GHCB_MSR_TERM_REASON_MASK) << GHCB_MSR_TERM_REASON_POS)) -#define GHCB_SEV_ES_REASON_GENERAL_REQUEST 0 -#define GHCB_SEV_ES_REASON_PROTOCOL_UNSUPPORTED 1 +#define GHCB_SEV_ES_GEN_REQ 0 +#define GHCB_SEV_ES_PROT_UNSUPPORTED 1#define GHCB_RESP_CODE (v) ((v) & GHCB_MSR_INFO_MASK)
arch/x86/kernel/sev-shared.c +1 -1
@@ -221,7 +221,7 @@ void __init do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code) fail:/* Terminate the guest */ -sev_es_terminate (GHCB_SEV_ES_REASON_GENERAL_REQUEST ); +sev_es_terminate (GHCB_SEV_ES_GEN_REQ ); } static enum es_result vc_insn_string_read(struct es_em_ctxt *ctxt,
arch/x86/kernel/sev.c +2 -2
@@ -1411,7 +1411,7 @@ DEFINE_IDTENTRY_VC_KERNEL(exc_vmm_communication)show_regs (regs);/* Ask hypervisor to sev_es_terminate */ -sev_es_terminate (GHCB_SEV_ES_REASON_GENERAL_REQUEST ); +sev_es_terminate (GHCB_SEV_ES_GEN_REQ );/* If that fails and we get here - just panic */ panic ("Returned from Terminate-Request to Hypervisor\n" );
@@ -1459,7 +1459,7 @@ bool __init handle_vc_boot_ghcb(struct pt_regs *regs)/* Do initial setup or terminate the guest */ if (unlikely (boot_ghcb ==NULL && !sev_es_setup_ghcb ())) -sev_es_terminate (GHCB_SEV_ES_REASON_GENERAL_REQUEST ); +sev_es_terminate (GHCB_SEV_ES_GEN_REQ );vc_ghcb_invalidate (boot_ghcb);
PATCH v7 5/45 x86/sev: Get rid of excessive use of defines
In reply to Brijesh SinghFrom: Borislav Petkov <[email protected]>
Remove all the defines of masks and bit positions for the GHCB MSR protocol and use comments instead which correspond directly to the spec so that following those can be a lot easier and straightforward with the spec opened in parallel to the code.
Aligh vertically while at it.
No functional changes.
--- arch/x86/include/asm/sev-common.h | 51 +++++++++++++++++-------------- 1 file changed, 28 insertions(+), 23 deletions(-)
arch/x86/include/asm/sev-common.h +28 -23
@@ -18,20 +18,19 @@/* SEV Information Request/Response */ #define GHCB_MSR_SEV_INFO_RESP 0x001#define GHCB_MSR_SEV_INFO_REQ 0x002 -#define GHCB_MSR_VER_MAX_POS 48 -#define GHCB_MSR_VER_MAX_MASK 0xffff -#define GHCB_MSR_VER_MIN_POS 32 -#define GHCB_MSR_VER_MIN_MASK 0xffff -#define GHCB_MSR_CBIT_POS 24 -#define GHCB_MSR_CBIT_MASK 0xff -#define GHCB_MSR_SEV_INFO (_max, _min, _cbit) \ - ((((_max) & GHCB_MSR_VER_MAX_MASK) << GHCB_MSR_VER_MAX_POS) | \ - (((_min) & GHCB_MSR_VER_MIN_MASK) << GHCB_MSR_VER_MIN_POS) | \ - (((_cbit) & GHCB_MSR_CBIT_MASK) << GHCB_MSR_CBIT_POS) | \ + +#define GHCB_MSR_SEV_INFO (_max, _min, _cbit) \ +/* GHCBData[63:48] */ \ + ((((_max) & 0xffff) << 48) | \ +/* GHCBData[47:32] */ \ + (((_min) & 0xffff) << 32) | \ + /* GHCBData[31:24] */ \ + (((_cbit) & 0xff) << 24) | \ GHCB_MSR_SEV_INFO_RESP) +#define GHCB_MSR_INFO (v) ((v) & 0xfffUL) -#define GHCB_MSR_PROTO_MAX (v) (((v) >> GHCB_MSR_VER_MAX_POS) & GHCB_MSR_VER_MAX_MASK) -#define GHCB_MSR_PROTO_MIN (v) (((v) >> GHCB_MSR_VER_MIN_POS) & GHCB_MSR_VER_MIN_MASK) +#define GHCB_MSR_PROTO_MAX (v) (((v) >> 48) & 0xffff) +#define GHCB_MSR_PROTO_MIN (v) (((v) >> 32) & 0xffff)/* CPUID Request/Response */ #define GHCB_MSR_CPUID_REQ 0x004
@@ -46,27 +45,33 @@#define GHCB_CPUID_REQ_EBX 1#define GHCB_CPUID_REQ_ECX 2#define GHCB_CPUID_REQ_EDX 3 -#define GHCB_CPUID_REQ (fn, reg) \ - (GHCB_MSR_CPUID_REQ | \ - (((unsigned long)reg & GHCB_MSR_CPUID_REG_MASK) << GHCB_MSR_CPUID_REG_POS) | \ - (((unsigned long)fn) << GHCB_MSR_CPUID_FUNC_POS)) +#define GHCB_CPUID_REQ (fn, reg) \ +/* GHCBData[11:0] */ \ + (GHCB_MSR_CPUID_REQ | \ +/* GHCBData[31:12] */ \ + (((unsigned long)(reg) & 0x3) << 30) | \ + /* GHCBData[63:32] */ \ + (((unsigned long)fn) << 32))/* AP Reset Hold */ -#define GHCB_MSR_AP_RESET_HOLD_REQ 0x006 -#define GHCB_MSR_AP_RESET_HOLD_RESP 0x007 +#define GHCB_MSR_AP_RESET_HOLD_REQ 0x006 +#define GHCB_MSR_AP_RESET_HOLD_RESP 0x007/* GHCB Hypervisor Feature Request/Response */ -#define GHCB_MSR_HV_FT_REQ 0x080 -#define GHCB_MSR_HV_FT_RESP 0x081 +#define GHCB_MSR_HV_FT_REQ 0x080 +#define GHCB_MSR_HV_FT_RESP 0x081#define GHCB_MSR_TERM_REQ 0x100#define GHCB_MSR_TERM_REASON_SET_POS 12#define GHCB_MSR_TERM_REASON_SET_MASK 0xf#define GHCB_MSR_TERM_REASON_POS 16#define GHCB_MSR_TERM_REASON_MASK 0xff -#define GHCB_SEV_TERM_REASON (reason_set, reason_val) \ - (((((u64)reason_set) & GHCB_MSR_TERM_REASON_SET_MASK) << GHCB_MSR_TERM_REASON_SET_POS) | \ - ((((u64)reason_val) & GHCB_MSR_TERM_REASON_MASK) << GHCB_MSR_TERM_REASON_POS)) + +#define GHCB_SEV_TERM_REASON (reason_set, reason_val) \ +/* GHCBData[15:12] */ \ + (((((u64)reason_set) & 0xf) << 12) | \ +/* GHCBData[23:16] */ \ + ((((u64)reason_val) & 0xff) << 16))#define GHCB_SEV_ES_GEN_REQ 0#define GHCB_SEV_ES_PROT_UNSUPPORTED 1
Signature · 1 line
2.25.1
[tip: x86/sev] x86/sev: Get rid of excessive use of defines
The following commit has been merged into the x86/sev branch of tip:
The following commit has been merged into the x86/sev branch of tip:
Commit-ID: dbc4c70e3cdfe204a67dd66bed78709ee3000ec0 Gitweb: https://git.kernel.org/tip/dbc4c70e3cdfe204a67dd66bed78709ee3000ec0 Author: Borislav Petkov <[email protected]> AuthorDate: Wed, 10 Nov 2021 16:06:51 -06:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 15 Nov 2021 20:53:40 +01:00
x86/sev: Get rid of excessive use of defines
Remove all the defines of masks and bit positions for the GHCB MSR protocol and use comments instead which correspond directly to the spec so that following those can be a lot easier and straightforward with the spec opened in parallel to the code.
Aligh vertically while at it.
No functional changes.
--- arch/x86/include/asm/sev-common.h | 51 ++++++++++++++++-------------- 1 file changed, 28 insertions(+), 23 deletions(-)
arch/x86/include/asm/sev-common.h +28 -23
@@ -18,20 +18,19 @@/* SEV Information Request/Response */ #define GHCB_MSR_SEV_INFO_RESP 0x001#define GHCB_MSR_SEV_INFO_REQ 0x002 -#define GHCB_MSR_VER_MAX_POS 48 -#define GHCB_MSR_VER_MAX_MASK 0xffff -#define GHCB_MSR_VER_MIN_POS 32 -#define GHCB_MSR_VER_MIN_MASK 0xffff -#define GHCB_MSR_CBIT_POS 24 -#define GHCB_MSR_CBIT_MASK 0xff -#define GHCB_MSR_SEV_INFO (_max, _min, _cbit) \ - ((((_max) & GHCB_MSR_VER_MAX_MASK) << GHCB_MSR_VER_MAX_POS) | \ - (((_min) & GHCB_MSR_VER_MIN_MASK) << GHCB_MSR_VER_MIN_POS) | \ - (((_cbit) & GHCB_MSR_CBIT_MASK) << GHCB_MSR_CBIT_POS) | \ + +#define GHCB_MSR_SEV_INFO (_max, _min, _cbit) \ +/* GHCBData[63:48] */ \ + ((((_max) & 0xffff) << 48) | \ +/* GHCBData[47:32] */ \ + (((_min) & 0xffff) << 32) | \ + /* GHCBData[31:24] */ \ + (((_cbit) & 0xff) << 24) | \ GHCB_MSR_SEV_INFO_RESP) +#define GHCB_MSR_INFO (v) ((v) & 0xfffUL) -#define GHCB_MSR_PROTO_MAX (v) (((v) >> GHCB_MSR_VER_MAX_POS) & GHCB_MSR_VER_MAX_MASK) -#define GHCB_MSR_PROTO_MIN (v) (((v) >> GHCB_MSR_VER_MIN_POS) & GHCB_MSR_VER_MIN_MASK) +#define GHCB_MSR_PROTO_MAX (v) (((v) >> 48) & 0xffff) +#define GHCB_MSR_PROTO_MIN (v) (((v) >> 32) & 0xffff)/* CPUID Request/Response */ #define GHCB_MSR_CPUID_REQ 0x004
@@ -46,27 +45,33 @@#define GHCB_CPUID_REQ_EBX 1#define GHCB_CPUID_REQ_ECX 2#define GHCB_CPUID_REQ_EDX 3 -#define GHCB_CPUID_REQ (fn, reg) \ - (GHCB_MSR_CPUID_REQ | \ - (((unsigned long)reg & GHCB_MSR_CPUID_REG_MASK) << GHCB_MSR_CPUID_REG_POS) | \ - (((unsigned long)fn) << GHCB_MSR_CPUID_FUNC_POS)) +#define GHCB_CPUID_REQ (fn, reg) \ +/* GHCBData[11:0] */ \ + (GHCB_MSR_CPUID_REQ | \ +/* GHCBData[31:12] */ \ + (((unsigned long)(reg) & 0x3) << 30) | \ + /* GHCBData[63:32] */ \ + (((unsigned long)fn) << 32))/* AP Reset Hold */ -#define GHCB_MSR_AP_RESET_HOLD_REQ 0x006 -#define GHCB_MSR_AP_RESET_HOLD_RESP 0x007 +#define GHCB_MSR_AP_RESET_HOLD_REQ 0x006 +#define GHCB_MSR_AP_RESET_HOLD_RESP 0x007/* GHCB Hypervisor Feature Request/Response */ -#define GHCB_MSR_HV_FT_REQ 0x080 -#define GHCB_MSR_HV_FT_RESP 0x081 +#define GHCB_MSR_HV_FT_REQ 0x080 +#define GHCB_MSR_HV_FT_RESP 0x081#define GHCB_MSR_TERM_REQ 0x100#define GHCB_MSR_TERM_REASON_SET_POS 12#define GHCB_MSR_TERM_REASON_SET_MASK 0xf#define GHCB_MSR_TERM_REASON_POS 16#define GHCB_MSR_TERM_REASON_MASK 0xff -#define GHCB_SEV_TERM_REASON (reason_set, reason_val) \ - (((((u64)reason_set) & GHCB_MSR_TERM_REASON_SET_MASK) << GHCB_MSR_TERM_REASON_SET_POS) | \ - ((((u64)reason_val) & GHCB_MSR_TERM_REASON_MASK) << GHCB_MSR_TERM_REASON_POS)) + +#define GHCB_SEV_TERM_REASON (reason_set, reason_val) \ +/* GHCBData[15:12] */ \ + (((((u64)reason_set) & 0xf) << 12) | \ +/* GHCBData[23:16] */ \ + ((((u64)reason_val) & 0xff) << 16))#define GHCB_SEV_ES_GEN_REQ 0#define GHCB_SEV_ES_PROT_UNSUPPORTED 1
PATCH v7 6/45 x86/head64: Carve out the guest encryption postprocessing into a helper
In reply to Brijesh SinghFrom: Borislav Petkov <[email protected]>
Carve it out so that it is abstracted out of the main boot path. All other encrypted guest-relevant processing should be placed in there.
No functional changes.
--- arch/x86/kernel/head64.c | 60 +++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 29 deletions(-)
arch/x86/kernel/head64.c +31 -29
@@ -126,6 +126,36 @@ static bool __head check_la57_support(unsigned long physaddr) }#endif +static unsigned long sme_postprocess_startup (struct boot_params *bp,pmdval_t *pmd) +{ +unsigned long vaddr, vaddr_end; +int i; + +/* Encrypt the kernel and related (if SME is active) */ +sme_encrypt_kernel (bp); + +/* +* Clear the memory encryption mask from the .bss..decrypted section. +* The bss section will be memset to zero later in the initialization so +* there is no need to zero it after changing the memory encryption +* attribute. +*/ +if (sme_get_me_mask ()) { + vaddr = (unsigned long )__start_bss_decrypted; + vaddr_end = (unsigned long )__end_bss_decrypted; +for (; vaddr < vaddr_end; vaddr +=PMD_SIZE ) { + i =pmd_index (vaddr); + pmd[i] -=sme_get_me_mask (); + } + } + +/* +* Return the SME encryption mask (if SME is active) to be used as a +* modifier for the initial pgdir entry programmed into CR3. +*/ +return sme_get_me_mask (); +} +/* Code in __startup_64() can be relocated during execution, but the compiler * doesn't have to generate PC-relative relocations when accessing globals from * that function. Clang actually does not generate them, which leads to
@@ -135,7 +165,6 @@ static bool __head check_la57_support(unsigned long physaddr)unsigned long __head __startup_64 (unsigned long physaddr,struct boot_params *bp) { -unsigned long vaddr, vaddr_end;unsigned long load_delta, *p;unsigned long pgtable_flags;pgdval_t *pgd;
@@ -273,34 +302,7 @@ unsigned long __head __startup_64(unsigned long physaddr,*/ *fixup_long (&phys_base, physaddr) += load_delta -sme_get_me_mask (); -/* Encrypt the kernel and related (if SME is active) */ -sme_encrypt_kernel (bp); - -/* -* Clear the memory encryption mask from the .bss..decrypted section. -* The bss section will be memset to zero later in the initialization so -* there is no need to zero it after changing the memory encryption -* attribute. -* -* This is early code, use an open coded check for SME instead of -* using cc_platform_has(). This eliminates worries about removing -* instrumentation or checking boot_cpu_data in the cc_platform_has() -* function. -*/ -if (sme_get_me_mask ()) { - vaddr = (unsigned long )__start_bss_decrypted; - vaddr_end = (unsigned long )__end_bss_decrypted; -for (; vaddr < vaddr_end; vaddr +=PMD_SIZE ) { - i =pmd_index (vaddr); - pmd[i] -=sme_get_me_mask (); - } - } - -/* -* Return the SME encryption mask (if SME is active) to be used as a -* modifier for the initial pgdir entry programmed into CR3. -*/ -return sme_get_me_mask (); +return sme_postprocess_startup (bp, pmd); }unsigned long __startup_secondary_64 (void )
Signature · 1 line
2.25.1
[tip: x86/sev] x86/head64: Carve out the guest encryption postprocessing into a helper
The following commit has been merged into the x86/sev branch of tip:
The following commit has been merged into the x86/sev branch of tip:
Commit-ID: 5ed0a99b12aa2dd09afe7ba485145529b89f26e6 Gitweb: https://git.kernel.org/tip/5ed0a99b12aa2dd09afe7ba485145529b89f26e6 Author: Borislav Petkov <[email protected]> AuthorDate: Wed, 10 Nov 2021 16:06:52 -06:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 15 Nov 2021 21:05:14 +01:00
x86/head64: Carve out the guest encryption postprocessing into a helper
Carve it out so that it is abstracted out of the main boot path. All other encrypted guest-relevant processing should be placed in there.
No functional changes.
--- arch/x86/kernel/head64.c | 60 ++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 29 deletions(-)
arch/x86/kernel/head64.c +31 -29
@@ -126,6 +126,36 @@ static bool __head check_la57_support(unsigned long physaddr) }#endif +static unsigned long sme_postprocess_startup (struct boot_params *bp,pmdval_t *pmd) +{ +unsigned long vaddr, vaddr_end; +int i; + +/* Encrypt the kernel and related (if SME is active) */ +sme_encrypt_kernel (bp); + +/* +* Clear the memory encryption mask from the .bss..decrypted section. +* The bss section will be memset to zero later in the initialization so +* there is no need to zero it after changing the memory encryption +* attribute. +*/ +if (sme_get_me_mask ()) { + vaddr = (unsigned long )__start_bss_decrypted; + vaddr_end = (unsigned long )__end_bss_decrypted; +for (; vaddr < vaddr_end; vaddr +=PMD_SIZE ) { + i =pmd_index (vaddr); + pmd[i] -=sme_get_me_mask (); + } + } + +/* +* Return the SME encryption mask (if SME is active) to be used as a +* modifier for the initial pgdir entry programmed into CR3. +*/ +return sme_get_me_mask (); +} +/* Code in __startup_64() can be relocated during execution, but the compiler * doesn't have to generate PC-relative relocations when accessing globals from * that function. Clang actually does not generate them, which leads to
@@ -135,7 +165,6 @@ static bool __head check_la57_support(unsigned long physaddr)unsigned long __head __startup_64 (unsigned long physaddr,struct boot_params *bp) { -unsigned long vaddr, vaddr_end;unsigned long load_delta, *p;unsigned long pgtable_flags;pgdval_t *pgd;
@@ -276,34 +305,7 @@ unsigned long __head __startup_64(unsigned long physaddr,*/ *fixup_long (&phys_base, physaddr) += load_delta -sme_get_me_mask (); -/* Encrypt the kernel and related (if SME is active) */ -sme_encrypt_kernel (bp); - -/* -* Clear the memory encryption mask from the .bss..decrypted section. -* The bss section will be memset to zero later in the initialization so -* there is no need to zero it after changing the memory encryption -* attribute. -* -* This is early code, use an open coded check for SME instead of -* using cc_platform_has(). This eliminates worries about removing -* instrumentation or checking boot_cpu_data in the cc_platform_has() -* function. -*/ -if (sme_get_me_mask ()) { - vaddr = (unsigned long )__start_bss_decrypted; - vaddr_end = (unsigned long )__end_bss_decrypted; -for (; vaddr < vaddr_end; vaddr +=PMD_SIZE ) { - i =pmd_index (vaddr); - pmd[i] -=sme_get_me_mask (); - } - } - -/* -* Return the SME encryption mask (if SME is active) to be used as a -* modifier for the initial pgdir entry programmed into CR3. -*/ -return sme_get_me_mask (); +return sme_postprocess_startup (bp, pmd); }unsigned long __startup_secondary_64 (void )
PATCH v7 7/45 x86/sev: Remove do_early_exception() forward declarations
In reply to Brijesh SinghFrom: Borislav Petkov <[email protected]>
There's a perfectly fine prototype in the asm/setup.h header. Use it.
No functional changes.
--- arch/x86/kernel/sev.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
arch/x86/kernel/sev.c +1 -6
@@ -26,6 +26,7 @@#include <asm/fpu/xcr.h> #include <asm/processor.h> #include <asm/realmode.h> +#include <asm/setup.h> #include <asm/traps.h> #include <asm/svm.h> #include <asm/smp.h>
@@ -86,9 +87,6 @@ struct ghcb_state { static DEFINE_PER_CPU(struct sev_es_runtime_data*, runtime_data);DEFINE_STATIC_KEY_FALSE (sev_es_enable_key); -/* Needed in vc_early_forward_exception */ -void do_early_exception (struct pt_regs *regs,int trapnr); - static __always_inline bool on_vc_stack(struct pt_regs *regs) {unsigned long sp = regs->sp;
@@ -209,9 +207,6 @@ static noinstr struct ghcb *__sev_get_ghcb(struct ghcb_state *state)return ghcb; } -/* Needed in vc_early_forward_exception */ -void do_early_exception (struct pt_regs *regs,int trapnr); -static inline u64 sev_es_rd_ghcb_msr (void ) {return __rdmsr (MSR_AMD64_SEV_ES_GHCB );
Signature · 1 line
2.25.1
[tip: x86/sev] x86/sev: Remove do_early_exception() forward declarations
The following commit has been merged into the x86/sev branch of tip:
The following commit has been merged into the x86/sev branch of tip:
Commit-ID: 75cc9a84c9eb36e436e3fcee5158fe31d1dfd78f Gitweb: https://git.kernel.org/tip/75cc9a84c9eb36e436e3fcee5158fe31d1dfd78f Author: Borislav Petkov <[email protected]> AuthorDate: Wed, 10 Nov 2021 16:06:53 -06:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 15 Nov 2021 21:06:33 +01:00
x86/sev: Remove do_early_exception() forward declarations
There's a perfectly fine prototype in the asm/setup.h header. Use it.
No functional changes.
--- arch/x86/kernel/sev.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
arch/x86/kernel/sev.c +1 -6
@@ -26,6 +26,7 @@#include <asm/fpu/xcr.h> #include <asm/processor.h> #include <asm/realmode.h> +#include <asm/setup.h> #include <asm/traps.h> #include <asm/svm.h> #include <asm/smp.h>
@@ -86,9 +87,6 @@ struct ghcb_state { static DEFINE_PER_CPU(struct sev_es_runtime_data*, runtime_data);DEFINE_STATIC_KEY_FALSE (sev_es_enable_key); -/* Needed in vc_early_forward_exception */ -void do_early_exception (struct pt_regs *regs,int trapnr); - static __always_inline bool on_vc_stack(struct pt_regs *regs) {unsigned long sp = regs->sp;
@@ -209,9 +207,6 @@ static noinstr struct ghcb *__sev_get_ghcb(struct ghcb_state *state)return ghcb; } -/* Needed in vc_early_forward_exception */ -void do_early_exception (struct pt_regs *regs,int trapnr); -static inline u64 sev_es_rd_ghcb_msr (void ) {return __rdmsr (MSR_AMD64_SEV_ES_GHCB );
PATCH v7 8/45 x86/sev: Define the Linux specific guest termination reasons
In reply to Brijesh SinghGHCB specification defines the reason code for reason set 0. The reason codes defined in the set 0 do not cover all possible causes for a guest to request termination.
The reason set 1 to 255 is reserved for the vendor-specific codes. Reseve the reason set 1 for the Linux guest. Define an error codes for reason set 1.
While at it, change the sev_es_terminate() to accept the reason set parameter.
--- arch/x86/boot/compressed/sev.c | 6 +++--- arch/x86/include/asm/sev-common.h | 8 ++++++++ arch/x86/kernel/sev-shared.c | 11 ++++------- arch/x86/kernel/sev.c | 4 ++-- 4 files changed, 17 insertions(+), 12 deletions(-)
arch/x86/boot/compressed/sev.c +3 -3
@@ -122,7 +122,7 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,static bool early_setup_sev_es (void ) {if (!sev_es_negotiate_protocol ()) -sev_es_terminate (GHCB_SEV_ES_PROT_UNSUPPORTED ); +sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SEV_ES_PROT_UNSUPPORTED );if (set_page_decrypted ((unsigned long )&boot_ghcb_page))return false;
@@ -175,7 +175,7 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)enum es_result result;if (!boot_ghcb && !early_setup_sev_es ()) -sev_es_terminate (GHCB_SEV_ES_GEN_REQ ); +sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SEV_ES_GEN_REQ );vc_ghcb_invalidate (boot_ghcb); result =vc_init_em_ctxt (&ctxt, regs, exit_code);
@@ -202,7 +202,7 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)if (result ==ES_OK )vc_finish_insn (&ctxt);else if (result !=ES_RETRY ) -sev_es_terminate (GHCB_SEV_ES_GEN_REQ ); +sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SEV_ES_GEN_REQ ); }static inline u64 rd_sev_status_msr (void )
arch/x86/include/asm/sev-common.h +8 -0
@@ -73,9 +73,17 @@/* GHCBData[23:16] */ \ ((((u64)reason_val) & 0xff) << 16)) +/* Error codes from reason set 0 */ +#define SEV_TERM_SET_GEN 0#define GHCB_SEV_ES_GEN_REQ 0#define GHCB_SEV_ES_PROT_UNSUPPORTED 1 +/* Linux-specific reason codes (used with reason set 1) */ +#define SEV_TERM_SET_LINUX 1 +#define GHCB_TERM_REGISTER 0/* GHCB GPA registration failure */ +#define GHCB_TERM_PSC 1/* Page State Change failure */ +#define GHCB_TERM_PVALIDATE 2/* Pvalidate failure */ +#define GHCB_RESP_CODE (v) ((v) & GHCB_MSR_INFO_MASK)#endif
arch/x86/kernel/sev-shared.c +4 -7
@@ -24,15 +24,12 @@ static bool __init sev_es_check_cpu_features(void)return true; } -static void __noreturn sev_es_terminate (unsigned int reason) +static void __noreturn sev_es_terminate (unsigned int set,unsigned int reason) {u64 val =GHCB_MSR_TERM_REQ ; -/* -* Tell the hypervisor what went wrong - only reason-set 0 is -* currently supported. -*/ - val |=GHCB_SEV_TERM_REASON (0 , reason); +/* Tell the hypervisor what went wrong. */ + val |=GHCB_SEV_TERM_REASON (set, reason);/* Request Guest Termination from Hypvervisor */ sev_es_wr_ghcb_msr (val);
@@ -221,7 +218,7 @@ void __init do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code) fail:/* Terminate the guest */ -sev_es_terminate (GHCB_SEV_ES_GEN_REQ ); +sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SEV_ES_GEN_REQ ); } static enum es_result vc_insn_string_read(struct es_em_ctxt *ctxt,
arch/x86/kernel/sev.c +2 -2
@@ -1406,7 +1406,7 @@ DEFINE_IDTENTRY_VC_KERNEL(exc_vmm_communication)show_regs (regs);/* Ask hypervisor to sev_es_terminate */ -sev_es_terminate (GHCB_SEV_ES_GEN_REQ ); +sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SEV_ES_GEN_REQ );/* If that fails and we get here - just panic */ panic ("Returned from Terminate-Request to Hypervisor\n" );
@@ -1454,7 +1454,7 @@ bool __init handle_vc_boot_ghcb(struct pt_regs *regs)/* Do initial setup or terminate the guest */ if (unlikely (boot_ghcb ==NULL && !sev_es_setup_ghcb ())) -sev_es_terminate (GHCB_SEV_ES_GEN_REQ ); +sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SEV_ES_GEN_REQ );vc_ghcb_invalidate (boot_ghcb);
Signature · 1 line
2.25.1
PATCH v7 9/45 x86/sev: Save the negotiated GHCB version
In reply to Brijesh SinghThe SEV-ES guest calls the sev_es_negotiate_protocol() to negotiate the GHCB protocol version before establishing the GHCB. Cache the negotiated GHCB version so that it can be used later.
--- arch/x86/include/asm/sev.h | 2 +- arch/x86/kernel/sev-shared.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-)
arch/x86/include/asm/sev.h +1 -1
@@ -12,7 +12,7 @@#include <asm/insn.h> #include <asm/sev-common.h> -#define GHCB_PROTO_OUR 0x0001UL +#define GHCB_PROTOCOL_MIN 1ULL#define GHCB_PROTOCOL_MAX 1ULL#define GHCB_DEFAULT_USAGE 0ULL
arch/x86/kernel/sev-shared.c +14 -3
@@ -14,6 +14,15 @@#define has_cpuflag (f) boot_cpu_has(f)#endif +/* +* Since feature negotiation related variables are set early in the boot +* process they must reside in the .data section so as not to be zeroed +* out when the .bss section is later cleared. +* +* GHCB protocol version negotiated with the hypervisor. +*/ +static u16 ghcb_version__ro_after_init ; +static bool __init sev_es_check_cpu_features (void ) {if (!has_cpuflag (X86_FEATURE_RDRAND )) {
@@ -51,10 +60,12 @@ static bool sev_es_negotiate_protocol(void)if (GHCB_MSR_INFO (val) !=GHCB_MSR_SEV_INFO_RESP )return false; -if (GHCB_MSR_PROTO_MAX (val) <GHCB_PROTO_OUR || -GHCB_MSR_PROTO_MIN (val) >GHCB_PROTO_OUR ) +if (GHCB_MSR_PROTO_MAX (val) <GHCB_PROTOCOL_MIN || +GHCB_MSR_PROTO_MIN (val) >GHCB_PROTOCOL_MAX )return false; + ghcb_version =min_t (size_t,GHCB_MSR_PROTO_MAX (val),GHCB_PROTOCOL_MAX ); +return true; }
@@ -127,7 +138,7 @@ enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, bool set_ghcb_msr, u64 exit_info_1, u64 exit_info_2) {/* Fill in protocol and format specifiers */ - ghcb->protocol_version =GHCB_PROTOCOL_MAX ; + ghcb->protocol_version = ghcb_version; ghcb->ghcb_usage =GHCB_DEFAULT_USAGE ;ghcb_set_sw_exit_code (ghcb, exit_code);
Signature · 1 line
2.25.1
Re: [PATCH v7 09/45] x86/sev: Save the negotiated GHCB version
Hi Brijesh:
We find this patch breaks AMD SEV support in the Hyper-V Isolation
VM. Hyper-V code also uses sev_es_ghcb_hv_call() to read or write msr
value. The sev_es_check_cpu_features() isn't called in the Hyper-V code
and so the ghcb_version is always 0. Could you add a new parameter ghcb_version for sev_es_ghcb_hv_call() and then caller may input ghcb_version?
Thanks.
Quoted 68 lines · Brijesh Singh
The SEV-ES guest calls the
sev_es_negotiate_protocol()to negotiate the GHCB protocol version before establishing the GHCB. Cache the negotiated GHCB version so that it can be used later.Signed-off-by Brijesh Singh <[email protected]>--- arch/x86/include/asm/sev.h | 2 +- arch/x86/kernel/sev-shared.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-)arch/x86/include/asm/sev.h +1
-1@@ -12,7 +12,7 @@#include <asm/insn.h> #include <asm/sev-common.h> -#define GHCB_PROTO_OUR 0x0001UL +#define GHCB_PROTOCOL_MIN 1ULL#define GHCB_PROTOCOL_MAX 1ULL#define GHCB_DEFAULT_USAGE 0ULLarch/x86/kernel/sev-shared.c +14
-3@@ -14,6 +14,15 @@#define has_cpuflag (f) boot_cpu_has(f)#endif +/* +* Since feature negotiation related variables are set early in the boot +* process they must reside in the .data section so as not to be zeroed +* out when the .bss section is later cleared. +* +* GHCB protocol version negotiated with the hypervisor. +*/ +static u16 ghcb_version__ro_after_init ; +static bool __init sev_es_check_cpu_features (void ) {if (!has_cpuflag (X86_FEATURE_RDRAND )) {@@ -51,10 +60,12 @@ static bool sev_es_negotiate_protocol(void)if (GHCB_MSR_INFO (val) !=GHCB_MSR_SEV_INFO_RESP )return false; -if (GHCB_MSR_PROTO_MAX (val) <GHCB_PROTO_OUR || -GHCB_MSR_PROTO_MIN (val) >GHCB_PROTO_OUR ) +if (GHCB_MSR_PROTO_MAX (val) <GHCB_PROTOCOL_MIN || +GHCB_MSR_PROTO_MIN (val) >GHCB_PROTOCOL_MAX )return false; + ghcb_version =min_t (size_t,GHCB_MSR_PROTO_MAX (val),GHCB_PROTOCOL_MAX ); +return true; }@@ -127,7 +138,7 @@ enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, bool set_ghcb_msr, u64 exit_info_1, u64 exit_info_2) {/* Fill in protocol and format specifiers */ - ghcb->protocol_version =GHCB_PROTOCOL_MAX ; + ghcb->protocol_version = ghcb_version; ghcb->ghcb_usage =GHCB_DEFAULT_USAGE ;ghcb_set_sw_exit_code (ghcb, exit_code);
Borislav Petkov
maintainerRe: [PATCH v7 09/45] x86/sev: Save the negotiated GHCB version
Quoted 1 line · Tianyu Lan
Hi Brijesh:
Do me a favor please and learn not to top-post on a public mailing list. Also, take the time to read Documentation/process/ before you send upstream patches and how to work with the community in general.
Quoted 4 lines
We find this patch breaks AMD SEV support in the Hyper-V Isolation VM. Hyper-V code also uses
sev_es_ghcb_hv_call()to read or write msr value. Thesev_es_check_cpu_features()isn't called in the Hyper-V code and so theghcb_versionis always 0.
If hyperv is going to expose hypervisor features, then it better report GHCB v2. If not, then I guess < 2 or 1 or so, depending on how this is defined.
Quoted 2 lines
Could you add a new parameter
ghcb_versionforsev_es_ghcb_hv_call()and then caller may inputghcb_version?
No, your hypervisor needs to adhere to the spec and report proper ghcb version. We won't be doing any accomodate-hyperv hacks.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v7 09/45] x86/sev: Save the negotiated GHCB version
Quoted 16 lines · Borislav Petkov
Quoted 1 line · Tianyu Lan
Hi Brijesh:
Do me a favor please and learn not to top-post on a public mailing list. Also, take the time to read
Documentation/process/before you send upstream patches and how to work with the community in general.Quoted 4 lines
We find this patch breaks AMD SEV support in the Hyper-V Isolation VM. Hyper-V code also uses
sev_es_ghcb_hv_call()to read or write msr value. Thesev_es_check_cpu_features()isn't called in the Hyper-V code and so theghcb_versionis always 0.If hyperv is going to expose hypervisor features, then it better report GHCB v2. If not, then I guess < 2 or 1 or so, depending on how this is defined.
Quoted 6 lines
Quoted 2 lines
Could you add a new parameter
ghcb_versionforsev_es_ghcb_hv_call()and then caller may inputghcb_version?No, your hypervisor needs to adhere to the spec and report proper ghcb version. We won't be doing any accomodate-hyperv hacks.
Agreed, the HyperV support need to negotiate the GHCB version before making those HC. In the current patch, the sev_es_negotiate_protocol() will save the ghcb_version in global variable and the saved value is used during the HC. Just make sure that initial HyperV support is adhering to the specification.
thanks
PATCH v7 10/45 x86/sev: Add support for hypervisor feature VMGEXIT
In reply to Brijesh SinghVersion 2 of GHCB specification introduced advertisement of a features that are supported by the hypervisor. Add support to query the HV features on boot.
Version 2 of GHCB specification adds several new NAEs, most of them are optional except the hypervisor feature. Now that hypervisor feature NAE is implemented, so bump the GHCB maximum support protocol version.
--- arch/x86/include/asm/sev-common.h | 3 +++ arch/x86/include/asm/sev.h | 2 +- arch/x86/include/uapi/asm/svm.h | 2 ++ arch/x86/kernel/sev-shared.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-)
arch/x86/include/asm/sev-common.h +3 -0
@@ -60,6 +60,9 @@/* GHCB Hypervisor Feature Request/Response */ #define GHCB_MSR_HV_FT_REQ 0x080#define GHCB_MSR_HV_FT_RESP 0x081 +#define GHCB_MSR_HV_FT_RESP_VAL (v) \ +/* GHCBData[63:12] */ \ + (((u64)(v) & GENMASK_ULL(63, 12)) >> 12)#define GHCB_MSR_TERM_REQ 0x100#define GHCB_MSR_TERM_REASON_SET_POS 12
arch/x86/include/asm/sev.h +1 -1
@@ -13,7 +13,7 @@#include <asm/sev-common.h> #define GHCB_PROTOCOL_MIN 1ULL -#define GHCB_PROTOCOL_MAX 1ULL +#define GHCB_PROTOCOL_MAX 2ULL#define GHCB_DEFAULT_USAGE 0ULL#define VMGEXIT () { asm volatile("rep; vmmcall\n\r"); }
arch/x86/include/uapi/asm/svm.h +2 -0
@@ -108,6 +108,7 @@#define SVM_VMGEXIT_AP_JUMP_TABLE 0x80000005#define SVM_VMGEXIT_SET_AP_JUMP_TABLE 0#define SVM_VMGEXIT_GET_AP_JUMP_TABLE 1 +#define SVM_VMGEXIT_HV_FEATURES 0x8000fffd#define SVM_VMGEXIT_UNSUPPORTED_EVENT 0x8000ffff/* Exit code reserved for hypervisor/software use */
@@ -218,6 +219,7 @@ { SVM_VMGEXIT_NMI_COMPLETE, "vmgexit_nmi_complete" }, \ { SVM_VMGEXIT_AP_HLT_LOOP, "vmgexit_ap_hlt_loop" }, \ { SVM_VMGEXIT_AP_JUMP_TABLE, "vmgexit_ap_jump_table" }, \ + { SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, \ { SVM_EXIT_ERR, "invalid_guest_state" }
arch/x86/kernel/sev-shared.c +30 -0
@@ -23,6 +23,9 @@*/ static u16 ghcb_version__ro_after_init ; +/* Bitmap of SEV features supported by the hypervisor */ +static u64 sev_hv_features__ro_after_init ; +static bool __init sev_es_check_cpu_features (void ) {if (!has_cpuflag (X86_FEATURE_RDRAND )) {
@@ -48,6 +51,30 @@ static void __noreturn sev_es_terminate(unsigned int set, unsigned int reason) asmvolatile ("hlt\n" : : :"memory" ); } +/* +* The hypervisor features are available from GHCB version 2 onward. +*/ +static bool get_hv_features (void ) +{ +u64 val; + + sev_hv_features =0 ; + +if (ghcb_version <2 ) +return false; + +sev_es_wr_ghcb_msr (GHCB_MSR_HV_FT_REQ ); +VMGEXIT (); + + val =sev_es_rd_ghcb_msr (); +if (GHCB_RESP_CODE (val) !=GHCB_MSR_HV_FT_RESP ) +return false; + + sev_hv_features =GHCB_MSR_HV_FT_RESP_VAL (val); + +return true; +} +static bool sev_es_negotiate_protocol (void ) {u64 val;
@@ -66,6 +93,9 @@ static bool sev_es_negotiate_protocol(void) ghcb_version =min_t (size_t,GHCB_MSR_PROTO_MAX (val),GHCB_PROTOCOL_MAX ); +if (!get_hv_features ()) +return false; +return true; }
Signature · 1 line
2.25.1
Borislav Petkov
maintainerRe: [PATCH v7 10/45] x86/sev: Add support for hypervisor feature VMGEXIT
Quoted 13 lines · Brijesh Singh
arch/x86/kernel/sev-shared.c +13
-0+/* +* The hypervisor features are available from GHCB version 2 onward. +*/ +static bool get_hv_features (void ) +{ +u64 val; + + sev_hv_features =0 ; + +if (ghcb_version <2 ) +return false; + +sev_es_wr_ghcb_msr (GHCB_MSR_HV_FT_REQ );
arch/x86/kernel/sev-shared.c static void __noreturn sev_es_terminate(unsigned int set, unsigned int reason) · line 76
Quoted 10 lines
arch/x86/kernel/sev-shared.c +10
-0+VMGEXIT (); + + val =sev_es_rd_ghcb_msr (); +if (GHCB_RESP_CODE (val) !=GHCB_MSR_HV_FT_RESP ) +return false; + + sev_hv_features =GHCB_MSR_HV_FT_RESP_VAL (val); + +return true; +}
I still don't like this.
This is more of that run-me-in-the-exception-handler thing while this is purely feature detection stuff which needs to be done exactly once on init.
IOW, that stanza
if (!sev_es_negotiate_protocol())
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_PROT_UNSUPPORTED);should be called once in sev_enable() for the decompressor kernel and once in sev_es_init_vc_handling() for kernel proper.
Then you don't need to do any of that sev_hv_features = 0 thing but detect them exactly once and query them as much as you can.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v7 10/45] x86/sev: Add support for hypervisor feature VMGEXIT
Quoted 31 lines · Borislav Petkov
Quoted 13 lines · Brijesh Singh
arch/x86/kernel/sev-shared.c +13
-0+/* +* The hypervisor features are available from GHCB version 2 onward. +*/ +static bool get_hv_features (void ) +{ +u64 val; + + sev_hv_features =0 ; + +if (ghcb_version <2 ) +return false; + +sev_es_wr_ghcb_msr (GHCB_MSR_HV_FT_REQ );arch/x86/kernel/sev-shared.c static void __noreturn sev_es_terminate(unsigned int set, unsigned int reason) · line 76
Quoted 10 lines
arch/x86/kernel/sev-shared.c +10
-0+VMGEXIT (); + + val =sev_es_rd_ghcb_msr (); +if (GHCB_RESP_CODE (val) !=GHCB_MSR_HV_FT_RESP ) +return false; + + sev_hv_features =GHCB_MSR_HV_FT_RESP_VAL (val); + +return true; +}I still don't like this.
This is more of that run-me-in-the-exception-handler thing while this is purely feature detection stuff which needs to be done exactly once on init.
Quoted 8 lines
IOW, that stanza
if (!sev_es_negotiate_protocol()) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_PROT_UNSUPPORTED);should be called once in
sev_enable()for the decompressor kernel and once insev_es_init_vc_handling()for kernel proper.
I will look into it, I will improve the sev_enable() to call GHCB MSR protocol query the version and feature.
Quoted 5 lines
Then you don't need to do any of that
sev_hv_features= 0 thing but detect them exactly once and query them as much as you can.Thx.
PATCH v7 11/45 x86/sev: Check SEV-SNP features support
In reply to Brijesh SinghVersion 2 of the GHCB specification added the advertisement of features that are supported by the hypervisor. If hypervisor supports the SEV-SNP then it must set the SEV-SNP features bit to indicate that the base SEV-SNP is supported.
Check the SEV-SNP feature while establishing the GHCB, if failed, terminate the guest.
--- arch/x86/boot/compressed/sev.c | 17 +++++++++++++++-- arch/x86/include/asm/sev-common.h | 3 +++ arch/x86/kernel/sev.c | 12 ++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-)
arch/x86/boot/compressed/sev.c +15 -2
@@ -119,11 +119,24 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,/* Include code for early handlers */ #include "../../kernel/sev-shared.c" -static bool early_setup_sev_es (void ) +static inline bool sev_snp_enabled (void ) +{ +return sev_status &MSR_AMD64_SEV_SNP_ENABLED ; +} + +static bool do_early_sev_setup (void ) {if (!sev_es_negotiate_protocol ())sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SEV_ES_PROT_UNSUPPORTED ); +/* +* SNP is supported in v2 of the GHCB spec which mandates support for HV +* features. If SEV-SNP is enabled, then check if the hypervisor supports +* the SEV-SNP features. +*/ +if (sev_snp_enabled () && !(sev_hv_features &GHCB_HV_FT_SNP )) +sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SNP_UNSUPPORTED ); +if (set_page_decrypted ((unsigned long )&boot_ghcb_page))return false;
@@ -174,7 +187,7 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)struct es_em_ctxt ctxt;enum es_result result; -if (!boot_ghcb && !early_setup_sev_es ()) +if (!boot_ghcb && !do_early_sev_setup ())sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SEV_ES_GEN_REQ );vc_ghcb_invalidate (boot_ghcb);
arch/x86/include/asm/sev-common.h +3 -0
@@ -64,6 +64,8 @@/* GHCBData[63:12] */ \ (((u64)(v) & GENMASK_ULL(63, 12)) >> 12) +#define GHCB_HV_FT_SNP BIT_ULL(0) +#define GHCB_MSR_TERM_REQ 0x100#define GHCB_MSR_TERM_REASON_SET_POS 12#define GHCB_MSR_TERM_REASON_SET_MASK 0xf
@@ -80,6 +82,7 @@#define SEV_TERM_SET_GEN 0#define GHCB_SEV_ES_GEN_REQ 0#define GHCB_SEV_ES_PROT_UNSUPPORTED 1 +#define GHCB_SNP_UNSUPPORTED 2/* Linux-specific reason codes (used with reason set 1) */ #define SEV_TERM_SET_LINUX 1
arch/x86/kernel/sev.c +10 -2
@@ -627,12 +627,20 @@ static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *ctxt)* This function runs on the first #VC exception after the kernel * switched to virtual addresses. */ -static bool __init sev_es_setup_ghcb (void ) +static bool __init setup_ghcb (void ) {/* First make sure the hypervisor talks a supported protocol. */ if (!sev_es_negotiate_protocol ())return false; +/* +* SNP is supported in v2 of the GHCB spec which mandates support for HV +* features. If SEV-SNP is enabled, then check if the hypervisor supports +* the SEV-SNP features. +*/ +if (cc_platform_has (CC_ATTR_SEV_SNP ) && !(sev_hv_features &GHCB_HV_FT_SNP )) +sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SNP_UNSUPPORTED ); +/* * Clear the boot_ghcb. The first exception comes in before the bss * section is cleared.
@@ -1453,7 +1461,7 @@ bool __init handle_vc_boot_ghcb(struct pt_regs *regs)enum es_result result;/* Do initial setup or terminate the guest */ -if (unlikely (boot_ghcb ==NULL && !sev_es_setup_ghcb ())) +if (unlikely (!boot_ghcb && !setup_ghcb ()))sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SEV_ES_GEN_REQ );vc_ghcb_invalidate (boot_ghcb);
Signature · 1 line
2.25.1
PATCH v7 12/45 x86/sev: Add a helper for the PVALIDATE instruction
In reply to Brijesh SinghAn SNP-active guest uses the PVALIDATE instruction to validate or rescind the validation of a guest page’s RMP entry. Upon completion, a return code is stored in EAX and rFLAGS bits are set based on the return code. If the instruction completed successfully, the CF indicates if the content of the RMP were changed or not.
See AMD APM Volume 3 for additional details.
--- arch/x86/include/asm/sev.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
arch/x86/include/asm/sev.h +21 -0
@@ -60,6 +60,9 @@ extern void vc_no_ghcb(void);extern void vc_boot_ghcb (void );extern bool handle_vc_boot_ghcb (struct pt_regs *regs); +/* Software defined (when rFlags.CF = 1) */ +#define PVALIDATE_FAIL_NOUPDATE 255 +#ifdef CONFIG_AMD_MEM_ENCRYPT extern struct static_key_false sev_es_enable_key;extern void __sev_es_ist_enter (struct pt_regs *regs);
@@ -87,12 +90,30 @@ extern enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb,struct es_em_ctxt *ctxt, u64 exit_code, u64 exit_info_1, u64 exit_info_2); +static inline int pvalidate (unsigned long vaddr,bool rmp_psize,bool validate) +{ +bool no_rmpupdate; +int rc; + +/* "pvalidate" mnemonic support in binutils 2.36 and newer */ + asm volatile(".byte 0xF2, 0x0F, 0x01, 0xFF\n\t" + CC_SET(c) + : CC_OUT(c) (no_rmpupdate), "=a"(rc) + : "a"(vaddr), "c"(rmp_psize), "d"(validate) + : "memory", "cc"); + +if (no_rmpupdate) +return PVALIDATE_FAIL_NOUPDATE ; + +return rc; +}#else static inline void sev_es_ist_enter (struct pt_regs *regs) { }static inline void sev_es_ist_exit (void ) { }static inline int sev_es_setup_ap_jump_table (struct real_mode_header *rmh) {return 0 ; }static inline void sev_es_nmi_complete (void ) { }static inline int sev_es_efi_map_ghcbs (pgd_t *pgd) {return 0 ; } +static inline int pvalidate (unsigned long vaddr,bool rmp_psize,bool validate) {return 0 ; }#endif #endif
Signature · 1 line
2.25.1
PATCH v7 13/45 x86/sev: Check the vmpl level
In reply to Brijesh SinghVirtual Machine Privilege Level (VMPL) is an optional feature in the SEV-SNP architecture, which allows a guest VM to divide its address space into four levels. The level can be used to provide the hardware isolated abstraction layers with a VM. The VMPL0 is the highest privilege, and VMPL3 is the least privilege. Certain operations must be done by the VMPL0 software, such as:
* Validate or invalidate memory range (PVALIDATE instruction)
* Allocate VMSA page (RMPADJUST instruction when VMSA=1)
The initial SEV-SNP support assumes that the guest kernel is running on VMPL0. Let's add a check to make sure that kernel is running at VMPL0 before continuing the boot. There is no easy method to query the current VMPL level, so use the RMPADJUST instruction to determine whether its booted at the VMPL0.
--- arch/x86/boot/compressed/sev.c | 34 ++++++++++++++++++++++++++++--- arch/x86/include/asm/sev-common.h | 1 + arch/x86/include/asm/sev.h | 16 +++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-)
arch/x86/boot/compressed/sev.c +31 -3
@@ -124,6 +124,29 @@ static inline bool sev_snp_enabled(void)return sev_status &MSR_AMD64_SEV_SNP_ENABLED ; } +static bool is_vmpl0 (void ) +{ +u64 attrs; +int err; + +/* +* There is no straightforward way to query the current VMPL level. The +* simplest method is to use the RMPADJUST instruction to change a page +* permission to a VMPL level-1, and if the guest kernel is launched at +* a level <= 1, then RMPADJUST instruction will return an error. +*/ + attrs =1 ; + +/* +* Any page-aligned virtual address is sufficient to test the VMPL level. +* The boot_ghcb_page is page aligned memory, so lets use for the test. +*/ +if (rmpadjust ((unsigned long )&boot_ghcb_page,RMP_PG_SIZE_4K , attrs)) +return false; + +return true; +} +static bool do_early_sev_setup (void ) {if (!sev_es_negotiate_protocol ())
@@ -132,10 +155,15 @@ static bool do_early_sev_setup(void)/* * SNP is supported in v2 of the GHCB spec which mandates support for HV * features. If SEV-SNP is enabled, then check if the hypervisor supports -* the SEV-SNP features. +* the SEV-SNP features and is launched at VMPL-0 level. */ -if (sev_snp_enabled () && !(sev_hv_features &GHCB_HV_FT_SNP )) -sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SNP_UNSUPPORTED ); +if (sev_snp_enabled ()) { +if (!(sev_hv_features &GHCB_HV_FT_SNP )) +sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SNP_UNSUPPORTED ); + +if (!is_vmpl0 ()) +sev_es_terminate (SEV_TERM_SET_LINUX ,GHCB_TERM_NOT_VMPL0 ); + }if (set_page_decrypted ((unsigned long )&boot_ghcb_page))return false;
arch/x86/include/asm/sev-common.h +1 -0
@@ -89,6 +89,7 @@#define GHCB_TERM_REGISTER 0/* GHCB GPA registration failure */ #define GHCB_TERM_PSC 1/* Page State Change failure */ #define GHCB_TERM_PVALIDATE 2/* Pvalidate failure */ +#define GHCB_TERM_NOT_VMPL0 3/* SNP guest is not running at VMPL-0 */ #define GHCB_RESP_CODE (v) ((v) & GHCB_MSR_INFO_MASK)
arch/x86/include/asm/sev.h +16 -0
@@ -63,6 +63,9 @@ extern bool handle_vc_boot_ghcb(struct pt_regs *regs);/* Software defined (when rFlags.CF = 1) */ #define PVALIDATE_FAIL_NOUPDATE 255 +/* RMP page size */ +#define RMP_PG_SIZE_4K 0 +#ifdef CONFIG_AMD_MEM_ENCRYPT extern struct static_key_false sev_es_enable_key;extern void __sev_es_ist_enter (struct pt_regs *regs);
@@ -90,6 +93,18 @@ extern enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb,struct es_em_ctxt *ctxt, u64 exit_code, u64 exit_info_1, u64 exit_info_2); +static inline int rmpadjust (unsigned long vaddr,bool rmp_psize,unsigned long attrs) +{ +int rc; + +/* "rmpadjust" mnemonic support in binutils 2.36 and newer */ + asmvolatile (".byte 0xF3,0x0F,0x01,0xFE\n\t" + :"=a" (rc) + :"a" (vaddr),"c" (rmp_psize),"d" (attrs) + :"memory" ,"cc" ); + +return rc; +}static inline int pvalidate (unsigned long vaddr,bool rmp_psize,bool validate) {bool no_rmpupdate;
@@ -114,6 +129,7 @@ static inline int sev_es_setup_ap_jump_table(struct real_mode_header *rmh) { retstatic inline void sev_es_nmi_complete (void ) { }static inline int sev_es_efi_map_ghcbs (pgd_t *pgd) {return 0 ; }static inline int pvalidate (unsigned long vaddr,bool rmp_psize,bool validate) {return 0 ; } +static inline int rmpadjust (unsigned long vaddr,bool rmp_psize,unsigned long attrs) {return 0 ; }#endif #endif
Signature · 1 line
2.25.1
Borislav Petkov
maintainerRe: [PATCH v7 13/45] x86/sev: Check the vmpl level
Quoted 4 lines · Brijesh Singh
Virtual Machine Privilege Level (VMPL) is an optional feature in the SEV-SNP architecture, which allows a guest VM to divide its address space into four levels. The level can be used to provide the hardware isolated abstraction layers with a VM.
That sentence needs improving.
Quoted 8 lines
The VMPL0 is the highest privilege, and
VMPL3 is the least privilege. Certain operations must be done by the VMPL0 software, such as:* Validate or invalidate memory range (PVALIDATE instruction)
* Allocate VMSA page (RMPADJUST instruction when VMSA=1)The initial SEV-SNP support assumes that the guest kernel is running on
assumes? I think it is "requires".
Quoted 1 line
VMPL0. Let's add a check to make sure that kernel is running at VMPL0
s/Let's //
Quoted 2 lines
before continuing the boot. There is no easy method to query the current VMPL level, so use the RMPADJUST instruction to determine whether its
"... whether the guest is running at VMPL0."
Quoted 18 lines
booted at the VMPL0.
Signed-off-by Brijesh Singh <[email protected]>--- arch/x86/boot/compressed/sev.c | 34 ++++++++++++++++++++++++++++--- arch/x86/include/asm/sev-common.h | 1 + arch/x86/include/asm/sev.h | 16 +++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-)arch/x86/boot/compressed/sev.c +1
-0@@ -124,6 +124,29 @@ static inline bool sev_snp_enabled(void)return sev_status &MSR_AMD64_SEV_SNP_ENABLED ; } +static bool is_vmpl0 (void )
arch/x86/boot/compressed/sev.c static inline bool sev_snp_enabled(void) · line 137
Quoted 10 lines
arch/x86/boot/compressed/sev.c +10
-0+{ +u64 attrs; +int err; + +/* +* There is no straightforward way to query the current VMPL level. The +* simplest method is to use the RMPADJUST instruction to change a page +* permission to a VMPL level-1, and if the guest kernel is launched at +* a level <= 1, then RMPADJUST instruction will return an error. +*/
So I was wondering what this is changing because if the change you do is relevant, you'd have to undo it.
But looking at RMPADJUST, TARGET_PERM_MASK is 0 for target VMPL1 so you're basically clearing all permissions for boot_ghcb_page on VMPL1. Which is fine currently as we do only VMPL0 but pls write that out explicitly what you're doing here and why it is ok to use RMPADJUST without having to restore any changes it has done to the RMP table.
Quoted 16 lines
arch/x86/boot/compressed/sev.c +12
-0+ attrs =1 ; + +/* +* Any page-aligned virtual address is sufficient to test the VMPL level. +* The boot_ghcb_page is page aligned memory, so lets use for the test. +*/ +if (rmpadjust ((unsigned long )&boot_ghcb_page,RMP_PG_SIZE_4K , attrs)) +return false; + +return true; +} +static bool do_early_sev_setup (void ) {if (!sev_es_negotiate_protocol ())
arch/x86/boot/compressed/sev.c static bool do_early_sev_setup(void) · line 158
Quoted 5 lines
arch/x86/boot/compressed/sev.c +1
-1@@ -132,10 +155,15 @@ static bool do_early_sev_setup(void)/* * SNP is supported in v2 of the GHCB spec which mandates support for HV * features. If SEV-SNP is enabled, then check if the hypervisor supports -* the SEV-SNP features. +* the SEV-SNP features and is launched at VMPL-0 level.
"VMPL0" - no hyphen - like in the APM. Below too.
Quoted 13 lines
arch/x86/boot/compressed/sev.c +7
-2*/ -if (sev_snp_enabled () && !(sev_hv_features &GHCB_HV_FT_SNP )) -sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SNP_UNSUPPORTED ); +if (sev_snp_enabled ()) { +if (!(sev_hv_features &GHCB_HV_FT_SNP )) +sev_es_terminate (SEV_TERM_SET_GEN ,GHCB_SNP_UNSUPPORTED ); + +if (!is_vmpl0 ()) +sev_es_terminate (SEV_TERM_SET_LINUX ,GHCB_TERM_NOT_VMPL0 ); + }if (set_page_decrypted ((unsigned long )&boot_ghcb_page))return false;
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePATCH v7 14/45 x86/compressed: Add helper for validating pages in the decompression stage
In reply to Brijesh SinghMany of the integrity guarantees of SEV-SNP are enforced through the Reverse Map Table (RMP). Each RMP entry contains the GPA at which a particular page of DRAM should be mapped. The VMs can request the hypervisor to add pages in the RMP table via the Page State Change VMGEXIT defined in the GHCB specification. Inside each RMP entry is a Validated flag; this flag is automatically cleared to 0 by the CPU hardware when a new RMP entry is created for a guest. Each VM page can be either validated or invalidated, as indicated by the Validated flag in the RMP entry. Memory access to a private page that is not validated generates a #VC. A VM must use PVALIDATE instruction to validate the private page before using it.
To maintain the security guarantee of SEV-SNP guests, when transitioning pages from private to shared, the guest must invalidate the pages before asking the hypervisor to change the page state to shared in the RMP table.
After the pages are mapped private in the page table, the guest must issue a page state change VMGEXIT to make the pages private in the RMP table and validate it.
On boot, BIOS should have validated the entire system memory. During the kernel decompression stage, the VC handler uses the set_memory_decrypted() to make the GHCB page shared (i.e clear encryption attribute). And while exiting from the decompression, it calls the set_page_encrypted() to make the page private.
Add sev_snp_set_page_{private,shared}() helper that is used by the set_memory_{decrypt,encrypt}() to change the page state in the RMP table.
--- arch/x86/boot/compressed/ident_map_64.c | 18 ++++++++++- arch/x86/boot/compressed/misc.h | 4 +++ arch/x86/boot/compressed/sev.c | 41 +++++++++++++++++++++++++ arch/x86/include/asm/sev-common.h | 26 ++++++++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/ident_map_64.c +17 -1
@@ -275,15 +275,31 @@ static int set_clr_page_flags(struct x86_mapping_info *info,* Changing encryption attributes of a page requires to flush it from * the caches. */ -if ((set | clr) & _PAGE_ENC) +if ((set | clr) & _PAGE_ENC) {clflush_page (address); +/* +* If the encryption attribute is being cleared, then change +* the page state to shared in the RMP table. +*/ +if (clr) +snp_set_page_shared (pte_pfn (*ptep) <<PAGE_SHIFT ); + } +/* Update PTE */ pte = *ptep; pte =pte_set_flags (pte, set); pte =pte_clear_flags (pte, clr);set_pte (ptep, pte); +/* +* If the encryption attribute is being set, then change the page state to +* private in the RMP entry. The page state must be done after the PTE +* is updated. +*/ +if (set & _PAGE_ENC) +snp_set_page_private (pte_pfn (*ptep) <<PAGE_SHIFT ); +/* Flush TLB after changing encryption attribute */ write_cr3 (top_level_pgt);
arch/x86/boot/compressed/misc.h +4 -0
@@ -124,6 +124,8 @@ static inline void console_init(void)void sev_enable (struct boot_params *bp);void sev_es_shutdown_ghcb (void );extern bool sev_es_check_ghcb_fault (unsigned long address); +void snp_set_page_private (unsigned long paddr); +void snp_set_page_shared (unsigned long paddr);#else static inline void sev_enable (struct boot_params *bp) { }static inline void sev_es_shutdown_ghcb (void ) { }
@@ -131,6 +133,8 @@ static inline bool sev_es_check_ghcb_fault(unsigned long address) {return false; } +static inline void snp_set_page_private (unsigned long paddr) { } +static inline void snp_set_page_shared (unsigned long paddr) { }#endif /* acpi.c */
arch/x86/boot/compressed/sev.c +41 -0
47 lines not on this page · raw message
arch/x86/include/asm/sev-common.h +26 -0
@@ -57,6 +57,32 @@#define GHCB_MSR_AP_RESET_HOLD_REQ 0x006#define GHCB_MSR_AP_RESET_HOLD_RESP 0x007 +/* +* SNP Page State Change Operation +* +* GHCBData[55:52] - Page operation: +* 0x0001 – Page assignment, Private +* 0x0002 – Page assignment, Shared +*/ +enum psc_op { +SNP_PAGE_STATE_PRIVATE =1 , +SNP_PAGE_STATE_SHARED , +}; + +#define GHCB_MSR_PSC_REQ 0x014 +#define GHCB_MSR_PSC_REQ_GFN (gfn, op) \ +/* GHCBData[55:52] */ \ + (((u64)((op) & 0xf) << 52) | \ +/* GHCBData[51:12] */ \ + ((u64)((gfn) & GENMASK_ULL(39, 0)) << 12) | \ + /* GHCBData[11:0] */ \ + GHCB_MSR_PSC_REQ) + +#define GHCB_MSR_PSC_RESP 0x015 +#define GHCB_MSR_PSC_RESP_VAL (val) \ +/* GHCBData[63:32] */ \ + (((u64)(val) & GENMASK_ULL(63, 32)) >> 32) +/* GHCB Hypervisor Feature Request/Response */ #define GHCB_MSR_HV_FT_REQ 0x080#define GHCB_MSR_HV_FT_RESP 0x081
Signature · 1 line
2.25.1
Borislav Petkov
maintainerRe: [PATCH v7 14/45] x86/compressed: Add helper for validating pages in the decompression stage
Quoted 8 lines · Brijesh Singh
arch/x86/boot/compressed/ident_map_64.c +0
-0@@ -275,15 +275,31 @@ static int set_clr_page_flags(struct x86_mapping_info *info,* Changing encryption attributes of a page requires to flush it from * the caches. */
arch/x86/boot/compressed/ident_map_64.c static int set_clr_page_flags(struct x86_mapping_info *info, · line 286
Quoted 10 lines
arch/x86/boot/compressed/ident_map_64.c +7
-1-if ((set | clr) & _PAGE_ENC) +if ((set | clr) & _PAGE_ENC) {clflush_page (address); +/* +* If the encryption attribute is being cleared, then change +* the page state to shared in the RMP table. +*/ +if (clr) +snp_set_page_shared (pte_pfn (*ptep) <<PAGE_SHIFT );
So I'm wondering: __page_state_change() wants a physical address and you're reading it out from the PTE here.
Why not do
__pa(address & PAGE_MASK);
like it is usually done?
And those macros are right there at the top of ident_map_64.c with an explanation that we're ident-mapped here so pa == va...
arch/x86/boot/compressed/ident_map_64.c static int set_clr_page_flags(struct x86_mapping_info *info, · line 297
Quoted 11 lines
arch/x86/boot/compressed/ident_map_64.c +5
-0+ } +/* Update PTE */ pte = *ptep; pte =pte_set_flags (pte, set); pte =pte_clear_flags (pte, clr);set_pte (ptep, pte); +/* +* If the encryption attribute is being set, then change the page state to +* private in the RMP entry. The page state must be done after the PTE
^ change
Quoted 8 lines
arch/x86/boot/compressed/ident_map_64.c +5
-0+* is updated. +*/ +if (set & _PAGE_ENC) +snp_set_page_private (pte_pfn (*ptep) <<PAGE_SHIFT ); +/* Flush TLB after changing encryption attribute */ write_cr3 (top_level_pgt);
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v7 14/45] x86/compressed: Add helper for validating pages in the decompression stage
Quoted 23 lines · Borislav Petkov
Quoted 8 lines · Brijesh Singh
arch/x86/boot/compressed/ident_map_64.c +0
-0@@ -275,15 +275,31 @@ static int set_clr_page_flags(struct x86_mapping_info *info,* Changing encryption attributes of a page requires to flush it from * the caches. */ arch/x86/boot/compressed/ident_map_64.c static int set_clr_page_flags(struct x86_mapping_info *info, · line 286
Quoted 10 lines
arch/x86/boot/compressed/ident_map_64.c +7
-1-if ((set | clr) & _PAGE_ENC) +if ((set | clr) & _PAGE_ENC) {clflush_page (address); +/* +* If the encryption attribute is being cleared, then change +* the page state to shared in the RMP table. +*/ +if (clr) +snp_set_page_shared (pte_pfn (*ptep) <<PAGE_SHIFT );So I'm wondering:
__page_state_change()wants a physical address and you're reading it out from the PTE here.
Quoted 5 lines
Why not do
__pa(address & PAGE_MASK);like it is usually done?
I am okay to use __pa().
thanks
PATCH v7 15/45 x86/compressed: Register GHCB memory when SEV-SNP is active
In reply to Brijesh SinghThe SEV-SNP guest is required to perform GHCB GPA registration. This is because the hypervisor may prefer that a guest use a consistent and/or specific GPA for the GHCB associated with a vCPU. For more information, see the GHCB specification.
If hypervisor can not work with the guest provided GPA then terminate the guest boot.
--- arch/x86/boot/compressed/sev.c | 4 ++++ arch/x86/include/asm/sev-common.h | 13 +++++++++++++ arch/x86/kernel/sev-shared.c | 16 ++++++++++++++++ 3 files changed, 33 insertions(+)
arch/x86/boot/compressed/sev.c +4 -0
@@ -217,6 +217,10 @@ static bool do_early_sev_setup(void)/* Initialize lookup tables for the instruction decoder */ inat_init_tables (); +/* SEV-SNP guest requires the GHCB GPA must be registered */ +if (sev_snp_enabled ()) +snp_register_ghcb_early (__pa (&boot_ghcb_page)); +return true; }
arch/x86/include/asm/sev-common.h +13 -0
@@ -57,6 +57,19 @@#define GHCB_MSR_AP_RESET_HOLD_REQ 0x006#define GHCB_MSR_AP_RESET_HOLD_RESP 0x007 +/* GHCB GPA Register */ +#define GHCB_MSR_REG_GPA_REQ 0x012 +#define GHCB_MSR_REG_GPA_REQ_VAL(v) \ + /* GHCBData[63:12] */ \ + (((u64)((v) & GENMASK_ULL(51, 0)) << 12) | \ + /* GHCBData[11:0] */ \ +GHCB_MSR_REG_GPA_REQ ) + +#define GHCB_MSR_REG_GPA_RESP 0x013 +#define GHCB_MSR_REG_GPA_RESP_VAL (v) \ +/* GHCBData[63:12] */ \ + (((u64)(v) & GENMASK_ULL(63, 12)) >> 12) +/* * SNP Page State Change Operation *
arch/x86/kernel/sev-shared.c +16 -0
@@ -75,6 +75,22 @@ static bool get_hv_features(void)return true; } +static void snp_register_ghcb_early (unsigned long paddr) +{ +unsigned long pfn = paddr >>PAGE_SHIFT ; +u64 val; + +sev_es_wr_ghcb_msr (GHCB_MSR_REG_GPA_REQ_VAL (pfn)); +VMGEXIT (); + + val =sev_es_rd_ghcb_msr (); + +/* If the response GPA is not ours then abort the guest */ +if ((GHCB_RESP_CODE (val) !=GHCB_MSR_REG_GPA_RESP ) || + (GHCB_MSR_REG_GPA_RESP_VAL (val) != pfn)) +sev_es_terminate (SEV_TERM_SET_LINUX ,GHCB_TERM_REGISTER ); +} +static bool sev_es_negotiate_protocol (void ) {u64 val;
Signature · 1 line
2.25.1
Re: [PATCH v7 15/45] x86/compressed: Register GHCB memory when SEV-SNP is active
Quoted 1 line · Brijesh Singh
+static void
snp_register_ghcb_early(unsigned long paddr)
This needs __maybe_unused, otherwise it triggers a warning:
arch/x86/kernel/sev-shared.c:78:13: warning: ‘snp_register_ghcb_early’ defined but not used [-Wunused-function]
78 | static void snp_register_ghcb_early(unsigned long paddr)
| ^~~~~~~~~~~~~~~~~~~~~~~
PATCH v7 16/45 x86/sev: Register GHCB memory when SEV-SNP is active
In reply to Brijesh SinghThe SEV-SNP guest is required to perform GHCB GPA registration. This is because the hypervisor may prefer that a guest use a consistent and/or specific GPA for the GHCB associated with a vCPU. For more information, see the GHCB specification section GHCB GPA Registration.
During the boot, init_ghcb() allocates a per-cpu GHCB page. On very first VC exception, the exception handler switch to using the per-cpu GHCB page allocated during the init_ghcb(). The GHCB page must be registered in the current vcpu context.
--- arch/x86/include/asm/sev.h | 2 + arch/x86/kernel/cpu/common.c | 5 ++ arch/x86/kernel/head64.c | 3 + arch/x86/kernel/sev.c | 116 ++++++++++++++++++++--------------- 4 files changed, 77 insertions(+), 49 deletions(-)
arch/x86/include/asm/sev.h +2 -0
@@ -122,6 +122,7 @@ static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool validate) return rc; } +void sev_snp_register_ghcb (void );#else static inline void sev_es_ist_enter (struct pt_regs *regs) { }static inline void sev_es_ist_exit (void ) { }
@@ -130,6 +131,7 @@ static inline void sev_es_nmi_complete(void) { }static inline int sev_es_efi_map_ghcbs (pgd_t *pgd) {return 0 ; }static inline int pvalidate (unsigned long vaddr,bool rmp_psize,bool validate) {return 0 ; }static inline int rmpadjust (unsigned long vaddr,bool rmp_psize,unsigned long attrs) {return 0 ; } +static inline void sev_snp_register_ghcb (void ) { }#endif #endif
arch/x86/kernel/cpu/common.c +5 -0
@@ -59,6 +59,7 @@#include <asm/cpu_device_id.h> #include <asm/uv/uv.h> #include <asm/sigframe.h> +#include <asm/sev.h> #include "cpu.h"
@@ -1977,6 +1978,10 @@ void cpu_init_exception_handling(void)load_TR_desc (); +/* Register the GHCB before taking any VC exception */ +if (IS_ENABLED (CONFIG_AMD_MEM_ENCRYPT )) +sev_snp_register_ghcb (); +/* Finally load the IDT */ load_current_idt (); }
arch/x86/kernel/head64.c +3 -0
@@ -588,6 +588,9 @@ void early_setup_idt(void) bringup_idt_descr.address = (unsigned long )bringup_idt_table;native_load_idt (&bringup_idt_descr); + +if (IS_ENABLED (CONFIG_AMD_MEM_ENCRYPT )) +sev_snp_register_ghcb (); }/*
arch/x86/kernel/sev.c +67 -49
140 lines not on this page · raw message
Signature · 1 line
2.25.1
Borislav Petkov
maintainerRe: [PATCH v7 16/45] x86/sev: Register GHCB memory when SEV-SNP is active
Quoted 7 lines · Brijesh Singh
The SEV-SNP guest is required to perform GHCB GPA registration. This is because the hypervisor may prefer that a guest use a consistent and/or specific GPA for the GHCB associated with a vCPU. For more information, see the GHCB specification section GHCB GPA Registration.
During the boot,
init_ghcb()allocates a per-cpu GHCB page. On very first VC exception,
That is not true anymore - you're doing proper init at init time - no more #VC hackery.
arch/x86/kernel/cpu/common.c void cpu_init_exception_handling(void) · line 1982
Quoted 6 lines
arch/x86/kernel/cpu/common.c +2
-0@@ -1977,6 +1978,10 @@ void cpu_init_exception_handling(void)load_TR_desc (); +/* Register the GHCB before taking any VC exception */ +if (IS_ENABLED (CONFIG_AMD_MEM_ENCRYPT ))
No need for that if branch - sev_snp_register_ghcb() already has an empty stub for the !CONFIG_AMD_MEM_ENCRYPT case so you can simply call it unconditionally.
Quoted 10 lines
arch/x86/kernel/cpu/common.c +2
-0+sev_snp_register_ghcb (); +/* Finally load the IDT */ load_current_idt (); }arch/x86/kernel/head64.c +0
-0
arch/x86/kernel/head64.c void early_setup_idt(void) · line 593
Quoted 6 lines
arch/x86/kernel/head64.c +3
-0@@ -588,6 +588,9 @@ void early_setup_idt(void) bringup_idt_descr.address = (unsigned long )bringup_idt_table;native_load_idt (&bringup_idt_descr); + +if (IS_ENABLED (CONFIG_AMD_MEM_ENCRYPT )) +sev_snp_register_ghcb ();
Ditto.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePATCH v7 17/45 x86/sev: Add helper for validating pages in early enc attribute changes
In reply to Brijesh SinghThe early_set_memory_{encrypt,decrypt}() are used for changing the page from decrypted (shared) to encrypted (private) and vice versa. When SEV-SNP is active, the page state transition needs to go through additional steps.
If the page is transitioned from shared to private, then perform the following after the encryption attribute is set in the page table:
1. Issue the page state change VMGEXIT to add the page as a private in the RMP table.
2. Validate the page after its successfully added in the RMP table.
To maintain the security guarantees, if the page is transitioned from private to shared, then perform the following before clearing the encryption attribute from the page table.
1. Invalidate the page.
2. Issue the page state change VMGEXIT to make the page shared in the RMP table.
The early_set_memory_{encrypt,decrypt} can be called before the GHCB is setup, use the SNP page state MSR protocol VMGEXIT defined in the GHCB specification to request the page state change in the RMP table.
While at it, add a helper snp_prep_memory() that can be used outside the sev specific files to change the page state for a specified memory range.
--- arch/x86/include/asm/sev.h | 10 ++++ arch/x86/kernel/sev.c | 102 +++++++++++++++++++++++++++++++++++++ arch/x86/mm/mem_encrypt.c | 51 +++++++++++++++++-- 3 files changed, 159 insertions(+), 4 deletions(-)
arch/x86/include/asm/sev.h +10 -0
@@ -123,6 +123,11 @@ static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool validate) return rc; }void sev_snp_register_ghcb (void ); +void __init early_snp_set_memory_private (unsigned long vaddr,unsigned long paddr, +unsigned int npages); +void __init early_snp_set_memory_shared (unsigned long vaddr,unsigned long paddr, +unsigned int npages); +void __init snp_prep_memory (unsigned long paddr,unsigned int sz,enum psc_op op);#else static inline void sev_es_ist_enter (struct pt_regs *regs) { }static inline void sev_es_ist_exit (void ) { }
@@ -132,6 +137,11 @@ static inline int sev_es_efi_map_ghcbs(pgd_t *pgd) { return 0; }static inline int pvalidate (unsigned long vaddr,bool rmp_psize,bool validate) {return 0 ; }static inline int rmpadjust (unsigned long vaddr,bool rmp_psize,unsigned long attrs) {return 0 ; }static inline void sev_snp_register_ghcb (void ) { } +static inline void __init +early_snp_set_memory_private (unsigned long vaddr,unsigned long paddr,unsigned int npages) { } +static inline void __init +early_snp_set_memory_shared (unsigned long vaddr,unsigned long paddr,unsigned int npages) { } +static inline void __init snp_prep_memory (unsigned long paddr,unsigned int sz,enum psc_op op) { }#endif #endif
arch/x86/kernel/sev.c +102 -0
108 lines not on this page · raw message
arch/x86/mm/mem_encrypt.c +47 -4
81 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v7 18/45 x86/kernel: Make the bss.decrypted section shared in RMP table
In reply to Brijesh SinghThe encryption attribute for the bss.decrypted region is cleared in the initial page table build. This is because the section contains the data that need to be shared between the guest and the hypervisor.
When SEV-SNP is active, just clearing the encryption attribute in the page table is not enough. The page state need to be updated in the RMP table.
--- arch/x86/kernel/head64.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/x86/kernel/head64.c +7 -0
@@ -143,7 +143,14 @@ static unsigned long sme_postprocess_startup(struct boot_params *bp, pmdval_t *pif (sme_get_me_mask ()) { vaddr = (unsigned long )__start_bss_decrypted; vaddr_end = (unsigned long )__end_bss_decrypted; +for (; vaddr < vaddr_end; vaddr +=PMD_SIZE ) { +/* +* When SEV-SNP is active then transition the page to shared in the RMP +* table so that it is consistent with the page table attribute change. +*/ +early_snp_set_memory_shared (__pa (vaddr),__pa (vaddr),PTRS_PER_PMD ); + i =pmd_index (vaddr); pmd[i] -=sme_get_me_mask (); }
Signature · 1 line
2.25.1
PATCH v7 19/45 x86/kernel: Validate rom memory before accessing when SEV-SNP is active
In reply to Brijesh SinghThe probe_roms() access the memory range (0xc0000 - 0x10000) to probe various ROMs. The memory range is not part of the E820 system RAM range. The memory range is mapped as private (i.e encrypted) in page table.
When SEV-SNP is active, all the private memory must be validated before the access. The ROM range was not part of E820 map, so the guest BIOS did not validate it. An access to invalidated memory will cause a VC exception. The guest does not support handling not-validated VC exception yet, so validate the ROM memory regions before it is accessed.
--- arch/x86/kernel/probe_roms.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
arch/x86/kernel/probe_roms.c +12 -1
@@ -21,6 +21,7 @@#include <asm/sections.h> #include <asm/io.h> #include <asm/setup_arch.h> +#include <asm/sev.h> static struct resource system_rom_resource = { .name ="System ROM" ,
@@ -197,11 +198,21 @@ static int __init romchecksum(const unsigned char *rom, unsigned long length)void __init probe_roms (void ) { -const unsigned char *rom;unsigned long start, length, upper; +const unsigned char *rom;unsigned char c;int i; +/* +* The ROM memory is not part of the E820 system RAM and is not pre-validated +* by the BIOS. The kernel page table maps the ROM region as encrypted memory, +* the SEV-SNP requires the encrypted memory must be validated before the +* access. Validate the ROM before accessing it. +*/ +snp_prep_memory (video_rom_resource.start, + ((system_rom_resource.end +1 ) - video_rom_resource.start), +SNP_PAGE_STATE_PRIVATE ); +/* video rom */ upper = adapter_rom_resources[0 ].start;for (start = video_rom_resource.start; start < upper; start +=2048 ) {
Signature · 1 line
2.25.1
PATCH v7 20/45 x86/mm: Add support to validate memory when changing C-bit
In reply to Brijesh SinghThe set_memory_{encrypt,decrypt}() are used for changing the pages from decrypted (shared) to encrypted (private) and vice versa. When SEV-SNP is active, the page state transition needs to go through additional steps.
If the page is transitioned from shared to private, then perform the following after the encryption attribute is set in the page table:
1. Issue the page state change VMGEXIT to add the memory region in the RMP table.
2. Validate the memory region after the RMP entry is added.
To maintain the security guarantees, if the page is transitioned from private to shared, then perform the following before encryption attribute is removed from the page table:
1. Invalidate the page.
2. Issue the page state change VMGEXIT to remove the page from RMP table.
To change the page state in the RMP table, use the Page State Change VMGEXIT defined in the GHCB specification.
The GHCB specification provides the flexibility to use either 4K or 2MB page size in during the page state change (PSC) request. For now use the 4K page size for all the PSC until page size tracking is supported in the kernel.
--- arch/x86/include/asm/sev-common.h | 22 ++++ arch/x86/include/asm/sev.h | 4 + arch/x86/include/asm/svm.h | 4 +- arch/x86/include/uapi/asm/svm.h | 2 + arch/x86/kernel/sev.c | 161 +++++++++++++++++++++++++++++- arch/x86/mm/pat/set_memory.c | 15 +++ 6 files changed, 204 insertions(+), 4 deletions(-)
arch/x86/include/asm/sev-common.h +22 -0
@@ -105,6 +105,28 @@ enum psc_op {#define GHCB_HV_FT_SNP BIT_ULL(0) +/* SNP Page State Change NAE event */ +#define VMGEXIT_PSC_MAX_ENTRY 253 + +struct psc_hdr { +u16 cur_entry; +u16 end_entry; +u32 reserved; +} __packed; + +struct psc_entry { +u64 cur_page :12 , + gfn :40 , + operation :4 , + pagesize :1 , + reserved :7 ; +} __packed; + +struct snp_psc_desc { +struct psc_hdr hdr; +struct psc_entry entries[VMGEXIT_PSC_MAX_ENTRY ]; +} __packed; +#define GHCB_MSR_TERM_REQ 0x100#define GHCB_MSR_TERM_REASON_SET_POS 12#define GHCB_MSR_TERM_REASON_SET_MASK 0xf
arch/x86/include/asm/sev.h +4 -0
@@ -128,6 +128,8 @@ void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long paddvoid __init early_snp_set_memory_shared (unsigned long vaddr,unsigned long paddr,unsigned int npages);void __init snp_prep_memory (unsigned long paddr,unsigned int sz,enum psc_op op); +void snp_set_memory_shared (unsigned long vaddr,unsigned int npages); +void snp_set_memory_private (unsigned long vaddr,unsigned int npages);#else static inline void sev_es_ist_enter (struct pt_regs *regs) { }static inline void sev_es_ist_exit (void ) { }
@@ -142,6 +144,8 @@ early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr, unsignedstatic inline void __init early_snp_set_memory_shared (unsigned long vaddr,unsigned long paddr,unsigned int npages) { }static inline void __init snp_prep_memory (unsigned long paddr,unsigned int sz,enum psc_op op) { } +static inline void snp_set_memory_shared (unsigned long vaddr,unsigned int npages) { } +static inline void snp_set_memory_private (unsigned long vaddr,unsigned int npages) { }#endif #endif
arch/x86/include/asm/svm.h +3 -1
@@ -309,11 +309,13 @@ struct vmcb_save_area {u64 x87_state_gpa; } __packed; +#define GHCB_SHARED_BUF_SIZE 2032 +struct ghcb {struct vmcb_save_area save;u8 reserved_save[2048 -sizeof (struct vmcb_save_area )]; -u8 shared_buffer[2032 ]; +u8 shared_buffer[GHCB_SHARED_BUF_SIZE ];u8 reserved_1[10 ];u16 protocol_version;/* negotiated SEV-ES/GHCB protocol version */
arch/x86/include/uapi/asm/svm.h +2 -0
@@ -108,6 +108,7 @@#define SVM_VMGEXIT_AP_JUMP_TABLE 0x80000005#define SVM_VMGEXIT_SET_AP_JUMP_TABLE 0#define SVM_VMGEXIT_GET_AP_JUMP_TABLE 1 +#define SVM_VMGEXIT_PSC 0x80000010#define SVM_VMGEXIT_HV_FEATURES 0x8000fffd#define SVM_VMGEXIT_UNSUPPORTED_EVENT 0x8000ffff
@@ -219,6 +220,7 @@ { SVM_VMGEXIT_NMI_COMPLETE, "vmgexit_nmi_complete" }, \ { SVM_VMGEXIT_AP_HLT_LOOP, "vmgexit_ap_hlt_loop" }, \ { SVM_VMGEXIT_AP_JUMP_TABLE, "vmgexit_ap_jump_table" }, \ + { SVM_VMGEXIT_PSC, "vmgexit_page_state_change" }, \ { SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, \ { SVM_EXIT_ERR, "invalid_guest_state" }
arch/x86/kernel/sev.c +158 -3
185 lines not on this page · raw message
arch/x86/mm/pat/set_memory.c +15 -0
@@ -30,6 +30,7 @@#include <asm/proto.h> #include <asm/memtype.h> #include <asm/set_memory.h> +#include <asm/sev.h> #include "../mm_internal.h"
@@ -2010,8 +2011,22 @@ static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc)*/ cpa_flush (&cpa, !this_cpu_has (X86_FEATURE_SME_COHERENT )); +/* +* To maintain the security guarantees of SEV-SNP guest invalidate the memory +* before clearing the encryption attribute. +*/ +if (!enc) +snp_set_memory_shared (addr, numpages); + ret =__change_page_attr_set_clr (&cpa,1 ); +/* +* Now that memory is mapped encrypted in the page table, validate it +* so that is consistent with the above page state. +*/ +if (!ret && enc) +snp_set_memory_private (addr, numpages); +/* * After changing the encryption attribute, we need to flush TLBs again * in case any speculative TLB caching occurred (but no need to flush
Signature · 1 line
2.25.1
PATCH v7 21/45 KVM: SVM: Define sev_features and vmpl field in the VMSA
In reply to Brijesh SinghThe hypervisor uses the sev_features field (offset 3B0h) in the Save State Area to control the SEV-SNP guest features such as SNPActive, vTOM, ReflectVC etc. An SEV-SNP guest can read the SEV_FEATURES fields through the SEV_STATUS MSR.
While at it, update the dump_vmcb() to log the VMPL level.
See APM2 Table 15-34 and B-4 for more details.
--- arch/x86/include/asm/svm.h | 6 ++++-- arch/x86/kvm/svm/svm.c | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-)
arch/x86/include/asm/svm.h +4 -2
@@ -238,7 +238,8 @@ struct vmcb_save_area {struct vmcb_seg ldtr;struct vmcb_seg idtr;struct vmcb_seg tr; -u8 reserved_1[43 ]; +u8 reserved_1[42 ]; +u8 vmpl;u8 cpl;u8 reserved_2[4 ];u64 efer;
@@ -303,7 +304,8 @@ struct vmcb_save_area {u64 sw_exit_info_1;u64 sw_exit_info_2;u64 sw_scratch; -u8 reserved_11[56 ]; +u64 sev_features; +u8 reserved_11[48 ];u64 xcr0;u8 valid_bitmap[16 ];u64 x87_state_gpa;
arch/x86/kvm/svm/svm.c +2 -2
@@ -3211,8 +3211,8 @@ static void dump_vmcb(struct kvm_vcpu *vcpu)"tr:" , save01->tr.selector, save01->tr.attrib, save01->tr.limit, save01->tr.base); -pr_err ("cpl: %d efer: %016llx\n" , - save->cpl, save->efer); +pr_err ("vmpl: %d cpl: %d efer: %016llx\n" , + save->vmpl, save->cpl, save->efer);pr_err ("%-15s %016llx %-13s %016llx\n" ,"cr0:" , save->cr0,"cr2:" , save->cr2); pr_err("%-15s %016llx %-13s %016llx\n",
Signature · 1 line
2.25.1
PATCH v7 22/45 KVM: SVM: Create a separate mapping for the SEV-ES save area
In reply to Brijesh SinghFrom: Tom Lendacky <[email protected]>
The save area for SEV-ES/SEV-SNP guests, as used by the hardware, is different from the save area of a non SEV-ES/SEV-SNP guest.
This is the first step in defining the multiple save areas to keep them separate and ensuring proper operation amongst the different types of guests. Create an SEV-ES/SEV-SNP save area and adjust usage to the new save area definition where needed.
--- arch/x86/include/asm/svm.h | 83 +++++++++++++++++++++++++++++--------- arch/x86/kvm/svm/sev.c | 24 +++++------ arch/x86/kvm/svm/svm.h | 2 +- 3 files changed, 77 insertions(+), 32 deletions(-)
arch/x86/include/asm/svm.h +64 -19
@@ -227,6 +227,7 @@ struct vmcb_seg {u64 base; } __packed; +/* Save area definition for legacy and SEV-MEM guests */ struct vmcb_save_area {struct vmcb_seg es;struct vmcb_seg cs;
@@ -243,8 +244,58 @@ struct vmcb_save_area {u8 cpl;u8 reserved_2[4 ];u64 efer; +u8 reserved_3[112 ]; +u64 cr4; +u64 cr3; +u64 cr0; +u64 dr7; +u64 dr6; +u64 rflags; +u64 rip; +u8 reserved_4[88 ]; +u64 rsp; +u64 s_cet; +u64 ssp; +u64 isst_addr; +u64 rax; +u64 star; +u64 lstar; +u64 cstar; +u64 sfmask; +u64 kernel_gs_base; +u64 sysenter_cs; +u64 sysenter_esp; +u64 sysenter_eip; +u64 cr2; +u8 reserved_5[32 ]; +u64 g_pat; +u64 dbgctl; +u64 br_from; +u64 br_to; +u64 last_excp_from; +u64 last_excp_to; +u8 reserved_6[72 ]; +u32 spec_ctrl;/* Guest version of SPEC_CTRL at 0x2E0 */ +} __packed; + +/* Save area definition for SEV-ES and SEV-SNP guests */ +struct sev_es_save_area { +struct vmcb_seg es; +struct vmcb_seg cs; +struct vmcb_seg ss; +struct vmcb_seg ds; +struct vmcb_seg fs; +struct vmcb_seg gs; +struct vmcb_seg gdtr; +struct vmcb_seg ldtr; +struct vmcb_seg idtr; +struct vmcb_seg tr; +u8 reserved_1[43 ]; +u8 cpl; +u8 reserved_2[4 ]; +u64 efer;u8 reserved_3[104 ]; -u64 xss;/* Valid for SEV-ES only */ +u64 xss;u64 cr4;u64 cr3;u64 cr0;
@@ -272,22 +323,14 @@ struct vmcb_save_area {u64 br_to;u64 last_excp_from;u64 last_excp_to; - -/* -* The following part of the save area is valid only for -* SEV-ES guests when referenced through the GHCB or for -* saving to the host save area. -*/ -u8 reserved_7[72 ]; -u32 spec_ctrl;/* Guest version of SPEC_CTRL at 0x2E0 */ -u8 reserved_7b[4 ]; +u8 reserved_7[80 ];u32 pkru; -u8 reserved_7a[20 ]; -u64 reserved_8;/* rax already available at 0x01f8 */ +u8 reserved_9[20 ]; +u64 reserved_10;/* rax already available at 0x01f8 */ u64 rcx;u64 rdx;u64 rbx; -u64 reserved_9;/* rsp already available at 0x01d8 */ +u64 reserved_11;/* rsp already available at 0x01d8 */ u64 rbp;u64 rsi;u64 rdi;
@@ -299,13 +342,13 @@ struct vmcb_save_area {u64 r13;u64 r14;u64 r15; -u8 reserved_10[16 ]; +u8 reserved_12[16 ];u64 sw_exit_code;u64 sw_exit_info_1;u64 sw_exit_info_2;u64 sw_scratch;u64 sev_features; -u8 reserved_11[48 ]; +u8 reserved_13[48 ];u64 xcr0;u8 valid_bitmap[16 ];u64 x87_state_gpa;
@@ -314,8 +357,8 @@ struct vmcb_save_area {#define GHCB_SHARED_BUF_SIZE 2032struct ghcb { -struct vmcb_save_area save; -u8 reserved_save[2048 -sizeof (struct vmcb_save_area )]; +struct sev_es_save_area save; +u8 reserved_save[2048 -sizeof (struct sev_es_save_area )];u8 shared_buffer[GHCB_SHARED_BUF_SIZE ];
@@ -325,13 +368,15 @@ struct ghcb { } __packed; -#define EXPECTED_VMCB_SAVE_AREA_SIZE 1032 +#define EXPECTED_VMCB_SAVE_AREA_SIZE 740 +#define EXPECTED_SEV_ES_SAVE_AREA_SIZE 1032#define EXPECTED_VMCB_CONTROL_AREA_SIZE 1024#define EXPECTED_GHCB_SIZE PAGE_SIZEstatic inline void __unused_size_checks (void ) {BUILD_BUG_ON (sizeof (struct vmcb_save_area ) !=EXPECTED_VMCB_SAVE_AREA_SIZE ); +BUILD_BUG_ON (sizeof (struct sev_es_save_area ) !=EXPECTED_SEV_ES_SAVE_AREA_SIZE );BUILD_BUG_ON (sizeof (struct vmcb_control_area ) !=EXPECTED_VMCB_CONTROL_AREA_SIZE );BUILD_BUG_ON (sizeof (struct ghcb ) !=EXPECTED_GHCB_SIZE ); }
@@ -401,7 +446,7 @@ struct vmcb {/* GHCB Accessor functions */ #define GHCB_BITMAP_IDX (field) \ - (offsetof(struct vmcb_save_area, field) / sizeof(u64)) + (offsetof(struct sev_es_save_area, field) / sizeof(u64))#define DEFINE_GHCB_ACCESSORS (field) \ static inline bool ghcb_##field##_is_valid(const struct ghcb *ghcb) \
arch/x86/kvm/svm/sev.c +12 -12
@@ -551,12 +551,20 @@ static int sev_launch_update_data(struct kvm *kvm, struct kvm_sev_cmd *argp)static int sev_es_sync_vmsa (struct vcpu_svm *svm) { -struct vmcb_save_area *save = &svm->vmcb->save; +struct sev_es_save_area *save = svm->vmsa;/* Check some debug related fields before encrypting the VMSA */ -if (svm->vcpu.guest_debug || (save->dr7 & ~DR7_FIXED_1 )) +if (svm->vcpu.guest_debug || (svm->vmcb->save.dr7 & ~DR7_FIXED_1 ))return -EINVAL ; +/* +* SEV-ES will use a VMSA that is pointed to by the VMCB, not +* the traditional VMSA that is part of the VMCB. Copy the +* traditional VMSA as it has been built so far (in prep +* for LAUNCH_UPDATE_VMSA) to be the initial SEV-ES state. +*/ +memcpy (save, &svm->vmcb->save,sizeof (svm->vmcb->save)); +/* Sync registgers */ save->rax = svm->vcpu.arch.regs[VCPU_REGS_RAX ]; save->rbx = svm->vcpu.arch.regs[VCPU_REGS_RBX ];
@@ -584,14 +592,6 @@ static int sev_es_sync_vmsa(struct vcpu_svm *svm) save->xss = svm->vcpu.arch.ia32_xss; save->dr6 = svm->vcpu.arch.dr6; -/* -* SEV-ES will use a VMSA that is pointed to by the VMCB, not -* the traditional VMSA that is part of the VMCB. Copy the -* traditional VMSA as it has been built so far (in prep -* for LAUNCH_UPDATE_VMSA) to be the initial SEV-ES state. -*/ -memcpy (svm->vmsa, save,sizeof (*save)); -return 0 ; }
@@ -2666,7 +2666,7 @@ void sev_es_create_vcpu(struct vcpu_svm *svm)void sev_es_prepare_guest_switch (struct vcpu_svm *svm,unsigned int cpu) {struct svm_cpu_data *sd =per_cpu (svm_data, cpu); -struct vmcb_save_area *hostsa; +struct sev_es_save_area *hostsa;/* * As an SEV-ES guest, hardware will restore the host state on VMEXIT,
@@ -2676,7 +2676,7 @@ void sev_es_prepare_guest_switch(struct vcpu_svm *svm, unsigned int cpu)vmsave (__sme_page_pa (sd->save_area));/* XCR0 is restored on VMEXIT, save the current host value */ - hostsa = (struct vmcb_save_area *)(page_address (sd->save_area) +0x400 ); + hostsa = (struct sev_es_save_area *)(page_address (sd->save_area) +0x400 ); hostsa->xcr0 =xgetbv (XCR_XFEATURE_ENABLED_MASK );/* PKRU is restored on VMEXIT, save the current host value */
arch/x86/kvm/svm/svm.h +1 -1
@@ -184,7 +184,7 @@ struct vcpu_svm { } shadow_msr_intercept;/* SEV-ES support */ -struct vmcb_save_area *vmsa; +struct sev_es_save_area *vmsa;struct ghcb *ghcb;struct kvm_host_map ghcb_map;bool received_first_sipi;
Signature · 1 line
2.25.1
PATCH v7 23/45 KVM: SVM: Create a separate mapping for the GHCB save area
In reply to Brijesh SinghFrom: Tom Lendacky <[email protected]>
The initial implementation of the GHCB spec was based on trying to keep the register state offsets the same relative to the VM save area. However, the save area for SEV-ES has changed within the hardware causing the relation between the SEV-ES save area to change relative to the GHCB save area.
This is the second step in defining the multiple save areas to keep them separate and ensuring proper operation amongst the different types of guests. Create a GHCB save area that matches the GHCB specification.
--- arch/x86/include/asm/svm.h | 48 +++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-)
arch/x86/include/asm/svm.h +45 -3
@@ -354,11 +354,51 @@ struct sev_es_save_area {u64 x87_state_gpa; } __packed; +struct ghcb_save_area { +u8 reserved_1[203 ]; +u8 cpl; +u8 reserved_2[116 ]; +u64 xss; +u8 reserved_3[24 ]; +u64 dr7; +u8 reserved_4[16 ]; +u64 rip; +u8 reserved_5[88 ]; +u64 rsp; +u8 reserved_6[24 ]; +u64 rax; +u8 reserved_7[264 ]; +u64 rcx; +u64 rdx; +u64 rbx; +u8 reserved_8[8 ]; +u64 rbp; +u64 rsi; +u64 rdi; +u64 r8; +u64 r9; +u64 r10; +u64 r11; +u64 r12; +u64 r13; +u64 r14; +u64 r15; +u8 reserved_9[16 ]; +u64 sw_exit_code; +u64 sw_exit_info_1; +u64 sw_exit_info_2; +u64 sw_scratch; +u8 reserved_10[56 ]; +u64 xcr0; +u8 valid_bitmap[16 ]; +u64 x87_state_gpa; +} __packed; +#define GHCB_SHARED_BUF_SIZE 2032struct ghcb { -struct sev_es_save_area save; -u8 reserved_save[2048 -sizeof (struct sev_es_save_area )]; +struct ghcb_save_area save; +u8 reserved_save[2048 -sizeof (struct ghcb_save_area )];u8 shared_buffer[GHCB_SHARED_BUF_SIZE ];
@@ -369,6 +409,7 @@ struct ghcb {#define EXPECTED_VMCB_SAVE_AREA_SIZE 740 +#define EXPECTED_GHCB_SAVE_AREA_SIZE 1032#define EXPECTED_SEV_ES_SAVE_AREA_SIZE 1032#define EXPECTED_VMCB_CONTROL_AREA_SIZE 1024#define EXPECTED_GHCB_SIZE PAGE_SIZE
@@ -376,6 +417,7 @@ struct ghcb {static inline void __unused_size_checks (void ) {BUILD_BUG_ON (sizeof (struct vmcb_save_area ) !=EXPECTED_VMCB_SAVE_AREA_SIZE ); +BUILD_BUG_ON (sizeof (struct ghcb_save_area ) !=EXPECTED_GHCB_SAVE_AREA_SIZE );BUILD_BUG_ON (sizeof (struct sev_es_save_area ) !=EXPECTED_SEV_ES_SAVE_AREA_SIZE );BUILD_BUG_ON (sizeof (struct vmcb_control_area ) !=EXPECTED_VMCB_CONTROL_AREA_SIZE );BUILD_BUG_ON (sizeof (struct ghcb ) !=EXPECTED_GHCB_SIZE );
@@ -446,7 +488,7 @@ struct vmcb {/* GHCB Accessor functions */ #define GHCB_BITMAP_IDX (field) \ - (offsetof(struct sev_es_save_area, field) / sizeof(u64)) + (offsetof(struct ghcb_save_area, field) / sizeof(u64))#define DEFINE_GHCB_ACCESSORS (field) \ static inline bool ghcb_##field##_is_valid(const struct ghcb *ghcb) \
Signature · 1 line
2.25.1
PATCH v7 24/45 KVM: SVM: Update the SEV-ES save area mapping
In reply to Brijesh SinghFrom: Tom Lendacky <[email protected]>
This is the final step in defining the multiple save areas to keep them separate and ensuring proper operation amongst the different types of guests. Update the SEV-ES/SEV-SNP save area to match the APM. This save area will be used for the upcoming SEV-SNP AP Creation NAE event support.
--- arch/x86/include/asm/svm.h | 66 +++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 16 deletions(-)
arch/x86/include/asm/svm.h +50 -16
@@ -290,7 +290,13 @@ struct sev_es_save_area {struct vmcb_seg ldtr;struct vmcb_seg idtr;struct vmcb_seg tr; -u8 reserved_1[43 ]; +u64 vmpl0_ssp; +u64 vmpl1_ssp; +u64 vmpl2_ssp; +u64 vmpl3_ssp; +u64 u_cet; +u8 reserved_1[2 ]; +u8 vmpl;u8 cpl;u8 reserved_2[4 ];u64 efer;
@@ -303,9 +309,19 @@ struct sev_es_save_area {u64 dr6;u64 rflags;u64 rip; -u8 reserved_4[88 ]; +u64 dr0; +u64 dr1; +u64 dr2; +u64 dr3; +u64 dr0_addr_mask; +u64 dr1_addr_mask; +u64 dr2_addr_mask; +u64 dr3_addr_mask; +u8 reserved_4[24 ];u64 rsp; -u8 reserved_5[24 ]; +u64 s_cet; +u64 ssp; +u64 isst_addr;u64 rax;u64 star;u64 lstar;
@@ -316,7 +332,7 @@ struct sev_es_save_area {u64 sysenter_esp;u64 sysenter_eip;u64 cr2; -u8 reserved_6[32 ]; +u8 reserved_5[32 ];u64 g_pat;u64 dbgctl;u64 br_from;
@@ -325,12 +341,12 @@ struct sev_es_save_area {u64 last_excp_to;u8 reserved_7[80 ];u32 pkru; -u8 reserved_9[20 ]; -u64 reserved_10;/* rax already available at 0x01f8 */ +u8 reserved_8[20 ]; +u64 reserved_9;/* rax already available at 0x01f8 */ u64 rcx;u64 rdx;u64 rbx; -u64 reserved_11;/* rsp already available at 0x01d8 */ +u64 reserved_10;/* rsp already available at 0x01d8 */ u64 rbp;u64 rsi;u64 rdi;
@@ -342,16 +358,34 @@ struct sev_es_save_area {u64 r13;u64 r14;u64 r15; -u8 reserved_12[16 ]; -u64 sw_exit_code; -u64 sw_exit_info_1; -u64 sw_exit_info_2; -u64 sw_scratch; +u8 reserved_11[16 ]; +u64 guest_exit_info_1; +u64 guest_exit_info_2; +u64 guest_exit_int_info; +u64 guest_nrip;u64 sev_features; -u8 reserved_13[48 ]; +u64 vintr_ctrl; +u64 guest_exit_code; +u64 virtual_tom; +u64 tlb_id; +u64 pcpu_id; +u64 event_inj;u64 xcr0; -u8 valid_bitmap[16 ]; -u64 x87_state_gpa; +u8 reserved_12[16 ]; + +/* Floating point area */ +u64 x87_dp; +u32 mxcsr; +u16 x87_ftw; +u16 x87_fsw; +u16 x87_fcw; +u16 x87_fop; +u16 x87_ds; +u16 x87_cs; +u64 x87_rip; +u8 fpreg_x87[80 ]; +u8 fpreg_xmm[256 ]; +u8 fpreg_ymm[256 ]; } __packed;struct ghcb_save_area {
@@ -410,7 +444,7 @@ struct ghcb {#define EXPECTED_VMCB_SAVE_AREA_SIZE 740#define EXPECTED_GHCB_SAVE_AREA_SIZE 1032 -#define EXPECTED_SEV_ES_SAVE_AREA_SIZE 1032 +#define EXPECTED_SEV_ES_SAVE_AREA_SIZE 1648#define EXPECTED_VMCB_CONTROL_AREA_SIZE 1024#define EXPECTED_GHCB_SIZE PAGE_SIZE
Signature · 1 line
2.25.1
PATCH v7 25/45 x86/sev: Use SEV-SNP AP creation to start secondary CPUs
In reply to Brijesh SinghFrom: Tom Lendacky <[email protected]>
To provide a more secure way to start APs under SEV-SNP, use the SEV-SNP AP Creation NAE event. This allows for guest control over the AP register state rather than trusting the hypervisor with the SEV-ES Jump Table address.
During native_smp_prepare_cpus(), invoke an SEV-SNP function that, if SEV-SNP is active, will set/override apic->wakeup_secondary_cpu. This will allow the SEV-SNP AP Creation NAE event method to be used to boot the APs. As a result of installing the override when SEV-SNP is active, this method of starting the APs becomes the required method. The override function will fail to start the AP if the hypervisor does not have support for AP creation.
--- arch/x86/include/asm/sev-common.h | 1 + arch/x86/include/asm/sev.h | 4 + arch/x86/include/uapi/asm/svm.h | 5 + arch/x86/kernel/sev.c | 229 ++++++++++++++++++++++++++++++ arch/x86/kernel/smpboot.c | 3 + 5 files changed, 242 insertions(+)
arch/x86/include/asm/sev-common.h +1 -0
@@ -104,6 +104,7 @@ enum psc_op { (((u64)(v) & GENMASK_ULL(63, 12)) >> 12)#define GHCB_HV_FT_SNP BIT_ULL(0) +#define GHCB_HV_FT_SNP_AP_CREATION (BIT_ULL(1) | GHCB_HV_FT_SNP)/* SNP Page State Change NAE event */ #define VMGEXIT_PSC_MAX_ENTRY 253
arch/x86/include/asm/sev.h +4 -0
@@ -66,6 +66,8 @@ extern bool handle_vc_boot_ghcb(struct pt_regs *regs);/* RMP page size */ #define RMP_PG_SIZE_4K 0 +#define RMPADJUST_VMSA_PAGE_BIT BIT(16) +#ifdef CONFIG_AMD_MEM_ENCRYPT extern struct static_key_false sev_es_enable_key;extern void __sev_es_ist_enter (struct pt_regs *regs);
@@ -130,6 +132,7 @@ void __init early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddrvoid __init snp_prep_memory (unsigned long paddr,unsigned int sz,enum psc_op op);void snp_set_memory_shared (unsigned long vaddr,unsigned int npages);void snp_set_memory_private (unsigned long vaddr,unsigned int npages); +void snp_set_wakeup_secondary_cpu (void );#else static inline void sev_es_ist_enter (struct pt_regs *regs) { }static inline void sev_es_ist_exit (void ) { }
@@ -146,6 +149,7 @@ early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr, unsigned istatic inline void __init snp_prep_memory (unsigned long paddr,unsigned int sz,enum psc_op op) { }static inline void snp_set_memory_shared (unsigned long vaddr,unsigned int npages) { }static inline void snp_set_memory_private (unsigned long vaddr,unsigned int npages) { } +static inline void snp_set_wakeup_secondary_cpu (void ) { }#endif #endif
arch/x86/include/uapi/asm/svm.h +5 -0
@@ -109,6 +109,10 @@#define SVM_VMGEXIT_SET_AP_JUMP_TABLE 0#define SVM_VMGEXIT_GET_AP_JUMP_TABLE 1#define SVM_VMGEXIT_PSC 0x80000010 +#define SVM_VMGEXIT_AP_CREATION 0x80000013 +#define SVM_VMGEXIT_AP_CREATE_ON_INIT 0 +#define SVM_VMGEXIT_AP_CREATE 1 +#define SVM_VMGEXIT_AP_DESTROY 2#define SVM_VMGEXIT_HV_FEATURES 0x8000fffd#define SVM_VMGEXIT_UNSUPPORTED_EVENT 0x8000ffff
@@ -221,6 +225,7 @@ { SVM_VMGEXIT_AP_HLT_LOOP, "vmgexit_ap_hlt_loop" }, \ { SVM_VMGEXIT_AP_JUMP_TABLE, "vmgexit_ap_jump_table" }, \ { SVM_VMGEXIT_PSC, "vmgexit_page_state_change" }, \ + { SVM_VMGEXIT_AP_CREATION, "vmgexit_ap_creation" }, \ { SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, \ { SVM_EXIT_ERR, "invalid_guest_state" }
arch/x86/kernel/sev.c +229 -0
253 lines not on this page · raw message
arch/x86/kernel/smpboot.c +3 -0
@@ -82,6 +82,7 @@#include <asm/spec-ctrl.h> #include <asm/hw_irq.h> #include <asm/stackprotector.h> +#include <asm/sev.h> #ifdef CONFIG_ACPI_CPPC_LIB #include <acpi/cppc_acpi.h>
@@ -1419,6 +1420,8 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)smp_quirk_init_udelay ();speculative_store_bypass_ht_init (); + +snp_set_wakeup_secondary_cpu (); }void arch_thaw_secondary_cpus_begin (void )
Signature · 1 line
2.25.1
PATCH v7 26/45 x86/head: re-enable stack protection for 32/64-bit builds
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
As of commit 103a4908ad4d ("x86/head/64: Disable stack protection for head$(BITS).o") kernel/head64.c is compiled with -fno-stack-protector to allow a call to set_bringup_idt_handler(), which would otherwise have stack protection enabled with CONFIG_STACKPROTECTOR_STRONG. While sufficient for that case, there may still be issues with calls to any external functions that were compiled with stack protection enabled that in-turn make stack-protected calls, or if the exception handlers set up by set_bringup_idt_handler() make calls to stack-protected functions. As part of 103a4908ad4d, stack protection was also disabled for kernel/head32.c as a precaution.
Subsequent patches for SEV-SNP CPUID validation support will introduce both such cases. Attempting to disable stack protection for everything in scope to address that is prohibitive since much of the code, like SEV-ES #VC handler, is shared code that remains in use after boot and could benefit from having stack protection enabled. Attempting to inline calls is brittle and can quickly balloon out to library/helper code where that's not really an option.
Instead, re-enable stack protection for head32.c/head64.c and make the appropriate changes to ensure the segment used for the stack canary is initialized in advance of any stack-protected C calls.
for head64.c:
- The BSP will enter from startup_64 and call into C code (startup_64_setup_env) shortly after setting up the stack, which may result in calls to stack-protected code. Set up %gs early to allow for this safely.
- APs will enter from secondary_startup_64*, and %gs will be set up soon after. There is one call to C code prior to this (__startup_secondary_64), but it is only to fetch sme_me_mask, and unlikely to be stack-protected, so leave things as they are, but add a note about this in case things change in the future.
for head32.c:
- BSPs/APs will set %fs to __BOOT_DS prior to any C calls. In recent kernels, the compiler is configured to access the stack canary at %fs:__stack_chk_guard, which overlaps with the initial per-cpu __stack_chk_guard variable in the initial/'master' .data..percpu area. This is sufficient to allow access to the canary for use during initial startup, so no changes are needed there.
--- arch/x86/kernel/Makefile | 1 - arch/x86/kernel/head_64.S | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-)
arch/x86/kernel/Makefile +0 -1
@@ -48,7 +48,6 @@ endif # non-deterministic coverage. KCOV_INSTRUMENT := n -CFLAGS_head$(BITS).o += -fno-stack-protector CFLAGS_cc_platform.o += -fno-stack-protector CFLAGS_irq.o := -I $(srctree)/$(src)/../include/asm/trace
arch/x86/kernel/head_64.S +24 -0
@@ -65,6 +65,22 @@ SYM_CODE_START_NOALIGN(startup_64) leaq (__end_init_task - FRAME_SIZE)(%rip), %rsp leaq _text(%rip), %rdi + + /* + * initial_gs points to initial fixed_per_cpu struct with storage for + * the stack protector canary. Global pointer fixups are needed at this + * stage, so apply them as is done in fixup_pointer(), and initialize %gs + * such that the canary can be accessed at %gs:40 for subsequent C calls. + */ + movl $MSR_GS_BASE, %ecx + movq initial_gs(%rip), %rax + movq $_text, %rdx + subq %rdx, %rax + addq %rdi, %rax + movq %rax, %rdx + shrq $32, %rdx + wrmsr + pushq %rsi call startup_64_setup_env popq %rsi
@@ -133,6 +149,14 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL) * added to the initial pgdir entry that will be programmed into CR3. */ pushq %rsi + /* + * NOTE: %gs at this point is a stale data segment left over from the + * real-mode trampoline, so the default stack protector canary location + * at %gs:40 does not yet coincide with the expected fixed_per_cpu struct + * that contains storage for the stack canary. So take care not to add + * anything to the C functions in this path that would result in stack + * protected C code being generated. + */ call __startup_secondary_64 popq %rsi
Signature · 1 line
2.25.1
PATCH v7 27/45 x86/sev: move MSR-based VMGEXITs for CPUID to helper
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
This code will also be used later for SEV-SNP-validated CPUID code in some cases, so move it to a common helper.
--- arch/x86/kernel/sev-shared.c | 84 +++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 26 deletions(-)
arch/x86/kernel/sev-shared.c +58 -26
@@ -204,6 +204,58 @@ enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, bool set_ghcb_msr,return verify_exception_info (ghcb, ctxt); } +static int sev_cpuid_hv (u32 func,u32 subfunc,u32 *eax,u32 *ebx, +u32 *ecx,u32 *edx) +{ +u64 val; + +if (eax) { +sev_es_wr_ghcb_msr (GHCB_CPUID_REQ (func,GHCB_CPUID_REQ_EAX )); +VMGEXIT (); + val =sev_es_rd_ghcb_msr (); + +if (GHCB_RESP_CODE (val) !=GHCB_MSR_CPUID_RESP ) +return -EIO ; + + *eax = (val >>32 ); + } + +if (ebx) { +sev_es_wr_ghcb_msr (GHCB_CPUID_REQ (func,GHCB_CPUID_REQ_EBX )); +VMGEXIT (); + val =sev_es_rd_ghcb_msr (); + +if (GHCB_RESP_CODE (val) !=GHCB_MSR_CPUID_RESP ) +return -EIO ; + + *ebx = (val >>32 ); + } + +if (ecx) { +sev_es_wr_ghcb_msr (GHCB_CPUID_REQ (func,GHCB_CPUID_REQ_ECX )); +VMGEXIT (); + val =sev_es_rd_ghcb_msr (); + +if (GHCB_RESP_CODE (val) !=GHCB_MSR_CPUID_RESP ) +return -EIO ; + + *ecx = (val >>32 ); + } + +if (edx) { +sev_es_wr_ghcb_msr (GHCB_CPUID_REQ (func,GHCB_CPUID_REQ_EDX )); +VMGEXIT (); + val =sev_es_rd_ghcb_msr (); + +if (GHCB_RESP_CODE (val) !=GHCB_MSR_CPUID_RESP ) +return -EIO ; + + *edx = (val >>32 ); + } + +return 0 ; +} +/* * Boot VC Handler - This is the first VC handler during boot, there is no GHCB * page yet, so it only supports the MSR based communication with the
@@ -212,39 +264,19 @@ enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, bool set_ghcb_msr,void __init do_vc_no_ghcb (struct pt_regs *regs,unsigned long exit_code) {unsigned int fn =lower_bits (regs->ax,32 ); -unsigned long val; +u32 eax, ebx, ecx, edx;/* Only CPUID is supported via MSR protocol */ if (exit_code !=SVM_EXIT_CPUID ) goto fail; -sev_es_wr_ghcb_msr (GHCB_CPUID_REQ (fn,GHCB_CPUID_REQ_EAX )); -VMGEXIT (); - val =sev_es_rd_ghcb_msr (); -if (GHCB_RESP_CODE (val) !=GHCB_MSR_CPUID_RESP ) +if (sev_cpuid_hv (fn,0 , &eax, &ebx, &ecx, &edx)) goto fail; - regs->ax = val >>32 ; -sev_es_wr_ghcb_msr (GHCB_CPUID_REQ (fn,GHCB_CPUID_REQ_EBX )); -VMGEXIT (); - val =sev_es_rd_ghcb_msr (); -if (GHCB_RESP_CODE (val) !=GHCB_MSR_CPUID_RESP ) - goto fail; - regs->bx = val >>32 ; - -sev_es_wr_ghcb_msr (GHCB_CPUID_REQ (fn,GHCB_CPUID_REQ_ECX )); -VMGEXIT (); - val =sev_es_rd_ghcb_msr (); -if (GHCB_RESP_CODE (val) !=GHCB_MSR_CPUID_RESP ) - goto fail; - regs->cx = val >>32 ; - -sev_es_wr_ghcb_msr (GHCB_CPUID_REQ (fn,GHCB_CPUID_REQ_EDX )); -VMGEXIT (); - val =sev_es_rd_ghcb_msr (); -if (GHCB_RESP_CODE (val) !=GHCB_MSR_CPUID_RESP ) - goto fail; - regs->dx = val >>32 ; + regs->ax = eax; + regs->bx = ebx; + regs->cx = ecx; + regs->dx = edx;/* * This is a VC handler and the #VC is only raised when SEV-ES is
Signature · 1 line
2.25.1
PATCH v7 28/45 KVM: x86: move lookup of indexed CPUID leafs to helper
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
Determining which CPUID leafs have significant ECX/index values is also needed by guest kernel code when doing SEV-SNP-validated CPUID lookups. Move this to common code to keep future updates in sync.
--- arch/x86/include/asm/cpuid.h | 26 ++++++++++++++++++++++++++ arch/x86/kvm/cpuid.c | 17 ++--------------- 2 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 arch/x86/include/asm/cpuid.h
arch/x86/include/asm/cpuid.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_CPUID_H +#define _ASM_X86_CPUID_H + +static __always_inline bool cpuid_function_is_indexed(u32 function) +{ +switch (function) { +case 4 : +case 7 : +case 0xb : +case 0xd : +case 0xf : +case 0x10 : +case 0x12 : +case 0x14 : +case 0x17 : +case 0x18 : +case 0x1f : +case 0x8000001d : +return true; + } + +return false; +} + +#endif /* _ASM_X86_CPUID_H */
arch/x86/kvm/cpuid.c +2 -15
@@ -19,6 +19,7 @@#include <asm/user.h> #include <asm/fpu/xstate.h> #include <asm/sgx.h> +#include <asm/cpuid.h> #include "cpuid.h" #include "lapic.h" #include "mmu.h"
@@ -582,22 +583,8 @@ static struct kvm_cpuid_entry2 *do_host_cpuid(struct kvm_cpuid_array *array,cpuid_count (entry->function, entry->index, &entry->eax, &entry->ebx, &entry->ecx, &entry->edx); -switch (function) { -case 4 : -case 7 : -case 0xb : -case 0xd : -case 0xf : -case 0x10 : -case 0x12 : -case 0x14 : -case 0x17 : -case 0x18 : -case 0x1f : -case 0x8000001d : +if (cpuid_function_is_indexed (function)) entry->flags |=KVM_CPUID_FLAG_SIGNIFCANT_INDEX ; -break ; - }return entry; }
Signature · 1 line
2.25.1
PATCH v7 29/45 x86/compressed/acpi: move EFI system table lookup to helper
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
Future patches for SEV-SNP-validated CPUID will also require early parsing of the EFI configuration. Incrementally move the related code into a set of helpers that can be re-used for that purpose.
--- arch/x86/boot/compressed/Makefile | 1 + arch/x86/boot/compressed/acpi.c | 60 ++++++++++---------------- arch/x86/boot/compressed/efi.c | 71 +++++++++++++++++++++++++++++++ arch/x86/boot/compressed/misc.h | 14 ++++++ 4 files changed, 108 insertions(+), 38 deletions(-) create mode 100644 arch/x86/boot/compressed/efi.c
arch/x86/boot/compressed/Makefile +1 -0
@@ -100,6 +100,7 @@ endif vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o +vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o efi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a $(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE
arch/x86/boot/compressed/acpi.c +22 -38
93 lines not on this page · raw message
arch/x86/boot/compressed/efi.c new file +71 -0
71 lines not on this page · raw message
arch/x86/boot/compressed/misc.h +14 -0
@@ -23,6 +23,7 @@#include <linux/screen_info.h> #include <linux/elf.h> #include <linux/io.h> +#include <linux/efi.h> #include <asm/page.h> #include <asm/boot.h> #include <asm/bootparam.h>
@@ -176,4 +177,17 @@ void boot_stage2_vc(void);unsigned long sev_verify_cbit (unsigned long cr3); +#ifdef CONFIG_EFI +/* helpers for early EFI config table access */ +int efi_get_system_table (struct boot_params *boot_params, +unsigned long *sys_tbl_pa,bool *is_efi_64); +#else +static inline int +efi_get_system_table (struct boot_params *boot_params, +unsigned long *sys_tbl_pa,bool *is_efi_64) +{ +return -ENOENT ; +} +#endif /* CONFIG_EFI */ +#endif /* BOOT_COMPRESSED_MISC_H */
Signature · 1 line
2.25.1
PATCH v7 30/45 x86/compressed/acpi: move EFI config table lookup to helper
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
Future patches for SEV-SNP-validated CPUID will also require early parsing of the EFI configuration. Incrementally move the related code into a set of helpers that can be re-used for that purpose.
--- arch/x86/boot/compressed/acpi.c | 25 ++++++-------------- arch/x86/boot/compressed/efi.c | 42 +++++++++++++++++++++++++++++++++ arch/x86/boot/compressed/misc.h | 9 +++++++ 3 files changed, 58 insertions(+), 18 deletions(-)
arch/x86/boot/compressed/acpi.c +7 -18
@@ -117,8 +117,9 @@ static acpi_physical_address kexec_get_rsdp_addr(void) { return 0; }static acpi_physical_address efi_get_rsdp_addr (void ) {#ifdef CONFIG_EFI -unsigned long systab_tbl_pa, config_tables; -unsigned int nr_tables; +unsigned long cfg_tbl_pa =0 ; +unsigned long systab_tbl_pa; +unsigned int cfg_tbl_len;bool efi_64;int ret;
@@ -134,23 +135,11 @@ static acpi_physical_address efi_get_rsdp_addr(void)if (ret)error ("EFI support advertised, but unable to locate system table." ); -/* Handle EFI bitness properly */ -if (efi_64) { -efi_system_table_64_t *stbl = (efi_system_table_64_t *)systab_tbl_pa; + ret =efi_get_conf_table (boot_params, &cfg_tbl_pa, &cfg_tbl_len, &efi_64); +if (ret || !cfg_tbl_pa) +error ("EFI config table not found." ); - config_tables = stbl->tables; - nr_tables = stbl->nr_tables; - }else { -efi_system_table_32_t *stbl = (efi_system_table_32_t *)systab_tbl_pa; - - config_tables = stbl->tables; - nr_tables = stbl->nr_tables; - } - -if (!config_tables) -error ("EFI config tables not found." ); - -return __efi_get_rsdp_addr (config_tables, nr_tables, efi_64); +return __efi_get_rsdp_addr (cfg_tbl_pa, cfg_tbl_len, efi_64);#else return 0 ;#endif
arch/x86/boot/compressed/efi.c +42 -0
45 lines not on this page · raw message
arch/x86/boot/compressed/misc.h +9 -0
@@ -181,6 +181,8 @@ unsigned long sev_verify_cbit(unsigned long cr3);/* helpers for early EFI config table access */ int efi_get_system_table (struct boot_params *boot_params,unsigned long *sys_tbl_pa,bool *is_efi_64); +int efi_get_conf_table (struct boot_params *boot_params,unsigned long *cfg_tbl_pa, +unsigned int *cfg_tbl_len,bool *is_efi_64);#else static inline int efi_get_system_table(struct boot_params *boot_params,
@@ -188,6 +190,13 @@ efi_get_system_table(struct boot_params *boot_params, {return -ENOENT ; } + +static inline int +efi_get_conf_table (struct boot_params *boot_params,unsigned long *cfg_tbl_pa, +unsigned int *cfg_tbl_len,bool *is_efi_64) +{ +return -ENOENT ; +}#endif /* CONFIG_EFI */ #endif /* BOOT_COMPRESSED_MISC_H */
Signature · 1 line
2.25.1
PATCH v7 31/45 x86/compressed/acpi: move EFI vendor table lookup to helper
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
Future patches for SEV-SNP-validated CPUID will also require early parsing of the EFI configuration. Incrementally move the related code into a set of helpers that can be re-used for that purpose.
--- arch/x86/boot/compressed/acpi.c | 50 ++++++++----------------- arch/x86/boot/compressed/efi.c | 65 +++++++++++++++++++++++++++++++++ arch/x86/boot/compressed/misc.h | 9 +++++ 3 files changed, 90 insertions(+), 34 deletions(-)
arch/x86/boot/compressed/acpi.c +16 -34
@@ -20,46 +20,28 @@*/ struct mem_vector immovable_mem[MAX_NUMNODES *2 ]; -/* -* Search EFI system tables for RSDP. If both ACPI_20_TABLE_GUID and -* ACPI_TABLE_GUID are found, take the former, which has more features. -*/ static acpi_physical_address -__efi_get_rsdp_addr (unsigned long config_tables,unsigned int nr_tables, -bool efi_64) +__efi_get_rsdp_addr (unsigned long cfg_tbl_pa,unsigned int cfg_tbl_len,bool efi_64) {acpi_physical_address rsdp_addr =0 ;#ifdef CONFIG_EFI -int i; - -/* Get EFI tables from systab. */ -for (i =0 ; i < nr_tables; i++) { -acpi_physical_address table; -efi_guid_t guid; - -if (efi_64) { -efi_config_table_64_t *tbl = (efi_config_table_64_t *)config_tables + i; - - guid = tbl->guid; - table = tbl->table; - -if (!IS_ENABLED (CONFIG_X86_64 ) && table >>32 ) { -debug_putstr ("Error getting RSDP address: EFI config table located above 4GB.\n" ); -return 0 ; - } - }else { -efi_config_table_32_t *tbl = (efi_config_table_32_t *)config_tables + i; - - guid = tbl->guid; - table = tbl->table; - } +int ret; -if (!(efi_guidcmp (guid,ACPI_TABLE_GUID ))) - rsdp_addr = table; -else if (!(efi_guidcmp (guid,ACPI_20_TABLE_GUID ))) -return table; - } +/* +* Search EFI system tables for RSDP. Preferred is ACPI_20_TABLE_GUID to +* ACPI_TABLE_GUID because it has more features. +*/ + ret =efi_find_vendor_table (cfg_tbl_pa, cfg_tbl_len,ACPI_20_TABLE_GUID , + efi_64, (unsigned long *)&rsdp_addr); +if (!ret) +return rsdp_addr; + +/* No ACPI_20_TABLE_GUID found, fallback to ACPI_TABLE_GUID. */ + ret =efi_find_vendor_table (cfg_tbl_pa, cfg_tbl_len,ACPI_TABLE_GUID , + efi_64, (unsigned long *)&rsdp_addr); +if (ret) +debug_putstr ("Error getting RSDP address.\n" );#endif return rsdp_addr; }
arch/x86/boot/compressed/efi.c +65 -0
68 lines not on this page · raw message
arch/x86/boot/compressed/misc.h +9 -0
@@ -183,6 +183,8 @@ int efi_get_system_table(struct boot_params *boot_params, unsigned long *sys_tbl_pa, bool *is_efi_64);int efi_get_conf_table (struct boot_params *boot_params,unsigned long *cfg_tbl_pa,unsigned int *cfg_tbl_len,bool *is_efi_64); +int efi_find_vendor_table (unsigned long cfg_tbl_pa,unsigned int cfg_tbl_len, +efi_guid_t guid,bool efi_64,unsigned long *vendor_tbl_pa);#else static inline int efi_get_system_table(struct boot_params *boot_params,
@@ -197,6 +199,13 @@ efi_get_conf_table(struct boot_params *boot_params, unsigned long *cfg_tbl_pa, {return -ENOENT ; } + +static inline int +efi_find_vendor_table (unsigned long cfg_tbl_pa,unsigned int cfg_tbl_len, +efi_guid_t guid,bool efi_64,unsigned long *vendor_tbl_pa) +{ +return -ENOENT ; +}#endif /* CONFIG_EFI */ #endif /* BOOT_COMPRESSED_MISC_H */
Signature · 1 line
2.25.1
PATCH v7 32/45 x86/boot: Add Confidential Computing type to setup_data
In reply to Brijesh SinghWhile launching the encrypted guests, the hypervisor may need to provide some additional information during the guest boot. When booting under the EFI based BIOS, the EFI configuration table contains an entry for the confidential computing blob that contains the required information.
To support booting encrypted guests on non-EFI VM, the hypervisor needs to pass this additional information to the kernel with a different method.
For this purpose, introduce SETUP_CC_BLOB type in setup_data to hold the physical address of the confidential computing blob location. The boot loader or hypervisor may choose to use this method instead of EFI configuration table. The CC blob location scanning should give preference to setup_data data over the EFI configuration table.
In AMD SEV-SNP, the CC blob contains the address of the secrets and CPUID pages. The secrets page includes information such as a VM to PSP communication key and CPUID page contains PSP filtered CPUID values. Define the AMD SEV confidential computing blob structure.
While at it, define the EFI GUID for the confidential computing blob.
--- arch/x86/include/asm/sev.h | 12 ++++++++++++ arch/x86/include/uapi/asm/bootparam.h | 1 + include/linux/efi.h | 1 + 3 files changed, 14 insertions(+)
arch/x86/include/asm/sev.h +12 -0
@@ -44,6 +44,18 @@ struct es_em_ctxt {void do_vc_no_ghcb (struct pt_regs *regs,unsigned long exit_code); +/* AMD SEV Confidential computing blob structure */ +#define CC_BLOB_SEV_HDR_MAGIC 0x45444d41 +struct cc_blob_sev_info { +u32 magic; +u16 version; +u16 reserved; +u64 secrets_phys; +u32 secrets_len; +u64 cpuid_phys; +u32 cpuid_len; +}; +static inline u64 lower_bits (u64 val,unsigned int bits) {u64 mask = (1ULL << bits) -1 ;
arch/x86/include/uapi/asm/bootparam.h +1 -0
@@ -10,6 +10,7 @@#define SETUP_EFI 4#define SETUP_APPLE_PROPERTIES 5#define SETUP_JAILHOUSE 6 +#define SETUP_CC_BLOB 7#define SETUP_INDIRECT (1<<31)
include/linux/efi.h +1 -0
@@ -344,6 +344,7 @@ void efi_native_runtime_setup(void);#define EFI_CERT_SHA256_GUID EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, 0x41, 0xf9, 0x36, 0x93, 0x43, 0x28)#define EFI_CERT_X509_GUID EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72)#define EFI_CERT_X509_SHA256_GUID EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed) +#define EFI_CC_BLOB_GUID EFI_GUID(0x067b1f5f, 0xcf26, 0x44c5, 0x85, 0x54, 0x93, 0xd7, 0x77, 0x91, 0x2d, 0x42)/* * This GUID is used to pass to the kernel proper the struct screen_info
Signature · 1 line
2.25.1
PATCH v7 33/45 KVM: SEV: Add documentation for SEV-SNP CPUID Enforcement
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
Update the documentation with SEV-SNP CPUID enforcement.
--- .../virt/kvm/amd-memory-encryption.rst | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+)
Documentation/virt/kvm/amd-memory-encryption.rst +28 -0
@@ -427,6 +427,34 @@ issued by the hypervisor to make the guest ready for execution. Returns: 0 on success, -negative on error +SEV-SNP CPUID Enforcement +========================= + +SEV-SNP guests can access a special page that contains a table of CPUID values +that have been validated by the PSP as part of SNP_LAUNCH_UPDATE firmware +command. It provides the following assurances regarding the validity of CPUID +values: + + - Its address is obtained via bootloader/firmware (via CC blob), whose + binares will be measured as part of the SEV-SNP attestation report. + - Its initial state will be encrypted/pvalidated, so attempts to modify + it during run-time will be result in garbage being written, or #VC + exceptions being generated due to changes in validation state if the + hypervisor tries to swap the backing page. + - Attempts to bypass PSP checks by hypervisor by using a normal page, or a + non-CPUID encrypted page will change the measurement provided by the + SEV-SNP attestation report. + - The CPUID page contents are *not* measured, but attempts to modify the + expected contents of a CPUID page as part of guest initialization will be + gated by the PSP CPUID enforcement policy checks performed on the page + during SNP_LAUNCH_UPDATE, and noticeable later if the guest owner + implements their own checks of the CPUID values. + +It is important to note that this last assurance is only useful if the kernel +has taken care to make use of the SEV-SNP CPUID throughout all stages of boot. +Otherwise guest owner attestation provides no assurance that the kernel wasn't +fed incorrect values at some point during boot. + References ==========
Signature · 1 line
2.25.1
PATCH v7 34/45 x86/compressed/64: add support for SEV-SNP CPUID table in #VC handlers
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
CPUID instructions generate a #VC exception for SEV-ES/SEV-SNP guests, for which early handlers are currently set up to handle. In the case of SEV-SNP, guests can use a configurable location in guest memory that has been pre-populated with a firmware-validated CPUID table to look up the relevant CPUID values rather than requesting them from hypervisor via a VMGEXIT. Add the various hooks in the #VC handlers to allow CPUID instructions to be handled via the table. The code to actually configure/enable the table will be added in a subsequent commit.
--- arch/x86/boot/compressed/sev.c | 1 + arch/x86/include/asm/sev-common.h | 2 + arch/x86/kernel/sev-shared.c | 320 ++++++++++++++++++++++++++++++ arch/x86/kernel/sev.c | 1 + 4 files changed, 324 insertions(+)
arch/x86/boot/compressed/sev.c +1 -0
@@ -20,6 +20,7 @@#include <asm/fpu/xcr.h> #include <asm/ptrace.h> #include <asm/svm.h> +#include <asm/cpuid.h> #include "error.h"
arch/x86/include/asm/sev-common.h +2 -0
@@ -152,6 +152,8 @@ struct snp_psc_desc {#define GHCB_TERM_PSC 1/* Page State Change failure */ #define GHCB_TERM_PVALIDATE 2/* Pvalidate failure */ #define GHCB_TERM_NOT_VMPL0 3/* SNP guest is not running at VMPL-0 */ +#define GHCB_TERM_CPUID 4/* CPUID-validation failure */ +#define GHCB_TERM_CPUID_HV 5/* CPUID failure during hypervisor fallback */ #define GHCB_RESP_CODE (v) ((v) & GHCB_MSR_INFO_MASK)
arch/x86/kernel/sev-shared.c +320 -0
366 lines not on this page · raw message
arch/x86/kernel/sev.c +1 -0
@@ -33,6 +33,7 @@#include <asm/smp.h> #include <asm/cpu.h> #include <asm/apic.h> +#include <asm/cpuid.h> #define DR7_RESET_VALUE 0x400
Signature · 1 line
2.25.1
PATCH v7 35/45 x86/boot: add a pointer to Confidential Computing blob in bootparams
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
The previously defined Confidential Computing blob is provided to the kernel via a setup_data structure or EFI config table entry. Currently these are both checked for by boot/compressed kernel to access the CPUID table address within it for use with SEV-SNP CPUID enforcement.
To also enable SEV-SNP CPUID enforcement for the run-time kernel, similar early access to the CPUID table is needed early on while it's still using the identity-mapped page table set up by boot/compressed, where global pointers need to be accessed via fixup_pointer().
This isn't much of an issue for accessing setup_data, and the EFI config table helper code currently used in boot/compressed *could* be used in this case as well since they both rely on identity-mapping. However, it has some reliance on EFI helpers/string constants that would need to be accessed via fixup_pointer(), and fixing it up while making it shareable between boot/compressed and run-time kernel is fragile and introduces a good bit of uglyness.
Instead, add a boot_params->cc_blob_address pointer that the boot/compressed kernel can initialize so that the run-time kernel can access the CC blob from there instead of re-scanning the EFI config table.
--- arch/x86/include/asm/bootparam_utils.h | 1 + arch/x86/include/uapi/asm/bootparam.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
arch/x86/include/asm/bootparam_utils.h +1 -0
@@ -74,6 +74,7 @@ static void sanitize_boot_params(struct boot_params *boot_params)BOOT_PARAM_PRESERVE (hdr),BOOT_PARAM_PRESERVE (e820_table),BOOT_PARAM_PRESERVE (eddbuf), +BOOT_PARAM_PRESERVE (cc_blob_address), };memset (&scratch,0 ,sizeof (scratch));
arch/x86/include/uapi/asm/bootparam.h +2 -1
@@ -188,7 +188,8 @@ struct boot_params {__u32 ext_ramdisk_image;/* 0x0c0 */ __u32 ext_ramdisk_size;/* 0x0c4 */ __u32 ext_cmd_line_ptr;/* 0x0c8 */ -__u8 _pad4[116 ];/* 0x0cc */ +__u8 _pad4[112 ];/* 0x0cc */ +__u32 cc_blob_address;/* 0x13c */ struct edid_info edid_info;/* 0x140 */ struct efi_info efi_info;/* 0x1c0 */ __u32 alt_mem_k;/* 0x1e0 */
Signature · 1 line
2.25.1
PATCH v7 36/45 x86/compressed: add SEV-SNP feature detection/setup
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
Initial/preliminary detection of SEV-SNP is done via the Confidential Computing blob. Check for it prior to the normal SEV/SME feature initialization, and add some sanity checks to confirm it agrees with SEV-SNP CPUID/MSR bits.
--- arch/x86/boot/compressed/sev.c | 90 +++++++++++++++++++++++++++++++++- arch/x86/include/asm/sev.h | 13 +++++ arch/x86/kernel/sev-shared.c | 34 +++++++++++++ 3 files changed, 136 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/sev.c +89 -1
@@ -305,6 +305,13 @@ static inline u64 rd_sev_status_msr(void)void sev_enable (struct boot_params *bp) {unsigned int eax, ebx, ecx, edx; +bool snp; + +/* +* Setup/preliminary detection of SEV-SNP. This will be sanity-checked +* against CPUID/MSR values later. +*/ + snp =snp_init (bp);/* Check for the SME/SEV support leaf */ eax =0x80000000 ;
@@ -325,14 +332,95 @@ void sev_enable(struct boot_params *bp) ecx =0 ;native_cpuid (&eax, &ebx, &ecx, &edx);/* Check whether SEV is supported */ -if (!(eax &BIT (1 ))) +if (!(eax &BIT (1 ))) { +if (snp) +error ("SEV-SNP support indicated by CC blob, but not CPUID." );return ; + }/* Check the SEV MSR whether SEV or SME is enabled */ sev_status =rd_sev_status_msr ();if (!(sev_status &MSR_AMD64_SEV_ENABLED ))error ("SEV support indicated by CPUID, but not SEV status MSR." ); +if (snp && !(sev_status &MSR_AMD64_SEV_SNP_ENABLED )) +error ("SEV-SNP supported indicated by CC blob, but not SEV status MSR." ); sme_me_mask =1UL << (ebx &0x3f ); } + +/* Search for Confidential Computing blob in the EFI config table. */ +static struct cc_blob_sev_info *snp_find_cc_blob_efi (struct boot_params *bp) +{ +struct cc_blob_sev_info *cc_info; +unsigned long conf_table_pa; +unsigned int conf_table_len; +bool efi_64; +int ret; + + ret =efi_get_conf_table (bp, &conf_table_pa, &conf_table_len, &efi_64); +if (ret) +return NULL ; + + ret =efi_find_vendor_table (conf_table_pa, conf_table_len, +EFI_CC_BLOB_GUID , efi_64, + (unsigned long *)&cc_info); +if (ret) +return NULL ; + +return cc_info; +} + +/* +* Initial set up of SEV-SNP relies on information provided by the +* Confidential Computing blob, which can be passed to the boot kernel +* by firmware/bootloader in the following ways: +* +* - via an entry in the EFI config table +* - via a setup_data structure, as defined by the Linux Boot Protocol +* +* Scan for the blob in that order. +*/ +struct cc_blob_sev_info *snp_find_cc_blob (struct boot_params *bp) +{ +struct cc_blob_sev_info *cc_info; + + cc_info =snp_find_cc_blob_efi (bp); +if (cc_info) + goto found_cc_info; + + cc_info =snp_find_cc_blob_setup_data (bp); +if (!cc_info) +return NULL ; + +found_cc_info: +if (cc_info->magic !=CC_BLOB_SEV_HDR_MAGIC ) +sev_es_terminate (0 ,GHCB_SNP_UNSUPPORTED ); + +return cc_info; +} + +bool snp_init (struct boot_params *bp) +{ +struct cc_blob_sev_info *cc_info; + +if (!bp) +return false; + + cc_info =snp_find_cc_blob (bp); +if (!cc_info) +return false; + +/* +* Pass run-time kernel a pointer to CC info via boot_params so EFI +* config table doesn't need to be searched again during early startup +* phase. +*/ + bp->cc_blob_address = (u32 )(unsigned long )cc_info; + +/* +* Indicate SEV-SNP based on presence of SEV-SNP-specific CC blob. +* Subsequent checks will verify SEV-SNP CPUID/MSR bits. +*/ +return true; +}
arch/x86/include/asm/sev.h +13 -0
@@ -11,6 +11,7 @@#include <linux/types.h> #include <asm/insn.h> #include <asm/sev-common.h> +#include <asm/bootparam.h> #define GHCB_PROTOCOL_MIN 1ULL#define GHCB_PROTOCOL_MAX 2ULL
@@ -145,6 +146,17 @@ void __init snp_prep_memory(unsigned long paddr, unsigned int sz, enum psc_op opvoid snp_set_memory_shared (unsigned long vaddr,unsigned int npages);void snp_set_memory_private (unsigned long vaddr,unsigned int npages);void snp_set_wakeup_secondary_cpu (void ); +bool snp_init (struct boot_params *bp); +/* +* TODO: These are exported only temporarily while boot/compressed/sev.c is +* the only user. This is to avoid unused function warnings for kernel/sev.c +* during the build of kernel proper. +* +* Once the code is added to consume these in kernel proper these functions +* can be moved back to being statically-scoped to units that pull in +* sev-shared.c via #include and these declarations can be dropped. +*/ +struct cc_blob_sev_info *snp_find_cc_blob_setup_data (struct boot_params *bp);#else static inline void sev_es_ist_enter (struct pt_regs *regs) { }static inline void sev_es_ist_exit (void ) { }
@@ -162,6 +174,7 @@ static inline void __init snp_prep_memory(unsigned long paddr, unsigned int sz,static inline void snp_set_memory_shared (unsigned long vaddr,unsigned int npages) { }static inline void snp_set_memory_private (unsigned long vaddr,unsigned int npages) { }static inline void snp_set_wakeup_secondary_cpu (void ) { } +static inline bool snp_init (struct boot_params *bp) {return false; }#endif #endif
arch/x86/kernel/sev-shared.c +34 -0
@@ -944,3 +944,37 @@ static enum es_result vc_handle_rdtsc(struct ghcb *ghcb,return ES_OK ; } + +struct cc_setup_data { +struct setup_data header; +u32 cc_blob_address; +}; + +static struct cc_setup_data *get_cc_setup_data (struct boot_params *bp) +{ +struct setup_data *hdr = (struct setup_data *)bp->hdr.setup_data; + +while (hdr) { +if (hdr->type ==SETUP_CC_BLOB ) +return (struct cc_setup_data *)hdr; + hdr = (struct setup_data *)hdr->next; + } + +return NULL ; +} + +/* +* Search for a Confidential Computing blob passed in as a setup_data entry +* via the Linux Boot Protocol. +*/ +struct cc_blob_sev_info * +snp_find_cc_blob_setup_data (struct boot_params *bp) +{ +struct cc_setup_data *sd; + + sd =get_cc_setup_data (bp); +if (!sd) +return NULL ; + +return (struct cc_blob_sev_info *)(unsigned long )sd->cc_blob_address; +}
Signature · 1 line
2.25.1
PATCH v7 37/45 x86/compressed: use firmware-validated CPUID for SEV-SNP guests
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
SEV-SNP guests will be provided the location of special 'secrets' 'CPUID' pages via the Confidential Computing blob. This blob is provided to the boot kernel either through an EFI config table entry, or via a setup_data structure as defined by the Linux Boot Protocol.
Locate the Confidential Computing from these sources and, if found, use the provided CPUID page/table address to create a copy that the boot kernel will use when servicing cpuid instructions via a #VC handler.
--- arch/x86/boot/compressed/sev.c | 13 +++++++++ arch/x86/include/asm/sev.h | 1 + arch/x86/kernel/sev-shared.c | 48 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+)
arch/x86/boot/compressed/sev.c +13 -0
@@ -411,6 +411,19 @@ bool snp_init(struct boot_params *bp)if (!cc_info)return false; +/* +* If SEV-SNP-specific Confidential Computing blob is present, then +* firmware/bootloader have indicated SEV-SNP support. Verifying this +* involves CPUID checks which will be more reliable if the SEV-SNP +* CPUID table is used. See comments for snp_cpuid_info_create() for +* more details. +*/ +snp_cpuid_info_create (cc_info); + +/* SEV-SNP CPUID table should be set up now. */ +if (!snp_cpuid_active ()) +sev_es_terminate (1 ,GHCB_TERM_CPUID ); +/* * Pass run-time kernel a pointer to CC info via boot_params so EFI * config table doesn't need to be searched again during early startup
arch/x86/include/asm/sev.h +1 -0
@@ -157,6 +157,7 @@ bool snp_init(struct boot_params *bp);* sev-shared.c via #include and these declarations can be dropped. */ struct cc_blob_sev_info *snp_find_cc_blob_setup_data (struct boot_params *bp); +void __init snp_cpuid_info_create (const struct cc_blob_sev_info *cc_info);#else static inline void sev_es_ist_enter (struct pt_regs *regs) { }static inline void sev_es_ist_exit (void ) { }
arch/x86/kernel/sev-shared.c +48 -0
63 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v7 38/45 x86/compressed/64: add identity mapping for Confidential Computing blob
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
The run-time kernel will need to access the Confidential Computing blob very early in boot to access the CPUID table it points to. At that stage of boot it will be relying on the identity-mapped page table set up by boot/compressed kernel, so make sure the blob and the CPUID table it points to are mapped in advance.
--- arch/x86/boot/compressed/ident_map_64.c | 26 ++++++++++++++++++++++++- arch/x86/boot/compressed/misc.h | 4 ++++ arch/x86/boot/compressed/sev.c | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/ident_map_64.c +25 -1
@@ -37,6 +37,8 @@#include <asm/setup.h> /* For COMMAND_LINE_SIZE */ #undef _SETUP +#include <asm/sev.h> /* For ConfidentialComputing blob */ +extern unsigned long get_cmd_line_ptr (void );/* Used by PAGE_KERN* macros: */
@@ -106,6 +108,27 @@ static void add_identity_map(unsigned long start, unsigned long end)error ("Error: kernel_ident_mapping_init() failed\n" ); } +void sev_prep_identity_maps (void ) +{ +/* +* The ConfidentialComputing blob is used very early in uncompressed +* kernel to find the in-memory cpuid table to handle cpuid +* instructions. Make sure an identity-mapping exists so it can be +* accessed after switchover. +*/ +if (sev_snp_enabled ()) { +struct cc_blob_sev_info *cc_info = + (void *)(unsigned long )boot_params->cc_blob_address; + +add_identity_map ((unsigned long )cc_info, + (unsigned long )cc_info +sizeof (*cc_info)); +add_identity_map ((unsigned long )cc_info->cpuid_phys, + (unsigned long )cc_info->cpuid_phys + cc_info->cpuid_len); + } + +sev_verify_cbit (top_level_pgt); +} +/* Locates and clears a region for a new top level page table. */ void initialize_identity_maps (void *rmode) {
@@ -163,8 +186,9 @@ void initialize_identity_maps(void *rmode) cmdline =get_cmd_line_ptr ();add_identity_map (cmdline, cmdline +COMMAND_LINE_SIZE ); +sev_prep_identity_maps (); +/* Load the new page-table. */ -sev_verify_cbit (top_level_pgt);write_cr3 (top_level_pgt); }
arch/x86/boot/compressed/misc.h +4 -0
@@ -127,6 +127,8 @@ void sev_es_shutdown_ghcb(void);extern bool sev_es_check_ghcb_fault (unsigned long address);void snp_set_page_private (unsigned long paddr);void snp_set_page_shared (unsigned long paddr); +bool sev_snp_enabled (void ); +#else static inline void sev_enable (struct boot_params *bp) { }static inline void sev_es_shutdown_ghcb (void ) { }
@@ -136,6 +138,8 @@ static inline bool sev_es_check_ghcb_fault(unsigned long address) }static inline void snp_set_page_private (unsigned long paddr) { }static inline void snp_set_page_shared (unsigned long paddr) { } +static inline bool sev_snp_enabled (void ) {return false; } +#endif /* acpi.c */
arch/x86/boot/compressed/sev.c +1 -1
@@ -120,7 +120,7 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,/* Include code for early handlers */ #include "../../kernel/sev-shared.c" -static inline bool sev_snp_enabled (void ) +bool sev_snp_enabled (void ) {return sev_status &MSR_AMD64_SEV_SNP_ENABLED ; }
Signature · 1 line
2.25.1
PATCH v7 39/45 x86/sev: add SEV-SNP feature detection/setup
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
Initial/preliminary detection of SEV-SNP is done via the Confidential Computing blob. Check for it prior to the normal SEV/SME feature initialization, and add some sanity checks to confirm it agrees with SEV-SNP CPUID/MSR bits.
--- arch/x86/include/asm/sev.h | 3 +- arch/x86/kernel/sev-shared.c | 2 +- arch/x86/kernel/sev.c | 65 ++++++++++++++++++++++++++++++ arch/x86/mm/mem_encrypt_identity.c | 8 ++++ 4 files changed, 76 insertions(+), 2 deletions(-)
arch/x86/include/asm/sev.h +2 -1
@@ -147,6 +147,7 @@ void snp_set_memory_shared(unsigned long vaddr, unsigned int npages);void snp_set_memory_private (unsigned long vaddr,unsigned int npages);void snp_set_wakeup_secondary_cpu (void );bool snp_init (struct boot_params *bp); +void snp_abort (void );/* * TODO: These are exported only temporarily while boot/compressed/sev.c is * the only user. This is to avoid unused function warnings for kernel/sev.c
@@ -156,7 +157,6 @@ bool snp_init(struct boot_params *bp);* can be moved back to being statically-scoped to units that pull in * sev-shared.c via #include and these declarations can be dropped. */ -struct cc_blob_sev_info *snp_find_cc_blob_setup_data (struct boot_params *bp);void __init snp_cpuid_info_create (const struct cc_blob_sev_info *cc_info);#else static inline void sev_es_ist_enter (struct pt_regs *regs) { }
@@ -176,6 +176,7 @@ static inline void snp_set_memory_shared(unsigned long vaddr, unsigned int npagestatic inline void snp_set_memory_private (unsigned long vaddr,unsigned int npages) { }static inline void snp_set_wakeup_secondary_cpu (void ) { }static inline bool snp_init (struct boot_params *bp) {return false; } +static inline void snp_abort (void ) { }#endif #endif
arch/x86/kernel/sev-shared.c +1 -1
@@ -989,7 +989,7 @@ static struct cc_setup_data *get_cc_setup_data(struct boot_params *bp)* Search for a Confidential Computing blob passed in as a setup_data entry * via the Linux Boot Protocol. */ -struct cc_blob_sev_info * +static struct cc_blob_sev_info *snp_find_cc_blob_setup_data (struct boot_params *bp) {struct cc_setup_data *sd;
arch/x86/kernel/sev.c +65 -0
68 lines not on this page · raw message
arch/x86/mm/mem_encrypt_identity.c +8 -0
@@ -44,6 +44,7 @@#include <asm/setup.h> #include <asm/sections.h> #include <asm/cmdline.h> +#include <asm/sev.h> #include "mm_internal.h"
@@ -508,8 +509,11 @@ void __init sme_enable(struct boot_params *bp)bool active_by_default;unsigned long me_mask;char buffer[16 ]; +bool snp;u64 msr; + snp =snp_init (bp); +/* Check for the SME/SEV support leaf */ eax =0x80000000 ; ecx =0 ;
@@ -541,6 +545,10 @@ void __init sme_enable(struct boot_params *bp) sev_status =__rdmsr (MSR_AMD64_SEV ); feature_mask = (sev_status &MSR_AMD64_SEV_ENABLED ) ?AMD_SEV_BIT :AMD_SME_BIT ; +/* The SEV-SNP CC blob should never be present unless SEV-SNP is enabled. */ +if (snp && !(sev_status &MSR_AMD64_SEV_SNP_ENABLED )) +snp_abort (); +/* Check if memory encryption is enabled */ if (feature_mask ==AMD_SME_BIT ) {/*
Signature · 1 line
2.25.1
PATCH v7 40/45 x86/sev: use firmware-validated CPUID for SEV-SNP guests
In reply to Brijesh SinghFrom: Michael Roth <[email protected]>
SEV-SNP guests will be provided the location of special 'secrets' and 'CPUID' pages via the Confidential Computing blob. This blob is provided to the run-time kernel either through bootparams field that was initialized by the boot/compressed kernel, or via a setup_data structure as defined by the Linux Boot Protocol.
Locate the Confidential Computing from these sources and, if found, use the provided CPUID page/table address to create a copy that the run-time kernel will use when servicing cpuid instructions via a #VC handler.
--- arch/x86/include/asm/sev.h | 10 ---------- arch/x86/kernel/sev-shared.c | 2 +- arch/x86/kernel/sev.c | 37 ++++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 11 deletions(-)
arch/x86/include/asm/sev.h +0 -10
@@ -148,16 +148,6 @@ void snp_set_memory_private(unsigned long vaddr, unsigned int npages);void snp_set_wakeup_secondary_cpu (void );bool snp_init (struct boot_params *bp);void snp_abort (void ); -/* -* TODO: These are exported only temporarily while boot/compressed/sev.c is -* the only user. This is to avoid unused function warnings for kernel/sev.c -* during the build of kernel proper. -* -* Once the code is added to consume these in kernel proper these functions -* can be moved back to being statically-scoped to units that pull in -* sev-shared.c via #include and these declarations can be dropped. -*/ -void __init snp_cpuid_info_create (const struct cc_blob_sev_info *cc_info);#else static inline void sev_es_ist_enter (struct pt_regs *regs) { }static inline void sev_es_ist_exit (void ) { }
arch/x86/kernel/sev-shared.c +1 -1
@@ -1010,7 +1010,7 @@ snp_find_cc_blob_setup_data(struct boot_params *bp)* mapping needs to be updated in sync with all the changes to virtual memory * layout and related mapping facilities throughout the boot process. */ -void __init snp_cpuid_info_create (const struct cc_blob_sev_info *cc_info) +static void __init snp_cpuid_info_create (const struct cc_blob_sev_info *cc_info) {const struct snp_cpuid_info *cpuid_info_fw, *cpuid_info;
arch/x86/kernel/sev.c +37 -0
@@ -2062,6 +2062,12 @@ bool __init snp_init(struct boot_params *bp)if (!cc_info)return false; +snp_cpuid_info_create (cc_info); + +/* SEV-SNP CPUID table is set up now. Do some sanity checks. */ +if (!snp_cpuid_active ()) +sev_es_terminate (1 ,GHCB_TERM_CPUID ); +/* * The CC blob will be used later to access the secrets page. Cache * it here like the boot kernel does.
@@ -2075,3 +2081,34 @@ void __init snp_abort(void) {sev_es_terminate (1 ,GHCB_SNP_UNSUPPORTED ); } + +/* +* It is useful from an auditing/testing perspective to provide an easy way +* for the guest owner to know that the CPUID table has been initialized as +* expected, but that initialization happens too early in boot to print any +* sort of indicator, and there's not really any other good place to do it. So +* do it here, and while at it, go ahead and re-verify that nothing strange has +* happened between early boot and now. +*/ +static int __init snp_cpuid_check_status (void ) +{ +const struct snp_cpuid_info *cpuid_info =snp_cpuid_info_get_ptr (); + +if (!cc_platform_has (CC_ATTR_SEV_SNP )) { +/* Firmware should not have advertised the feature. */ +if (snp_cpuid_active ()) +panic ("Invalid use of SEV-SNP CPUID table." ); +return 0 ; + } + +/* CPUID table should always be available when SEV-SNP is enabled. */ +if (!snp_cpuid_active ()) +sev_es_terminate (1 ,GHCB_TERM_CPUID ); + +pr_info ("Using SEV-SNP CPUID table, %d entries present.\n" , + cpuid_info->count); + +return 0 ; +} + +arch_initcall (snp_cpuid_check_status);
Signature · 1 line
2.25.1
PATCH v7 41/45 x86/sev: Provide support for SNP guest request NAEs
In reply to Brijesh SinghVersion 2 of GHCB specification provides SNP_GUEST_REQUEST and SNP_EXT_GUEST_REQUEST NAE that can be used by the SNP guest to communicate with the PSP.
While at it, add a snp_issue_guest_request() helper that can be used by driver or other subsystem to issue the request to PSP.
See SEV-SNP and GHCB spec for more details.
--- arch/x86/include/asm/sev-common.h | 3 ++ arch/x86/include/asm/sev.h | 14 +++++++++ arch/x86/include/uapi/asm/svm.h | 4 +++ arch/x86/kernel/sev.c | 51 +++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+)
arch/x86/include/asm/sev-common.h +3 -0
@@ -128,6 +128,9 @@ struct snp_psc_desc {struct psc_entry entries[VMGEXIT_PSC_MAX_ENTRY ]; } __packed; +/* Guest message request error code */ +#define SNP_GUEST_REQ_INVALID_LEN BIT_ULL(32) +#define GHCB_MSR_TERM_REQ 0x100#define GHCB_MSR_TERM_REASON_SET_POS 12#define GHCB_MSR_TERM_REASON_SET_MASK 0xf
arch/x86/include/asm/sev.h +14 -0
@@ -81,6 +81,14 @@ extern bool handle_vc_boot_ghcb(struct pt_regs *regs);#define RMPADJUST_VMSA_PAGE_BIT BIT(16) +/* SNP Guest message request */ +struct snp_req_data { +unsigned long req_gpa; +unsigned long resp_gpa; +unsigned long data_gpa; +unsigned int data_npages; +}; +#ifdef CONFIG_AMD_MEM_ENCRYPT extern struct static_key_false sev_es_enable_key;extern void __sev_es_ist_enter (struct pt_regs *regs);
@@ -148,6 +156,7 @@ void snp_set_memory_private(unsigned long vaddr, unsigned int npages);void snp_set_wakeup_secondary_cpu (void );bool snp_init (struct boot_params *bp);void snp_abort (void ); +int snp_issue_guest_request (u64 exit_code,struct snp_req_data *input,unsigned long *fw_err);#else static inline void sev_es_ist_enter (struct pt_regs *regs) { }static inline void sev_es_ist_exit (void ) { }
@@ -167,6 +176,11 @@ static inline void snp_set_memory_private(unsigned long vaddr, unsigned int npagstatic inline void snp_set_wakeup_secondary_cpu (void ) { }static inline bool snp_init (struct boot_params *bp) {return false; }static inline void snp_abort (void ) { } +static inline int snp_issue_guest_request (u64 exit_code,struct snp_req_data *input, +unsigned long *fw_err) +{ +return -ENOTTY ; +}#endif #endif
arch/x86/include/uapi/asm/svm.h +4 -0
@@ -109,6 +109,8 @@#define SVM_VMGEXIT_SET_AP_JUMP_TABLE 0#define SVM_VMGEXIT_GET_AP_JUMP_TABLE 1#define SVM_VMGEXIT_PSC 0x80000010 +#define SVM_VMGEXIT_GUEST_REQUEST 0x80000011 +#define SVM_VMGEXIT_EXT_GUEST_REQUEST 0x80000012#define SVM_VMGEXIT_AP_CREATION 0x80000013#define SVM_VMGEXIT_AP_CREATE_ON_INIT 0#define SVM_VMGEXIT_AP_CREATE 1
@@ -225,6 +227,8 @@ { SVM_VMGEXIT_AP_HLT_LOOP, "vmgexit_ap_hlt_loop" }, \ { SVM_VMGEXIT_AP_JUMP_TABLE, "vmgexit_ap_jump_table" }, \ { SVM_VMGEXIT_PSC, "vmgexit_page_state_change" }, \ + { SVM_VMGEXIT_GUEST_REQUEST, "vmgexit_guest_request" }, \ + { SVM_VMGEXIT_EXT_GUEST_REQUEST, "vmgexit_ext_guest_request" }, \ { SVM_VMGEXIT_AP_CREATION, "vmgexit_ap_creation" }, \ { SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, \ { SVM_EXIT_ERR, "invalid_guest_state" }
arch/x86/kernel/sev.c +51 -0
54 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v7 42/45 x86/sev: Register SNP guest request platform device
In reply to Brijesh SinghVersion 2 of GHCB specification provides Non Automatic Exit (NAE) that can be used by the SNP guest to communicate with the PSP without risk from a malicious hypervisor who wishes to read, alter, drop or replay the messages sent.
SNP_LAUNCH_UPDATE can insert two special pages into the guest’s memory:
the secrets page and the CPUID page. The PSP firmware populate the contents of the secrets page. The secrets page contains encryption keys used by the guest to interact with the firmware. Because the secrets page is encrypted with the guest’s memory encryption key, the hypervisor cannot read the keys. See SNP FW ABI spec for further details about the secrets page.
Create a platform device that the SNP guest driver can bind to get the platform resources such as encryption key and message id to use to communicate with the PSP. The SNP guest driver provides a userspace interface to get the attestation report, key derivation, extended attestation report etc.
--- arch/x86/include/asm/sev.h | 4 +++ arch/x86/kernel/sev.c | 61 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+)
arch/x86/include/asm/sev.h +4 -0
@@ -89,6 +89,10 @@ struct snp_req_data {unsigned int data_npages; }; +struct snp_guest_platform_data { +u64 secrets_gpa; +}; +#ifdef CONFIG_AMD_MEM_ENCRYPT extern struct static_key_false sev_es_enable_key;extern void __sev_es_ist_enter (struct pt_regs *regs);
arch/x86/kernel/sev.c +61 -0
76 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v7 43/45 virt: Add SEV-SNP guest driver
In reply to Brijesh SinghSEV-SNP specification provides the guest a mechanisum to communicate with the PSP without risk from a malicious hypervisor who wishes to read, alter, drop or replay the messages sent. The driver uses snp_issue_guest_request() to issue GHCB SNP_GUEST_REQUEST or SNP_EXT_GUEST_REQUEST NAE events to submit the request to PSP.
The PSP requires that all communication should be encrypted using key specified through the platform_data.
The userspace can use SNP_GET_REPORT ioctl() to query the guest attestation report.
See SEV-SNP spec section Guest Messages for more details.
--- Documentation/virt/coco/sevguest.rst | 77 ++++ drivers/virt/Kconfig | 3 + drivers/virt/Makefile | 1 + drivers/virt/coco/sevguest/Kconfig | 9 + drivers/virt/coco/sevguest/Makefile | 2 + drivers/virt/coco/sevguest/sevguest.c | 601 ++++++++++++++++++++++++++ drivers/virt/coco/sevguest/sevguest.h | 98 +++++ include/uapi/linux/sev-guest.h | 44 ++ 8 files changed, 835 insertions(+) create mode 100644 Documentation/virt/coco/sevguest.rst create mode 100644 drivers/virt/coco/sevguest/Kconfig create mode 100644 drivers/virt/coco/sevguest/Makefile create mode 100644 drivers/virt/coco/sevguest/sevguest.c create mode 100644 drivers/virt/coco/sevguest/sevguest.h create mode 100644 include/uapi/linux/sev-guest.h
Documentation/virt/coco/sevguest.rst new file +77 -0
@@ -0,0 +1,77 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=================================================================== +The Definitive SEV Guest API Documentation +=================================================================== + +1. General description +====================== + +The SEV API is a set of ioctls that are used by the guest or hypervisor +to get or set certain aspect of the SEV virtual machine. The ioctls belong +to the following classes: + + - Hypervisor ioctls: These query and set global attributes which affect the + whole SEV firmware. These ioctl are used by platform provision tools. + + - Guest ioctls: These query and set attributes of the SEV virtual machine. + +2. API description +================== + +This section describes ioctls that can be used to query or set SEV guests. +For each ioctl, the following information is provided along with a +description: + + Technology: + which SEV techology provides this ioctl. sev, sev-es, sev-snp or all. + + Type: + hypervisor or guest. The ioctl can be used inside the guest or the + hypervisor. + + Parameters: + what parameters are accepted by the ioctl. + + Returns: + the return value. General error numbers (ENOMEM, EINVAL) + are not detailed, but errors with specific meanings are. + +The guest ioctl should be issued on a file descriptor of the /dev/sev-guest device. +The ioctl accepts struct snp_user_guest_request. The input and output structure is +specified through the req_data and resp_data field respectively. If the ioctl fails +to execute due to a firmware error, then fw_err code will be set. + +:: + struct snp_guest_request_ioctl { + /* Request and response structure address */ + __u64 req_data; + __u64 resp_data; + + /* firmware error code on failure (see psp-sev.h) */ + __u64 fw_err; + }; + +2.1 SNP_GET_REPORT +------------------ + +:Technology: sev-snp +:Type: guest ioctl +:Parameters (in): struct snp_report_req +:Returns (out): struct snp_report_resp on success, -negative on error + +The SNP_GET_REPORT ioctl can be used to query the attestation report from the +SEV-SNP firmware. The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command +provided by the SEV-SNP firmware to query the attestation report. + +On success, the snp_report_resp.data will contains the report. The report +will contain the format described in the SEV-SNP specification. See the SEV-SNP +specification for further details. + + +Reference +--------- + +SEV-SNP and GHCB specification: developer.amd.com/sev + +The driver is based on SEV-SNP firmware spec 0.9 and GHCB spec version 2.0.
drivers/virt/Kconfig +3 -0
@@ -36,4 +36,7 @@ source "drivers/virt/vboxguest/Kconfig" source "drivers/virt/nitro_enclaves/Kconfig" source "drivers/virt/acrn/Kconfig" + +source "drivers/virt/coco/sevguest/Kconfig" + endif
drivers/virt/Makefile +1 -0
@@ -8,3 +8,4 @@ obj-y += vboxguest/ obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/ obj-$(CONFIG_ACRN_HSM) += acrn/ +obj-$(CONFIG_SEV_GUEST) += coco/sevguest/
drivers/virt/coco/sevguest/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +config SEV_GUEST + tristate "AMD SEV Guest driver" + default y + depends on AMD_MEM_ENCRYPT && CRYPTO_AEAD2 + help + The driver can be used by the SEV-SNP guest to communicate with the PSP to + request the attestation report and more. + + If you choose 'M' here, this module will be called sevguest.
drivers/virt/coco/sevguest/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_SEV_GUEST) += sevguest.o
drivers/virt/coco/sevguest/sevguest.c new file +601 -0
601 lines not on this page · raw message
drivers/virt/coco/sevguest/sevguest.h new file +98 -0
98 lines not on this page · raw message
include/uapi/linux/sev-guest.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.25.1
Randy Dunlap
reviewerRe: [PATCH v7 43/45] virt: Add SEV-SNP guest driver
Hi,
drivers/virt/coco/sevguest/Kconfig line 3
Quoted 9 lines · Brijesh Singh
drivers/virt/coco/sevguest/Kconfig new file +3
-0@@ -0,0 +1,9 @@ +config SEV_GUEST + tristate "AMD SEV Guest driver" + default y
For this to remain as "default y", you need to justify it. E.g., if a board cannot boot with an interrupt controller, the driver for the interrupt controller can be "default y".
So why is this default y?
No other drivers in drivers/virt/ are default y.
drivers/virt/coco/sevguest/Kconfig line 9
Quoted 6 lines
drivers/virt/coco/sevguest/Kconfig new file +6
-0+ depends on AMD_MEM_ENCRYPT && CRYPTO_AEAD2 + help + The driver can be used by the SEV-SNP guest to communicate with the PSP to + request the attestation report and more. + + If you choose 'M' here, this module will be called sevguest.
thanks.
Signature · 1 line
~Randy
Re: [PATCH v7 43/45] virt: Add SEV-SNP guest driver
Hi Randy,
Quoted 17 lines · Randy Dunlap
Hi,
drivers/virt/coco/sevguest/Kconfig line 3
Quoted 9 lines · Brijesh Singh
drivers/virt/coco/sevguest/Kconfig new file +3
-0@@ -0,0 +1,9 @@ +config SEV_GUEST + tristate "AMD SEV Guest driver" + default yFor this to remain as "default y", you need to justify it. E.g., if a board cannot boot with an interrupt controller, the driver for the interrupt controller can be "default y".
Quoted 3 lines
So why is this default y?
No other drivers indrivers/virt/are default y.
I choose the default "y" for two reasons:
1. The driver is built if the user enables the AMD memory encryption support. If the user has selected the AMD memory encryption support, they will be querying an attestation report to verify that the guest is running on AMD memory encryption enabled hardware.
2. Typically, an attestation report is retrieved from an initial ramdisk (before mounting the disk). IIUC, the standard initramfs build tools may not include the driver by default and requires the user to go through hoops.
However, I have no strong reason to keep it to "y" if other prefers "m".
thanks
Randy Dunlap
reviewerRe: [PATCH v7 43/45] virt: Add SEV-SNP guest driver
Quoted 20 lines · Brijesh Singh
Hi Randy,
Quoted 17 lines · Randy Dunlap
Hi,
drivers/virt/coco/sevguest/Kconfig line 3
Quoted 9 lines · Brijesh Singh
drivers/virt/coco/sevguest/Kconfig new file +3
-0@@ -0,0 +1,9 @@ +config SEV_GUEST + tristate "AMD SEV Guest driver" + default yFor this to remain as "default y", you need to justify it. E.g., if a board cannot boot with an interrupt controller, the driver for the interrupt controller can be "default y".
Quoted 7 lines
Quoted 3 lines
So why is this default y?
No other drivers indrivers/virt/are default y.I choose the default "y" for two reasons:
1. The driver is built if the user enables the AMD memory encryption support. If the user has selected the AMD memory encryption support, they will be querying an attestation report to verify that the guest is running on AMD memory encryption enabled hardware.
OK, I see. I'm OK with this.
Quoted 3 lines
2. Typically, an attestation report is retrieved from an initial ramdisk (before mounting the disk). IIUC, the standard initramfs build tools may not include the driver by default and requires the user to go through hoops.
However, I have no strong reason to keep it to "y" if other prefers "m".
"m" is no better than "y" in this case.
thanks.
Signature · 1 line
~Randy
Re: [PATCH v7 43/45] virt: Add SEV-SNP guest driver
In reply to Brijesh SinghQuoted 2 lines · Brijesh Singh
SEV-SNP specification provides the guest a mechanisum to communicate with
mechanism
Quoted 54 lines
the PSP without risk from a malicious hypervisor who wishes to read, alter, drop or replay the messages sent. The driver uses
snp_issue_guest_request()to issue GHCBSNP_GUEST_REQUESTorSNP_EXT_GUEST_REQUESTNAE events to submit the request to PSP.The PSP requires that all communication should be encrypted using key specified through the
platform_data.The userspace can use
SNP_GET_REPORTioctl()to query the guest attestation report.See SEV-SNP spec section Guest Messages for more details.
Signed-off-by Brijesh Singh <[email protected]>--- Documentation/virt/coco/sevguest.rst | 77 ++++ drivers/virt/Kconfig | 3 + drivers/virt/Makefile | 1 + drivers/virt/coco/sevguest/Kconfig | 9 + drivers/virt/coco/sevguest/Makefile | 2 + drivers/virt/coco/sevguest/sevguest.c | 601 ++++++++++++++++++++++++++ drivers/virt/coco/sevguest/sevguest.h | 98 +++++ include/uapi/linux/sev-guest.h | 44 ++ 8 files changed, 835 insertions(+) create mode 100644 Documentation/virt/coco/sevguest.rst create mode 100644 drivers/virt/coco/sevguest/Kconfig create mode 100644 drivers/virt/coco/sevguest/Makefile create mode 100644 drivers/virt/coco/sevguest/sevguest.c create mode 100644 drivers/virt/coco/sevguest/sevguest.h create mode 100644 include/uapi/linux/sev-guest.hDocumentation/virt/coco/sevguest.rst new file +17
-0@@ -0,0 +1,77 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=================================================================== +The Definitive SEV Guest API Documentation +=================================================================== + +1. General description +====================== + +The SEV API is a set of ioctls that are used by the guest or hypervisor +to get or set certain aspect of the SEV virtual machine. The ioctls belong +to the following classes: + + - Hypervisor ioctls: These query and set global attributes which affect the + whole SEV firmware. These ioctl are used by platform provision tools. + + - Guest ioctls: These query and set attributes of the SEV virtual machine.
Documentation/virt/coco/sevguest.rst line 27
Quoted 10 lines
Documentation/virt/coco/sevguest.rst new file +10
-0+ +2. API description +================== + +This section describes ioctls that can be used to query or set SEV guests. +For each ioctl, the following information is provided along with a +description: + + Technology: + which SEV techology provides this ioctl. sev, sev-es, sev-snp or all.
technology
Quoted 6 lines
Documentation/virt/coco/sevguest.rst new file +6
-0+ + Type: + hypervisor or guest. The ioctl can be used inside the guest or the + hypervisor. + + Parameters:
Documentation/virt/coco/sevguest.rst line 43
Quoted 10 lines
Documentation/virt/coco/sevguest.rst new file +10
-0+ what parameters are accepted by the ioctl. + + Returns: + the return value. General error numbers (ENOMEM, EINVAL) + are not detailed, but errors with specific meanings are. + +The guest ioctl should be issued on a file descriptor of the /dev/sev-guest device. +The ioctl accepts struct snp_user_guest_request. The input and output structure is +specified through the req_data and resp_data field respectively. If the ioctl fails +to execute due to a firmware error, then fw_err code will be set.
Should way say what it will be set to? Also Sean pointed out on CCP driver that 0 is strange to set the error to, its a uint so we cannot do -1 like we did there. What about all FFs?
Quoted 14 lines
Documentation/virt/coco/sevguest.rst new file +14
-0+ +:: + struct snp_guest_request_ioctl { + /* Request and response structure address */ + __u64 req_data; + __u64 resp_data; + + /* firmware error code on failure (see psp-sev.h) */ + __u64 fw_err; + }; + +2.1 SNP_GET_REPORT +------------------ +
Documentation/virt/coco/sevguest.rst line 67
Quoted 10 lines
Documentation/virt/coco/sevguest.rst new file +10
-0+:Technology: sev-snp +:Type: guest ioctl +:Parameters (in): struct snp_report_req +:Returns (out): struct snp_report_resp on success, -negative on error + +The SNP_GET_REPORT ioctl can be used to query the attestation report from the +SEV-SNP firmware. The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command +provided by the SEV-SNP firmware to query the attestation report. + +On success, the snp_report_resp.data will contains the report. The report
contain
Quoted 126 lines
Documentation/virt/coco/sevguest.rst new file +10
-0+will contain the format described in the SEV-SNP specification. See the SEV-SNP +specification for further details. + + +Reference +--------- + +SEV-SNP and GHCB specification: developer.amd.com/sev + +The driver is based on SEV-SNP firmware spec 0.9 and GHCB spec version 2.0.drivers/virt/Kconfig +3
-0@@ -36,4 +36,7 @@ source "drivers/virt/vboxguest/Kconfig" source "drivers/virt/nitro_enclaves/Kconfig" source "drivers/virt/acrn/Kconfig" + +source "drivers/virt/coco/sevguest/Kconfig" + endifdrivers/virt/Makefile +1
-0@@ -8,3 +8,4 @@ obj-y += vboxguest/ obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/ obj-$(CONFIG_ACRN_HSM) += acrn/ +obj-$(CONFIG_SEV_GUEST) += coco/sevguest/drivers/virt/coco/sevguest/Kconfig new file +9
-0@@ -0,0 +1,9 @@ +config SEV_GUEST + tristate "AMD SEV Guest driver" + default y + depends on AMD_MEM_ENCRYPT && CRYPTO_AEAD2 + help + The driver can be used by the SEV-SNP guest to communicate with the PSP to + request the attestation report and more. + + If you choose 'M' here, this module will be called sevguest.drivers/virt/coco/sevguest/Makefile new file +2
-0@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_SEV_GUEST) += sevguest.odrivers/virt/coco/sevguest/sevguest.c new file +66
-0@@ -0,0 +1,601 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* AMD Secure Encrypted Virtualization Nested Paging (SEV-SNP) guest request interface +* +* Copyright (C) 2021 Advanced Micro Devices, Inc. +* +* Author: Brijesh Singh <[email protected]> +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/types.h> +#include <linux/mutex.h> +#include <linux/io.h> +#include <linux/platform_device.h> +#include <linux/miscdevice.h> +#include <linux/set_memory.h> +#include <linux/fs.h> +#include <crypto/aead.h> +#include <linux/scatterlist.h> +#include <linux/psp-sev.h> +#include <uapi/linux/sev-guest.h> +#include <uapi/linux/psp-sev.h> + +#include <asm/svm.h> +#include <asm/sev.h> + +#include "sevguest.h" + +#define DEVICE_NAME "sev-guest" +#define AAD_LEN 48 +#define MSG_HDR_VER 1 + +struct snp_guest_crypto { +struct crypto_aead *tfm; +u8 *iv, *authtag; +int iv_len, a_len; +}; + +struct snp_guest_dev { +struct device *dev; +struct miscdevice misc; + +struct snp_guest_crypto *crypto; +struct snp_guest_msg *request, *response; +struct snp_secrets_page_layout *layout; +struct snp_req_data input; +u32 *os_area_msg_seqno; +u8 *vmpck; +}; + +static u32 vmpck_id; +module_param (vmpck_id, uint,0444 ); +MODULE_PARM_DESC (vmpck_id,"The VMPCK ID to use when communicating with the PSP." ); + +static DEFINE_MUTEX (snp_cmd_mutex); + +static bool is_vmpck_empty (struct snp_guest_dev *snp_dev) +{ +char zero_key[VMPCK_KEY_LEN ] = {0 }; + +if (snp_dev->vmpck) +return memcmp (snp_dev->vmpck, zero_key,VMPCK_KEY_LEN ) ==0 ; + +return true; +}
drivers/virt/coco/sevguest/sevguest.c line 76
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.c new file +10
-0+ +static void snp_disable_vmpck (struct snp_guest_dev *snp_dev) +{ +memzero_explicit (snp_dev->vmpck,VMPCK_KEY_LEN ); + snp_dev->vmpck =NULL ; +} + +static inline u64 __snp_get_msg_seqno (struct snp_guest_dev *snp_dev) +{ +u64 count;
I may be overly paranoid here but how about lockdep_assert_held(&snp_cmd_mutex); when writing or reading directly from this data?
Quoted 6 lines
drivers/virt/coco/sevguest/sevguest.c new file +6
-0+ +/* Read the current message sequence counter from secrets pages */ + count = *snp_dev->os_area_msg_seqno; + +return count +1 ; +}
drivers/virt/coco/sevguest/sevguest.c line 92
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.c new file +10
-0+ +/* Return a non-zero on success */ +static u64 snp_get_msg_seqno (struct snp_guest_dev *snp_dev) +{ +u64 count =__snp_get_msg_seqno (snp_dev); + +/* +* The message sequence counter for the SNP guest request is a 64-bit +* value but the version 2 of GHCB specification defines a 32-bit storage +* for the it. If the counter exceeds the 32-bit value then return zero.
"for it. ..." or maybe "defines 32-bit field for the sequence counter"
drivers/virt/coco/sevguest/sevguest.c line 93
Quoted 1 line
drivers/virt/coco/sevguest/sevguest.c new file +1
-0+* The caller should check the return value, but if the caller happen to
happens
Quoted 221 lines
drivers/virt/coco/sevguest/sevguest.c new file +221
-0+* not check the value and use it, then the firmware treats zero as an +* invalid number and will fail the message request. +*/ +if (count >=UINT_MAX ) { +pr_err_ratelimited ("SNP guest request message sequence counter overflow\n" ); +return 0 ; + } + +return count; +} + +static void snp_inc_msg_seqno (struct snp_guest_dev *snp_dev) +{ +/* +* The counter is also incremented by the PSP, so increment it by 2 +* and save in secrets page. +*/ + *snp_dev->os_area_msg_seqno +=2 ; +} + +static inline struct snp_guest_dev *to_snp_dev (struct file *file) +{ +struct miscdevice *dev = file->private_data; + + return container_of(dev, struct snp_guest_dev, misc); +} + +static struct snp_guest_crypto *init_crypto (struct snp_guest_dev *snp_dev,u8 *key,size_t keylen) +{ +struct snp_guest_crypto *crypto; + + crypto =kzalloc (sizeof (*crypto),GFP_KERNEL_ACCOUNT ); +if (!crypto) +return NULL ; + + crypto->tfm =crypto_alloc_aead ("gcm(aes)" ,0 ,0 ); +if (IS_ERR (crypto->tfm)) + goto e_free; + +if (crypto_aead_setkey (crypto->tfm, key, keylen)) + goto e_free_crypto; + + crypto->iv_len =crypto_aead_ivsize (crypto->tfm); +if (crypto->iv_len <12 ) { +dev_err (snp_dev->dev,"IV length is less than 12.\n" ); + goto e_free_crypto; + } + + crypto->iv =kmalloc (crypto->iv_len,GFP_KERNEL_ACCOUNT ); +if (!crypto->iv) + goto e_free_crypto; + +if (crypto_aead_authsize (crypto->tfm) >MAX_AUTHTAG_LEN ) { +if (crypto_aead_setauthsize (crypto->tfm,MAX_AUTHTAG_LEN )) { +dev_err (snp_dev->dev,"failed to set authsize to %d\n" ,MAX_AUTHTAG_LEN ); + goto e_free_crypto; + } + } + + crypto->a_len =crypto_aead_authsize (crypto->tfm); + crypto->authtag =kmalloc (crypto->a_len,GFP_KERNEL_ACCOUNT ); +if (!crypto->authtag) + goto e_free_crypto; + +return crypto; + +e_free_crypto: +crypto_free_aead (crypto->tfm); +e_free: +kfree (crypto->iv); +kfree (crypto->authtag); +kfree (crypto); + +return NULL ; +} + +static void deinit_crypto (struct snp_guest_crypto *crypto) +{ +crypto_free_aead (crypto->tfm); +kfree (crypto->iv); +kfree (crypto->authtag); +kfree (crypto); +} + +static int enc_dec_message (struct snp_guest_crypto *crypto,struct snp_guest_msg *msg, +u8 *src_buf,u8 *dst_buf,size_t len,bool enc) +{ +struct snp_guest_msg_hdr *hdr = &msg->hdr; +struct scatterlist src[3 ], dst[3 ]; +DECLARE_CRYPTO_WAIT (wait); +struct aead_request *req; +int ret; + + req =aead_request_alloc (crypto->tfm,GFP_KERNEL ); +if (!req) +return -ENOMEM ; + +/* +* AEAD memory operations: +* +------ AAD -------+------- DATA -----+---- AUTHTAG----+ +* | msg header | plaintext | hdr->authtag | +* | bytes 30h - 5Fh | or | | +* | | cipher | | +* +------------------+------------------+----------------+ +*/ +sg_init_table (src,3 ); +sg_set_buf (&src[0 ], &hdr->algo,AAD_LEN ); +sg_set_buf (&src[1 ], src_buf, hdr->msg_sz); +sg_set_buf (&src[2 ], hdr->authtag, crypto->a_len); + +sg_init_table (dst,3 ); +sg_set_buf (&dst[0 ], &hdr->algo,AAD_LEN ); +sg_set_buf (&dst[1 ], dst_buf, hdr->msg_sz); +sg_set_buf (&dst[2 ], hdr->authtag, crypto->a_len); + +aead_request_set_ad (req,AAD_LEN ); +aead_request_set_tfm (req, crypto->tfm); +aead_request_set_callback (req,0 , crypto_req_done, &wait); + +aead_request_set_crypt (req, src, dst, len, crypto->iv); + ret =crypto_wait_req (enc ?crypto_aead_encrypt (req) :crypto_aead_decrypt (req), &wait); + +aead_request_free (req); +return ret; +} + +static int __enc_payload (struct snp_guest_dev *snp_dev,struct snp_guest_msg *msg, +void *plaintext,size_t len) +{ +struct snp_guest_crypto *crypto = snp_dev->crypto; +struct snp_guest_msg_hdr *hdr = &msg->hdr; + +memset (crypto->iv,0 , crypto->iv_len); +memcpy (crypto->iv, &hdr->msg_seqno,sizeof (hdr->msg_seqno)); + +return enc_dec_message (crypto, msg, plaintext, msg->payload, len, true); +} + +static int dec_payload (struct snp_guest_dev *snp_dev,struct snp_guest_msg *msg, +void *plaintext,size_t len) +{ +struct snp_guest_crypto *crypto = snp_dev->crypto; +struct snp_guest_msg_hdr *hdr = &msg->hdr; + +/* Build IV with response buffer sequence number */ +memset (crypto->iv,0 , crypto->iv_len); +memcpy (crypto->iv, &hdr->msg_seqno,sizeof (hdr->msg_seqno)); + +return enc_dec_message (crypto, msg, msg->payload, plaintext, len, false); +} + +static int verify_and_dec_payload (struct snp_guest_dev *snp_dev,void *payload,u32 sz) +{ +struct snp_guest_crypto *crypto = snp_dev->crypto; +struct snp_guest_msg *resp = snp_dev->response; +struct snp_guest_msg *req = snp_dev->request; +struct snp_guest_msg_hdr *req_hdr = &req->hdr; +struct snp_guest_msg_hdr *resp_hdr = &resp->hdr; + +dev_dbg (snp_dev->dev,"response [seqno %lld type %d version %d sz %d]\n" , + resp_hdr->msg_seqno, resp_hdr->msg_type, resp_hdr->msg_version, resp_hdr->msg_sz); + +/* Verify that the sequence counter is incremented by 1 */ +if (unlikely (resp_hdr->msg_seqno != (req_hdr->msg_seqno +1 ))) +return -EBADMSG ; + +/* Verify response message type and version number. */ +if (resp_hdr->msg_type != (req_hdr->msg_type +1 ) || + resp_hdr->msg_version != req_hdr->msg_version) +return -EBADMSG ; + +/* +* If the message size is greater than our buffer length then return +* an error. +*/ +if (unlikely ((resp_hdr->msg_sz + crypto->a_len) > sz)) +return -EBADMSG ; + +/* Decrypt the payload */ +return dec_payload (snp_dev, resp, payload, resp_hdr->msg_sz + crypto->a_len); +} + +static bool enc_payload (struct snp_guest_dev *snp_dev,u64 seqno,int version,u8 type, +void *payload,size_t sz) +{ +struct snp_guest_msg *req = snp_dev->request; +struct snp_guest_msg_hdr *hdr = &req->hdr; + +memset (req,0 ,sizeof (*req)); + + hdr->algo =SNP_AEAD_AES_256_GCM ; + hdr->hdr_version =MSG_HDR_VER ; + hdr->hdr_sz =sizeof (*hdr); + hdr->msg_type = type; + hdr->msg_version = version; + hdr->msg_seqno = seqno; + hdr->msg_vmpck = vmpck_id; + hdr->msg_sz = sz; + +/* Verify the sequence number is non-zero */ +if (!hdr->msg_seqno) +return -ENOSR ; + +dev_dbg (snp_dev->dev,"request [seqno %lld type %d version %d sz %d]\n" , + hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); + +return __enc_payload (snp_dev, req, payload, sz); +} + +static int handle_guest_request (struct snp_guest_dev *snp_dev,u64 exit_code,int msg_ver, +u8 type,void *req_buf,size_t req_sz,void *resp_buf, +u32 resp_sz,__u64 *fw_err) +{ +unsigned long err; +u64 seqno; +int rc; + +/* Get message sequence and verify that its a non-zero */ + seqno =snp_get_msg_seqno (snp_dev); +if (!seqno) +return -EIO ;
drivers/virt/coco/sevguest/sevguest.c line 324
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.c new file +10
-0+ +memset (snp_dev->response,0 ,sizeof (*snp_dev->response)); + +/* Encrypt the userspace provided payload */ + rc =enc_payload (snp_dev, seqno, msg_ver, type, req_buf, req_sz); +if (rc) +return rc; + +/* Call firmware to process the request */ + rc =snp_issue_guest_request (exit_code, &snp_dev->input, &err);
Isn't everything in the file going to be calling this with SVM_VMGEXIT_EXT_GUEST_REQUEST because they are all placing guest requests? If so, why not drop the @exit_code parameter and just hardcode SVM_VMGEXIT_EXT_GUEST_REQUEST here?
drivers/virt/coco/sevguest/sevguest.c line 335
Quoted 11 lines
drivers/virt/coco/sevguest/sevguest.c new file +11
-0+if (fw_err) + *fw_err = err; + +if (rc) +return rc; + + rc =verify_and_dec_payload (snp_dev, resp_buf, resp_sz); +if (rc) { +/* +* The verify_and_dec_payload() will fail only if the hypervisor is +* actively modifiying the message header or corrupting the encrypted payload.
modifiying
drivers/virt/coco/sevguest/sevguest.c line 338
Quoted 3 lines
drivers/virt/coco/sevguest/sevguest.c new file +3
-0+* This hints that hypervisor is acting in a bad faith. Disable the VMPCK so that +* the key cannot be used for any communication. +*/
This looks great, thanks for changes Brijesh. Should we mention in comment here or at snp_disable_vmpck() the AES-GCM issues with continuing to use the key? Or will future updaters to this code understand already?
Quoted 114 lines
drivers/virt/coco/sevguest/sevguest.c new file +114
-0+dev_alert (snp_dev->dev, +"Detected unexpected decode failure, disabling the vmpck_id %d\n" , vmpck_id); +snp_disable_vmpck (snp_dev); +return rc; + } + +/* Increment to new message sequence after payload descryption was successful. */ +snp_inc_msg_seqno (snp_dev); + +return 0 ; +} + +static int get_report (struct snp_guest_dev *snp_dev,struct snp_guest_request_ioctl *arg) +{ +struct snp_guest_crypto *crypto = snp_dev->crypto; +struct snp_report_resp *resp; +struct snp_report_req req; +int rc, resp_len; + +if (!arg->req_data || !arg->resp_data) +return -EINVAL ; + +/* Copy the request payload from userspace */ +if (copy_from_user (&req, (void __user *)arg->req_data,sizeof (req))) +return -EFAULT ; + +/* Message version must be non-zero */ +if (!req.msg_version) +return -EINVAL ; + +/* +* The intermediate response buffer is used while decrypting the +* response payload. Make sure that it has enough space to cover the +* authtag. +*/ + resp_len =sizeof (resp->data) + crypto->a_len; + resp =kzalloc (resp_len,GFP_KERNEL_ACCOUNT ); +if (!resp) +return -ENOMEM ; + +/* Issue the command to get the attestation report */ + rc =handle_guest_request (snp_dev,SVM_VMGEXIT_GUEST_REQUEST , req.msg_version, +SNP_MSG_REPORT_REQ , &req.user_data,sizeof (req.user_data), + resp->data, resp_len, &arg->fw_err); +if (rc) + goto e_free; + +/* Copy the response payload to userspace */ +if (copy_to_user ((void __user *)arg->resp_data, resp,sizeof (*resp))) + rc = -EFAULT ; + +e_free: +kfree (resp); +return rc; +} + +static long snp_guest_ioctl (struct file *file,unsigned int ioctl,unsigned long arg) +{ +struct snp_guest_dev *snp_dev =to_snp_dev (file); +void __user *argp = (void __user *)arg; +struct snp_guest_request_ioctl input; +int ret = -ENOTTY ; + +if (copy_from_user (&input, argp,sizeof (input))) +return -EFAULT ; + + input.fw_err =0 ; + +mutex_lock (&snp_cmd_mutex); + +/* Check if the VMPCK is not empty */ +if (is_vmpck_empty (snp_dev)) { +dev_err_ratelimited (snp_dev->dev,"VMPCK is disabled\n" ); +mutex_unlock (&snp_cmd_mutex); +return -ENOTTY ; + } + +switch (ioctl) { +case SNP_GET_REPORT : + ret =get_report (snp_dev, &input); +break ; +default : +break ; + } + +mutex_unlock (&snp_cmd_mutex); + +if (input.fw_err &©_to_user (argp, &input,sizeof (input))) +return -EFAULT ; + +return ret; +} + +static void free_shared_pages (void *buf,size_t sz) +{ +unsigned int npages =PAGE_ALIGN (sz) >>PAGE_SHIFT ; + +if (!buf) +return ; + +/* If fail to restore the encryption mask then leak it. */ +if (WARN_ONCE (set_memory_encrypted ((unsigned long )buf, npages), +"Failed to restore encryption mask (leak it)\n" )) +return ; + +__free_pages (virt_to_page (buf),get_order (sz)); +} + +static void *alloc_shared_pages (size_t sz) +{ +unsigned int npages =PAGE_ALIGN (sz) >>PAGE_SHIFT ; +struct page *page; +int ret; +
drivers/virt/coco/sevguest/sevguest.c line 462
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.c new file +10
-0+ page =alloc_pages (GFP_KERNEL_ACCOUNT ,get_order (sz)); +if (IS_ERR (page)) +return NULL ; + + ret =set_memory_decrypted ((unsigned long )page_address (page), npages); +if (ret) { +pr_err ("SEV-SNP: failed to mark page shared, ret=%d\n" , ret); +__free_pages (page,get_order (sz)); +return NULL ; + }
No strong preference or anything just curious. Why not allocate from SWIOTLB or use the DMA pool that supports decrypted memory:
https://lkml.org/lkml/2020/4/14/1508.
Quoted 168 lines
drivers/virt/coco/sevguest/sevguest.c new file +139
-0+ +return page_address (page); +} + +static const struct file_operations snp_guest_fops = { + .owner =THIS_MODULE , + .unlocked_ioctl = snp_guest_ioctl, +}; + +static u8 *get_vmpck (int id,struct snp_secrets_page_layout *layout,u32 **seqno) +{ +u8 *key =NULL ; + +switch (id) { +case 0 : + *seqno = &layout->os_area.msg_seqno_0; + key = layout->vmpck0; +break ; +case 1 : + *seqno = &layout->os_area.msg_seqno_1; + key = layout->vmpck1; +break ; +case 2 : + *seqno = &layout->os_area.msg_seqno_2; + key = layout->vmpck2; +break ; +case 3 : + *seqno = &layout->os_area.msg_seqno_3; + key = layout->vmpck3; +break ; +default : +break ; + } + +return key; +} + +static int __init snp_guest_probe (struct platform_device *pdev) +{ +struct snp_secrets_page_layout *layout; +struct snp_guest_platform_data *data; +struct device *dev = &pdev->dev; +struct snp_guest_dev *snp_dev; +struct miscdevice *misc; +int ret; + +if (!dev->platform_data) +return -ENODEV ; + + data = (struct snp_guest_platform_data *)dev->platform_data; + layout = (__force void *)ioremap_encrypted (data->secrets_gpa,PAGE_SIZE ); +if (!layout) +return -ENODEV ; + + ret = -ENOMEM ; + snp_dev =devm_kzalloc (&pdev->dev,sizeof (struct snp_guest_dev ),GFP_KERNEL ); +if (!snp_dev) + goto e_fail; + + ret = -EINVAL ; + snp_dev->vmpck =get_vmpck (vmpck_id, layout, &snp_dev->os_area_msg_seqno); +if (!snp_dev->vmpck) { +dev_err (dev,"invalid vmpck id %d\n" , vmpck_id); + goto e_fail; + } + +/* Verify that VMPCK is not zero. */ +if (is_vmpck_empty (snp_dev)) { +dev_err (dev,"vmpck id %d is null\n" , vmpck_id); + goto e_fail; + } + +platform_set_drvdata (pdev, snp_dev); + snp_dev->dev = dev; + snp_dev->layout = layout; + +/* Allocate the shared page used for the request and response message. */ + snp_dev->request =alloc_shared_pages (sizeof (struct snp_guest_msg )); +if (!snp_dev->request) + goto e_fail; + + snp_dev->response =alloc_shared_pages (sizeof (struct snp_guest_msg )); +if (!snp_dev->response) + goto e_fail; + + ret = -EIO ; + snp_dev->crypto =init_crypto (snp_dev, snp_dev->vmpck,VMPCK_KEY_LEN ); +if (!snp_dev->crypto) + goto e_fail; + + misc = &snp_dev->misc; + misc->minor =MISC_DYNAMIC_MINOR ; + misc->name =DEVICE_NAME ; + misc->fops = &snp_guest_fops; + +/* initial the input address for guest request */ + snp_dev->input.req_gpa =__pa (snp_dev->request); + snp_dev->input.resp_gpa =__pa (snp_dev->response); + + ret =misc_register (misc); +if (ret) + goto e_fail; + +dev_info (dev,"Initialized SNP guest driver (using vmpck_id %d)\n" , vmpck_id); +return 0 ; + +e_fail: +iounmap (layout); +free_shared_pages (snp_dev->request,sizeof (struct snp_guest_msg )); +free_shared_pages (snp_dev->response,sizeof (struct snp_guest_msg )); + +return ret; +} + +static int __exit snp_guest_remove(struct platform_device *pdev) +{ +struct snp_guest_dev *snp_dev =platform_get_drvdata (pdev); + +free_shared_pages (snp_dev->request,sizeof (struct snp_guest_msg )); +free_shared_pages (snp_dev->response,sizeof (struct snp_guest_msg )); +deinit_crypto (snp_dev->crypto); +misc_deregister (&snp_dev->misc); + +return 0 ; +} + +static struct platform_driver snp_guest_driver = { + .remove =__exit_p (snp_guest_remove), + .driver = { + .name ="snp-guest" , + }, +}; + +module_platform_driver_probe (snp_guest_driver, snp_guest_probe); + +MODULE_AUTHOR ("Brijesh Singh <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +MODULE_VERSION ("1.0.0" ); +MODULE_DESCRIPTION ("AMD SNP Guest Driver" );drivers/virt/coco/sevguest/sevguest.h new file +23
-0@@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2021 Advanced Micro Devices, Inc. +* +* Author: Brijesh Singh <[email protected]> +* +* SEV-SNP API spec is available at https://developer.amd.com/sev +*/ + +#ifndef __LINUX_SEVGUEST_H_ +#define __LINUX_SEVGUEST_H_ + +#include <linux/types.h> + +#define MAX_AUTHTAG_LEN 32 + +/* See SNP spec SNP_GUEST_REQUEST section for the structure */ +enum msg_type { +SNP_MSG_TYPE_INVALID =0 , +SNP_MSG_CPUID_REQ , +SNP_MSG_CPUID_RSP , +SNP_MSG_KEY_REQ , + SNP_MSG_KEY_RSP,
drivers/virt/coco/sevguest/sevguest.h line 33
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.h new file +10
-0+SNP_MSG_REPORT_REQ , +SNP_MSG_REPORT_RSP , +SNP_MSG_EXPORT_REQ , +SNP_MSG_EXPORT_RSP , +SNP_MSG_IMPORT_REQ , +SNP_MSG_IMPORT_RSP , +SNP_MSG_ABSORB_REQ , +SNP_MSG_ABSORB_RSP , +SNP_MSG_VMRK_REQ , + SNP_MSG_VMRK_RSP,
Did you want to include MSG_ABSORB_NOMA_REQ and MSG_ABSORB_NOMA_RESP here?
Quoted 83 lines
drivers/virt/coco/sevguest/sevguest.h new file +65
-0+ +SNP_MSG_TYPE_MAX +}; + +enum aead_algo { +SNP_AEAD_INVALID , +SNP_AEAD_AES_256_GCM , +}; + +struct snp_guest_msg_hdr { +u8 authtag[MAX_AUTHTAG_LEN ]; +u64 msg_seqno; +u8 rsvd1[8 ]; +u8 algo; +u8 hdr_version; +u16 hdr_sz; +u8 msg_type; +u8 msg_version; +u16 msg_sz; +u32 rsvd2; +u8 msg_vmpck; +u8 rsvd3[35 ]; +} __packed; + +struct snp_guest_msg { +struct snp_guest_msg_hdr hdr; +u8 payload[4000 ]; +} __packed; + +/* +* The secrets page contains 96-bytes of reserved field that can be used by +* the guest OS. The guest OS uses the area to save the message sequence +* number for each VMPCK. +* +* See the GHCB spec section Secret page layout for the format for this area. +*/ +struct secrets_os_area { +u32 msg_seqno_0; +u32 msg_seqno_1; +u32 msg_seqno_2; +u32 msg_seqno_3; +u64 ap_jump_table_pa; +u8 rsvd[40 ]; +u8 guest_usage[32 ]; +} __packed; + +#define VMPCK_KEY_LEN 32 + +/* See the SNP spec version 0.9 for secrets page format */ +struct snp_secrets_page_layout { +u32 version; +u32 imien :1 , + rsvd1 :31 ; +u32 fms; +u32 rsvd2; +u8 gosvw[16 ]; +u8 vmpck0[VMPCK_KEY_LEN ]; +u8 vmpck1[VMPCK_KEY_LEN ]; +u8 vmpck2[VMPCK_KEY_LEN ]; +u8 vmpck3[VMPCK_KEY_LEN ]; +struct secrets_os_area os_area; +u8 rsvd3[3840 ]; +} __packed; + +#endif /* __LINUX_SNP_GUEST_H__ */ include/uapi/linux/sev-guest.h new file +12
-0@@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ +/* +* Userspace interface for AMD SEV and SEV-SNP guest driver. +* +* Copyright (C) 2021 Advanced Micro Devices, Inc. +* +* Author: Brijesh Singh <[email protected]> +* +* SEV API specification is available at: https://developer.amd.com/sev/ +*/ + +#ifndef __UAPI_LINUX_SEV_GUEST_H_
include/uapi/linux/sev-guest.h line 22
Quoted 10 lines
include/uapi/linux/sev-guest.h new file +10
-0+#define __UAPI_LINUX_SEV_GUEST_H_ + +#include <linux/types.h> + +struct snp_report_req { +/* message version number (must be non-zero) */ +__u8 msg_version; + +/* user data that should be included in the report */ +__u8 user_data[64 ];
Are we missing the 'vmpl' field here? Does those default all requests to be signed with VMPL0? Users might want to change that, they could be using a paravisor.
Quoted 25 lines
include/uapi/linux/sev-guest.h new file +22
-1+}; + +struct snp_report_resp { +/* response data, see SEV-SNP spec for the format */ +__u8 data[4000 ]; +}; + +struct snp_guest_request_ioctl { +/* Request and response structure address */ +__u64 req_data; +__u64 resp_data; + +/* firmware error code on failure (see psp-sev.h) */ +__u64 fw_err; +}; + +#define SNP_GUEST_REQ_IOC_TYPE 'S' + +/* Get SNP attestation report */ +#define SNP_GET_REPORT _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x0, struct snp_guest_request_ioctl) + +#endif /* __UAPI_LINUX_SEV_GUEST_H_ */ --2.25.1
Re: [PATCH v7 43/45] virt: Add SEV-SNP guest driver
. and
Quoted 514 lines · Peter Gonda
Quoted 2 lines · Brijesh Singh
SEV-SNP specification provides the guest a mechanisum to communicate with
mechanism
Quoted 54 lines
the PSP without risk from a malicious hypervisor who wishes to read, alter, drop or replay the messages sent. The driver uses
snp_issue_guest_request()to issue GHCBSNP_GUEST_REQUESTorSNP_EXT_GUEST_REQUESTNAE events to submit the request to PSP.The PSP requires that all communication should be encrypted using key specified through the
platform_data.The userspace can use
SNP_GET_REPORTioctl()to query the guest attestation report.See SEV-SNP spec section Guest Messages for more details.
Signed-off-by Brijesh Singh <[email protected]>--- Documentation/virt/coco/sevguest.rst | 77 ++++ drivers/virt/Kconfig | 3 + drivers/virt/Makefile | 1 + drivers/virt/coco/sevguest/Kconfig | 9 + drivers/virt/coco/sevguest/Makefile | 2 + drivers/virt/coco/sevguest/sevguest.c | 601 ++++++++++++++++++++++++++ drivers/virt/coco/sevguest/sevguest.h | 98 +++++ include/uapi/linux/sev-guest.h | 44 ++ 8 files changed, 835 insertions(+) create mode 100644 Documentation/virt/coco/sevguest.rst create mode 100644 drivers/virt/coco/sevguest/Kconfig create mode 100644 drivers/virt/coco/sevguest/Makefile create mode 100644 drivers/virt/coco/sevguest/sevguest.c create mode 100644 drivers/virt/coco/sevguest/sevguest.h create mode 100644 include/uapi/linux/sev-guest.hDocumentation/virt/coco/sevguest.rst new file +17
-0@@ -0,0 +1,77 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=================================================================== +The Definitive SEV Guest API Documentation +=================================================================== + +1. General description +====================== + +The SEV API is a set of ioctls that are used by the guest or hypervisor +to get or set certain aspect of the SEV virtual machine. The ioctls belong +to the following classes: + + - Hypervisor ioctls: These query and set global attributes which affect the + whole SEV firmware. These ioctl are used by platform provision tools. + + - Guest ioctls: These query and set attributes of the SEV virtual machine.Documentation/virt/coco/sevguest.rst line 27
Quoted 10 lines
Documentation/virt/coco/sevguest.rst new file +10
-0+ +2. API description +================== + +This section describes ioctls that can be used to query or set SEV guests. +For each ioctl, the following information is provided along with a +description: + + Technology: + which SEV techology provides this ioctl. sev, sev-es, sev-snp or all.technology
Quoted 6 lines
Documentation/virt/coco/sevguest.rst new file +6
-0+ + Type: + hypervisor or guest. The ioctl can be used inside the guest or the + hypervisor. + + Parameters:Documentation/virt/coco/sevguest.rst line 43
Quoted 10 lines
Documentation/virt/coco/sevguest.rst new file +10
-0+ what parameters are accepted by the ioctl. + + Returns: + the return value. General error numbers (ENOMEM, EINVAL) + are not detailed, but errors with specific meanings are. + +The guest ioctl should be issued on a file descriptor of the /dev/sev-guest device. +The ioctl accepts struct snp_user_guest_request. The input and output structure is +specified through the req_data and resp_data field respectively. If the ioctl fails +to execute due to a firmware error, then fw_err code will be set.Should way say what it will be set to? Also Sean pointed out on CCP driver that 0 is strange to set the error to, its a uint so we cannot do -1 like we did there. What about all FFs?
Quoted 14 lines
Documentation/virt/coco/sevguest.rst new file +14
-0+ +:: + struct snp_guest_request_ioctl { + /* Request and response structure address */ + __u64 req_data; + __u64 resp_data; + + /* firmware error code on failure (see psp-sev.h) */ + __u64 fw_err; + }; + +2.1 SNP_GET_REPORT +------------------ +Documentation/virt/coco/sevguest.rst line 67
Quoted 10 lines
Documentation/virt/coco/sevguest.rst new file +10
-0+:Technology: sev-snp +:Type: guest ioctl +:Parameters (in): struct snp_report_req +:Returns (out): struct snp_report_resp on success, -negative on error + +The SNP_GET_REPORT ioctl can be used to query the attestation report from the +SEV-SNP firmware. The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command +provided by the SEV-SNP firmware to query the attestation report. + +On success, the snp_report_resp.data will contains the report. The reportcontain
Quoted 126 lines
Documentation/virt/coco/sevguest.rst new file +10
-0+will contain the format described in the SEV-SNP specification. See the SEV-SNP +specification for further details. + + +Reference +--------- + +SEV-SNP and GHCB specification: developer.amd.com/sev + +The driver is based on SEV-SNP firmware spec 0.9 and GHCB spec version 2.0.drivers/virt/Kconfig +3
-0@@ -36,4 +36,7 @@ source "drivers/virt/vboxguest/Kconfig" source "drivers/virt/nitro_enclaves/Kconfig" source "drivers/virt/acrn/Kconfig" + +source "drivers/virt/coco/sevguest/Kconfig" + endifdrivers/virt/Makefile +1
-0@@ -8,3 +8,4 @@ obj-y += vboxguest/ obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/ obj-$(CONFIG_ACRN_HSM) += acrn/ +obj-$(CONFIG_SEV_GUEST) += coco/sevguest/drivers/virt/coco/sevguest/Kconfig new file +9
-0@@ -0,0 +1,9 @@ +config SEV_GUEST + tristate "AMD SEV Guest driver" + default y + depends on AMD_MEM_ENCRYPT && CRYPTO_AEAD2 + help + The driver can be used by the SEV-SNP guest to communicate with the PSP to + request the attestation report and more. + + If you choose 'M' here, this module will be called sevguest.drivers/virt/coco/sevguest/Makefile new file +2
-0@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_SEV_GUEST) += sevguest.odrivers/virt/coco/sevguest/sevguest.c new file +66
-0@@ -0,0 +1,601 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* AMD Secure Encrypted Virtualization Nested Paging (SEV-SNP) guest request interface +* +* Copyright (C) 2021 Advanced Micro Devices, Inc. +* +* Author: Brijesh Singh <[email protected]> +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/types.h> +#include <linux/mutex.h> +#include <linux/io.h> +#include <linux/platform_device.h> +#include <linux/miscdevice.h> +#include <linux/set_memory.h> +#include <linux/fs.h> +#include <crypto/aead.h> +#include <linux/scatterlist.h> +#include <linux/psp-sev.h> +#include <uapi/linux/sev-guest.h> +#include <uapi/linux/psp-sev.h> + +#include <asm/svm.h> +#include <asm/sev.h> + +#include "sevguest.h" + +#define DEVICE_NAME "sev-guest" +#define AAD_LEN 48 +#define MSG_HDR_VER 1 + +struct snp_guest_crypto { +struct crypto_aead *tfm; +u8 *iv, *authtag; +int iv_len, a_len; +}; + +struct snp_guest_dev { +struct device *dev; +struct miscdevice misc; + +struct snp_guest_crypto *crypto; +struct snp_guest_msg *request, *response; +struct snp_secrets_page_layout *layout; +struct snp_req_data input; +u32 *os_area_msg_seqno; +u8 *vmpck; +}; + +static u32 vmpck_id; +module_param (vmpck_id, uint,0444 ); +MODULE_PARM_DESC (vmpck_id,"The VMPCK ID to use when communicating with the PSP." ); + +static DEFINE_MUTEX (snp_cmd_mutex); + +static bool is_vmpck_empty (struct snp_guest_dev *snp_dev) +{ +char zero_key[VMPCK_KEY_LEN ] = {0 }; + +if (snp_dev->vmpck) +return memcmp (snp_dev->vmpck, zero_key,VMPCK_KEY_LEN ) ==0 ; + +return true; +}drivers/virt/coco/sevguest/sevguest.c line 76
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.c new file +10
-0+ +static void snp_disable_vmpck (struct snp_guest_dev *snp_dev) +{ +memzero_explicit (snp_dev->vmpck,VMPCK_KEY_LEN ); + snp_dev->vmpck =NULL ; +} + +static inline u64 __snp_get_msg_seqno (struct snp_guest_dev *snp_dev) +{ +u64 count;I may be overly paranoid here but how about
lockdep_assert_held(&snp_cmd_mutex);when writing or reading directly from this data?Quoted 6 lines
drivers/virt/coco/sevguest/sevguest.c new file +6
-0+ +/* Read the current message sequence counter from secrets pages */ + count = *snp_dev->os_area_msg_seqno; + +return count +1 ; +}drivers/virt/coco/sevguest/sevguest.c line 92
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.c new file +10
-0+ +/* Return a non-zero on success */ +static u64 snp_get_msg_seqno (struct snp_guest_dev *snp_dev) +{ +u64 count =__snp_get_msg_seqno (snp_dev); + +/* +* The message sequence counter for the SNP guest request is a 64-bit +* value but the version 2 of GHCB specification defines a 32-bit storage +* for the it. If the counter exceeds the 32-bit value then return zero. "for it. ..." or maybe "defines 32-bit field for the sequence counter"
drivers/virt/coco/sevguest/sevguest.c line 93
Quoted 1 line
drivers/virt/coco/sevguest/sevguest.c new file +1
-0+* The caller should check the return value, but if the caller happen to happens
Quoted 228 lines
drivers/virt/coco/sevguest/sevguest.c new file +228
-0+* not check the value and use it, then the firmware treats zero as an +* invalid number and will fail the message request. +*/ +if (count >=UINT_MAX ) { +pr_err_ratelimited ("SNP guest request message sequence counter overflow\n" ); +return 0 ; + } + +return count; +} + +static void snp_inc_msg_seqno (struct snp_guest_dev *snp_dev) +{ +/* +* The counter is also incremented by the PSP, so increment it by 2 +* and save in secrets page. +*/ + *snp_dev->os_area_msg_seqno +=2 ; +} + +static inline struct snp_guest_dev *to_snp_dev (struct file *file) +{ +struct miscdevice *dev = file->private_data; + + return container_of(dev, struct snp_guest_dev, misc); +} + +static struct snp_guest_crypto *init_crypto (struct snp_guest_dev *snp_dev,u8 *key,size_t keylen) +{ +struct snp_guest_crypto *crypto; + + crypto =kzalloc (sizeof (*crypto),GFP_KERNEL_ACCOUNT ); +if (!crypto) +return NULL ; + + crypto->tfm =crypto_alloc_aead ("gcm(aes)" ,0 ,0 ); +if (IS_ERR (crypto->tfm)) + goto e_free; + +if (crypto_aead_setkey (crypto->tfm, key, keylen)) + goto e_free_crypto; + + crypto->iv_len =crypto_aead_ivsize (crypto->tfm); +if (crypto->iv_len <12 ) { +dev_err (snp_dev->dev,"IV length is less than 12.\n" ); + goto e_free_crypto; + } + + crypto->iv =kmalloc (crypto->iv_len,GFP_KERNEL_ACCOUNT ); +if (!crypto->iv) + goto e_free_crypto; + +if (crypto_aead_authsize (crypto->tfm) >MAX_AUTHTAG_LEN ) { +if (crypto_aead_setauthsize (crypto->tfm,MAX_AUTHTAG_LEN )) { +dev_err (snp_dev->dev,"failed to set authsize to %d\n" ,MAX_AUTHTAG_LEN ); + goto e_free_crypto; + } + } + + crypto->a_len =crypto_aead_authsize (crypto->tfm); + crypto->authtag =kmalloc (crypto->a_len,GFP_KERNEL_ACCOUNT ); +if (!crypto->authtag) + goto e_free_crypto; + +return crypto; + +e_free_crypto: +crypto_free_aead (crypto->tfm); +e_free: +kfree (crypto->iv); +kfree (crypto->authtag); +kfree (crypto); + +return NULL ; +} + +static void deinit_crypto (struct snp_guest_crypto *crypto) +{ +crypto_free_aead (crypto->tfm); +kfree (crypto->iv); +kfree (crypto->authtag); +kfree (crypto); +} + +static int enc_dec_message (struct snp_guest_crypto *crypto,struct snp_guest_msg *msg, +u8 *src_buf,u8 *dst_buf,size_t len,bool enc) +{ +struct snp_guest_msg_hdr *hdr = &msg->hdr; +struct scatterlist src[3 ], dst[3 ]; +DECLARE_CRYPTO_WAIT (wait); +struct aead_request *req; +int ret; + + req =aead_request_alloc (crypto->tfm,GFP_KERNEL ); +if (!req) +return -ENOMEM ; + +/* +* AEAD memory operations: +* +------ AAD -------+------- DATA -----+---- AUTHTAG----+ +* | msg header | plaintext | hdr->authtag | +* | bytes 30h - 5Fh | or | | +* | | cipher | | +* +------------------+------------------+----------------+ +*/ +sg_init_table (src,3 ); +sg_set_buf (&src[0 ], &hdr->algo,AAD_LEN ); +sg_set_buf (&src[1 ], src_buf, hdr->msg_sz); +sg_set_buf (&src[2 ], hdr->authtag, crypto->a_len); + +sg_init_table (dst,3 ); +sg_set_buf (&dst[0 ], &hdr->algo,AAD_LEN ); +sg_set_buf (&dst[1 ], dst_buf, hdr->msg_sz); +sg_set_buf (&dst[2 ], hdr->authtag, crypto->a_len); + +aead_request_set_ad (req,AAD_LEN ); +aead_request_set_tfm (req, crypto->tfm); +aead_request_set_callback (req,0 , crypto_req_done, &wait); + +aead_request_set_crypt (req, src, dst, len, crypto->iv); + ret =crypto_wait_req (enc ?crypto_aead_encrypt (req) :crypto_aead_decrypt (req), &wait); + +aead_request_free (req); +return ret; +} + +static int __enc_payload (struct snp_guest_dev *snp_dev,struct snp_guest_msg *msg, +void *plaintext,size_t len) +{ +struct snp_guest_crypto *crypto = snp_dev->crypto; +struct snp_guest_msg_hdr *hdr = &msg->hdr; + +memset (crypto->iv,0 , crypto->iv_len); +memcpy (crypto->iv, &hdr->msg_seqno,sizeof (hdr->msg_seqno)); + +return enc_dec_message (crypto, msg, plaintext, msg->payload, len, true); +} + +static int dec_payload (struct snp_guest_dev *snp_dev,struct snp_guest_msg *msg, +void *plaintext,size_t len) +{ +struct snp_guest_crypto *crypto = snp_dev->crypto; +struct snp_guest_msg_hdr *hdr = &msg->hdr; + +/* Build IV with response buffer sequence number */ +memset (crypto->iv,0 , crypto->iv_len); +memcpy (crypto->iv, &hdr->msg_seqno,sizeof (hdr->msg_seqno)); + +return enc_dec_message (crypto, msg, msg->payload, plaintext, len, false); +} + +static int verify_and_dec_payload (struct snp_guest_dev *snp_dev,void *payload,u32 sz) +{ +struct snp_guest_crypto *crypto = snp_dev->crypto; +struct snp_guest_msg *resp = snp_dev->response; +struct snp_guest_msg *req = snp_dev->request; +struct snp_guest_msg_hdr *req_hdr = &req->hdr; +struct snp_guest_msg_hdr *resp_hdr = &resp->hdr; + +dev_dbg (snp_dev->dev,"response [seqno %lld type %d version %d sz %d]\n" , + resp_hdr->msg_seqno, resp_hdr->msg_type, resp_hdr->msg_version, resp_hdr->msg_sz); + +/* Verify that the sequence counter is incremented by 1 */ +if (unlikely (resp_hdr->msg_seqno != (req_hdr->msg_seqno +1 ))) +return -EBADMSG ; + +/* Verify response message type and version number. */ +if (resp_hdr->msg_type != (req_hdr->msg_type +1 ) || + resp_hdr->msg_version != req_hdr->msg_version) +return -EBADMSG ; + +/* +* If the message size is greater than our buffer length then return +* an error. +*/ +if (unlikely ((resp_hdr->msg_sz + crypto->a_len) > sz)) +return -EBADMSG ; + +/* Decrypt the payload */ +return dec_payload (snp_dev, resp, payload, resp_hdr->msg_sz + crypto->a_len); +} + +static bool enc_payload (struct snp_guest_dev *snp_dev,u64 seqno,int version,u8 type, +void *payload,size_t sz) +{ +struct snp_guest_msg *req = snp_dev->request; +struct snp_guest_msg_hdr *hdr = &req->hdr; + +memset (req,0 ,sizeof (*req)); + + hdr->algo =SNP_AEAD_AES_256_GCM ; + hdr->hdr_version =MSG_HDR_VER ; + hdr->hdr_sz =sizeof (*hdr); + hdr->msg_type = type; + hdr->msg_version = version; + hdr->msg_seqno = seqno; + hdr->msg_vmpck = vmpck_id; + hdr->msg_sz = sz; + +/* Verify the sequence number is non-zero */ +if (!hdr->msg_seqno) +return -ENOSR ; + +dev_dbg (snp_dev->dev,"request [seqno %lld type %d version %d sz %d]\n" , + hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz); + +return __enc_payload (snp_dev, req, payload, sz); +} + +static int handle_guest_request (struct snp_guest_dev *snp_dev,u64 exit_code,int msg_ver, +u8 type,void *req_buf,size_t req_sz,void *resp_buf, +u32 resp_sz,__u64 *fw_err) +{ +unsigned long err; +u64 seqno; +int rc; + +/* Get message sequence and verify that its a non-zero */ + seqno =snp_get_msg_seqno (snp_dev); +if (!seqno) +return -EIO ; + +memset (snp_dev->response,0 ,sizeof (*snp_dev->response)); + +/* Encrypt the userspace provided payload */ + rc =enc_payload (snp_dev, seqno, msg_ver, type, req_buf, req_sz); +if (rc) +return rc;
Quoted 8 lines
drivers/virt/coco/sevguest/sevguest.c line 324
Quoted 3 lines
drivers/virt/coco/sevguest/sevguest.c new file +3
-0+ +/* Call firmware to process the request */ + rc =snp_issue_guest_request (exit_code, &snp_dev->input, &err);Isn't everything in the file going to be calling this with
SVM_VMGEXIT_EXT_GUEST_REQUESTbecause they are all placing guest requests? If so, why not drop the @exit_code parameter and just hardcodeSVM_VMGEXIT_EXT_GUEST_REQUESThere?
Oops I see we use SVM_VMGEXIT_GUEST_REQUEST andSVM_VMGEXIT_GUEST_REQUEST, nevermind here.
Quoted 458 lines
drivers/virt/coco/sevguest/sevguest.c line 335
Quoted 12 lines
drivers/virt/coco/sevguest/sevguest.c new file +11
-0+if (fw_err) + *fw_err = err; + +if (rc) +return rc; + + rc =verify_and_dec_payload (snp_dev, resp_buf, resp_sz); +if (rc) { +/* +* The verify_and_dec_payload() will fail only if the hypervisor is +* actively modifiying the message header or corrupting the encrypted payload. modifiying
drivers/virt/coco/sevguest/sevguest.c line 338
Quoted 3 lines
drivers/virt/coco/sevguest/sevguest.c new file +3
-0+* This hints that hypervisor is acting in a bad faith. Disable the VMPCK so that +* the key cannot be used for any communication. +*/ This looks great, thanks for changes Brijesh. Should we mention in comment here or at
snp_disable_vmpck()the AES-GCM issues with continuing to use the key? Or will future updaters to this code understand already?Quoted 114 lines
drivers/virt/coco/sevguest/sevguest.c new file +114
-0+dev_alert (snp_dev->dev, +"Detected unexpected decode failure, disabling the vmpck_id %d\n" , vmpck_id); +snp_disable_vmpck (snp_dev); +return rc; + } + +/* Increment to new message sequence after payload descryption was successful. */ +snp_inc_msg_seqno (snp_dev); + +return 0 ; +} + +static int get_report (struct snp_guest_dev *snp_dev,struct snp_guest_request_ioctl *arg) +{ +struct snp_guest_crypto *crypto = snp_dev->crypto; +struct snp_report_resp *resp; +struct snp_report_req req; +int rc, resp_len; + +if (!arg->req_data || !arg->resp_data) +return -EINVAL ; + +/* Copy the request payload from userspace */ +if (copy_from_user (&req, (void __user *)arg->req_data,sizeof (req))) +return -EFAULT ; + +/* Message version must be non-zero */ +if (!req.msg_version) +return -EINVAL ; + +/* +* The intermediate response buffer is used while decrypting the +* response payload. Make sure that it has enough space to cover the +* authtag. +*/ + resp_len =sizeof (resp->data) + crypto->a_len; + resp =kzalloc (resp_len,GFP_KERNEL_ACCOUNT ); +if (!resp) +return -ENOMEM ; + +/* Issue the command to get the attestation report */ + rc =handle_guest_request (snp_dev,SVM_VMGEXIT_GUEST_REQUEST , req.msg_version, +SNP_MSG_REPORT_REQ , &req.user_data,sizeof (req.user_data), + resp->data, resp_len, &arg->fw_err); +if (rc) + goto e_free; + +/* Copy the response payload to userspace */ +if (copy_to_user ((void __user *)arg->resp_data, resp,sizeof (*resp))) + rc = -EFAULT ; + +e_free: +kfree (resp); +return rc; +} + +static long snp_guest_ioctl (struct file *file,unsigned int ioctl,unsigned long arg) +{ +struct snp_guest_dev *snp_dev =to_snp_dev (file); +void __user *argp = (void __user *)arg; +struct snp_guest_request_ioctl input; +int ret = -ENOTTY ; + +if (copy_from_user (&input, argp,sizeof (input))) +return -EFAULT ; + + input.fw_err =0 ; + +mutex_lock (&snp_cmd_mutex); + +/* Check if the VMPCK is not empty */ +if (is_vmpck_empty (snp_dev)) { +dev_err_ratelimited (snp_dev->dev,"VMPCK is disabled\n" ); +mutex_unlock (&snp_cmd_mutex); +return -ENOTTY ; + } + +switch (ioctl) { +case SNP_GET_REPORT : + ret =get_report (snp_dev, &input); +break ; +default : +break ; + } + +mutex_unlock (&snp_cmd_mutex); + +if (input.fw_err &©_to_user (argp, &input,sizeof (input))) +return -EFAULT ; + +return ret; +} + +static void free_shared_pages (void *buf,size_t sz) +{ +unsigned int npages =PAGE_ALIGN (sz) >>PAGE_SHIFT ; + +if (!buf) +return ; + +/* If fail to restore the encryption mask then leak it. */ +if (WARN_ONCE (set_memory_encrypted ((unsigned long )buf, npages), +"Failed to restore encryption mask (leak it)\n" )) +return ; + +__free_pages (virt_to_page (buf),get_order (sz)); +} + +static void *alloc_shared_pages (size_t sz) +{ +unsigned int npages =PAGE_ALIGN (sz) >>PAGE_SHIFT ; +struct page *page; +int ret; +drivers/virt/coco/sevguest/sevguest.c line 462
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.c new file +10
-0+ page =alloc_pages (GFP_KERNEL_ACCOUNT ,get_order (sz)); +if (IS_ERR (page)) +return NULL ; + + ret =set_memory_decrypted ((unsigned long )page_address (page), npages); +if (ret) { +pr_err ("SEV-SNP: failed to mark page shared, ret=%d\n" , ret); +__free_pages (page,get_order (sz)); +return NULL ; + }No strong preference or anything just curious. Why not allocate from SWIOTLB or use the DMA pool that supports decrypted memory:
https://lkml.org/lkml/2020/4/14/1508.Quoted 168 lines
drivers/virt/coco/sevguest/sevguest.c new file +139
-0+ +return page_address (page); +} + +static const struct file_operations snp_guest_fops = { + .owner =THIS_MODULE , + .unlocked_ioctl = snp_guest_ioctl, +}; + +static u8 *get_vmpck (int id,struct snp_secrets_page_layout *layout,u32 **seqno) +{ +u8 *key =NULL ; + +switch (id) { +case 0 : + *seqno = &layout->os_area.msg_seqno_0; + key = layout->vmpck0; +break ; +case 1 : + *seqno = &layout->os_area.msg_seqno_1; + key = layout->vmpck1; +break ; +case 2 : + *seqno = &layout->os_area.msg_seqno_2; + key = layout->vmpck2; +break ; +case 3 : + *seqno = &layout->os_area.msg_seqno_3; + key = layout->vmpck3; +break ; +default : +break ; + } + +return key; +} + +static int __init snp_guest_probe (struct platform_device *pdev) +{ +struct snp_secrets_page_layout *layout; +struct snp_guest_platform_data *data; +struct device *dev = &pdev->dev; +struct snp_guest_dev *snp_dev; +struct miscdevice *misc; +int ret; + +if (!dev->platform_data) +return -ENODEV ; + + data = (struct snp_guest_platform_data *)dev->platform_data; + layout = (__force void *)ioremap_encrypted (data->secrets_gpa,PAGE_SIZE ); +if (!layout) +return -ENODEV ; + + ret = -ENOMEM ; + snp_dev =devm_kzalloc (&pdev->dev,sizeof (struct snp_guest_dev ),GFP_KERNEL ); +if (!snp_dev) + goto e_fail; + + ret = -EINVAL ; + snp_dev->vmpck =get_vmpck (vmpck_id, layout, &snp_dev->os_area_msg_seqno); +if (!snp_dev->vmpck) { +dev_err (dev,"invalid vmpck id %d\n" , vmpck_id); + goto e_fail; + } + +/* Verify that VMPCK is not zero. */ +if (is_vmpck_empty (snp_dev)) { +dev_err (dev,"vmpck id %d is null\n" , vmpck_id); + goto e_fail; + } + +platform_set_drvdata (pdev, snp_dev); + snp_dev->dev = dev; + snp_dev->layout = layout; + +/* Allocate the shared page used for the request and response message. */ + snp_dev->request =alloc_shared_pages (sizeof (struct snp_guest_msg )); +if (!snp_dev->request) + goto e_fail; + + snp_dev->response =alloc_shared_pages (sizeof (struct snp_guest_msg )); +if (!snp_dev->response) + goto e_fail; + + ret = -EIO ; + snp_dev->crypto =init_crypto (snp_dev, snp_dev->vmpck,VMPCK_KEY_LEN ); +if (!snp_dev->crypto) + goto e_fail; + + misc = &snp_dev->misc; + misc->minor =MISC_DYNAMIC_MINOR ; + misc->name =DEVICE_NAME ; + misc->fops = &snp_guest_fops; + +/* initial the input address for guest request */ + snp_dev->input.req_gpa =__pa (snp_dev->request); + snp_dev->input.resp_gpa =__pa (snp_dev->response); + + ret =misc_register (misc); +if (ret) + goto e_fail; + +dev_info (dev,"Initialized SNP guest driver (using vmpck_id %d)\n" , vmpck_id); +return 0 ; + +e_fail: +iounmap (layout); +free_shared_pages (snp_dev->request,sizeof (struct snp_guest_msg )); +free_shared_pages (snp_dev->response,sizeof (struct snp_guest_msg )); + +return ret; +} + +static int __exit snp_guest_remove(struct platform_device *pdev) +{ +struct snp_guest_dev *snp_dev =platform_get_drvdata (pdev); + +free_shared_pages (snp_dev->request,sizeof (struct snp_guest_msg )); +free_shared_pages (snp_dev->response,sizeof (struct snp_guest_msg )); +deinit_crypto (snp_dev->crypto); +misc_deregister (&snp_dev->misc); + +return 0 ; +} + +static struct platform_driver snp_guest_driver = { + .remove =__exit_p (snp_guest_remove), + .driver = { + .name ="snp-guest" , + }, +}; + +module_platform_driver_probe (snp_guest_driver, snp_guest_probe); + +MODULE_AUTHOR ("Brijesh Singh <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +MODULE_VERSION ("1.0.0" ); +MODULE_DESCRIPTION ("AMD SNP Guest Driver" );drivers/virt/coco/sevguest/sevguest.h new file +23
-0@@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2021 Advanced Micro Devices, Inc. +* +* Author: Brijesh Singh <[email protected]> +* +* SEV-SNP API spec is available at https://developer.amd.com/sev +*/ + +#ifndef __LINUX_SEVGUEST_H_ +#define __LINUX_SEVGUEST_H_ + +#include <linux/types.h> + +#define MAX_AUTHTAG_LEN 32 + +/* See SNP spec SNP_GUEST_REQUEST section for the structure */ +enum msg_type { +SNP_MSG_TYPE_INVALID =0 , +SNP_MSG_CPUID_REQ , +SNP_MSG_CPUID_RSP , +SNP_MSG_KEY_REQ , + SNP_MSG_KEY_RSP,drivers/virt/coco/sevguest/sevguest.h line 33
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.h new file +10
-0+SNP_MSG_REPORT_REQ , +SNP_MSG_REPORT_RSP , +SNP_MSG_EXPORT_REQ , +SNP_MSG_EXPORT_RSP , +SNP_MSG_IMPORT_REQ , +SNP_MSG_IMPORT_RSP , +SNP_MSG_ABSORB_REQ , +SNP_MSG_ABSORB_RSP , +SNP_MSG_VMRK_REQ , + SNP_MSG_VMRK_RSP,Did you want to include
MSG_ABSORB_NOMA_REQandMSG_ABSORB_NOMA_RESPhere?Quoted 83 lines
drivers/virt/coco/sevguest/sevguest.h new file +65
-0+ +SNP_MSG_TYPE_MAX +}; + +enum aead_algo { +SNP_AEAD_INVALID , +SNP_AEAD_AES_256_GCM , +}; + +struct snp_guest_msg_hdr { +u8 authtag[MAX_AUTHTAG_LEN ]; +u64 msg_seqno; +u8 rsvd1[8 ]; +u8 algo; +u8 hdr_version; +u16 hdr_sz; +u8 msg_type; +u8 msg_version; +u16 msg_sz; +u32 rsvd2; +u8 msg_vmpck; +u8 rsvd3[35 ]; +} __packed; + +struct snp_guest_msg { +struct snp_guest_msg_hdr hdr; +u8 payload[4000 ]; +} __packed; + +/* +* The secrets page contains 96-bytes of reserved field that can be used by +* the guest OS. The guest OS uses the area to save the message sequence +* number for each VMPCK. +* +* See the GHCB spec section Secret page layout for the format for this area. +*/ +struct secrets_os_area { +u32 msg_seqno_0; +u32 msg_seqno_1; +u32 msg_seqno_2; +u32 msg_seqno_3; +u64 ap_jump_table_pa; +u8 rsvd[40 ]; +u8 guest_usage[32 ]; +} __packed; + +#define VMPCK_KEY_LEN 32 + +/* See the SNP spec version 0.9 for secrets page format */ +struct snp_secrets_page_layout { +u32 version; +u32 imien :1 , + rsvd1 :31 ; +u32 fms; +u32 rsvd2; +u8 gosvw[16 ]; +u8 vmpck0[VMPCK_KEY_LEN ]; +u8 vmpck1[VMPCK_KEY_LEN ]; +u8 vmpck2[VMPCK_KEY_LEN ]; +u8 vmpck3[VMPCK_KEY_LEN ]; +struct secrets_os_area os_area; +u8 rsvd3[3840 ]; +} __packed; + +#endif /* __LINUX_SNP_GUEST_H__ */ include/uapi/linux/sev-guest.h new file +12
-0@@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ +/* +* Userspace interface for AMD SEV and SEV-SNP guest driver. +* +* Copyright (C) 2021 Advanced Micro Devices, Inc. +* +* Author: Brijesh Singh <[email protected]> +* +* SEV API specification is available at: https://developer.amd.com/sev/ +*/ + +#ifndef __UAPI_LINUX_SEV_GUEST_H_include/uapi/linux/sev-guest.h line 22
Quoted 10 lines
include/uapi/linux/sev-guest.h new file +10
-0+#define __UAPI_LINUX_SEV_GUEST_H_ + +#include <linux/types.h> + +struct snp_report_req { +/* message version number (must be non-zero) */ +__u8 msg_version; + +/* user data that should be included in the report */ +__u8 user_data[64 ];Are we missing the 'vmpl' field here? Does those default all requests to be signed with VMPL0? Users might want to change that, they could be using a paravisor.
Quoted 25 lines
include/uapi/linux/sev-guest.h new file +22
-1+}; + +struct snp_report_resp { +/* response data, see SEV-SNP spec for the format */ +__u8 data[4000 ]; +}; + +struct snp_guest_request_ioctl { +/* Request and response structure address */ +__u64 req_data; +__u64 resp_data; + +/* firmware error code on failure (see psp-sev.h) */ +__u64 fw_err; +}; + +#define SNP_GUEST_REQ_IOC_TYPE 'S' + +/* Get SNP attestation report */ +#define SNP_GET_REPORT _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x0, struct snp_guest_request_ioctl) + +#endif /* __UAPI_LINUX_SEV_GUEST_H_ */ --2.25.1
Re: [PATCH v7 43/45] virt: Add SEV-SNP guest driver
In reply to Peter GondaQuoted 9 lines · Peter Gonda
Documentation/virt/coco/sevguest.rst line 43
Quoted 4 lines
Documentation/virt/coco/sevguest.rst new file +4
-0+The guest ioctl should be issued on a file descriptor of the /dev/sev-guest device. +The ioctl accepts struct snp_user_guest_request. The input and output structure is +specified through the req_data and resp_data field respectively. If the ioctl fails +to execute due to a firmware error, then fw_err code will be set.Should way say what it will be set to? Also Sean pointed out on CCP driver that 0 is strange to set the error to, its a uint so we cannot do -1 like we did there. What about all FFs?
Sure, all FF's works, I can document and use it.
Quoted 8 lines
drivers/virt/coco/sevguest/sevguest.c line 76
Quoted 3 lines
drivers/virt/coco/sevguest/sevguest.c new file +3
-0+static inline u64 __snp_get_msg_seqno (struct snp_guest_dev *snp_dev) +{ +u64 count;I may be overly paranoid here but how about
lockdep_assert_held(&snp_cmd_mutex);when writing or reading directly from this data?
Sure, I can do it.
...
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.c line 335
Quoted 9 lines
drivers/virt/coco/sevguest/sevguest.c new file +9
-0+ +if (rc) +return rc; + + rc =verify_and_dec_payload (snp_dev, resp_buf, resp_sz); +if (rc) { +/* +* The verify_and_dec_payload() will fail only if the hypervisor is +* actively modifiying the message header or corrupting the encrypted payload. modifiying
Quoted 9 lines
drivers/virt/coco/sevguest/sevguest.c line 338
Quoted 3 lines
drivers/virt/coco/sevguest/sevguest.c new file +3
-0+* This hints that hypervisor is acting in a bad faith. Disable the VMPCK so that +* the key cannot be used for any communication. +*/ This looks great, thanks for changes Brijesh. Should we mention in comment here or at
snp_disable_vmpck()the AES-GCM issues with continuing to use the key? Or will future updaters to this code understand already?
Sure, I can add comment about the AES-GCM.
...
Quoted 12 lines
Quoted 12 lines
drivers/virt/coco/sevguest/sevguest.h new file +12
-0+ +/* See SNP spec SNP_GUEST_REQUEST section for the structure */ +enum msg_type { +SNP_MSG_TYPE_INVALID =0 , +SNP_MSG_CPUID_REQ , +SNP_MSG_CPUID_RSP , +SNP_MSG_KEY_REQ , +SNP_MSG_KEY_RSP , +SNP_MSG_REPORT_REQ , +SNP_MSG_REPORT_RSP , +SNP_MSG_EXPORT_REQ , +SNP_MSG_EXPORT_RSP ,
Quoted 9 lines
drivers/virt/coco/sevguest/sevguest.h line 33
Quoted 6 lines
drivers/virt/coco/sevguest/sevguest.h new file +6
-0+SNP_MSG_IMPORT_REQ , +SNP_MSG_IMPORT_RSP , +SNP_MSG_ABSORB_REQ , +SNP_MSG_ABSORB_RSP , +SNP_MSG_VMRK_REQ , + SNP_MSG_VMRK_RSP,Did you want to include
MSG_ABSORB_NOMA_REQandMSG_ABSORB_NOMA_RESPhere?
Yes, I can includes those for the completeness.
...
Quoted 11 lines
include/uapi/linux/sev-guest.h line 22
Quoted 6 lines
include/uapi/linux/sev-guest.h new file +6
-0+struct snp_report_req { +/* message version number (must be non-zero) */ +__u8 msg_version; + +/* user data that should be included in the report */ +__u8 user_data[64 ];Are we missing the 'vmpl' field here? Does those default all requests to be signed with VMPL0? Users might want to change that, they could be using a paravisor.
Good question, so far I was thinking that guest kernel will provide its vmpl level instead of accepted the vmpl level from the userspace. Do you see a need for a userspace to provide this information ?
thanks
Re: [PATCH v7 43/45] virt: Add SEV-SNP guest driver
Quoted 94 lines · Brijesh Singh
Quoted 9 lines · Peter Gonda
Documentation/virt/coco/sevguest.rst line 43
Quoted 4 lines
Documentation/virt/coco/sevguest.rst new file +4
-0+The guest ioctl should be issued on a file descriptor of the /dev/sev-guest device. +The ioctl accepts struct snp_user_guest_request. The input and output structure is +specified through the req_data and resp_data field respectively. If the ioctl fails +to execute due to a firmware error, then fw_err code will be set.Should way say what it will be set to? Also Sean pointed out on CCP driver that 0 is strange to set the error to, its a uint so we cannot do -1 like we did there. What about all FFs?
Sure, all FF's works, I can document and use it.
Quoted 8 lines
drivers/virt/coco/sevguest/sevguest.c line 76
Quoted 3 lines
drivers/virt/coco/sevguest/sevguest.c new file +3
-0+static inline u64 __snp_get_msg_seqno (struct snp_guest_dev *snp_dev) +{ +u64 count;I may be overly paranoid here but how about
lockdep_assert_held(&snp_cmd_mutex);when writing or reading directly from this data?Sure, I can do it.
...
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.c line 335
Quoted 9 lines
drivers/virt/coco/sevguest/sevguest.c new file +9
-0+ +if (rc) +return rc; + + rc =verify_and_dec_payload (snp_dev, resp_buf, resp_sz); +if (rc) { +/* +* The verify_and_dec_payload() will fail only if the hypervisor is +* actively modifiying the message header or corrupting the encrypted payload. modifiying
Quoted 9 lines
drivers/virt/coco/sevguest/sevguest.c line 338
Quoted 3 lines
drivers/virt/coco/sevguest/sevguest.c new file +3
-0+* This hints that hypervisor is acting in a bad faith. Disable the VMPCK so that +* the key cannot be used for any communication. +*/ This looks great, thanks for changes Brijesh. Should we mention in comment here or at
snp_disable_vmpck()the AES-GCM issues with continuing to use the key? Or will future updaters to this code understand already?Sure, I can add comment about the AES-GCM.
...
Quoted 12 lines
Quoted 12 lines
drivers/virt/coco/sevguest/sevguest.h new file +12
-0+ +/* See SNP spec SNP_GUEST_REQUEST section for the structure */ +enum msg_type { +SNP_MSG_TYPE_INVALID =0 , +SNP_MSG_CPUID_REQ , +SNP_MSG_CPUID_RSP , +SNP_MSG_KEY_REQ , +SNP_MSG_KEY_RSP , +SNP_MSG_REPORT_REQ , +SNP_MSG_REPORT_RSP , +SNP_MSG_EXPORT_REQ , +SNP_MSG_EXPORT_RSP ,Quoted 9 lines
drivers/virt/coco/sevguest/sevguest.h line 33
Quoted 6 lines
drivers/virt/coco/sevguest/sevguest.h new file +6
-0+SNP_MSG_IMPORT_REQ , +SNP_MSG_IMPORT_RSP , +SNP_MSG_ABSORB_REQ , +SNP_MSG_ABSORB_RSP , +SNP_MSG_VMRK_REQ , + SNP_MSG_VMRK_RSP,Did you want to include
MSG_ABSORB_NOMA_REQandMSG_ABSORB_NOMA_RESPhere?Yes, I can includes those for the completeness.
...
Quoted 11 lines
include/uapi/linux/sev-guest.h line 22
Quoted 6 lines
include/uapi/linux/sev-guest.h new file +6
-0+struct snp_report_req { +/* message version number (must be non-zero) */ +__u8 msg_version; + +/* user data that should be included in the report */ +__u8 user_data[64 ];Are we missing the 'vmpl' field here? Does those default all requests to be signed with VMPL0? Users might want to change that, they could be using a paravisor.
Quoted 3 lines
Good question, so far I was thinking that guest kernel will provide its vmpl level instead of accepted the vmpl level from the userspace. Do you see a need for a userspace to provide this information ?
That seems fine. I am just confused because we are just encrypting this struct as the payload for the PSP. Doesn't the message require a struct that looks like 'snp_report_req_user_data' below?
snp_report_req{
/* message version number (must be non-zero) */
__u8 msg_version;
/* user data that should be included in the report */
struct snp_report_req_user_data;
};struct snp_report_req_user_data {
u8 user_data[64];
u32 vmpl;
u32 reserved;
};
Quoted 3 lines
thanks
Re: [PATCH v7 43/45] virt: Add SEV-SNP guest driver
Quoted 99 lines · Peter Gonda
Quoted 83 lines · Brijesh Singh
Quoted 8 lines · Peter Gonda
Documentation/virt/coco/sevguest.rst line 43
Quoted 4 lines
Documentation/virt/coco/sevguest.rst new file +4
-0+The guest ioctl should be issued on a file descriptor of the /dev/sev-guest device. +The ioctl accepts struct snp_user_guest_request. The input and output structure is +specified through the req_data and resp_data field respectively. If the ioctl fails +to execute due to a firmware error, then fw_err code will be set.Should way say what it will be set to? Also Sean pointed out on CCP driver that 0 is strange to set the error to, its a uint so we cannot do -1 like we did there. What about all FFs?
Sure, all FF's works, I can document and use it.
Quoted 7 lines
drivers/virt/coco/sevguest/sevguest.c line 76
Quoted 3 lines
drivers/virt/coco/sevguest/sevguest.c new file +3
-0+static inline u64 __snp_get_msg_seqno (struct snp_guest_dev *snp_dev) +{ +u64 count;I may be overly paranoid here but how about
lockdep_assert_held(&snp_cmd_mutex);when writing or reading directly from this data?Sure, I can do it.
...
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.c line 335
Quoted 9 lines
drivers/virt/coco/sevguest/sevguest.c new file +9
-0+ +if (rc) +return rc; + + rc =verify_and_dec_payload (snp_dev, resp_buf, resp_sz); +if (rc) { +/* +* The verify_and_dec_payload() will fail only if the hypervisor is +* actively modifiying the message header or corrupting the encrypted payload. modifiying
Quoted 8 lines
drivers/virt/coco/sevguest/sevguest.c line 338
Quoted 3 lines
drivers/virt/coco/sevguest/sevguest.c new file +3
-0+* This hints that hypervisor is acting in a bad faith. Disable the VMPCK so that +* the key cannot be used for any communication. +*/ This looks great, thanks for changes Brijesh. Should we mention in comment here or at
snp_disable_vmpck()the AES-GCM issues with continuing to use the key? Or will future updaters to this code understand already?Sure, I can add comment about the AES-GCM.
...
Quoted 11 lines
Quoted 11 lines
drivers/virt/coco/sevguest/sevguest.h new file +11
-0+ +/* See SNP spec SNP_GUEST_REQUEST section for the structure */ +enum msg_type { +SNP_MSG_TYPE_INVALID =0 , +SNP_MSG_CPUID_REQ , +SNP_MSG_CPUID_RSP , +SNP_MSG_KEY_REQ , +SNP_MSG_KEY_RSP , +SNP_MSG_REPORT_REQ , +SNP_MSG_REPORT_RSP , +SNP_MSG_EXPORT_REQ ,Quoted 9 lines
drivers/virt/coco/sevguest/sevguest.h line 33
Quoted 7 lines
drivers/virt/coco/sevguest/sevguest.h new file +7
-0+SNP_MSG_EXPORT_RSP , +SNP_MSG_IMPORT_REQ , +SNP_MSG_IMPORT_RSP , +SNP_MSG_ABSORB_REQ , +SNP_MSG_ABSORB_RSP , +SNP_MSG_VMRK_REQ , + SNP_MSG_VMRK_RSP,Did you want to include
MSG_ABSORB_NOMA_REQandMSG_ABSORB_NOMA_RESPhere?Yes, I can includes those for the completeness.
...
Quoted 10 lines
include/uapi/linux/sev-guest.h line 22
Quoted 6 lines
include/uapi/linux/sev-guest.h new file +6
-0+struct snp_report_req { +/* message version number (must be non-zero) */ +__u8 msg_version; + +/* user data that should be included in the report */ +__u8 user_data[64 ];Are we missing the 'vmpl' field here? Does those default all requests to be signed with VMPL0? Users might want to change that, they could be using a paravisor.
Quoted 3 lines
Good question, so far I was thinking that guest kernel will provide its vmpl level instead of accepted the vmpl level from the userspace. Do you see a need for a userspace to provide this information ?
That seems fine. I am just confused because we are just encrypting this struct as the payload for the PSP. Doesn't the message require a struct that looks like '
snp_report_req_user_data' below?snp_report_req{ /* message version number (must be non-zero) */ __u8 msg_version; /* user data that should be included in the report */ struct snp_report_req_user_data; };
Quoted 6 lines
struct
snp_report_req_user_data{
u8 user_data[64];
u32 vmpl;
u32 reserved;
};
The snp_guest_msg structure is zero'ed before building the hdr and copying the user provided input, see enc_payload. The patch series was focused on vmpl-0 only I didn't consider anything other than vmpl-. Let me work to provide the option for userspace to provide the vmpl as an input during the request so that we give the flexibility to userspace.
Quoted 2 lines
Quoted 2 lines
thanks
PATCH v7 44/45 virt: sevguest: Add support to derive key
In reply to Brijesh SinghThe SNP_GET_DERIVED_KEY ioctl interface can be used by the SNP guest to ask the firmware to provide a key derived from a root key. The derived key may be used by the guest for any purposes it choose, such as a sealing key or communicating with the external entities.
See SEV-SNP firmware spec for more information.
--- Documentation/virt/coco/sevguest.rst | 19 ++++++++++- drivers/virt/coco/sevguest/sevguest.c | 49 +++++++++++++++++++++++++++ include/uapi/linux/sev-guest.h | 24 +++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-)
Documentation/virt/coco/sevguest.rst +18 -1
@@ -64,10 +64,27 @@ The SNP_GET_REPORT ioctl can be used to query the attestation report from the SEV-SNP firmware. The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command provided by the SEV-SNP firmware to query the attestation report. -On success, the snp_report_resp.data will contains the report. The report +On success, the snp_report_resp.data will contain the report. The report will contain the format described in the SEV-SNP specification. See the SEV-SNP specification for further details. +2.2 SNP_GET_DERIVED_KEY +----------------------- +:Technology: sev-snp +:Type: guest ioctl +:Parameters (in): struct snp_derived_key_req +:Returns (out): struct snp_derived_key_req on success, -negative on error + +The SNP_GET_DERIVED_KEY ioctl can be used to get a key derive from a root key. +The derived key can be used by the guest for any purpose, such as sealing keys +or communicating with external entities. + +The ioctl uses the SNP_GUEST_REQUEST (MSG_KEY_REQ) command provided by the +SEV-SNP firmware to derive the key. See SEV-SNP specification for further details +on the various fields passed in the key derivation request. + +On success, the snp_derived_key_resp.data will contains the derived key value. See +the SEV-SNP specification for further details. Reference ---------
drivers/virt/coco/sevguest/sevguest.c +49 -0
61 lines not on this page · raw message
include/uapi/linux/sev-guest.h +24 -0
@@ -36,9 +36,33 @@ struct snp_guest_request_ioctl { __u64 fw_err; }; +struct __snp_derived_key_req { +__u32 root_key_select; +__u32 rsvd; +__u64 guest_field_select; +__u32 vmpl; +__u32 guest_svn; +__u64 tcb_version; +}; + +struct snp_derived_key_req { +/* message version number (must be non-zero) */ +__u8 msg_version; + +struct __snp_derived_key_req data; +}; + +struct snp_derived_key_resp { +/* response data, see SEV-SNP spec for the format */ +__u8 data[64 ]; +}; +#define SNP_GUEST_REQ_IOC_TYPE 'S'/* Get SNP attestation report */ #define SNP_GET_REPORT _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x0, struct snp_guest_request_ioctl) +/* Get a derived key from the root */ +#define SNP_GET_DERIVED_KEY _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x1, struct snp_guest_request_ioctl) +#endif /* __UAPI_LINUX_SEV_GUEST_H_ */
Signature · 1 line
2.25.1
Re: [PATCH v7 44/45] virt: sevguest: Add support to derive key
Quoted 26 lines · Brijesh Singh
The
SNP_GET_DERIVED_KEYioctl interface can be used by the SNP guest to ask the firmware to provide a key derived from a root key. The derived key may be used by the guest for any purposes it choose, such as a sealing key or communicating with the external entities.See SEV-SNP firmware spec for more information.
Signed-off-by Brijesh Singh <[email protected]>--- Documentation/virt/coco/sevguest.rst | 19 ++++++++++- drivers/virt/coco/sevguest/sevguest.c | 49 +++++++++++++++++++++++++++ include/uapi/linux/sev-guest.h | 24 +++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-)Documentation/virt/coco/sevguest.rst +1
-1@@ -64,10 +64,27 @@ The SNP_GET_REPORT ioctl can be used to query the attestation report from the SEV-SNP firmware. The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command provided by the SEV-SNP firmware to query the attestation report. -On success, the snp_report_resp.data will contains the report. The report +On success, the snp_report_resp.data will contain the report. The report will contain the format described in the SEV-SNP specification. See the SEV-SNP
Documentation/virt/coco/sevguest.rst The SNP_GET_REPORT ioctl can be used to query the attestation report from the · line 78
Quoted 10 lines
Documentation/virt/coco/sevguest.rst +8
-0specification for further details. +2.2 SNP_GET_DERIVED_KEY +----------------------- +:Technology: sev-snp +:Type: guest ioctl +:Parameters (in): struct snp_derived_key_req +:Returns (out): struct snp_derived_key_req on success, -negative on error + +The SNP_GET_DERIVED_KEY ioctl can be used to get a key derive from a root key.
derived
Documentation/virt/coco/sevguest.rst The SNP_GET_REPORT ioctl can be used to query the attestation report from the · line 86
Quoted 8 lines
Documentation/virt/coco/sevguest.rst +8
-0+The derived key can be used by the guest for any purpose, such as sealing keys +or communicating with external entities. + +The ioctl uses the SNP_GUEST_REQUEST (MSG_KEY_REQ) command provided by the +SEV-SNP firmware to derive the key. See SEV-SNP specification for further details +on the various fields passed in the key derivation request. + +On success, the snp_derived_key_resp.data will contains the derived key value. See
".data will contain the..." or ".data contains the derived key..."
Quoted 9 lines
Documentation/virt/coco/sevguest.rst +1
-0+the SEV-SNP specification for further details. Reference ---------drivers/virt/coco/sevguest/sevguest.c +0
-0
drivers/virt/coco/sevguest/sevguest.c static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io · line 401
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.c +7
-0@@ -392,6 +392,52 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_ioreturn rc; } +static int get_derived_key (struct snp_guest_dev *snp_dev,struct snp_guest_request_ioctl *arg) +{ +struct snp_guest_crypto *crypto = snp_dev->crypto; +struct snp_derived_key_resp resp = {0 }; +struct snp_derived_key_req req; +int rc, resp_len; +u8 buf[89 ];
Could we document this magic number?
Quoted 17 lines
drivers/virt/coco/sevguest/sevguest.c +17
-0+ +if (!arg->req_data || !arg->resp_data) +return -EINVAL ; + +/* Copy the request payload from userspace */ +if (copy_from_user (&req, (void __user *)arg->req_data,sizeof (req))) +return -EFAULT ; + +/* Message version must be non-zero */ +if (!req.msg_version) +return -EINVAL ; + +/* +* The intermediate response buffer is used while decrypting the +* response payload. Make sure that it has enough space to cover the +* authtag. +*/
drivers/virt/coco/sevguest/sevguest.c static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io · line 428
Quoted 10 lines
drivers/virt/coco/sevguest/sevguest.c +10
-0+ resp_len =sizeof (resp.data) + crypto->a_len; +if (sizeof (buf) < resp_len) +return -ENOMEM ; + +/* Issue the command to get the attestation report */ + rc =handle_guest_request (snp_dev,SVM_VMGEXIT_GUEST_REQUEST , req.msg_version, +SNP_MSG_KEY_REQ , &req.data,sizeof (req.data), buf, resp_len, + &arg->fw_err); +if (rc) + goto e_free;
Should we check the first 32 bits of |data| here since that is a status field? If we see 16h here we could return -EINVAL, or better to let userspace deal with that error handling?
Quoted 66 lines
drivers/virt/coco/sevguest/sevguest.c +15
-0+ +/* Copy the response payload to userspace */ +memcpy (resp.data, buf,sizeof (resp.data)); +if (copy_to_user ((void __user *)arg->resp_data, &resp,sizeof (resp))) + rc = -EFAULT ; + +e_free: +memzero_explicit (buf,sizeof (buf)); +memzero_explicit (&resp,sizeof (resp)); +return rc; +} +static long snp_guest_ioctl (struct file *file,unsigned int ioctl,unsigned long arg) {struct snp_guest_dev *snp_dev =to_snp_dev (file);@@ -417,6 +463,9 @@ static long snp_guest_ioctl(struct file *file, unsigned int ioctl, unsigned longcase SNP_GET_REPORT : ret =get_report (snp_dev, &input);break ; +case SNP_GET_DERIVED_KEY : + ret =get_derived_key (snp_dev, &input); +break ;default :break ; }include/uapi/linux/sev-guest.h +24
-1@@ -36,9 +36,33 @@ struct snp_guest_request_ioctl { __u64 fw_err; }; +struct __snp_derived_key_req { +__u32 root_key_select; +__u32 rsvd; +__u64 guest_field_select; +__u32 vmpl; +__u32 guest_svn; +__u64 tcb_version; +}; + +struct snp_derived_key_req { +/* message version number (must be non-zero) */ +__u8 msg_version; + +struct __snp_derived_key_req data; +}; + +struct snp_derived_key_resp { +/* response data, see SEV-SNP spec for the format */ +__u8 data[64 ]; +}; +#define SNP_GUEST_REQ_IOC_TYPE 'S'/* Get SNP attestation report */ #define SNP_GET_REPORT _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x0, struct snp_guest_request_ioctl) +/* Get a derived key from the root */ +#define SNP_GET_DERIVED_KEY _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x1, struct snp_guest_request_ioctl) +#endif /* __UAPI_LINUX_SEV_GUEST_H_ */ --2.25.1
Re: [PATCH v7 44/45] virt: sevguest: Add support to derive key
On 11/18/21 10:43 AM, Peter Gonda wrote:
...
Quoted 4 lines
Quoted 1 line
+ u8 buf[89];
Could we document this magic number?
Yes, I will document from where this number came.
Quoted 23 lines
Quoted 23 lines
drivers/virt/coco/sevguest/sevguest.c +23
-0+ +if (!arg->req_data || !arg->resp_data) +return -EINVAL ; + +/* Copy the request payload from userspace */ +if (copy_from_user (&req, (void __user *)arg->req_data,sizeof (req))) +return -EFAULT ; + +/* Message version must be non-zero */ +if (!req.msg_version) +return -EINVAL ; + +/* +* The intermediate response buffer is used while decrypting the +* response payload. Make sure that it has enough space to cover the +* authtag. +*/ + resp_len =sizeof (resp.data) + crypto->a_len; +if (sizeof (buf) < resp_len) +return -ENOMEM ; + +/* Issue the command to get the attestation report */ + rc = handle_guest_request(snp_dev, SVM_VMGEXIT_GUEST_REQUEST, req.msg_version,
Quoted 9 lines
drivers/virt/coco/sevguest/sevguest.c static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io · line 428
Quoted 4 lines
drivers/virt/coco/sevguest/sevguest.c +4
-0+SNP_MSG_KEY_REQ , &req.data,sizeof (req.data), buf, resp_len, + &arg->fw_err); +if (rc) + goto e_free;Should we check the first 32 bits of |data| here since that is a status field? If we see 16h here we could return
-EINVAL, or better to let userspace deal with that error handling?
I was trying to avoid looking into a response structure to keep the flexibility; e.g if SNP firmware changes a response format then we don't need to have any changes in the driver. The userspace should be able to deal with it and it can check the "status" or a new field etc.
thanks
PATCH v7 45/45 virt: sevguest: Add support to get extended report
In reply to Brijesh SinghVersion 2 of GHCB specification defines Non-Automatic-Exit(NAE) to get the extended guest report. It is similar to the SNP_GET_REPORT ioctl. The main difference is related to the additional data that will be returned. The additional data returned is a certificate blob that can be used by the SNP guest user. The certificate blob layout is defined in the GHCB specification. The driver simply treats the blob as a opaque data and copies it to userspace.
--- Documentation/virt/coco/sevguest.rst | 23 +++++++ drivers/virt/coco/sevguest/sevguest.c | 93 +++++++++++++++++++++++++++ include/uapi/linux/sev-guest.h | 13 ++++ 3 files changed, 129 insertions(+)
Documentation/virt/coco/sevguest.rst +23 -0
@@ -86,6 +86,29 @@ on the various fields passed in the key derivation request. On success, the snp_derived_key_resp.data will contains the derived key value. See the SEV-SNP specification for further details. + +2.3 SNP_GET_EXT_REPORT +---------------------- +:Technology: sev-snp +:Type: guest ioctl +:Parameters (in/out): struct snp_ext_report_req +:Returns (out): struct snp_report_resp on success, -negative on error + +The SNP_GET_EXT_REPORT ioctl is similar to the SNP_GET_REPORT. The difference is +related to the additional certificate data that is returned with the report. +The certificate data returned is being provided by the hypervisor through the +SNP_SET_EXT_CONFIG. + +The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command provided by the SEV-SNP +firmware to get the attestation report. + +On success, the snp_ext_report_resp.data will contain the attestation report +and snp_ext_report_req.certs_address will contain the certificate blob. If the +length of the blob is smaller than expected then snp_ext_report_req.certs_len will +be updated with the expected value. + +See GHCB specification for further detail on how to parse the certificate blob. + Reference ---------
drivers/virt/coco/sevguest/sevguest.c +93 -0
135 lines not on this page · raw message
include/uapi/linux/sev-guest.h +13 -0
@@ -57,6 +57,16 @@ struct snp_derived_key_resp {__u8 data[64 ]; }; +struct snp_ext_report_req { +struct snp_report_req data; + +/* where to copy the certificate blob */ +__u64 certs_address; + +/* length of the certificate blob */ +__u32 certs_len; +}; +#define SNP_GUEST_REQ_IOC_TYPE 'S'/* Get SNP attestation report */
@@ -65,4 +75,7 @@ struct snp_derived_key_resp {/* Get a derived key from the root */ #define SNP_GET_DERIVED_KEY _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x1, struct snp_guest_request_ioctl) +/* Get SNP extended report as defined in the GHCB specification version 2. */ +#define SNP_GET_EXT_REPORT _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x2, struct snp_guest_request_ioctl) +#endif /* __UAPI_LINUX_SEV_GUEST_H_ */
Signature · 1 line
2.25.1
Quoted 41 lines · Brijesh Singh
This part of Secure Encrypted Paging (SEV-SNP) series focuses on the changes required in a guest OS for SEV-SNP support.
SEV-SNP builds upon existing SEV and SEV-ES functionality while adding new hardware-based memory protections. SEV-SNP adds strong memory integrity protection to help prevent malicious hypervisor-based attacks like data replay, memory re-mapping and more in order to create an isolated memory encryption environment.
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.
Many of the integrity guarantees of SEV-SNP are enforced through a new structure called the Reverse Map Table (RMP). Adding a new page to SEV-SNP VM requires a 2-step process. First, the hypervisor assigns a page to the guest using the new RMPUPDATE instruction. This transitions the page to guest-invalid. Second, the guest validates the page using the new PVALIDATE instruction. The SEV-SNP VMs can use the new "Page State Change Request NAE" defined in the GHCB specification to ask hypervisor to add or remove page from the RMP table.
Each page assigned to the SEV-SNP VM can either be validated or unvalidated, as indicated by the Validated flag in the page's RMP entry. There are two approaches that can be taken for the page validation: Pre-validation and Lazy Validation.
Under pre-validation, the pages are validated prior to first use. And under lazy validation, pages are validated when first accessed. An access to a unvalidated page results in a #VC exception, at which time the exception handler may validate the page. Lazy validation requires careful tracking of the validated pages to avoid validating the same GPA more than once. The recently introduced "Unaccepted" memory type can be used to communicate the unvalidated memory ranges to the Guest OS.
At this time we only sypport the pre-validation, the OVMF guest BIOS validates the entire RAM before the control is handed over to the guest kernel. The early_set_memory_{encrypt,decrypt} and set_memory_{encrypt,decrypt} are enlightened to perform the page validation or invalidation while setting or clearing the encryption attribute from the page table.
Quoted 5 lines
This series does not provide support for the Interrupt security yet which will be added after the base support.
The series is based on tip/master
ea79c24a30aa(origin/master, origin/HEAD, master) Merge branch 'timers/urgent'
I am looking at
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git,
and I cannot find the commit ea79c24a30aa there. Am I looking at the wrong tree?
Venu
Quoted 199 lines
Additional resources
---------------------
SEV-SNP whitepaper
https://www.amd.com/system/files/TechDocs/SEV-SNP-strengthening-vm-isolation-with-integrity-protection-and-more.pdfAPM 2: https://www.amd.com/system/files/TechDocs/24593.pdf
(section 15.36)GHCB spec:
https://developer.amd.com/wp-content/resources/56421.pdfSEV-SNP firmware specification:
https://developer.amd.com/sev/v6: https://lore.kernel.org/linux-mm/[email protected]/
v5: https://lore.kernel.org/lkml/[email protected]/Changes since v6:
* Addrmpadjust()helper to be used by AP creation and vmpl0 detect function.
* Clear the VM communication key if guest detects that hypervisor is modifying theSNP_GUEST_REQresponse header.
* Move the per-cpu GHCB registration from first #VC to idt setup.
* Consolidate initial SEV/SME setup into a common entry point that gets called early enough to also be used for SEV-SNP CPUID table setup.
* SNP CPUID: separate initial SEV-SNP feature detection out into standalonesnp_init()routines, then add CPUID table setup to it as a separate patch.
* SNP CPUID: fix boot issue with Seabios due to ACPI relying on certain EFI config table lookup failures as fallthrough cases rather than error cases.
* SNP CPUID: drop the use of a separate init routines to handle pointer fixups after switching to kernel virtual addresses, instead use a helper that uses RIP-relative addressing to access CPUID table when either on identity mapping or kernel virtual addresses.Changes since v5:
* move the seqno allocation in the sevguest driver.
* extendsnp_issue_guest_request()to accept theexit_infoto simplify the logic.
* use smaller structure names based on feedback.
* explicitly clear the memory after the SNP guest request is completed.
* cpuid validation: use a local copy of cpuid table instead of keeping firmware table mapped throughout boot.
* cpuid validation: coding style fix-ups and refactor cpuid-related helpers as suggested.
* cpuid validation: drop a number of BOOT_COMPRESSED-guarded defs/declarations by moving things like snp_cpuid_init*() out ofsev-shared.cand keeping only the common bits there.
* Break up EFI config table helpers and relatedacpi.cchanges into separate patches.
* re-enable stack protection for 32-bit kernels as well, not just 64-bitChanges since v4:
* Address the cpuid specific review comment
* Simplified the macro based on the review feedback
* Move macro definition to the patch that needs it
* Fix the issues reported by the checkpath
* Address the AP creation specific review commentChanges since v3:
* Add support to use the PSP filtered CPUID.
* Add support for the extended guest request.
* Move sevguest driver in driver/virt/coco.
* Add documentation for sevguest ioctl.
* Add support to check the vmpl0.
* Pass the VM encryption key and id to be used for encrypting guest messages through the platform drv data.
* Multiple cleanup and fixes to address the review feedbacks.Changes since v2:
* Add support for AP startup using SNP specific vmgexit.
* Addsnp_prep_memory()helper.
* Dropsev_snp_active()helper.
* Addsev_feature_enabled()helper to check which SEV feature is active.
* Sync the SNP guest message request header with latest SNP FW spec.
* Multiple cleanup and fixes to address the review feedbacks.Changes since v1:
* Integerate the SNP support in sev.{ch}.
* Add support to query the hypervisor feature and detect whether SNP is supported.
* Define Linux specific reason code for the SNP guest termination.
* Extend thesetup_headerprovide a way for hypervisor to pass secret and cpuid page.
* Add support to create a platform device and driver to query the attestation report and the derive a key.
* Multiple cleanup and fixes to address Boris's review fedback.Borislav Petkov (3):
x86/sev: Get rid of excessive use of defines x86/head64: Carve out the guest encryption postprocessing into a
helper
x86/sev: Removedo_early_exception()forward declarationsBrijesh Singh (22):
x86/mm: Extendcc_attrto include AMD SEV-SNP
x86/sev: Shorten GHCB terminate macro names
x86/sev: Define the Linux specific guest termination reasons x86/sev: Save the negotiated GHCB version
x86/sev: Add support for hypervisor feature VMGEXIT x86/sev: Check SEV-SNP features support
x86/sev: Add a helper for the PVALIDATE instruction x86/sev: Check the vmpl level
x86/compressed: Add helper for validating pages in the decompression
stage
x86/compressed: Register GHCB memory when SEV-SNP is active x86/sev: Register GHCB memory when SEV-SNP is active x86/sev: Add helper for validating pages in early enc attribute
changes
x86/kernel: Make the bss.decrypted section shared in RMP table x86/kernel: Validate rom memory before accessing when SEV-SNP is
active
x86/mm: Add support to validate memory when changing C-bit
KVM: SVM: Definesev_featuresand vmpl field in the VMSA x86/boot: Add Confidential Computing type tosetup_datax86/sev: Provide support for SNP guest request NAEs x86/sev: Register SNP guest request platform device
virt: Add SEV-SNP guest driver
virt: sevguest: Add support to derive key
virt: sevguest: Add support to get extended reportMichael Roth (16):
x86/compressed/64: detect/setup SEV/SME features earlier in boot x86/sev: detect/setup SEV/SME features earlier in boot x86/head: re-enable stack protection for 32/64-bit builds x86/sev: move MSR-based VMGEXITs for CPUID to helper
KVM: x86: move lookup of indexed CPUID leafs to helper x86/compressed/acpi: move EFI system table lookup to helper x86/compressed/acpi: move EFI config table lookup to helper x86/compressed/acpi: move EFI vendor table lookup to helper
KVM: SEV: Add documentation for SEV-SNP CPUID Enforcement x86/compressed/64: add support for SEV-SNP CPUID table in #VC handlers x86/boot: add a pointer to Confidential Computing blob in bootparams x86/compressed: add SEV-SNP feature detection/setup x86/compressed: use firmware-validated CPUID for SEV-SNP guests x86/compressed/64: add identity mapping for Confidential Computing
blob
x86/sev: add SEV-SNP feature detection/setup
x86/sev: use firmware-validated CPUID for SEV-SNP guestsTom Lendacky (4):
KVM: SVM: Create a separate mapping for the SEV-ES save area
KVM: SVM: Create a separate mapping for the GHCB save area
KVM: SVM: Update the SEV-ES save area mapping x86/sev: Use SEV-SNP AP creation to start secondary CPUsDocumentation/virt/coco/sevguest.rst | 117 +++ .../virt/kvm/amd-memory-encryption.rst | 28 + arch/x86/boot/compressed/Makefile | 1 + arch/x86/boot/compressed/acpi.c | 129 +-- arch/x86/boot/compressed/efi.c | 178 ++++ arch/x86/boot/compressed/head_64.S | 8 +- arch/x86/boot/compressed/ident_map_64.c | 44 +- arch/x86/boot/compressed/mem_encrypt.S | 36 - arch/x86/boot/compressed/misc.h | 44 +- arch/x86/boot/compressed/sev.c | 243 ++++- arch/x86/include/asm/bootparam_utils.h | 1 + arch/x86/include/asm/cpuid.h | 26 + arch/x86/include/asm/msr-index.h | 2 + arch/x86/include/asm/setup.h | 2 +- arch/x86/include/asm/sev-common.h | 137 ++- arch/x86/include/asm/sev.h | 96 +- arch/x86/include/asm/svm.h | 171 +++- arch/x86/include/uapi/asm/bootparam.h | 4 +- arch/x86/include/uapi/asm/svm.h | 13 + arch/x86/kernel/Makefile | 1 - arch/x86/kernel/cc_platform.c | 2 + arch/x86/kernel/cpu/common.c | 5 + arch/x86/kernel/head64.c | 78 +- arch/x86/kernel/head_64.S | 24 + arch/x86/kernel/probe_roms.c | 13 +- arch/x86/kernel/sev-shared.c | 554 +++++++++++- arch/x86/kernel/sev.c | 838 ++++++++++++++++-- arch/x86/kernel/smpboot.c | 3 + arch/x86/kvm/cpuid.c | 17 +- arch/x86/kvm/svm/sev.c | 24 +- arch/x86/kvm/svm/svm.c | 4 +- arch/x86/kvm/svm/svm.h | 2 +- arch/x86/mm/mem_encrypt.c | 55 +- arch/x86/mm/mem_encrypt_identity.c | 8 + arch/x86/mm/pat/set_memory.c | 15 + drivers/virt/Kconfig | 3 + drivers/virt/Makefile | 1 + drivers/virt/coco/sevguest/Kconfig | 9 + drivers/virt/coco/sevguest/Makefile | 2 + drivers/virt/coco/sevguest/sevguest.c | 743 ++++++++++++++++ drivers/virt/coco/sevguest/sevguest.h | 98 ++ include/linux/cc_platform.h | 8 + include/linux/efi.h | 1 + include/uapi/linux/sev-guest.h | 81 ++ 44 files changed, 3524 insertions(+), 345 deletions(-) create mode 100644 Documentation/virt/coco/sevguest.rst create mode 100644 arch/x86/boot/compressed/efi.c create mode 100644 arch/x86/include/asm/cpuid.h create mode 100644 drivers/virt/coco/sevguest/Kconfig create mode 100644 drivers/virt/coco/sevguest/Makefile create mode 100644 drivers/virt/coco/sevguest/sevguest.c create mode 100644 drivers/virt/coco/sevguest/sevguest.h create mode 100644 include/uapi/linux/sev-guest.hSignature · 1 line
2.25.1
On 11/15/21 9:56 AM, Venu Busireddy wrote:
...
Quoted 8 lines
Quoted 2 lines
The series is based on tip/master
ea79c24a30aa(origin/master, origin/HEAD, master) Merge branch 'timers/urgent'I am looking at
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7Cb83627413bf24921b15e08d9a8508a4a%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637725887206373140%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=pZvyYsg1crWmsLTpGO4amfYxgUnI9TUy414burkbcdY%3D&reserved=0,
and I cannot find the commitea79c24a30aathere. Am I looking at the wrong tree?
Yes.
You should use the tip [1] tree .
[1] https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/
thanks
Quoted 14 lines · Brijesh Singh
On 11/15/21 9:56 AM, Venu Busireddy wrote:
...Quoted 8 lines
Quoted 2 lines
The series is based on tip/master
ea79c24a30aa(origin/master, origin/HEAD, master) Merge branch 'timers/urgent'I am looking at
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7Cb83627413bf24921b15e08d9a8508a4a%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637725887206373140%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=pZvyYsg1crWmsLTpGO4amfYxgUnI9TUy414burkbcdY%3D&reserved=0,
and I cannot find the commitea79c24a30aathere. Am I looking at the wrong tree?
Quoted 5 lines
Yes.
You should use the tip [1] tree .
[1] https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/
Same problem with tip.git too.
bash-4.2$ git remote -v
origin https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git (fetch) origin https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git (push) bash-4.2$ git branch
* master
bash-4.2$ git log --oneline | grep ea79c24a30aa
bash-4.2$
Still missing something?
Venu
Quoted 31 lines · Venu Busireddy
Quoted 14 lines · Brijesh Singh
On 11/15/21 9:56 AM, Venu Busireddy wrote:
...Quoted 8 lines
Quoted 2 lines
The series is based on tip/master
ea79c24a30aa(origin/master, origin/HEAD, master) Merge branch 'timers/urgent'I am looking at
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7C566cca1a4ceb44dac52f08d9a85639fd%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637725911063489322%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=CT%2BZ6Nm6pnvVGY%2B%2FmzK4gG1zxlMNQ1fn7ie6K%2FYueTQ%3D&reserved=0,
and I cannot find the commitea79c24a30aathere. Am I looking at the wrong tree?Quoted 5 lines
Yes.
You should use the tip [1] tree .
Same problem with tip.git too.
bash-4.2$ git remote -v
origin https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftip%2Ftip.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7C566cca1a4ceb44dac52f08d9a85639fd%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637725911063499319%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=W%2BA8qZwPicXo7OSslFPqL8s8QRxzW9n68TX1B7MXFYQ%3D&reserved=0 (fetch) origin https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftip%2Ftip.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7C566cca1a4ceb44dac52f08d9a85639fd%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637725911063499319%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=W%2BA8qZwPicXo7OSslFPqL8s8QRxzW9n68TX1B7MXFYQ%3D&reserved=0 (push) bash-4.2$ git branch
* master
bash-4.2$ git log --oneline | grepea79c24a30aa
bash-4.2$
Quoted 2 lines
Still missing something?
I can see the base commit on my local clone and also on web interface
thanks
Quoted 34 lines · Brijesh Singh
Quoted 31 lines · Venu Busireddy
Quoted 14 lines · Brijesh Singh
On 11/15/21 9:56 AM, Venu Busireddy wrote:
...Quoted 8 lines
Quoted 2 lines
The series is based on tip/master
ea79c24a30aa(origin/master, origin/HEAD, master) Merge branch 'timers/urgent'I am looking at
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7C566cca1a4ceb44dac52f08d9a85639fd%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637725911063489322%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=CT%2BZ6Nm6pnvVGY%2B%2FmzK4gG1zxlMNQ1fn7ie6K%2FYueTQ%3D&reserved=0,
and I cannot find the commitea79c24a30aathere. Am I looking at the wrong tree?Quoted 5 lines
Yes.
You should use the tip [1] tree .
Same problem with tip.git too.
bash-4.2$ git remote -v
origin https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftip%2Ftip.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7C566cca1a4ceb44dac52f08d9a85639fd%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637725911063499319%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=W%2BA8qZwPicXo7OSslFPqL8s8QRxzW9n68TX1B7MXFYQ%3D&reserved=0 (fetch) origin https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftip%2Ftip.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7C566cca1a4ceb44dac52f08d9a85639fd%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637725911063499319%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=W%2BA8qZwPicXo7OSslFPqL8s8QRxzW9n68TX1B7MXFYQ%3D&reserved=0 (push) bash-4.2$ git branch
* master
bash-4.2$ git log --oneline | grepea79c24a30aa
bash-4.2$
Quoted 4 lines
Quoted 2 lines
Still missing something?
I can see the base commit on my local clone and also on web interface
But can you see the commit ea79c24a30aa if you clone git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git?
Quoted 1 line
The web interface has the weird warning "Notice: this object is not reachable from any branch." Don't know what to make of that.
Venu
Quoted 2 lines
thanks
Quoted 40 lines · Venu Busireddy
Quoted 34 lines · Brijesh Singh
Quoted 31 lines · Venu Busireddy
Quoted 14 lines · Brijesh Singh
On 11/15/21 9:56 AM, Venu Busireddy wrote:
...Quoted 8 lines
Quoted 2 lines
The series is based on tip/master
ea79c24a30aa(origin/master, origin/HEAD, master) Merge branch 'timers/urgent'I am looking at
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7C566cca1a4ceb44dac52f08d9a85639fd%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637725911063489322%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=CT%2BZ6Nm6pnvVGY%2B%2FmzK4gG1zxlMNQ1fn7ie6K%2FYueTQ%3D&reserved=0,
and I cannot find the commitea79c24a30aathere. Am I looking at the wrong tree?Quoted 5 lines
Yes.
You should use the tip [1] tree .
Same problem with tip.git too.
bash-4.2$ git remote -v
origin https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftip%2Ftip.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7C566cca1a4ceb44dac52f08d9a85639fd%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637725911063499319%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=W%2BA8qZwPicXo7OSslFPqL8s8QRxzW9n68TX1B7MXFYQ%3D&reserved=0 (fetch) origin https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftip%2Ftip.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7C566cca1a4ceb44dac52f08d9a85639fd%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637725911063499319%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=W%2BA8qZwPicXo7OSslFPqL8s8QRxzW9n68TX1B7MXFYQ%3D&reserved=0 (push) bash-4.2$ git branch
* master
bash-4.2$ git log --oneline | grepea79c24a30aa
bash-4.2$Quoted 4 lines
Quoted 2 lines
Still missing something?
I can see the base commit on my local clone and also on web interface
Quoted 7 lines
But can you see the commit
ea79c24a30aaif you clone git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git?Quoted 1 line
The web interface has the weird warning "Notice: this object is not reachable from any branch." Don't know what to make of that.
Just wanted to clarify. I am not interested in the commit ea79c24a30aa per se. I am trying to apply this patch series to a local copy of the tip. I tried applying to the top of the tree, and that failed. I tried to apply on top of commit ca7752caeaa7 (which appeared to be the closest commit to your description), and that also failed. I just need a commit on which I can successfully apply this series.
Thanks,
Venu
Quoted 5 lines
Venu
Quoted 2 lines
thanks
Quoted 49 lines · Venu Busireddy
Quoted 40 lines · Venu Busireddy
Quoted 34 lines · Brijesh Singh
Quoted 31 lines · Venu Busireddy
Quoted 14 lines · Brijesh Singh
On 11/15/21 9:56 AM, Venu Busireddy wrote:
...Quoted 8 lines
Quoted 2 lines
The series is based on tip/master
ea79c24a30aa(origin/master, origin/HEAD, master) Merge branch 'timers/urgent'I am looking at
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7C527b875208904981677108d9a9183dba%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637726744508270539%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=hfqoF4d95hWAY8%2BKW4t5UyrWIPAUuHOTvzTQGXyxQik%3D&reserved=0,
and I cannot find the commitea79c24a30aathere. Am I looking at the wrong tree?Quoted 5 lines
Yes.
You should use the tip [1] tree .
Same problem with tip.git too.
bash-4.2$ git remote -v
origin https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftip%2Ftip.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7C527b875208904981677108d9a9183dba%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637726744508270539%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=0qPjqphHSBSnpxOrPGDyJ7BF5O3fnTJtXQgnO0ZwCXY%3D&reserved=0 (fetch) origin https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftip%2Ftip.git&data=04%7C01%7Cbrijesh.singh%40amd.com%7C527b875208904981677108d9a9183dba%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637726744508270539%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=0qPjqphHSBSnpxOrPGDyJ7BF5O3fnTJtXQgnO0ZwCXY%3D&reserved=0 (push) bash-4.2$ git branch
* master
bash-4.2$ git log --oneline | grepea79c24a30aa
bash-4.2$Quoted 4 lines
Quoted 2 lines
Still missing something?
I can see the base commit on my local clone and also on web interface
Quoted 7 lines
But can you see the commit
ea79c24a30aaif you clone git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git?The web interface has the weird warning "Notice: this object is not reachable from any branch." Don't know what to make of that.
Quoted 7 lines
Just wanted to clarify. I am not interested in the commit
ea79c24a30aaper se. I am trying to apply this patch series to a local copy of the tip. I tried applying to the top of the tree, and that failed. I tried to apply on top of commitca7752caeaa7(which appeared to be the closest commit to your description), and that also failed. I just need a commit on which I can successfully apply this series.
At the time I pulled the tip, the said commit was valid and my entire series was generated against it. Its possible that commit is no longer valid in the recent tip (maybe due to force push). You can grab a staging tree from here https://github.com/AMDESE/linux/tree/snp-part1-v7.
Quoted 9 lines
Thanks,
Venu
Quoted 5 lines
Venu
Quoted 2 lines
thanks