All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/3] Linux user patches
@ 2026-08-07 13:26 Helge Deller
  2026-08-07 13:26 ` [PULL 1/3] linux-user/sh4: Deliver SIGILL on invalid instruction Helge Deller
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Helge Deller @ 2026-08-07 13:26 UTC (permalink / raw)
  To: qemu-devel, Stefan Hajnoczi
  Cc: Pierrick Bouvier, deller, Laurent Vivier, Mikulas Patocka

From: Helge Deller <deller@gmx.de>

The following changes since commit 3e3ccab106f879b1512f8e0d51a827dd4de30e22:

  Update version for v11.1.0-rc3 release (2026-08-04 15:36:08 -0400)

are available in the Git repository at:

  https://github.com/hdeller/qemu-hppa.git tags/linux-user-pull-request

for you to fetch changes up to f7ad7b1f8c8148f39bc1f2c984bfc7b7c9c59041:

  linux-user/sh4: Fix crashes on signal delivery in conditional delay slot (2026-08-07 15:13:36 +0200)

----------------------------------------------------------------
linux-user sh4 signal patches

Three important small signal handling fixes for the sh4 architecture from
Mikulas Patocka.

----------------------------------------------------------------

Mikulas Patocka (3):
  linux-user/sh4: Deliver SIGILL on invalid instruction
  linux-user/sh4: Initialize the FPSCR register on signal
  linux-user/sh4: Fix crashes on signal delivery in conditional delay
    slot

 linux-user/sh4/cpu_loop.c | 7 +++++++
 linux-user/sh4/signal.c   | 6 +++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

-- 
2.54.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PULL 1/3] linux-user/sh4: Deliver SIGILL on invalid instruction
  2026-08-07 13:26 [PULL 0/3] Linux user patches Helge Deller
@ 2026-08-07 13:26 ` Helge Deller
  2026-08-07 13:26 ` [PULL 2/3] linux-user/sh4: Initialize the FPSCR register on signal Helge Deller
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Helge Deller @ 2026-08-07 13:26 UTC (permalink / raw)
  To: qemu-devel, Stefan Hajnoczi
  Cc: Pierrick Bouvier, deller, Laurent Vivier, Mikulas Patocka,
	Yoshinori Sato, Richard Henderson

From: Mikulas Patocka <mpatocka@redhat.com>

On invalid instruction, deliver SIGILL rather than crashing the whole
process unconditionally.

Cc: qemu-stable@nongnu.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Reviewed-by: Yoshinori Sato <yoshinori.sato@nifty.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/sh4/cpu_loop.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/linux-user/sh4/cpu_loop.c b/linux-user/sh4/cpu_loop.c
index ee2958d0d9..0815b9c9bf 100644
--- a/linux-user/sh4/cpu_loop.c
+++ b/linux-user/sh4/cpu_loop.c
@@ -64,6 +64,13 @@ void cpu_loop(CPUSH4State *env)
             cpu_exec_step_atomic(cs);
             arch_interrupt = false;
             break;
+        case 0x180:
+            /* Illegal instruction */
+            /* fallthrough */
+        case 0x1a0:
+            /* Illegal instruction in delay slot */
+            force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc);
+            break;
         default:
             fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
             cpu_dump_state(cs, stderr, 0);
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PULL 2/3] linux-user/sh4: Initialize the FPSCR register on signal
  2026-08-07 13:26 [PULL 0/3] Linux user patches Helge Deller
  2026-08-07 13:26 ` [PULL 1/3] linux-user/sh4: Deliver SIGILL on invalid instruction Helge Deller
@ 2026-08-07 13:26 ` Helge Deller
  2026-08-07 13:26 ` [PULL 3/3] linux-user/sh4: Fix crashes on signal delivery in conditional delay slot Helge Deller
  2026-08-11 21:37 ` [PULL 0/3] Linux user patches Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Helge Deller @ 2026-08-07 13:26 UTC (permalink / raw)
  To: qemu-devel, Stefan Hajnoczi
  Cc: Pierrick Bouvier, deller, Laurent Vivier, Mikulas Patocka,
	Yoshinori Sato

From: Mikulas Patocka <mpatocka@redhat.com>

On the SH4 architecture, the instructions that perform single precision
and double precision floating point operations are encoded in the same
way. The bit PR in the FPSCR register determines if the CPU performs
single or double operation.

According to the ABI, the PR bit must be set at function entry and
function exit.

GCC generates code that flips this bit as needed during function
execution. If we get a signal, we must set the PR bit, so that the signal
handler finds the bit in the expected state. Qemu lacked this logic, so
that if the signal interrupts single-precision floating point
calculation, the PR bit would be incorrectly clear at signal handler
entry. If the signal handler performed some floating-point calculation,
it would get incorrect result.

This patch fixes the bug, by initializing the FPSCR register at signal
entry. Note that we initialize the whole register, because the Linux
kernel initializes the whole register too.

Cc: qemu-stable@nongnu.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Reviewed-by: Yoshinori Sato <yoshinori.sato@nifty.com>
Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/sh4/signal.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/linux-user/sh4/signal.c b/linux-user/sh4/signal.c
index 00290d6e40..7f246e750d 100644
--- a/linux-user/sh4/signal.c
+++ b/linux-user/sh4/signal.c
@@ -206,6 +206,8 @@ void setup_frame(int sig, struct target_sigaction *ka,
         __put_user(set->sig[i + 1], &frame->extramask[i]);
     }
 
+    regs->fpscr = FPSCR_PR;
+
     /* Set up to return from userspace.  If provided, use a stub
        already in userspace.  */
     if (ka->sa_flags & TARGET_SA_RESTORER) {
@@ -258,6 +260,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
         __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
     }
 
+    regs->fpscr = FPSCR_PR;
+
     /* Set up to return from userspace.  If provided, use a stub
        already in userspace.  */
     if (ka->sa_flags & TARGET_SA_RESTORER) {
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PULL 3/3] linux-user/sh4: Fix crashes on signal delivery in conditional delay slot
  2026-08-07 13:26 [PULL 0/3] Linux user patches Helge Deller
  2026-08-07 13:26 ` [PULL 1/3] linux-user/sh4: Deliver SIGILL on invalid instruction Helge Deller
  2026-08-07 13:26 ` [PULL 2/3] linux-user/sh4: Initialize the FPSCR register on signal Helge Deller
@ 2026-08-07 13:26 ` Helge Deller
  2026-08-11 21:37 ` [PULL 0/3] Linux user patches Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Helge Deller @ 2026-08-07 13:26 UTC (permalink / raw)
  To: qemu-devel, Stefan Hajnoczi
  Cc: Pierrick Bouvier, deller, Laurent Vivier, Mikulas Patocka,
	Yoshinori Sato

From: Mikulas Patocka <mpatocka@redhat.com>

If we get a signal in the delay slot, we must roll-back the PC to the
jump instruction. This was already fixed by the commit 3b894b699c9a
("linux-user/sh4: Fix crashes on signal delivery"), however this fix
omits a test for TB_FLAG_DELAY_SLOT_COND. TB_FLAG_DELAY_SLOT_COND is set
by the conditional delayed branches bf/s and bt/s. Qemu did not roll-back
the PC in this case, resulting in incorrect program execution.

This patch fixes it.

Cc: qemu-stable@nongnu.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Reviewed-by: Yoshinori Sato <yoshinori.sato@nifty.com>
Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/sh4/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/sh4/signal.c b/linux-user/sh4/signal.c
index 7f246e750d..047174ac8f 100644
--- a/linux-user/sh4/signal.c
+++ b/linux-user/sh4/signal.c
@@ -109,7 +109,7 @@ static void unwind_gusa(CPUSH4State *regs)
            the SP, otherwise we would be pushing the signal context to
            invalid memory.  */
         regs->gregs[15] = regs->gregs[1];
-    } else if (regs->flags & TB_FLAG_DELAY_SLOT) {
+    } else if (regs->flags & (TB_FLAG_DELAY_SLOT | TB_FLAG_DELAY_SLOT_COND)) {
         /* If we are in a delay slot, push the previous instruction.  */
         regs->pc -= 2;
     }
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PULL 0/3] Linux user patches
  2026-08-07 13:26 [PULL 0/3] Linux user patches Helge Deller
                   ` (2 preceding siblings ...)
  2026-08-07 13:26 ` [PULL 3/3] linux-user/sh4: Fix crashes on signal delivery in conditional delay slot Helge Deller
@ 2026-08-11 21:37 ` Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2026-08-11 21:37 UTC (permalink / raw)
  To: Helge Deller
  Cc: qemu-devel, Stefan Hajnoczi, Pierrick Bouvier, deller,
	Laurent Vivier, Mikulas Patocka

[-- Attachment #1: Type: text/plain, Size: 116 bytes --]

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/11.2 for any user-visible changes.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-11 21:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07 13:26 [PULL 0/3] Linux user patches Helge Deller
2026-08-07 13:26 ` [PULL 1/3] linux-user/sh4: Deliver SIGILL on invalid instruction Helge Deller
2026-08-07 13:26 ` [PULL 2/3] linux-user/sh4: Initialize the FPSCR register on signal Helge Deller
2026-08-07 13:26 ` [PULL 3/3] linux-user/sh4: Fix crashes on signal delivery in conditional delay slot Helge Deller
2026-08-11 21:37 ` [PULL 0/3] Linux user patches Stefan Hajnoczi

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.