public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/fpu: Fix the os panic issue caused by the XGETBV instruction
@ 2025-01-02  7:54 Tony W Wang-oc
  2025-01-15 18:39 ` Chang S. Bae
  0 siblings, 1 reply; 5+ messages in thread
From: Tony W Wang-oc @ 2025-01-02  7:54 UTC (permalink / raw)
  To: tglx, mingo, bp, dave.hansen, x86, hpa, aruna.ramakrishna,
	pbonzini, levymitchell0, attofari, linux-kernel
  Cc: CobeChen, TimGuo, LeoLiu-oc, Lyle Li

From: Lyle Li <LyleLi@zhaoxin.com>

The callers of the xfeatures_in_use function must ensure that the
current processor has the X86_FEATURE_XGETBV1 feature. However, in some
places where xfeatures_in_use is called, there is no check to see if the
processor supports this feature, leading to the execution of the XGETBV
XCR1 instruction on processors that do not support this feature,
triggering a #GP exception, and ultimately causing an OS panic.

To fix this issue, a check for the X86_FEATURE_XGETBV1 feature has been
added before calling xfeatures_in_use.

Fixes: ae6012d72fa6 ("x86/pkeys: Ensure updated PKRU value is XRSTOR'd") 
Fixes: 30d02551ba4f ("x86/fpu: Optimize out sigframe xfeatures when in init state")
Signed-off-by: Lyle Li <LyleLi@zhaoxin.com>
Signed-off-by: Tony W Wang-oc <TonyWWang-oc@zhaoxin.com>
---
 arch/x86/kernel/fpu/xstate.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h
index aa16f1a1b..4d966c6c7 100644
--- a/arch/x86/kernel/fpu/xstate.h
+++ b/arch/x86/kernel/fpu/xstate.h
@@ -80,6 +80,9 @@ static inline int update_pkru_in_sigframe(struct xregs_state __user *buf, u64 ma
 	if (unlikely(!cpu_feature_enabled(X86_FEATURE_OSPKE)))
 		return 0;
 
+	if (!cpu_feature_enabled(X86_FEATURE_XGETBV1))
+		return 0;
+
 	/* Mark PKRU as in-use so that it is restored correctly. */
 	xstate_bv = (mask & xfeatures_in_use()) | XFEATURE_MASK_PKRU;
 
@@ -292,7 +295,7 @@ static inline int xsave_to_user_sigframe(struct xregs_state __user *buf, u32 pkr
 	int err;
 
 	/* Optimize away writing unnecessary xfeatures: */
-	if (fpu_state_size_dynamic())
+	if (cpu_feature_enabled(X86_FEATURE_XGETBV1) && fpu_state_size_dynamic())
 		mask &= xfeatures_need_sigframe_write();
 
 	lmask = mask;
-- 
2.25.1


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

end of thread, other threads:[~2025-01-18  3:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-02  7:54 [PATCH] x86/fpu: Fix the os panic issue caused by the XGETBV instruction Tony W Wang-oc
2025-01-15 18:39 ` Chang S. Bae
2025-01-17 22:10   ` Sean Christopherson
2025-01-17 23:24     ` Chang S. Bae
2025-01-18  3:13     ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox