[PATCH] MIPS: Mask FCSR Cause bits in native do_fpe() path
From: Shirong Qu
Date: Sun Nov 29 2026 - 15:32:07 EST
Commit 5a1aca4469fd ("MIPS: Fix FCSR Cause bit handling for correct
SIGFPE issue") factored force_fcr31_sig() out of process_fpemu_return()
and moved the Cause-against-Enable masking to its callers via
mask_fcr31_x(), but missed the native FPE else branch in do_fpe().
On MIPS, hardware FPU instructions update the FCSR Cause bits for all
exceptions raised by the instruction regardless of the Enable bits, and
trap when any enabled Cause bit is set. Because force_fcr31_sig() checks
Cause bits in fixed priority order, passing the raw fcr31 can report a
masked exception instead of the enabled one that triggered the trap (for
example, enabling only FPU_CSR_INE_E and executing DBL_MAX * 2.0 sets
both Cause.O and Cause.I, reporting FPE_FLTOVF instead of FPE_FLTRES).
Mask fcr31 with mask_fcr31_x() in the native branch of do_fpe() before
passing it to process_fpemu_return().
Cc: stable@xxxxxxxxxxxxxxx
Fixes: 5a1aca4469fd ("MIPS: Fix FCSR Cause bit handling for correct SIGFPE issue")
Signed-off-by: Shirong Qu <qc_n3ep@xxxxxxxxxxx>
---
Tested on QEMU mips64el (malta, -cpu I6400) with a standalone user-space
test that enables only FPU_CSR_INE_E and evaluates DBL_MAX * 2.0: si_code
changes from FPE_FLTOVF (4) before this patch to FPE_FLTRES (6) after
this patch.
AI assistance (Gemini) was used to help locate the missed call site from
commit 5a1aca4469fd, draft the patch and changelog, and build the QEMU
test harness; the author reviewed all changes and verified the test
results.
arch/mips/kernel/traps.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 8ec1e185b35c..bf9e4f4b5aa6 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -916,6 +916,7 @@ asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
/* Restore the hardware register state */
own_fpu(1); /* Using the FPU again. */
} else {
+ fcr31 = mask_fcr31_x(fcr31);
sig = SIGFPE;
fault_addr = (void __user *) regs->cp0_epc;
}
base-commit: ca20d5a011d35fc25e328fe31ac47f7aae557c5a
--
2.56.1