x86/fpu: Remove unnecessary checks for X86_FEATURE_FPU
PATCH v2 1/1 x86/fpu: Remove unnecessary checks for X86_FEATURE_FPU
Since commit ab05214025ee ("x86/fpu: Remove MATH_EMULATION and related glue code"), X86_FEATURE_FPU is mandatory. If it's absent, the kernel halts execution in fpu__init_system_early_generic().
Therefore, remove unnecessary checks for X86_FEATURE_FPU that occur later in x86/fpu code.
This makes struct swregs_state and the extern declarations of fpregs_soft_get and fpregs_soft_set all unused. So remove those too.
---
v2: Remove more unnecessary code.
arch/x86/include/asm/fpu/regset.h | 6 ++---- arch/x86/include/asm/fpu/sched.h | 1 - arch/x86/include/asm/fpu/types.h | 25 ------------------------- arch/x86/kernel/fpu/bugs.c | 4 ---- arch/x86/kernel/fpu/core.c | 13 +------------ arch/x86/kernel/fpu/init.c | 6 +----- arch/x86/kernel/fpu/regset.c | 6 ------ arch/x86/kernel/fpu/signal.c | 16 +--------------- arch/x86/kernel/fpu/xstate.c | 5 ----- 9 files changed, 5 insertions(+), 77 deletions(-)
arch/x86/include/asm/fpu/regset.h +2 -4
@@ -9,10 +9,8 @@extern user_regset_active_fn regset_fpregs_active, regset_xregset_fpregs_active, ssp_active; -extern user_regset_get2_fn fpregs_get, xfpregs_get, fpregs_soft_get, - xstateregs_get, ssp_get; -extern user_regset_set_fn fpregs_set, xfpregs_set, fpregs_soft_set, - xstateregs_set, ssp_set; +extern user_regset_get2_fn fpregs_get, xfpregs_get, xstateregs_get, ssp_get; +extern user_regset_set_fn fpregs_set, xfpregs_set, xstateregs_set, ssp_set;/* * xstateregs_active == regset_fpregs_active. Please refer to the comment
arch/x86/include/asm/fpu/sched.h +0 -1
@@ -32,7 +32,6 @@ extern void fpu_flush_thread(void);static inline void switch_fpu (struct task_struct *old,int cpu) {if (!test_tsk_thread_flag (old,TIF_NEED_FPU_LOAD ) && -cpu_feature_enabled (X86_FEATURE_FPU ) && !(old->flags & (PF_KTHREAD |PF_USER_WORKER ))) {struct fpu *old_fpu =x86_task_fpu (old);
arch/x86/include/asm/fpu/types.h +0 -25
@@ -74,30 +74,6 @@ struct fxregs_state {/* Copy both mxcsr & mxcsr_flags with a single u64 memcpy: */ #define MXCSR_AND_FLAGS_SIZE sizeof(u64) -/* -* Software based FPU emulation state. This is arbitrary really, -* it matches the x87 format to make it easier to understand: -*/ -struct swregs_state { -u32 cwd; -u32 swd; -u32 twd; -u32 fip; -u32 fcs; -u32 foo; -u32 fos; -/* 8*10 bytes for each FP-reg = 80 bytes: */ -u32 st_space[20 ]; -u8 ftop; -u8 changed; -u8 lookahead; -u8 no_update; -u8 rm; -u8 alimit; -struct math_emu_info *info; -u32 entry_eip; -}; -/* * List of XSAVE features Linux knows about: */
@@ -369,7 +345,6 @@ struct xregs_state {union fpregs_state {struct fregs_state fsave;struct fxregs_state fxsave; -struct swregs_state soft;struct xregs_state xsave;u8 __padding[PAGE_SIZE ]; };
arch/x86/kernel/fpu/bugs.c +0 -4
@@ -29,10 +29,6 @@ void __init fpu__init_check_bugs(void) {s32 fdiv_bug; -/* kernel_fpu_begin/end() relies on patched alternative instructions. */ -if (!boot_cpu_has (X86_FEATURE_FPU )) -return ; -kernel_fpu_begin ();/*
arch/x86/kernel/fpu/core.c +1 -12
@@ -491,7 +491,7 @@ void kernel_fpu_begin_mask(unsigned int kfpu_mask)if (likely (kfpu_mask &KFPU_MXCSR ) &&boot_cpu_has (X86_FEATURE_XMM ))ldmxcsr (MXCSR_DEFAULT ); -if (unlikely (kfpu_mask &KFPU_387 ) &&boot_cpu_has (X86_FEATURE_FPU )) +if (unlikely (kfpu_mask &KFPU_387 )) asmvolatile ("fninit" ); }EXPORT_SYMBOL_GPL (kernel_fpu_begin_mask);
@@ -672,9 +672,6 @@ int fpu_clone(struct task_struct *dst, u64 clone_flags, bool minimal,fpstate_reset (dst_fpu); -if (!cpu_feature_enabled (X86_FEATURE_FPU )) -return 0 ; -/* * Enforce reload for user space tasks and prevent kernel threads * from trying to save the FPU registers on context switch.
@@ -833,11 +830,6 @@ void fpu__clear_user_states(struct fpu *fpu)WARN_ON_FPU (fpu !=x86_task_fpu (current));fpregs_lock (); -if (!cpu_feature_enabled (X86_FEATURE_FPU )) { -fpu_reset_fpstate_regs (); -fpregs_unlock (); -return ; - }/* * Ensure that current's supervisor states are loaded into their
@@ -874,9 +866,6 @@ void fpu_flush_thread(void)*/ void switch_fpu_return (void ) { -if (!cpu_feature_enabled (X86_FEATURE_FPU )) -return ; -fpregs_restore_userregs (); }EXPORT_SYMBOL_FOR_KVM (switch_fpu_return);
arch/x86/kernel/fpu/init.c +1 -5
@@ -31,8 +31,6 @@ static void fpu__init_cpu_generic(void) cr0 =read_cr0 (); cr0 &= ~(X86_CR0_TS |X86_CR0_EM );/* clear TS and EM */ -if (!boot_cpu_has (X86_FEATURE_FPU )) - cr0 |=X86_CR0_EM ;write_cr0 (cr0);/* Flush out any pending x87 state: */
@@ -184,9 +182,7 @@ static void __init fpu__init_system_xstate_size_legacy(void)* Note that the size configuration might be overwritten later * during fpu__init_system_xstate(). */ -if (!cpu_feature_enabled (X86_FEATURE_FPU )) { - size =sizeof (struct swregs_state ); - }else if (cpu_feature_enabled (X86_FEATURE_FXSR )) { +if (cpu_feature_enabled (X86_FEATURE_FXSR )) { size =sizeof (struct fxregs_state ); fpu_user_cfg.legacy_features =XFEATURE_MASK_FPSSE ; }else {
arch/x86/kernel/fpu/regset.c +0 -6
@@ -407,9 +407,6 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,sync_fpstate (fpu); -if (!cpu_feature_enabled (X86_FEATURE_FPU )) -return fpregs_soft_get (target, regset, to); -if (!cpu_feature_enabled (X86_FEATURE_FXSR )) {return membuf_write (&to, &fpu->fpstate->regs.fsave,sizeof (struct fregs_state ));
@@ -441,9 +438,6 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,if (pos !=0 || count !=sizeof (struct user_i387_ia32_struct ))return -EINVAL ; -if (!cpu_feature_enabled (X86_FEATURE_FPU )) -return fpregs_soft_set (target, regset, pos, count, kbuf, ubuf); - ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &env,0 ,-1 );if (ret)return ret;
arch/x86/kernel/fpu/signal.c +1 -15
@@ -187,14 +187,6 @@ bool copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size, u ia32_fxstate &= (IS_ENABLED (CONFIG_X86_32 ) ||IS_ENABLED (CONFIG_IA32_EMULATION )); -if (!cpu_feature_enabled (X86_FEATURE_FPU )) { -struct user_i387_ia32_struct fp; - -fpregs_soft_get (current,NULL , (struct membuf ){.p = &fp, - .left =sizeof (fp)}); -return !copy_to_user (buf, &fp,sizeof (fp)); - } -if (!access_ok (buf, size))return false;
@@ -477,13 +469,7 @@ bool fpu__restore_sig(void __user *buf, int ia32_frame)if (!access_ok (buf, size)) goto out; -if (!IS_ENABLED (CONFIG_X86_64 ) && !cpu_feature_enabled (X86_FEATURE_FPU )) { - success = !fpregs_soft_set (current,NULL ,0 , -sizeof (struct user_i387_ia32_struct ), -NULL , buf); - }else { - success =__fpu_restore_sig (buf, buf_fx, ia32_fxstate); - } + success =__fpu_restore_sig (buf, buf_fx, ia32_fxstate); out:if (unlikely (!success))
arch/x86/kernel/fpu/xstate.c +0 -5
@@ -810,11 +810,6 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)int err;int i; -if (!boot_cpu_has (X86_FEATURE_FPU )) { -pr_info ("x86/fpu: No FPU detected\n" ); -return ; - } -if (!boot_cpu_has (X86_FEATURE_XSAVE )) {pr_info ("x86/fpu: x87 FPU will use %s\n" ,boot_cpu_has (X86_FEATURE_FXSR ) ?"FXSAVE" :"FSAVE" );
base-commit: c0a44d1745d3f209e4840b78ab75274fb74f01a0
Signature · 1 line
2.55.0
The following commit has been merged into the x86/fpu branch of tip:
The following commit has been merged into the x86/fpu branch of tip:
Commit-ID: 67639ee98521c1592190c5c67047067a9c3a3fd5 Gitweb: https://git.kernel.org/tip/67639ee98521c1592190c5c67047067a9c3a3fd5 Author: Eric Biggers <[email protected]> AuthorDate: Fri, 25 Sep 2026 21:30:07 -07:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Fri, 25 Sep 2026 21:35:37 -07:00
x86/fpu: Remove unnecessary checks for X86_FEATURE_FPU
Since
ab05214025ee ("x86/fpu: Remove MATH_EMULATION and related glue code"),
X86_FEATURE_FPU is mandatory. If it's absent, the kernel halts execution in fpu__init_system_early_generic().
Therefore, remove unnecessary checks for X86_FEATURE_FPU that occur later in x86/fpu code.
This makes struct swregs_state and the extern declarations of fpregs_soft_get and fpregs_soft_set all unused. So remove those too.
--- arch/x86/include/asm/fpu/regset.h | 6 ++---- arch/x86/include/asm/fpu/sched.h | 1 - arch/x86/include/asm/fpu/types.h | 25 ------------------------- arch/x86/kernel/fpu/bugs.c | 4 ---- arch/x86/kernel/fpu/core.c | 13 +------------ arch/x86/kernel/fpu/init.c | 6 +----- arch/x86/kernel/fpu/regset.c | 6 ------ arch/x86/kernel/fpu/signal.c | 15 --------------- arch/x86/kernel/fpu/xstate.c | 5 ----- 9 files changed, 4 insertions(+), 77 deletions(-)
arch/x86/include/asm/fpu/regset.h +2 -4
@@ -9,10 +9,8 @@extern user_regset_active_fn regset_fpregs_active, regset_xregset_fpregs_active, ssp_active; -extern user_regset_get2_fn fpregs_get, xfpregs_get, fpregs_soft_get, - xstateregs_get, ssp_get; -extern user_regset_set_fn fpregs_set, xfpregs_set, fpregs_soft_set, - xstateregs_set, ssp_set; +extern user_regset_get2_fn fpregs_get, xfpregs_get, xstateregs_get, ssp_get; +extern user_regset_set_fn fpregs_set, xfpregs_set, xstateregs_set, ssp_set;/* * xstateregs_active == regset_fpregs_active. Please refer to the comment
arch/x86/include/asm/fpu/sched.h +0 -1
@@ -32,7 +32,6 @@ extern void fpu_flush_thread(void);static inline void switch_fpu (struct task_struct *old,int cpu) {if (!test_tsk_thread_flag (old,TIF_NEED_FPU_LOAD ) && -cpu_feature_enabled (X86_FEATURE_FPU ) && !(old->flags & (PF_KTHREAD |PF_USER_WORKER ))) {struct fpu *old_fpu =x86_task_fpu (old);
arch/x86/include/asm/fpu/types.h +0 -25
@@ -75,30 +75,6 @@ struct fxregs_state {#define MXCSR_AND_FLAGS_SIZE sizeof(u64)/* -* Software based FPU emulation state. This is arbitrary really, -* it matches the x87 format to make it easier to understand: -*/ -struct swregs_state { -u32 cwd; -u32 swd; -u32 twd; -u32 fip; -u32 fcs; -u32 foo; -u32 fos; -/* 8*10 bytes for each FP-reg = 80 bytes: */ -u32 st_space[20 ]; -u8 ftop; -u8 changed; -u8 lookahead; -u8 no_update; -u8 rm; -u8 alimit; -struct math_emu_info *info; -u32 entry_eip; -}; - -/* * List of XSAVE features Linux knows about: */ enum xfeature {
@@ -369,7 +345,6 @@ struct xregs_state {union fpregs_state {struct fregs_state fsave;struct fxregs_state fxsave; -struct swregs_state soft;struct xregs_state xsave;u8 __padding[PAGE_SIZE ]; };
arch/x86/kernel/fpu/bugs.c +0 -4
@@ -29,10 +29,6 @@ void __init fpu__init_check_bugs(void) {s32 fdiv_bug; -/* kernel_fpu_begin/end() relies on patched alternative instructions. */ -if (!boot_cpu_has (X86_FEATURE_FPU )) -return ; -kernel_fpu_begin ();/*
arch/x86/kernel/fpu/core.c +1 -12
@@ -491,7 +491,7 @@ void kernel_fpu_begin_mask(unsigned int kfpu_mask)if (likely (kfpu_mask &KFPU_MXCSR ) &&boot_cpu_has (X86_FEATURE_XMM ))ldmxcsr (MXCSR_DEFAULT ); -if (unlikely (kfpu_mask &KFPU_387 ) &&boot_cpu_has (X86_FEATURE_FPU )) +if (unlikely (kfpu_mask &KFPU_387 )) asmvolatile ("fninit" ); }EXPORT_SYMBOL_GPL (kernel_fpu_begin_mask);
@@ -672,9 +672,6 @@ int fpu_clone(struct task_struct *dst, u64 clone_flags, bool minimal,fpstate_reset (dst_fpu); -if (!cpu_feature_enabled (X86_FEATURE_FPU )) -return 0 ; -/* * Enforce reload for user space tasks and prevent kernel threads * from trying to save the FPU registers on context switch.
@@ -833,11 +830,6 @@ void fpu__clear_user_states(struct fpu *fpu)WARN_ON_FPU (fpu !=x86_task_fpu (current));fpregs_lock (); -if (!cpu_feature_enabled (X86_FEATURE_FPU )) { -fpu_reset_fpstate_regs (); -fpregs_unlock (); -return ; - }/* * Ensure that current's supervisor states are loaded into their
@@ -874,9 +866,6 @@ void fpu_flush_thread(void)*/ void switch_fpu_return (void ) { -if (!cpu_feature_enabled (X86_FEATURE_FPU )) -return ; -fpregs_restore_userregs (); }EXPORT_SYMBOL_FOR_KVM (switch_fpu_return);
arch/x86/kernel/fpu/init.c +1 -5
@@ -31,8 +31,6 @@ static void fpu__init_cpu_generic(void) cr0 =read_cr0 (); cr0 &= ~(X86_CR0_TS |X86_CR0_EM );/* clear TS and EM */ -if (!boot_cpu_has (X86_FEATURE_FPU )) - cr0 |=X86_CR0_EM ;write_cr0 (cr0);/* Flush out any pending x87 state: */
@@ -184,9 +182,7 @@ static void __init fpu__init_system_xstate_size_legacy(void)* Note that the size configuration might be overwritten later * during fpu__init_system_xstate(). */ -if (!cpu_feature_enabled (X86_FEATURE_FPU )) { - size =sizeof (struct swregs_state ); - }else if (cpu_feature_enabled (X86_FEATURE_FXSR )) { +if (cpu_feature_enabled (X86_FEATURE_FXSR )) { size =sizeof (struct fxregs_state ); fpu_user_cfg.legacy_features =XFEATURE_MASK_FPSSE ; }else {
arch/x86/kernel/fpu/regset.c +0 -6
@@ -407,9 +407,6 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,sync_fpstate (fpu); -if (!cpu_feature_enabled (X86_FEATURE_FPU )) -return fpregs_soft_get (target, regset, to); -if (!cpu_feature_enabled (X86_FEATURE_FXSR )) {return membuf_write (&to, &fpu->fpstate->regs.fsave,sizeof (struct fregs_state ));
@@ -441,9 +438,6 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,if (pos !=0 || count !=sizeof (struct user_i387_ia32_struct ))return -EINVAL ; -if (!cpu_feature_enabled (X86_FEATURE_FPU )) -return fpregs_soft_set (target, regset, pos, count, kbuf, ubuf); - ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &env,0 ,-1 );if (ret)return ret;
arch/x86/kernel/fpu/signal.c +0 -15
@@ -212,14 +212,6 @@ bool copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size, u ia32_fxstate &= (IS_ENABLED (CONFIG_X86_32 ) ||IS_ENABLED (CONFIG_IA32_EMULATION )); -if (!cpu_feature_enabled (X86_FEATURE_FPU )) { -struct user_i387_ia32_struct fp; - -fpregs_soft_get (current,NULL , (struct membuf ){.p = &fp, - .left =sizeof (fp)}); -return !copy_to_user (buf, &fp,sizeof (fp)); - } -if (!access_ok (buf, size))return false;
@@ -499,13 +491,6 @@ bool fpu__restore_sig(void __user *buf, int ia32_frame)if (!access_ok (buf, size)) goto out; -if (!IS_ENABLED (CONFIG_X86_64 ) && !cpu_feature_enabled (X86_FEATURE_FPU )) { - success = !fpregs_soft_set (current,NULL ,0 , -sizeof (struct user_i387_ia32_struct ), -NULL , buf); - goto out; - } -if (use_xsave ()) {struct _fpx_sw_bytes fx_sw_user;
arch/x86/kernel/fpu/xstate.c +0 -5
@@ -811,11 +811,6 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)int err;int i; -if (!boot_cpu_has (X86_FEATURE_FPU )) { -pr_info ("x86/fpu: No FPU detected\n" ); -return ; - } -if (!boot_cpu_has (X86_FEATURE_XSAVE )) {pr_info ("x86/fpu: x87 FPU will use %s\n" ,boot_cpu_has (X86_FEATURE_FXSR ) ?"FXSAVE" :"FSAVE" );