Skip to contentSkip to conversation

x86/boot/sev: Avoid shared GHCB page for early memory acceptance

PATCH New Ard Biesheuvel 1 participant 1 message Apr 17, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 x86/boot/sev: Avoid shared GHCB page for early memory acceptance

From: Ard Biesheuvel <[email protected]>

Communicating with the hypervisor using the shared GHCB page requires clearing the C bit in the mapping of that page. When executing in the context of the EFI boot services, the page tables are owned by the firmware, and this manipulation is not possible.

So switch to a different API for accepting memory in SEV-SNP guests, one which is actually supported at the point during boot where the EFI stub may need to accept memory, but the SEV-SNP init code has not executed yet.

For simplicity, also switch the memory acceptance carried out by the decompressor when not booting via EFI - this only involves the allocation for the decompressed kernel, and is generally only called after kexec, as normal boot will jump straight into the kernel from the EFI stub.

Cc Tom Lendacky <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dionna Amalie Glaze <[email protected]>
Cc Kevin Loughlin <[email protected]>
Fixes 6c3211796326 ("x86/sev: Add SNP-specific unaccepted memory support")

---
Changes since v3 [0]:
- work around the fact that sev_snp_enabled() does not work yet when the EFI stub accepts misaligned chunks of memory while populating the E820 table

Changes since v2 [1]:
- avoid two separate acceptance APIs; instead, use MSR based page-by-page acceptance for the decompressor as well

[0] https://lore.kernel.org/all/[email protected]/T/#u
[1] https://lore.kernel.org/all/[email protected]/T/#u

 arch/x86/boot/compressed/mem.c |  5 +-
 arch/x86/boot/compressed/sev.c | 67 +++++---------------
 arch/x86/boot/compressed/sev.h |  2 +
 3 files changed, 21 insertions(+), 53 deletions(-)
arch/x86/boot/compressed/mem.c +4 -1
index dbba332e4a12..f676156d9f3d 100644
@@ -34,11 +34,14 @@ static bool early_is_tdx_guest(void)
 
 void arch_accept_memory(phys_addr_t start, phys_addr_t end)
 {
+	static bool sevsnp;
+
 	/* Platform-specific memory-acceptance call goes here */
 	if (early_is_tdx_guest()) {
 		if (!tdx_accept_memory(start, end))
 			panic("TDX: Failed to accept memory\n");
-	} else if (sev_snp_enabled()) {
+	} else if (sevsnp || (sev_get_status() & MSR_AMD64_SEV_SNP_ENABLED)) {
+		sevsnp = true;
 		snp_accept_memory(start, end);
 	} else {
 		error("Cannot accept memory: unknown platform\n");
arch/x86/boot/compressed/sev.c +15 -52

104 lines not on this page · raw message

arch/x86/boot/compressed/sev.h +2 -0
index fc725a981b09..4e463f33186d 100644
@@ -12,11 +12,13 @@
 
 bool sev_snp_enabled(void);
 void snp_accept_memory(phys_addr_t start, phys_addr_t end);
+u64 sev_get_status(void);
 
 #else
 
 static inline bool sev_snp_enabled(void) { return false; }
 static inline void snp_accept_memory(phys_addr_t start, phys_addr_t end) { }
+static inline u64 sev_get_status(void) { return 0; }
 
 #endif
 
Signature · 1 line
2.49.0.805.g082f7c87e0-goog