From: Helge Deller <deller@kernel.org>
To: qemu-devel@nongnu.org
Cc: "Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
qemu-s390x@nongnu.org,
"Richard Henderson" <richard.henderson@linaro.org>,
"Eric Farman" <farman@linux.ibm.com>,
"Matthew Rosato" <mjrosato@linux.ibm.com>,
"Helge Deller" <deller@gmx.de>,
"Aleksandar Rikalo" <arikalo@gmail.com>,
"David Hildenbrand" <david@kernel.org>,
"Laurent Vivier" <laurent@vivier.eu>,
"Cornelia Huck" <cohuck@redhat.com>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Yoshinori Sato" <yoshinori.sato@nifty.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Ilya Leoshkevich" <iii@linux.ibm.com>,
"Aurelien Jarno" <aurelien@aurel32.net>
Subject: [PULL 02/12] linux-user/mips: save/restore FCSR across signal delivery
Date: Tue, 26 May 2026 22:01:57 +0200 [thread overview]
Message-ID: <20260526200207.79738-3-deller@kernel.org> (raw)
In-Reply-To: <20260526200207.79738-1-deller@kernel.org>
From: Matt Turner <mattst88@gmail.com>
QEMU keeps the MIPS FPU control/status register (FCSR, fcr31) in
env->active_fpu.fcr31. The rounding mode, flush-to-zero (FS), and
NaN-2008 mode bits in fcr31 are reflected into the derived
env->active_fpu.fp_status via set_float_rounding_mode() and friends;
every architectural write to FCSR goes through helper_ctc1() which
calls restore_fp_status() to keep the two in sync.
Both target_sigcontext variants (O32 and N32/N64) have an sc_fpc_csr
field that holds FCSR, but setup_sigcontext() never wrote it and
restore_sigcontext() never read it. As a result:
- The signal frame always delivered sc_fpc_csr == 0 to the handler,
so sigaction(SA_SIGINFO) handlers that inspect the interrupted
context see the wrong FCSR.
- On sigreturn, active_fpu.fcr31 retained whatever value the signal
handler last installed (if any), and active_fpu.fp_status was
never resynced. Interrupted code resumed with the wrong rounding
mode, FS flag, and NaN-2008 semantics.
Fix setup_sigcontext() to save fcr31 into sc_fpc_csr. Fix
restore_sigcontext() to read it back (masked to fcr31_rw_bitmask as
the kernel does) and call cpu_mips_restore_fp_status() to resync
fp_status from the restored fcr31.
Add cpu_mips_restore_fp_status() in target/mips/fpu.c (which already
defines ieee_rm and includes fpu_helper.h), and declare it in cpu.h.
Fixes: 084d0497a0 ("mips-linux-user: Save and restore fpu and dsp from sigcontext")
Cc: qemu-stable@nongnu.org
Signed-off-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Helge Deller <deller@gmx.de>
---
linux-user/mips/signal.c | 7 +++++++
target/mips/cpu.h | 3 +++
target/mips/fpu.c | 5 +++++
3 files changed, 15 insertions(+)
diff --git a/linux-user/mips/signal.c b/linux-user/mips/signal.c
index d69a5d73dd..1b10012726 100644
--- a/linux-user/mips/signal.c
+++ b/linux-user/mips/signal.c
@@ -134,6 +134,7 @@ static inline void setup_sigcontext(CPUMIPSState *regs,
for (i = 0; i < 32; ++i) {
__put_user(regs->active_fpu.fpr[i].d, &sc->sc_fpregs[i]);
}
+ __put_user(regs->active_fpu.fcr31, &sc->sc_fpc_csr);
}
static inline void
@@ -165,6 +166,12 @@ restore_sigcontext(CPUMIPSState *regs, struct target_sigcontext *sc)
for (i = 0; i < 32; ++i) {
__get_user(regs->active_fpu.fpr[i].d, &sc->sc_fpregs[i]);
}
+ {
+ uint32_t fcr31;
+ __get_user(fcr31, &sc->sc_fpc_csr);
+ regs->active_fpu.fcr31 = fcr31 & regs->active_fpu.fcr31_rw_bitmask;
+ cpu_mips_restore_fp_status(regs);
+ }
}
/*
diff --git a/target/mips/cpu.h b/target/mips/cpu.h
index 346713705a..392406aff8 100644
--- a/target/mips/cpu.h
+++ b/target/mips/cpu.h
@@ -1384,6 +1384,9 @@ void cpu_mips_clock_init(MIPSCPU *cpu);
/* helper.c */
target_ulong exception_resume_pc(CPUMIPSState *env);
+/* fpu.c */
+void cpu_mips_restore_fp_status(CPUMIPSState *env);
+
/**
* mips_cpu_create_with_clock:
* @typename: a MIPS CPU type.
diff --git a/target/mips/fpu.c b/target/mips/fpu.c
index c7c487c1f9..8b661865ca 100644
--- a/target/mips/fpu.c
+++ b/target/mips/fpu.c
@@ -17,6 +17,11 @@ const FloatRoundMode ieee_rm[4] = {
float_round_down
};
+void cpu_mips_restore_fp_status(CPUMIPSState *env)
+{
+ restore_fp_status(env);
+}
+
const char fregnames[32][4] = {
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
--
2.54.0
next prev parent reply other threads:[~2026-05-26 20:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 20:01 [PULL 00/12] Linux user next patches Helge Deller
2026-05-26 20:01 ` [PULL 01/12] linux-user/ppc: restore fp_status from FPSCR on sigreturn Helge Deller
2026-05-26 20:01 ` Helge Deller [this message]
2026-05-26 20:01 ` [PULL 03/12] linux-user/alpha: add coredump support Helge Deller
2026-05-27 16:26 ` Richard Henderson
2026-05-26 20:01 ` [PULL 04/12] linux-user/sh4: preserve T/M/Q bits across signal delivery Helge Deller
2026-05-26 20:02 ` [PULL 05/12] linux-user/sh4: restore FP rounding mode on sigreturn Helge Deller
2026-05-26 20:02 ` [PULL 06/12] target/sh4: sync fp_status when gdb writes FPSCR Helge Deller
2026-05-26 20:02 ` [PULL 07/12] linux-user/s390x: restore fpu_status rounding mode from FPC on sigreturn Helge Deller
2026-05-26 20:02 ` [PULL 08/12] linux-user: Implement finer grained madivse() syscall Helge Deller
2026-05-26 20:02 ` [PULL 09/12] linux-user: Fix typo in function documentation for pgb_addr_set() Helge Deller
2026-05-26 20:02 ` [PULL 10/12] linux-user: Fix loading static ARM cortex-m55 binaries Helge Deller
2026-05-26 20:02 ` [PULL 11/12] linux-user: Move init_main_thread() prototype to user-internals.h Helge Deller
2026-05-26 20:02 ` [PULL 12/12] linux-user: Move cpu_copy() " Helge Deller
2026-05-27 11:41 ` [PULL 00/12] Linux user next patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260526200207.79738-3-deller@kernel.org \
--to=deller@kernel.org \
--cc=arikalo@gmail.com \
--cc=aurelien@aurel32.net \
--cc=cohuck@redhat.com \
--cc=david@kernel.org \
--cc=deller@gmx.de \
--cc=farman@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=jiaxun.yang@flygoat.com \
--cc=laurent@vivier.eu \
--cc=mjrosato@linux.ibm.com \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=yoshinori.sato@nifty.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.