Linux EFI development
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb+git@google.com>
To: linux-efi@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>, Borislav Petkov <bp@alien8.de>,
	 Tom Lendacky <thomas.lendacky@amd.com>,
	Ashish Kalra <Ashish.Kalra@amd.com>
Subject: [PATCH v2 1/3] x86/efistub: Obtain SEV CC blob address from the stub
Date: Fri,  4 Dec 2026 16:48:44 +0100	[thread overview]
Message-ID: <20261204154842.414894-6-ardb+git@google.com> (raw)
In-Reply-To: <20261204154842.414894-5-ardb+git@google.com>

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


  reply	other threads:[~2026-12-04 15:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204154842.414894-6-ardb+git@google.com \
    --to=ardb+git@google.com \
    --cc=Ashish.Kalra@amd.com \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=linux-efi@vger.kernel.org \
    --cc=thomas.lendacky@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox