]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/boot/sev: Support memory acceptance in the EFI stub under SVSM
authorArd Biesheuvel <ardb@kernel.org>
Mon, 28 Apr 2025 17:43:22 +0000 (19:43 +0200)
committerIngo Molnar <mingo@kernel.org>
Sun, 4 May 2025 06:20:27 +0000 (08:20 +0200)
Commit:

  d54d610243a4 ("x86/boot/sev: Avoid shared GHCB page for early memory acceptance")

provided a fix for SEV-SNP memory acceptance from the EFI stub when
running at VMPL #0. However, that fix was insufficient for SVSM SEV-SNP
guests running at VMPL >0, as those rely on a SVSM calling area, which
is a shared buffer whose address is programmed into a SEV-SNP MSR, and
the SEV init code that sets up this calling area executes much later
during the boot.

Given that booting via the EFI stub at VMPL >0 implies that the firmware
has configured this calling area already, reuse it for performing memory
acceptance in the EFI stub.

Fixes: fcd042e86422 ("x86/sev: Perform PVALIDATE using the SVSM when not at VMPL0")
Tested-by: Tom Lendacky <thomas.lendacky@amd.com>
Co-developed-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: <stable@vger.kernel.org>
Cc: Dionna Amalie Glaze <dionnaglaze@google.com>
Cc: Kevin Loughlin <kevinloughlin@google.com>
Cc: linux-efi@vger.kernel.org
Link: https://lore.kernel.org/r/20250428174322.2780170-2-ardb+git@google.com
arch/x86/boot/compressed/mem.c
arch/x86/boot/compressed/sev.c
arch/x86/boot/compressed/sev.h

index f676156d9f3db41f9a6ba3b7bcdb62639772ff63..0e9f84ab4bdcd18a3966e27b4249cc02833262d7 100644 (file)
@@ -34,14 +34,11 @@ 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 (sevsnp || (sev_get_status() & MSR_AMD64_SEV_SNP_ENABLED)) {
-               sevsnp = true;
+       } else if (early_is_sevsnp_guest()) {
                snp_accept_memory(start, end);
        } else {
                error("Cannot accept memory: unknown platform\n");
index 89ba168f4f0f02b613e8886e88890637037b336b..0003e4416efd16bc74181bbafa78a6c3d71f3362 100644 (file)
@@ -645,3 +645,43 @@ void sev_prep_identity_maps(unsigned long top_level_pgt)
 
        sev_verify_cbit(top_level_pgt);
 }
+
+bool early_is_sevsnp_guest(void)
+{
+       static bool sevsnp;
+
+       if (sevsnp)
+               return true;
+
+       if (!(sev_get_status() & MSR_AMD64_SEV_SNP_ENABLED))
+               return false;
+
+       sevsnp = true;
+
+       if (!snp_vmpl) {
+               unsigned int eax, ebx, ecx, edx;
+
+               /*
+                * CPUID Fn8000_001F_EAX[28] - SVSM support
+                */
+               eax = 0x8000001f;
+               ecx = 0;
+               native_cpuid(&eax, &ebx, &ecx, &edx);
+               if (eax & BIT(28)) {
+                       struct msr m;
+
+                       /* Obtain the address of the calling area to use */
+                       boot_rdmsr(MSR_SVSM_CAA, &m);
+                       boot_svsm_caa = (void *)m.q;
+                       boot_svsm_caa_pa = m.q;
+
+                       /*
+                        * The real VMPL level cannot be discovered, but the
+                        * memory acceptance routines make no use of that so
+                        * any non-zero value suffices here.
+                        */
+                       snp_vmpl = U8_MAX;
+               }
+       }
+       return true;
+}
index 4e463f33186df47ee445a1024aad22e4bf8e17d7..d3900384b8abb570f6caf9687f8a40415f59f667 100644 (file)
 bool sev_snp_enabled(void);
 void snp_accept_memory(phys_addr_t start, phys_addr_t end);
 u64 sev_get_status(void);
+bool early_is_sevsnp_guest(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; }
+static inline bool early_is_sevsnp_guest(void) { return false; }
 
 #endif