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 05/12] linux-user/sh4: restore FP rounding mode on sigreturn
Date: Tue, 26 May 2026 22:02:00 +0200 [thread overview]
Message-ID: <20260526200207.79738-6-deller@kernel.org> (raw)
In-Reply-To: <20260526200207.79738-1-deller@kernel.org>
From: Matt Turner <mattst88@gmail.com>
The SH4 FPSCR rounding-mode (RM) and denormal (DN) bits are not held
only in env->fpscr: they are also reflected into the derived
env->fp_status via set_float_rounding_mode()/set_flush_to_zero(). The
guest keeps the two in sync by routing every write to FPSCR through
helper_ld_fpscr().
restore_sigcontext() wrote the saved value straight into env->fpscr and
never touched env->fp_status, so on sigreturn the interrupted code
resumed with whatever FP rounding mode and flush-to-zero setting the
signal handler last installed. (regs->flags = 0 forces the FR/SZ/PR TB
flags to be recomputed, but fp_status is runtime float state, not a TB
flag, so it was left stale.) This is the FP analogue of the T/M/Q bit
problem just fixed for the integer status register.
Factor the FPSCR -> fp_status synchronisation out of helper_ld_fpscr()
into cpu_load_fpscr() and use it from restore_sigcontext() so the
rounding mode round-trips correctly across signal delivery.
Fixes: c3b5bc8ab3 ("SH4: Signal handling for the user space emulator, by Magnus Damm.")
Cc: qemu-stable@nongnu.org
Reviewed-by: Yoshinori Sato <yoshinori.sato@nifty.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Helge Deller <deller@gmx.de>
---
linux-user/sh4/signal.c | 7 ++++++-
target/sh4/cpu.h | 3 +++
target/sh4/op_helper.c | 7 ++++++-
3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/linux-user/sh4/signal.c b/linux-user/sh4/signal.c
index cc36425c49..00290d6e40 100644
--- a/linux-user/sh4/signal.c
+++ b/linux-user/sh4/signal.c
@@ -173,7 +173,12 @@ static void restore_sigcontext(CPUSH4State *regs, struct target_sigcontext *sc)
for (i=0; i<16; i++) {
__get_user(regs->fregs[i], &sc->sc_fpregs[i]);
}
- __get_user(regs->fpscr, &sc->sc_fpscr);
+ /* Resync the derived float_status state, not just env->fpscr. */
+ {
+ uint32_t fpscr;
+ __get_user(fpscr, &sc->sc_fpscr);
+ cpu_load_fpscr(regs, fpscr);
+ }
__get_user(regs->fpul, &sc->sc_fpul);
regs->tra = -1; /* disable syscall checks */
diff --git a/target/sh4/cpu.h b/target/sh4/cpu.h
index 4b0f3f6d97..3302702376 100644
--- a/target/sh4/cpu.h
+++ b/target/sh4/cpu.h
@@ -379,4 +379,7 @@ static inline void cpu_write_sr(CPUSH4State *env, uint32_t sr)
env->sr = sr & ~((1u << SR_M) | (1u << SR_Q) | (1u << SR_T));
}
+/* Set FPSCR and the derived float_status rounding/flush-to-zero state. */
+void cpu_load_fpscr(CPUSH4State *env, uint32_t val);
+
#endif /* SH4_CPU_H */
diff --git a/target/sh4/op_helper.c b/target/sh4/op_helper.c
index 669bc84cb6..cf0f80e4a5 100644
--- a/target/sh4/op_helper.c
+++ b/target/sh4/op_helper.c
@@ -204,7 +204,7 @@ void helper_macw(CPUSH4State *env, int32_t arg0, int32_t arg1)
}
}
-void helper_ld_fpscr(CPUSH4State *env, uint32_t val)
+void cpu_load_fpscr(CPUSH4State *env, uint32_t val)
{
env->fpscr = val & FPSCR_MASK;
if ((val & FPSCR_RM_MASK) == FPSCR_RM_ZERO) {
@@ -215,6 +215,11 @@ void helper_ld_fpscr(CPUSH4State *env, uint32_t val)
set_flush_to_zero((val & FPSCR_DN) != 0, &env->fp_status);
}
+void helper_ld_fpscr(CPUSH4State *env, uint32_t val)
+{
+ cpu_load_fpscr(env, val);
+}
+
static void update_fpscr(CPUSH4State *env, uintptr_t retaddr)
{
int xcpt, cause, enable;
--
2.54.0
next prev parent reply other threads:[~2026-05-26 20:05 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 ` [PULL 02/12] linux-user/mips: save/restore FCSR across signal delivery Helge Deller
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 ` Helge Deller [this message]
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-6-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.