Skip to content

Commit 3a6b90e

Browse files
committed
x86/sev: Do not try to parse for the CC blob on non-AMD hardware
jira LE-1907 Rebuild_History Non-Buildable kernel-5.14.0-284.30.1.el9_2 commit-author Borislav Petkov (AMD) <[email protected]> commit bee6cf1 Tao Liu reported a boot hang on an Intel Atom machine due to an unmapped EFI config table. The reason being that the CC blob which contains the CPUID page for AMD SNP guests is parsed for before even checking whether the machine runs on AMD hardware. Usually that's not a problem on !AMD hw - it simply won't find the CC blob's GUID and return. However, if any parts of the config table pointers array is not mapped, the kernel will #PF very early in the decompressor stage without any opportunity to recover. Therefore, do a superficial CPUID check before poking for the CC blob. This will fix the current issue on real hardware. It would also work as a guest on a non-lying hypervisor. For the lying hypervisor, the check is done again, *after* parsing the CC blob as the real CPUID page will be present then. Clear the #VC handler in case SEV-{ES,SNP} hasn't been detected, as a precaution. Fixes: c01fce9 ("x86/compressed: Add SEV-SNP feature detection/setup") Reported-by: Tao Liu <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Acked-by: Tom Lendacky <[email protected]> Tested-by: Tao Liu <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] (cherry picked from commit bee6cf1) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 936d064 commit 3a6b90e

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

arch/x86/boot/compressed/idt_64.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,14 @@ void load_stage2_idt(void)
6363
set_idt_entry(X86_TRAP_PF, boot_page_fault);
6464

6565
#ifdef CONFIG_AMD_MEM_ENCRYPT
66-
set_idt_entry(X86_TRAP_VC, boot_stage2_vc);
66+
/*
67+
* Clear the second stage #VC handler in case guest types
68+
* needing #VC have not been detected.
69+
*/
70+
if (sev_status & BIT(1))
71+
set_idt_entry(X86_TRAP_VC, boot_stage2_vc);
72+
else
73+
set_idt_entry(X86_TRAP_VC, NULL);
6774
#endif
6875

6976
load_boot_idt(&boot_idt_desc);

arch/x86/boot/compressed/sev.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,21 +284,54 @@ void sev_enable(struct boot_params *bp)
284284
if (bp)
285285
bp->cc_blob_address = 0;
286286

287+
/*
288+
* Do an initial SEV capability check before snp_init() which
289+
* loads the CPUID page and the same checks afterwards are done
290+
* without the hypervisor and are trustworthy.
291+
*
292+
* If the HV fakes SEV support, the guest will crash'n'burn
293+
* which is good enough.
294+
*/
295+
296+
/* Check for the SME/SEV support leaf */
297+
eax = 0x80000000;
298+
ecx = 0;
299+
native_cpuid(&eax, &ebx, &ecx, &edx);
300+
if (eax < 0x8000001f)
301+
return;
302+
303+
/*
304+
* Check for the SME/SEV feature:
305+
* CPUID Fn8000_001F[EAX]
306+
* - Bit 0 - Secure Memory Encryption support
307+
* - Bit 1 - Secure Encrypted Virtualization support
308+
* CPUID Fn8000_001F[EBX]
309+
* - Bits 5:0 - Pagetable bit position used to indicate encryption
310+
*/
311+
eax = 0x8000001f;
312+
ecx = 0;
313+
native_cpuid(&eax, &ebx, &ecx, &edx);
314+
/* Check whether SEV is supported */
315+
if (!(eax & BIT(1)))
316+
return;
317+
287318
/*
288319
* Setup/preliminary detection of SNP. This will be sanity-checked
289320
* against CPUID/MSR values later.
290321
*/
291322
snp = snp_init(bp);
292323

293-
/* Check for the SME/SEV support leaf */
324+
/* Now repeat the checks with the SNP CPUID table. */
325+
326+
/* Recheck the SME/SEV support leaf */
294327
eax = 0x80000000;
295328
ecx = 0;
296329
native_cpuid(&eax, &ebx, &ecx, &edx);
297330
if (eax < 0x8000001f)
298331
return;
299332

300333
/*
301-
* Check for the SME/SEV feature:
334+
* Recheck for the SME/SEV feature:
302335
* CPUID Fn8000_001F[EAX]
303336
* - Bit 0 - Secure Memory Encryption support
304337
* - Bit 1 - Secure Encrypted Virtualization support

0 commit comments

Comments
 (0)