All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Michael Roth" <michael.roth@amd.com>,
	"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Dr. David Alan Gilbert" <dave@treblig.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
	"Eric Blake" <eblake@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>
Subject: [PATCH 13/21] system: enable crash dumps on SIGSEGV, SIGILL, SIGFPE and SIGABRT
Date: Thu, 15 Oct 2026 12:20:36 +0100	[thread overview]
Message-ID: <20261015112044.1999748-14-berrange@redhat.com> (raw)
In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com>

Expand the current SIGBUS crash dumps onto further signals that
represent program crashes from bad code or guest OS behaviour.
This change covers Windows platforms too, by using the dummy
siginfo struct definition from osdeup.h.

Note that the signal handler gets unregistered before trying the
crash dump, so in the unlikely event that crash dump itself crashes,
QEMU will exit, rather than getting into a loop.

In a debugger we'll still see the full stack history of the original
flaw, just with one extra frame present for the signal handler.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 system/signal.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/system/signal.c b/system/signal.c
index 615704900bc..4568ded4cdd 100644
--- a/system/signal.c
+++ b/system/signal.c
@@ -56,11 +56,11 @@ static void sig_handler(int n, siginfo_t *siginfo, void *ctx)
 
     memset(&action, 0, sizeof(action));
     action.sa_handler = SIG_DFL;
-    assert(sigaction(SIGBUS, &action, NULL) == 0);
+    assert(sigaction(siginfo->si_signo, &action, NULL) == 0);
     qtldr_crash_dump_signal(siginfo);
-    raise(SIGBUS);
+    raise(siginfo->si_signo);
     sigemptyset(&set);
-    sigaddset(&set, SIGBUS);
+    sigaddset(&set, siginfo->si_signo);
     pthread_sigmask(SIG_UNBLOCK, &set, NULL);
 }
 
@@ -108,10 +108,13 @@ void qemu_init_crash_signals(void)
      */
     memset(&action, 0, sizeof(action));
     action.sa_flags = SA_SIGINFO | SA_ONSTACK;
+    action.sa_sigaction = sig_handler;
+    sigaction(SIGSEGV, &action, NULL);
+    sigaction(SIGABRT, &action, NULL);
+    sigaction(SIGILL, &action, NULL);
+    sigaction(SIGFPE, &action, NULL);
 #ifdef CONFIG_LINUX
     action.sa_sigaction = sigbus_handler;
-#else
-    action.sa_sigaction = sig_handler;
 #endif
     sigaction(SIGBUS, &action, NULL);
 
@@ -120,7 +123,27 @@ void qemu_init_crash_signals(void)
 #endif
 }
 #else /* !CONFIG_SIGACTION */
+
+static void sig_handler(int signo)
+{
+    siginfo_t si = {
+        .si_signo = signo,
+        .si_code = 0,
+        .si_addr = 0x0,
+    };
+    assert(signal(signo, SIG_DFL) == 0);
+    qtldr_crash_dump_signal(&si);
+    raise(signo);
+}
+
 void qemu_init_crash_signals(void)
 {
+#ifndef WIN32
+    signal(SIGBUS, sig_handler);
+#endif
+    signal(SIGSEGV, sig_handler);
+    signal(SIGABRT, sig_handler);
+    signal(SIGILL, sig_handler);
+    signal(SIGFPE, sig_handler);
 }
 #endif /* !CONFIG_SIGACTION */
-- 
2.56.0



  parent reply	other threads:[~2026-10-15 11:22 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 11:20 [PATCH 00/21] system: introduce a live data recorder facility Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 01/21] osdep: add 'ignore_value(x)' macro Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 02/21] system: move SIGBUS signal handling to signal.c Daniel P. Berrangé
2026-10-15 12:15   ` marcandre.lureau
2026-10-15 11:20 ` [PATCH 03/21] system: rename qemu_init_sigbus to qemu_init_crash_signals Daniel P. Berrangé
2026-10-15 12:15   ` marcandre.lureau
2026-10-15 11:20 ` [PATCH 04/21] system: run SIGBUS handler on alternate signal stack Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 05/21] util: expand alternate signal stack to all threads Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 06/21] osdep: provide dummy siginfo_t definition Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 07/21] util: introduce 'tldr', a system data recorder for crash handling Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 08/21] qapi: add 'tldr-dump' command for on-demand data recorder output Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 09/21] system: trigger TLDR crash dump on unhandled SIGBUS Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 10/21] system: simplify signal handler logic Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 11/21] main: allow SIGBUS in the main loop Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 12/21] system: enable SIGBUS handling on non-Linux platforms Daniel P. Berrangé
2026-10-15 11:20 ` Daniel P. Berrangé [this message]
2026-10-15 11:20 ` [PATCH 14/21] util: introduce capture of textual messages in data recorder Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 15/21] util: capture warnings and errors in the " Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 16/21] monitor: remove obsolete/redundant exports Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 17/21] monitor: capture monitor commands and events in data recorder Daniel P. Berrangé
2026-10-15 15:57   ` Dr. David Alan Gilbert
2026-10-15 16:11     ` Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 18/21] log: enable directing log messages to " Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 19/21] tests/qtest: add API to declare an expected crash signal Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 20/21] qtest: add 'crash' command to generate 'authentic' process crashes Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 21/21] tests/qtest: add test to validate data recorder on crashes Daniel P. Berrangé
2026-10-15 12:15 ` [PATCH 00/21] system: introduce a live data recorder facility marcandre.lureau
2026-10-15 12:32   ` Daniel P. Berrangé
2026-10-15 17:34 ` Pierrick Bouvier

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=20261015112044.1999748-14-berrange@redhat.com \
    --to=berrange@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dave@treblig.org \
    --cc=eblake@redhat.com \
    --cc=farosas@suse.de \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@oss.qualcomm.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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 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.