mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/xstate: don't globally disable TILE_DATA just on its own
@ 2024-07-04 11:32 Jan Beulich
  0 siblings, 0 replies; only message in thread
From: Jan Beulich @ 2024-07-04 11:32 UTC (permalink / raw)
  To: lkml
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	the arch/x86 maintainers

In XCR0 certain bits need to be simultaneously set / clear. Since
fpu__init_cpu_xstate() wants to pass fpu_user_cfg.max_features to
XSETBV, make sure invalid values cannot end up there in case XFD is not
available. Do the clearing right for fpu_kernel_cfg.max_features (which
fpu_user_cfg.max_features is derived from), to avoid that field holding
an invalid combination of bits either.

Fixes: 2ae996e0c1a3 ("x86/fpu: Calculate the default sizes independently")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
#GP observed in a virtualized environment with AMX enabled, but XFD off
(which is an architecturally legal combination of features, afaict).

--- a/arch/x86/include/asm/fpu/xstate.h
+++ b/arch/x86/include/asm/fpu/xstate.h
@@ -49,6 +49,9 @@
 /* Features which are dynamically enabled for a process on request */
 #define XFEATURE_MASK_USER_DYNAMIC	XFEATURE_MASK_XTILE_DATA
 
+/* Features which the above ones are tied to. */
+#define XFEATURE_MASK_USER_DYN_DEPS	XFEATURE_MASK_XTILE_CFG
+
 /* All currently supported supervisor features */
 #define XFEATURE_MASK_SUPERVISOR_SUPPORTED (XFEATURE_MASK_PASID | \
 					    XFEATURE_MASK_CET_USER)
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -799,8 +799,15 @@ void __init fpu__init_system_xstate(unsi
 			fpu_kernel_cfg.max_features &= ~BIT_ULL(i);
 	}
 
-	if (!cpu_feature_enabled(X86_FEATURE_XFD))
-		fpu_kernel_cfg.max_features &= ~XFEATURE_MASK_USER_DYNAMIC;
+	if (!cpu_feature_enabled(X86_FEATURE_XFD)) {
+		/*
+		 * Besides disabling all dynamic features, also disable all
+		 * of their dependents, such that the resulting value can be
+		 * handed to XSETBV without causing #GP.
+		 */
+		fpu_kernel_cfg.max_features &= ~(XFEATURE_MASK_USER_DYNAMIC |
+						 XFEATURE_MASK_USER_DYN_DEPS);
+	}
 
 	if (!cpu_feature_enabled(X86_FEATURE_XSAVES))
 		fpu_kernel_cfg.max_features &= XFEATURE_MASK_USER_SUPPORTED;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-07-04 11:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-04 11:32 [PATCH] x86/xstate: don't globally disable TILE_DATA just on its own Jan Beulich

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

all inboxes | Powered by JetHome®