public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
From: Warner Losh <imp@bsdimp.com>
To: Nicholas Piggin <npiggin@gmail.com>
Cc: qemu-devel@nongnu.org, "Kyle Evans" <kevans@freebsd.org>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Peter Maydell" <peter.maydell@linaro.org>
Subject: Re: [PATCH 2/3] bsd-user, linux-user: signal: recursive signal delivery fix
Date: Sat, 21 Mar 2026 09:51:24 -0600	[thread overview]
Message-ID: <CANCZdfoOwgUJZP3Do4Vgj5cN_NRK2_cacorK8LXKjZ=TbBdCsQ@mail.gmail.com> (raw)
In-Reply-To: <20260321135624.581398-3-npiggin@gmail.com>

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

On Sat, Mar 21, 2026 at 7:56 AM Nicholas Piggin <npiggin@gmail.com> wrote:

> Synchronous signals must accommodate a synchronous signal being
> raised during delivery, as asynchronous ones do. For example
> badframe errors during delivery will cause SIGSEGV to be raised.
>
> Without this fix, cpu_loop() runs process_pending_signals() which
> delivers the first synchronous signal (e.g., SIGILL) which fails
> to set the handler and forces SIGSEGV, but that is not picked up.
> process_pending_signals() returns. Then cpu_loop() runs cpu_exec()
> again, which attempts to execute the same instruction, another
> SIGILL.
>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>  bsd-user/signal.c   | 10 ++++++----
>  linux-user/signal.c |  9 ++++++---
>  2 files changed, 12 insertions(+), 7 deletions(-)
>

Reviewed-by: Warner Losh <imp@bsdimp.com>

Interesting edge case...

Warner


> diff --git a/bsd-user/signal.c b/bsd-user/signal.c
> index dadcc037dc..3e5e41e1b1 100644
> --- a/bsd-user/signal.c
> +++ b/bsd-user/signal.c
> @@ -998,7 +998,12 @@ void process_pending_signals(CPUArchState *env)
>                  sigdelset(&ts->signal_mask, target_to_host_signal(sig));
>                  sigact_table[sig - 1]._sa_handler = TARGET_SIG_DFL;
>              }
> +            /*
> +             * Restart scan from the beginning, as handle_pending_signal
> +             * might have resulted in a new synchronous signal (eg
> SIGSEGV).
> +             */
>              handle_pending_signal(env, sig, &ts->sync_signal);
> +            goto restart_scan;
>          }
>
>          k = ts->sigtab;
> @@ -1008,10 +1013,7 @@ void process_pending_signals(CPUArchState *env)
>              if (k->pending &&
>                  !sigismember(blocked_set, target_to_host_signal(sig))) {
>                  handle_pending_signal(env, sig, k);
> -                /*
> -                 * Restart scan from the beginning, as
> handle_pending_signal
> -                 * might have resulted in a new synchronous signal (eg
> SIGSEGV).
> -                 */
> +                /* Restart scan, explained above. */
>                  goto restart_scan;
>              }
>          }
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index e4b8b28bfe..9d43e080ce 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -1385,6 +1385,11 @@ void process_pending_signals(CPUArchState *cpu_env)
>              }
>
>              handle_pending_signal(cpu_env, sig, &ts->sync_signal);
> +            /*
> +             * Restart scan from the beginning, as handle_pending_signal
> +             * might have resulted in a new synchronous signal (eg
> SIGSEGV).
> +             */
> +            goto restart_scan;
>          }
>
>          for (sig = 1; sig <= TARGET_NSIG; sig++) {
> @@ -1395,9 +1400,7 @@ void process_pending_signals(CPUArchState *cpu_env)
>                  (!sigismember(blocked_set,
>                                target_to_host_signal_table[sig]))) {
>                  handle_pending_signal(cpu_env, sig, &ts->sigtab[sig - 1]);
> -                /* Restart scan from the beginning, as
> handle_pending_signal
> -                 * might have resulted in a new synchronous signal (eg
> SIGSEGV).
> -                 */
> +                /* Restart scan, explained above. */
>                  goto restart_scan;
>              }
>          }
> --
> 2.51.0
>
>

[-- Attachment #2: Type: text/html, Size: 4626 bytes --]

  reply	other threads:[~2026-03-21 15:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-21 13:56 [PATCH 0/3] user: recursive signal delivery fix and test Nicholas Piggin
2026-03-21 13:56 ` [PATCH 1/3] linux-user: sigaltstack lock_user_struct missing unlock Nicholas Piggin
2026-03-21 13:56 ` [PATCH 2/3] bsd-user, linux-user: signal: recursive signal delivery fix Nicholas Piggin
2026-03-21 15:51   ` Warner Losh [this message]
2026-03-21 13:56 ` [PATCH 3/3] tests/tcg: add recursive signal delivery tests Nicholas Piggin

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='CANCZdfoOwgUJZP3Do4Vgj5cN_NRK2_cacorK8LXKjZ=TbBdCsQ@mail.gmail.com' \
    --to=imp@bsdimp.com \
    --cc=alex.bennee@linaro.org \
    --cc=kevans@freebsd.org \
    --cc=laurent@vivier.eu \
    --cc=npiggin@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox