linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/sev: Check whether SEV or SME is supported first
@ 2021-05-26  7:24 Pu Wen
  2021-05-26 17:27 ` Sean Christopherson
  2021-06-01 18:30 ` Tom Lendacky
  0 siblings, 2 replies; 16+ messages in thread
From: Pu Wen @ 2021-05-26  7:24 UTC (permalink / raw)
  To: x86
  Cc: puwen, joro, thomas.lendacky, dave.hansen, peterz, tglx, mingo,
	bp, hpa, jroedel, sashal, gregkh, linux-kernel, kvm, stable

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 supported before checking the SEV MSR(0xc0010131) to
see whether SEV or SME is enabled.

This also avoid the MSR reading failure on the first generation Hygon
Dhyana CPU which does not support SEV or SME.

Fixes: eab696d8e8b9 ("x86/sev: Do not require Hypervisor CPUID bit for SEV guests")
Cc: <stable@vger.kernel.org> # v5.10+
Signed-off-by: Pu Wen <puwen@hygon.cn>
---
 arch/x86/mm/mem_encrypt_identity.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c
index a9639f663d25..470b20208430 100644
--- a/arch/x86/mm/mem_encrypt_identity.c
+++ b/arch/x86/mm/mem_encrypt_identity.c
@@ -504,10 +504,6 @@ void __init sme_enable(struct boot_params *bp)
 #define AMD_SME_BIT	BIT(0)
 #define AMD_SEV_BIT	BIT(1)
 
-	/* Check the SEV MSR whether SEV or SME is enabled */
-	sev_status   = __rdmsr(MSR_AMD64_SEV);
-	feature_mask = (sev_status & MSR_AMD64_SEV_ENABLED) ? AMD_SEV_BIT : AMD_SME_BIT;
-
 	/*
 	 * Check for the SME/SEV feature:
 	 *   CPUID Fn8000_001F[EAX]
@@ -519,11 +515,16 @@ void __init sme_enable(struct boot_params *bp)
 	eax = 0x8000001f;
 	ecx = 0;
 	native_cpuid(&eax, &ebx, &ecx, &edx);
-	if (!(eax & feature_mask))
+	/* Check whether SEV or SME is supported */
+	if (!(eax & (AMD_SEV_BIT | AMD_SME_BIT)))
 		return;
 
 	me_mask = 1UL << (ebx & 0x3f);
 
+	/* Check the SEV MSR whether SEV or SME is enabled */
+	sev_status   = __rdmsr(MSR_AMD64_SEV);
+	feature_mask = (sev_status & MSR_AMD64_SEV_ENABLED) ? AMD_SEV_BIT : AMD_SME_BIT;
+
 	/* Check if memory encryption is enabled */
 	if (feature_mask == AMD_SME_BIT) {
 		/*
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-06-02  6:57 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-26  7:24 [PATCH] x86/sev: Check whether SEV or SME is supported first Pu Wen
2021-05-26 17:27 ` Sean Christopherson
2021-05-27 15:08   ` Pu Wen
2021-05-31  9:37     ` Joerg Roedel
2021-05-31 14:56       ` Pu Wen
2021-06-01 14:39         ` Borislav Petkov
2021-06-01 16:14           ` Sean Christopherson
2021-06-01 16:36             ` Tom Lendacky
2021-06-01 16:59               ` Borislav Petkov
2021-06-01 17:16                 ` Sean Christopherson
2021-06-01 17:48                   ` Borislav Petkov
2021-06-01 18:08                     ` Sean Christopherson
2021-06-01 18:24                       ` Borislav Petkov
2021-06-01 17:09               ` Sean Christopherson
2021-06-01 18:30 ` Tom Lendacky
2021-06-02  6:55   ` Wen Pu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).