Skip to content

Commit 009767d

Browse files
Pu Wensuryasaimadhu
authored andcommitted
x86/sev: Check SME/SEV support in CPUID first
The first two bits of the CPUID leaf 0x8000001F EAX indicate whether SEV or SME is supported, respectively. It's better to check whether SEV or SME is actually supported before accessing the MSR_AMD64_SEV to check whether SEV or SME is enabled. This is both a bare-metal issue and a guest/VM issue. Since the first generation Hygon Dhyana CPU doesn't support the MSR_AMD64_SEV, reading that MSR results in a #GP - either directly from hardware in the bare-metal case or via the hypervisor (because the RDMSR is actually intercepted) in the guest/VM case, resulting in a failed boot. And since this is very early in the boot phase, rdmsrl_safe()/native_read_msr_safe() can't be used. So check the CPUID bits first, before accessing the MSR. [ tlendacky: Expand and improve commit message. ] [ bp: Massage commit message. ] Fixes: eab696d ("x86/sev: Do not require Hypervisor CPUID bit for SEV guests") Signed-off-by: Pu Wen <puwen@hygon.cn> Signed-off-by: Borislav Petkov <bp@suse.de> Acked-by: Tom Lendacky <thomas.lendacky@amd.com> Cc: <stable@vger.kernel.org> # v5.10+ Link: https://lkml.kernel.org/r/20210602070207.2480-1-puwen@hygon.cn
1 parent 5405b42 commit 009767d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

arch/x86/mm/mem_encrypt_identity.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,6 @@ void __init sme_enable(struct boot_params *bp)
504504
#define AMD_SME_BIT BIT(0)
505505
#define AMD_SEV_BIT BIT(1)
506506

507-
/* Check the SEV MSR whether SEV or SME is enabled */
508-
sev_status = __rdmsr(MSR_AMD64_SEV);
509-
feature_mask = (sev_status & MSR_AMD64_SEV_ENABLED) ? AMD_SEV_BIT : AMD_SME_BIT;
510-
511507
/*
512508
* Check for the SME/SEV feature:
513509
* CPUID Fn8000_001F[EAX]
@@ -519,11 +515,16 @@ void __init sme_enable(struct boot_params *bp)
519515
eax = 0x8000001f;
520516
ecx = 0;
521517
native_cpuid(&eax, &ebx, &ecx, &edx);
522-
if (!(eax & feature_mask))
518+
/* Check whether SEV or SME is supported */
519+
if (!(eax & (AMD_SEV_BIT | AMD_SME_BIT)))
523520
return;
524521

525522
me_mask = 1UL << (ebx & 0x3f);
526523

524+
/* Check the SEV MSR whether SEV or SME is enabled */
525+
sev_status = __rdmsr(MSR_AMD64_SEV);
526+
feature_mask = (sev_status & MSR_AMD64_SEV_ENABLED) ? AMD_SEV_BIT : AMD_SME_BIT;
527+
527528
/* Check if memory encryption is enabled */
528529
if (feature_mask == AMD_SME_BIT) {
529530
/*

0 commit comments

Comments
 (0)