Skip to contentSkip to conversation

system: introduce a live data recorder facility

PATCH In review Daniel P. Berrangé 6 participants 45 messages Oct 15 – Nov 17 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover system: introduce a live data recorder facility

This series introduces a new facility called 'tldr' which is a live data recorder. This is intended to aid support of production QEMU deployments, by providing a data collection facility that can be left "always on", such that in the event of a QEMU crash or guest OS crash, certain important information will be recorded.

The data recorder has to be enabled by adding a "tldr-config" object instance with -object / object_add.

With this series, the data recorder collects

* error_report/warn_report/error_printf messages
* QMP events
* QMP errors
* QMP commands, which are not query-XXX/qom-list, or any command associated with a QMP error.
* qemu_log output

The last item is intended primarily to be used in combination with tracing and its 'log' backend, to have continuous recording of certain interesting probes.

Each type of data is collected in a distinct circular buffer, such that high volumes of one type of data, does not result in overwriting other types of low volume data.

The data recorder is set to trigger on SIGBUS, SIGSEGV, SIGILL, SIGFPE and SIGABRT, or manually via QMP 'tldr-dump'.

There is a open question in one of the patches about SIGBUS handling, since that is already used for MCE capture and I'm unclear if I'm breaking something about KVM MCE reporting.

This series proposes using sigaltstack() to register an alternative signal handling stack. This would mainly be useful if we have a crash from a stack overflow, but the cost is that we have 8k extra per thread, and I'm not entirely convinced that's a beneficial tradeoff. Might be better to just accept stack overflows as a risk.

This series only captures text based info, but as a followup I would like to extend this to capture statistics data from relevant subsystems. For example, the BlockBackend has its own "always on" stats accounting code, which can be queried with QMP. Ideally I would like to figure out a way to dump all the BlockBackend stats in the data recorder output. Likewise perhaps capture NIC stats and/or KVM stats in an "always on" manner for some interesting baseline dataset. The challenge with that is making it safe to access the stats data without taking any mutex locks, since this must run from a signal handler.

A typical recommended usage would be:

$QEMU -object tldr-config,id=tldr
-d tldr
-trace events=/var/lib/libvirt/qemu/trace.txt

This leaves dumps to go to QEMU's stderr on crash, but to send them to a file

-object tldr-config,id=tldr,crash-target=/some/path

The '-d tldr' flag redirects qemu_log() to the TLDR buffer instead of stdout, and the '-trace events' arg defines the "always on" tracepoints we want to capture.

An example crash dump seen if I send SIGBUS to a libvirt managed QEMU is, with 'object*' tracepoints collected:

🚨🚨🚨 QEMU Data Recorder Start 🚨🚨🚨

🔍 Trigger:
- Signal: SIGBUS (7)
- Code: User process kill (0)
- Address: 0x1e5a9e

🎥 Message recording 'command':

2026-10-15T10:59:11.318427Z {"execute": "qmp_capabilities", "id": "libvirt-1"}
2026-10-15T10:59:11.322047Z {"execute": "migrate-set-capabilities", "arguments": {"capabilities": [{"state": true, "capability": "events"}]}, "id": "libvirt-3"}
2026-10-15T10:59:11.347566Z {"execute": "balloon", "arguments": {"value": 4294967296}, "id": "libvirt-9"}
2026-10-15T10:59:11.354570Z {"execute": "set-action", "arguments": {"panic": "pause"}, "id": "libvirt-12"}
2026-10-15T10:59:11.358046Z {"execute": "cont", "id": "libvirt-14"}

🎥 Message recording 'event':

2026-10-15T10:59:11.358108Z {"timestamp": {"seconds": 1792061951, "microseconds": 358094}, "event": "RESUME"}
2026-10-15T10:59:20.757392Z {"timestamp": {"seconds": 1792061960, "microseconds": 757371}, "event": "VSERPORT_CHANGE", "data": {"open": true, "id": "console1"}}
2026-10-15T10:59:24.431398Z {"timestamp": {"seconds": 1792061964, "microseconds": 431379}, "event": "NIC_RX_FILTER_CHANGED", "data": {"name": "net0", "path": "/machine/peripheral/net0/virtio-backend"}}
2026-10-15T10:59:32.586658Z {"timestamp": {"seconds": 1792061972, "microseconds": 586603}, "event": "RTC_CHANGE", "data": {"offset": 0, "qom-path": "/machine/unattached/device[12]/rtc"}}

🎥 Message recording 'log':
28:QIO_CHANNEL_FILE)

2026-10-15T10:59:31.753125Z object_dynamic_cast_assert obj=0x557d5c828780 type=chardev-pty->chardev-pty (../chardev/char-pty.c:50:PTY_CHARDEV)
2026-10-15T10:59:31.753128Z object_dynamic_cast_assert obj=0x557d5c828780 type=chardev-pty->chardev-pty (../chardev/char-pty.c:50:PTY_CHARDEV)
2026-10-15T10:59:31.796114Z object_dynamic_cast_assert obj=0x557d5ca7d3a0 type=host-x86_64-cpu->x86_64-cpu (../target/i386/cpu-qom.h:31:X86_CPU)
2026-10-15T10:59:31.796148Z object_class_dynamic_cast_assert type=kvm-apic->apic-common (/home/berrange/src/virt/qemu/include/hw/i386/apic_internal.h:131:APIC_COMMON_GET_CLASS)

...snip...

2026-10-15T10:59:33.713641Z object_dynamic_cast_assert obj=0x557d5cc20b10 type=PCIE->PCI (/home/berrange/src/virt/qemu/include/hw/pci/pci.h:289:PCI_BUS)
2026-10-15T10:59:33.713643Z object_class_dynamic_cast_assert type=PCIE->PCI (/home/berrange/src/virt/qemu/include/hw/pci/pci.h:289:PCI_BUS_GET_CLASS)
2026-10-15T10:59:33.713648Z object_dynamic_cast_assert obj=0x557d5ca03700 type=host-x86_64-cpu->x86_64-cpu (../target/i386/cpu-qom.h:31:X86_CPU)
2026-10-15T10:59:33.713664Z object_dynamic_cast_assert obj=0x557d5eadd320 type=virtio-gpu-device->virtio-device (/home/berrange/src/virt/qemu/include/hw/virtio/virtio.h:91:VIRTIO_DEVICE)

🚨🚨🚨 QEMU Data Recorder End 🚨🚨🚨

"object_*" is not a particularly good choice for 'always on' data collection as it is high volume and mostly noise. The job of identifying the "interesting" low volume tracepoints is outstanding. We can provide guidance upstream but downstream should control what they're interested in collecting. We might want to add further tracepoints in the code at interesting places that we useful for post-crash debugging.

Daniel P. Berrangé (21):
osdep: add 'ignore_value(x)' macro
system: move SIGBUS signal handling to signal.c
system: rename qemu_init_sigbus to qemu_init_crash_signals
system: run SIGBUS handler on alternate signal stack
util: expand alternate signal stack to all threads
osdep: provide dummy siginfo_t definition
util: introduce 'tldr', a system data recorder for crash handling
qapi: add 'tldr-dump' command for on-demand data recorder output
system: trigger TLDR crash dump on unhandled SIGBUS
system: simplify signal handler logic
main: allow SIGBUS in the main loop
system: enable SIGBUS handling on non-Linux platforms
system: enable crash dumps on SIGSEGV, SIGILL, SIGFPE and SIGABRT
util: introduce capture of textual messages in data recorder
util: capture warnings and errors in the data recorder
monitor: remove obsolete/redundant exports
monitor: capture monitor commands and events in data recorder
log: enable directing log messages to data recorder tests/qtest: add API to declare an expected crash signal
qtest: add 'crash' command to generate 'authentic' process crashes tests/qtest: add test to validate data recorder on crashes

 MAINTAINERS                 |  12 +
 include/qemu/log.h          |   1 +
 include/qemu/osdep.h        |  16 +
 include/qemu/tldr.h         |  76 ++++
 include/system/signal.h     |  25 ++
 meson.build                 |   4 +
 monitor/monitor-internal.h  |   2 -
 monitor/qmp.c               |  66 +++-
 qapi/meson.build            |   1 +
 qapi/qapi-schema.json       |   1 +
 qapi/qom.json               |  18 +
 qapi/tldr.json              |  62 +++
 qemu-options.hx             |  24 ++
 stubs/meson.build           |   1 +
 stubs/monitor-puts.c        |   9 +
 system/cpus.c               |  78 +---
 system/meson.build          |   1 +
 system/qtest.c              |  50 +++
 system/signal.c             | 149 +++++++
 tests/qtest/libqtest.c      |  62 ++-
 tests/qtest/libqtest.h      |  27 ++
 tests/qtest/meson.build     |   3 +
 tests/qtest/tldr-test.c     | 124 ++++++
 tests/unit/meson.build      |   1 +
 tests/unit/test-util-tldr.c | 377 ++++++++++++++++++
 util/error-report.c         |  43 ++-
 util/log.c                  |  42 +-
 util/main-loop.c            |   1 -
 util/meson.build            |   1 +
 util/qemu-thread-posix.c    |  20 +
 util/tldr-internal.h        |  52 +++
 util/tldr.c                 | 750 ++++++++++++++++++++++++++++++++++++
 32 files changed, 1976 insertions(+), 123 deletions(-)
 create mode 100644 include/qemu/tldr.h
 create mode 100644 include/system/signal.h
 create mode 100644 qapi/tldr.json
 create mode 100644 stubs/monitor-puts.c
 create mode 100644 system/signal.c
 create mode 100644 tests/qtest/tldr-test.c
 create mode 100644 tests/unit/test-util-tldr.c
 create mode 100644 util/tldr-internal.h
 create mode 100644 util/tldr.c
Signature · 1 line
2.56.0
#1 lore raw

PATCH 1/21 osdep: add 'ignore_value(x)' macro

Functions annotated with 'warn_unused_result' cannot be cast to (void) to silence the compiler. Add the ignore_value() macro which tricks the compiler into thinking the result is genuinely used, avoiding the need for manual workarounds where the return value is intentionally ignored.

This clever macro is derived from one originating with the GNULIB project:

https://gitweb.git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/ignore-value.h;hb=HEAD

but simplified since we don't need compat with old GCC and optimizing on clang is overkill.

---
 include/qemu/osdep.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/qemu/osdep.h +8 -0
index 1ec5b42230b..c1ca2c127b6 100644
@@ -251,6 +251,14 @@ extern "C" {
 #endif
 
 
+/*
+ * Merely casting to (void) is not sufficient for functions
+ * annotated with the "warn_unused_result" attribute
+ */
+#define ignore_value(x) \
+    (__extension__ ({ __typeof__(x) __x = (x); (void) __x; }))
+
+
 /*
  * For mingw, as of v6.0.0, the function implementing the assert macro is
  * not marked as noreturn, so the compiler cannot delete code following an
Signature · 1 line
2.56.0
#2 lore raw

PATCH 2/21 system: move SIGBUS signal handling to signal.c

In reply to Daniel P. Berrangé

Introduce a new file 'system/signal.c' to hold the SIGBUS signal handler, since subsequent commits are going to expand the signal handling logic somewhat.

The existing copyright header/license boilerplate is retained instead of a SPDX tag, to respect historic context.

---
 MAINTAINERS             |   2 +
 include/system/signal.h |  25 ++++++++++
 system/cpus.c           |  76 +---------------------------
 system/meson.build      |   1 +
 system/signal.c         | 107 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 136 insertions(+), 75 deletions(-)
 create mode 100644 include/system/signal.h
 create mode 100644 system/signal.c
MAINTAINERS +2 -0
index fc60193aa3f..6b5aafe43b1 100644
@@ -553,6 +553,7 @@ F: include/exec/target_long.h
 F: include/qemu/accel.h
 F: include/system/accel-*.h
 F: include/system/cpus.h
+F: include/system/signal.h
 F: include/accel/accel-*.h
 F: accel/accel-*.?
 F: accel/dummy-cpus.?
@@ -562,6 +563,7 @@ F: cpu-common.c
 F: cpu-target.c
 F: qapi/accelerator.json
 F: system/cpus.c
+F: system/signal.c
 
 Apple Silicon HVF CPUs
 M: Alexander Graf <[email protected]>
include/system/signal.h new file +25 -0
new file mode 100644
index 00000000000..f8d00221bcf
@@ -0,0 +1,25 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+void qemu_init_sigbus(void);
system/cpus.c +1 -75

92 lines not on this page · raw message

system/meson.build +1 -0
index a6ba7a04f7d..1829de3d25b 100644
@@ -24,6 +24,7 @@ system_ss.add(files(
   'rtc.c',
   'runstate-action.c',
   'runstate.c',
+  'signal.c',
   'watchpoint.c',
 ))
 
system/signal.c new file +107 -0

107 lines not on this page · raw message

Signature · 1 line
2.56.0
Reviewed-by on v1 2/21
#3 lore raw

Re: [PATCH 02/21] system: move SIGBUS signal handling to signal.c

Quoted 8 lines · Daniel P. Berrangé

Introduce a new file 'system/signal.c' to hold the SIGBUS signal handler, since subsequent commits are going to expand the signal handling logic somewhat.

The existing copyright header/license boilerplate is retained instead of a SPDX tag, to respect historic context.

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
#4 lore raw

PATCH 3/21 system: rename qemu_init_sigbus to qemu_init_crash_signals

In reply to Daniel P. Berrangé

Support for handling further crash signals will be introduced in subsequent commits, so remove 'sigbus' from the initializer function name.

---
 include/system/signal.h | 2 +-
 system/cpus.c           | 2 +-
 system/signal.c         | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
include/system/signal.h +1 -1
index f8d00221bcf..bb9b77428b1 100644
@@ -22,4 +22,4 @@
  * THE SOFTWARE.
  */
 
-void qemu_init_sigbus(void);
+void qemu_init_crash_signals(void);
system/cpus.c +1 -1
index b231ca4c4ac..870d4cfaaa3 100644
@@ -295,7 +295,7 @@ static QemuCond qemu_pause_cond;
 
 void qemu_init_cpu_loop(void)
 {
-    qemu_init_sigbus();
+    qemu_init_crash_signals();
     qemu_cond_init(&qemu_cpu_cond);
     qemu_cond_init(&qemu_pause_cond);
     qemu_mutex_init(&bql);
system/signal.c +2 -2
index 6d69db2bc79..423325c9a1a 100644
@@ -85,7 +85,7 @@ static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx)
     }
 }
 
-void qemu_init_sigbus(void)
+void qemu_init_crash_signals(void)
 {
     struct sigaction action;
 
@@ -101,7 +101,7 @@ void qemu_init_sigbus(void)
     prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0, 0);
 }
 #else /* !CONFIG_LINUX */
-void qemu_init_sigbus(void)
+void qemu_init_crash_signals(void)
 {
 }
 #endif /* !CONFIG_LINUX */
Signature · 1 line
2.56.0
Reviewed-by on v1 3/21
#5 lore raw

Re: [PATCH 03/21] system: rename qemu_init_sigbus to qemu_init_crash_signals

Quoted 3 lines · Daniel P. Berrangé

Support for handling further crash signals will be introduced in subsequent commits, so remove 'sigbus' from the initializer function name.

Signature · 1 line
Marc-André Lureau <[email protected]>
#6 lore raw

PATCH 4/21 system: run SIGBUS handler on alternate signal stack

In reply to Daniel P. Berrangé

In preparation for introducing data recorder dumps during handling of of crash signals (BUS, SEGV, ILL, FPE, ABRT), introduce an alternative signal stack. This gives a known safe stack for code to operate under.

This adds overhead of SIGSTKSZ bytes, which is OS-dependent, but on Linux is 8kb.

---
 meson.build     |  1 +
 system/signal.c | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)
meson.build +1 -0
index 255c887e8e6..b383c7fceef 100644
@@ -2647,6 +2647,7 @@ config_host_data.set('HAVE_GLIB_WITH_SLICE_ALLOCATOR', glib_has_gslice)
 config_host_data.set('HAVE_OPENPTY', cc.has_function('openpty', dependencies: util))
 config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul', prefix: osdep_prefix))
 config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix: '#include <stdlib.h>'))
+config_host_data.set('CONFIG_SIGALTSTACK', cc.has_function('sigaltstack'))
 if rbd.found()
   config_host_data.set('HAVE_RBD_NAMESPACE_EXISTS',
                        cc.has_function('rbd_namespace_exists',
system/signal.c +13 -1
index 423325c9a1a..dc5a75e2816 100644
@@ -26,6 +26,7 @@
 #include "system/signal.h"
 #include "hw/core/cpu.h"
 #include "system/kvm.h"
+#include "qemu/error-report.h"
 
 #ifdef CONFIG_LINUX
 
@@ -89,12 +90,23 @@ void qemu_init_crash_signals(void)
 {
     struct sigaction action;
 
+#ifdef CONFIG_SIGALTSTACK
+    static stack_t signal_stack;
+    signal_stack.ss_sp = (void *)g_new0(char, SIGSTKSZ);
+    signal_stack.ss_size = SIGSTKSZ;
+    if (sigaltstack(&signal_stack, NULL) < 0) {
+        error_printf("unable to enable alternate signal stack: %s",
+                     strerror(errno));
+        abort();
+    }
+#endif
+
     /*
      * ALERT: when modifying this, take care that SIGBUS forwarding in
      * qemu_prealloc_mem() will continue working as expected.
      */
     memset(&action, 0, sizeof(action));
-    action.sa_flags = SA_SIGINFO;
+    action.sa_flags = SA_SIGINFO | SA_ONSTACK;
     action.sa_sigaction = sigbus_handler;
     sigaction(SIGBUS, &action, NULL);
 
Signature · 1 line
2.56.0
#7 lore raw

PATCH 5/21 util: expand alternate signal stack to all threads

In reply to Daniel P. Berrangé

The sigaltstack() function is per thread, so setting SA_ONSTACK has no effect unless all threads have an alternate signal stack registered.

This adds overhead of SIGSTKSZ bytes per thread, which is OS-dependent, but on Linux is 8kb.

---
 util/qemu-thread-posix.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
util/qemu-thread-posix.c +20 -0
index 089606c93fb..66858018057 100644
@@ -381,12 +381,28 @@ typedef struct {
     char *name;
 } QemuThreadArgs;
 
+static void qemu_thread_sigstack_free(void *data)
+{
+    stack_t sigstack = {
+        .ss_sp = NULL,
+        .ss_size = 0,
+        .ss_flags = SS_DISABLE,
+    };
+    sigaltstack(&sigstack, NULL);
+    g_free(data);
+}
+
 static void *qemu_thread_start(void *args)
 {
     QemuThreadArgs *qemu_thread_args = args;
     void *(*start_routine)(void *) = qemu_thread_args->start_routine;
     void *arg = qemu_thread_args->arg;
     void *r;
+    stack_t sigstack = {
+        .ss_sp = g_new0(char, SIGSTKSZ),
+        .ss_size = SIGSTKSZ,
+        .ss_flags = 0,
+    };
 
     if (qemu_thread_args->name) {
         qemu_thread_set_name(qemu_thread_args->name);
@@ -395,6 +411,9 @@ static void *qemu_thread_start(void *args)
     g_free(qemu_thread_args->name);
     g_free(qemu_thread_args);
 
+    sigaltstack(&sigstack, NULL);
+    pthread_cleanup_push(qemu_thread_sigstack_free, sigstack.ss_sp);
+
     /*
      * GCC 11 with glibc 2.17 on PowerPC reports
      *
@@ -413,6 +432,7 @@ static void *qemu_thread_start(void *args)
     pthread_cleanup_push(qemu_thread_atexit_notify, NULL);
     r = start_routine(arg);
     pthread_cleanup_pop(1);
+    pthread_cleanup_pop(1);
 
 #pragma GCC diagnostic pop
 
Signature · 1 line
2.56.0
#8 lore raw

PATCH 6/21 osdep: provide dummy siginfo_t definition

In reply to Daniel P. Berrangé

Windows platforms lack sigaction and thus also lack siginfo_t. For the convenience of later code, provide a dummy siginfo_t struct definition when it is missing.

---
 include/qemu/osdep.h | 8 ++++++++
 meson.build          | 2 ++
 2 files changed, 10 insertions(+)
include/qemu/osdep.h +8 -0
index c1ca2c127b6..fdb61d5d51e 100644
@@ -635,6 +635,14 @@ void sigaction_invoke(struct sigaction *action,
                       struct qemu_signalfd_siginfo *info);
 #endif
 
+#ifndef HAVE_SIGINFO_T
+typedef struct {
+    int si_signo;
+    int si_code;
+    void *si_addr;
+} siginfo_t;
+#endif
+
 /*
  * Don't introduce new usage of this function, prefer the following
  * qemu_open/qemu_create that take an "Error **errp"
meson.build +2 -0
index b383c7fceef..c6207443365 100644
@@ -2709,6 +2709,8 @@ config_host_data.set('HAVE_OPTRESET',
                      cc.has_header_symbol('getopt.h', 'optreset'))
 config_host_data.set('HAVE_IPPROTO_MPTCP',
                      cc.has_header_symbol('netinet/in.h', 'IPPROTO_MPTCP'))
+config_host_data.set('HAVE_SIGINFO_T',
+                     cc.has_header_symbol('signal.h', 'siginfo_t'))
 if libaio.found()
   config_host_data.set('HAVE_IO_PREP_PWRITEV2',
                        cc.has_header_symbol('libaio.h', 'io_prep_pwritev2'))
Signature · 1 line
2.56.0
#9 lore raw

PATCH 7/21 util: introduce 'tldr', a system data recorder for crash handling

In reply to Daniel P. Berrangé

Introduce a new subsystem "tldr" aka "thrifty live data recorder" that will be able to continuously collect certain information at runtime and dump that in a crash report when QEMU exits abnormally. As a second use case, it will support manual triggering on interesting events such as guest OS panic.

Initially the framework does nothing except print the signal information. Later commits will introduce broader data collection. This relies on the dummy siginfo_t struct for portability to Windows.

---
 MAINTAINERS                 |   8 +
 include/qemu/tldr.h         |  24 ++
 qapi/qom.json               |  15 ++
 qemu-options.hx             |  14 ++
 tests/unit/meson.build      |   1 +
 tests/unit/test-util-tldr.c | 105 +++++++++
 util/meson.build            |   1 +
 util/tldr-internal.h        |  21 ++
 util/tldr.c                 | 438 ++++++++++++++++++++++++++++++++++++
 9 files changed, 627 insertions(+)
 create mode 100644 include/qemu/tldr.h
 create mode 100644 tests/unit/test-util-tldr.c
 create mode 100644 util/tldr-internal.h
 create mode 100644 util/tldr.c
MAINTAINERS +8 -0
index 6b5aafe43b1..4fa68810c1e 100644
@@ -4772,3 +4772,11 @@ Machine development tool
 M: Maksim Davydov <[email protected]>
 S: Supported
 F: scripts/compare-machine-types.py
+
+Data Recorder
+M: Daniel P. Berrangé <[email protected]>
+S: Maintained
+F: util/tldr.c
+F: util/tldr-internal.h
+F: include/qemu/tldr.h
+F: tests/unit/test-util-tldr.c
include/qemu/tldr.h new file +24 -0
new file mode 100644
index 00000000000..67152b136b3
@@ -0,0 +1,24 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * TL;DR: Thrifty Live Data Recorder
+ *
+ * Copyright (C) 2026 Red Hat Inc.
+ */
+
+#ifndef QEMU_TLDR_H__
+#define QEMU_TLDR_H__
+
+/**
+ * qtldr_crash_dump_signal:
+ * @si: signal information
+ *
+ * Print a crash dump in response to a signal.
+ *
+ * The crash will be printed to the configured crash
+ * file, if set. If opening the crash file fails, or
+ * no path is configured, STDERR will be used.
+ */
+void qtldr_crash_dump_signal(siginfo_t *si);
+
+#endif /* QEMU_TLDR_H__ */
qapi/qom.json +15 -0
index 49f222796ab..1c9031fba9a 100644
@@ -1233,6 +1233,19 @@
   'data': { '*pretty': 'bool',
             '*close-action': 'MonitorQMPCloseAction' } }
 
+##
+# @QTLDRConfigProperties:
+#     Configuration for data recorder
+#
+# @crash-target: fully qualified path to perserve data recorder
+#                contents on QEMU crash
+#
+# Since: 11.2.0
+##
+{ 'struct': 'QTLDRConfigProperties',
+  'data': { '*crash-target': 'str' }
+}
+
 ##
 # @ObjectType:
 #
@@ -1302,6 +1315,7 @@
     's390-pv-guest',
     'tdx-guest',
     'throttle-group',
+    'tldr-config',
     'tls-creds-anon',
     'tls-creds-psk',
     'tls-creds-x509',
@@ -1379,6 +1393,7 @@
       'tdx-guest':                  'TdxGuestProperties',
       'thread-context':             'ThreadContextProperties',
       'throttle-group':             'ThrottleGroupProperties',
+      'tldr-config':                'QTLDRConfigProperties',
       'tls-creds-anon':             'TlsCredsAnonProperties',
       'tls-creds-psk':              'TlsCredsPskProperties',
       'tls-creds-x509':             'TlsCredsX509Properties',
qemu-options.hx +14 -0
index 2f6863180b0..2f63d86b635 100644
@@ -6682,6 +6682,20 @@ SRST
         ::
 
             (qemu) qom-set /objects/iothread1 poll-max-ns 100000
+
+
+    ``-object tldr-config,id=id,crash-target=path``
+        Creating the ``tldr-config`` object enables the thrifty live data
+        recorder, which continuously captures important information about
+        the operation of the QEMU process. When a SIGSEGV, SIGBUS,
+        SIGILL, SIGFPE or SIGABRT are seen the contents of the data
+        recorder will be dumped to the stderr stream. If the
+        ``crash-target`` parameter was given, that specifies a fully
+        qualified file path to write the dump to instead of stderr.
+
+        The ``tldr-config`` object can be added at initial startup
+        or via QMP at runtime. Once created, however, it is not
+        permitted to disable it.
 ERST
 
 
tests/unit/meson.build +1 -0
index d17435c1877..aa02895e767 100644
@@ -136,6 +136,7 @@ if have_system
     'test-qmp-cmds': [testqapi],
     'test-xbzrle': [migration],
     'test-util-sockets': ['socket-helpers.c'],
+    'test-util-tldr': [],
     'test-base64': [],
     'test-bufferiszero': [],
     'test-smp-parse': [qom, meson.project_source_root() / 'hw/core/machine-smp.c'],
tests/unit/test-util-tldr.c new file +105 -0

105 lines not on this page · raw message

util/meson.build +1 -0
index fa174c07a57..00c2350c87e 100644
@@ -66,6 +66,7 @@ util_ss.add(files('int128.c'))
 util_ss.add(files('memalign.c'))
 util_ss.add(files('interval-tree.c'))
 util_ss.add(files('lockcnt.c'))
+util_ss.add(files('tldr.c'))
 
 if have_system
   util_ss.add(files('crc-ccitt.c'))
util/tldr-internal.h new file +21 -0
new file mode 100644
index 00000000000..193d8425eee
@@ -0,0 +1,21 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * TL;DR: Thrifty Live Data Recorder
+ *
+ * Copyright (C) 2026 Red Hat Inc.
+ */
+
+#ifndef QEMU_TLDR_INTERNAL_H__
+#define QEMU_TLDR_INTERNAL_H__
+
+#include "qemu/tldr.h"
+
+#define QTLDR_DUMP_LEADER "\n🚨🚨🚨 QEMU Data Recorder Start 🚨🚨🚨\n"
+#define QTLDR_DUMP_TRAILER "\n🚨🚨🚨 QEMU Data Recorder End 🚨🚨🚨\n\n"
+#define QTLDR_DUMP_TRIGGER_PREFIX "\n🔍 Trigger:"
+#define QTLDR_DUMP_OPEN_ERROR "🔥 Unable to dump to '"
+
+void qtldr_crash_dump_internal(int fd, siginfo_t *si);
+
+#endif /* QEMU_TLDR_INTERNAL_H__ */
util/tldr.c new file +438 -0

438 lines not on this page · raw message

Signature · 1 line
2.56.0
#10 lore raw

Re: [PATCH 07/21] util: introduce 'tldr', a system data recorder for crash handling

Quoted 5 lines · Daniel P. Berrangé

Introduce a new subsystem "tldr" aka "thrifty live data recorder" that will be able to continuously collect certain information at runtime and dump that in a crash report when QEMU exits abnormally. As a second use case, it will support manual triggering on interesting events such as guest OS panic.

What's manual about that?

Quoted 5 lines

Initially the framework does nothing except print the signal information. Later commits will introduce broader data collection. This relies on the dummy siginfo_t struct for portability to Windows.

[...]

Quoted 5 lines
qapi/qom.json +0 -0
index 49f222796ab..1c9031fba9a 100644

qapi/qom.json line 1241

Quoted 9 lines
qapi/qom.json +6 -0
@@ -1233,6 +1233,19 @@
   'data': { '*pretty': 'bool',
             '*close-action': 'MonitorQMPCloseAction' } }
 
+##
+# @QTLDRConfigProperties:
+#     Configuration for data recorder
+#
+# @crash-target: fully qualified path to perserve data recorder
+#                contents on QEMU crash

What's a "fully qualified path"?

Do you mean what POSIX calls "absolute pathname"?

Please format member descriptions like this:

# @crash-target: fully qualified path to perserve data recorder
# contents on QEMU crash

Quoted 38 lines
qapi/qom.json +9 -0
+#
+# Since: 11.2.0
+##
+{ 'struct': 'QTLDRConfigProperties',
+  'data': { '*crash-target': 'str' }
+}
+
 ##
 # @ObjectType:
 #
@@ -1302,6 +1315,7 @@
     's390-pv-guest',
     'tdx-guest',
     'throttle-group',
+    'tldr-config',
     'tls-creds-anon',
     'tls-creds-psk',
     'tls-creds-x509',
@@ -1379,6 +1393,7 @@
       'tdx-guest':                  'TdxGuestProperties',
       'thread-context':             'ThreadContextProperties',
       'throttle-group':             'ThrottleGroupProperties',
+      'tldr-config':                'QTLDRConfigProperties',
       'tls-creds-anon':             'TlsCredsAnonProperties',
       'tls-creds-psk':              'TlsCredsPskProperties',
       'tls-creds-x509':             'TlsCredsX509Properties',
qemu-options.hx +4 -0
index 2f6863180b0..2f63d86b635 100644
@@ -6682,6 +6682,20 @@ SRST
         ::
 
             (qemu) qom-set /objects/iothread1 poll-max-ns 100000
+
+
+    ``-object tldr-config,id=id,crash-target=path``
+        Creating the ``tldr-config`` object enables the thrifty live data

qemu-options.hx SRST · line 6698

Quoted 10 lines
qemu-options.hx +10 -0
+        recorder, which continuously captures important information about
+        the operation of the QEMU process. When a SIGSEGV, SIGBUS,
+        SIGILL, SIGFPE or SIGABRT are seen the contents of the data
+        recorder will be dumped to the stderr stream. If the
+        ``crash-target`` parameter was given, that specifies a fully
+        qualified file path to write the dump to instead of stderr.
+
+        The ``tldr-config`` object can be added at initial startup
+        or via QMP at runtime. Once created, however, it is not
+        permitted to disable it.

Call the object "tldr"?

Quoted 3 lines
qemu-options.hx +0 -0
 ERST
 
 

[...]

Quoted 13 lines
util/tldr-internal.h new file +7 -0
new file mode 100644
index 00000000000..193d8425eee
@@ -0,0 +1,21 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * TL;DR: Thrifty Live Data Recorder
+ *
+ * Copyright (C) 2026 Red Hat Inc.
+ */

util/tldr-internal.h line 17

Quoted 10 lines
util/tldr-internal.h new file +10 -0
+
+#ifndef QEMU_TLDR_INTERNAL_H__
+#define QEMU_TLDR_INTERNAL_H__
+
+#include "qemu/tldr.h"
+
+#define QTLDR_DUMP_LEADER "\n🚨🚨🚨 QEMU Data Recorder Start 🚨🚨🚨\n"
+#define QTLDR_DUMP_TRAILER "\n🚨🚨🚨 QEMU Data Recorder End 🚨🚨🚨\n\n"
+#define QTLDR_DUMP_TRIGGER_PREFIX "\n🔍 Trigger:"
+#define QTLDR_DUMP_OPEN_ERROR "🔥 Unable to dump to '"

The emojis make the dump file UTF-8. Fine, I guess?

Quoted 4 lines
util/tldr-internal.h new file +4 -0
+
+void qtldr_crash_dump_internal(int fd, siginfo_t *si);
+
+#endif /* QEMU_TLDR_INTERNAL_H__ */

[...]

#11 lore raw

Re: [PATCH 07/21] util: introduce 'tldr', a system data recorder for crash handling

Quoted 9 lines · Markus Armbruster
Quoted 5 lines · Daniel P. Berrangé

Introduce a new subsystem "tldr" aka "thrifty live data recorder" that will be able to continuously collect certain information at runtime and dump that in a crash report when QEMU exits abnormally. As a second use case, it will support manual triggering on interesting events such as guest OS panic.

What's manual about that?

Manual in the sense that the mgmt app has to explicitly request the data recorder contents when a guest OS panics, vs automatic dump when QEMU dies with a fatal signal.

Quoted 17 lines
Quoted 5 lines
qapi/qom.json +0 -0
index 49f222796ab..1c9031fba9a 100644

qapi/qom.json line 1241

Quoted 9 lines
qapi/qom.json +6 -0
@@ -1233,6 +1233,19 @@
   'data': { '*pretty': 'bool',
             '*close-action': 'MonitorQMPCloseAction' } }
 
+##
+# @QTLDRConfigProperties:
+#     Configuration for data recorder
+#
+# @crash-target: fully qualified path to perserve data recorder
+#                contents on QEMU crash

What's a "fully qualified path"?

Quoted 1 line

Do you mean what POSIX calls "absolute pathname"?

Yes.

Quoted 16 lines
Quoted 16 lines
qemu-options.hx +8 -0
index 2f6863180b0..2f63d86b635 100644
@@ -6682,6 +6682,20 @@ SRST
         ::
 
             (qemu) qom-set /objects/iothread1 poll-max-ns 100000
+
+
+    ``-object tldr-config,id=id,crash-target=path``
+        Creating the ``tldr-config`` object enables the thrifty live data
+        recorder, which continuously captures important information about
+        the operation of the QEMU process. When a SIGSEGV, SIGBUS,
+        SIGILL, SIGFPE or SIGABRT are seen the contents of the data
+        recorder will be dumped to the stderr stream. If the
Quoted 8 lines

qemu-options.hx SRST · line 6698

Quoted 6 lines
qemu-options.hx +6 -0
+        ``crash-target`` parameter was given, that specifies a fully
+        qualified file path to write the dump to instead of stderr.
+
+        The ``tldr-config`` object can be added at initial startup
+        or via QMP at runtime. Once created, however, it is not
+        permitted to disable it.

Call the object "tldr"?

Yes, that's an option.

Quoted 17 lines
Quoted 17 lines
util/tldr-internal.h new file +11 -0
new file mode 100644
index 00000000000..193d8425eee
@@ -0,0 +1,21 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * TL;DR: Thrifty Live Data Recorder
+ *
+ * Copyright (C) 2026 Red Hat Inc.
+ */
+
+#ifndef QEMU_TLDR_INTERNAL_H__
+#define QEMU_TLDR_INTERNAL_H__
+
Quoted 8 lines

util/tldr-internal.h line 17

Quoted 6 lines
util/tldr-internal.h new file +6 -0
+#include "qemu/tldr.h"
+
+#define QTLDR_DUMP_LEADER "\n🚨🚨🚨 QEMU Data Recorder Start 🚨🚨🚨\n"
+#define QTLDR_DUMP_TRAILER "\n🚨🚨🚨 QEMU Data Recorder End 🚨🚨🚨\n\n"
+#define QTLDR_DUMP_TRIGGER_PREFIX "\n🔍 Trigger:"
+#define QTLDR_DUMP_OPEN_ERROR "🔥 Unable to dump to '"

The emojis make the dump file UTF-8. Fine, I guess?

Personally I consider UTF-8 to be acceptable/expected to work for any OS platform since the mid 2000s, certainly for platforms that QEMU targets.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#12 lore raw

Re: [PATCH 07/21] util: introduce 'tldr', a system data recorder for crash handling

Quoted 9 lines · Daniel P. Berrangé
Quoted 8 lines · Markus Armbruster
Quoted 5 lines · Daniel P. Berrangé

Introduce a new subsystem "tldr" aka "thrifty live data recorder" that will be able to continuously collect certain information at runtime and dump that in a crash report when QEMU exits abnormally. As a second use case, it will support manual triggering on interesting events such as guest OS panic.

Quoted 5 lines
Quoted 1 line

What's manual about that?

Manual in the sense that the mgmt app has to explicitly request the data recorder contents when a guest OS panics, vs automatic dump when QEMU dies with a fatal signal.

Suggest to clarify like this: "it lets a management application dump it manually, say when it received an interesting event such as GUEST_PANICKED."

Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
qapi/qom.json +0 -0
index 49f222796ab..1c9031fba9a 100644

qapi/qom.json line 1241

Quoted 9 lines
qapi/qom.json +6 -0
@@ -1233,6 +1233,19 @@
   'data': { '*pretty': 'bool',
             '*close-action': 'MonitorQMPCloseAction' } }
 
+##
+# @QTLDRConfigProperties:
+#     Configuration for data recorder
+#
+# @crash-target: fully qualified path to perserve data recorder
+#                contents on QEMU crash

What's a "fully qualified path"?

Quoted 3 lines
Quoted 1 line

Do you mean what POSIX calls "absolute pathname"?

Yes.

Let's use that term then.

[...]

#13 lore raw

Re: [PATCH 07/21] util: introduce 'tldr', a system data recorder for crash handling

In reply to Daniel P. Berrangé
Quoted 6 lines · Daniel P. Berrangé

Introduce a new subsystem "tldr" aka "thrifty live data recorder" that will be able to continuously collect certain information at runtime and dump that in a crash report when QEMU exits abnormally. As a second use case, it will support manual triggering on interesting events such as guest OS panic.

Could we bind this to the existing panic and watchdog actions? Why wait for management layer permission just to spit some logs?

Quoted 55 lines

Initially the framework does nothing except print the signal information. Later commits will introduce broader data collection. This relies on the dummy siginfo_t struct for portability to Windows.

---
 MAINTAINERS                 |   8 +
 include/qemu/tldr.h         |  24 ++
 qapi/qom.json               |  15 ++
 qemu-options.hx             |  14 ++
 tests/unit/meson.build      |   1 +
 tests/unit/test-util-tldr.c | 105 +++++++++
 util/meson.build            |   1 +
 util/tldr-internal.h        |  21 ++
 util/tldr.c                 | 438 ++++++++++++++++++++++++++++++++++++
 9 files changed, 627 insertions(+)
 create mode 100644 include/qemu/tldr.h
 create mode 100644 tests/unit/test-util-tldr.c
 create mode 100644 util/tldr-internal.h
 create mode 100644 util/tldr.c
MAINTAINERS +8 -0
index 6b5aafe43b1..4fa68810c1e 100644
@@ -4772,3 +4772,11 @@ Machine development tool
 M: Maksim Davydov <[email protected]>
 S: Supported
 F: scripts/compare-machine-types.py
+
+Data Recorder
+M: Daniel P. Berrangé <[email protected]>
+S: Maintained
+F: util/tldr.c
+F: util/tldr-internal.h
+F: include/qemu/tldr.h
+F: tests/unit/test-util-tldr.c
include/qemu/tldr.h new file +12 -0
new file mode 100644
index 00000000000..67152b136b3
@@ -0,0 +1,24 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * TL;DR: Thrifty Live Data Recorder
+ *
+ * Copyright (C) 2026 Red Hat Inc.
+ */
+
+#ifndef QEMU_TLDR_H__
+#define QEMU_TLDR_H__
+
+/**

include/qemu/tldr.h line 22

Quoted 10 lines
include/qemu/tldr.h new file +10 -0
+ * qtldr_crash_dump_signal:
+ * @si: signal information
+ *
+ * Print a crash dump in response to a signal.
+ *
+ * The crash will be printed to the configured crash
+ * file, if set. If opening the crash file fails, or
+ * no path is configured, STDERR will be used.
+ */
+void qtldr_crash_dump_signal(siginfo_t *si);

Will the terms get confusing? There's the existing core dump, the crash, the other crash, and now the crash dump, the crash file, the crash-target, etc.

Also, does the use case of dumping on guest panic allow the virtual machine to continue running? If so, then we definitely need to drop the "crash" mentions all over.

Perhaps qtldr_dump_on_signal for this one.

Quoted 7 lines
include/qemu/tldr.h new file +2 -0
+
+#endif /* QEMU_TLDR_H__ */
qapi/qom.json +0 -0
index 49f222796ab..1c9031fba9a 100644

qapi/qom.json line 1240

Quoted 8 lines
qapi/qom.json +5 -0
@@ -1233,6 +1233,19 @@
   'data': { '*pretty': 'bool',
             '*close-action': 'MonitorQMPCloseAction' } }
 
+##
+# @QTLDRConfigProperties:
+#     Configuration for data recorder
+#
+# @crash-target: fully qualified path to perserve data recorder

preserve

Also,
s/crash-target/dump-target/ ?

qapi/qom.json line 1241

Quoted 1 line
qapi/qom.json +1 -0
+#                contents on QEMU crash

Slightly ambiguous, maybe one of:

s/on/about/
s/on/upon/

Quoted 199 lines
qapi/qom.json +9 -0
+#
+# Since: 11.2.0
+##
+{ 'struct': 'QTLDRConfigProperties',
+  'data': { '*crash-target': 'str' }
+}
+
 ##
 # @ObjectType:
 #
@@ -1302,6 +1315,7 @@
     's390-pv-guest',
     'tdx-guest',
     'throttle-group',
+    'tldr-config',
     'tls-creds-anon',
     'tls-creds-psk',
     'tls-creds-x509',
@@ -1379,6 +1393,7 @@
       'tdx-guest':                  'TdxGuestProperties',
       'thread-context':             'ThreadContextProperties',
       'throttle-group':             'ThrottleGroupProperties',
+      'tldr-config':                'QTLDRConfigProperties',
       'tls-creds-anon':             'TlsCredsAnonProperties',
       'tls-creds-psk':              'TlsCredsPskProperties',
       'tls-creds-x509':             'TlsCredsX509Properties',
qemu-options.hx +14 -0
index 2f6863180b0..2f63d86b635 100644
@@ -6682,6 +6682,20 @@ SRST
         ::
 
             (qemu) qom-set /objects/iothread1 poll-max-ns 100000
+
+
+    ``-object tldr-config,id=id,crash-target=path``
+        Creating the ``tldr-config`` object enables the thrifty live data
+        recorder, which continuously captures important information about
+        the operation of the QEMU process. When a SIGSEGV, SIGBUS,
+        SIGILL, SIGFPE or SIGABRT are seen the contents of the data
+        recorder will be dumped to the stderr stream. If the
+        ``crash-target`` parameter was given, that specifies a fully
+        qualified file path to write the dump to instead of stderr.
+
+        The ``tldr-config`` object can be added at initial startup
+        or via QMP at runtime. Once created, however, it is not
+        permitted to disable it.
 ERST
 
 
tests/unit/meson.build +1 -0
index d17435c1877..aa02895e767 100644
@@ -136,6 +136,7 @@ if have_system
     'test-qmp-cmds': [testqapi],
     'test-xbzrle': [migration],
     'test-util-sockets': ['socket-helpers.c'],
+    'test-util-tldr': [],
     'test-base64': [],
     'test-bufferiszero': [],
     'test-smp-parse': [qom, meson.project_source_root() / 'hw/core/machine-smp.c'],
tests/unit/test-util-tldr.c new file +105 -0
new file mode 100644
index 00000000000..4384e10cc18
@@ -0,0 +1,105 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Tests for util/tldr.c
+ *
+ * Copyright 2026 Red Hat, Inc.
+ */
+
+#include "qemu/osdep.h"
+#include "util/tldr-internal.h"
+
+typedef struct {
+    bool siginfo;
+    const char *data;
+} QTLDRTestData;
+
+#define TEST_SIGINFO_NULL \
+    QTLDR_DUMP_TRIGGER_PREFIX "manual\n"
+
+#define TEST_SIGINFO_SEGV \
+    QTLDR_DUMP_TRIGGER_PREFIX "\n" \
+    "  - Signal: SIGSEGV (11)\n" \
+    "  - Code: Address not mapped (1)\n" \
+    "  - Address: 0x87539319\n"
+
+
+static void
+test_tldr_one(QTLDRTestData *data)
+{
+    g_autofree char *tmpname = NULL;
+    int tmpfd;
+    char buf[1024];
+    ssize_t dumplen;
+
+    tmpfd = g_file_open_tmp("test-util-tldr-XXXXXX",
+                            &tmpname, NULL);
+    unlink(tmpname);
+
+    if (data->siginfo) {
+        siginfo_t si = {};
+        si.si_signo = 11; /*
+                           * SIGSEGV on Linux, but don't use constant
+                           * since expected output string hardcodes 11
+                           */
+        si.si_code = 1;
+        si.si_addr = (void *)0x87539319;
+        qtldr_crash_dump_internal(tmpfd, &si);
+    } else {
+        qtldr_crash_dump_internal(tmpfd, NULL);
+    }
+
+    lseek(tmpfd, 0, SEEK_SET);
+
+    dumplen = read(tmpfd, buf, sizeof(buf));
+
+    assert(dumplen > 0);
+    buf[dumplen] = '\0';
+
+    close(tmpfd);
+
+    g_assert_cmpstr(buf, ==, data->data);
+}
+
+
+static void
+test_tldr_minimal_default(void)
+{
+    QTLDRTestData data = {
+        .siginfo = false,
+        .data =
+            QTLDR_DUMP_LEADER
+            TEST_SIGINFO_NULL
+            QTLDR_DUMP_TRAILER
+    };
+
+    test_tldr_one(&data);
+}
+
+
+static void
+test_tldr_minimal_siginfo(void)
+{
+    QTLDRTestData data = {
+        .siginfo = true,
+        .data =
+            QTLDR_DUMP_LEADER
+            TEST_SIGINFO_SEGV
+            QTLDR_DUMP_TRAILER
+    };
+
+    test_tldr_one(&data);
+}
+
+
+int main(int argc, char **argv)
+{
+    g_test_init(&argc, &argv, NULL);
+
+    g_test_add_func("/util/tldr/minimal/default",
+                    test_tldr_minimal_default);
+    g_test_add_func("/util/tldr/minimal/siginfo",
+                    test_tldr_minimal_siginfo);
+
+    return g_test_run();
+}
util/meson.build +1 -0
index fa174c07a57..00c2350c87e 100644
@@ -66,6 +66,7 @@ util_ss.add(files('int128.c'))
 util_ss.add(files('memalign.c'))
 util_ss.add(files('interval-tree.c'))
 util_ss.add(files('lockcnt.c'))
+util_ss.add(files('tldr.c'))
 
 if have_system
   util_ss.add(files('crc-ccitt.c'))
util/tldr-internal.h new file +7 -0
new file mode 100644
index 00000000000..193d8425eee
@@ -0,0 +1,21 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * TL;DR: Thrifty Live Data Recorder
+ *
+ * Copyright (C) 2026 Red Hat Inc.
+ */

util/tldr-internal.h line 17

Quoted 10 lines
util/tldr-internal.h new file +10 -0
+
+#ifndef QEMU_TLDR_INTERNAL_H__
+#define QEMU_TLDR_INTERNAL_H__
+
+#include "qemu/tldr.h"
+
+#define QTLDR_DUMP_LEADER "\n🚨🚨🚨 QEMU Data Recorder Start 🚨🚨🚨\n"
+#define QTLDR_DUMP_TRAILER "\n🚨🚨🚨 QEMU Data Recorder End 🚨🚨🚨\n\n"
+#define QTLDR_DUMP_TRIGGER_PREFIX "\n🔍 Trigger:"
+#define QTLDR_DUMP_OPEN_ERROR "🔥 Unable to dump to '"

These markers got me thinking whether regular QEMU logs can interleave with tldr when directed to stderr. This is a new situation for libvirt.

#14 lore raw

PATCH 8/21 qapi: add 'tldr-dump' command for on-demand data recorder output

In reply to Daniel P. Berrangé

While the data recorder is designed to dump its contents in response to various signals that result in a QEMU crash, it is also interesting to explicitly request dump.

This could be simply as an adhoc debugging activity, or could be in response to a specific event like a guest OS panic notification.

---
 MAINTAINERS           |  1 +
 qapi/meson.build      |  1 +
 qapi/qapi-schema.json |  1 +
 qapi/tldr.json        | 28 ++++++++++++++++++++++++++++
 qemu-options.hx       |  2 ++
 util/tldr.c           | 32 ++++++++++++++++++++++++++++++++
 6 files changed, 65 insertions(+)
 create mode 100644 qapi/tldr.json
MAINTAINERS +1 -0
index 4fa68810c1e..54265d987cb 100644
@@ -4780,3 +4780,4 @@ F: util/tldr.c
 F: util/tldr-internal.h
 F: include/qemu/tldr.h
 F: tests/unit/test-util-tldr.c
+F: qapi/tldr.json
qapi/meson.build +1 -0
index a46269b5a0c..f8aecb61284 100644
@@ -49,6 +49,7 @@ qapi_all_modules = [
   'run-state',
   'sockets',
   'stats',
+  'tldr',
   'trace',
   'transaction',
   'vfio',
qapi/qapi-schema.json +1 -0
index b93dd68d94c..b36777970d1 100644
@@ -76,3 +76,4 @@
 { 'include': 'cryptodev.json' }
 { 'include': 'cxl.json' }
 { 'include': 'uefi.json' }
+{ 'include': 'tldr.json' }
qapi/tldr.json new file +28 -0
new file mode 100644
index 00000000000..8e2b7cda324
@@ -0,0 +1,28 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+##
+# @QTLDRDumpOptions:
+#     Options for `tldr-dump`.
+#
+# @target: the fully qualified file path to dump
+#     the data recorder to
+#
+# Since: 11.2.0
+##
+{ 'struct': 'QTLDRDumpOptions',
+  'data': { 'target': 'str' } }
+
+##
+# @tldr-dump:
+#     Dump the data recorder to a file
+#
+# Since: 11.2.0
+#
+# .. qmp-example::
+#
+#     -> { "execute": "tldr-dump", "arguments": { "target": "/tmp/qemu.txt" } }
+#     <- { "return": {} }
+##
+{ 'command': 'tldr-dump', 'data': 'QTLDRDumpOptions' }
qemu-options.hx +2 -0
index 2f63d86b635..5f96257cef0 100644
@@ -6692,6 +6692,8 @@ SRST
         recorder will be dumped to the stderr stream. If the
         ``crash-target`` parameter was given, that specifies a fully
         qualified file path to write the dump to instead of stderr.
+        The ``tldr-dump`` QMP command can also be used at any time to
+        save the captured data to an arbitrary file.
 
         The ``tldr-config`` object can be added at initial startup
         or via QMP at runtime. Once created, however, it is not
util/tldr.c +32 -0
index 13e9881bc9b..ea7c26b8e9b 100644
@@ -12,6 +12,7 @@
 #include "qom/object.h"
 #include "qom/object_interfaces.h"
 #include "qapi/error.h"
+#include "qapi/qapi-commands-tldr.h"
 
 struct QTLDRConfig {
     Object parent;
@@ -436,3 +437,34 @@ qtldr_crash_dump_signal(siginfo_t *si)
         close(fd);
     }
 }
+
+
+/*
+ * WARNING: Code below this marker provides a QMP handler
+ * WARNING: for use in normal execution. It calls into
+ * WARNING: the common crash report outputting APIs, but
+ * WARNING: this specific method is not restricted to async
+ * WARNING: signal safe POSIX functions.
+ */
+
+
+void
+qmp_tldr_dump(const char *target, Error **errp)
+{
+    int fd;
+
+    if (!qatomic_read(&qtldr_active)) {
+        error_setg(errp, "No 'tldr-config' object has been creted");
+        return;
+    }
+
+    fd = qemu_create(target, O_WRONLY | O_TRUNC, 0600, errp);
+    if (fd < 0) {
+        return;
+    }
+
+    qtldr_crash_dump_internal(fd, NULL);
+
+    qemu_fdatasync(fd);
+    close(fd);
+}
Signature · 1 line
2.56.0
#15 lore raw

Re: [PATCH 08/21] qapi: add 'tldr-dump' command for on-demand data recorder output

Quoted 55 lines · Daniel P. Berrangé

While the data recorder is designed to dump its contents in response to various signals that result in a QEMU crash, it is also interesting to explicitly request dump.

This could be simply as an adhoc debugging activity, or could be in response to a specific event like a guest OS panic notification.

---
 MAINTAINERS           |  1 +
 qapi/meson.build      |  1 +
 qapi/qapi-schema.json |  1 +
 qapi/tldr.json        | 28 ++++++++++++++++++++++++++++
 qemu-options.hx       |  2 ++
 util/tldr.c           | 32 ++++++++++++++++++++++++++++++++
 6 files changed, 65 insertions(+)
 create mode 100644 qapi/tldr.json
MAINTAINERS +1 -0
index 4fa68810c1e..54265d987cb 100644
@@ -4780,3 +4780,4 @@ F: util/tldr.c
 F: util/tldr-internal.h
 F: include/qemu/tldr.h
 F: tests/unit/test-util-tldr.c
+F: qapi/tldr.json
qapi/meson.build +1 -0
index a46269b5a0c..f8aecb61284 100644
@@ -49,6 +49,7 @@ qapi_all_modules = [
   'run-state',
   'sockets',
   'stats',
+  'tldr',
   'trace',
   'transaction',
   'vfio',
qapi/qapi-schema.json +1 -0
index b93dd68d94c..b36777970d1 100644
@@ -76,3 +76,4 @@
 { 'include': 'cryptodev.json' }
 { 'include': 'cxl.json' }
 { 'include': 'uefi.json' }
+{ 'include': 'tldr.json' }
qapi/tldr.json new file +0 -0
new file mode 100644
index 00000000000..8e2b7cda324

qapi/tldr.json line 10

Quoted 10 lines
qapi/tldr.json new file +10 -0
@@ -0,0 +1,28 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+##
+# @QTLDRDumpOptions:
+#     Options for `tldr-dump`.
+#
+# @target: the fully qualified file path to dump
+#     the data recorder to

We're not dumping the data recorder, we're dumping recorded data.

Quoted 8 lines
qapi/tldr.json new file +8 -0
+#
+# Since: 11.2.0
+##
+{ 'struct': 'QTLDRDumpOptions',
+  'data': { 'target': 'str' } }
+
+##
+# @tldr-dump:

qapi/tldr.json line 28

Quoted 10 lines
qapi/tldr.json new file +10 -0
+#     Dump the data recorder to a file
+#
+# Since: 11.2.0
+#
+# .. qmp-example::
+#
+#     -> { "execute": "tldr-dump", "arguments": { "target": "/tmp/qemu.txt" } }
+#     <- { "return": {} }
+##
+{ 'command': 'tldr-dump', 'data': 'QTLDRDumpOptions' }

Why do you use a separate type for the arguments?

Quoted 28 lines
qemu-options.hx +2 -0
index 2f63d86b635..5f96257cef0 100644
@@ -6692,6 +6692,8 @@ SRST
         recorder will be dumped to the stderr stream. If the
         ``crash-target`` parameter was given, that specifies a fully
         qualified file path to write the dump to instead of stderr.
+        The ``tldr-dump`` QMP command can also be used at any time to
+        save the captured data to an arbitrary file.
 
         The ``tldr-config`` object can be added at initial startup
         or via QMP at runtime. Once created, however, it is not
util/tldr.c +1 -0
index 13e9881bc9b..ea7c26b8e9b 100644
@@ -12,6 +12,7 @@
 #include "qom/object.h"
 #include "qom/object_interfaces.h"
 #include "qapi/error.h"
+#include "qapi/qapi-commands-tldr.h"
 
 struct QTLDRConfig {
     Object parent;
@@ -436,3 +437,34 @@ qtldr_crash_dump_signal(siginfo_t *si)
         close(fd);
     }

util/tldr.c qtldr_crash_dump_signal(siginfo_t *si) · line 448

Quoted 10 lines
util/tldr.c +9 -0
 }
+
+
+/*
+ * WARNING: Code below this marker provides a QMP handler
+ * WARNING: for use in normal execution. It calls into
+ * WARNING: the common crash report outputting APIs, but
+ * WARNING: this specific method is not restricted to async
+ * WARNING: signal safe POSIX functions.
+ */

Why is this a WARNING WARNING WARNING? Looks scary, then isn't.

Put it elsewhere, so the comment isn't needed?

Quoted 22 lines
util/tldr.c +22 -0
+
+
+void
+qmp_tldr_dump(const char *target, Error **errp)
+{
+    int fd;
+
+    if (!qatomic_read(&qtldr_active)) {
+        error_setg(errp, "No 'tldr-config' object has been creted");
+        return;
+    }
+
+    fd = qemu_create(target, O_WRONLY | O_TRUNC, 0600, errp);
+    if (fd < 0) {
+        return;
+    }
+
+    qtldr_crash_dump_internal(fd, NULL);
+
+    qemu_fdatasync(fd);
+    close(fd);
+}
#16 lore raw

Re: [PATCH 08/21] qapi: add 'tldr-dump' command for on-demand data recorder output

Quoted 61 lines · Markus Armbruster
Quoted 59 lines · Daniel P. Berrangé

While the data recorder is designed to dump its contents in response to various signals that result in a QEMU crash, it is also interesting to explicitly request dump.

This could be simply as an adhoc debugging activity, or could be in response to a specific event like a guest OS panic notification.

---
 MAINTAINERS           |  1 +
 qapi/meson.build      |  1 +
 qapi/qapi-schema.json |  1 +
 qapi/tldr.json        | 28 ++++++++++++++++++++++++++++
 qemu-options.hx       |  2 ++
 util/tldr.c           | 32 ++++++++++++++++++++++++++++++++
 6 files changed, 65 insertions(+)
 create mode 100644 qapi/tldr.json
MAINTAINERS +1 -0
index 4fa68810c1e..54265d987cb 100644
@@ -4780,3 +4780,4 @@ F: util/tldr.c
 F: util/tldr-internal.h
 F: include/qemu/tldr.h
 F: tests/unit/test-util-tldr.c
+F: qapi/tldr.json
qapi/meson.build +1 -0
index a46269b5a0c..f8aecb61284 100644
@@ -49,6 +49,7 @@ qapi_all_modules = [
   'run-state',
   'sockets',
   'stats',
+  'tldr',
   'trace',
   'transaction',
   'vfio',
qapi/qapi-schema.json +1 -0
index b93dd68d94c..b36777970d1 100644
@@ -76,3 +76,4 @@
 { 'include': 'cryptodev.json' }
 { 'include': 'cxl.json' }
 { 'include': 'uefi.json' }
+{ 'include': 'tldr.json' }
qapi/tldr.json new file +4 -0
new file mode 100644
index 00000000000..8e2b7cda324
@@ -0,0 +1,28 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+# SPDX-License-Identifier: GPL-2.0-or-later
+
Quoted 8 lines

qapi/tldr.json line 10

Quoted 6 lines
qapi/tldr.json new file +6 -0
+##
+# @QTLDRDumpOptions:
+#     Options for `tldr-dump`.
+#
+# @target: the fully qualified file path to dump
+#     the data recorder to

We're not dumping the data recorder, we're dumping recorded data.

Yes.

Quoted 13 lines
Quoted 13 lines
qapi/tldr.json new file +12 -0
+#
+# Since: 11.2.0
+##
+{ 'struct': 'QTLDRDumpOptions',
+  'data': { 'target': 'str' } }
+
+##
+# @tldr-dump:
+#     Dump the data recorder to a file
+#
+# Since: 11.2.0
+#
Quoted 8 lines

qapi/tldr.json line 28

Quoted 6 lines
qapi/tldr.json new file +6 -0
+# .. qmp-example::
+#
+#     -> { "execute": "tldr-dump", "arguments": { "target": "/tmp/qemu.txt" } }
+#     <- { "return": {} }
+##
+{ 'command': 'tldr-dump', 'data': 'QTLDRDumpOptions' }

Why do you use a separate type for the arguments?

Original iterations of this patch were passing
around more complex data, so this struct type
is redundant now.

Quoted 28 lines
Quoted 15 lines
util/tldr.c +1 -0
index 13e9881bc9b..ea7c26b8e9b 100644
@@ -12,6 +12,7 @@
 #include "qom/object.h"
 #include "qom/object_interfaces.h"
 #include "qapi/error.h"
+#include "qapi/qapi-commands-tldr.h"
 
 struct QTLDRConfig {
     Object parent;
@@ -436,3 +437,34 @@ qtldr_crash_dump_signal(siginfo_t *si)
         close(fd);
     }

util/tldr.c qtldr_crash_dump_signal(siginfo_t *si) · line 448

Quoted 10 lines
util/tldr.c +9 -0
 }
+
+
+/*
+ * WARNING: Code below this marker provides a QMP handler
+ * WARNING: for use in normal execution. It calls into
+ * WARNING: the common crash report outputting APIs, but
+ * WARNING: this specific method is not restricted to async
+ * WARNING: signal safe POSIX functions.
+ */

Why is this a WARNING WARNING WARNING? Looks scary, then isn't.

Quoted 1 line

Put it elsewhere, so the comment isn't needed?

Hmm, yes, we could split the file into separate pieces for different contexts.

Quoted 15 lines
Quoted 15 lines
util/tldr.c +14 -0
+
+
+void
+qmp_tldr_dump(const char *target, Error **errp)
+{
+    int fd;
+
+    if (!qatomic_read(&qtldr_active)) {
+        error_setg(errp, "No 'tldr-config' object has been creted");
+        return;
+    }
+
+    fd = qemu_create(target, O_WRONLY | O_TRUNC, 0600, errp);
+    if (fd < 0) {
Quoted 9 lines

util/tldr.c qtldr_crash_dump_signal(siginfo_t *si) · line 470

Quoted 8 lines
util/tldr.c +8 -0
+        return;
+    }
+
+    qtldr_crash_dump_internal(fd, NULL);
+
+    qemu_fdatasync(fd);
+    close(fd);
+}

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
Reviewed-by on v1 8/21
#17 lore raw

Re: [PATCH 08/21] qapi: add 'tldr-dump' command for on-demand data recorder output

In reply to Daniel P. Berrangé
Quoted 73 lines · Daniel P. Berrangé

While the data recorder is designed to dump its contents in response to various signals that result in a QEMU crash, it is also interesting to explicitly request dump.

This could be simply as an adhoc debugging activity, or could be in response to a specific event like a guest OS panic notification.

---
 MAINTAINERS           |  1 +
 qapi/meson.build      |  1 +
 qapi/qapi-schema.json |  1 +
 qapi/tldr.json        | 28 ++++++++++++++++++++++++++++
 qemu-options.hx       |  2 ++
 util/tldr.c           | 32 ++++++++++++++++++++++++++++++++
 6 files changed, 65 insertions(+)
 create mode 100644 qapi/tldr.json
MAINTAINERS +1 -0
index 4fa68810c1e..54265d987cb 100644
@@ -4780,3 +4780,4 @@ F: util/tldr.c
 F: util/tldr-internal.h
 F: include/qemu/tldr.h
 F: tests/unit/test-util-tldr.c
+F: qapi/tldr.json
qapi/meson.build +1 -0
index a46269b5a0c..f8aecb61284 100644
@@ -49,6 +49,7 @@ qapi_all_modules = [
   'run-state',
   'sockets',
   'stats',
+  'tldr',
   'trace',
   'transaction',
   'vfio',
qapi/qapi-schema.json +1 -0
index b93dd68d94c..b36777970d1 100644
@@ -76,3 +76,4 @@
 { 'include': 'cryptodev.json' }
 { 'include': 'cxl.json' }
 { 'include': 'uefi.json' }
+{ 'include': 'tldr.json' }
qapi/tldr.json new file +18 -0
new file mode 100644
index 00000000000..8e2b7cda324
@@ -0,0 +1,28 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+##
+# @QTLDRDumpOptions:
+#     Options for `tldr-dump`.
+#
+# @target: the fully qualified file path to dump
+#     the data recorder to
+#
+# Since: 11.2.0
+##
+{ 'struct': 'QTLDRDumpOptions',
+  'data': { 'target': 'str' } }
+
+##
+# @tldr-dump:

qapi/tldr.json line 28

Quoted 10 lines
qapi/tldr.json new file +10 -0
+#     Dump the data recorder to a file
+#
+# Since: 11.2.0
+#
+# .. qmp-example::
+#
+#     -> { "execute": "tldr-dump", "arguments": { "target": "/tmp/qemu.txt" } }
+#     <- { "return": {} }
+##
+{ 'command': 'tldr-dump', 'data': 'QTLDRDumpOptions' }

A good case for OOB?

Quoted 50 lines
qemu-options.hx +2 -0
index 2f63d86b635..5f96257cef0 100644
@@ -6692,6 +6692,8 @@ SRST
         recorder will be dumped to the stderr stream. If the
         ``crash-target`` parameter was given, that specifies a fully
         qualified file path to write the dump to instead of stderr.
+        The ``tldr-dump`` QMP command can also be used at any time to
+        save the captured data to an arbitrary file.
 
         The ``tldr-config`` object can be added at initial startup
         or via QMP at runtime. Once created, however, it is not
util/tldr.c +22 -0
index 13e9881bc9b..ea7c26b8e9b 100644
@@ -12,6 +12,7 @@
 #include "qom/object.h"
 #include "qom/object_interfaces.h"
 #include "qapi/error.h"
+#include "qapi/qapi-commands-tldr.h"
 
 struct QTLDRConfig {
     Object parent;
@@ -436,3 +437,34 @@ qtldr_crash_dump_signal(siginfo_t *si)
         close(fd);
     }
 }
+
+
+/*
+ * WARNING: Code below this marker provides a QMP handler
+ * WARNING: for use in normal execution. It calls into
+ * WARNING: the common crash report outputting APIs, but
+ * WARNING: this specific method is not restricted to async
+ * WARNING: signal safe POSIX functions.
+ */
+
+
+void
+qmp_tldr_dump(const char *target, Error **errp)
+{
+    int fd;
+
+    if (!qatomic_read(&qtldr_active)) {
+        error_setg(errp, "No 'tldr-config' object has been creted");
+        return;
+    }
+

util/tldr.c qtldr_crash_dump_signal(siginfo_t *si) · line 470

Quoted 10 lines
util/tldr.c +10 -0
+    fd = qemu_create(target, O_WRONLY | O_TRUNC, 0600, errp);
+    if (fd < 0) {
+        return;
+    }
+
+    qtldr_crash_dump_internal(fd, NULL);
+
+    qemu_fdatasync(fd);
+    close(fd);
+}
#18 lore raw

PATCH 9/21 system: trigger TLDR crash dump on unhandled SIGBUS

In reply to Daniel P. Berrangé

QEMU currently installs a SIGBUS handler which either forwards MCEs to KVM, or re-raises the SIGBUS. Leave MCE handling untouched, but wire up other to trigger the TLDR crash dump in the re-raise scenario.

---
 system/signal.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
system/signal.c +6 -4
index dc5a75e2816..f667b56255d 100644
@@ -27,6 +27,7 @@
 #include "hw/core/cpu.h"
 #include "system/kvm.h"
 #include "qemu/error-report.h"
+#include "qemu/tldr.h"
 
 #ifdef CONFIG_LINUX
 
@@ -48,7 +49,7 @@
 
 
 #ifdef CONFIG_LINUX
-static void sigbus_reraise(void)
+static void sigbus_reraise(siginfo_t *siginfo)
 {
     sigset_t set;
     struct sigaction action;
@@ -56,6 +57,7 @@ static void sigbus_reraise(void)
     memset(&action, 0, sizeof(action));
     action.sa_handler = SIG_DFL;
     if (!sigaction(SIGBUS, &action, NULL)) {
+        qtldr_crash_dump_signal(siginfo);
         raise(SIGBUS);
         sigemptyset(&set);
         sigaddset(&set, SIGBUS);
@@ -69,19 +71,19 @@ static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx)
 {
     if (siginfo->si_code != BUS_MCEERR_AO &&
         siginfo->si_code != BUS_MCEERR_AR) {
-        sigbus_reraise();
+        sigbus_reraise(siginfo);
     }
 
     if (current_cpu) {
         /* Called asynchronously in VCPU thread.  */
         if (kvm_on_sigbus_vcpu(current_cpu, siginfo->si_code,
                                siginfo->si_addr)) {
-            sigbus_reraise();
+            sigbus_reraise(siginfo);
         }
     } else {
         /* Called synchronously (via signalfd) in main thread.  */
         if (kvm_on_sigbus(siginfo->si_code, siginfo->si_addr)) {
-            sigbus_reraise();
+            sigbus_reraise(siginfo);
         }
     }
 }
Signature · 1 line
2.56.0
#19 lore raw

PATCH 10/21 system: simplify signal handler logic

In reply to Daniel P. Berrangé

sigaction() can fail if

* The signal number is invalid
* The signal number is KILL / STOP
* The sigaction struct points to invalid memory

None of these scenarios can arise with our use of sigaction(), so rather than try to handle failures, assert that the call passed.

---
 system/signal.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
system/signal.c +6 -9
index f667b56255d..88316089fc0 100644
@@ -56,15 +56,12 @@ static void sigbus_reraise(siginfo_t *siginfo)
 
     memset(&action, 0, sizeof(action));
     action.sa_handler = SIG_DFL;
-    if (!sigaction(SIGBUS, &action, NULL)) {
-        qtldr_crash_dump_signal(siginfo);
-        raise(SIGBUS);
-        sigemptyset(&set);
-        sigaddset(&set, SIGBUS);
-        pthread_sigmask(SIG_UNBLOCK, &set, NULL);
-    }
-    perror("Failed to re-raise SIGBUS!");
-    abort();
+    assert(sigaction(SIGBUS, &action, NULL) == 0);
+    qtldr_crash_dump_signal(siginfo);
+    raise(SIGBUS);
+    sigemptyset(&set);
+    sigaddset(&set, SIGBUS);
+    pthread_sigmask(SIG_UNBLOCK, &set, NULL);
 }
 
 static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx)
Signature · 1 line
2.56.0
#20 lore raw

PATCH 11/21 main: allow SIGBUS in the main loop

In reply to Daniel P. Berrangé

The data recorder wants to dump in response to SIGBUS in any thread, so it must be unblocked in the main loop.

XXX: this restriction appears to have been something historical related to the MCE handling to force MCEs out of the main thread, however, the signal handler appears to be able to matchup to vCPU threads regardless. Find someone with more knowledge to sanity check this change, as we really want to catch BUS errors from all threads, not merely vCPU threads.

---
 util/main-loop.c | 1 -
 1 file changed, 1 deletion(-)
util/main-loop.c +0 -1
index 65e5dbcc941..8d531f5ec90 100644
@@ -99,7 +99,6 @@ static int qemu_signal_init(Error **errp)
     sigaddset(&set, SIG_IPI);
     sigaddset(&set, SIGIO);
     sigaddset(&set, SIGALRM);
-    sigaddset(&set, SIGBUS);
     /* SIGINT cannot be handled via signalfd, so that ^C can be used
      * to interrupt QEMU when it is being run under gdb.  SIGHUP and
      * SIGTERM are also handled asynchronously, even though it is not
Signature · 1 line
2.56.0
#21 lore raw

PATCH 12/21 system: enable SIGBUS handling on non-Linux platforms

In reply to Daniel P. Berrangé

The MCE handling code is Linux/KVM specific, however, the handling of SIGBUS and crash dumps can work on any platform supporting the sigaction() function. The current function for re-raising SIGBUS can be used as the sigation handler on non-Linux by just adding the extra args.

---
 meson.build     |  1 +
 system/signal.c | 22 +++++++++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)
meson.build +1 -0
index c6207443365..c96c8884f51 100644
@@ -2648,6 +2648,7 @@ config_host_data.set('HAVE_OPENPTY', cc.has_function('openpty', dependencies: ut
 config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul', prefix: osdep_prefix))
 config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix: '#include <stdlib.h>'))
 config_host_data.set('CONFIG_SIGALTSTACK', cc.has_function('sigaltstack'))
+config_host_data.set('CONFIG_SIGACTION', cc.has_function('sigaction'))
 if rbd.found()
   config_host_data.set('HAVE_RBD_NAMESPACE_EXISTS',
                        cc.has_function('rbd_namespace_exists',
system/signal.c +15 -7
index 88316089fc0..615704900bc 100644
@@ -48,8 +48,8 @@
 #endif /* CONFIG_LINUX */
 
 
-#ifdef CONFIG_LINUX
-static void sigbus_reraise(siginfo_t *siginfo)
+#ifdef CONFIG_SIGACTION
+static void sig_handler(int n, siginfo_t *siginfo, void *ctx)
 {
     sigset_t set;
     struct sigaction action;
@@ -64,26 +64,28 @@ static void sigbus_reraise(siginfo_t *siginfo)
     pthread_sigmask(SIG_UNBLOCK, &set, NULL);
 }
 
+#ifdef CONFIG_LINUX
 static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx)
 {
     if (siginfo->si_code != BUS_MCEERR_AO &&
         siginfo->si_code != BUS_MCEERR_AR) {
-        sigbus_reraise(siginfo);
+        sig_handler(n, siginfo, ctx);
     }
 
     if (current_cpu) {
         /* Called asynchronously in VCPU thread.  */
         if (kvm_on_sigbus_vcpu(current_cpu, siginfo->si_code,
                                siginfo->si_addr)) {
-            sigbus_reraise(siginfo);
+            sig_handler(n, siginfo, ctx);
         }
     } else {
         /* Called synchronously (via signalfd) in main thread.  */
         if (kvm_on_sigbus(siginfo->si_code, siginfo->si_addr)) {
-            sigbus_reraise(siginfo);
+            sig_handler(n, siginfo, ctx);
         }
     }
 }
+#endif
 
 void qemu_init_crash_signals(void)
 {
@@ -106,13 +108,19 @@ void qemu_init_crash_signals(void)
      */
     memset(&action, 0, sizeof(action));
     action.sa_flags = SA_SIGINFO | SA_ONSTACK;
+#ifdef CONFIG_LINUX
     action.sa_sigaction = sigbus_handler;
+#else
+    action.sa_sigaction = sig_handler;
+#endif
     sigaction(SIGBUS, &action, NULL);
 
+#ifdef CONFIG_LINUX
     prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0, 0);
+#endif
 }
-#else /* !CONFIG_LINUX */
+#else /* !CONFIG_SIGACTION */
 void qemu_init_crash_signals(void)
 {
 }
-#endif /* !CONFIG_LINUX */
+#endif /* !CONFIG_SIGACTION */
Signature · 1 line
2.56.0
#22 lore raw

PATCH 13/21 system: enable crash dumps on SIGSEGV, SIGILL, SIGFPE and SIGABRT

In reply to Daniel P. Berrangé

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.

---
 system/signal.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)
system/signal.c +28 -5
index 615704900bc..4568ded4cdd 100644
@@ -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 */
Signature · 1 line
2.56.0
#23 lore raw

PATCH 14/21 util: introduce capture of textual messages in data recorder

In reply to Daniel P. Berrangé

Introduce a circular buffer concept to the data recorder that can be used to capture text based messages from subsystems. Support for multiple distinct "buckets" is provided, one per type of information to be captured. This ensures that data from subsystems which is captured at a high rate, does not prematurely wrap the buffer and overwrite (still relevant) messages from a subsystem that records at a low rate.

Each bucket has a max capacity of 64 KB by default (though it is configurable), but grows on demand. IOW the bucket capacity puts an upper limit on memory usage, actual usage will be zero until data is recorded. Every captured message will be prefixed by a timestamp and suffixed by a newline, if one is not already present at the end of the message.

While writing into the bufers is synchronized with mutex locks, when dumping from a signal handler the buffers are accessed without any locking to avoid deadlocks. Atomic loads/stores are used in certain places so the signal handler can dump data with acceptable accuracy even when racing with other threads still writing new messages.

When the circular buffer wraps, old messages will be overwritten without attention to message boundaries. IOW, when later dumping the data recorder, the first printed message is likely to have its leading text and timestamp missing. This is considered an acceptable tradeoff to avoid tracking message boundaries which greatly adds complexity and is hard todo safely without locks when dumping.

---
 include/qemu/tldr.h         |  52 +++++++
 qapi/qom.json               |   5 +-
 qapi/tldr.json              |  34 +++++
 qemu-options.hx             |   8 +
 tests/unit/test-util-tldr.c | 272 ++++++++++++++++++++++++++++++++++
 util/tldr-internal.h        |  31 ++++
 util/tldr.c                 | 282 +++++++++++++++++++++++++++++++++++-
 7 files changed, 682 insertions(+), 2 deletions(-)
include/qemu/tldr.h +52 -0
index 67152b136b3..5766acecb64 100644
@@ -9,6 +9,58 @@
 #ifndef QEMU_TLDR_H__
 #define QEMU_TLDR_H__
 
+#include "qapi/qapi-types-tldr.h"
+
+extern unsigned int qtldr_msg_enabled_mask;
+
+/**
+ * qtldr_msg_enabled:
+ * @bucket: bucket to check status for
+ *
+ * Returns: true if @bucket is enabled for recording
+ */
+#define qtldr_msg_enabled(bucket) \
+    (qtldr_msg_enabled_mask & (1 << bucket))
+
+/**
+ * qtldr_msg_record:
+ * @bucket: bucket to record into
+ * @msg: the message text to record
+ *
+ * Records @msg into @bucket, potentially overwriting
+ * old messages if the capacity is at its maximum
+ */
+void qtldr_msg_record(QTLDRMsgBucketType bucket,
+                      const char *msg);
+
+/**
+ * qtldr_msg_record_printf:
+ * @bucket: bucket to record into
+ * @fmt: the message format string to record
+ * @...: the arguments for @fmt
+ *
+ * Formats @fmt as a printf string and records the
+ * result into @bucket, potentially overwriting
+ * old messages if the capacity is at its maximum
+ */
+void qtldr_msg_record_printf(QTLDRMsgBucketType bucket,
+                             const char *fmt, ...)
+    G_GNUC_PRINTF(2, 3);
+
+/**
+ * qtldr_msg_record_vprintf:
+ * @bucket: bucket to record into
+ * @fmt: the message format string to record
+ * @ap: the arguments for @fmt
+ *
+ * Formats @fmt as a printf string and records the
+ * result into @bucket, potentially overwriting
+ * old messages if the capacity is at its maximum
+ */
+void qtldr_msg_record_vprintf(QTLDRMsgBucketType bucket,
+                              const char *fmt, va_list ap)
+    G_GNUC_PRINTF(2, 0);
+
 /**
  * qtldr_crash_dump_signal:
  * @si: signal information
qapi/qom.json +4 -1
index 1c9031fba9a..f1c37bce6c2 100644
@@ -8,6 +8,7 @@
 { 'include': 'block-core.json' }
 { 'include': 'common.json' }
 { 'include': 'crypto.json' }
+{ 'include': 'tldr.json' }
 
 ##
 # ***********************
@@ -1239,11 +1240,13 @@
 #
 # @crash-target: fully qualified path to perserve data recorder
 #                contents on QEMU crash
+# @messages: custom configuration for message buckets
 #
 # Since: 11.2.0
 ##
 { 'struct': 'QTLDRConfigProperties',
-  'data': { '*crash-target': 'str' }
+  'data': { '*crash-target': 'str',
+            '*messages': ['QTLDRMsgBucketConfig'] }
 }
 
 ##
qapi/tldr.json +34 -0
index 8e2b7cda324..987d36b91f8 100644
@@ -26,3 +26,37 @@
 #     <- { "return": {} }
 ##
 { 'command': 'tldr-dump', 'data': 'QTLDRDumpOptions' }
+
+##
+# @QTLDRMsgBucketType:
+#     List of message bucket types
+#
+# @error: error messages and warnings
+# @command: QMP commands which change state and error responses
+# @event: QMP events reflecting state changes
+# @log: log messages from any subsystems
+#
+# Since: 11.2.0
+##
+{ 'enum': 'QTLDRMsgBucketType',
+  'data': ['error', 'command', 'event', 'log' ] }
+
+
+##
+# @QTLDRMsgBucketConfig:
+#     Configuration for message buckets
+#
+# @type: the message bucket to enable
+# @capacity: override the default bucket size, in bytes (64kb)
+#
+# Each bucket allocates memory on demand, so capacity merely
+# puts an upper limit on the memory usage in a bucket.  The
+# capacity must be larger than the per-message size limit,
+# which is 2048 bytes.
+#
+# Since: 11.2.0
+##
+{ 'struct': 'QTLDRMsgBucketConfig',
+  'data': { 'type': 'QTLDRMsgBucketType',
+            '*capacity': 'size' }
+}
qemu-options.hx +8 -0
index 5f96257cef0..da9d1e2b7bd 100644
@@ -6685,6 +6685,8 @@ SRST
 
 
     ``-object tldr-config,id=id,crash-target=path``
+        \
+    ``-object "{'qom-type':'tldr-config','id':'tldr','crash-target':'foo','messages':[{'type':'BUCKET','capacity':BYTES}]}"``
         Creating the ``tldr-config`` object enables the thrifty live data
         recorder, which continuously captures important information about
         the operation of the QEMU process. When a SIGSEGV, SIGBUS,
@@ -6695,6 +6697,12 @@ SRST
         The ``tldr-dump`` QMP command can also be used at any time to
         save the captured data to an arbitrary file.
 
+        The data recorder will capture upto 64kb of data by default in
+        each bucket, but when using the JSON syntax for ``-object``, this
+        can be tailored with the ``messages`` parameter. ``BUCKET`` takes
+        one of ``error``, ``command``, ``event``, or ``log`` and the
+        capacity value is in bytes.
+
         The ``tldr-config`` object can be added at initial startup
         or via QMP at runtime. Once created, however, it is not
         permitted to disable it.
tests/unit/test-util-tldr.c +272 -0

312 lines not on this page · raw message

util/tldr-internal.h +31 -0
index 193d8425eee..f523565db85 100644
@@ -14,8 +14,39 @@
 #define QTLDR_DUMP_LEADER "\n🚨🚨🚨 QEMU Data Recorder Start 🚨🚨🚨\n"
 #define QTLDR_DUMP_TRAILER "\n🚨🚨🚨 QEMU Data Recorder End 🚨🚨🚨\n\n"
 #define QTLDR_DUMP_TRIGGER_PREFIX "\n🔍 Trigger:"
+#define QTLDR_DUMP_MSG_BUCKET_PREFIX "\n🎥  Message recording '"
 #define QTLDR_DUMP_OPEN_ERROR "🔥 Unable to dump to '"
 
+/*
+ * All writes to this struct must be protected by
+ * the qtldr_lock. Reads and writes of 'allocated'
+ * and 'next' must also use atomics, since they
+ * are accessed without locks during signal handler
+ * dumps. Reads of 'buf' may be done without locks
+ * or atomics, since we're happy to dump whatever
+ * incomplete writes may be in progress.
+ */
+typedef struct {
+    char *buf;
+    size_t allocated; /* Currently allocated */
+    size_t capacity; /* Max permitted allocation */
+    size_t next; /* Offset to write next byte */
+} QTLDRMsgBucket;
+
+#define QTLDR_MSG_ENTRY_MAX_BYTES (2 * 1024)
+#define QTLDR_MSG_BUCKET_SIZE_BYTES (64 * 1024)
+
+/*
+ * MUST always be greater than entry size, otherwise
+ * wrapping logic doesn't work
+ */
+G_STATIC_ASSERT(QTLDR_MSG_BUCKET_SIZE_BYTES >
+                QTLDR_MSG_ENTRY_MAX_BYTES);
+
+extern QTLDRMsgBucket qtldr_msg_buckets[];
+
+extern char *(*qtldr_now_str_func)(void);
+
 void qtldr_crash_dump_internal(int fd, siginfo_t *si);
 
 #endif /* QEMU_TLDR_INTERNAL_H__ */
util/tldr.c +281 -1

374 lines not on this page · raw message

Signature · 1 line
2.56.0
#24 lore raw

Re: [PATCH 14/21] util: introduce capture of textual messages in data recorder

Quoted 31 lines · Daniel P. Berrangé

Introduce a circular buffer concept to the data recorder that can be used to capture text based messages from subsystems. Support for multiple distinct "buckets" is provided, one per type of information to be captured. This ensures that data from subsystems which is captured at a high rate, does not prematurely wrap the buffer and overwrite (still relevant) messages from a subsystem that records at a low rate.

Each bucket has a max capacity of 64 KB by default (though it is configurable), but grows on demand. IOW the bucket capacity puts an upper limit on memory usage, actual usage will be zero until data is recorded. Every captured message will be prefixed by a timestamp and suffixed by a newline, if one is not already present at the end of the message.

While writing into the bufers is synchronized with mutex locks, when dumping from a signal handler the buffers are accessed without any locking to avoid deadlocks. Atomic loads/stores are used in certain places so the signal handler can dump data with acceptable accuracy even when racing with other threads still writing new messages.

When the circular buffer wraps, old messages will be overwritten without attention to message boundaries. IOW, when later dumping the data recorder, the first printed message is likely to have its leading text and timestamp missing. This is considered an acceptable tradeoff to avoid tracking message boundaries which greatly adds complexity and is hard todo safely without locks when dumping.

[...]

Quoted 13 lines
qapi/qom.json +1 -0
index 1c9031fba9a..f1c37bce6c2 100644
@@ -8,6 +8,7 @@
 { 'include': 'block-core.json' }
 { 'include': 'common.json' }
 { 'include': 'crypto.json' }
+{ 'include': 'tldr.json' }
 
 ##
 # ***********************

qapi/qom.json line 1242

Quoted 3 lines
qapi/qom.json +0 -0
@@ -1239,11 +1240,13 @@
 #
 # @crash-target: fully qualified path to perserve data recorder
 #                contents on QEMU crash

Blank line, please.

Quoted 16 lines
qapi/qom.json +3 -1
+# @messages: custom configuration for message buckets
 #
 # Since: 11.2.0
 ##
 { 'struct': 'QTLDRConfigProperties',
-  'data': { '*crash-target': 'str' }
+  'data': { '*crash-target': 'str',
+            '*messages': ['QTLDRMsgBucketConfig'] }
 }
 
 ##
qapi/tldr.json +0 -0
index 8e2b7cda324..987d36b91f8 100644

qapi/tldr.json line 32

Quoted 7 lines
qapi/tldr.json +4 -0
@@ -26,3 +26,37 @@
 #     <- { "return": {} }
 ##
 { 'command': 'tldr-dump', 'data': 'QTLDRDumpOptions' }
+
+##
+# @QTLDRMsgBucketType:
+#     List of message bucket types

This isn't a list, it's an enum. Simply scratch "List of".

qapi/tldr.json line 37

Quoted 5 lines
qapi/tldr.json +5 -0
+#
+# @error: error messages and warnings
+# @command: QMP commands which change state and error responses
+# @event: QMP events reflecting state changes
+# @log: log messages from any subsystems

Blank lines between member descriptions, please.

qapi/tldr.json line 39

Quoted 2 lines
qapi/tldr.json +2 -0
+#
+# Since: 11.2.0

Make this 11.2 to match overwhelming existing practice. Same elsewhere.

qapi/tldr.json line 49

Quoted 10 lines
qapi/tldr.json +10 -0
+##
+{ 'enum': 'QTLDRMsgBucketType',
+  'data': ['error', 'command', 'event', 'log' ] }
+
+
+##
+# @QTLDRMsgBucketConfig:
+#     Configuration for message buckets
+#
+# @type: the message bucket to enable

Blank line, please.

qapi/tldr.json line 50

Quoted 1 line
qapi/tldr.json +1 -0
+# @capacity: override the default bucket size, in bytes (64kb)

Let's use KiB.

Quoted 26 lines
qapi/tldr.json +12 -0
+#
+# Each bucket allocates memory on demand, so capacity merely
+# puts an upper limit on the memory usage in a bucket.  The
+# capacity must be larger than the per-message size limit,
+# which is 2048 bytes.
+#
+# Since: 11.2.0
+##
+{ 'struct': 'QTLDRMsgBucketConfig',
+  'data': { 'type': 'QTLDRMsgBucketType',
+            '*capacity': 'size' }
+}
qemu-options.hx +2 -0
index 5f96257cef0..da9d1e2b7bd 100644
@@ -6685,6 +6685,8 @@ SRST
 
 
     ``-object tldr-config,id=id,crash-target=path``
+        \
+    ``-object "{'qom-type':'tldr-config','id':'tldr','crash-target':'foo','messages':[{'type':'BUCKET','capacity':BYTES}]}"``
         Creating the ``tldr-config`` object enables the thrifty live data
         recorder, which continuously captures important information about
         the operation of the QEMU process. When a SIGSEGV, SIGBUS,

qemu-options.hx SRST · line 6704

Quoted 8 lines
qemu-options.hx +5 -0
@@ -6695,6 +6697,12 @@ SRST
         The ``tldr-dump`` QMP command can also be used at any time to
         save the captured data to an arbitrary file.
 
+        The data recorder will capture upto 64kb of data by default in
+        each bucket, but when using the JSON syntax for ``-object``, this
+        can be tailored with the ``messages`` parameter. ``BUCKET`` takes
+        one of ``error``, ``command``, ``event``, or ``log`` and the
+        capacity value is in bytes.

JSON only because -object still uses QemuOpts for KEY=VALUE,... arguments. Arrays can be done with QemuOpts, but it's not worth the bother here.

Quoted 4 lines
qemu-options.hx +1 -0
+
         The ``tldr-config`` object can be added at initial startup
         or via QMP at runtime. Once created, however, it is not
         permitted to disable it.

[...]

#25 lore raw

Re: [PATCH 14/21] util: introduce capture of textual messages in data recorder

In reply to Daniel P. Berrangé
Quoted 138 lines · Daniel P. Berrangé

Introduce a circular buffer concept to the data recorder that can be used to capture text based messages from subsystems. Support for multiple distinct "buckets" is provided, one per type of information to be captured. This ensures that data from subsystems which is captured at a high rate, does not prematurely wrap the buffer and overwrite (still relevant) messages from a subsystem that records at a low rate.

Each bucket has a max capacity of 64 KB by default (though it is configurable), but grows on demand. IOW the bucket capacity puts an upper limit on memory usage, actual usage will be zero until data is recorded. Every captured message will be prefixed by a timestamp and suffixed by a newline, if one is not already present at the end of the message.

While writing into the bufers is synchronized with mutex locks, when dumping from a signal handler the buffers are accessed without any locking to avoid deadlocks. Atomic loads/stores are used in certain places so the signal handler can dump data with acceptable accuracy even when racing with other threads still writing new messages.

When the circular buffer wraps, old messages will be overwritten without attention to message boundaries. IOW, when later dumping the data recorder, the first printed message is likely to have its leading text and timestamp missing. This is considered an acceptable tradeoff to avoid tracking message boundaries which greatly adds complexity and is hard todo safely without locks when dumping.

---
 include/qemu/tldr.h         |  52 +++++++
 qapi/qom.json               |   5 +-
 qapi/tldr.json              |  34 +++++
 qemu-options.hx             |   8 +
 tests/unit/test-util-tldr.c | 272 ++++++++++++++++++++++++++++++++++
 util/tldr-internal.h        |  31 ++++
 util/tldr.c                 | 282 +++++++++++++++++++++++++++++++++++-
 7 files changed, 682 insertions(+), 2 deletions(-)
include/qemu/tldr.h +52 -0
index 67152b136b3..5766acecb64 100644
@@ -9,6 +9,58 @@
 #ifndef QEMU_TLDR_H__
 #define QEMU_TLDR_H__
 
+#include "qapi/qapi-types-tldr.h"
+
+extern unsigned int qtldr_msg_enabled_mask;
+
+/**
+ * qtldr_msg_enabled:
+ * @bucket: bucket to check status for
+ *
+ * Returns: true if @bucket is enabled for recording
+ */
+#define qtldr_msg_enabled(bucket) \
+    (qtldr_msg_enabled_mask & (1 << bucket))
+
+/**
+ * qtldr_msg_record:
+ * @bucket: bucket to record into
+ * @msg: the message text to record
+ *
+ * Records @msg into @bucket, potentially overwriting
+ * old messages if the capacity is at its maximum
+ */
+void qtldr_msg_record(QTLDRMsgBucketType bucket,
+                      const char *msg);
+
+/**
+ * qtldr_msg_record_printf:
+ * @bucket: bucket to record into
+ * @fmt: the message format string to record
+ * @...: the arguments for @fmt
+ *
+ * Formats @fmt as a printf string and records the
+ * result into @bucket, potentially overwriting
+ * old messages if the capacity is at its maximum
+ */
+void qtldr_msg_record_printf(QTLDRMsgBucketType bucket,
+                             const char *fmt, ...)
+    G_GNUC_PRINTF(2, 3);
+
+/**
+ * qtldr_msg_record_vprintf:
+ * @bucket: bucket to record into
+ * @fmt: the message format string to record
+ * @ap: the arguments for @fmt
+ *
+ * Formats @fmt as a printf string and records the
+ * result into @bucket, potentially overwriting
+ * old messages if the capacity is at its maximum
+ */
+void qtldr_msg_record_vprintf(QTLDRMsgBucketType bucket,
+                              const char *fmt, va_list ap)
+    G_GNUC_PRINTF(2, 0);
+
 /**
  * qtldr_crash_dump_signal:
  * @si: signal information
qapi/qom.json +4 -1
index 1c9031fba9a..f1c37bce6c2 100644
@@ -8,6 +8,7 @@
 { 'include': 'block-core.json' }
 { 'include': 'common.json' }
 { 'include': 'crypto.json' }
+{ 'include': 'tldr.json' }
 
 ##
 # ***********************
@@ -1239,11 +1240,13 @@
 #
 # @crash-target: fully qualified path to perserve data recorder
 #                contents on QEMU crash
+# @messages: custom configuration for message buckets
 #
 # Since: 11.2.0
 ##
 { 'struct': 'QTLDRConfigProperties',
-  'data': { '*crash-target': 'str' }
+  'data': { '*crash-target': 'str',
+            '*messages': ['QTLDRMsgBucketConfig'] }
 }
 
 ##
qapi/tldr.json +0 -0
index 8e2b7cda324..987d36b91f8 100644
@@ -26,3 +26,37 @@
 #     <- { "return": {} }
 ##

qapi/tldr.json line 37

Quoted 10 lines
qapi/tldr.json +9 -0
 { 'command': 'tldr-dump', 'data': 'QTLDRDumpOptions' }
+
+##
+# @QTLDRMsgBucketType:
+#     List of message bucket types
+#
+# @error: error messages and warnings
+# @command: QMP commands which change state and error responses
+# @event: QMP events reflecting state changes
+# @log: log messages from any subsystems

Hm, all of these are generic and shared between subsystems, I'm not sure how the "high rate vs. low rate" property is to be kept if some code just runs fast over all of these classes of messages.

qapi/tldr.json line 50

Quoted 13 lines
qapi/tldr.json +13 -0
+#
+# Since: 11.2.0
+##
+{ 'enum': 'QTLDRMsgBucketType',
+  'data': ['error', 'command', 'event', 'log' ] }
+
+
+##
+# @QTLDRMsgBucketConfig:
+#     Configuration for message buckets
+#
+# @type: the message bucket to enable
+# @capacity: override the default bucket size, in bytes (64kb)

kB

Quoted 17 lines
qapi/tldr.json +12 -0
+#
+# Each bucket allocates memory on demand, so capacity merely
+# puts an upper limit on the memory usage in a bucket.  The
+# capacity must be larger than the per-message size limit,
+# which is 2048 bytes.
+#
+# Since: 11.2.0
+##
+{ 'struct': 'QTLDRMsgBucketConfig',
+  'data': { 'type': 'QTLDRMsgBucketType',
+            '*capacity': 'size' }
+}
qemu-options.hx +0 -0
index 5f96257cef0..da9d1e2b7bd 100644

qemu-options.hx SRST · line 6689

Quoted 5 lines
qemu-options.hx +2 -0
@@ -6685,6 +6685,8 @@ SRST
 
 
     ``-object tldr-config,id=id,crash-target=path``
+        \
+    ``-object "{'qom-type':'tldr-config','id':'tldr','crash-target':'foo','messages':[{'type':'BUCKET','capacity':BYTES}]}"``

So it's not possible to add new message buckets later on because the singleton tldr-config is already created?

qemu-options.hx SRST · line 6700

Quoted 8 lines
qemu-options.hx +1 -0
         Creating the ``tldr-config`` object enables the thrifty live data
         recorder, which continuously captures important information about
         the operation of the QEMU process. When a SIGSEGV, SIGBUS,
@@ -6695,6 +6697,12 @@ SRST
         The ``tldr-dump`` QMP command can also be used at any time to
         save the captured data to an arbitrary file.
 
+        The data recorder will capture upto 64kb of data by default in

up to 64 KiB

Quoted 8 lines
qemu-options.hx +5 -0
+        each bucket, but when using the JSON syntax for ``-object``, this
+        can be tailored with the ``messages`` parameter. ``BUCKET`` takes
+        one of ``error``, ``command``, ``event``, or ``log`` and the
+        capacity value is in bytes.
+
         The ``tldr-config`` object can be added at initial startup
         or via QMP at runtime. Once created, however, it is not
         permitted to disable it.
#26 lore raw

PATCH 15/21 util: capture warnings and errors in the data recorder

In reply to Daniel P. Berrangé

Any messages triggered at runtime for warn_report and error_report are potentially interesting, so should be captured for the data recorder. The most common expected scenario is use of any deprecated features which are liable to trigger warn_report.

---
 MAINTAINERS          |  1 +
 stubs/meson.build    |  1 +
 stubs/monitor-puts.c |  9 +++++++++
 util/error-report.c  | 43 ++++++++++++++++++++++++-------------------
 4 files changed, 35 insertions(+), 19 deletions(-)
 create mode 100644 stubs/monitor-puts.c
MAINTAINERS +1 -0
index 54265d987cb..3a7cd827e66 100644
@@ -3566,6 +3566,7 @@ F: include/monitor/hmp-completion.h
 F: tests/qtest/test-hmp.c
 F: include/qemu/qemu-print.h
 F: util/qemu-print.c
+F: stubs/monitor-puts.c
 
 Network device backends
 M: Jason Wang <[email protected]>
stubs/meson.build +1 -0
index 29b6644b254..52c733e32a9 100644
@@ -9,6 +9,7 @@ stub_ss.add(files('is-daemonized.c'))
 stub_ss.add(files('monitor-core.c'))
 stub_ss.add(files('monitor-cur.c'))
 stub_ss.add(files('monitor-hmp.c'))
+stub_ss.add(files('monitor-puts.c'))
 stub_ss.add(files('qapi-event-emit.c'))
 stub_ss.add(files('replay-mode.c'))
 stub_ss.add(files('trace-control.c'))
stubs/monitor-puts.c new file +9 -0
new file mode 100644
index 00000000000..bb9b726dd5e
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "monitor/monitor.h"
+
+int monitor_puts(Monitor *mon, const char *str)
+{
+    g_assert_not_reached();
+}
util/error-report.c +24 -19

107 lines not on this page · raw message

Signature · 1 line
2.56.0
#27 lore raw

PATCH 16/21 monitor: remove obsolete/redundant exports

In reply to Daniel P. Berrangé

qmp_send_response is only used within qmp.c so can be static and monitor_data_destroy_qmp no longer exists.

Fixes b723eeb815 (monitor: move monitor_data_(init|destroy) into QOM init/finalize)
---
 monitor/monitor-internal.h | 2 --
 monitor/qmp.c              | 3 ++-
 2 files changed, 2 insertions(+), 3 deletions(-)
monitor/monitor-internal.h +0 -2
index 822a66d06d0..dfdb8fb8caa 100644
@@ -122,8 +122,6 @@ void monitor_cancel_out_watch(Monitor *mon);
 void monitor_list_append(Monitor *mon);
 void monitor_fdsets_cleanup(void);
 
-void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
-void monitor_data_destroy_qmp(MonitorQMP *mon);
 void coroutine_fn monitor_qmp_dispatcher_co(void *data);
 void qmp_dispatcher_co_wake(void);
 
monitor/qmp.c +2 -1
index aec03157750..ccb39a48d4c 100644
@@ -80,6 +80,7 @@ static MonitorQMP *qmp_dispatcher_current_mon;
 OBJECT_DEFINE_TYPE(MonitorQMP, monitor_qmp, MONITOR_QMP, MONITOR);
 
 static void monitor_qmp_cleanup_req_queue_locked(MonitorQMP *mon);
+static void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
 
 static void monitor_qmp_finalize(Object *obj)
 {
@@ -242,7 +243,7 @@ static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *mon)
 
 }
 
-void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
+static void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
 {
     const QObject *data = QOBJECT(rsp);
     GString *json;
Signature · 1 line
2.56.0
#29 lore raw

PATCH 17/21 monitor: capture monitor commands and events in data recorder

In reply to Daniel P. Berrangé

QMP monitor commands which change system state (ie not query-XXX commands) are relevant to the data recorder, as they reflect what has been done to QEMU at runtime by the mgmt application.

QMP monitor events are relevant to the data recorder, as they reflect a combination of what has been done to QEMU at runtime by the mgmt application, as well as changes triggered by the guest OS.

QMP error responses are relevant either to reveal mistakes in mgmt apps, or to reveal problems in QEMU. If the associated QMP command was not already recorded, it will be recorded for any error response to provide context to the failure.

QMP normal responses are skipped since the data can be volumous and thus result in poor signal/noise ratio.

The QMP commands are never captured to a string buffer as input is streamed into the JSON parser and the result is spat out as a QObject. Thus, the commands need to be formatted back into JSON string format for the data recorder. This is a mild but acceptable performance overhead, in the overall context of handling a QMP command.

The QMP events are captured immediately before they are written back on the wire where already in string format.

---
 monitor/qmp.c | 67 +++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 59 insertions(+), 8 deletions(-)
monitor/qmp.c +59 -8
index ccb39a48d4c..659ad23d832 100644
@@ -34,6 +34,7 @@
 #include "qobject/qjson.h"
 #include "qobject/qlist.h"
 #include "qom/object_interfaces.h"
+#include "qemu/tldr.h"
 #include "trace.h"
 
 /*
@@ -80,7 +81,8 @@ static MonitorQMP *qmp_dispatcher_current_mon;
 OBJECT_DEFINE_TYPE(MonitorQMP, monitor_qmp, MONITOR_QMP, MONITOR);
 
 static void monitor_qmp_cleanup_req_queue_locked(MonitorQMP *mon);
-static void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
+static void qmp_send_response(MonitorQMP *mon, const QDict *rsp,
+                              const QObject *ctx);
 
 static void monitor_qmp_finalize(Object *obj)
 {
@@ -169,7 +171,7 @@ static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *qdict)
         }
     }
 
-    qmp_send_response(qmp, qdict);
+    qmp_send_response(qmp, qdict, NULL);
 }
 
 static bool monitor_qmp_requires_iothread(const Monitor *mon)
@@ -243,7 +245,8 @@ static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *mon)
 
 }
 
-static void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
+static void qmp_send_response(MonitorQMP *mon, const QDict *rsp,
+                              const QObject *ctx)
 {
     const QObject *data = QOBJECT(rsp);
     GString *json;
@@ -252,6 +255,30 @@ static void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
     assert(json != NULL);
     trace_monitor_qmp_respond(mon, json->str);
 
+    /*
+     * Errors are always useful to record. We recorded the
+     * command in the caller in many cases, but if not, then
+     * 'ctx' will be non-NULL and we should record it now
+     * for context.
+     */
+    if (qtldr_msg_enabled(QTLDR_MSG_BUCKET_TYPE_COMMAND) &&
+        qdict_haskey(rsp, "error")) {
+        if (ctx) {
+            g_autoptr(GString) ctxstr = qobject_to_json(ctx);
+            qtldr_msg_record(QTLDR_MSG_BUCKET_TYPE_COMMAND, ctxstr->str);
+        }
+        qtldr_msg_record(QTLDR_MSG_BUCKET_TYPE_COMMAND, json->str);
+    }
+
+    /*
+     * Capture events, since they represent changes
+     * in state or behaviour
+     */
+    if (qtldr_msg_enabled(QTLDR_MSG_BUCKET_TYPE_EVENT) &&
+        qdict_haskey(rsp, "event")) {
+        qtldr_msg_record(QTLDR_MSG_BUCKET_TYPE_EVENT, json->str);
+    }
+
     g_string_append_c(json, '\n');
     monitor_puts(&mon->parent_obj, json->str);
 
@@ -263,10 +290,10 @@ static void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
  * Null @rsp can only happen for commands with QCO_NO_SUCCESS_RESP.
  * Nothing is emitted then.
  */
-static void monitor_qmp_respond(MonitorQMP *mon, QDict *rsp)
+static void monitor_qmp_respond(MonitorQMP *mon, QDict *rsp, QObject *ctx)
 {
     if (rsp) {
-        qmp_send_response(mon, rsp);
+        qmp_send_response(mon, rsp, ctx);
     }
 }
 
@@ -276,9 +303,33 @@ static void monitor_qmp_respond(MonitorQMP *mon, QDict *rsp)
  */
 static void monitor_qmp_dispatch(MonitorQMP *mon, QObject *req)
 {
+    QObject *ctx = req;
     QDict *rsp;
     QDict *error;
 
+    /*
+     * Capture commands which are liable to change state,
+     * i.e. exclude purely information query comamnds
+     */
+    if (qtldr_msg_enabled(QTLDR_MSG_BUCKET_TYPE_COMMAND)) {
+        QDict *cmd = qobject_to(QDict, req);
+        if (cmd != NULL) {
+            const char *cmdname = qdict_get_try_str(cmd, "execute")
+                ?: qdict_get_try_str(cmd, "exec-oob");
+            if (cmdname != NULL &&
+                !g_str_has_prefix(cmdname, "query-") &&
+                !g_str_has_prefix(cmdname, "qom-list")) {
+                g_autoptr(GString) cmdstr = qobject_to_json(req);
+                qtldr_msg_record(QTLDR_MSG_BUCKET_TYPE_COMMAND, cmdstr->str);
+                /*
+                 * Prevent recording cmd twice if the later response
+                 * is an error
+                 */
+                ctx = NULL;
+            }
+        }
+    }
+
     rsp = qmp_dispatch(mon->commands, req, qmp_oob_enabled(mon),
                        &mon->parent_obj);
 
@@ -294,7 +345,7 @@ static void monitor_qmp_dispatch(MonitorQMP *mon, QObject *req)
         }
     }
 
-    monitor_qmp_respond(mon, rsp);
+    monitor_qmp_respond(mon, rsp, ctx);
     qobject_unref(rsp);
 }
 
@@ -455,7 +506,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
             trace_monitor_qmp_err_in_band(error_get_pretty(req_obj->err));
             rsp = qmp_error_response(req_obj->err);
             req_obj->err = NULL;
-            monitor_qmp_respond(mon, rsp);
+            monitor_qmp_respond(mon, rsp, NULL);
             qobject_unref(rsp);
         }
 
@@ -623,7 +674,7 @@ static void monitor_qmp_event(void *opaque, QEMUChrEvent event)
             monitor_qmp_caps_reset(mon);
         }
         data = qmp_greeting(mon);
-        qmp_send_response(mon, data);
+        qmp_send_response(mon, data, NULL);
         qobject_unref(data);
         break;
     case CHR_EVENT_CLOSED:
Signature · 1 line
2.56.0
#30 lore raw

Re: [PATCH 17/21] monitor: capture monitor commands and events in data recorder

Quoted 3 lines · * Daniel P. Berrangé ([email protected]) wrote:

QMP monitor commands which change system state (ie not query-XXX commands) are relevant to the data recorder, as they reflect what has been done to QEMU at runtime by the mgmt application.

Do you have any filters for avoiding capturing passwords/keys (which admitedly they should be doing by files, but hmm).

Dave

Quoted 176 lines

QMP monitor events are relevant to the data recorder, as they reflect a combination of what has been done to QEMU at runtime by the mgmt application, as well as changes triggered by the guest OS.

QMP error responses are relevant either to reveal mistakes in mgmt apps, or to reveal problems in QEMU. If the associated QMP command was not already recorded, it will be recorded for any error response to provide context to the failure.

QMP normal responses are skipped since the data can be volumous and thus result in poor signal/noise ratio.

The QMP commands are never captured to a string buffer as input is streamed into the JSON parser and the result is spat out as a QObject. Thus, the commands need to be formatted back into JSON string format for the data recorder. This is a mild but acceptable performance overhead, in the overall context of handling a QMP command.

The QMP events are captured immediately before they are written back on the wire where already in string format.

---
 monitor/qmp.c | 67 +++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 59 insertions(+), 8 deletions(-)
monitor/qmp.c +59 -8
index ccb39a48d4c..659ad23d832 100644
@@ -34,6 +34,7 @@
 #include "qobject/qjson.h"
 #include "qobject/qlist.h"
 #include "qom/object_interfaces.h"
+#include "qemu/tldr.h"
 #include "trace.h"
 
 /*
@@ -80,7 +81,8 @@ static MonitorQMP *qmp_dispatcher_current_mon;
 OBJECT_DEFINE_TYPE(MonitorQMP, monitor_qmp, MONITOR_QMP, MONITOR);
 
 static void monitor_qmp_cleanup_req_queue_locked(MonitorQMP *mon);
-static void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
+static void qmp_send_response(MonitorQMP *mon, const QDict *rsp,
+                              const QObject *ctx);
 
 static void monitor_qmp_finalize(Object *obj)
 {
@@ -169,7 +171,7 @@ static void monitor_qmp_emit_event(Monitor *mon, QAPIEvent event, QDict *qdict)
         }
     }
 
-    qmp_send_response(qmp, qdict);
+    qmp_send_response(qmp, qdict, NULL);
 }
 
 static bool monitor_qmp_requires_iothread(const Monitor *mon)
@@ -243,7 +245,8 @@ static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *mon)
 
 }
 
-static void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
+static void qmp_send_response(MonitorQMP *mon, const QDict *rsp,
+                              const QObject *ctx)
 {
     const QObject *data = QOBJECT(rsp);
     GString *json;
@@ -252,6 +255,30 @@ static void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
     assert(json != NULL);
     trace_monitor_qmp_respond(mon, json->str);
 
+    /*
+     * Errors are always useful to record. We recorded the
+     * command in the caller in many cases, but if not, then
+     * 'ctx' will be non-NULL and we should record it now
+     * for context.
+     */
+    if (qtldr_msg_enabled(QTLDR_MSG_BUCKET_TYPE_COMMAND) &&
+        qdict_haskey(rsp, "error")) {
+        if (ctx) {
+            g_autoptr(GString) ctxstr = qobject_to_json(ctx);
+            qtldr_msg_record(QTLDR_MSG_BUCKET_TYPE_COMMAND, ctxstr->str);
+        }
+        qtldr_msg_record(QTLDR_MSG_BUCKET_TYPE_COMMAND, json->str);
+    }
+
+    /*
+     * Capture events, since they represent changes
+     * in state or behaviour
+     */
+    if (qtldr_msg_enabled(QTLDR_MSG_BUCKET_TYPE_EVENT) &&
+        qdict_haskey(rsp, "event")) {
+        qtldr_msg_record(QTLDR_MSG_BUCKET_TYPE_EVENT, json->str);
+    }
+
     g_string_append_c(json, '\n');
     monitor_puts(&mon->parent_obj, json->str);
 
@@ -263,10 +290,10 @@ static void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
  * Null @rsp can only happen for commands with QCO_NO_SUCCESS_RESP.
  * Nothing is emitted then.
  */
-static void monitor_qmp_respond(MonitorQMP *mon, QDict *rsp)
+static void monitor_qmp_respond(MonitorQMP *mon, QDict *rsp, QObject *ctx)
 {
     if (rsp) {
-        qmp_send_response(mon, rsp);
+        qmp_send_response(mon, rsp, ctx);
     }
 }
 
@@ -276,9 +303,33 @@ static void monitor_qmp_respond(MonitorQMP *mon, QDict *rsp)
  */
 static void monitor_qmp_dispatch(MonitorQMP *mon, QObject *req)
 {
+    QObject *ctx = req;
     QDict *rsp;
     QDict *error;
 
+    /*
+     * Capture commands which are liable to change state,
+     * i.e. exclude purely information query comamnds
+     */
+    if (qtldr_msg_enabled(QTLDR_MSG_BUCKET_TYPE_COMMAND)) {
+        QDict *cmd = qobject_to(QDict, req);
+        if (cmd != NULL) {
+            const char *cmdname = qdict_get_try_str(cmd, "execute")
+                ?: qdict_get_try_str(cmd, "exec-oob");
+            if (cmdname != NULL &&
+                !g_str_has_prefix(cmdname, "query-") &&
+                !g_str_has_prefix(cmdname, "qom-list")) {
+                g_autoptr(GString) cmdstr = qobject_to_json(req);
+                qtldr_msg_record(QTLDR_MSG_BUCKET_TYPE_COMMAND, cmdstr->str);
+                /*
+                 * Prevent recording cmd twice if the later response
+                 * is an error
+                 */
+                ctx = NULL;
+            }
+        }
+    }
+
     rsp = qmp_dispatch(mon->commands, req, qmp_oob_enabled(mon),
                        &mon->parent_obj);
 
@@ -294,7 +345,7 @@ static void monitor_qmp_dispatch(MonitorQMP *mon, QObject *req)
         }
     }
 
-    monitor_qmp_respond(mon, rsp);
+    monitor_qmp_respond(mon, rsp, ctx);
     qobject_unref(rsp);
 }
 
@@ -455,7 +506,7 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
             trace_monitor_qmp_err_in_band(error_get_pretty(req_obj->err));
             rsp = qmp_error_response(req_obj->err);
             req_obj->err = NULL;
-            monitor_qmp_respond(mon, rsp);
+            monitor_qmp_respond(mon, rsp, NULL);
             qobject_unref(rsp);
         }
 
@@ -623,7 +674,7 @@ static void monitor_qmp_event(void *opaque, QEMUChrEvent event)
             monitor_qmp_caps_reset(mon);
         }
         data = qmp_greeting(mon);
-        qmp_send_response(mon, data);
+        qmp_send_response(mon, data, NULL);
         qobject_unref(data);
         break;
     case CHR_EVENT_CLOSED:
Signature · 1 line
2.56.0
Signature · 4 lines
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/
#31 lore raw

Re: [PATCH 17/21] monitor: capture monitor commands and events in data recorder

Quoted 7 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Daniel P. Berrangé ([email protected]) wrote:

QMP monitor commands which change system state (ie not query-XXX commands) are relevant to the data recorder, as they reflect what has been done to QEMU at runtime by the mgmt application.

Do you have any filters for avoiding capturing passwords/keys (which admitedly they should be doing by files, but hmm).

The "secret" object type supports this. You create a primary key which you pass to QEMU in a file on disk at startup, so it is invisible in process listing or QMP logs. Then any further secrets created at runtime should be encrypted with this primary key, so they are not compromised if capturing QMP logs

https://www.qemu.org/docs/master/system/secrets.html#best-practice

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#32 lore raw

PATCH 18/21 log: enable directing log messages to data recorder

In reply to Daniel P. Berrangé

Currently the log APIs can output messages to stderr, a named loge file, or discarded to /dev/null. Introduce a "tldr" log mask category which causes log messages to be directed to the data recorder.

This this output is mutually exclusive with file based logging and only captures single line logs emitted with qemu_log() or qemu_log_mask(). Log callers using direct FILE* access will be discarded. This is sufficient for the primary intended use case which is to collect output from the 'log' trace backend.

---
 include/qemu/log.h |  1 +
 util/log.c         | 42 +++++++++++++++++++++++++++++++++---------
 2 files changed, 34 insertions(+), 9 deletions(-)
include/qemu/log.h +1 -0
index 92956e5d0f5..47d89681d8e 100644
@@ -38,6 +38,7 @@ bool qemu_log_separate(void);
 #define CPU_LOG_TB_VPU     (1u << 21)
 #define LOG_TB_OP_PLUGIN   (1u << 22)
 #define LOG_INVALID_MEM    (1u << 23)
+#define LOG_TLDR           (1u << 24)
 
 /* Lock/unlock output. */
 
util/log.c +33 -9

85 lines not on this page · raw message

Signature · 1 line
2.56.0
#33 lore raw

PATCH 19/21 tests/qtest: add API to declare an expected crash signal

In reply to Daniel P. Berrangé

Most qtests are validating positive behaviour, but some might wish to validate that QEMU crashes. Add an API for libqtest that allows declaring an expected crash signal.

---
 tests/qtest/libqtest.c | 36 +++++++++++++++++++++++++++---------
 tests/qtest/libqtest.h | 11 +++++++++++
 2 files changed, 38 insertions(+), 9 deletions(-)
tests/qtest/libqtest.c +27 -9
index 05d88476154..e65451171e4 100644
@@ -86,6 +86,9 @@ struct QTestState
     DWORD exit_code;
 #endif
     int expected_status;
+#ifndef _WIN32
+    int expected_signal;
+#endif
     bool big_endian;
     bool irq_level[MAX_IRQ];
     GString *rx;
@@ -185,6 +188,13 @@ void qtest_set_expected_status(QTestState *s, int status)
     s->expected_status = status;
 }
 
+#ifndef _WIN32
+void qtest_set_expected_signal(QTestState *s, int signal)
+{
+    s->expected_signal = signal;
+}
+#endif
+
 static void qtest_check_status(QTestState *s)
 {
     assert(s->qemu_pid == -1);
@@ -195,20 +205,28 @@ static void qtest_check_status(QTestState *s)
      */
 #ifndef _WIN32
     int wstatus = s->wstatus;
-    if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != s->expected_status) {
-        fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
-                "process but encountered exit status %d (expected %d)\n",
-                __FILE__, __LINE__, WEXITSTATUS(wstatus), s->expected_status);
-        abort();
+    if (WIFEXITED(wstatus)) {
+        if (s->expected_signal) {
+            fprintf(stderr, "%s:%d: encountered exit status %d but expected signal %d\n",
+                    __FILE__, __LINE__, WEXITSTATUS(wstatus), s->expected_signal);
+            abort();
+        } else if (WEXITSTATUS(wstatus) != s->expected_status) {
+            fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
+                    "process but encountered exit status %d (expected %d)\n",
+                    __FILE__, __LINE__, WEXITSTATUS(wstatus), s->expected_status);
+            abort();
+        }
     } else if (WIFSIGNALED(wstatus)) {
         int sig = WTERMSIG(wstatus);
         const char *signame = strsignal(sig) ?: "unknown ???";
         const char *dump = WCOREDUMP(wstatus) ? " (core dumped)" : "";
 
-        fprintf(stderr, "%s:%d: kill_qemu() detected QEMU death "
-                "from signal %d (%s)%s\n",
-                __FILE__, __LINE__, sig, signame, dump);
-        abort();
+        if (sig != s->expected_signal) {
+            fprintf(stderr, "%s:%d: kill_qemu() detected QEMU death "
+                    "from signal %d (%s)%s\n",
+                    __FILE__, __LINE__, sig, signame, dump);
+            abort();
+        }
     }
 #else
     if (s->exit_code != s->expected_status) {
tests/qtest/libqtest.h +11 -0
index 20982d3fe8d..ddcf075e33a 100644
@@ -1155,6 +1155,17 @@ bool qtest_probe_child(QTestState *s);
  */
 void qtest_set_expected_status(QTestState *s, int status);
 
+#ifndef _WIN32
+/**
+ * qtest_set_expected_signal:
+ * @s: QTestState instance to operate on.
+ * @signal: an expected crash signal.
+ *
+ * Set expected crash signal of the child.
+ */
+void qtest_set_expected_signal(QTestState *s, int signal);
+#endif
+
 QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
                     void (*send)(void*, const char*));
 
Signature · 1 line
2.56.0
#34 lore raw

PATCH 20/21 qtest: add 'crash' command to generate 'authentic' process crashes

In reply to Daniel P. Berrangé

The 'crash' command provides a mechanism to generate process crashes, which serve to test the signal catching and handling facilities in a more authentic manner than simply running 'raise(SIG..)' against ourself.

Available usage is

crash null-pointer -> SIGSEGV on null pointer
crash invalid-addr -> SIGSEGV on derefence invalid address crash mapping-not-backed -> SIGBUS on writing to map with no storage crash bad-alignment -> SIGBUS on unaligned data write crash fpe-div-zero -> SIGFPE on floating point divide by zero crash assert -> SIGABRT on assertion failure
crash illegal-inst -> SIGILL on illegal instruction

---
 system/qtest.c         | 50 ++++++++++++++++++++++++++++++++++++++++++
 tests/qtest/libqtest.c | 26 ++++++++++++++++++++++
 tests/qtest/libqtest.h | 16 ++++++++++++++
 3 files changed, 92 insertions(+)
system/qtest.c +50 -0
index 47c954838dd..0ff04cf24e8 100644
@@ -811,6 +811,56 @@ static void qtest_process_command(CharFrontend *chr, gchar **words)
         qtest_sendf(chr, err ? "FAIL %s\n" : "OK\n",
                     err ? error_get_pretty(err) : NULL);
         error_free(err);
+    } else if (strcmp(words[0], "crash") == 0) {
+        if (strcmp(words[1], "null-pointer") == 0) {
+            char *c = (void *)0x0;
+            *c = 'a'; /* SIGSEGV */
+        } else if (strcmp(words[1], "invalid-addr") == 0) {
+            /* Hopefully invalid addr on all supported targets */
+            char *c = (void *)0x12345;
+            *c = 'b'; /* SIGSEGV */
+#ifndef WIN32
+        } else if (strcmp(words[1], "mapping-not-backed") == 0) {
+            char *m;
+            g_autofree char *tmpname = NULL;
+            int tmpfd = g_file_open_tmp("qtestcrash-XXXXXX", &tmpname, NULL);
+            m = (char *)mmap(0, 4, PROT_WRITE, MAP_PRIVATE, tmpfd, 0);
+            unlink(tmpname);
+            assert(m != MAP_FAILED);
+            /*
+             * Since no writes have been made to 'tmpfd', the backing
+             * store is still zero-length, and thus writes should
+             * trigger a bus error
+             */
+            m[0] = 0; /* SIGBUS */
+#if defined(__x86_64__) || defined(__aarch64__)
+        } else if (strcmp(words[1], "bad-alignment") == 0) {
+            /*
+             * XXX: can we assume any other arches will generate
+             * bus errors on unaligned writes ?
+             */
+            char *cptr = g_malloc(sizeof(int) + 1) + 1;
+            int *iptr = (int *)cptr;
+#ifdef __x86_64__
+            /* Turn on alignment checks */
+            __asm__("pushf\norl $0x40000,(%rsp)\npopf");
+#endif
+            *iptr = 42; /* SIGBUS */
+#endif
+#endif
+        } else if (strcmp(words[1], "fpe-div-zero") == 0) {
+            volatile int foo = 1729; /* volatile to stop optimizing */
+            volatile int bar = 0; /* volatile to stop optimizing */
+
+            foo = foo / bar; /* SIGFPE */
+            (void)foo;
+        } else if (strcmp(words[1], "assert") == 0) {
+            assert(1 == 2); /* SIGABRT */
+        } else if (strcmp(words[1], "illegal-inst") == 0) {
+            __builtin_trap(); /* SIGILL */
+        } else {
+            qtest_sendf(chr, "FAIL unsupported crash action '%s'", words[1]);
+        }
     } else if (process_command_cb && process_command_cb(chr, words)) {
         /* Command got consumed by the callback handler */
     } else {
tests/qtest/libqtest.c +26 -0
index e65451171e4..d6ca97b1c11 100644
@@ -828,6 +828,32 @@ static int qtest_query_target_endianness(QTestState *s)
     return big_endian;
 }
 
+static const char *crashtypestr[] = {
+    "null-pointer",
+    "invalid-addr",
+    "mapping-not-backed",
+#if defined(__x86_64__) || defined(__aarch64__)
+    "bad-alignment",
+#endif
+    "fpe-div-zero",
+    "assert",
+    "illegal-inst",
+};
+G_STATIC_ASSERT(G_N_ELEMENTS(crashtypestr) == QTEST_CRASH__MAX);
+
+void qtest_crash(QTestState *s, QTestCrashType type)
+{
+    char buf[1024];
+    ssize_t len;
+    assert(type < QTEST_CRASH__MAX);
+    qtest_sendf(s, "crash %s\n", crashtypestr[type]);
+    len = recv(s->fd, buf, sizeof(buf), 0);
+    if (len != 0) {
+        g_printerr("Expected crash from QEMU but saw qtest reply");
+        abort();
+    }
+}
+
 QDict *qtest_qmp_receive(QTestState *s)
 {
     while (true) {
tests/qtest/libqtest.h +16 -0
index ddcf075e33a..4988e627592 100644
@@ -1232,4 +1232,20 @@ bool mkimg(const char *file, const char *fmt, unsigned size_mb);
  */
 bool qtest_verbose(const char *domain);
 
+typedef enum {
+    QTEST_CRASH_NULL_POINTER,
+    QTEST_CRASH_INVALID_ADDR,
+    QTEST_CRASH_MAPPING_NOT_BACKED,
+#if defined(__x86_64__) || defined(__aarch64__)
+    QTEST_CRASH_BAD_ALIGNMENT,
+#endif
+    QTEST_CRASH_FPE_DIV_ZERO,
+    QTEST_CRASH_ASSERT,
+    QTEST_CRASH_ILLEGAL_INST,
+
+    QTEST_CRASH__MAX,
+} QTestCrashType;
+
+void qtest_crash(QTestState *s, QTestCrashType type);
+
 #endif
Signature · 1 line
2.56.0
#35 lore raw

PATCH 21/21 tests/qtest: add test to validate data recorder on crashes

In reply to Daniel P. Berrangé

Use qtest to trigger a QEMU crash and validate that a data recorder crash dump is written to disk.

---
 tests/qtest/meson.build |   3 +
 tests/qtest/tldr-test.c | 124 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 127 insertions(+)
 create mode 100644 tests/qtest/tldr-test.c
tests/qtest/meson.build +3 -0
index 200abf6f36d..c7bba9ea828 100644
@@ -27,6 +27,9 @@ qtests_generic = [
   'qmp-cmd-test',
   'qom-test',
 ]
+if host_os != 'windows'
+  qtests_generic += ['tldr-test']
+endif
 if have_hmp
   qtests_generic += [
     'test-hmp',
tests/qtest/tldr-test.c new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
2.56.0
#36 lore raw
In reply to Daniel P. Berrangé
Quoted 6 lines

This series introduces a new facility called 'tldr' which is a live data recorder. This is intended to aid support of production QEMU deployments, by providing a data collection facility that can be left "always on", such that in the event of a QEMU crash or guest OS crash, certain important information will be recorded.

Quoted 7 lines

The data recorder has to be enabled by adding a "tldr-config" object instance with -object / object_add.

With this series, the data recorder collects

* error_report/warn_report/error_printf messages
* QMP events

It should probably be recorded at emission, not per monitor

Quoted 9 lines

* QMP errors
* QMP commands, which are not query-XXX/qom-list, or any command associated with a QMP error.
* qemu_log output

The last item is intended primarily to be used in combination with tracing and its 'log' backend, to have continuous recording of certain interesting probes.

Quoted 6 lines

Each type of data is collected in a distinct circular buffer, such that high volumes of one type of data, does not result in overwriting other types of low volume data.

The data recorder is set to trigger on SIGBUS, SIGSEGV, SIGILL, SIGFPE and SIGABRT, or manually via QMP 'tldr-dump'.

Instead of allocating and dumping by a signal handler, why not use a file-backed mmap or a memfd? We would need to define a small fixed header for the file layout/buckets. This would avoid all the issues with signal handlers.

There would be a small window for consistency on crash, but that's probably acceptable.

Plain ASCII section markers would probably be easier to deal with than emojis

Signature · 1 line
Marc-André Lureau <[email protected]>
#37 lore raw
Quoted 9 lines · On Thu, Oct 15, 2026 at 04:15:52PM +0400, [email protected] wrote:
Quoted 9 lines

This series introduces a new facility called 'tldr' which is a live data recorder. This is intended to aid support of production QEMU deployments, by providing a data collection facility that can be left "always on", such that in the event of a QEMU crash or guest OS crash, certain important information will be recorded.

The data recorder has to be enabled by adding a "tldr-config" object instance with -object / object_add.

Quoted 6 lines
Quoted 4 lines

With this series, the data recorder collects

* error_report/warn_report/error_printf messages
* QMP events

It should probably be recorded at emission, not per monitor

Opps.

Quoted 13 lines
Quoted 13 lines

* QMP errors
* QMP commands, which are not query-XXX/qom-list, or any command associated with a QMP error.
* qemu_log output

The last item is intended primarily to be used in combination with tracing and its 'log' backend, to have continuous recording of certain interesting probes.

Each type of data is collected in a distinct circular buffer, such that high volumes of one type of data, does not result in overwriting other types of low volume data.

Quoted 6 lines
Quoted 2 lines

The data recorder is set to trigger on SIGBUS, SIGSEGV, SIGILL, SIGFPE and SIGABRT, or manually via QMP 'tldr-dump'.

Instead of allocating and dumping by a signal handler, why not use a file-backed mmap or a memfd? We would need to define a small fixed header for the file layout/buckets. This would avoid all the issues with signal handlers.

That would impose a continuous I/O workload on data recording, which is something I wanted to explicitly avoid, until the time the data is needed to be preserved. This only persists the final data, not any intermediate data that is overwritten as the circular buffer wraps. Coupling the in-memory layout to the on-disk layout also means that dumps would always be the max size, since we would not have grow-on demand buffers.

File backed would be even worse for the follow up goal of including statistics, since it'd be putting disk I/O into the stats gathering path.

Quoted 4 lines

There would be a small window for consistency on crash, but that's probably acceptable.

Plain ASCII section markers would probably be easier to deal with than emojis

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#38 lore raw

Hi

Quoted 36 lines · Daniel P. Berrangé
Quoted 9 lines · On Thu, Oct 15, 2026 at 04:15:52PM +0400, [email protected] wrote:
Quoted 9 lines

This series introduces a new facility called 'tldr' which is a live data recorder. This is intended to aid support of production QEMU deployments, by providing a data collection facility that can be left "always on", such that in the event of a QEMU crash or guest OS crash, certain important information will be recorded.

The data recorder has to be enabled by adding a "tldr-config" object instance with -object / object_add.

Quoted 6 lines
Quoted 4 lines

With this series, the data recorder collects

* error_report/warn_report/error_printf messages
* QMP events

It should probably be recorded at emission, not per monitor

Opps.

Quoted 16 lines
Quoted 15 lines

* QMP errors
* QMP commands, which are not query-XXX/qom-list, or any command associated with a QMP error.
* qemu_log output

The last item is intended primarily to be used in combination with tracing and its 'log' backend, to have continuous recording of certain interesting probes.

Each type of data is collected in a distinct circular buffer, such that high volumes of one type of data, does not result in overwriting other types of low volume data.

The data recorder is set to trigger on SIGBUS, SIGSEGV, SIGILL, SIGFPE and SIGABRT, or manually via QMP 'tldr-dump'.

Quoted 6 lines
Quoted 3 lines

Instead of allocating and dumping by a signal handler, why not use a file-backed mmap or a memfd? We would need to define a small fixed header for the file layout/buckets. This would avoid all the issues with signal handlers.

That would impose a continuous I/O workload on data recording, which is something I wanted to explicitly avoid, until the time the data is

Yes, a file-backed mapping shouldn't be the default, but memfd/tmpfs should have the same performance.

Quoted 2 lines

needed to be preserved. This only persists the final data, not any intermediate data that is overwritten as the circular buffer wraps.

Same design, the reader would handle the ring data

Quoted 3 lines

Coupling the in-memory layout to the on-disk layout also means that dumps would always be the max size, since we would not have grow-on demand buffers.

The dump output would not be the raw data, a reader would emit the same text format, skipping the unused parts.

mapping reserves address space only, pages are allocated on first write.

The benefits:
- no signal handler, no conflict with MCE, ASAN etc
- data survives SIGKILL, OOM, or a crash in the dump path itself
- data can be read from a hung QEMU

Someone needs to hold the memfd to outlive QEMU, otherwise QEMU could create a file under a runtime dir on tmpfs

Quoted 19 lines

File backed would be even worse for the follow up goal of including statistics, since it'd be putting disk I/O into the stats gathering path.

Quoted 4 lines

There would be a small window for consistency on crash, but that's probably acceptable.

Plain ASCII section markers would probably be easier to deal with than emojis

With regards,
Daniel
--

|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#39 lore raw
Quoted 52 lines · Marc-André Lureau

Hi

Quoted 36 lines · Daniel P. Berrangé
Quoted 9 lines · On Thu, Oct 15, 2026 at 04:15:52PM +0400, [email protected] wrote:
Quoted 9 lines

This series introduces a new facility called 'tldr' which is a live data recorder. This is intended to aid support of production QEMU deployments, by providing a data collection facility that can be left "always on", such that in the event of a QEMU crash or guest OS crash, certain important information will be recorded.

The data recorder has to be enabled by adding a "tldr-config" object instance with -object / object_add.

Quoted 6 lines
Quoted 4 lines

With this series, the data recorder collects

* error_report/warn_report/error_printf messages
* QMP events

It should probably be recorded at emission, not per monitor

Opps.

Quoted 16 lines
Quoted 15 lines

* QMP errors
* QMP commands, which are not query-XXX/qom-list, or any command associated with a QMP error.
* qemu_log output

The last item is intended primarily to be used in combination with tracing and its 'log' backend, to have continuous recording of certain interesting probes.

Each type of data is collected in a distinct circular buffer, such that high volumes of one type of data, does not result in overwriting other types of low volume data.

The data recorder is set to trigger on SIGBUS, SIGSEGV, SIGILL, SIGFPE and SIGABRT, or manually via QMP 'tldr-dump'.

Quoted 6 lines
Quoted 3 lines

Instead of allocating and dumping by a signal handler, why not use a file-backed mmap or a memfd? We would need to define a small fixed header for the file layout/buckets. This would avoid all the issues with signal handlers.

That would impose a continuous I/O workload on data recording, which is something I wanted to explicitly avoid, until the time the data is

Yes, a file-backed mapping shouldn't be the default, but memfd/tmpfs should have the same performance.

Quoted 2 lines

needed to be preserved. This only persists the final data, not any intermediate data that is overwritten as the circular buffer wraps.

Quoted 8 lines

Same design, the reader would handle the ring data

Quoted 3 lines

Coupling the in-memory layout to the on-disk layout also means that dumps would always be the max size, since we would not have grow-on demand buffers.

The dump output would not be the raw data, a reader would emit the same text format, skipping the unused parts.

IMHO that reader has to be QEMU owned code, as otherwise we're exposing a private data structure to a 3rd party and that makes it public ABI/API which is highly undesirable for this.

Quoted 4 lines

mapping reserves address space only, pages are allocated on first write.

The benefits:
- no signal handler, no conflict with MCE, ASAN etc

A signal handler is integral to some extent, as captured info about the signal is itself is an important part of the data record. IOW, even if moving writing of the dump out of the signal handler in some manner, I still want to be able to capture several siginfo_t fields.

You can get that info from a core dump, but the working premise is that a core dump is not guaranteed available, whereas the data record dumps are something we can more easily acquire.

Quoted 1 line

- data survives SIGKILL, OOM, or a crash in the dump path itself

Simplifying the signal handler to just stash the siginfo_t would help.

Quoted 1 line

- data can be read from a hung QEMU

Data can always be read from a hung QEMU by sending it a signal. We could wire up a non-fatal signal for this purpose if we want to read hung QEMUs without killing them.

Quoted 2 lines

Someone needs to hold the memfd to outlive QEMU, otherwise QEMU could create a file under a runtime dir on tmpfs

I wonder if QEMU could simply fork a child process itself that just hangs around waiting for death, and has a shared memory region with the main QEMU.

We already have a '-run-with async-teardown' comamnd line, which forks a child process and uses prctl(PR_SET_PDEATHSIG) to get notified with the parent goes away. We could expand that child process to also handle crash dump writing.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#40 lore raw

Hi

Quoted 60 lines · Daniel P. Berrangé
Quoted 58 lines · Marc-André Lureau

Hi

Quoted 36 lines · Daniel P. Berrangé
Quoted 9 lines · On Thu, Oct 15, 2026 at 04:15:52PM +0400, [email protected] wrote:
Quoted 9 lines

This series introduces a new facility called 'tldr' which is a live data recorder. This is intended to aid support of production QEMU deployments, by providing a data collection facility that can be left "always on", such that in the event of a QEMU crash or guest OS crash, certain important information will be recorded.

The data recorder has to be enabled by adding a "tldr-config" object instance with -object / object_add.

Quoted 6 lines
Quoted 4 lines

With this series, the data recorder collects

* error_report/warn_report/error_printf messages
* QMP events

It should probably be recorded at emission, not per monitor

Opps.

Quoted 16 lines
Quoted 15 lines

* QMP errors
* QMP commands, which are not query-XXX/qom-list, or any command associated with a QMP error.
* qemu_log output

The last item is intended primarily to be used in combination with tracing and its 'log' backend, to have continuous recording of certain interesting probes.

Each type of data is collected in a distinct circular buffer, such that high volumes of one type of data, does not result in overwriting other types of low volume data.

The data recorder is set to trigger on SIGBUS, SIGSEGV, SIGILL, SIGFPE and SIGABRT, or manually via QMP 'tldr-dump'.

Quoted 6 lines
Quoted 3 lines

Instead of allocating and dumping by a signal handler, why not use a file-backed mmap or a memfd? We would need to define a small fixed header for the file layout/buckets. This would avoid all the issues with signal handlers.

That would impose a continuous I/O workload on data recording, which is something I wanted to explicitly avoid, until the time the data is

Yes, a file-backed mapping shouldn't be the default, but memfd/tmpfs should have the same performance.

Quoted 2 lines

needed to be preserved. This only persists the final data, not any intermediate data that is overwritten as the circular buffer wraps.

Same design, the reader would handle the ring data

Quoted 3 lines

Coupling the in-memory layout to the on-disk layout also means that dumps would always be the max size, since we would not have grow-on demand buffers.

Quoted 6 lines
Quoted 2 lines

The dump output would not be the raw data, a reader would emit the same text format, skipping the unused parts.

IMHO that reader has to be QEMU owned code, as otherwise we're exposing a private data structure to a 3rd party and that makes it public ABI/API which is highly undesirable for this.

The resulting data will be ABI/API anyway, no?

Quoted 6 lines
Quoted 5 lines

mapping reserves address space only, pages are allocated on first write.

The benefits:
- no signal handler, no conflict with MCE, ASAN etc

Quoted 8 lines

A signal handler is integral to some extent, as captured info about the signal is itself is an important part of the data record. IOW, even if moving writing of the dump out of the signal handler in some manner, I still want to be able to capture several siginfo_t fields.

You can get that info from a core dump, but the working premise is that a core dump is not guaranteed available, whereas the data record dumps are something we can more easily acquire.

right.. this is something you don't touch in the cover letter. I assume most systems have a core dump handler already (perhaps differently on Windows), thus we could also rely on the dumped data instead of a signal handler. We should be explicit about why we don't follow that path

systemd/coredumpctl does store siginfo_t of the process too

Quoted 15 lines
Quoted 2 lines

- data survives SIGKILL, OOM, or a crash in the dump path itself

Simplifying the signal handler to just stash the siginfo_t would help.

Quoted 1 line

- data can be read from a hung QEMU

Data can always be read from a hung QEMU by sending it a signal. We could wire up a non-fatal signal for this purpose if we want to read hung QEMUs without killing them.

Quoted 2 lines

Someone needs to hold the memfd to outlive QEMU, otherwise QEMU could create a file under a runtime dir on tmpfs

Quoted 8 lines

I wonder if QEMU could simply fork a child process itself that just hangs around waiting for death, and has a shared memory region with the main QEMU.

We already have a '-run-with async-teardown' comamnd line, which forks a child process and uses prctl(PR_SET_PDEATHSIG) to get notified with the parent goes away. We could expand that child process to also handle crash dump writing.

Yes, that should work, although I would like to have a rationale why/when core dump aren't good enough.

thanks

#41 lore raw
Quoted 63 lines · Marc-André Lureau

Hi

Quoted 60 lines · Daniel P. Berrangé
Quoted 58 lines · Marc-André Lureau

Hi

Quoted 36 lines · Daniel P. Berrangé
Quoted 9 lines · On Thu, Oct 15, 2026 at 04:15:52PM +0400, [email protected] wrote:
Quoted 9 lines

This series introduces a new facility called 'tldr' which is a live data recorder. This is intended to aid support of production QEMU deployments, by providing a data collection facility that can be left "always on", such that in the event of a QEMU crash or guest OS crash, certain important information will be recorded.

The data recorder has to be enabled by adding a "tldr-config" object instance with -object / object_add.

Quoted 6 lines
Quoted 4 lines

With this series, the data recorder collects

* error_report/warn_report/error_printf messages
* QMP events

It should probably be recorded at emission, not per monitor

Opps.

Quoted 16 lines
Quoted 15 lines

* QMP errors
* QMP commands, which are not query-XXX/qom-list, or any command associated with a QMP error.
* qemu_log output

The last item is intended primarily to be used in combination with tracing and its 'log' backend, to have continuous recording of certain interesting probes.

Each type of data is collected in a distinct circular buffer, such that high volumes of one type of data, does not result in overwriting other types of low volume data.

The data recorder is set to trigger on SIGBUS, SIGSEGV, SIGILL, SIGFPE and SIGABRT, or manually via QMP 'tldr-dump'.

Quoted 6 lines
Quoted 3 lines

Instead of allocating and dumping by a signal handler, why not use a file-backed mmap or a memfd? We would need to define a small fixed header for the file layout/buckets. This would avoid all the issues with signal handlers.

That would impose a continuous I/O workload on data recording, which is something I wanted to explicitly avoid, until the time the data is

Yes, a file-backed mapping shouldn't be the default, but memfd/tmpfs should have the same performance.

Quoted 2 lines

needed to be preserved. This only persists the final data, not any intermediate data that is overwritten as the circular buffer wraps.

Same design, the reader would handle the ring data

Quoted 3 lines

Coupling the in-memory layout to the on-disk layout also means that dumps would always be the max size, since we would not have grow-on demand buffers.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

The dump output would not be the raw data, a reader would emit the same text format, skipping the unused parts.

IMHO that reader has to be QEMU owned code, as otherwise we're exposing a private data structure to a 3rd party and that makes it public ABI/API which is highly undesirable for this.

The resulting data will be ABI/API anyway, no?

I was considering it human targetted data, not machine targetted data, so not API and subject to change.

Quoted 16 lines
Quoted 7 lines
Quoted 6 lines

mapping reserves address space only, pages are allocated on first write.

The benefits:
- no signal handler, no conflict with MCE, ASAN etc

Quoted 8 lines

A signal handler is integral to some extent, as captured info about the signal is itself is an important part of the data record. IOW, even if moving writing of the dump out of the signal handler in some manner, I still want to be able to capture several siginfo_t fields.

You can get that info from a core dump, but the working premise is that a core dump is not guaranteed available, whereas the data record dumps are something we can more easily acquire.

Quoted 7 lines

right.. this is something you don't touch in the cover letter. I assume most systems have a core dump handler already (perhaps differently on Windows), thus we could also rely on the dumped data instead of a signal handler. We should be explicit about why we don't follow that path

systemd/coredumpctl does store siginfo_t of the process too

We often can't get at those core dump records when inside a container.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#42 lore raw

Hi

Quoted 68 lines · Daniel P. Berrangé
Quoted 66 lines · Marc-André Lureau

Hi

Quoted 63 lines · Daniel P. Berrangé
Quoted 60 lines · Marc-André Lureau

Hi

Quoted 36 lines · Daniel P. Berrangé
Quoted 9 lines · On Thu, Oct 15, 2026 at 04:15:52PM +0400, [email protected] wrote:
Quoted 9 lines

This series introduces a new facility called 'tldr' which is a live data recorder. This is intended to aid support of production QEMU deployments, by providing a data collection facility that can be left "always on", such that in the event of a QEMU crash or guest OS crash, certain important information will be recorded.

The data recorder has to be enabled by adding a "tldr-config" object instance with -object / object_add.

Quoted 6 lines
Quoted 4 lines

With this series, the data recorder collects

* error_report/warn_report/error_printf messages
* QMP events

It should probably be recorded at emission, not per monitor

Opps.

Quoted 16 lines
Quoted 15 lines

* QMP errors
* QMP commands, which are not query-XXX/qom-list, or any command associated with a QMP error.
* qemu_log output

The last item is intended primarily to be used in combination with tracing and its 'log' backend, to have continuous recording of certain interesting probes.

Each type of data is collected in a distinct circular buffer, such that high volumes of one type of data, does not result in overwriting other types of low volume data.

The data recorder is set to trigger on SIGBUS, SIGSEGV, SIGILL, SIGFPE and SIGABRT, or manually via QMP 'tldr-dump'.

Quoted 6 lines
Quoted 3 lines

Instead of allocating and dumping by a signal handler, why not use a file-backed mmap or a memfd? We would need to define a small fixed header for the file layout/buckets. This would avoid all the issues with signal handlers.

That would impose a continuous I/O workload on data recording, which is something I wanted to explicitly avoid, until the time the data is

Yes, a file-backed mapping shouldn't be the default, but memfd/tmpfs should have the same performance.

Quoted 2 lines

needed to be preserved. This only persists the final data, not any intermediate data that is overwritten as the circular buffer wraps.

Same design, the reader would handle the ring data

Quoted 3 lines

Coupling the in-memory layout to the on-disk layout also means that dumps would always be the max size, since we would not have grow-on demand buffers.

The dump output would not be the raw data, a reader would emit the same text format, skipping the unused parts.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

IMHO that reader has to be QEMU owned code, as otherwise we're exposing a private data structure to a 3rd party and that makes it public ABI/API which is highly undesirable for this.

The resulting data will be ABI/API anyway, no?

I was considering it human targetted data, not machine targetted data, so not API and subject to change.

So why would intermediate data be considered differently?

Quoted 23 lines
Quoted 23 lines
Quoted 8 lines
Quoted 7 lines

mapping reserves address space only, pages are allocated on first write.

The benefits:
- no signal handler, no conflict with MCE, ASAN etc

Quoted 8 lines

A signal handler is integral to some extent, as captured info about the signal is itself is an important part of the data record. IOW, even if moving writing of the dump out of the signal handler in some manner, I still want to be able to capture several siginfo_t fields.

You can get that info from a core dump, but the working premise is that a core dump is not guaranteed available, whereas the data record dumps are something we can more easily acquire.

right.. this is something you don't touch in the cover letter. I assume most systems have a core dump handler already (perhaps differently on Windows), thus we could also rely on the dumped data instead of a signal handler. We should be explicit about why we don't follow that path

Quoted 4 lines
Quoted 1 line

systemd/coredumpctl does store siginfo_t of the process too

We often can't get at those core dump records when inside a container.

I am not sure I understand that justification. But anyway, since the record will be in memory, we can also retrieve it from the coredump, even if a trace is written too.

#43 lore raw
In reply to Daniel P. Berrangé

Hi Daniel,

Quoted 58 lines · Daniel P. Berrangé

This series introduces a new facility called 'tldr' which is a live data recorder. This is intended to aid support of production QEMU deployments, by providing a data collection facility that can be left "always on", such that in the event of a QEMU crash or guest OS crash, certain important information will be recorded.

The data recorder has to be enabled by adding a "tldr-config" object instance with -object / object_add.

With this series, the data recorder collects

* error_report/warn_report/error_printf messages
* QMP events
* QMP errors
* QMP commands, which are not query-XXX/qom-list, or any command associated with a QMP error.
* qemu_log output

The last item is intended primarily to be used in combination with tracing and its 'log' backend, to have continuous recording of certain interesting probes.

Each type of data is collected in a distinct circular buffer, such that high volumes of one type of data, does not result in overwriting other types of low volume data.

The data recorder is set to trigger on SIGBUS, SIGSEGV, SIGILL, SIGFPE and SIGABRT, or manually via QMP 'tldr-dump'.

There is a open question in one of the patches about SIGBUS handling, since that is already used for MCE capture and I'm unclear if I'm breaking something about KVM MCE reporting.

This series proposes using sigaltstack() to register an alternative signal handling stack. This would mainly be useful if we have a crash from a stack overflow, but the cost is that we have 8k extra per thread, and I'm not entirely convinced that's a beneficial tradeoff. Might be better to just accept stack overflows as a risk.

This series only captures text based info, but as a followup I would like to extend this to capture statistics data from relevant subsystems. For example, the BlockBackend has its own "always on" stats accounting code, which can be queried with QMP. Ideally I would like to figure out a way to dump all the BlockBackend stats in the data recorder output. Likewise perhaps capture NIC stats and/or KVM stats in an "always on" manner for some interesting baseline dataset. The challenge with that is making it safe to access the stats data without taking any mutex locks, since this must run from a signal handler.

A typical recommended usage would be:

$QEMU -object tldr-config,id=tldr
-d tldr
-trace events=/var/lib/libvirt/qemu/trace.txt

Quoted 9 lines

This leaves dumps to go to QEMU's stderr on crash, but to send them to a file

-object tldr-config,id=tldr,crash-target=/some/path

The '-d tldr' flag redirects qemu_log() to the TLDR buffer instead of stdout, and the '-trace events' arg defines the "always on" tracepoints we want to capture.

if I understand correctly, the goal of this new object is to provide a per-topic rotating log in memory that will be flushed on disk only when we have a specific event (exit, or any signal). That's sounds like a good idea!

Why not refactor exisiting trace/log and provide the same feature directly there? This would be transparent, and user could decide to either dump the full file (same than before) or benefit from rotating memory buffered, with any custom size.

$QEMU -d category,size=4M -trace events=out,max-size=16M

Regards,
Pierrick

#44 lore raw
Quoted 76 lines · Pierrick Bouvier

Hi Daniel,

Quoted 58 lines · Daniel P. Berrangé

This series introduces a new facility called 'tldr' which is a live data recorder. This is intended to aid support of production QEMU deployments, by providing a data collection facility that can be left "always on", such that in the event of a QEMU crash or guest OS crash, certain important information will be recorded.

The data recorder has to be enabled by adding a "tldr-config" object instance with -object / object_add.

With this series, the data recorder collects

* error_report/warn_report/error_printf messages
* QMP events
* QMP errors
* QMP commands, which are not query-XXX/qom-list, or any command associated with a QMP error.
* qemu_log output

The last item is intended primarily to be used in combination with tracing and its 'log' backend, to have continuous recording of certain interesting probes.

Each type of data is collected in a distinct circular buffer, such that high volumes of one type of data, does not result in overwriting other types of low volume data.

The data recorder is set to trigger on SIGBUS, SIGSEGV, SIGILL, SIGFPE and SIGABRT, or manually via QMP 'tldr-dump'.

There is a open question in one of the patches about SIGBUS handling, since that is already used for MCE capture and I'm unclear if I'm breaking something about KVM MCE reporting.

This series proposes using sigaltstack() to register an alternative signal handling stack. This would mainly be useful if we have a crash from a stack overflow, but the cost is that we have 8k extra per thread, and I'm not entirely convinced that's a beneficial tradeoff. Might be better to just accept stack overflows as a risk.

This series only captures text based info, but as a followup I would like to extend this to capture statistics data from relevant subsystems. For example, the BlockBackend has its own "always on" stats accounting code, which can be queried with QMP. Ideally I would like to figure out a way to dump all the BlockBackend stats in the data recorder output. Likewise perhaps capture NIC stats and/or KVM stats in an "always on" manner for some interesting baseline dataset. The challenge with that is making it safe to access the stats data without taking any mutex locks, since this must run from a signal handler.

A typical recommended usage would be:

$QEMU -object tldr-config,id=tldr
-d tldr
-trace events=/var/lib/libvirt/qemu/trace.txt

Quoted 9 lines

This leaves dumps to go to QEMU's stderr on crash, but to send them to a file

-object tldr-config,id=tldr,crash-target=/some/path

The '-d tldr' flag redirects qemu_log() to the TLDR buffer instead of stdout, and the '-trace events' arg defines the "always on" tracepoints we want to capture.

if I understand correctly, the goal of this new object is to provide a per-topic rotating log in memory that will be flushed on disk only when we have a specific event (exit, or any signal). That's sounds like a good idea!

Quoted 6 lines

Why not refactor exisiting trace/log and provide the same feature directly there? This would be transparent, and user could decide to either dump the full file (same than before) or benefit from rotating memory buffered, with any custom size.

$QEMU -d category,size=4M -trace events=out,max-size=16M

The data recorder is intended to report more than just textual log messages. This series already captures signal info, and as noted in the cover letter will also be extended to capture structured data items such as performance statistics. The text based messages are just the simple first step.

That said I'll think about whether the split of responsibilities should adjust so that some of the logic is exposed more broadly into the log system.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|