[PATCH] x86/fpu: Remove unnecessary checks for X86_FEATURE_FPU

Eric Biggers posted 1 patch 3 weeks, 4 days ago
There is a newer version of this series
arch/x86/kernel/fpu/bugs.c   | 4 ----
arch/x86/kernel/fpu/core.c   | 2 +-
arch/x86/kernel/fpu/init.c   | 2 --
arch/x86/kernel/fpu/xstate.c | 5 -----
4 files changed, 1 insertion(+), 12 deletions(-)
[PATCH] x86/fpu: Remove unnecessary checks for X86_FEATURE_FPU
Posted by Eric Biggers 3 weeks, 4 days ago
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().  Remove unnecessary
checks for X86_FEATURE_FPU that occur later in core x86 code.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 arch/x86/kernel/fpu/bugs.c   | 4 ----
 arch/x86/kernel/fpu/core.c   | 2 +-
 arch/x86/kernel/fpu/init.c   | 2 --
 arch/x86/kernel/fpu/xstate.c | 5 -----
 4 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/arch/x86/kernel/fpu/bugs.c b/arch/x86/kernel/fpu/bugs.c
index edbafc5940e3..4b84cd0a9d24 100644
--- a/arch/x86/kernel/fpu/bugs.c
+++ b/arch/x86/kernel/fpu/bugs.c
@@ -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();
 
 	/*
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index d1aeecd57f5e..100bfe7336dd 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -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))
 		asm volatile ("fninit");
 }
 EXPORT_SYMBOL_GPL(kernel_fpu_begin_mask);
diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index 0d33c217b71c..8804ef0295dc 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -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: */
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index a7b6524a9dea..029a9b896997 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -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: cee9395acd8043be0644b25c34bfa86623f2b935
-- 
2.55.0
Re: [PATCH] x86/fpu: Remove unnecessary checks for X86_FEATURE_FPU
Posted by Borislav Petkov 2 days, 16 hours ago
On Mon, Aug 31, 2026 at 11:57:06AM -0700, Eric Biggers wrote:
> 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().  Remove unnecessary
> checks for X86_FEATURE_FPU that occur later in core x86 code.
> 
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> ---
>  arch/x86/kernel/fpu/bugs.c   | 4 ----
>  arch/x86/kernel/fpu/core.c   | 2 +-
>  arch/x86/kernel/fpu/init.c   | 2 --
>  arch/x86/kernel/fpu/xstate.c | 5 -----
>  4 files changed, 1 insertion(+), 12 deletions(-)

Sashiko might have a point here:

https://sashiko.dev/#/patchset/20260831185706.90103-1-ebiggers%40kernel.org

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
Re: [PATCH] x86/fpu: Remove unnecessary checks for X86_FEATURE_FPU
Posted by Eric Biggers 2 days, 10 hours ago
On Wed, Sep 23, 2026 at 02:14:50PM -0700, Borislav Petkov wrote:
> On Mon, Aug 31, 2026 at 11:57:06AM -0700, Eric Biggers wrote:
> > 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().  Remove unnecessary
> > checks for X86_FEATURE_FPU that occur later in core x86 code.
> > 
> > Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> > ---
> >  arch/x86/kernel/fpu/bugs.c   | 4 ----
> >  arch/x86/kernel/fpu/core.c   | 2 +-
> >  arch/x86/kernel/fpu/init.c   | 2 --
> >  arch/x86/kernel/fpu/xstate.c | 5 -----
> >  4 files changed, 1 insertion(+), 12 deletions(-)
> 
> Sashiko might have a point here:
> 
> https://sashiko.dev/#/patchset/20260831185706.90103-1-ebiggers%40kernel.org

Sure, there's more stuff that can be removed too.  It will make for a
large patch, but I'll try to get the rest in x86/fpu code.

- Eric
Re: [PATCH] x86/fpu: Remove unnecessary checks for X86_FEATURE_FPU
Posted by H. Peter Anvin 3 weeks, 4 days ago
On 2026-08-31 11:57, Eric Biggers wrote:
> 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().  Remove unnecessary
> checks for X86_FEATURE_FPU that occur later in core x86 code.
> 
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>

Reviewed-by: H. Peter Anvin <hpa@zytor.com>


	-hpa