* [PATCH v2 0/3] x86/efistub: Omit SEV-SNP init from the stub
@ 2026-12-04 15:48 Ard Biesheuvel
2026-12-04 15:48 ` [PATCH v2 1/3] x86/efistub: Obtain SEV CC blob address " Ard Biesheuvel
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2026-12-04 15:48 UTC (permalink / raw)
To: linux-efi; +Cc: Ard Biesheuvel, Borislav Petkov, Tom Lendacky, Ashish Kalra
From: Ard Biesheuvel <ardb@kernel.org>
Calling sev_enable() from the EFI stub is mostly pointless, as the core
kernel does the exact same thing once it boots right after.
So set the blob CC address in boot_params from the EFI stub as well, and
move the GHCB event support check for SVSM into the source file that the
decompressor shares with the core kernel.
With those changes, the sev_enable() call from the EFI stub can be
dropped, leaving the firmware's #VC handling in place until the kernel
proper takes over.
Changes since v1 [0]:
- Add SVSM GHCB handling
- Rebase onto recent kernel
[0] https://lore.kernel.org/linux-efi/20250909080631.2867579-5-ardb+git@google.com/
Cc: Borislav Petkov <bp@alien8.de>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Ashish Kalra <Ashish.Kalra@amd.com>
Ard Biesheuvel (3):
x86/efistub: Obtain SEV CC blob address from the stub
x86/sev: Check for SVSM GHCB event support in svsm_setup_ca()
x86/efistub: Don't bother enabling SEV in the EFI stub
arch/x86/boot/compressed/sev.c | 7 ----
arch/x86/boot/startup/exports.h | 1 +
arch/x86/boot/startup/sev-shared.c | 32 ++++++++++++++++++
arch/x86/coco/sev/vc-shared.c | 21 ------------
arch/x86/include/asm/sev.h | 2 --
drivers/firmware/efi/libstub/x86-stub.c | 34 +++++++++++++-------
6 files changed, 56 insertions(+), 41 deletions(-)
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/3] x86/efistub: Obtain SEV CC blob address from the stub
2026-12-04 15:48 [PATCH v2 0/3] x86/efistub: Omit SEV-SNP init from the stub Ard Biesheuvel
@ 2026-12-04 15:48 ` Ard Biesheuvel
2026-12-04 15:48 ` [PATCH v2 2/3] x86/sev: Check for SVSM GHCB event support in svsm_setup_ca() Ard Biesheuvel
2026-12-04 15:48 ` [PATCH v2 3/3] x86/efistub: Don't bother enabling SEV in the EFI stub Ard Biesheuvel
2 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2026-12-04 15:48 UTC (permalink / raw)
To: linux-efi; +Cc: Ard Biesheuvel, Borislav Petkov, Tom Lendacky, Ashish Kalra
From: Ard Biesheuvel <ardb@kernel.org>
The x86 EFI stub no longer boots the core kernel via the traditional
decompressor but jumps straight to it, avoiding all the page fault
handling and other complexity that is entirely unnecessary when booting
via EFI, which guarantees that all system memory is mapped 1:1.
The SEV startup code in the core kernel expects the address of the CC
blob configuration table in boot_params, so store it there when booting
from EFI with SEV-SNP enabled. This removes the need to call
sev_enable() from the EFI stub.
Clear the field unconditionally first, so that uninitialized values
passed by buggy boot loaders are not propagated, as the decompressor
does in sev_enable(). (See commit 4b1c74240757 ("x86/boot: Don't
propagate uninitialized boot_params->cc_blob_address"))
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/x86-stub.c | 28 ++++++++++++++++----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index 253dd3ba8fab..1cceab57a738 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -786,17 +786,35 @@ static efi_status_t exit_boot(struct boot_params *boot_params, void *handle)
return EFI_SUCCESS;
}
-static bool have_unsupported_snp_features(void)
+static bool check_snp_features(struct boot_params *bp)
{
+ u64 status = sev_get_status();
u64 unsupported;
- unsupported = snp_get_unsupported_features(sev_get_status());
+ /*
+ * bp->cc_blob_address should only be set by the EFI stub or the
+ * decompressor. Initialize it to 0 to ensure that uninitialized values
+ * from buggy bootloaders aren't propagated.
+ */
+ bp->cc_blob_address = 0;
+
+ unsupported = snp_get_unsupported_features(status);
if (unsupported) {
efi_err("Unsupported SEV-SNP features detected: 0x%llx\n",
unsupported);
- return true;
+ return false;
}
- return false;
+
+ if (status & MSR_AMD64_SEV_SNP_ENABLED) {
+ void *tbl = get_efi_config_table(EFI_CC_BLOB_GUID);
+
+ if (!tbl) {
+ efi_err("SEV-SNP is enabled but CC blob not found\n");
+ return false;
+ }
+ bp->cc_blob_address = (u32)(unsigned long)tbl;
+ }
+ return true;
}
static void efi_get_seed(void *seed, int size)
@@ -937,7 +955,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
hdr = &boot_params->hdr;
- if (have_unsupported_snp_features())
+ if (!check_snp_features(boot_params))
efi_exit(handle, EFI_UNSUPPORTED);
if (IS_ENABLED(CONFIG_EFI_DXE_MEM_ATTRIBUTES)) {
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] x86/sev: Check for SVSM GHCB event support in svsm_setup_ca()
2026-12-04 15:48 [PATCH v2 0/3] x86/efistub: Omit SEV-SNP init from the stub Ard Biesheuvel
2026-12-04 15:48 ` [PATCH v2 1/3] x86/efistub: Obtain SEV CC blob address " Ard Biesheuvel
@ 2026-12-04 15:48 ` Ard Biesheuvel
2026-12-04 16:41 ` sashiko-bot
2026-12-04 15:48 ` [PATCH v2 3/3] x86/efistub: Don't bother enabling SEV in the EFI stub Ard Biesheuvel
2 siblings, 1 reply; 6+ messages in thread
From: Ard Biesheuvel @ 2026-12-04 15:48 UTC (permalink / raw)
To: linux-efi; +Cc: Ard Biesheuvel, Borislav Petkov, Tom Lendacky, Ashish Kalra
From: Ard Biesheuvel <ardb@kernel.org>
Running an SEV-SNP guest at a VMPL other than 0 requires the hypervisor
to support the GHCB events that are used to communicate with the SVSM.
Currently, this is only checked in the decompressor's sev_enable(),
which the EFI stub calls as well before handing over to the core
kernel, but the core kernel's SEV-SNP startup code does not perform
this check itself.
This is the only check performed by sev_enable() that is not duplicated
by the core kernel, and so moving it into code that is shared with the
core kernel is needed so that SEV-SNP enablement can be omitted entirely
from the EFI stub boot path, without losing this check.
So move the check into svsm_setup_ca(), which is shared between the
decompressor and the core kernel's startup code, and is where it is
first established that the guest is not running at VMPL0. Given that
the hypervisor features are only available from GHCB protocol version 2
onward, and that svsm_setup_ca() is called before the GHCB protocol
version is negotiated, move sev_es_negotiate_protocol() into the shared
startup code as well, and call it before querying the hypervisor
features.
Suggested-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/boot/compressed/sev.c | 7 -----
arch/x86/boot/startup/exports.h | 1 +
arch/x86/boot/startup/sev-shared.c | 32 ++++++++++++++++++++
arch/x86/coco/sev/vc-shared.c | 21 -------------
4 files changed, 33 insertions(+), 28 deletions(-)
diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c
index c6512f2ea31e..496cb65c46ba 100644
--- a/arch/x86/boot/compressed/sev.c
+++ b/arch/x86/boot/compressed/sev.c
@@ -420,13 +420,6 @@ void sev_enable(struct boot_params *bp)
hv_features = get_hv_features();
if (!(hv_features & GHCB_HV_FT_SNP))
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED);
-
- /*
- * Running at VMPL0 is required unless an SVSM is present and
- * the hypervisor supports the required SVSM GHCB events.
- */
- if (snp_vmpl && !(hv_features & GHCB_HV_FT_SNP_MULTI_VMPL))
- sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0);
}
if (snp && !(sev_status & MSR_AMD64_SEV_SNP_ENABLED))
diff --git a/arch/x86/boot/startup/exports.h b/arch/x86/boot/startup/exports.h
index 01d2363dc445..daab87c9e2db 100644
--- a/arch/x86/boot/startup/exports.h
+++ b/arch/x86/boot/startup/exports.h
@@ -7,6 +7,7 @@ PROVIDE(early_set_pages_state = __pi_early_set_pages_state);
PROVIDE(early_snp_set_memory_private = __pi_early_snp_set_memory_private);
PROVIDE(early_snp_set_memory_shared = __pi_early_snp_set_memory_shared);
PROVIDE(get_hv_features = __pi_get_hv_features);
+PROVIDE(sev_es_negotiate_protocol = __pi_sev_es_negotiate_protocol);
PROVIDE(sev_es_terminate = __pi_sev_es_terminate);
PROVIDE(snp_cpuid = __pi_snp_cpuid);
PROVIDE(snp_cpuid_get_table = __pi_snp_cpuid_get_table);
diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev-shared.c
index d9ac3a929d33..c6648501433e 100644
--- a/arch/x86/boot/startup/sev-shared.c
+++ b/arch/x86/boot/startup/sev-shared.c
@@ -49,6 +49,27 @@ sev_es_terminate(unsigned int set, unsigned int reason)
asm volatile("hlt\n" : : : "memory");
}
+bool sev_es_negotiate_protocol(void)
+{
+ u64 val;
+
+ /* Do the GHCB protocol version negotiation */
+ sev_es_wr_ghcb_msr(GHCB_MSR_SEV_INFO_REQ);
+ VMGEXIT();
+ val = sev_es_rd_ghcb_msr();
+
+ if (GHCB_MSR_INFO(val) != GHCB_MSR_SEV_INFO_RESP)
+ return false;
+
+ 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;
+}
+
/*
* The hypervisor features are available from GHCB version 2 onward.
*/
@@ -722,6 +743,17 @@ static bool __init svsm_setup_ca(const struct cc_blob_sev_info *cc_info,
if (!rmpadjust((unsigned long)page, RMP_PG_SIZE_4K, 1))
return false;
+ /*
+ * Running at VMPL0 is required unless an SVSM is present and the
+ * hypervisor supports the required SVSM GHCB events. The hypervisor
+ * features are only available from GHCB version 2 onward, and this
+ * code may run before the GHCB protocol version has been negotiated,
+ * so take care of that first.
+ */
+ if (!sev_es_negotiate_protocol() ||
+ !(get_hv_features() & GHCB_HV_FT_SNP_MULTI_VMPL))
+ sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0);
+
/*
* Not running at VMPL0, ensure everything has been properly supplied
* for running under an SVSM.
diff --git a/arch/x86/coco/sev/vc-shared.c b/arch/x86/coco/sev/vc-shared.c
index 58b2f985d546..3048347c158c 100644
--- a/arch/x86/coco/sev/vc-shared.c
+++ b/arch/x86/coco/sev/vc-shared.c
@@ -633,24 +633,3 @@ bool __init sev_es_check_cpu_features(void)
return true;
}
-
-bool sev_es_negotiate_protocol(void)
-{
- u64 val;
-
- /* Do the GHCB protocol version negotiation */
- sev_es_wr_ghcb_msr(GHCB_MSR_SEV_INFO_REQ);
- VMGEXIT();
- val = sev_es_rd_ghcb_msr();
-
- if (GHCB_MSR_INFO(val) != GHCB_MSR_SEV_INFO_RESP)
- return false;
-
- 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;
-}
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] x86/efistub: Don't bother enabling SEV in the EFI stub
2026-12-04 15:48 [PATCH v2 0/3] x86/efistub: Omit SEV-SNP init from the stub Ard Biesheuvel
2026-12-04 15:48 ` [PATCH v2 1/3] x86/efistub: Obtain SEV CC blob address " Ard Biesheuvel
2026-12-04 15:48 ` [PATCH v2 2/3] x86/sev: Check for SVSM GHCB event support in svsm_setup_ca() Ard Biesheuvel
@ 2026-12-04 15:48 ` Ard Biesheuvel
2026-12-04 17:11 ` sashiko-bot
2 siblings, 1 reply; 6+ messages in thread
From: Ard Biesheuvel @ 2026-12-04 15:48 UTC (permalink / raw)
To: linux-efi; +Cc: Ard Biesheuvel, Borislav Petkov, Tom Lendacky, Ashish Kalra
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().
The only check performed by sev_enable() that was not covered by the
core kernel, i.e., whether the hypervisor supports the SVSM GHCB events
when not running at VMPL0, has been moved into svsm_setup_ca() in the
previous patch.
Note that the identity mapping of the CC blob and the secrets page that
the decompressor creates in sev_prep_identity_maps() is not needed
either, given that EFI maps all of system memory 1:1.
So let's just drop this call to sev_enable(), and rely on the core
kernel to initialize SEV correctly.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/include/asm/sev.h | 2 --
drivers/firmware/efi/libstub/x86-stub.c | 6 ------
2 files changed, 8 deletions(-)
diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
index c7ea9845351e..3682e39ed295 100644
--- a/arch/x86/include/asm/sev.h
+++ b/arch/x86/include/asm/sev.h
@@ -462,7 +462,6 @@ static __always_inline void sev_es_nmi_complete(void)
__sev_es_nmi_complete();
}
extern int __init sev_es_efi_map_ghcbs_cas(pgd_t *pgd);
-extern void sev_enable(struct boot_params *bp);
/*
* RMPADJUST modifies the RMP permissions of a page of a lesser-
@@ -606,7 +605,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_cas(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) { }
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index 1cceab57a738..66b98c6c0e2a 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -1052,12 +1052,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);
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/3] x86/sev: Check for SVSM GHCB event support in svsm_setup_ca()
2026-12-04 15:48 ` [PATCH v2 2/3] x86/sev: Check for SVSM GHCB event support in svsm_setup_ca() Ard Biesheuvel
@ 2026-12-04 16:41 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-04 16:41 UTC (permalink / raw)
To: Ard Biesheuvel, linux-efi
Cc: Ard Biesheuvel, Borislav Petkov, Tom Lendacky, Ashish Kalra
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] x86/sev: wrong termination reason in svsm_setup_ca() on protocol
failure
--
commit 639cfa984764f41b3b4fc2ff75b221d418a19a04
Author: Ard Biesheuvel <ardb@kernel.org>
x86/sev: Check for SVSM GHCB event support in svsm_setup_ca()
This commit moves the GHCB_HV_FT_SNP_MULTI_VMPL hypervisor feature check
from the decompressor's sev_enable() into the shared svsm_setup_ca()
helper, and moves sev_es_negotiate_protocol() into the shared startup
code so it can be called beforehand.
> diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev-shared.c
> index d9ac3a929d335..c6648501433e7 100644
> --- a/arch/x86/boot/startup/sev-shared.c
> +++ b/arch/x86/boot/startup/sev-shared.c
[ ... ]
> @@ -722,6 +743,17 @@ static bool __init svsm_setup_ca(const struct cc_blob_sev_info *cc_info,
> if (!rmpadjust((unsigned long)page, RMP_PG_SIZE_4K, 1))
> return false;
>
> + /*
> + * Running at VMPL0 is required unless an SVSM is present and the
> + * hypervisor supports the required SVSM GHCB events. The hypervisor
> + * features are only available from GHCB version 2 onward, and this
> + * code may run before the GHCB protocol version has been negotiated,
> + * so take care of that first.
> + */
> + if (!sev_es_negotiate_protocol() ||
> + !(get_hv_features() & GHCB_HV_FT_SNP_MULTI_VMPL))
> + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0);
[Severity: Low]
Should a sev_es_negotiate_protocol() failure terminate with
SEV_TERM_SET_GEN / GHCB_SEV_ES_PROT_UNSUPPORTED instead of
GHCB_TERM_NOT_VMPL0?
svsm_setup_ca() runs before sev_enable() negotiates the protocol, so a
failed negotiation on a non-VMPL0 guest now reports the Linux-specific
GHCB_TERM_NOT_VMPL0 reason instead of the standard GHCB code, misleading
host diagnostics.
Checking !sev_es_negotiate_protocol() separately would preserve the
previous termination reason.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204154842.414894-5-ardb+git@google.com?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 3/3] x86/efistub: Don't bother enabling SEV in the EFI stub
2026-12-04 15:48 ` [PATCH v2 3/3] x86/efistub: Don't bother enabling SEV in the EFI stub Ard Biesheuvel
@ 2026-12-04 17:11 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-04 17:11 UTC (permalink / raw)
To: Ard Biesheuvel, linux-efi
Cc: Ard Biesheuvel, Borislav Petkov, Tom Lendacky, Ashish Kalra
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] x86/efistub: zero sme_me_mask breaks CR3 masking in
efi_5level_switch()
--
commit 6ed7d1eff8de535daf26e44568a238a0ae556e41
Author: Ard Biesheuvel <ardb@kernel.org>
x86/efistub: Don't bother enabling SEV in the EFI stub
This patch removes the sev_enable() call from efi_stub_entry() and its
declarations in asm/sev.h, relying on the core kernel's sme_enable() to
initialize SEV instead.
> diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
> index ebed96c03fa71..3ccc4670b2e12 100644
> --- a/drivers/firmware/efi/libstub/x86-stub.c
> +++ b/drivers/firmware/efi/libstub/x86-stub.c
> @@ -1047,12 +1047,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();
[Severity: High]
Does removing sev_enable() break CR3 masking in efi_5level_switch() on
AMD SEV guests?
efi_5level_switch() calls native_read_cr3_pa(), which relies on
CR3_ADDR_MASK (__sme_clr(PHYSICAL_PAGE_MASK)) to strip the C-bit from
CR3. Without sev_enable(), sme_me_mask stays 0 and physical_mask keeps
all 52 bits set since initialize_identity_maps() never runs in the stub.
When booting an SEV guest from 5-level UEFI firmware with no5lvl,
efi_5level_switch() will dereference cr3[0] with the C-bit still set,
causing a fatal page fault during boot.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204154842.414894-5-ardb+git@google.com?part=3
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-04 17:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 15:48 [PATCH v2 0/3] x86/efistub: Omit SEV-SNP init from the stub Ard Biesheuvel
2026-12-04 15:48 ` [PATCH v2 1/3] x86/efistub: Obtain SEV CC blob address " Ard Biesheuvel
2026-12-04 15:48 ` [PATCH v2 2/3] x86/sev: Check for SVSM GHCB event support in svsm_setup_ca() Ard Biesheuvel
2026-12-04 16:41 ` sashiko-bot
2026-12-04 15:48 ` [PATCH v2 3/3] x86/efistub: Don't bother enabling SEV in the EFI stub Ard Biesheuvel
2026-12-04 17:11 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox