* [PATCH 0/4] x86/fpu: Complete the removal of cpu_has_xfeatures()
@ 2026-12-06 5:12 Eric Biggers
2026-12-06 5:12 ` [PATCH 1/4] x86/fpu: Check for missing CET_USER xstate component Eric Biggers
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Eric Biggers @ 2026-12-06 5:12 UTC (permalink / raw)
To: x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: linux-kernel, Christoph Hellwig, Dapeng Mi, Kan Liang,
Peter Zijlstra, Jiaming Zhang, Eric Biggers
This series completes the removal of cpu_has_xfeatures(), which was
originally attempted in
https://lore.kernel.org/all/20260901145740.42337-1-ebiggers@kernel.org/
but the actual removal was delayed because a new caller appeared.
Patches 1-3 address that new caller, then patch 4 removes
cpu_has_xfeatures().
Patch 1 also happens to fix the get_xsave_addr() warning reported by
Jiaming Zhang. (I know it's debatable whether it's really a "bug", as
it requires a buggy CPU or hypervisor. I'll let the x86 maintainers
decide whether they want to add Fixes and Cc stable to patch 1.)
This applies to next-20261204.
Eric Biggers (4):
x86/fpu: Check for missing CET_USER xstate component
x86/fpu: Check for missing APX xstate component
perf/x86/intel: Remove redundant cpu_has_xfeatures() checks
x86/fpu: Remove cpu_has_xfeatures()
arch/x86/events/intel/core.c | 22 ++++--------
arch/x86/include/asm/fpu/api.h | 9 -----
arch/x86/kernel/cpu/cpuid-deps.c | 1 +
arch/x86/kernel/fpu/xstate.c | 60 ++++++++++----------------------
4 files changed, 25 insertions(+), 67 deletions(-)
base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] x86/fpu: Check for missing CET_USER xstate component
2026-12-06 5:12 [PATCH 0/4] x86/fpu: Complete the removal of cpu_has_xfeatures() Eric Biggers
@ 2026-12-06 5:12 ` Eric Biggers
2026-12-06 5:12 ` [PATCH 2/4] x86/fpu: Check for missing APX " Eric Biggers
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2026-12-06 5:12 UTC (permalink / raw)
To: x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: linux-kernel, Christoph Hellwig, Dapeng Mi, Kan Liang,
Peter Zijlstra, Jiaming Zhang, Eric Biggers
If the CPU enumerates shadow stack support, verify that the CET_USER
xstate component is also enumerated. If not, warn and clear
X86_FEATURE_SHSTK. Also make X86_FEATURE_USER_SHSTK depend on
X86_FEATURE_SHSTK so that X86_FEATURE_USER_SHSTK gets cleared as well
(both here and if XSAVE is later disabled).
Previously, on a buggy CPU or hypervisor that enumerated SHSTK and
XSAVES without enumerating the CET_USER xstate component,
X86_FEATURE_USER_SHSTK remained enabled even though XFEATURE_CET_USER
was absent from the kernel's xstate mask. An unprivileged process could
then enable shadow stacks via arch_prctl() and trigger a WARNING in
get_xsave_addr() (e.g. via ssp_get() during a core dump or ptrace()).
This fixes the warning and allows kernel code to assume that
X86_FEATURE_USER_SHSTK (or X86_FEATURE_SHSTK) together with
X86_FEATURE_XSAVES implies XFEATURE_MASK_CET_USER.
Reported-by: Jiaming Zhang <r772577952@gmail.com>
Closes: https://lore.kernel.org/r/CANypQFbh+s+dORvfGnJ=Wp-2VDQPCJ7_wFWiVkVacdJA_U=6Ww@mail.gmail.com
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
arch/x86/kernel/cpu/cpuid-deps.c | 1 +
arch/x86/kernel/fpu/xstate.c | 7 +++++++
2 files changed, 8 insertions(+)
diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
index acbcec394ef16..a1a7b2c1b2f07 100644
--- a/arch/x86/kernel/cpu/cpuid-deps.c
+++ b/arch/x86/kernel/cpu/cpuid-deps.c
@@ -89,6 +89,7 @@ static const struct cpuid_dep cpuid_deps[] = {
{ X86_FEATURE_AMX_BF16, X86_FEATURE_AMX_TILE },
{ X86_FEATURE_AMX_INT8, X86_FEATURE_AMX_TILE },
{ X86_FEATURE_SHSTK, X86_FEATURE_XSAVES },
+ { X86_FEATURE_USER_SHSTK, X86_FEATURE_SHSTK },
{ X86_FEATURE_FRED, X86_FEATURE_LKGS },
{ X86_FEATURE_SPEC_CTRL_SSBD, X86_FEATURE_SPEC_CTRL },
{ X86_FEATURE_LASS, X86_FEATURE_SMAP },
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index da303714379cd..346aa126e1730 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -861,6 +861,13 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
}
}
+ if (boot_cpu_has(X86_FEATURE_SHSTK) &&
+ !(fpu_kernel_cfg.max_features & XFEATURE_MASK_CET_USER)) {
+ pr_err(FW_BUG
+ "x86/fpu: Disabling SHSTK support due to missing xstate feature\n");
+ setup_clear_cpu_cap(X86_FEATURE_SHSTK);
+ }
+
if (fpu_kernel_cfg.max_features & XFEATURE_MASK_APX &&
fpu_kernel_cfg.max_features & (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR)) {
/*
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] x86/fpu: Check for missing APX xstate component
2026-12-06 5:12 [PATCH 0/4] x86/fpu: Complete the removal of cpu_has_xfeatures() Eric Biggers
2026-12-06 5:12 ` [PATCH 1/4] x86/fpu: Check for missing CET_USER xstate component Eric Biggers
@ 2026-12-06 5:12 ` Eric Biggers
2026-12-06 5:12 ` [PATCH 3/4] perf/x86/intel: Remove redundant cpu_has_xfeatures() checks Eric Biggers
2026-12-06 5:12 ` [PATCH 4/4] x86/fpu: Remove cpu_has_xfeatures() Eric Biggers
3 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2026-12-06 5:12 UTC (permalink / raw)
To: x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: linux-kernel, Christoph Hellwig, Dapeng Mi, Kan Liang,
Peter Zijlstra, Jiaming Zhang, Eric Biggers
If the CPU enumerates APX support, verify that the corresponding xstate
component is also enumerated. If not, warn and clear X86_FEATURE_APX.
This allows kernel code to assume that X86_FEATURE_APX implies
XFEATURE_MASK_APX.
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
arch/x86/kernel/fpu/xstate.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 346aa126e1730..12759e17f3410 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -868,6 +868,13 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
setup_clear_cpu_cap(X86_FEATURE_SHSTK);
}
+ if (boot_cpu_has(X86_FEATURE_APX) &&
+ !(fpu_kernel_cfg.max_features & XFEATURE_MASK_APX)) {
+ pr_err(FW_BUG
+ "x86/fpu: Disabling APX support due to missing xstate feature\n");
+ setup_clear_cpu_cap(X86_FEATURE_APX);
+ }
+
if (fpu_kernel_cfg.max_features & XFEATURE_MASK_APX &&
fpu_kernel_cfg.max_features & (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR)) {
/*
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] perf/x86/intel: Remove redundant cpu_has_xfeatures() checks
2026-12-06 5:12 [PATCH 0/4] x86/fpu: Complete the removal of cpu_has_xfeatures() Eric Biggers
2026-12-06 5:12 ` [PATCH 1/4] x86/fpu: Check for missing CET_USER xstate component Eric Biggers
2026-12-06 5:12 ` [PATCH 2/4] x86/fpu: Check for missing APX " Eric Biggers
@ 2026-12-06 5:12 ` Eric Biggers
2026-12-06 5:12 ` [PATCH 4/4] x86/fpu: Remove cpu_has_xfeatures() Eric Biggers
3 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2026-12-06 5:12 UTC (permalink / raw)
To: x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: linux-kernel, Christoph Hellwig, Dapeng Mi, Kan Liang,
Peter Zijlstra, Jiaming Zhang, Eric Biggers
Remove the cpu_has_xfeatures() checks from
__intel_update_pmu_xregs_caps(), since they are redundant with the
corresponding X86_FEATURE_* checks. fpu__init_system_xstate() already
disables XSAVE (and therefore XSAVES), AVX, AVX512F, SHSTK (and
USER_SHSTK), and APX if their required xstate components are missing.
Also simplify the AVX-512 case to OR in XFEATURE_MASK_AVX512 directly.
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
arch/x86/events/intel/core.c | 22 ++++++----------------
1 file changed, 6 insertions(+), 16 deletions(-)
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index e752111f5ecd7..2f6ad6121a815 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -6255,8 +6255,7 @@ static inline void __intel_update_pmu_xregs_caps(struct pmu *pmu)
if (!boot_cpu_has(X86_FEATURE_XSAVES))
return;
- if (!boot_cpu_has(X86_FEATURE_XMM) ||
- !cpu_has_xfeatures(XFEATURE_MASK_SSE, NULL))
+ if (!boot_cpu_has(X86_FEATURE_XMM))
return;
/*
@@ -6266,22 +6265,13 @@ static inline void __intel_update_pmu_xregs_caps(struct pmu *pmu)
*/
x86_pmu.ext_regs_mask |= XFEATURE_MASK_SSE;
- if (boot_cpu_has(X86_FEATURE_AVX) &&
- cpu_has_xfeatures(XFEATURE_MASK_YMM, NULL))
+ if (boot_cpu_has(X86_FEATURE_AVX))
x86_pmu.ext_regs_mask |= XFEATURE_MASK_YMM;
- if (boot_cpu_has(X86_FEATURE_APX) &&
- cpu_has_xfeatures(XFEATURE_MASK_APX, NULL))
+ if (boot_cpu_has(X86_FEATURE_APX))
x86_pmu.ext_regs_mask |= XFEATURE_MASK_APX;
- if (boot_cpu_has(X86_FEATURE_AVX512F)) {
- if (cpu_has_xfeatures(XFEATURE_MASK_OPMASK, NULL))
- x86_pmu.ext_regs_mask |= XFEATURE_MASK_OPMASK;
- if (cpu_has_xfeatures(XFEATURE_MASK_ZMM_Hi256, NULL))
- x86_pmu.ext_regs_mask |= XFEATURE_MASK_ZMM_Hi256;
- if (cpu_has_xfeatures(XFEATURE_MASK_Hi16_ZMM, NULL))
- x86_pmu.ext_regs_mask |= XFEATURE_MASK_Hi16_ZMM;
- }
- if (cpu_feature_enabled(X86_FEATURE_USER_SHSTK) &&
- cpu_has_xfeatures(XFEATURE_MASK_CET_USER, NULL))
+ if (boot_cpu_has(X86_FEATURE_AVX512F))
+ x86_pmu.ext_regs_mask |= XFEATURE_MASK_AVX512;
+ if (cpu_feature_enabled(X86_FEATURE_USER_SHSTK))
x86_pmu.ext_regs_mask |= XFEATURE_MASK_CET_USER;
dest_pmu->capabilities |= PERF_PMU_CAP_EXTENDED_REGS;
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] x86/fpu: Remove cpu_has_xfeatures()
2026-12-06 5:12 [PATCH 0/4] x86/fpu: Complete the removal of cpu_has_xfeatures() Eric Biggers
` (2 preceding siblings ...)
2026-12-06 5:12 ` [PATCH 3/4] perf/x86/intel: Remove redundant cpu_has_xfeatures() checks Eric Biggers
@ 2026-12-06 5:12 ` Eric Biggers
3 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2026-12-06 5:12 UTC (permalink / raw)
To: x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: linux-kernel, Christoph Hellwig, Dapeng Mi, Kan Liang,
Peter Zijlstra, Jiaming Zhang, Eric Biggers
The only remaining caller of cpu_has_xfeatures() is
print_xstate_features(), which uses it only to check and get the name of
a single feature. Remove cpu_has_xfeatures() and inline the needed
check directly into print_xstate_features().
This also makes the trailing "unknown xstate feature" entry at index
XFEATURE_MAX of xfeature_names[] unnecessary, so remove it and add a
static_assert() verifying ARRAY_SIZE(xfeature_names) == XFEATURE_MAX.
Finally, make xfeature_names[] an __initconst, as it is no longer
accessed from any non-__init functions.
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
arch/x86/include/asm/fpu/api.h | 9 -------
arch/x86/kernel/fpu/xstate.c | 46 +++-------------------------------
2 files changed, 4 insertions(+), 51 deletions(-)
diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h
index 90c63fe19c0fb..cfed8b24d64f0 100644
--- a/arch/x86/include/asm/fpu/api.h
+++ b/arch/x86/include/asm/fpu/api.h
@@ -99,15 +99,6 @@ static inline void fpregs_assert_state_consistent(void) { }
*/
extern void switch_fpu_return(void);
-/*
- * Query the presence of one or more xfeatures. Works on any legacy CPU as well.
- *
- * If 'feature_name' is set then put a human-readable description of
- * the feature there as well - this can be used to print error (or success)
- * messages.
- */
-extern int cpu_has_xfeatures(u64 xfeatures_mask, const char **feature_name);
-
/* Trap handling */
extern int fpu__exception_code(struct fpu *fpu, int trap_nr);
extern void fpu_sync_fpstate(struct fpu *fpu);
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 12759e17f3410..30f22434e897f 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -44,7 +44,7 @@
* xfeature is completely unused. We use other mechanisms
* to save/restore PT state in Linux.
*/
-static const char *xfeature_names[] =
+static const char * const xfeature_names[] __initconst =
{
"x87 floating point registers",
"SSE registers",
@@ -66,8 +66,8 @@ static const char *xfeature_names[] =
"AMX Tile config",
"AMX Tile data",
"APX registers",
- "unknown xstate feature",
};
+static_assert(ARRAY_SIZE(xfeature_names) == XFEATURE_MAX);
static unsigned short xsave_cpuid_features[] __initdata = {
[XFEATURE_FP] = X86_FEATURE_FPU,
@@ -122,44 +122,6 @@ static inline unsigned int next_xfeature_order(unsigned int i, u64 mask)
#define XSTATE_FLAG_SUPERVISOR BIT(0)
#define XSTATE_FLAG_ALIGNED64 BIT(1)
-/*
- * Return whether the system supports a given xfeature.
- *
- * Also return the name of the (most advanced) feature that the caller requested:
- */
-int cpu_has_xfeatures(u64 xfeatures_needed, const char **feature_name)
-{
- u64 xfeatures_missing = xfeatures_needed & ~fpu_kernel_cfg.max_features;
-
- if (unlikely(feature_name)) {
- long xfeature_idx, max_idx;
- u64 xfeatures_print;
- /*
- * So we use FLS here to be able to print the most advanced
- * feature that was requested but is missing. So if a driver
- * asks about "XFEATURE_MASK_SSE | XFEATURE_MASK_YMM" we'll print the
- * missing AVX feature - this is the most informative message
- * to users:
- */
- if (xfeatures_missing)
- xfeatures_print = xfeatures_missing;
- else
- xfeatures_print = xfeatures_needed;
-
- xfeature_idx = fls64(xfeatures_print)-1;
- max_idx = ARRAY_SIZE(xfeature_names)-1;
- xfeature_idx = min(xfeature_idx, max_idx);
-
- *feature_name = xfeature_names[xfeature_idx];
- }
-
- if (xfeatures_missing)
- return 0;
-
- return 1;
-}
-EXPORT_SYMBOL_GPL(cpu_has_xfeatures);
-
static bool xfeature_is_aligned64(int xfeature_nr)
{
return xstate_flags[xfeature_nr] & XSTATE_FLAG_ALIGNED64;
@@ -302,9 +264,9 @@ static void __init print_xstate_features(void)
for (i = 0; i < XFEATURE_MAX; i++) {
u64 mask = BIT_ULL(i);
- const char *name;
+ const char *name = xfeature_names[i];
- if (cpu_has_xfeatures(mask, &name))
+ if (fpu_kernel_cfg.max_features & mask)
pr_info("x86/fpu: Supporting XSAVE feature 0x%03Lx: '%s'\n", mask, name);
}
}
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-06 5:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06 5:12 [PATCH 0/4] x86/fpu: Complete the removal of cpu_has_xfeatures() Eric Biggers
2026-12-06 5:12 ` [PATCH 1/4] x86/fpu: Check for missing CET_USER xstate component Eric Biggers
2026-12-06 5:12 ` [PATCH 2/4] x86/fpu: Check for missing APX " Eric Biggers
2026-12-06 5:12 ` [PATCH 3/4] perf/x86/intel: Remove redundant cpu_has_xfeatures() checks Eric Biggers
2026-12-06 5:12 ` [PATCH 4/4] x86/fpu: Remove cpu_has_xfeatures() Eric Biggers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox