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 2/3] x86/sev: Check for SVSM GHCB event support in svsm_setup_ca()
Date: Fri,  4 Dec 2026 16:48:45 +0100	[thread overview]
Message-ID: <20261204154842.414894-7-ardb+git@google.com> (raw)
In-Reply-To: <20261204154842.414894-5-ardb+git@google.com>

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


  parent 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 ` [PATCH v2 1/3] x86/efistub: Obtain SEV CC blob address " Ard Biesheuvel
2026-12-04 15:48 ` Ard Biesheuvel [this message]
2026-12-04 16:41   ` [PATCH v2 2/3] x86/sev: Check for SVSM GHCB event support in svsm_setup_ca() 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-7-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