FAILED: patch "[PATCH] x86/fpu: Avoid writing LBR bit to IA32_XSS unless supported" failed to apply to 5.15-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 2848ff28d180bd63a95da8e5dcbcdd76c1beeb7b
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2024090809-plaything-sash-1d57@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^..
Possible dependencies:
2848ff28d180 ("x86/fpu: Avoid writing LBR bit to IA32_XSS unless supported") c33f0a81a2cf ("x86/fpu: Add fpu_state_config::legacy_features") d72c87018d00 ("x86/fpu/xstate: Move remaining xfeature helpers to core") eda32f4f93b4 ("x86/fpu: Rework restore_regs_from_fpstate()") daddee247319 ("x86/fpu: Mop up xfeatures_mask_uabi()")1c253ff2287f ("x86/fpu: Move xstate feature masks to fpu_*_cfg") 2bd264bce238 ("x86/fpu: Move xstate size to fpu_*_cfg")cd9ae7617449 ("x86/fpu/xstate: Cleanup size calculations") 617473acdfe4 ("x86/fpu: Cleanup fpu__init_system_xstate_size_legacy()") 578971f4e228 ("x86/fpu: Provide struct fpu_config")5509cc78080d ("x86/fpu/signal: Use fpstate for size and features") ad6ede407aae ("x86/fpu: Use fpstate in fpu_copy_kvm_uabi_to_fpstate()") be31dfdfd75b ("x86/fpu: Use fpstate::size")248452ce21ae ("x86/fpu: Add size and mask information to fpstate") 2dd8eedc80b1 ("x86/process: Move arch_thread_struct_whitelist() out of line") c20942ce5128 ("x86/fpu/core: Convert to fpstate")7e049e8b7459 ("x86/fpu/signal: Convert to fpstate")087df48c298c ("x86/fpu: Replace KVMs xstate component clearing") 18b3fa1ad15f ("x86/fpu: Convert restore_fpregs_from_fpstate() to struct fpstate") f83ac56acdad ("x86/fpu: Convert fpstate_init() to struct fpstate")
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 2848ff28d180bd63a95da8e5dcbcdd76c1beeb7b Mon Sep 17 00:00:00 2001
From: Mitchell Levy <[email protected]>
Date: Mon, 12 Aug 2024 13:44:12 -0700
Subject: [PATCH] x86/fpu: Avoid writing LBR bit to IA32_XSS unless supported
There are two distinct CPU features related to the use of XSAVES and LBR:
whether LBR is itself supported and whether XSAVES supports LBR. The LBR subsystem correctly checks both in intel_pmu_arch_lbr_init(), but the XSTATE subsystem does not.
The LBR bit is only removed from xfeatures_mask_independent when LBR is not supported by the CPU, but there is no validation of XSTATE support.
If XSAVES does not support LBR the write to IA32_XSS causes a #GP fault, leaving the state of IA32_XSS unchanged, i.e. zero. The fault is handled with a warning and the boot continues.
Consequently the next XRSTORS which tries to restore supervisor state fails with #GP because the RFBM has zero for all supervisor features, which does not match the XCOMP_BV field.
As XFEATURE_MASK_FPSTATE includes supervisor features setting up the FPU causes a #GP, which ends up in fpu_reset_from_exception_fixup(). That fails due to the same problem resulting in recursive #GPs until the kernel runs out of stack space and double faults.
Prevent this by storing the supported independent features in fpu_kernel_cfg during XSTATE initialization and use that cached value for retrieving the independent feature bits to be written into IA32_XSS.
[ tglx: Massaged change log ]
arch/x86/include/asm/fpu/types.h +7 -0
@@ -591,6 +591,13 @@ struct fpu_state_config {* even without XSAVE support, i.e. legacy features FP + SSE */ u64 legacy_features; +/* +* @independent_features: +* +* Features that are supported by XSAVES, but not managed as part of +* the FPU core, such as LBR +*/ +u64 independent_features; };/* FPU state configuration information */
arch/x86/kernel/fpu/xstate.c +3 -0
@@ -788,6 +788,9 @@ void __init fpu__init_system_xstate(unsigned int legacy_size) goto out_disable; } + fpu_kernel_cfg.independent_features = fpu_kernel_cfg.max_features & +XFEATURE_MASK_INDEPENDENT ; +/* * Clear XSAVE features that are disabled in the normal CPUID. */
arch/x86/kernel/fpu/xstate.h +2 -2
@@ -62,9 +62,9 @@ static inline u64 xfeatures_mask_supervisor(void)static inline u64 xfeatures_mask_independent (void ) {if (!cpu_feature_enabled (X86_FEATURE_ARCH_LBR )) -return XFEATURE_MASK_INDEPENDENT & ~XFEATURE_MASK_LBR ; +return fpu_kernel_cfg.independent_features & ~XFEATURE_MASK_LBR ; -return XFEATURE_MASK_INDEPENDENT ; +return fpu_kernel_cfg.independent_features; }/* XSAVE/XRSTOR wrapper functions */
PATCH 1/1 x86/fpu: Avoid writing LBR bit to IA32_XSS unless supported
There are two distinct CPU features related to the use of XSAVES and LBR:
whether LBR is itself supported and whether XSAVES supports LBR. The LBR subsystem correctly checks both in intel_pmu_arch_lbr_init(), but the XSTATE subsystem does not.
The LBR bit is only removed from xfeatures_mask_independent when LBR is not supported by the CPU, but there is no validation of XSTATE support. If XSAVES does not support LBR the write to IA32_XSS causes a #GP fault, leaving the state of IA32_XSS unchanged, i.e. zero. The fault is handled with a warning and the boot continues.
Consequently the next XRSTORS which tries to restore supervisor state fails with #GP because the RFBM has zero for all supervisor features, which does not match the XCOMP_BV field.
As XFEATURE_MASK_FPSTATE includes supervisor features setting up the FPU causes a #GP, which ends up in fpu_reset_from_exception_fixup(). That fails due to the same problem resulting in recursive #GPs until the kernel runs out of stack space and double faults.
Prevent this by storing the supported independent features in fpu_kernel_cfg during XSTATE initialization and use that cached value for retrieving the independent feature bits to be written into IA32_XSS.
[ tglx: Massaged change log ]
[ Mitchell Levy: Backport to 5.15, since struct fpu_config is not
introduced until 578971f4e228 and feature masks are not included in said struct until 1c253ff2287f ]
--- arch/x86/include/asm/fpu/xstate.h | 5 +++-- arch/x86/kernel/fpu/xstate.c | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-)
arch/x86/include/asm/fpu/xstate.h +3 -2
@@ -85,6 +85,7 @@#endif extern u64 xfeatures_mask_all; +extern u64 xfeatures_mask_indep;static inline u64 xfeatures_mask_supervisor (void ) {
@@ -124,9 +125,9 @@ static inline u64 xfeatures_mask_fpstate(void)static inline u64 xfeatures_mask_independent (void ) {if (!boot_cpu_has (X86_FEATURE_ARCH_LBR )) -return XFEATURE_MASK_INDEPENDENT & ~XFEATURE_MASK_LBR ; +return xfeatures_mask_indep & ~XFEATURE_MASK_LBR ; -return XFEATURE_MASK_INDEPENDENT ; +return xfeatures_mask_indep; }extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS ];
arch/x86/kernel/fpu/xstate.c +7 -0
@@ -60,6 +60,11 @@ static short xsave_cpuid_features[] __initdata = {* XSAVE buffer, both supervisor and user xstates. */ u64 xfeatures_mask_all__ro_after_init ; +/* +* This represents the "independent" xfeatures that are supported by XSAVES, but not managed as part +* of the FPU core, such as LBR. +*/ +u64 xfeatures_mask_indep__ro_after_init ;EXPORT_SYMBOL_GPL (xfeatures_mask_all); static unsigned int xstate_offsets[XFEATURE_MAX] __ro_after_init =
@@ -768,6 +773,8 @@ void __init fpu__init_system_xstate(void) goto out_disable; } + xfeatures_mask_indep = xfeatures_mask_all &XFEATURE_MASK_INDEPENDENT ; +/* * Clear XSAVE features that are disabled in the normal CPUID. */
Signature · 1 line
2.34.1
Greg KH
maintainerRe: [PATCH 5.15.y] x86/fpu: Avoid writing LBR bit to IA32_XSS unless supported
Quoted 31 lines · Mitchell Levy
There are two distinct CPU features related to the use of XSAVES and LBR:
whether LBR is itself supported and whether XSAVES supports LBR. The LBR subsystem correctly checks both inintel_pmu_arch_lbr_init(), but the XSTATE subsystem does not.The LBR bit is only removed from
xfeatures_mask_independentwhen LBR is not supported by the CPU, but there is no validation of XSTATE support. If XSAVES does not support LBR the write toIA32_XSScauses a #GP fault, leaving the state ofIA32_XSSunchanged, i.e. zero. The fault is handled with a warning and the boot continues.Consequently the next XRSTORS which tries to restore supervisor state fails with #GP because the RFBM has zero for all supervisor features, which does not match the
XCOMP_BVfield.As
XFEATURE_MASK_FPSTATEincludes supervisor features setting up the FPU causes a #GP, which ends up infpu_reset_from_exception_fixup(). That fails due to the same problem resulting in recursive #GPs until the kernel runs out of stack space and double faults.Prevent this by storing the supported independent features in
fpu_kernel_cfgduring XSTATE initialization and use that cached value for retrieving the independent feature bits to be written intoIA32_XSS.[ tglx: Massaged change log ]
Fixes f0dccc9da4c0 ("x86/fpu/xstate: Support dynamic supervisor feature for LBR")Suggested-by Thomas Gleixner <[email protected]>[ Mitchell Levy: Backport to 5.15, since struct
fpu_configis not
introduced until578971f4e228and feature masks are not included in said struct until1c253ff2287f]
Quoted 9 lines
Signed-off-by Mitchell Levy <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>--- arch/x86/include/asm/fpu/xstate.h | 5 +++-- arch/x86/kernel/fpu/xstate.c | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-)
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>