All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] linux-user/sh4: Fix crashes on signal delivery in conditional delay slot
@ 2026-08-03 19:38 Mikulas Patocka
  2026-08-04  9:27 ` yoshinori.sato
  0 siblings, 1 reply; 2+ messages in thread
From: Mikulas Patocka @ 2026-08-03 19:38 UTC (permalink / raw)
  To: Yoshinori Sato, Richard Henderson; +Cc: qemu-devel

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>

---
 linux-user/sh4/signal.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: qemu/linux-user/sh4/signal.c
===================================================================
--- qemu.orig/linux-user/sh4/signal.c	2026-08-02 18:02:30.000000000 +0200
+++ qemu/linux-user/sh4/signal.c	2026-08-02 18:03:09.000000000 +0200
@@ -109,7 +109,7 @@ static void unwind_gusa(CPUSH4State *reg
            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;
     }



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

* Re: [PATCH] linux-user/sh4: Fix crashes on signal delivery in conditional delay slot
  2026-08-03 19:38 [PATCH] linux-user/sh4: Fix crashes on signal delivery in conditional delay slot Mikulas Patocka
@ 2026-08-04  9:27 ` yoshinori.sato
  0 siblings, 0 replies; 2+ messages in thread
From: yoshinori.sato @ 2026-08-04  9:27 UTC (permalink / raw)
  To: Mikulas Patocka; +Cc: Richard Henderson, qemu-devel

On Tue, 04 Aug 2026 04:38:32 +0900,
Mikulas Patocka wrote:
> 
> 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>
> 
> ---
>  linux-user/sh4/signal.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Index: qemu/linux-user/sh4/signal.c
> ===================================================================
> --- qemu.orig/linux-user/sh4/signal.c	2026-08-02 18:02:30.000000000 +0200
> +++ qemu/linux-user/sh4/signal.c	2026-08-02 18:03:09.000000000 +0200
> @@ -109,7 +109,7 @@ static void unwind_gusa(CPUSH4State *reg
>             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;
>      }
> 

Reviewed-by: Yoshinori Sato <yoshinori.sato@nifty.com>

-- 
Yosinori Sato


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

end of thread, other threads:[~2026-08-04  9:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03 19:38 [PATCH] linux-user/sh4: Fix crashes on signal delivery in conditional delay slot Mikulas Patocka
2026-08-04  9:27 ` yoshinori.sato

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.