Skip to contentSkip to conversation

x86/xstate: don't globally disable TILE_DATA just on its own

PATCH New Jan Beulich 1 participant 1 message Jul 4, 2024 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/xstate: don't globally disable TILE_DATA just on its own

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")

---
#GP observed in a virtualized environment with AMX enabled, but XFD off (which is an architecturally legal combination of features, afaict).

arch/x86/include/asm/fpu/xstate.h +3 -0
@@ -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)
arch/x86/kernel/fpu/xstate.c +9 -2
@@ -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;