OSDN Git Service

UPSTREAM: MIPS: Fix FCSR Cause bit handling for correct SIGFPE issue
authorMaciej W. Rozycki <macro@imgtec.com>
Fri, 28 Oct 2016 07:21:03 +0000 (08:21 +0100)
committerGreg Kroah-Hartman <gregkh@google.com>
Mon, 5 Feb 2018 16:58:31 +0000 (08:58 -0800)
commitfb0c12e677a335c99b7b2a2f72f6fc8ede79ad14
tree36bfe4c67bfa82c109d7c524807ba69dfdbe2e4d
parent1c7d67bedb0d84d045f5788536a9ca835f1768e8
UPSTREAM: MIPS: Fix FCSR Cause bit handling for correct SIGFPE issue

Sanitize FCSR Cause bit handling, following a trail of past attempts:

* commit 4249548454f7 ("MIPS: ptrace: Fix FP context restoration FCSR
regression"),

* commit 443c44032a54 ("MIPS: Always clear FCSR cause bits after
emulation"),

* commit 64bedffe4968 ("MIPS: Clear [MSA]FPE CSR.Cause after
notify_die()"),

* commit b1442d39fac2 ("MIPS: Prevent user from setting FCSR cause
bits"),

* commit b54d2901517d ("Properly handle branch delay slots in connection
with signals.").

Specifically do not mask these bits out in ptrace(2) processing and send
a SIGFPE signal instead whenever a matching pair of an FCSR Cause and
Enable bit is seen as execution of an affected context is about to
resume.  Only then clear Cause bits, and even then do not clear any bits
that are set but masked with the respective Enable bits.  Adjust Cause
bit clearing throughout code likewise, except within the FPU emulator
proper where they are set according to IEEE 754 exceptions raised as the
operation emulated executed.  Do so so that any IEEE 754 exceptions
subject to their default handling are recorded like with operations
executed by FPU hardware.

Signed-off-by: Maciej W. Rozycki <macro@imgtec.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/14460/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
(cherry picked from commit 5a1aca4469fdccd5b74ba0b4e490173b2b447895)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
arch/mips/include/asm/fpu_emulator.h
arch/mips/include/asm/switch_to.h
arch/mips/kernel/mips-r2-to-r6-emul.c
arch/mips/kernel/ptrace.c
arch/mips/kernel/traps.c