[PATCH v4 0/3] efi: Don't initalize SEV-SNP from the EFI stub

Ard Biesheuvel posted 3 patches 3 weeks, 2 days ago
arch/x86/boot/compressed/misc.h         | 11 --------
arch/x86/include/asm/sev.h              |  2 --
drivers/firmware/efi/libstub/x86-stub.c | 27 ++++++++++++--------
3 files changed, 16 insertions(+), 24 deletions(-)
[PATCH v4 0/3] efi: Don't initalize SEV-SNP from the EFI stub
Posted by Ard Biesheuvel 3 weeks, 2 days ago
From: Ard Biesheuvel <ardb@kernel.org>

The EFI stub no longer invokes the legacy decompressor, and so there is
no longer any reason to perform all SEV-SNP initialization twice: it is
sufficient to rely on the SEV-SNP work done by the core kernel.

Changes since v3: [2]
- Drop patches that have been merged in the meantime
- Rebase onto tip/x86/sev

Note that the issue pointed out by Tom in reply to the v3 cover letter
has been fixed in the meantime as well [3]

Changes since v2: [1]
- rebase onto tip/x86/boot
- add patch to remove unused static inline fallback implementation of
  sev_enable()

Changes since v1: [0]
- address shortcomings pointed out by Tom, related to missing checks and
  to discovery of the CC blob table from the EFI stub

[0] https://lore.kernel.org/all/20250414130417.1486395-2-ardb+git@google.com/T/#u
[1] https://lore.kernel.org/all/20250416165743.4080995-6-ardb+git@google.com/T/#u
[2] https://lore.kernel.org/all/20250422100728.208479-7-ardb+git@google.com/T/#u
[3] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=8ed12ab1319b2d8e4a529504777aacacf71371e4

Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Borislav Petkov <bp@alien8.de>

Ard Biesheuvel (3):
  x86/boot: Drop unused sev_enable() fallback
  x86/efistub: Obtain SEV CC blob address from the stub
  x86/efistub: Don't bother enabling SEV in the EFI stub

 arch/x86/boot/compressed/misc.h         | 11 --------
 arch/x86/include/asm/sev.h              |  2 --
 drivers/firmware/efi/libstub/x86-stub.c | 27 ++++++++++++--------
 3 files changed, 16 insertions(+), 24 deletions(-)


base-commit: 0ca77f8d33e8136b8926775380506f78a8d04811
-- 
2.51.0.384.g4c02a37b29-goog
Re: [PATCH v4 3/3] x86/efistub: Don't bother enabling SEV in the EFI stub
Posted by Ashish Kalra 2 weeks, 6 days ago
From: Ard Biesheuvel <ardb@kernel.org>

>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. sme_enable() performs the same
>SEV-SNP initialization that the decompressor performs in sev_enable().

>So let's just drop this call to sev_enable(), and rely on the core
>kernel to initiaize SEV correctly.

If the EFI stub no longer boots the core kernel via the traditional 
decompressor and jumps straight to it, there are some specific things 
which i see are being setup by the decompressed kernel before passing
control to the uncompressed kernel such as calling sev_prep_identity_maps()
as part of setting up the identity map: 

From sev_prep_identity_maps(): 

The Confidential Computing 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.

Won't this setup in identity mapping be needed to find the 
in-memory CPUID table as this won't exist if the EFI stub boots
directly boots the core kernel skipping the decompressor ?

Thanks,
Ashish
Re: [PATCH v4 3/3] x86/efistub: Don't bother enabling SEV in the EFI stub
Posted by Ard Biesheuvel 2 weeks, 6 days ago
On Fri, 12 Sept 2025 at 22:36, Ashish Kalra <Ashish.Kalra@amd.com> wrote:
>
> From: Ard Biesheuvel <ardb@kernel.org>
>
> >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. sme_enable() performs the same
> >SEV-SNP initialization that the decompressor performs in sev_enable().
>
> >So let's just drop this call to sev_enable(), and rely on the core
> >kernel to initiaize SEV correctly.
>
> If the EFI stub no longer boots the core kernel via the traditional
> decompressor and jumps straight to it, there are some specific things
> which i see are being setup by the decompressed kernel before passing
> control to the uncompressed kernel such as calling sev_prep_identity_maps()
> as part of setting up the identity map:
>
> From sev_prep_identity_maps():
>
> The Confidential Computing 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.
>
> Won't this setup in identity mapping be needed to find the
> in-memory CPUID table as this won't exist if the EFI stub boots
> directly boots the core kernel skipping the decompressor ?
>

EFI maps all memory 1:1 so none of this is needed.