x86/efistub: Don't bother enabling SEV in the EFI stub
PATCH 1/1 x86/efistub: Don't bother enabling SEV in the EFI stub
From: Ard Biesheuvel <[email protected]>
One of the last things the EFI stub does before handing over to the core kernel when booting as a SEV guest is enabling SEV, even though this is mostly redundant: one of the first things the core kernel does is calling sme_enable(), after setting up the early GDT and IDT but before even setting up the kernel page tables.
So let's just drop this call to sev_enable(), and rely on the core kernel to initiaize SEV correctly.
--- arch/x86/include/asm/sev.h | 2 -- drivers/firmware/efi/libstub/x86-stub.c | 6 ------ 2 files changed, 8 deletions(-)
I'm still waiting for my SEV-capable hardware to turn up so this was build tested only.
arch/x86/include/asm/sev.h +0 -2
@@ -442,7 +442,6 @@ static __always_inline void sev_es_nmi_complete(void)__sev_es_nmi_complete (); }extern int __init sev_es_efi_map_ghcbs (pgd_t *pgd); -extern void sev_enable (struct boot_params *bp);/* * RMPADJUST modifies the RMP permissions of a page of a lesser-
@@ -533,7 +532,6 @@ 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 void sev_enable (struct boot_params *bp) { }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 setup_ghcb (void ) { }
drivers/firmware/efi/libstub/x86-stub.c +0 -6
@@ -925,12 +925,6 @@ void __noreturn efi_stub_entry(efi_handle_t handle, goto fail; } -/* -* Call the SEV init code while still running with the firmware's -* GDT/IDT, so #VC exceptions will be handled by EFI. -*/ -sev_enable (boot_params); -efi_5level_switch ();enter_kernel (kernel_entry, boot_params);
Signature · 1 line
2.49.0.604.gff1f9ca942-goog
Quoted 10 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
One of the last things the EFI stub does before handing over to the core kernel when booting as a SEV guest is enabling SEV, even though this is mostly redundant: one of the first things the core kernel does is calling
sme_enable(), after setting up the early GDT and IDT but before even setting up the kernel page tables.So let's just drop this call to
sev_enable(), and rely on the core kernel to initiaize SEV correctly.
SEV support does some things in sev_enable() that aren't done later in the kernel proper. For example, we check certain hypervisor features and save the CC blob into the boot parameters. And as I look closer, I see that we don't call initialize_identity_maps() from the EFI stub so we aren't calling snp_check_features() from the EFI stub, which we should have been doing.
Just removing the call does cause an SNP boot to crash. My testing shows just ensuring that the cc_blob_address in the boot_params structure is set results in a successful boot under SNP. So some of sev_enable() needs to remain and some things need to be moved into the kernel proper.
Thanks,
Tom
Quoted 51 lines
Cc Tom Lendacky <[email protected]>Cc Borislav Petkov <[email protected]>Cc Dionna Amalie Glaze <[email protected]>Cc Kevin Loughlin <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>--- arch/x86/include/asm/sev.h | 2 -- drivers/firmware/efi/libstub/x86-stub.c | 6 ------ 2 files changed, 8 deletions(-)I'm still waiting for my SEV-capable hardware to turn up so this was build tested only.
arch/x86/include/asm/sev.h +0
-2@@ -442,7 +442,6 @@ static __always_inline void sev_es_nmi_complete(void)__sev_es_nmi_complete (); }extern int __init sev_es_efi_map_ghcbs (pgd_t *pgd); -extern void sev_enable (struct boot_params *bp);/* * RMPADJUST modifies the RMP permissions of a page of a lesser- @@ -533,7 +532,6 @@ 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 void sev_enable (struct boot_params *bp) { }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 setup_ghcb (void ) { }drivers/firmware/efi/libstub/x86-stub.c +0
-6@@ -925,12 +925,6 @@ void __noreturn efi_stub_entry(efi_handle_t handle, goto fail; } -/* -* Call the SEV init code while still running with the firmware's -* GDT/IDT, so #VC exceptions will be handled by EFI. -*/ -sev_enable (boot_params); -efi_5level_switch ();enter_kernel (kernel_entry, boot_params);
Ard Biesheuvel
maintainerHi Tom,
Thanks for taking a look.
Quoted 10 lines · Tom Lendacky
Quoted 8 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
One of the last things the EFI stub does before handing over to the core kernel when booting as a SEV guest is enabling SEV, even though this is mostly redundant: one of the first things the core kernel does is calling
sme_enable(), after setting up the early GDT and IDT but before even setting up the kernel page tables.
Quoted 6 lines
Quoted 2 lines
So let's just drop this call to
sev_enable(), and rely on the core kernel to initiaize SEV correctly.SEV support does some things in
sev_enable()that aren't done later in the kernel proper. For example, we check certain hypervisor features and save the CC blob into the boot parameters.
I misread the last part: the kernel proper checks struct boot_params and setup_data, whereas the decompressor checks both of those as well as the EFI config table.
It would make sense for the EFI stub to populate the field in struct boot_params directly.
Quoted 5 lines
And as I look closer, I see
that we don't callinitialize_identity_maps()from the EFI stub so we aren't callingsnp_check_features()from the EFI stub, which we should have been doing.
The EFI stub has its own check for this, based on the same underlying logic (have_unsupported_snp_features()). But it checks this much earlier so it can fail gracefully and return to the firmware, rather than terminate.
Quoted 5 lines
Just removing the call does cause an SNP boot to crash. My testing shows just ensuring that the
cc_blob_addressin theboot_paramsstructure is set results in a successful boot under SNP. So some ofsev_enable()needs to remain and some things need to be moved into the kernel proper.
Thanks, this is very helpful. I'll dig a bit deeper and try to address the points you raised.
Quoted 36 lines · Ard Biesheuvel
Hi Tom,
Thanks for taking a look.
Quoted 10 lines · Tom Lendacky
Quoted 8 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
One of the last things the EFI stub does before handing over to the core kernel when booting as a SEV guest is enabling SEV, even though this is mostly redundant: one of the first things the core kernel does is calling
sme_enable(), after setting up the early GDT and IDT but before even setting up the kernel page tables.Quoted 6 lines
Quoted 2 lines
So let's just drop this call to
sev_enable(), and rely on the core kernel to initiaize SEV correctly.SEV support does some things in
sev_enable()that aren't done later in the kernel proper. For example, we check certain hypervisor features and save the CC blob into the boot parameters.I misread the last part: the kernel proper checks struct
boot_paramsandsetup_data, whereas the decompressor checks both of those as well as the EFI config table.It would make sense for the EFI stub to populate the field in struct
boot_paramsdirectly.Quoted 5 lines
And as I look closer, I see
that we don't callinitialize_identity_maps()from the EFI stub so we aren't callingsnp_check_features()from the EFI stub, which we should have been doing.
Quoted 4 lines
The EFI stub has its own check for this, based on the same underlying logic (
have_unsupported_snp_features()). But it checks this much earlier so it can fail gracefully and return to the firmware, rather than terminate.
Ah, whew! I forgot we have a slightly different call for that in the EFI stub, thanks for reminding me.
Thanks,
Tom
Quoted 9 lines
Quoted 6 lines
Just removing the call does cause an SNP boot to crash. My testing shows just ensuring that the
cc_blob_addressin theboot_paramsstructure is set results in a successful boot under SNP. So some ofsev_enable()needs to remain and some things need to be moved into the kernel proper.Thanks, this is very helpful. I'll dig a bit deeper and try to address the points you raised.