[PATCH 08/15] x86/fpu: Remove MATH_EMULATION and related glue code

Ingo Molnar
2025-12-14T08:47:52Z

Cc: Ahmed S . Darwish <darwi@linutronix.de>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: H . Peter Anvin <hpa@zytor.com>
Cc: John Ogness <john.ogness@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250425084216.3913608-9-mingo@kernel.org
---
arch/x86/Kconfig | 27 ---------------------------
arch/x86/Kconfig.cpufeatures | 1 -
arch/x86/Makefile | 1 -
arch/x86/include/asm/fpu/api.h | 6 ------
arch/x86/kernel/fpu/core.c | 5 -----
arch/x86/kernel/fpu/init.c | 9 +--------
arch/x86/kernel/traps.c | 14 --------------
7 files changed, 1 insertion(+), 62 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ecd4c77827e9..60a03b61214a 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1622,33 +1622,6 @@ config X86_BOOTPARAM_MEMORY_CORRUPTION_CHECK
Set whether the default state of memory_corruption_check is
on or off.

-config MATH_EMULATION
- bool
- depends on MODIFY_LDT_SYSCALL
- prompt "Math emulation" if X86_32 && (M486SX || MELAN)
- help
- Linux can emulate a math coprocessor (used for floating point
- operations) if you don't have one. 486DX and Pentium processors have
- a math coprocessor built in, 486SX and 386 do not, unless you added
- a 487DX or 387, respectively. (The messages during boot time can
- give you some hints here ["man dmesg"].) Everyone needs either a
- coprocessor or this emulation.
-
- If you don't have a math coprocessor, you need to say Y here; if you
- say Y here even though you have a coprocessor, the coprocessor will
- be used nevertheless. (This behavior can be changed with the kernel
- command line option "no387", which comes handy if your coprocessor
- is broken. Try "man bootparam" or see the documentation of your boot
- loader (lilo or loadlin) about how to pass options to the kernel at
- boot time.) This means that it is a good idea to say Y here if you
- intend to use this kernel on different machines.
-
- More information about the internals of the Linux math coprocessor
- emulation can be found in <file:arch/x86/math-emu/README>.
-
- If you are not sure, say Y; apart from resulting in a 66 KB bigger
- kernel, it won't hurt.
-
config MTRR
def_bool y
prompt "MTRR (Memory Type Range Register) support" if EXPERT
diff --git a/arch/x86/Kconfig.cpufeatures b/arch/x86/Kconfig.cpufeatures
index 733d5aff2456..888487e109bf 100644
--- a/arch/x86/Kconfig.cpufeatures
+++ b/arch/x86/Kconfig.cpufeatures
@@ -66,7 +66,6 @@ config X86_REQUIRED_FEATURE_UP

config X86_REQUIRED_FEATURE_FPU
def_bool y
- depends on !MATH_EMULATION

config X86_REQUIRED_FEATURE_PAE
def_bool y
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 1d403a3612ea..be7d282bebc6 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -280,7 +280,6 @@ archprepare: $(cpufeaturemasks.hdr)
libs-y += arch/x86/lib/

# drivers-y are linked after core-y
-drivers-$(CONFIG_MATH_EMULATION) += arch/x86/math-emu/
drivers-$(CONFIG_PCI) += arch/x86/pci/

# suspend and hibernation support
diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h
index cd6f194a912b..90c63fe19c0f 100644
--- a/arch/x86/include/asm/fpu/api.h
+++ b/arch/x86/include/asm/fpu/api.h
@@ -119,12 +119,6 @@ extern void fpu__init_system(void);
extern void fpu__init_check_bugs(void);
extern void fpu__resume_cpu(void);

-#ifdef CONFIG_MATH_EMULATION
-extern void fpstate_init_soft(struct swregs_state *soft);
-#else
-static inline void fpstate_init_soft(struct swregs_state *soft) {}
-#endif
-
/* State tracking */
DECLARE_PER_CPU(bool, kernel_fpu_allowed);
DECLARE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index da233f20ae6f..2996c1c8c71a 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -532,11 +532,6 @@ static inline void fpstate_init_fstate(struct fpstate *fpstate)
*/
void fpstate_init_user(struct fpstate *fpstate)
{
- if (!cpu_feature_enabled(X86_FEATURE_FPU)) {
- fpstate_init_soft(&fpstate->regs.soft);
- return;
- }
-
xstate_init_xcomp_bv(&fpstate->regs.xsave, fpstate->xfeatures);

if (cpu_feature_enabled(X86_FEATURE_FXSR))
diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c
index ff988b9ea39f..0d33c217b71c 100644
--- a/arch/x86/kernel/fpu/init.c
+++ b/arch/x86/kernel/fpu/init.c
@@ -36,12 +36,7 @@ static void fpu__init_cpu_generic(void)
write_cr0(cr0);

/* Flush out any pending x87 state: */
-#ifdef CONFIG_MATH_EMULATION
- if (!boot_cpu_has(X86_FEATURE_FPU))
- ;
- else
-#endif
- asm volatile ("fninit");
+ asm volatile ("fninit");
}

/*
@@ -86,13 +81,11 @@ static void __init fpu__init_system_early_generic(void)
setup_clear_cpu_cap(X86_FEATURE_FPU);
}

-#ifndef CONFIG_MATH_EMULATION
if (!test_cpu_cap(&boot_cpu_data, X86_FEATURE_FPU)) {
pr_emerg("x86/fpu: Giving up, no FPU found and no math emulation present\n");
for (;;)
asm volatile("hlt");
}
-#endif
}

/*
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 5434cba078fb..d974b22e8b2a 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -1541,20 +1541,6 @@ DEFINE_IDTENTRY(exc_device_not_available)
if (handle_xfd_event(regs))
return;

-#ifdef CONFIG_MATH_EMULATION
- if (!boot_cpu_has(X86_FEATURE_FPU) && (cr0 & X86_CR0_EM)) {
- struct math_emu_info info = { };
-
- cond_local_irq_enable(regs);
-
- info.regs = regs;
- math_emulate(&info);
-
- cond_local_irq_disable(regs);
- return;
- }
-#endif
-
/* This should not happen. */
if (WARN(cr0 & X86_CR0_TS, "CR0.TS was set")) {
/* Try to fix it up and carry on. */
--
2.51.0