From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063413; cv=none; d=zohomail.com; s=zohoarc; b=jVGdJ35TeHWlkmcUN5se7S6Yjhp7ykayT/4LHCVDwJtYaoZC3Anj1y3I7Et2KX823afLWJGtDNqAmdy6iky+lP4E/W1Q6z38kDbLOpu4rcXTNtiVEDwIasdz1gqAR1o3dFAmO4m0IweQ8SZ9EYwvnciSwn+rh4GQn8zsvYUX3mQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063413; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O5TfJyrp+3GRBMwwxJEWwIumgF4JQ2HcEpDuwuszYDk=; b=kfJyWiudwwN8o5vpCeJqxGGm+nmoSaZnhEDyQ4YwwVrX5h7Qm+P9nxDrFcnftdxVcBNTDV08YpyshOgCoUAkaKBRXB0Yr5GdI7wITt+VE+3CZWVN/G3Ety6CpaodUAtvzYjSBBdD9Twmu+OiEMZx9a/XUrRWlBPlzhg8lLygyOk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063413184856.0691732065372; Thu, 15 Oct 2026 04:23:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJWM-00027f-RA; Thu, 15 Oct 2026 07:21:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWH-00024i-JM for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWG-00043M-4i for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:09 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-JW5FT6nBMRKsP9htG2srug-1; Thu, 15 Oct 2026 11:20:56 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 806E01955F54; Thu, 15 Oct 2026 11:20:54 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D5A671800677; Thu, 15 Oct 2026 11:20:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063267; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O5TfJyrp+3GRBMwwxJEWwIumgF4JQ2HcEpDuwuszYDk=; b=BX0p20NbcHL5gwp/1gND9RUyHiQ6O0YMuVjro51fpgA/8SlGmS8SB13wu7m1itFqjBd0BR PeeSdZ2/D64Yz+anIfOieuRv9lmFJ8ItwdUXa0mxaHn/bkBx7Ad9H5u4VqHfYWJZAFNBV2 7BQ5+moTPZLXn6fvvv/PeRsO+t0Vtos= X-MC-Unique: JW5FT6nBMRKsP9htG2srug-1 X-Mimecast-MFC-AGG-ID: JW5FT6nBMRKsP9htG2srug_1792063254 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 01/21] osdep: add 'ignore_value(x)' macro Date: Thu, 15 Oct 2026 12:20:24 +0100 Message-ID: <20261015112044.1999748-2-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063414172158500 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=3Dgnulib.git;a=3Dblob;f=3Dl= ib/ignore-value.h;hb=3DHEAD but simplified since we don't need compat with old GCC and optimizing on clang is overkill. Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/osdep.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 1ec5b42230b..c1ca2c127b6 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -251,6 +251,14 @@ extern "C" { #endif =20 =20 +/* + * Merely casting to (void) is not sufficient for functions + * annotated with the "warn_unused_result" attribute + */ +#define ignore_value(x) \ + (__extension__ ({ __typeof__(x) __x =3D (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 --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063381; cv=none; d=zohomail.com; s=zohoarc; b=GKaYxS0GLKEDz8PyYaQK1v+4vDtaIpU2PeZjm1WOm6tZbQe5i+ArSvJp/swCFK/GzJ3rz4RRo9ytJnPDielTnbwWrVAS9AfkTSzc61+oPLakrLhdyArGIiq3Q8wVEJ3/QM99s+KqyEXl+NVweQUkagNGXICJRKIdcI0k5qyckO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063381; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Qlpt+MdO11lcCowkxz4GM0uQ0zXlAJAaoHffBaEqEvw=; b=OinlM7wj2DgEpaPEf4iEgBIMTQk+ZWoR1j5PWb+gcJKSi7MeqYaO6GoJ1t0eCDFOJLLIkLNDs6xYgKgEYPirD6ditpUJ7/cdkeKKHaVd4ojr8Odj1rytzDLbf+wR5Eqv/4I+4HChpdh+TIX38HpQ0NWf3ABgJrZsiCRBx1ZUw+I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063381105321.07359898577135; Thu, 15 Oct 2026 04:23:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJWK-00025g-JA; Thu, 15 Oct 2026 07:21:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWF-00023n-8F for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWC-000432-9f for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:06 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-PfGTlsMXMLqvgF-v3E13ww-1; Thu, 15 Oct 2026 11:21:00 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B4AAB1956071; Thu, 15 Oct 2026 11:20:58 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E90881800677; Thu, 15 Oct 2026 11:20:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063263; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qlpt+MdO11lcCowkxz4GM0uQ0zXlAJAaoHffBaEqEvw=; b=AAeK8ph0IcBEoj0T6zJXKtN09OWN9SVhIBKVtxQPB9kLzaTl9jM4bmvZDu/GGdr47uPT1w hDPd2XNEo+KExkWB9ZujscexvlCtVaPQ18oGORVZzrkvWUFX9rmb+foWciZuzFRrRlHif2 xcSa0ZVcds2kHq+LWtFcujc9tPkSavo= X-MC-Unique: PfGTlsMXMLqvgF-v3E13ww-1 X-Mimecast-MFC-AGG-ID: PfGTlsMXMLqvgF-v3E13ww_1792063259 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 02/21] system: move SIGBUS signal handling to signal.c Date: Thu, 15 Oct 2026 12:20:25 +0100 Message-ID: <20261015112044.1999748-3-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063383615158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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 diff --git a/MAINTAINERS b/MAINTAINERS index fc60193aa3f..6b5aafe43b1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -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 =20 Apple Silicon HVF CPUs M: Alexander Graf diff --git a/include/system/signal.h b/include/system/signal.h new file mode 100644 index 00000000000..f8d00221bcf --- /dev/null +++ b/include/system/signal.h @@ -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"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * 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 OT= HER + * 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); diff --git a/system/cpus.c b/system/cpus.c index e11a5aab6a6..b231ca4c4ac 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -39,28 +39,11 @@ #include "system/runstate.h" #include "system/cpu-timers.h" #include "system/whpx.h" +#include "system/signal.h" #include "hw/core/boards.h" #include "hw/core/hw-error.h" #include "trace.h" =20 -#ifdef CONFIG_LINUX - -#include - -#ifndef PR_MCE_KILL -#define PR_MCE_KILL 33 -#endif - -#ifndef PR_MCE_KILL_SET -#define PR_MCE_KILL_SET 1 -#endif - -#ifndef PR_MCE_KILL_EARLY -#define PR_MCE_KILL_EARLY 1 -#endif - -#endif /* CONFIG_LINUX */ - /* The Big QEMU Lock (BQL) */ static QemuMutex bql; =20 @@ -302,63 +285,6 @@ void cpu_handle_guest_debug(CPUState *cpu) } } =20 -#ifdef CONFIG_LINUX -static void sigbus_reraise(void) -{ - sigset_t set; - struct sigaction action; - - memset(&action, 0, sizeof(action)); - action.sa_handler =3D SIG_DFL; - if (!sigaction(SIGBUS, &action, NULL)) { - raise(SIGBUS); - sigemptyset(&set); - sigaddset(&set, SIGBUS); - pthread_sigmask(SIG_UNBLOCK, &set, NULL); - } - perror("Failed to re-raise SIGBUS!"); - abort(); -} - -static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx) -{ - if (siginfo->si_code !=3D BUS_MCEERR_AO && siginfo->si_code !=3D BUS_M= CEERR_AR) { - sigbus_reraise(); - } - - if (current_cpu) { - /* Called asynchronously in VCPU thread. */ - if (kvm_on_sigbus_vcpu(current_cpu, siginfo->si_code, siginfo->si_= addr)) { - sigbus_reraise(); - } - } else { - /* Called synchronously (via signalfd) in main thread. */ - if (kvm_on_sigbus(siginfo->si_code, siginfo->si_addr)) { - sigbus_reraise(); - } - } -} - -static void qemu_init_sigbus(void) -{ - struct sigaction action; - - /* - * 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 =3D SA_SIGINFO; - action.sa_sigaction =3D sigbus_handler; - sigaction(SIGBUS, &action, NULL); - - prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0, 0); -} -#else /* !CONFIG_LINUX */ -static void qemu_init_sigbus(void) -{ -} -#endif /* !CONFIG_LINUX */ =20 static QemuThread io_thread; =20 diff --git a/system/meson.build b/system/meson.build index a6ba7a04f7d..1829de3d25b 100644 --- a/system/meson.build +++ b/system/meson.build @@ -24,6 +24,7 @@ system_ss.add(files( 'rtc.c', 'runstate-action.c', 'runstate.c', + 'signal.c', 'watchpoint.c', )) =20 diff --git a/system/signal.c b/system/signal.c new file mode 100644 index 00000000000..6d69db2bc79 --- /dev/null +++ b/system/signal.c @@ -0,0 +1,107 @@ +/* + * 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"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * 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 OT= HER + * 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. + */ + +#include "qemu/osdep.h" +#include "system/signal.h" +#include "hw/core/cpu.h" +#include "system/kvm.h" + +#ifdef CONFIG_LINUX + +#include + +#ifndef PR_MCE_KILL +#define PR_MCE_KILL 33 +#endif + +#ifndef PR_MCE_KILL_SET +#define PR_MCE_KILL_SET 1 +#endif + +#ifndef PR_MCE_KILL_EARLY +#define PR_MCE_KILL_EARLY 1 +#endif + +#endif /* CONFIG_LINUX */ + + +#ifdef CONFIG_LINUX +static void sigbus_reraise(void) +{ + sigset_t set; + struct sigaction action; + + memset(&action, 0, sizeof(action)); + action.sa_handler =3D SIG_DFL; + if (!sigaction(SIGBUS, &action, NULL)) { + raise(SIGBUS); + sigemptyset(&set); + sigaddset(&set, SIGBUS); + pthread_sigmask(SIG_UNBLOCK, &set, NULL); + } + perror("Failed to re-raise SIGBUS!"); + abort(); +} + +static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx) +{ + if (siginfo->si_code !=3D BUS_MCEERR_AO && + siginfo->si_code !=3D BUS_MCEERR_AR) { + sigbus_reraise(); + } + + if (current_cpu) { + /* Called asynchronously in VCPU thread. */ + if (kvm_on_sigbus_vcpu(current_cpu, siginfo->si_code, + siginfo->si_addr)) { + sigbus_reraise(); + } + } else { + /* Called synchronously (via signalfd) in main thread. */ + if (kvm_on_sigbus(siginfo->si_code, siginfo->si_addr)) { + sigbus_reraise(); + } + } +} + +void qemu_init_sigbus(void) +{ + struct sigaction action; + + /* + * 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 =3D SA_SIGINFO; + action.sa_sigaction =3D sigbus_handler; + sigaction(SIGBUS, &action, NULL); + + prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0, 0); +} +#else /* !CONFIG_LINUX */ +void qemu_init_sigbus(void) +{ +} +#endif /* !CONFIG_LINUX */ --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063396; cv=none; d=zohomail.com; s=zohoarc; b=Ul3ByTevlQLAKg9jiDlEmnh5mQOeP4fhaIFlgeUD1uGH6Mz0qDPsfAQ2fHvy8hTDE2WkCuY1UgKTTYCli2QxbY9UaEIffuoN2cGlh/ycid25QlR9akz2+dK1Eo7HJci8dgtGNlh69FMorB+8O86F+5H/Jgb12fuofAPi/WuYKlE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063396; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KbgCyTF1uksFvjh6xj1JJtYuBY5wZ7IAXRMhquiwRfY=; b=GCstup2GeK5hL8V5JkqpoHt0bnBzWixM5Wuf4p/de8CTuGGlpmeEhm3vZIrf+ajjQKd1zJ3ZX3OxmamVo1wQQI3efesdppQ+qAmcQmdoGF52O0F88OABEgb6/M6lvkF0K1DzfBlV7TSXQm0shNuOcc6r2PMHlHBi75xU7/thNyU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063396531767.7931001997398; Thu, 15 Oct 2026 04:23:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJWK-00025b-7n; Thu, 15 Oct 2026 07:21:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWG-00023q-Mq for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWF-000439-1S for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:08 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-446-OU8aU9FHMJiheKY3gtNAQQ-1; Thu, 15 Oct 2026 11:21:04 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9F7C61954B17; Thu, 15 Oct 2026 11:21:02 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 28DD11800677; Thu, 15 Oct 2026 11:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KbgCyTF1uksFvjh6xj1JJtYuBY5wZ7IAXRMhquiwRfY=; b=cFMYqkNnRs7VolosPeITwpEUUeNSBTpM+tYQuWYGtSfscLv8LE8weasmBaT6XgO9CXVJZJ 7wwRtxPuW3W6e4ml/nJhqMaiOVBHfkvMLP5sT1iE6wNTIwsx0dY0tGkjaY0illG6PoBDfD HXfKj325vFPrGiGbRBj0OWs6travuPo= X-MC-Unique: OU8aU9FHMJiheKY3gtNAQQ-1 X-Mimecast-MFC-AGG-ID: OU8aU9FHMJiheKY3gtNAQQ_1792063262 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 03/21] system: rename qemu_init_sigbus to qemu_init_crash_signals Date: Thu, 15 Oct 2026 12:20:26 +0100 Message-ID: <20261015112044.1999748-4-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063398110158500 Support for handling further crash signals will be introduced in subsequent commits, so remove 'sigbus' from the initializer function name. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Marc-Andr=C3=A9 Lureau --- include/system/signal.h | 2 +- system/cpus.c | 2 +- system/signal.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/system/signal.h b/include/system/signal.h index f8d00221bcf..bb9b77428b1 100644 --- a/include/system/signal.h +++ b/include/system/signal.h @@ -22,4 +22,4 @@ * THE SOFTWARE. */ =20 -void qemu_init_sigbus(void); +void qemu_init_crash_signals(void); diff --git a/system/cpus.c b/system/cpus.c index b231ca4c4ac..870d4cfaaa3 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -295,7 +295,7 @@ static QemuCond qemu_pause_cond; =20 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); diff --git a/system/signal.c b/system/signal.c index 6d69db2bc79..423325c9a1a 100644 --- a/system/signal.c +++ b/system/signal.c @@ -85,7 +85,7 @@ static void sigbus_handler(int n, siginfo_t *siginfo, voi= d *ctx) } } =20 -void qemu_init_sigbus(void) +void qemu_init_crash_signals(void) { struct sigaction action; =20 @@ -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 */ --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063396; cv=none; d=zohomail.com; s=zohoarc; b=MANxDdweKHdn+4V/LxVlViC/9QrLOf+OoAaw1Ej4liPN2P+iA4C59rlNBGNRHdEPssDvdB8lk+MfvYGmDdODFrdrd8++e9YI7SLk6Q4DcgdxxcyoIwEwe/lOwJqE0fWo7IxLwYAXzac0Q85clNKnmKnIjMzUKZqGGBngEtl5a9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063396; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vcE4vzjSzMZVA3M8g7QAKl6n6d9Iw1O4wO/Zs3KKo1U=; b=YYCqgNSZzxCGy7Xv4YL7Cxh8y9Bd2aA4b+lUxUd12QXyJhZEcfSXpMd4BN7HwPKtqMhuZFIYS65BNWtAIg82ddwkp9r1bpmychTfBUSs0qcU311qCF7HSZWUJgXPXfvdx9kdrPgwn1v1dPA0urCL7/7wvL+DIHKZ57dxdTI5wzQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179206339653773.54177323113765; Thu, 15 Oct 2026 04:23:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJWM-00027Z-Me; Thu, 15 Oct 2026 07:21:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWL-00026H-NB for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWJ-00043i-Tt for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:13 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-a_HvIE3oPJyUZf2cEmYI0Q-1; Thu, 15 Oct 2026 11:21:08 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A4C5A1956040; Thu, 15 Oct 2026 11:21:06 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 082341800257; Thu, 15 Oct 2026 11:21:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063271; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vcE4vzjSzMZVA3M8g7QAKl6n6d9Iw1O4wO/Zs3KKo1U=; b=Vo5G2VhelwJifv47oyg+LOQOZRWEUkMEFcdxF3mGzj927Z7tqMgorQl3OCLk2/S+VUHKVC Vo+qmDhZrCKYWo2f9twJUo0kS9XZWopOm3NXSXnBzZeIPDy1usPm6KOX32tDs/QRhBKn4e nwIISePmoP/UJ4kCy8c6EoRiSwcjc10= X-MC-Unique: a_HvIE3oPJyUZf2cEmYI0Q-1 X-Mimecast-MFC-AGG-ID: a_HvIE3oPJyUZf2cEmYI0Q_1792063266 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 04/21] system: run SIGBUS handler on alternate signal stack Date: Thu, 15 Oct 2026 12:20:27 +0100 Message-ID: <20261015112044.1999748-5-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063398110158501 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- meson.build | 1 + system/signal.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 255c887e8e6..b383c7fceef 100644 --- a/meson.build +++ b/meson.build @@ -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', dependenci= es: 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', pre= fix: '#include ')) +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', diff --git a/system/signal.c b/system/signal.c index 423325c9a1a..dc5a75e2816 100644 --- a/system/signal.c +++ b/system/signal.c @@ -26,6 +26,7 @@ #include "system/signal.h" #include "hw/core/cpu.h" #include "system/kvm.h" +#include "qemu/error-report.h" =20 #ifdef CONFIG_LINUX =20 @@ -89,12 +90,23 @@ void qemu_init_crash_signals(void) { struct sigaction action; =20 +#ifdef CONFIG_SIGALTSTACK + static stack_t signal_stack; + signal_stack.ss_sp =3D (void *)g_new0(char, SIGSTKSZ); + signal_stack.ss_size =3D 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 =3D SA_SIGINFO; + action.sa_flags =3D SA_SIGINFO | SA_ONSTACK; action.sa_sigaction =3D sigbus_handler; sigaction(SIGBUS, &action, NULL); =20 --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063293; cv=none; d=zohomail.com; s=zohoarc; b=N6tqdWV7rNlXC3egw5/zGnc2zQNvyG157qKwP/clNx0Q3lS/ektTUpeFq4AS2EPTnS5g8mA++14MRaJm+/SZ06+0lgmTonNp4BJJfpo+Bq46cP9k5l6FBQ6LSao7jd0QbQ59aRw8TiOOMuaAaxOZzc5YIdmCDe3cPjObcP7YUdw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063293; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lGCv+AfKMnU61s9G0ocGnKK177Rsaciih/XA+CS5lHg=; b=hvkUipv4aeC5vvnmGQ4qwqkaDw2jScJM9bwPyiekw0tnyRCFajuJDhql6dcsOmnFFH6vL8GgwSiWgSG1u9jgX5Qu2sQ03z5OuFED/A+KajLT1jFEwncI1SW2A4VzJcHVIA1VmX1FlFpJQx9mlpdX1zdMfkPK69Jq0G5950Tf3yM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063293493967.7209198727255; Thu, 15 Oct 2026 04:21:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJWR-0002CR-KR; Thu, 15 Oct 2026 07:21:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWP-00029G-FA for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWN-00043x-UB for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:17 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-141-yUCRfPbLNoK9D_HpSsS9rQ-1; Thu, 15 Oct 2026 11:21:11 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7DDD81955EB9; Thu, 15 Oct 2026 11:21:10 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1D9821800257; Thu, 15 Oct 2026 11:21:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063275; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lGCv+AfKMnU61s9G0ocGnKK177Rsaciih/XA+CS5lHg=; b=XChsOuamm44nXm6DHpPe/80ro66+eYIaMWaNWk26uTWGdt5qXr0u21zvNZT1tacdNmIlg1 QQgrIMYr2kETLZIyLPrbhvgADy6KdklFi40PMyV/8fSOBEvlmkuVy1Kskxs0GHGp3wg+dy rxtqw8fyGRZ0da7EF/KSzrAz92bnQfM= X-MC-Unique: yUCRfPbLNoK9D_HpSsS9rQ-1 X-Mimecast-MFC-AGG-ID: yUCRfPbLNoK9D_HpSsS9rQ_1792063270 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 05/21] util: expand alternate signal stack to all threads Date: Thu, 15 Oct 2026 12:20:28 +0100 Message-ID: <20261015112044.1999748-6-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063293981158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- util/qemu-thread-posix.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 089606c93fb..66858018057 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -381,12 +381,28 @@ typedef struct { char *name; } QemuThreadArgs; =20 +static void qemu_thread_sigstack_free(void *data) +{ + stack_t sigstack =3D { + .ss_sp =3D NULL, + .ss_size =3D 0, + .ss_flags =3D SS_DISABLE, + }; + sigaltstack(&sigstack, NULL); + g_free(data); +} + static void *qemu_thread_start(void *args) { QemuThreadArgs *qemu_thread_args =3D args; void *(*start_routine)(void *) =3D qemu_thread_args->start_routine; void *arg =3D qemu_thread_args->arg; void *r; + stack_t sigstack =3D { + .ss_sp =3D g_new0(char, SIGSTKSZ), + .ss_size =3D SIGSTKSZ, + .ss_flags =3D 0, + }; =20 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); =20 + 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 =3D start_routine(arg); pthread_cleanup_pop(1); + pthread_cleanup_pop(1); =20 #pragma GCC diagnostic pop =20 --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063318; cv=none; d=zohomail.com; s=zohoarc; b=jInyEPkuZEotZFscoQZPv25zIRs771dA4+8N7I2yIkFnyJ8isIGik33G7PL1dbFFNyN66d2/0H5fclvwXdvs/6LlHcsnJEwmlze4nZMj8P784vNylMz4v3AZkknvaspae0LfvvZbrV4ZRpvPu7cDnFjZW8/KOoVEjtJWJghqu3s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063318; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kn2yPrDKKgwsS0hJAc6JBW5Mc5UxaTcj3bqOOrNgn0U=; b=M0H0/YlTM+IN9GSaJP0hrmie+kCKDzQ7dQDvmn+c2deQA04+Kq7zk7OicVnRt93LmTo1WdQIycMyGlpSk5znCMadaV9iqxCRH6juQsyfL8g9rbgpxXod/Yr6IxQpDD7xAsV6Oj2m00U2uUWhPk0kenvz1lz2c5Q3xBf8kWjGCDs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063318914304.3666956655011; Thu, 15 Oct 2026 04:21:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJWU-0002FD-4r; Thu, 15 Oct 2026 07:21:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWT-0002Er-3w for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWR-00044D-Kn for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:20 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-464-6StLNXmrM8ycDjz6fJBXXA-1; Thu, 15 Oct 2026 11:21:15 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 45B8F18009C7; Thu, 15 Oct 2026 11:21:14 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E1EF71800677; Thu, 15 Oct 2026 11:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063279; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kn2yPrDKKgwsS0hJAc6JBW5Mc5UxaTcj3bqOOrNgn0U=; b=dY0q0SJLlPCmWRmMacnVURBV5GOJkj5siul5zpxAb3Im5RnhmDwBq+qRA8wqQXDF3J/f33 vd+wQvcUljku5Aysh0HHHNnZqBK9J+99VHGEB3pjtbPeb9wPwJFEPYdOFr6YOm6cosylzc uf4bieYbEKYQkjszxn3hlnWKZY2vCBI= X-MC-Unique: 6StLNXmrM8ycDjz6fJBXXA-1 X-Mimecast-MFC-AGG-ID: 6StLNXmrM8ycDjz6fJBXXA_1792063274 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 06/21] osdep: provide dummy siginfo_t definition Date: Thu, 15 Oct 2026 12:20:29 +0100 Message-ID: <20261015112044.1999748-7-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063320687158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/osdep.h | 8 ++++++++ meson.build | 2 ++ 2 files changed, 10 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index c1ca2c127b6..fdb61d5d51e 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -635,6 +635,14 @@ void sigaction_invoke(struct sigaction *action, struct qemu_signalfd_siginfo *info); #endif =20 +#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" diff --git a/meson.build b/meson.build index b383c7fceef..c6207443365 100644 --- a/meson.build +++ b/meson.build @@ -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'= )) --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063292; cv=none; d=zohomail.com; s=zohoarc; b=VDDl1LaavqNkabhhghfuhojBL2m1gfQKmtOdAv9lLojRIql9gUv0l6Ui9IUi0lJt8fyHziiGNRLBtohXo78HNEETbdMi8EOSHLL/n1FJ/MfnLHR4dVgPHmtQgx+ODIkKOgrQfT/8UjH0UnrBGcRblwM3HLwacEXcjfHlsi4TLeo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063292; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WmbF2rav6olts7r91nikWE5VNRBJjs1nM9Ql/qEIAzk=; b=lweu4DIsviLCwRsgTsP3AW6eEJzcg96i+DWmcnCUI2n+DqNoziq1DUS71IJ6GrbVSL2e/gCaFtY4NBinP8nksqHKjlAZVghowLn3nyf7UCD+cwCSyMJZ8Ikp+yLMDeGMj3x3jlrVenp4ZBB8g3zN5yJFJt75A+d/D5hSt/P4NH4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063292380918.7661656196506; Thu, 15 Oct 2026 04:21:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJWZ-0002Kb-Ld; Thu, 15 Oct 2026 07:21:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWY-0002J3-JQ for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWV-00045J-LA for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:26 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-7-TvMfxSBrN2e5UdyjGzfKAQ-1; Thu, 15 Oct 2026 11:21:19 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1824818011D5; Thu, 15 Oct 2026 11:21:18 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id ABDB41800677; Thu, 15 Oct 2026 11:21:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063283; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WmbF2rav6olts7r91nikWE5VNRBJjs1nM9Ql/qEIAzk=; b=H3nKjkHsHMcj7CJKbgvf3CXtkMASQOEclQZLbqkBgbrhqPaJk2RyFnFdRIPlKk4Du1FiyD 0xC/YnRoz53wc4+vxfPcx+tWSlQg+LRVIcUyVHlTC/zua6TU7nmDQyW2Fu3TXQbxd5uIC8 L+B0u+w3KBGJdtxDQnPgafsJBRYuopI= X-MC-Unique: TvMfxSBrN2e5UdyjGzfKAQ-1 X-Mimecast-MFC-AGG-ID: TvMfxSBrN2e5UdyjGzfKAQ_1792063278 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 07/21] util: introduce 'tldr', a system data recorder for crash handling Date: Thu, 15 Oct 2026 12:20:30 +0100 Message-ID: <20261015112044.1999748-8-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063294098158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- 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 diff --git a/MAINTAINERS b/MAINTAINERS index 6b5aafe43b1..4fa68810c1e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4772,3 +4772,11 @@ Machine development tool M: Maksim Davydov S: Supported F: scripts/compare-machine-types.py + +Data Recorder +M: Daniel P. Berrang=C3=A9 +S: Maintained +F: util/tldr.c +F: util/tldr-internal.h +F: include/qemu/tldr.h +F: tests/unit/test-util-tldr.c diff --git a/include/qemu/tldr.h b/include/qemu/tldr.h new file mode 100644 index 00000000000..67152b136b3 --- /dev/null +++ b/include/qemu/tldr.h @@ -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__ */ diff --git a/qapi/qom.json b/qapi/qom.json index 49f222796ab..1c9031fba9a 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -1233,6 +1233,19 @@ 'data': { '*pretty': 'bool', '*close-action': 'MonitorQMPCloseAction' } } =20 +## +# @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', diff --git a/qemu-options.hx b/qemu-options.hx index 2f6863180b0..2f63d86b635 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -6682,6 +6682,20 @@ SRST :: =20 (qemu) qom-set /objects/iothread1 poll-max-ns 100000 + + + ``-object tldr-config,id=3Did,crash-target=3Dpath`` + 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 =20 =20 diff --git a/tests/unit/meson.build b/tests/unit/meson.build index d17435c1877..aa02895e767 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -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'], diff --git a/tests/unit/test-util-tldr.c b/tests/unit/test-util-tldr.c new file mode 100644 index 00000000000..4384e10cc18 --- /dev/null +++ b/tests/unit/test-util-tldr.c @@ -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 =3D NULL; + int tmpfd; + char buf[1024]; + ssize_t dumplen; + + tmpfd =3D g_file_open_tmp("test-util-tldr-XXXXXX", + &tmpname, NULL); + unlink(tmpname); + + if (data->siginfo) { + siginfo_t si =3D {}; + si.si_signo =3D 11; /* + * SIGSEGV on Linux, but don't use constant + * since expected output string hardcodes 11 + */ + si.si_code =3D 1; + si.si_addr =3D (void *)0x87539319; + qtldr_crash_dump_internal(tmpfd, &si); + } else { + qtldr_crash_dump_internal(tmpfd, NULL); + } + + lseek(tmpfd, 0, SEEK_SET); + + dumplen =3D read(tmpfd, buf, sizeof(buf)); + + assert(dumplen > 0); + buf[dumplen] =3D '\0'; + + close(tmpfd); + + g_assert_cmpstr(buf, =3D=3D, data->data); +} + + +static void +test_tldr_minimal_default(void) +{ + QTLDRTestData data =3D { + .siginfo =3D false, + .data =3D + QTLDR_DUMP_LEADER + TEST_SIGINFO_NULL + QTLDR_DUMP_TRAILER + }; + + test_tldr_one(&data); +} + + +static void +test_tldr_minimal_siginfo(void) +{ + QTLDRTestData data =3D { + .siginfo =3D true, + .data =3D + 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(); +} diff --git a/util/meson.build b/util/meson.build index fa174c07a57..00c2350c87e 100644 --- a/util/meson.build +++ b/util/meson.build @@ -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')) =20 if have_system util_ss.add(files('crc-ccitt.c')) diff --git a/util/tldr-internal.h b/util/tldr-internal.h new file mode 100644 index 00000000000..193d8425eee --- /dev/null +++ b/util/tldr-internal.h @@ -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=F0=9F=9A=A8=F0=9F=9A=A8=F0=9F=9A=A8 QEMU Dat= a Recorder Start =F0=9F=9A=A8=F0=9F=9A=A8=F0=9F=9A=A8\n" +#define QTLDR_DUMP_TRAILER "\n=F0=9F=9A=A8=F0=9F=9A=A8=F0=9F=9A=A8 QEMU Da= ta Recorder End =F0=9F=9A=A8=F0=9F=9A=A8=F0=9F=9A=A8\n\n" +#define QTLDR_DUMP_TRIGGER_PREFIX "\n=F0=9F=94=8D Trigger:" +#define QTLDR_DUMP_OPEN_ERROR "=F0=9F=94=A5 Unable to dump to '" + +void qtldr_crash_dump_internal(int fd, siginfo_t *si); + +#endif /* QEMU_TLDR_INTERNAL_H__ */ diff --git a/util/tldr.c b/util/tldr.c new file mode 100644 index 00000000000..13e9881bc9b --- /dev/null +++ b/util/tldr.c @@ -0,0 +1,438 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * TL;DR: Thrifty Live Data Recorder + * + * Copyright (C) 2026 Red Hat Inc. + */ + +#include "qemu/osdep.h" +#include "qemu/atomic.h" +#include "util/tldr-internal.h" +#include "qom/object.h" +#include "qom/object_interfaces.h" +#include "qapi/error.h" + +struct QTLDRConfig { + Object parent; + + char *crash_target; +}; + +static int qtldr_active; +static char *qtldr_crash_target; + +#define TYPE_QTLDR_CONFIG "tldr-config" + +OBJECT_DECLARE_SIMPLE_TYPE(QTLDRConfig, QTLDR_CONFIG); + +OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(QTLDRConfig, + qtldr_config, + QTLDR_CONFIG, + OBJECT, + { TYPE_USER_CREATABLE }, + { NULL }); + + +static void +qtldr_config_finalize(Object *obj) +{ + QTLDRConfig *cfg =3D QTLDR_CONFIG(obj); + + g_free(cfg->crash_target); +} + + +static char * +qtldr_config_get_crash_target(Object *obj, Error **errp) +{ + QTLDRConfig *cfg =3D QTLDR_CONFIG(obj); + return g_strdup(cfg->crash_target); +} + + +static void +qtldr_config_set_crash_target(Object *obj, const char *path, Error **errp) +{ + QTLDRConfig *cfg =3D QTLDR_CONFIG(obj); + g_free(cfg->crash_target); + cfg->crash_target =3D g_strdup(path); +} + + +static void +qtldr_config_complete(UserCreatable *uc, Error **errp) +{ + QTLDRConfig *cfg =3D QTLDR_CONFIG(uc); + + /* + * Forbid changes, since once configured, we can't safely + * change it due to signal handlers running without ability + * to hold mutex locks + */ + if (qtldr_crash_target) { + error_setg(errp, "TLDR configuration cannot be changed"); + return; + } + + qatomic_store_release(&qtldr_crash_target, g_strdup(cfg->crash_target)= ); + qatomic_inc(&qtldr_active); +} + + +static bool +qtldr_config_prepare_delete(UserCreatable *uc, Error **errp) +{ + /* + * Forbid deletion, since once configured, we can't safely + * change it due to signal handlers running without ability + * to hold mutex locks + */ + error_setg(errp, "Deleting the 'tldr-config' object is not supported"); + return false; +} + + +static void +qtldr_config_class_init(ObjectClass *klass, const void *opaque) +{ + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(klass); + object_class_property_add_str(klass, "crash-target", + qtldr_config_get_crash_target, + qtldr_config_set_crash_target); + + ucc->complete =3D qtldr_config_complete; + ucc->prepare_delete =3D qtldr_config_prepare_delete; +} + + +static void +qtldr_config_init(Object *obj) +{ +} + + +/* + * WARNING: Code below this marker is used when dumping + * WARNING: the data recorder buffers. It is subject to + * WARNING: execution directly in signal handler context + * WARNING: on a limited stack (SIGSTKSZ). + * + * WARNING: Thus from here onwards must only use async + * WARNING: signal safe POSIX functions. + */ + + +static void +qtldr_write_int_buf(int fd, uint64_t v, + const char *digits, size_t digitslen, + char *target, size_t targetlen) +{ + size_t offset =3D targetlen; + do { + uint64_t r =3D (v % digitslen); + target[--offset] =3D digits[r]; + v /=3D digitslen; + } while (v && offset); + ignore_value(write(fd, target + offset, targetlen - offset)); +} + + +static void +qtldr_write_int_dec(int fd, uint64_t v) +{ + static char digits[] =3D "0123456789"; + char target[20]; + qtldr_write_int_buf(fd, v, digits, strlen(digits), + target, G_N_ELEMENTS(target)); +} + + +static void +qtldr_write_int_hex(int fd, uint64_t v) +{ + static const char digits[] =3D "0123456789abcdef"; + char target[16]; + qtldr_write_int_buf(fd, v, digits, strlen(digits), + target, G_N_ELEMENTS(target)); +} + + +static const char * +qtldr_crash_dump_signal_str(int signo) +{ + switch (signo) { + case SIGSEGV: + return "SIGSEGV"; +#ifndef WIN32 + case SIGBUS: + return "SIGBUS"; +#endif + case SIGABRT: + return "SIGABRT"; + case SIGILL: + return "SIGILL"; + case SIGFPE: + return "SIGFPE"; + } + return NULL; +} + + +static const char * +qtldr_crash_dump_code_str(int signo, int code) +{ + switch (code) { +#ifdef SI_USER + case SI_USER: + return "User process kill"; +#endif +#ifdef SI_KERNEL + case SI_KERNEL: + return "Kernel process kill"; +#endif +#ifdef SI_QUEUE + case SI_QUEUE: + return "Signal queue"; +#endif +#ifdef SI_TIMER + case SI_TIMER: + return "Timer expired"; +#endif +#ifdef SI_MESGQ + case SI_MESGQ: + return "Message queue state changed"; +#endif +#ifdef SI_ASYNCIO + case SI_ASYNCIO: + return "AIO completed"; +#endif +#ifdef SI_TKILL + case SI_TKILL: + return "User thread kill"; +#endif + } + switch (signo) { + case SIGSEGV: + switch (code) { +#ifdef SEGV_MAPERR + case SEGV_MAPERR: + return "Address not mapped"; +#endif +#ifdef SEGV_ACCERR + case SEGV_ACCERR: + return "Access permissions"; +#endif +#ifdef SEGV_BNDERR + case SEGV_BNDERR: + return "Address out of bounds"; +#endif +#ifdef SEGV_PKUERR + case SEGV_PKUERR: + return "Memory protection keys"; +#endif + } + break; + +#ifndef WIN32 + case SIGBUS: + switch (code) { +#ifdef BUS_ADRALN + case BUS_ADRALN: + return "Address alignment"; +#endif +#ifdef BUS_ADDRER + case BUS_ADRERR: + return "Physical address error"; +#endif +#ifdef BUS_OBJERR + case BUS_OBJERR: + return "Object hardware error"; +#endif +#ifdef BUS_MCEERR_AR + case BUS_MCEERR_AR: + return "Memory error, machine check"; +#endif +#ifdef BUS_MCEERR_AO + case BUS_MCEERR_AO: + return "Memory error, not consumed"; +#endif + } + break; +#endif + + case SIGILL: + switch (code) { +#ifdef ILL_ILLOPC + case ILL_ILLOPC: + return "Illegal opcode"; +#endif +#ifdef ILL_ILLOPN + case ILL_ILLOPN: + return "Illegal operand"; +#endif +#ifdef ILL_ILLADR + case ILL_ILLADR: + return "Illegal addressing mode"; +#endif +#ifdef ILL_ILLTRP + case ILL_ILLTRP: + return "Illegal trap"; +#endif +#ifdef ILL_PRVOPC + case ILL_PRVOPC: + return "Privileged opcode"; +#endif +#ifdef ILL_PRVREG + case ILL_PRVREG: + return "Privileged register"; +#endif +#ifdef ILL_COPROC + case ILL_COPROC: + return "Coprocessor error"; +#endif +#ifdef ILL_BADSTK + case ILL_BADSTK: + return "Internal stack error"; +#endif + } + break; + + case SIGFPE: + switch (code) { +#ifdef FPE_INTDIV + case FPE_INTDIV: + return "Integer divide by zero"; +#endif +#ifdef FPE_INTOVF + case FPE_INTOVF: + return "Integer overflow"; +#endif +#ifdef FPE_FLTDIV + case FPE_FLTDIV: + return "Floating-point divide by zero"; +#endif +#ifdef FPE_FLTOVF + case FPE_FLTOVF: + return "Floating-point overflow"; +#endif +#ifdef FPE_FLTUND + case FPE_FLTUND: + return "Floating-point underflow"; +#endif +#ifdef FPE_FLTRES + case FPE_FLTRES: + return "Floating-point inexact result"; +#endif +#ifdef FPE_FLTINV + case FPE_FLTINV: + return "Floating-point invalid operation"; +#endif +#ifdef FPE_FLTSUB + case FPE_FLTSUB: + return "Subscript out of range"; +#endif + } + break; + } + return NULL; +} + + +static void +qtldr_crash_dump_print_field(int fd, const char *label, + const char *valstr, int val) +{ + ignore_value(write(fd, label, strlen(label))); + if (valstr) { + ignore_value(write(fd, valstr, strlen(valstr))); + ignore_value(write(fd, " (", 2)); + } + qtldr_write_int_dec(fd, val); + if (valstr) { + ignore_value(write(fd, ")", 1)); + } + ignore_value(write(fd, "\n", 1)); +} + + +static void +qtldr_crash_dump_print_siginfo(int fd, siginfo_t *si) +{ + const char *signostr =3D qtldr_crash_dump_signal_str(si->si_signo); + const char *codestr =3D qtldr_crash_dump_code_str(si->si_signo, si->si= _code); + ignore_value(write(fd, QTLDR_DUMP_TRIGGER_PREFIX, + strlen(QTLDR_DUMP_TRIGGER_PREFIX))); + ignore_value(write(fd, "\n", 1)); + + qtldr_crash_dump_print_field(fd, " - Signal: ", signostr, si->si_sign= o); + qtldr_crash_dump_print_field(fd, " - Code: ", codestr, si->si_code); + + ignore_value(write(fd, " - Address: 0x", 15)); + qtldr_write_int_hex(fd, (uint64_t)si->si_addr); + ignore_value(write(fd, "\n", 1)); +} + + +void +qtldr_crash_dump_internal(int fd, siginfo_t *si) +{ + if (fd =3D=3D -1) { + fd =3D STDERR_FILENO; + } + + ignore_value(write(fd, QTLDR_DUMP_LEADER, strlen(QTLDR_DUMP_LEADER))); + if (si) { + qtldr_crash_dump_print_siginfo(fd, si); + } else { + ignore_value(write(fd, QTLDR_DUMP_TRIGGER_PREFIX, + strlen(QTLDR_DUMP_TRIGGER_PREFIX))); + ignore_value(write(fd, "manual\n", 7)); + } + + ignore_value(write(fd, QTLDR_DUMP_TRAILER, strlen(QTLDR_DUMP_TRAILER))= ); +} + + +void +qtldr_crash_dump_signal(siginfo_t *si) +{ + int fd =3D STDERR_FILENO; + const char *tgt; + + if (!qatomic_read(&qtldr_active)) { + return; + } + + tgt =3D qatomic_load_acquire(&qtldr_crash_target); + if (tgt) { + /* + * Must NOT use qemu_create, as it is not safe from + * signal handler context due to using monitor APIs + */ + fd =3D open(tgt, O_WRONLY | O_CREAT | O_TRUNC, 0600); + if (fd < 0) { + /* + * Couldn't open our designated crash report + * file location, so fallback to STDERR as + * the least worst next best option, and + * warn the user of the failure + */ + fd =3D STDERR_FILENO; + int saved_errno =3D errno; + ignore_value(write(fd, QTLDR_DUMP_OPEN_ERROR, + strlen(QTLDR_DUMP_OPEN_ERROR))); + ignore_value(write(fd, tgt, strlen(tgt))); + ignore_value(write(fd, "': ", 3)); + qtldr_write_int_dec(fd, saved_errno); + ignore_value(write(fd, "\n", 1)); + } + } + + qtldr_crash_dump_internal(fd, si); + + if (fd !=3D STDERR_FILENO) { + qemu_fdatasync(fd); + close(fd); + } +} --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063336; cv=none; d=zohomail.com; s=zohoarc; b=nBzg9CBACRMatwWYz8iW2x3FnUcy03NOgVppZq514yU1+VyApLNqN08nrBMaBQVbudyLZtxz1jdhU787XkZDSOLFVtIoZNWPsVKQRN3nhHHsTyr1vwsdcwpYdd6dzWVjZUxV4kpdQ5Lh3mLyExSS80mIfsneLP+tlyV0Vw1ix0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063336; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wzuyrR5dOghgw8SJJA0o5GFJw2MvFnUErv0Wo8Ig0rg=; b=YhVsb8H2X+6mbAqpb3WKMaHSnnEAB08AfHm4Apx5P2DDcKGyEUEVPrzD4j1er37oWyKcj98j+0P6Yg8lYbP38w97E8gcFbK81wi2jUloviB4+S/23z35KdKU3SmACa1t20JQbBQ/13JtRMTbyw4UfugYdfK3VaIO4galJP5eCF0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063336301507.1187282954138; Thu, 15 Oct 2026 04:22:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJWb-0002ME-E9; Thu, 15 Oct 2026 07:21:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWZ-0002JH-AV for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWX-00045N-4W for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:27 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-443-R9DTo9RbMOqlyVb-r_PBuw-1; Thu, 15 Oct 2026 11:21:23 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E97A618011D7; Thu, 15 Oct 2026 11:21:21 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 80A101800257; Thu, 15 Oct 2026 11:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063284; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wzuyrR5dOghgw8SJJA0o5GFJw2MvFnUErv0Wo8Ig0rg=; b=D71vBQK9sQ5AI9UDC1fINYVpWPhpBcCCtc0Ke6C8JlV6tcRMZH5S6WK0Fg9yCUYC7TJnTg /ffVLOTuDSi1NBbwNwJpbjuq7T6dO9zxkScVJMSD8BY8yOPZNr1gjqobO2Nu/dCM5OkNbx 7eaQEsATCul56fjvlBeT3dJIb3xEpgo= X-MC-Unique: R9DTo9RbMOqlyVb-r_PBuw-1 X-Mimecast-MFC-AGG-ID: R9DTo9RbMOqlyVb-r_PBuw_1792063282 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 08/21] qapi: add 'tldr-dump' command for on-demand data recorder output Date: Thu, 15 Oct 2026 12:20:31 +0100 Message-ID: <20261015112044.1999748-9-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063336786158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Fabiano Rosas --- 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 diff --git a/MAINTAINERS b/MAINTAINERS index 4fa68810c1e..54265d987cb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -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 diff --git a/qapi/meson.build b/qapi/meson.build index a46269b5a0c..f8aecb61284 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -49,6 +49,7 @@ qapi_all_modules =3D [ 'run-state', 'sockets', 'stats', + 'tldr', 'trace', 'transaction', 'vfio', diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index b93dd68d94c..b36777970d1 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -76,3 +76,4 @@ { 'include': 'cryptodev.json' } { 'include': 'cxl.json' } { 'include': 'uefi.json' } +{ 'include': 'tldr.json' } diff --git a/qapi/tldr.json b/qapi/tldr.json new file mode 100644 index 00000000000..8e2b7cda324 --- /dev/null +++ b/qapi/tldr.json @@ -0,0 +1,28 @@ +# -*- Mode: Python -*- +# vim: filetype=3Dpython +# 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' } diff --git a/qemu-options.hx b/qemu-options.hx index 2f63d86b635..5f96257cef0 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -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. =20 The ``tldr-config`` object can be added at initial startup or via QMP at runtime. Once created, however, it is not diff --git a/util/tldr.c b/util/tldr.c index 13e9881bc9b..ea7c26b8e9b 100644 --- a/util/tldr.c +++ b/util/tldr.c @@ -12,6 +12,7 @@ #include "qom/object.h" #include "qom/object_interfaces.h" #include "qapi/error.h" +#include "qapi/qapi-commands-tldr.h" =20 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 =3D qemu_create(target, O_WRONLY | O_TRUNC, 0600, errp); + if (fd < 0) { + return; + } + + qtldr_crash_dump_internal(fd, NULL); + + qemu_fdatasync(fd); + close(fd); +} --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063390; cv=none; d=zohomail.com; s=zohoarc; b=QIuOcrNpVd1KSLD3vpkMWBv0oOMVzRHoLn934nG6RJnxXp/BdHoTSKQK9hwp8Xu62wjXrzzCYftaonEelVsqqQuSCiY6iWkuIEYGiXUKeZO0zyhkXialt2mCLsGl2QpwZXmTtbZmfnDou7lYu+nhlEZKTP2MPfm4x1RE9tJ1kNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063390; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gTnJllB9fustWggRt0G/FCD+pXdMXjfOMHK6D5h8GU4=; b=k19z2xHvqtflTBs6N0OkcVuUIM/auHeiJRxinRVRrwophdkYbX0+96ZC+J8r3gpnfwEMBqfuKYwx/Cc8UGJJIRPx2yc0R02BaqlrLnC0HDSps457pnzMZMCwsCzt60u4/ZbVwVXin3W4BRUihPprCuiKn+j1smk0hIXHSeXg3qM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063390439126.71814609901662; Thu, 15 Oct 2026 04:23:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJWp-0002g6-VI; Thu, 15 Oct 2026 07:21:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWf-0002Yb-3U for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWd-000464-Em for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:32 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-424-RtYVXydaNfCnE3YxBIVcRg-1; Thu, 15 Oct 2026 11:21:27 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1471D18002E6; Thu, 15 Oct 2026 11:21:26 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 750951800257; Thu, 15 Oct 2026 11:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gTnJllB9fustWggRt0G/FCD+pXdMXjfOMHK6D5h8GU4=; b=FjvjMv8/DmzJb/kKnivUhc1xhgIO4uHQ4jq58b1rbDn6IBE9rZelnZrjTPx2t/+2XN506L qiGyc8Lgb0nvaKNcPfiX6aWDbtigcPf/Oh2w59ZxXYFVJ35zOGjQabeNdrhEB20Z68J17M Xf4vKj5g0ssYvtFK7zFMF0xwJ7g0OWg= X-MC-Unique: RtYVXydaNfCnE3YxBIVcRg-1 X-Mimecast-MFC-AGG-ID: RtYVXydaNfCnE3YxBIVcRg_1792063286 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 09/21] system: trigger TLDR crash dump on unhandled SIGBUS Date: Thu, 15 Oct 2026 12:20:32 +0100 Message-ID: <20261015112044.1999748-10-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063391776158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- system/signal.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/system/signal.c b/system/signal.c index dc5a75e2816..f667b56255d 100644 --- a/system/signal.c +++ b/system/signal.c @@ -27,6 +27,7 @@ #include "hw/core/cpu.h" #include "system/kvm.h" #include "qemu/error-report.h" +#include "qemu/tldr.h" =20 #ifdef CONFIG_LINUX =20 @@ -48,7 +49,7 @@ =20 =20 #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 =3D 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, v= oid *ctx) { if (siginfo->si_code !=3D BUS_MCEERR_AO && siginfo->si_code !=3D BUS_MCEERR_AR) { - sigbus_reraise(); + sigbus_reraise(siginfo); } =20 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); } } } --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063335; cv=none; d=zohomail.com; s=zohoarc; b=V0/Mx/egaClhTqq1h7Od+aw0PcTN6SnHu3Evwnm/8ORfH9yqGop3GuV8ul8/PR8NtennN3j5Z9taNOZTxrIg3TU6faSauJ6VtkTTKSWHJ7lMRgaksPYVyy86zwYthy1iFeM5BtkhlHd91AnbSgVvaFKi3LF/jdQTFZu7IsR2gcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063335; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5haCt0bm54wWL2bVHp0taWIAhiA12SOJQyRH0t+ZRFE=; b=DwGRedxZsMwrPtqYbq4XrOGfHGyZOLh5ojYUxvMRSUKb85Hf3N09TWkd3PDuUiNRvuRA1WtnpsMyf6fHyHeHGIaiQvdlZQ7nDEkA0LDep4VC6PsyomC0GHrKmS/9SAcQsRQrS/eH5nuB30/F5C5uGNIAZwqw7hE7zPg18zSQbsY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063335492253.5908947407487; Thu, 15 Oct 2026 04:22:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJWt-00031Y-SF; Thu, 15 Oct 2026 07:21:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWk-0002e4-Vp for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWj-00046p-Fe for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:38 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-400-j9NgM4cmMjC0JqRR77FYZA-1; Thu, 15 Oct 2026 11:21:31 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 893F91956059; Thu, 15 Oct 2026 11:21:30 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A0A2D1800257; Thu, 15 Oct 2026 11:21:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063296; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5haCt0bm54wWL2bVHp0taWIAhiA12SOJQyRH0t+ZRFE=; b=bvhZJP2MwXz0Tej8lJ+cvAGrq77y0c+zQO2W6mQaXVXVKJB40Vdg9vWoLifPX991EmfsSO M9G0jN4TLUaUsdtpqBWpSya0VMeluSabaLORkF/vA063kLIyzP5yhOWqJbbs5r09TJrc1K 1RYBdO5T4Z3QHPmcHpcNWdJ2GI09RHQ= X-MC-Unique: j9NgM4cmMjC0JqRR77FYZA-1 X-Mimecast-MFC-AGG-ID: j9NgM4cmMjC0JqRR77FYZA_1792063290 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 10/21] system: simplify signal handler logic Date: Thu, 15 Oct 2026 12:20:33 +0100 Message-ID: <20261015112044.1999748-11-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063336737158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- system/signal.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/system/signal.c b/system/signal.c index f667b56255d..88316089fc0 100644 --- a/system/signal.c +++ b/system/signal.c @@ -56,15 +56,12 @@ static void sigbus_reraise(siginfo_t *siginfo) =20 memset(&action, 0, sizeof(action)); action.sa_handler =3D 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) =3D=3D 0); + qtldr_crash_dump_signal(siginfo); + raise(SIGBUS); + sigemptyset(&set); + sigaddset(&set, SIGBUS); + pthread_sigmask(SIG_UNBLOCK, &set, NULL); } =20 static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx) --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063379; cv=none; d=zohomail.com; s=zohoarc; b=TLexhQROSFoYGuoMuY7jGhMz7xunOLgYmP3c1Az+SzG3sqmtZP3RFA0gXSqtzcYh9vpUrkFdimMdjcgHjZpcC53vNeeJPBwAKpdEt0VROyDE72tv5Zs4SHkDnmktVlLxtHJefoqDncsUca+455cUHf5CL0bUmON57mG6DPWhFBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063379; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Wu48miSzSYwIK0yUr6JMWr2KuK6767CBHpbml9amLA0=; b=VzL62+rxAQnCFOy0z7KDhdqIBwtLJBriJqQstz7sc8BDKeK9taQ9NNZ8zVnmMGjvdWMRwCZNeqtl/20QV9i16enjqhm3wBXtwq7BOjp0/Ak9X68t5ewwDVVRPMydtzW9fEhZ3NfgGeXygtIx6ez9gEt1+eauf3vLsr1yYwvJwcw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063379332857.3792467823795; Thu, 15 Oct 2026 04:22:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJWw-00034z-3e; Thu, 15 Oct 2026 07:21:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWm-0002ew-3R for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWj-00046t-VI for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:39 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-664-nQ3LBnxDMmOpstZyX_-pBQ-1; Thu, 15 Oct 2026 11:21:35 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 709631955E9E; Thu, 15 Oct 2026 11:21:34 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F03B91800765; Thu, 15 Oct 2026 11:21:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wu48miSzSYwIK0yUr6JMWr2KuK6767CBHpbml9amLA0=; b=UZkNQf6tm6pwW+WYnlATXZRb3d5djWtn5fNTbUvT/JPTCMdh0T41el+fxe1kMx/4vYaN3d XIUCAnlQhpaUdgT3WBw2xvTAM5FuRk4703aIWJ/4Drp8kykguMKPMwZPmRzioKuiuWKFDg pnyLF+/PqCRIYysZ0xN5LiLXNBkpkU8= X-MC-Unique: nQ3LBnxDMmOpstZyX_-pBQ-1 X-Mimecast-MFC-AGG-ID: nQ3LBnxDMmOpstZyX_-pBQ_1792063294 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 11/21] main: allow SIGBUS in the main loop Date: Thu, 15 Oct 2026 12:20:34 +0100 Message-ID: <20261015112044.1999748-12-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063381515158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- util/main-loop.c | 1 - 1 file changed, 1 deletion(-) diff --git a/util/main-loop.c b/util/main-loop.c index 65e5dbcc941..8d531f5ec90 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -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 --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063387; cv=none; d=zohomail.com; s=zohoarc; b=aqqNsEQleRCCTv24qoB6aS36lYyM/XKEilfux0VWLwwiDLHqdTCEdpgtmf/oV17EvnLa1lDEToURTw/zIZcsv9YWBsMlUBoHldpsaoG8o6yAqBZCuIKFR0UZXAwHW1Pen7tyKZYamlAVUKtDXQuZsjVGV/xats3sfeCuwoggpZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063387; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ikOWBCnGd0ZSp7V1Io6El/Mrne0pg5RABHu9yG81MyQ=; b=GcWsQXB6EqqViqj1MwE/pH6AjpRDkvSSWo+l6NAxs/M5vFspi7Px4sZza1yqtCSNq0rBicyF4P3jcVA/k5/7RdOnoVxlcNEeIMzjf0bXIUs+b3opzzoW4I68Y7LvP4I1e+eNrTogOM8juVN6/EbL6RkQ5o3tjHY8SV4MX2btSvw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063387829869.4855216146514; Thu, 15 Oct 2026 04:23:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJX1-0003Vl-Oa; Thu, 15 Oct 2026 07:21:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWr-0002k4-21 for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWp-00047Y-GU for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:44 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-569-ZXRSdLc8MyeVC86tFGJkKg-1; Thu, 15 Oct 2026 11:21:39 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2F7F818007F4; Thu, 15 Oct 2026 11:21:38 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C191C1800677; Thu, 15 Oct 2026 11:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063302; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ikOWBCnGd0ZSp7V1Io6El/Mrne0pg5RABHu9yG81MyQ=; b=fbdyo2HhpHZUnku1oMnRVnhgJoFJg6WVtelXbUPURYwNDGb+34sLz2Pi5YDz0p7FhWcqdn Dm52JJGDV/tCH3MF3RyX5zvJMv/qmoXPwARPummIyd1CJA0eA8j952XS+xMZt8w657gOWH xbT+cXn5j3i5pBFmkL7TVOplWG8IF8M= X-MC-Unique: ZXRSdLc8MyeVC86tFGJkKg-1 X-Mimecast-MFC-AGG-ID: ZXRSdLc8MyeVC86tFGJkKg_1792063298 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 12/21] system: enable SIGBUS handling on non-Linux platforms Date: Thu, 15 Oct 2026 12:20:35 +0100 Message-ID: <20261015112044.1999748-13-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063389692158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- meson.build | 1 + system/signal.c | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index c6207443365..c96c8884f51 100644 --- a/meson.build +++ b/meson.build @@ -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', pre= fix: '#include ')) 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', diff --git a/system/signal.c b/system/signal.c index 88316089fc0..615704900bc 100644 --- a/system/signal.c +++ b/system/signal.c @@ -48,8 +48,8 @@ #endif /* CONFIG_LINUX */ =20 =20 -#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); } =20 +#ifdef CONFIG_LINUX static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx) { if (siginfo->si_code !=3D BUS_MCEERR_AO && siginfo->si_code !=3D BUS_MCEERR_AR) { - sigbus_reraise(siginfo); + sig_handler(n, siginfo, ctx); } =20 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 =20 void qemu_init_crash_signals(void) { @@ -106,13 +108,19 @@ void qemu_init_crash_signals(void) */ memset(&action, 0, sizeof(action)); action.sa_flags =3D SA_SIGINFO | SA_ONSTACK; +#ifdef CONFIG_LINUX action.sa_sigaction =3D sigbus_handler; +#else + action.sa_sigaction =3D sig_handler; +#endif sigaction(SIGBUS, &action, NULL); =20 +#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 */ --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063329; cv=none; d=zohomail.com; s=zohoarc; b=hGvqNq2YhcQZX0eM5nISnubh9SRVbQuI+4lh4enYYDhrKHNKtI5XUSNK3PzC5ARnN5jMrnOisQsfzcbFGyeLGBdAEeGuIR0DixdegMbOsEOB2llVNS+KXE0tWiD40QXagGK1H5LlqQezSXZIhqvDVHSJUT31SFINt6UfeIOIjfY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063329; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XzlJyDe4zs3886N5xEwtyoKBEt/CgdMwFT2Y2P20zYo=; b=CFiz59JB2bSAMI0Z4zwIDpDMNHxzjj7A/3ETOvft/lhYeuaNm91aTadfwGQF0nB2hMWwRbJyqHg6Zz+yfiSB5Q5jKI/wRiSwO0z6JRLQItoVxtzI1O6eRjOu1I3DDoL/LqLlp5LHq0ZhNaoT5p6ckky2m7tshe6aPg0WC+TEjBY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063329735300.04237534294384; Thu, 15 Oct 2026 04:22:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJWy-0003Mt-Ui; Thu, 15 Oct 2026 07:21:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWv-000358-ED for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWt-000488-Fe for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:48 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-86-JZz9jQJ_Mai0Jf-I2CB70g-1; Thu, 15 Oct 2026 11:21:43 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1A1FA1956040; Thu, 15 Oct 2026 11:21:42 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C8181803A40; Thu, 15 Oct 2026 11:21:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063306; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XzlJyDe4zs3886N5xEwtyoKBEt/CgdMwFT2Y2P20zYo=; b=XCRDQ9FFofC1Al50MFMN95/ZGFwW8HhKfcU8Alszr8DhnT2ANrSmBVrCjgWfN2rQtsUVDp PEzHPrXOfypImpA6Lzx0agY6nP9t0+llMZ9k1FBf4stmffM6rcSBCrryc/NzDTDcwv+/fZ 4k//QFbwFD8Rm66aZBM18tyUAk11HDQ= X-MC-Unique: JZz9jQJ_Mai0Jf-I2CB70g-1 X-Mimecast-MFC-AGG-ID: JZz9jQJ_Mai0Jf-I2CB70g_1792063302 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 13/21] system: enable crash dumps on SIGSEGV, SIGILL, SIGFPE and SIGABRT Date: Thu, 15 Oct 2026 12:20:36 +0100 Message-ID: <20261015112044.1999748-14-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063330673158500 Expand the current SIGBUS crash dumps onto further signals that represent program crashes from bad code or guest OS behaviour. This change covers Windows platforms too, by using the dummy siginfo struct definition from osdeup.h. Note that the signal handler gets unregistered before trying the crash dump, so in the unlikely event that crash dump itself crashes, QEMU will exit, rather than getting into a loop. In a debugger we'll still see the full stack history of the original flaw, just with one extra frame present for the signal handler. Signed-off-by: Daniel P. Berrang=C3=A9 --- system/signal.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/system/signal.c b/system/signal.c index 615704900bc..4568ded4cdd 100644 --- a/system/signal.c +++ b/system/signal.c @@ -56,11 +56,11 @@ static void sig_handler(int n, siginfo_t *siginfo, void= *ctx) =20 memset(&action, 0, sizeof(action)); action.sa_handler =3D SIG_DFL; - assert(sigaction(SIGBUS, &action, NULL) =3D=3D 0); + assert(sigaction(siginfo->si_signo, &action, NULL) =3D=3D 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); } =20 @@ -108,10 +108,13 @@ void qemu_init_crash_signals(void) */ memset(&action, 0, sizeof(action)); action.sa_flags =3D SA_SIGINFO | SA_ONSTACK; + action.sa_sigaction =3D sig_handler; + sigaction(SIGSEGV, &action, NULL); + sigaction(SIGABRT, &action, NULL); + sigaction(SIGILL, &action, NULL); + sigaction(SIGFPE, &action, NULL); #ifdef CONFIG_LINUX action.sa_sigaction =3D sigbus_handler; -#else - action.sa_sigaction =3D sig_handler; #endif sigaction(SIGBUS, &action, NULL); =20 @@ -120,7 +123,27 @@ void qemu_init_crash_signals(void) #endif } #else /* !CONFIG_SIGACTION */ + +static void sig_handler(int signo) +{ + siginfo_t si =3D { + .si_signo =3D signo, + .si_code =3D 0, + .si_addr =3D 0x0, + }; + assert(signal(signo, SIG_DFL) =3D=3D 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 */ --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063341; cv=none; d=zohomail.com; s=zohoarc; b=A3ATepqOW4ace9WFSFd7UD+k+mP4zXcRyyJ5lppj7LgyZY76DN9j8OEJSkHlWWQSjz6xTGcvUY8UTqFmOE1WnuXFCjTYu3S3JsnB34aqTdu/hmepttK5bie4nN/WoxTo9yKGRg1+gqpXU3l57AWgePgntf20K4TZOX85o5R56CI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063341; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UR8HM/wlzD4qLVupKo+DuKdvJTIqEWqiIX3b66yaHv4=; b=W+I045GCGSgcVWumUAlQdb8lph8wUp1VjBiFgfpk8FOSpsWayTjq9MQxSytg0sFE3ItLJCYgTOqIotWUt3WxdRf817d4bS390ydB/v1QXi6ad0xV4n9SCrOf2fYLBf9eKG0Emr8zd0ytKgGss7G8bkVd3GUzSscv6XJak5I12R0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063341346101.1989428109647; Thu, 15 Oct 2026 04:22:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJX8-00040K-C7; Thu, 15 Oct 2026 07:22:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJX5-0003o6-B4 for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJX1-00048z-LE for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:58 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-K5fQMR-QMluXlyjAnpQO1Q-1; Thu, 15 Oct 2026 11:21:47 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 253A21956059; Thu, 15 Oct 2026 11:21:46 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 872C41800677; Thu, 15 Oct 2026 11:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063315; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UR8HM/wlzD4qLVupKo+DuKdvJTIqEWqiIX3b66yaHv4=; b=RmE0DK7dSrkek5EP4lx5d+FCaOAD2DBEeLUYnGH88Gbzg6Rb90HbwHWGYvaBlKgzZ+2k3A ON5UgKq+KHD5CFkHZ3bMIP3l3ub+C7KX/oipfJ6Qd3AzNbOIUo95QR/wrzJyYJAZy228Ev 0Mk7ziBQ+7rYIy3LbiNv+yrB96+JxVc= X-MC-Unique: K5fQMR-QMluXlyjAnpQO1Q-1 X-Mimecast-MFC-AGG-ID: K5fQMR-QMluXlyjAnpQO1Q_1792063306 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 14/21] util: introduce capture of textual messages in data recorder Date: Thu, 15 Oct 2026 12:20:37 +0100 Message-ID: <20261015112044.1999748-15-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063342882158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- 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(-) diff --git a/include/qemu/tldr.h b/include/qemu/tldr.h index 67152b136b3..5766acecb64 100644 --- a/include/qemu/tldr.h +++ b/include/qemu/tldr.h @@ -9,6 +9,58 @@ #ifndef QEMU_TLDR_H__ #define QEMU_TLDR_H__ =20 +#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 diff --git a/qapi/qom.json b/qapi/qom.json index 1c9031fba9a..f1c37bce6c2 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -8,6 +8,7 @@ { 'include': 'block-core.json' } { 'include': 'common.json' } { 'include': 'crypto.json' } +{ 'include': 'tldr.json' } =20 ## # *********************** @@ -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'] } } =20 ## diff --git a/qapi/tldr.json b/qapi/tldr.json index 8e2b7cda324..987d36b91f8 100644 --- a/qapi/tldr.json +++ b/qapi/tldr.json @@ -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' } +} diff --git a/qemu-options.hx b/qemu-options.hx index 5f96257cef0..da9d1e2b7bd 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -6685,6 +6685,8 @@ SRST =20 =20 ``-object tldr-config,id=3Did,crash-target=3Dpath`` + \ + ``-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. =20 + 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. diff --git a/tests/unit/test-util-tldr.c b/tests/unit/test-util-tldr.c index 4384e10cc18..42b4e350540 100644 --- a/tests/unit/test-util-tldr.c +++ b/tests/unit/test-util-tldr.c @@ -9,11 +9,20 @@ #include "qemu/osdep.h" #include "util/tldr-internal.h" =20 +typedef struct { + size_t next; + const char *msg; +} QTLDRTestStep; + typedef struct { bool siginfo; + size_t capacity; + QTLDRTestStep *steps; const char *data; } QTLDRTestData; =20 +static int timestampIndex; + #define TEST_SIGINFO_NULL \ QTLDR_DUMP_TRIGGER_PREFIX "manual\n" =20 @@ -23,15 +32,65 @@ typedef struct { " - Code: Address not mapped (1)\n" \ " - Address: 0x87539319\n" =20 +/* + * Total message length including timestamp, \f, record len, + * message and extra newline will be 58 bytes + */ +#define TEST_MSG_1_TRUNC "mnopqrstuvwxyz\n" +#define TEST_MSG_1 "abcdefghijkl" TEST_MSG_1_TRUNC +#define TEST_MSG_2 "0123456789helloworld!!@@##" +#define TEST_MSG_3 ">$><%><@@@>[*&^()]!!<<<<()\n" +#define TEST_TIMESTAMP_1_TRUNC "026-10-05T16:35:40.601961Z" +#define TEST_TIMESTAMP_1 "2" TEST_TIMESTAMP_1_TRUNC +#define TEST_TIMESTAMP_2_TRUNC "T16:38:40.601961Z" +#define TEST_TIMESTAMP_2 "2026-10-05" TEST_TIMESTAMP_2_TRUNC +#define TEST_TIMESTAMP_3 "2026-10-05T16:40:40.601961Z" + + +static char * +test_tldr_now_str_func(void) +{ + static const char *timestamps[] =3D { + TEST_TIMESTAMP_1, + TEST_TIMESTAMP_2, + TEST_TIMESTAMP_3, + }; + timestampIndex =3D timestampIndex % 3; + return g_strdup(timestamps[timestampIndex++]); +} + =20 static void test_tldr_one(QTLDRTestData *data) { + QTLDRMsgBucket *bucket =3D &(qtldr_msg_buckets[QTLDR_MSG_BUCKET_TYPE_E= RROR]); + size_t i; g_autofree char *tmpname =3D NULL; int tmpfd; char buf[1024]; ssize_t dumplen; =20 + qtldr_msg_enabled_mask =3D (1 << QTLDR_MSG_BUCKET_TYPE_ERROR); + + if (data->capacity && data->steps) { + timestampIndex =3D 0; + + g_clear_pointer(&bucket->buf, g_free); + bucket->allocated =3D 0; + bucket->capacity =3D data->capacity; + bucket->next =3D 0; + + for (i =3D 0; data->steps[i].msg; i++) { + qtldr_msg_record(QTLDR_MSG_BUCKET_TYPE_ERROR, + data->steps[i].msg); + + assert(bucket->next =3D=3D data->steps[i].next); + assert(bucket->allocated =3D=3D data->capacity); + assert(bucket->capacity =3D=3D data->capacity); + assert(bucket->buf !=3D NULL); + } + } + tmpfd =3D g_file_open_tmp("test-util-tldr-XXXXXX", &tmpname, NULL); unlink(tmpname); @@ -92,14 +151,227 @@ test_tldr_minimal_siginfo(void) } =20 =20 +/* + * A single message which easily fits in the buffer + * to sanity check minimal functionality + */ +static void +test_tldr_msgs_simple(void) +{ + QTLDRTestData data =3D { + .capacity =3D 70, + .steps =3D (QTLDRTestStep[]){ + { .next =3D 55, .msg =3D TEST_MSG_1 }, + { .next =3D -1, .msg =3D NULL }, + }, + .data =3D + QTLDR_DUMP_LEADER + TEST_SIGINFO_NULL + QTLDR_DUMP_MSG_BUCKET_PREFIX "error':\n" + TEST_TIMESTAMP_1 " " TEST_MSG_1 + QTLDR_DUMP_TRAILER + }; + + test_tldr_one(&data); +} + + +/* + * A pair of messages which exactly hit the buffer + * size to sanity check we wrap back to start on + * the limit. + */ +static void +test_tldr_msgs_exact(void) +{ + QTLDRTestData data =3D { + .capacity =3D 110, + .steps =3D (QTLDRTestStep[]){ + { .next =3D 55, .msg =3D TEST_MSG_1 }, + { .next =3D 0, .msg =3D TEST_MSG_2 }, + { .next =3D -1, .msg =3D NULL }, + }, + .data =3D + QTLDR_DUMP_LEADER + TEST_SIGINFO_NULL + QTLDR_DUMP_MSG_BUCKET_PREFIX "error':\n" + TEST_TIMESTAMP_1 " " TEST_MSG_1 + TEST_TIMESTAMP_2 " " TEST_MSG_2 "\n" + QTLDR_DUMP_TRAILER + }; + + test_tldr_one(&data); +} + + +/* + * A pair of messages which easily exceed the buffer + * size to sanity check we wrap and overwrite existing + * old data + */ +static void +test_tldr_msgs_wrap_simple(void) +{ + QTLDRTestData data =3D { + .capacity =3D 70, + .steps =3D (QTLDRTestStep[]){ + { .next =3D 55, .msg =3D TEST_MSG_1 }, + { .next =3D 40, .msg =3D TEST_MSG_2 }, + { .next =3D -1, .msg =3D NULL }, + }, + .data =3D + QTLDR_DUMP_LEADER + TEST_SIGINFO_NULL + QTLDR_DUMP_MSG_BUCKET_PREFIX "error':\n" + TEST_MSG_1_TRUNC + TEST_TIMESTAMP_2 " " TEST_MSG_2 "\n" + QTLDR_DUMP_TRAILER + }; + + test_tldr_one(&data); +} + + +/* + * A pair of messages which both exactly match the + * buffer size to further sanity check wrapping + * behaviour + */ +static void +test_tldr_msgs_wrap_exact(void) +{ + QTLDRTestData data =3D { + .capacity =3D 55, + .steps =3D (QTLDRTestStep[]){ + { .next =3D 0, .msg =3D TEST_MSG_1 }, + { .next =3D 0, .msg =3D TEST_MSG_2 }, + { .next =3D -1, .msg =3D NULL }, + }, + .data =3D + QTLDR_DUMP_LEADER + TEST_SIGINFO_NULL + QTLDR_DUMP_MSG_BUCKET_PREFIX "error':\n" + TEST_TIMESTAMP_2 " " TEST_MSG_2 "\n" + QTLDR_DUMP_TRAILER + }; + + test_tldr_one(&data); +} + + +/* + * A set of messages where first two are one less + * than the buffer size, to further sanity check + * wrapping behaviour + */ +static void +test_tldr_msgs_wrap_oneextra(void) +{ + QTLDRTestData data =3D { + .capacity =3D 111, + .steps =3D (QTLDRTestStep[]){ + { .next =3D 55, .msg =3D TEST_MSG_1 }, + { .next =3D 110, .msg =3D TEST_MSG_2 }, + { .next =3D 54, .msg =3D TEST_MSG_3 }, + { .next =3D -1, .msg =3D NULL }, + }, + .data =3D + QTLDR_DUMP_LEADER + TEST_SIGINFO_NULL + QTLDR_DUMP_MSG_BUCKET_PREFIX "error':\n" + "\n" + TEST_TIMESTAMP_2 " " TEST_MSG_2 "\n" + TEST_TIMESTAMP_3 " " TEST_MSG_3 + QTLDR_DUMP_TRAILER + }; + + test_tldr_one(&data); +} + + +/* + * A set of messages where first two are one larger + * than the buffer size, to further sanity check + * wrapping behaviour + */ +static void +test_tldr_msgs_wrap_oneunder(void) +{ + QTLDRTestData data =3D { + .capacity =3D 109, + .steps =3D (QTLDRTestStep[]){ + { .next =3D 55, .msg =3D TEST_MSG_1 }, + { .next =3D 1, .msg =3D TEST_MSG_2 }, + { .next =3D -1, .msg =3D NULL }, + }, + .data =3D + QTLDR_DUMP_LEADER + TEST_SIGINFO_NULL + QTLDR_DUMP_MSG_BUCKET_PREFIX "error':\n" + TEST_TIMESTAMP_1_TRUNC " " TEST_MSG_1 + TEST_TIMESTAMP_2 " " TEST_MSG_2 "\n" + QTLDR_DUMP_TRAILER + }; + + test_tldr_one(&data); +} + + +/* + * A set of messages that make us wrap around + * many times over. + */ +static void +test_tldr_msgs_wrap_repeat(void) +{ + QTLDRTestData data =3D { + .capacity =3D 100, + .steps =3D (QTLDRTestStep[]){ + { .next =3D 55, .msg =3D TEST_MSG_1 }, + { .next =3D 10, .msg =3D TEST_MSG_2 }, + { .next =3D 65, .msg =3D TEST_MSG_3 }, + { .next =3D 20, .msg =3D TEST_MSG_1 }, + { .next =3D 75, .msg =3D TEST_MSG_2 }, + { .next =3D 30, .msg =3D TEST_MSG_3 }, + { .next =3D -1, .msg =3D NULL }, + }, + .data =3D + QTLDR_DUMP_LEADER + TEST_SIGINFO_NULL + QTLDR_DUMP_MSG_BUCKET_PREFIX "error':\n" + TEST_TIMESTAMP_2_TRUNC " " TEST_MSG_2 "\n" + TEST_TIMESTAMP_3 " " TEST_MSG_3 + QTLDR_DUMP_TRAILER + }; + + test_tldr_one(&data); +} + + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); =20 + qtldr_now_str_func =3D test_tldr_now_str_func; + g_test_add_func("/util/tldr/minimal/default", test_tldr_minimal_default); g_test_add_func("/util/tldr/minimal/siginfo", test_tldr_minimal_siginfo); + g_test_add_func("/util/tldr/msgs/simple", + test_tldr_msgs_simple); + g_test_add_func("/util/tldr/msgs/exact", + test_tldr_msgs_exact); + g_test_add_func("/util/tldr/msgs/wrap/simple", + test_tldr_msgs_wrap_simple); + g_test_add_func("/util/tldr/msgs/wrap/exact", + test_tldr_msgs_wrap_exact); + g_test_add_func("/util/tldr/msgs/wrap/oneextra", + test_tldr_msgs_wrap_oneextra); + g_test_add_func("/util/tldr/msgs/wrap/oneunder", + test_tldr_msgs_wrap_oneunder); + g_test_add_func("/util/tldr/msgs/wrap/repeat", + test_tldr_msgs_wrap_repeat); =20 return g_test_run(); } diff --git a/util/tldr-internal.h b/util/tldr-internal.h index 193d8425eee..f523565db85 100644 --- a/util/tldr-internal.h +++ b/util/tldr-internal.h @@ -14,8 +14,39 @@ #define QTLDR_DUMP_LEADER "\n=F0=9F=9A=A8=F0=9F=9A=A8=F0=9F=9A=A8 QEMU Dat= a Recorder Start =F0=9F=9A=A8=F0=9F=9A=A8=F0=9F=9A=A8\n" #define QTLDR_DUMP_TRAILER "\n=F0=9F=9A=A8=F0=9F=9A=A8=F0=9F=9A=A8 QEMU Da= ta Recorder End =F0=9F=9A=A8=F0=9F=9A=A8=F0=9F=9A=A8\n\n" #define QTLDR_DUMP_TRIGGER_PREFIX "\n=F0=9F=94=8D Trigger:" +#define QTLDR_DUMP_MSG_BUCKET_PREFIX "\n=F0=9F=8E=A5 Message recording '" #define QTLDR_DUMP_OPEN_ERROR "=F0=9F=94=A5 Unable to dump to '" =20 +/* + * 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); =20 #endif /* QEMU_TLDR_INTERNAL_H__ */ diff --git a/util/tldr.c b/util/tldr.c index ea7c26b8e9b..34922d82ee4 100644 --- a/util/tldr.c +++ b/util/tldr.c @@ -8,20 +8,26 @@ =20 #include "qemu/osdep.h" #include "qemu/atomic.h" +#include "qemu/thread.h" #include "util/tldr-internal.h" #include "qom/object.h" #include "qom/object_interfaces.h" #include "qapi/error.h" #include "qapi/qapi-commands-tldr.h" +#include "qapi/qapi-visit-tldr.h" =20 struct QTLDRConfig { Object parent; =20 char *crash_target; + QTLDRMsgBucketConfigList *messages; }; =20 +static QemuMutex qtldr_lock; static int qtldr_active; static char *qtldr_crash_target; +QTLDRMsgBucket qtldr_msg_buckets[QTLDR_MSG_BUCKET_TYPE__MAX]; +unsigned int qtldr_msg_enabled_mask; =20 #define TYPE_QTLDR_CONFIG "tldr-config" =20 @@ -34,6 +40,22 @@ OBJECT_DEFINE_SIMPLE_TYPE_WITH_INTERFACES(QTLDRConfig, { TYPE_USER_CREATABLE }, { NULL }); =20 +static char * +qtldr_now_str_func_default(void) +{ + g_autoptr(GDateTime) dt =3D g_date_time_new_now_utc(); + return g_date_time_format_iso8601(dt); +} + +char *(*qtldr_now_str_func)(void) =3D qtldr_now_str_func_default; + + +static void __attribute__((constructor)) +qtldr_global_init(void) +{ + qemu_mutex_init(&qtldr_lock); +} + =20 static void qtldr_config_finalize(Object *obj) @@ -41,6 +63,7 @@ qtldr_config_finalize(Object *obj) QTLDRConfig *cfg =3D QTLDR_CONFIG(obj); =20 g_free(cfg->crash_target); + qapi_free_QTLDRMsgBucketConfigList(cfg->messages); } =20 =20 @@ -60,24 +83,93 @@ qtldr_config_set_crash_target(Object *obj, const char *= path, Error **errp) cfg->crash_target =3D g_strdup(path); } =20 +static void qtldr_config_get_messages(Object *obj, Visitor *v, const char = *name, + void *opaque, Error **errp) +{ + QTLDRConfig *cfg =3D QTLDR_CONFIG(obj); + + visit_type_QTLDRMsgBucketConfigList(v, name, &cfg->messages, errp); +} + +static void qtldr_config_set_messages(Object *obj, Visitor *v, const char = *name, + void *opaque, Error **errp) +{ + QTLDRConfig *cfg =3D QTLDR_CONFIG(obj); + QTLDRMsgBucketConfigList *oldmsgs; + + oldmsgs =3D cfg->messages; + visit_type_QTLDRMsgBucketConfigList(v, name, &cfg->messages, errp); + + qapi_free_QTLDRMsgBucketConfigList(oldmsgs); +} =20 static void qtldr_config_complete(UserCreatable *uc, Error **errp) { QTLDRConfig *cfg =3D QTLDR_CONFIG(uc); + QTLDRMsgBucketConfigList *messages =3D cfg->messages; =20 /* * Forbid changes, since once configured, we can't safely * change it due to signal handlers running without ability * to hold mutex locks */ - if (qtldr_crash_target) { + if (qtldr_crash_target || qtldr_msg_enabled_mask) { error_setg(errp, "TLDR configuration cannot be changed"); return; } =20 + /* + * Sanity check before changing anything, so errors don't + * leave us in a partially configured state + */ + while (messages) { + QTLDRMsgBucketConfig *msgcfg =3D messages->value; + assert(msgcfg->type < QTLDR_MSG_BUCKET_TYPE__MAX); + + if (msgcfg->has_capacity && + msgcfg->capacity <=3D QTLDR_MSG_ENTRY_MAX_BYTES) { + error_setg(errp, "Message bucket capacity must be greater than= %d", + QTLDR_MSG_ENTRY_MAX_BYTES); + return; + } + messages =3D messages->next; + } + + qemu_mutex_lock(&qtldr_lock); qatomic_store_release(&qtldr_crash_target, g_strdup(cfg->crash_target)= ); + + messages =3D cfg->messages; + while (messages) { + QTLDRMsgBucketConfig *msgcfg =3D messages->value; + assert(msgcfg->type < QTLDR_MSG_BUCKET_TYPE__MAX); + + if (msgcfg->has_capacity) { + qtldr_msg_buckets[msgcfg->type].capacity =3D msgcfg->capacity; + } else { + qtldr_msg_buckets[msgcfg->type].capacity =3D + QTLDR_MSG_BUCKET_SIZE_BYTES; + } + + qtldr_msg_enabled_mask |=3D (1 << msgcfg->type); + + messages =3D messages->next; + } + + if (!cfg->messages) { + size_t i; + qtldr_msg_enabled_mask =3D + (1 << QTLDR_MSG_BUCKET_TYPE_ERROR) | + (1 << QTLDR_MSG_BUCKET_TYPE_COMMAND) | + (1 << QTLDR_MSG_BUCKET_TYPE_EVENT) | + (1 << QTLDR_MSG_BUCKET_TYPE_LOG); + for (i =3D 0; i < QTLDR_MSG_BUCKET_TYPE__MAX; i++) { + qtldr_msg_buckets[i].capacity =3D QTLDR_MSG_BUCKET_SIZE_BYTES; + } + } + qatomic_inc(&qtldr_active); + qemu_mutex_unlock(&qtldr_lock); } =20 =20 @@ -101,6 +193,10 @@ qtldr_config_class_init(ObjectClass *klass, const void= *opaque) object_class_property_add_str(klass, "crash-target", qtldr_config_get_crash_target, qtldr_config_set_crash_target); + object_class_property_add(klass, "messages", "QTLDRMsgBucketConfigList= ", + qtldr_config_get_messages, + qtldr_config_set_messages, + NULL, NULL); =20 ucc->complete =3D qtldr_config_complete; ucc->prepare_delete =3D qtldr_config_prepare_delete; @@ -113,6 +209,145 @@ qtldr_config_init(Object *obj) } =20 =20 +/* + * WARNING: The data recorder is intended to be called from + * WARNING: many places within QEMU, including tracing, error + * WARNING: reporting and logging code. + * + * WARNING: The code following this marker is used in the call + * WARNING: chain from qtldr_msg_record() and must be self + * WARNING: contained and performance oriented. + */ + +static void +qtldr_msg_record_ensure_size(QTLDRMsgBucket *bucket, + size_t need) +{ + /* + * If bucket is not yet at max size then we can't have + * wrapped the buffer and so 'head' must reflect the + * amount of written data so far. + */ + if (bucket->allocated < bucket->capacity) { + size_t space =3D bucket->allocated - bucket->next; + if (space < need) { + size_t newlen =3D MIN(bucket->capacity, + bucket->allocated + MAX(4096, need - space= )); + bucket->buf =3D g_realloc(bucket->buf, newlen); + /* + * Fill with zeros, so the dumping method + * knows what is unused so far. + */ + memset(bucket->buf + bucket->allocated, '\0', + newlen - bucket->allocated); + qatomic_store_release(&bucket->allocated, newlen); + } + } +} + + +static size_t +qtldr_msg_record_append_buf(QTLDRMsgBucket *bucket, + size_t next, + const void *buf, + size_t len) +{ + size_t forend =3D MIN(bucket->allocated - next, len); + size_t forfront =3D len - forend; + + if (forend) { + memcpy(bucket->buf + next, buf, forend); + } + if (forfront) { + memcpy(bucket->buf, buf + forend, forfront); + return forfront; + } else { + return (next + forend) % bucket->allocated; + } +} + + +void +qtldr_msg_record(QTLDRMsgBucketType type, + const char *msg) +{ + QTLDRMsgBucket *bucket; + size_t msglen, timelen; + g_autofree char *timestr =3D qtldr_now_str_func(); + bool addnl =3D false; + uint16_t recordlen; + size_t next; + + assert(type < QTLDR_MSG_BUCKET_TYPE__MAX); + if (!qtldr_msg_enabled(type)) { + return; + } + + qemu_mutex_lock(&qtldr_lock); + + bucket =3D &qtldr_msg_buckets[type]; + timelen =3D strlen(timestr); + msglen =3D strlen(msg); + + recordlen =3D timelen + 1 /* " " */ + msglen; + if (recordlen > (QTLDR_MSG_ENTRY_MAX_BYTES - 1)) { + size_t cut =3D (QTLDR_MSG_ENTRY_MAX_BYTES - 1) - recordlen; + msglen -=3D cut; + recordlen -=3D cut; + } + + if (msglen && msg[msglen - 1] !=3D '\n') { + addnl =3D true; + recordlen++; + } + + + qtldr_msg_record_ensure_size(bucket, recordlen); + next =3D qtldr_msg_record_append_buf(bucket, bucket->next, timestr, ti= melen); + next =3D qtldr_msg_record_append_buf(bucket, next, " ", 1); + next =3D qtldr_msg_record_append_buf(bucket, next, msg, msglen); + if (addnl) { + next =3D qtldr_msg_record_append_buf(bucket, next, "\n", 1); + } + + /* + * We could be racing with a signal handler dumping text + * outside the mutex lock, so while we write text without + * any sync, we atomically change the "next" pointer. + * + * Worst case, some text the signal handler dumps will be + * "new" instead of old part of the buffer. + */ + qatomic_store_release(&bucket->next, next); + qemu_mutex_unlock(&qtldr_lock); +} + + +void +qtldr_msg_record_printf(QTLDRMsgBucketType type, + const char *fmt, ...) +{ + char msg[1024]; + va_list ap; + + va_start(ap, fmt); + vsnprintf(msg, G_N_ELEMENTS(msg), fmt, ap); + va_end(ap); + + qtldr_msg_record(type, msg); +} + + +void +qtldr_msg_record_vprintf(QTLDRMsgBucketType type, + const char *fmt, va_list ap) +{ + char msg[1024]; + vsnprintf(msg, G_N_ELEMENTS(msg), fmt, ap); + qtldr_msg_record(type, msg); +} + + /* * WARNING: Code below this marker is used when dumping * WARNING: the data recorder buffers. It is subject to @@ -159,6 +394,43 @@ qtldr_write_int_hex(int fd, uint64_t v) } =20 =20 +static void +qtldr_crash_dump_msg(int fd, QTLDRMsgBucketType type, QTLDRMsgBucket *buck= et) +{ + size_t allocated, head; + + if (!bucket->allocated) { + return; + } + ignore_value(write(fd, QTLDR_DUMP_MSG_BUCKET_PREFIX, + strlen(QTLDR_DUMP_MSG_BUCKET_PREFIX))); + ignore_value(write(fd, QTLDRMsgBucketType_str(type), + strlen(QTLDRMsgBucketType_str(type)))); + ignore_value(write(fd, "':\n", 3)); + + /* + * We're potentially racing with a thread appending. + * Load 'head' first, so we're guaranteed it does + * not point beyond the 'allocated' region, should + * we be racing with buffer enlargement + */ + head =3D qatomic_load_acquire(&bucket->next); + allocated =3D qatomic_load_acquire(&bucket->allocated); + + /* + * If we haven't wrapped around yet, the allocated but + * unused space is filled with NULs. We can assume + * that no valid messages contain NULs, since we used + * "strlen" when writing messages originally. + */ + if (bucket->buf[head] !=3D '\0') { + ignore_value(write(fd, bucket->buf + head, + allocated - head)); + } + ignore_value(write(fd, bucket->buf, head)); +} + + static const char * qtldr_crash_dump_signal_str(int signo) { @@ -378,6 +650,8 @@ qtldr_crash_dump_print_siginfo(int fd, siginfo_t *si) void qtldr_crash_dump_internal(int fd, siginfo_t *si) { + size_t i; + if (fd =3D=3D -1) { fd =3D STDERR_FILENO; } @@ -391,6 +665,10 @@ qtldr_crash_dump_internal(int fd, siginfo_t *si) ignore_value(write(fd, "manual\n", 7)); } =20 + for (i =3D 0; i < QTLDR_MSG_BUCKET_TYPE__MAX; i++) { + qtldr_crash_dump_msg(fd, i, &qtldr_msg_buckets[i]); + } + ignore_value(write(fd, QTLDR_DUMP_TRAILER, strlen(QTLDR_DUMP_TRAILER))= ); } =20 @@ -463,7 +741,9 @@ qmp_tldr_dump(const char *target, Error **errp) return; } =20 + qemu_mutex_lock(&qtldr_lock); qtldr_crash_dump_internal(fd, NULL); + qemu_mutex_unlock(&qtldr_lock); =20 qemu_fdatasync(fd); close(fd); --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063347; cv=none; d=zohomail.com; s=zohoarc; b=YzZ4JokyXu0hu90wdQ8b99s0ES78eYWQHO+Fmuke+V1TmVEQq+AwlpZlmpQBDZ8G4a6ZUu5xPyQyvbihty4co9vyxg0E/vwu5mlb6W/XTNiEhwiaSjAcFdqsySJl6VwrwH71SwGIEaCqa+fVmNVWSTgn/3dl3Q5Z70ot3998gz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063347; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PZKmmbraeh9Kl20GcdX853uFGdOFcVe3/sO8XnVPYP0=; b=Rva+wFexwh7+FSSwOFcL9yHFpHnx7l/P8V66WiQdrfxb7J6yz/eT8d2/iVjPQPzSp8s/qftyXFZXCjgKsewK5xF1YFgrg7EfVjH1zv+q4fWwuZtF0L05AUIUki6pYOjvl94O+lyIYTpsFo1vMzbAdC0RIYEh3W3DrPsdStqBKQU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063347312150.16639419423404; Thu, 15 Oct 2026 04:22:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJX5-0003j2-4a; Thu, 15 Oct 2026 07:21:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJX0-0003UZ-Rt for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJWz-00048k-4D for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:21:54 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-QxZJN_W6NJGyubl20goTyA-1; Thu, 15 Oct 2026 11:21:51 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DFDC819560AA; Thu, 15 Oct 2026 11:21:49 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 88FEC1800257; Thu, 15 Oct 2026 11:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063312; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PZKmmbraeh9Kl20GcdX853uFGdOFcVe3/sO8XnVPYP0=; b=JzTKTAx8ceRLieoWQwB2vrj4d/FEdSpIZBLys4ckNh6kiRvXIIi6I/mc1z2pep3zt68SdU p/Cd3DqYD1X/Lg9j8LJxO5nzLStZWhRcgUMlBUQ78EROK6UczbAcjmaBfC5JSiAu/tWQwT LW0JY+llItSXsdx63kpZgSqg98AcXQw= X-MC-Unique: QxZJN_W6NJGyubl20goTyA-1 X-Mimecast-MFC-AGG-ID: QxZJN_W6NJGyubl20goTyA_1792063310 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 15/21] util: capture warnings and errors in the data recorder Date: Thu, 15 Oct 2026 12:20:38 +0100 Message-ID: <20261015112044.1999748-16-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063349023158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- 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 diff --git a/MAINTAINERS b/MAINTAINERS index 54265d987cb..3a7cd827e66 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -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 =20 Network device backends M: Jason Wang diff --git a/stubs/meson.build b/stubs/meson.build index 29b6644b254..52c733e32a9 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -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')) diff --git a/stubs/monitor-puts.c b/stubs/monitor-puts.c new file mode 100644 index 00000000000..bb9b726dd5e --- /dev/null +++ b/stubs/monitor-puts.c @@ -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(); +} diff --git a/util/error-report.c b/util/error-report.c index 8932beebfb9..251d8b7d16e 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "monitor/hmp.h" #include "qemu/error-report.h" +#include "qemu/tldr.h" =20 /* * @report_type is the type of message: error, warning or @@ -32,28 +33,32 @@ const char *error_guest_name; /* * Print to the @hmp monitor, else to stderr. */ -static int G_GNUC_PRINTF(2, 0) -error_vprintf_hmp(MonitorHMP *hmp, const char *fmt, va_list ap) +static int G_GNUC_PRINTF(3, 0) +error_vprintf_hmp(MonitorHMP *hmp, bool tldr, const char *fmt, va_list ap) { + g_autofree char *str =3D g_strdup_vprintf(fmt, ap); + if (qtldr_msg_enabled(QTLDR_MSG_BUCKET_TYPE_ERROR) && tldr) { + qtldr_msg_record(QTLDR_MSG_BUCKET_TYPE_ERROR, str); + } #ifdef CONFIG_HMP if (hmp) { - return monitor_hmp_vprintf(hmp, fmt, ap); + return monitor_puts(MONITOR(hmp), str); } #endif - return vfprintf(stderr, fmt, ap); + return fwrite(str, 1, strlen(str), stderr); } =20 /* * Print to the @hmp monitor, else to stderr. */ -static int G_GNUC_PRINTF(2, 3) -error_printf_hmp(MonitorHMP *hmp, const char *fmt, ...) +static int G_GNUC_PRINTF(3, 4) +error_printf_hmp(MonitorHMP *hmp, bool tldr, const char *fmt, ...) { va_list ap; int ret; =20 va_start(ap, fmt); - ret =3D error_vprintf_hmp(hmp, fmt, ap); + ret =3D error_vprintf_hmp(hmp, tldr, fmt, ap); va_end(ap); return ret; } @@ -63,7 +68,7 @@ error_printf_hmp(MonitorHMP *hmp, const char *fmt, ...) */ int error_vprintf(const char *fmt, va_list ap) { - return error_vprintf_hmp(monitor_cur_hmp(), fmt, ap); + return error_vprintf_hmp(monitor_cur_hmp(), true, fmt, ap); } =20 /* @@ -75,7 +80,7 @@ int error_printf(const char *fmt, ...) int ret; =20 va_start(ap, fmt); - ret =3D error_vprintf_hmp(monitor_cur_hmp(), fmt, ap); + ret =3D error_vprintf_hmp(monitor_cur_hmp(), true, fmt, ap); va_end(ap); return ret; } @@ -193,20 +198,20 @@ static void print_loc(MonitorHMP *hmp) case LOC_CMDLINE: argp =3D cur_loc->ptr; for (i =3D 0; i < cur_loc->num; i++) { - error_printf_hmp(hmp, "%s%s", sep, argp[i]); + error_printf_hmp(hmp, false, "%s%s", sep, argp[i]); sep =3D " "; } - error_printf_hmp(hmp, ": "); + error_printf_hmp(hmp, false, ": "); break; case LOC_FILE: - error_printf_hmp(hmp, "%s:", (const char *)cur_loc->ptr); + error_printf_hmp(hmp, false, "%s:", (const char *)cur_loc->ptr); if (cur_loc->num) { - error_printf_hmp(hmp, "%d:", cur_loc->num); + error_printf_hmp(hmp, false, "%d:", cur_loc->num); } - error_printf_hmp(hmp, " "); + error_printf_hmp(hmp, false, " "); break; default: - error_printf_hmp(hmp, "%s", sep); + error_printf_hmp(hmp, false, "%s", sep); } } =20 @@ -251,15 +256,15 @@ static void vreport(report_type type, const char *fmt= , va_list ap) case REPORT_TYPE_ERROR: break; case REPORT_TYPE_WARNING: - error_printf_hmp(hmp, "warning: "); + error_printf_hmp(hmp, false, "warning: "); break; case REPORT_TYPE_INFO: - error_printf_hmp(hmp, "info: "); + error_printf_hmp(hmp, false, "info: "); break; } =20 - error_vprintf_hmp(hmp, fmt, ap); - error_printf_hmp(hmp, "\n"); + error_vprintf_hmp(hmp, true, fmt, ap); + error_printf_hmp(hmp, false, "\n"); =20 if (!hmp) { qemu_funlockfile(stderr); --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063346; cv=none; d=zohomail.com; s=zohoarc; b=RiHSraJLtcNm/pf8CYBWBawz10gFhek4W7qbvBimxyChn/f3is/ZKIljtr+c19cP6BSCQ8FybCpe7BdR2jIVY0vxiwVll6iCrhADlA5B+9eHbNZZuBQIx14Tlc/0gHhi9mWlXxrWl8n9TYngUNjFTaQGmN27Yw3oWdS3euhrV04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063346; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sRRYIQzBm9AdCh/M/BnHxN2UdPWPfu66Z4pmlnKzGGo=; b=Nos9Jkm7O1TEJ5JWd1CX0LK1QIitkhApfB5d7CEluuZqna36varrra16tvopWb8Ut7DNI7ftIUNfJJRMSnLxx78BrGu/aOPuf4wlDkh861v+JPGD2DrvXd+otmRtNqKju/geMKrn9jx045blL80B8Swap1ygIjqI0tOLKC3bWIY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063346269294.49136078772165; Thu, 15 Oct 2026 04:22:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJXB-0004Fl-Ax; Thu, 15 Oct 2026 07:22:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJX7-00040D-OL for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:22:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJX6-00049Y-9Z for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:22:01 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-407-ccjKyR8EOKetrAYyUe5dRQ-1; Thu, 15 Oct 2026 11:21:55 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BCCB21955F17; Thu, 15 Oct 2026 11:21:53 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 52AA51800677; Thu, 15 Oct 2026 11:21:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063319; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sRRYIQzBm9AdCh/M/BnHxN2UdPWPfu66Z4pmlnKzGGo=; b=VmlhWiWyxMBKRdtTjDTuozB7EoDTn2fUZZUt6MAJNKqE3KLrBer9Ij+XO0/5Dc3pWbvHv9 f1XKDIJv2S99v0qkUXdoYR+iQeG8Ni0rFmtftlZ476VuAxOmFu8b54CwI6mAIDGqIn6viQ zNT9cP6Zu4mHW2rkPSjv3z27dk1dl3w= X-MC-Unique: ccjKyR8EOKetrAYyUe5dRQ-1 X-Mimecast-MFC-AGG-ID: ccjKyR8EOKetrAYyUe5dRQ_1792063313 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 16/21] monitor: remove obsolete/redundant exports Date: Thu, 15 Oct 2026 12:20:39 +0100 Message-ID: <20261015112044.1999748-17-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063346932158500 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) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Markus Armbruster --- monitor/monitor-internal.h | 2 -- monitor/qmp.c | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 822a66d06d0..dfdb8fb8caa 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -122,8 +122,6 @@ void monitor_cancel_out_watch(Monitor *mon); void monitor_list_append(Monitor *mon); void monitor_fdsets_cleanup(void); =20 -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); =20 diff --git a/monitor/qmp.c b/monitor/qmp.c index aec03157750..ccb39a48d4c 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -80,6 +80,7 @@ static MonitorQMP *qmp_dispatcher_current_mon; OBJECT_DEFINE_TYPE(MonitorQMP, monitor_qmp, MONITOR_QMP, MONITOR); =20 static void monitor_qmp_cleanup_req_queue_locked(MonitorQMP *mon); +static void qmp_send_response(MonitorQMP *mon, const QDict *rsp); =20 static void monitor_qmp_finalize(Object *obj) { @@ -242,7 +243,7 @@ static void monitor_qmp_cleanup_queue_and_resume(Monito= rQMP *mon) =20 } =20 -void qmp_send_response(MonitorQMP *mon, const QDict *rsp) +static void qmp_send_response(MonitorQMP *mon, const QDict *rsp) { const QObject *data =3D QOBJECT(rsp); GString *json; --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063338; cv=none; d=zohomail.com; s=zohoarc; b=F9kqz9uZ0/OcnH7nW8eq73IvTCT/6yEYFsyNMJypOebatL+1ZjlY3PCVDigPZjlreT1tC43wVuEU1H1ZOV9ch88byQ51Nyg1nuTWarYxgWJUPNzxV5FtzxNUT2F6wkf23yIs2rN9roYMEXTmURL48ZeERvOanA4FCSRuLYpJHbw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063338; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=291beaW8H/SmRMZ3rzIXf8UTtlKNS0ohfqrHvHqrY8g=; b=XhUVhJE8XqW3Bs+pWVcwLIDhfsbT2UDEG2vpS0N1UatAvJqycIZir0imTCSRA5PWIv5DIHrkcqN/ZiF0ohtnoxQorPgLX/x2N7C7KjKoO2nnsBqcqqUpp12K2072Jn0IxlN+NB0PjZkVowm66g3+HHJHP2DPZvMudGtBE5dx47o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063338416298.2881131047792; Thu, 15 Oct 2026 04:22:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJXE-0004Pr-BC; Thu, 15 Oct 2026 07:22:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJXA-0004Fc-T4 for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:22:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJX8-0004A1-VU for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:22:04 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-394-NZCPBX9FP7CpWN3oXL3PMA-1; Thu, 15 Oct 2026 11:21:59 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B0BEE1955F70; Thu, 15 Oct 2026 11:21:57 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3064A1800257; Thu, 15 Oct 2026 11:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=291beaW8H/SmRMZ3rzIXf8UTtlKNS0ohfqrHvHqrY8g=; b=NkzfNFIwBad/UGH53NVMATxVJdFmXgkH2FjASdDuoDurYkCgMY1qbMs5Fm1PQ3R8pbFL7F wBwk1yUE07JoXwEjAjWG6O6SPCWB6vsKq2uNR6RX/EfHmjPJPqo0wIrTmBdjhxO+2EjXJV azmsyrQI4zDIB2e69vEqhyPzmDo789w= X-MC-Unique: NZCPBX9FP7CpWN3oXL3PMA-1 X-Mimecast-MFC-AGG-ID: NZCPBX9FP7CpWN3oXL3PMA_1792063317 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 17/21] monitor: capture monitor commands and events in data recorder Date: Thu, 15 Oct 2026 12:20:40 +0100 Message-ID: <20261015112044.1999748-18-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063339989158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- monitor/qmp.c | 67 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/monitor/qmp.c b/monitor/qmp.c index ccb39a48d4c..659ad23d832 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -34,6 +34,7 @@ #include "qobject/qjson.h" #include "qobject/qlist.h" #include "qom/object_interfaces.h" +#include "qemu/tldr.h" #include "trace.h" =20 /* @@ -80,7 +81,8 @@ static MonitorQMP *qmp_dispatcher_current_mon; OBJECT_DEFINE_TYPE(MonitorQMP, monitor_qmp, MONITOR_QMP, MONITOR); =20 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); =20 static void monitor_qmp_finalize(Object *obj) { @@ -169,7 +171,7 @@ static void monitor_qmp_emit_event(Monitor *mon, QAPIEv= ent event, QDict *qdict) } } =20 - qmp_send_response(qmp, qdict); + qmp_send_response(qmp, qdict, NULL); } =20 static bool monitor_qmp_requires_iothread(const Monitor *mon) @@ -243,7 +245,8 @@ static void monitor_qmp_cleanup_queue_and_resume(Monito= rQMP *mon) =20 } =20 -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 =3D QOBJECT(rsp); GString *json; @@ -252,6 +255,30 @@ static void qmp_send_response(MonitorQMP *mon, const Q= Dict *rsp) assert(json !=3D NULL); trace_monitor_qmp_respond(mon, json->str); =20 + /* + * 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 =3D 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); =20 @@ -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); } } =20 @@ -276,9 +303,33 @@ static void monitor_qmp_respond(MonitorQMP *mon, QDict= *rsp) */ static void monitor_qmp_dispatch(MonitorQMP *mon, QObject *req) { + QObject *ctx =3D req; QDict *rsp; QDict *error; =20 + /* + * 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 =3D qobject_to(QDict, req); + if (cmd !=3D NULL) { + const char *cmdname =3D qdict_get_try_str(cmd, "execute") + ?: qdict_get_try_str(cmd, "exec-oob"); + if (cmdname !=3D NULL && + !g_str_has_prefix(cmdname, "query-") && + !g_str_has_prefix(cmdname, "qom-list")) { + g_autoptr(GString) cmdstr =3D qobject_to_json(req); + qtldr_msg_record(QTLDR_MSG_BUCKET_TYPE_COMMAND, cmdstr->st= r); + /* + * Prevent recording cmd twice if the later response + * is an error + */ + ctx =3D NULL; + } + } + } + rsp =3D qmp_dispatch(mon->commands, req, qmp_oob_enabled(mon), &mon->parent_obj); =20 @@ -294,7 +345,7 @@ static void monitor_qmp_dispatch(MonitorQMP *mon, QObje= ct *req) } } =20 - monitor_qmp_respond(mon, rsp); + monitor_qmp_respond(mon, rsp, ctx); qobject_unref(rsp); } =20 @@ -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 =3D qmp_error_response(req_obj->err); req_obj->err =3D NULL; - monitor_qmp_respond(mon, rsp); + monitor_qmp_respond(mon, rsp, NULL); qobject_unref(rsp); } =20 @@ -623,7 +674,7 @@ static void monitor_qmp_event(void *opaque, QEMUChrEven= t event) monitor_qmp_caps_reset(mon); } data =3D qmp_greeting(mon); - qmp_send_response(mon, data); + qmp_send_response(mon, data, NULL); qobject_unref(data); break; case CHR_EVENT_CLOSED: --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063357; cv=none; d=zohomail.com; s=zohoarc; b=Hy26BikXo+GlvjgSbVQlO6fnHHNygknwercu+4a7WZQX941UfEDIRNogSZT+3+g/wFw4s+Tvap1/uIKRh44+ouO2DrL6JIfHkZwx40cr3KIH7h2DnZCThjq6swIV3np/RhUW8wN6rbamPis1dCYgAScJ39Tw7xoJxAD0BRPazZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063357; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=B+zhWeQKtUX98A0ZtH2YiRpOcgZq3pNyAaVSkumucB4=; b=h5O14yKzdDdnlluMHr6uXuOkx93i8TTwFP3QuYHOTs/N4PbCWk3oaIIDT3CUeq+/5edSo8mzSN8t4ki2aaToFXzk88uitYMUFi2nFkHuMv10CN3hZb8kxQ6YpPLh60TdL5JcV4PMv1dJk5MsjpQjd7G079Lv3XIXR8ASDfrylsQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063357232889.1804764114107; Thu, 15 Oct 2026 04:22:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJXJ-0004fD-3Y; Thu, 15 Oct 2026 07:22:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJXE-0004UM-SR for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:22:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJXD-0004AU-15 for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:22:08 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-474-wCRrl8GaNjif1atdC9KAXg-1; Thu, 15 Oct 2026 11:22:03 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A286318007E8; Thu, 15 Oct 2026 11:22:01 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 23F891800677; Thu, 15 Oct 2026 11:21:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063326; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B+zhWeQKtUX98A0ZtH2YiRpOcgZq3pNyAaVSkumucB4=; b=Yhdn7YIbfsnskmkk45PWQFt0CpeQRpbJY6YEH6tJnJvRzuupQWKs7mA5DJNO7+O6Dat0WI IZTTQUGI5RG7IF4NYP1pytxTcthuUZ2Q1k2jVQW9/rEKd4WuibYeBcsaDj0APJJLE+LHnN D7YfVgLhzJJcY6eDdWk+WoZwyU8xlQc= X-MC-Unique: wCRrl8GaNjif1atdC9KAXg-1 X-Mimecast-MFC-AGG-ID: wCRrl8GaNjif1atdC9KAXg_1792063321 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 18/21] log: enable directing log messages to data recorder Date: Thu, 15 Oct 2026 12:20:41 +0100 Message-ID: <20261015112044.1999748-19-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063359257158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- include/qemu/log.h | 1 + util/log.c | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/include/qemu/log.h b/include/qemu/log.h index 92956e5d0f5..47d89681d8e 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -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) =20 /* Lock/unlock output. */ =20 diff --git a/util/log.c b/util/log.c index 7cffbc1bf89..df7499012f6 100644 --- a/util/log.c +++ b/util/log.c @@ -27,6 +27,7 @@ #include "qemu/thread.h" #include "qemu/lockable.h" #include "qemu/rcu.h" +#include "qemu/tldr.h" #ifdef CONFIG_LINUX #include #endif @@ -172,12 +173,20 @@ void qemu_log_unlock(FILE *logfile) =20 void qemu_log(const char *fmt, ...) { - FILE *f =3D qemu_log_trylock_with_context(); - if (f) { - va_list ap; - va_start(ap, fmt); - vfprintf(f, fmt, ap); - va_end(ap); + va_list ap; + if (qemu_loglevel & LOG_TLDR) { + if (qtldr_msg_enabled(QTLDR_MSG_BUCKET_TYPE_LOG)) { + va_start(ap, fmt); + qtldr_msg_record_vprintf(QTLDR_MSG_BUCKET_TYPE_LOG, fmt, ap); + va_end(ap); + } + } else { + FILE *f =3D qemu_log_trylock_with_context(); + if (f) { + va_start(ap, fmt); + vfprintf(f, fmt, ap); + va_end(ap); + } qemu_log_unlock(f); } } @@ -236,6 +245,7 @@ static bool qemu_set_log_internal(const char *filename,= bool changed_name, bool need_to_open_file; bool daemonized; bool per_thread; + bool tldr; FILE *logfile; =20 QEMU_LOCK_GUARD(&global_mutex); @@ -251,8 +261,20 @@ static bool qemu_set_log_internal(const char *filename= , bool changed_name, } =20 per_thread =3D log_flags & LOG_PER_THREAD; + tldr =3D log_flags & LOG_TLDR; =20 - if (changed_name) { + if (tldr) { + if (filename) { + error_setg(errp, "Cannot enable TLDR with a log file"); + return false; + } + if (per_thread) { + error_setg(errp, "Cannot enable TLDR with per-thread log files= "); + return false; + } + } + + if (changed_name && !tldr) { char *newname =3D NULL; =20 /* @@ -282,7 +304,7 @@ static bool qemu_set_log_internal(const char *filename,= bool changed_name, g_free(global_filename); global_filename =3D newname; filename =3D newname; - } else { + } else if (!tldr) { filename =3D global_filename; if (per_thread && valid_filename_template(filename, true, errp) =3D=3D vft_error= ) { @@ -309,7 +331,7 @@ static bool qemu_set_log_internal(const char *filename,= bool changed_name, * stderr or to a file (if there is a filename). * If per-thread, open the file for each thread in qemu_log_tryloc= k(). */ - need_to_open_file =3D qemu_loglevel && !log_per_thread; + need_to_open_file =3D qemu_loglevel && !log_per_thread && !tldr; } else { /* * If we are daemonized, we will only log if there is a filename. @@ -531,6 +553,8 @@ const QEMULogItem qemu_log_items[] =3D { "include VPU registers in the 'cpu' logging" }, { LOG_INVALID_MEM, "invalid_mem", "log invalid memory accesses" }, + { LOG_TLDR, "tldr", + "log to QEMU data recorder instead ofa file" }, { 0, NULL, NULL }, }; =20 --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063410; cv=none; d=zohomail.com; s=zohoarc; b=LcfxU3QXnoV367yq+Uz0ANkk0+uHFq4zOr9p91u5k+adRRCstcO9b1vX/rhdICEJp59dL6zNAMmrFwk/Oky49l4kaee93Uw7JFCvqZ6xUPWmOI3z1ZOH3E6rXxbx+MvH+XeardG9M4RYcab4IcgxS8BlrAHFdP0hMFLkClsL3QQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063410; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1CsPZct2byPKvJCqqrPOQ9z+NngHcWHt2CGXzjTTRak=; b=W8dRQN3ZIGJ1Mx18ipG4ymC+JsdCcoI+0afLiWBTZJStNQx/iDi+7mWw6epKPVwUsHHFsJeV28G3jICQE2WNJryWxCipYAs/hARoVz2sGot0wtmlxG3oqN3LsxjIGPGElh1drTaExcuAbA5MVc+1Gi+FRjg3bOIGS6n08dLU1S8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063410121176.4615047425399; Thu, 15 Oct 2026 04:23:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJXM-0004po-5z; Thu, 15 Oct 2026 07:22:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJXJ-0004gr-2q for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:22:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJXH-0004B4-8S for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:22:12 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-327-qH5gjgKzMQCzzrzuC_n6Ag-1; Thu, 15 Oct 2026 11:22:06 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 592F61800667; Thu, 15 Oct 2026 11:22:05 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 099D11800677; Thu, 15 Oct 2026 11:22:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1CsPZct2byPKvJCqqrPOQ9z+NngHcWHt2CGXzjTTRak=; b=Ortkahk+lV4eo8mHQoYeeWJesR0j3Zm1XmC+ymR5l9K+Zc6xfLP6CTduAM8I+W2QpfmmzR 6NYOwbOZOGHWXTBmJ/SupncX16dQx7Nb4qTLMrobXxhzLOioozCu6Z/GtnDBIkOQFO/3yL IcMIzM1NKN4w5nB3f6Dq+57ZXCf4ASA= X-MC-Unique: qH5gjgKzMQCzzrzuC_n6Ag-1 X-Mimecast-MFC-AGG-ID: qH5gjgKzMQCzzrzuC_n6Ag_1792063325 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 19/21] tests/qtest: add API to declare an expected crash signal Date: Thu, 15 Oct 2026 12:20:42 +0100 Message-ID: <20261015112044.1999748-20-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063412176158500 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. Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/qtest/libqtest.c | 36 +++++++++++++++++++++++++++--------- tests/qtest/libqtest.h | 11 +++++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 05d88476154..e65451171e4 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -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 stat= us) s->expected_status =3D status; } =20 +#ifndef _WIN32 +void qtest_set_expected_signal(QTestState *s, int signal) +{ + s->expected_signal =3D signal; +} +#endif + static void qtest_check_status(QTestState *s) { assert(s->qemu_pid =3D=3D -1); @@ -195,20 +205,28 @@ static void qtest_check_status(QTestState *s) */ #ifndef _WIN32 int wstatus =3D s->wstatus; - if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) !=3D 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_stat= us); - abort(); + if (WIFEXITED(wstatus)) { + if (s->expected_signal) { + fprintf(stderr, "%s:%d: encountered exit status %d but expecte= d signal %d\n", + __FILE__, __LINE__, WEXITSTATUS(wstatus), s->expected_= signal); + abort(); + } else if (WEXITSTATUS(wstatus) !=3D 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 =3D WTERMSIG(wstatus); const char *signame =3D strsignal(sig) ?: "unknown ???"; const char *dump =3D WCOREDUMP(wstatus) ? " (core dumped)" : ""; =20 - fprintf(stderr, "%s:%d: kill_qemu() detected QEMU death " - "from signal %d (%s)%s\n", - __FILE__, __LINE__, sig, signame, dump); - abort(); + if (sig !=3D 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 !=3D s->expected_status) { diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h index 20982d3fe8d..ddcf075e33a 100644 --- a/tests/qtest/libqtest.h +++ b/tests/qtest/libqtest.h @@ -1155,6 +1155,17 @@ bool qtest_probe_child(QTestState *s); */ void qtest_set_expected_status(QTestState *s, int status); =20 +#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*)); =20 --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063361; cv=none; d=zohomail.com; s=zohoarc; b=EwAVpQIPo0pRxF0zXwFnzKv3Z6eBV2j6I+X20sAH37EMygz2FsX0G2JsXvtEoJUw/6stg8b5LIJuxY2Nmbbc7jeZ70AI0InCj/FeeIr2whFVuEtUJOX2ajGzr/Wfs+fU5OJdmaWpvhsZKqtz7Pu/jnEVsXYvN/NhEbyjJt4x7hA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063361; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=d0V+1Yt9bM+H+erMJRFKkFIUv64UmwFBKlWbudq0rME=; b=In0/T6B1rs2RyMP3dXVthg9BSuZ2+BDRafynFzuLmXZQwDdv5PC0yCTx5xGfPK94mwJPvVfiJ5dwpgHaz/9hbU2RAZ82YRW0l1RRDsu2OFbbL4v8UeNI69iQoR/iuvjSdNQw1/w++m6hlkOJFGtCMsGCMmMi9+ZdsA9NarFJ3YA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063361340695.1144693803519; Thu, 15 Oct 2026 04:22:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJXQ-000592-5U; Thu, 15 Oct 2026 07:22:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJXM-0004sn-Uk for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:22:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJXK-0004BQ-Q3 for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:22:16 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-KeOFUiyfMz-5cIQtDWHduQ-1; Thu, 15 Oct 2026 11:22:10 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 22AE91800BC6; Thu, 15 Oct 2026 11:22:09 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BEE051800257; Thu, 15 Oct 2026 11:22:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063334; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d0V+1Yt9bM+H+erMJRFKkFIUv64UmwFBKlWbudq0rME=; b=gDgrkQS1uMU3t1oSNpZhk9GZ45TDEzkW+N9tjYWm9MRPqIZir1vDD/SY9HF/OH7Bsre4NZ 5DTKndG1GvxEfJFE4ebDP1bqK9/DO/nHSCUPda9BVq1dBv6LPalP6bl4urzUqiOcvA/K2S AlGI6IX4EtRQ9TtwLFRJpJiPet9MSms= X-MC-Unique: KeOFUiyfMz-5cIQtDWHduQ-1 X-Mimecast-MFC-AGG-ID: KeOFUiyfMz-5cIQtDWHduQ_1792063329 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 20/21] qtest: add 'crash' command to generate 'authentic' process crashes Date: Thu, 15 Oct 2026 12:20:43 +0100 Message-ID: <20261015112044.1999748-21-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063363289158500 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 Signed-off-by: Daniel P. Berrang=C3=A9 --- system/qtest.c | 50 ++++++++++++++++++++++++++++++++++++++++++ tests/qtest/libqtest.c | 26 ++++++++++++++++++++++ tests/qtest/libqtest.h | 16 ++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/system/qtest.c b/system/qtest.c index 47c954838dd..0ff04cf24e8 100644 --- a/system/qtest.c +++ b/system/qtest.c @@ -811,6 +811,56 @@ static void qtest_process_command(CharFrontend *chr, g= char **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") =3D=3D 0) { + if (strcmp(words[1], "null-pointer") =3D=3D 0) { + char *c =3D (void *)0x0; + *c =3D 'a'; /* SIGSEGV */ + } else if (strcmp(words[1], "invalid-addr") =3D=3D 0) { + /* Hopefully invalid addr on all supported targets */ + char *c =3D (void *)0x12345; + *c =3D 'b'; /* SIGSEGV */ +#ifndef WIN32 + } else if (strcmp(words[1], "mapping-not-backed") =3D=3D 0) { + char *m; + g_autofree char *tmpname =3D NULL; + int tmpfd =3D g_file_open_tmp("qtestcrash-XXXXXX", &tmpname, N= ULL); + m =3D (char *)mmap(0, 4, PROT_WRITE, MAP_PRIVATE, tmpfd, 0); + unlink(tmpname); + assert(m !=3D 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] =3D 0; /* SIGBUS */ +#if defined(__x86_64__) || defined(__aarch64__) + } else if (strcmp(words[1], "bad-alignment") =3D=3D 0) { + /* + * XXX: can we assume any other arches will generate + * bus errors on unaligned writes ? + */ + char *cptr =3D g_malloc(sizeof(int) + 1) + 1; + int *iptr =3D (int *)cptr; +#ifdef __x86_64__ + /* Turn on alignment checks */ + __asm__("pushf\norl $0x40000,(%rsp)\npopf"); +#endif + *iptr =3D 42; /* SIGBUS */ +#endif +#endif + } else if (strcmp(words[1], "fpe-div-zero") =3D=3D 0) { + volatile int foo =3D 1729; /* volatile to stop optimizing */ + volatile int bar =3D 0; /* volatile to stop optimizing */ + + foo =3D foo / bar; /* SIGFPE */ + (void)foo; + } else if (strcmp(words[1], "assert") =3D=3D 0) { + assert(1 =3D=3D 2); /* SIGABRT */ + } else if (strcmp(words[1], "illegal-inst") =3D=3D 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 { diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index e65451171e4..d6ca97b1c11 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -828,6 +828,32 @@ static int qtest_query_target_endianness(QTestState *s) return big_endian; } =20 +static const char *crashtypestr[] =3D { + "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) =3D=3D 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 =3D recv(s->fd, buf, sizeof(buf), 0); + if (len !=3D 0) { + g_printerr("Expected crash from QEMU but saw qtest reply"); + abort(); + } +} + QDict *qtest_qmp_receive(QTestState *s) { while (true) { diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h index ddcf075e33a..4988e627592 100644 --- a/tests/qtest/libqtest.h +++ b/tests/qtest/libqtest.h @@ -1232,4 +1232,20 @@ bool mkimg(const char *file, const char *fmt, unsign= ed size_mb); */ bool qtest_verbose(const char *domain); =20 +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 --=20 2.56.0 From nobody Mon Nov 23 04:44:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1792063406; cv=none; d=zohomail.com; s=zohoarc; b=QazMnivhKF2t8KgTSBwXKDkqzX8xmiKW58ev92td61jcn3RMgCfo4VIA0mTkO8ruNad5Cd0iBghm0kPtsDUkja88Qq37KdhnGz/6Tn5aDsLbSIQE0thH+AQ8zE43N2U6iO9fzZRQBUhhj6hDFHP7Tc4Th6QyUnBOMhtoT1yjtDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792063406; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6vLizomyPwqHlqTEjyg8D92Xsk6Hhk4CiZI2lAtTgxY=; b=W9WSQgg+o64+/UeyoZLmyeUvdEuSPBKEGh8/Pz79ZxrkiOE9PcxmIf2Tj6OfLvY+COMuR3wac9kTiAM4pavKDv1Royc8SPfbtq3JjM3oc2qbgmKGyidn30ehfQq+CtpQilsvs8bKYuW1KiIrcxwJltJtbLS2XjkyfiZbCrDyeTM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1792063406772539.852307742611; Thu, 15 Oct 2026 04:23:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xHJXr-0006IQ-M1; Thu, 15 Oct 2026 07:22:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJXc-0005qM-4s for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:22:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xHJXa-0004Cd-9B for qemu-devel@nongnu.org; Thu, 15 Oct 2026 07:22:31 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-540-3q5SrAryO1usPkma5n3Uqw-1; Thu, 15 Oct 2026 11:22:14 +0000 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EFA98180067A; Thu, 15 Oct 2026 11:22:12 +0000 (UTC) Received: from berrange.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 88BBF1800677; Thu, 15 Oct 2026 11:22:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792063349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6vLizomyPwqHlqTEjyg8D92Xsk6Hhk4CiZI2lAtTgxY=; b=I7VB7wMhWF4/phsuc3D8xC/ehc2qqahaCR+QxU1sOaxQxuvc5QmVKjKxo8wQUj2ldUuP+3 LLEQDtcxS+NwYY0O5yFUuQ6JVLzGbXH4ObJspNvrbsv9qXjIJQaGAS0znx1fia94DabR3+ V7V/KQF93DDHEObBeQK1WoDNCHvt458= X-MC-Unique: 3q5SrAryO1usPkma5n3Uqw-1 X-Mimecast-MFC-AGG-ID: 3q5SrAryO1usPkma5n3Uqw_1792063333 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Markus Armbruster , Pierrick Bouvier , Eric Blake , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Laurent Vivier Subject: [PATCH 21/21] tests/qtest: add test to validate data recorder on crashes Date: Thu, 15 Oct 2026 12:20:44 +0100 Message-ID: <20261015112044.1999748-22-berrange@redhat.com> In-Reply-To: <20261015112044.1999748-1-berrange@redhat.com> References: <20261015112044.1999748-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1792063408066158500 Use qtest to trigger a QEMU crash and validate that a data recorder crash dump is written to disk. Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/qtest/meson.build | 3 + tests/qtest/tldr-test.c | 124 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 tests/qtest/tldr-test.c diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 200abf6f36d..c7bba9ea828 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -27,6 +27,9 @@ qtests_generic =3D [ 'qmp-cmd-test', 'qom-test', ] +if host_os !=3D 'windows' + qtests_generic +=3D ['tldr-test'] +endif if have_hmp qtests_generic +=3D [ 'test-hmp', diff --git a/tests/qtest/tldr-test.c b/tests/qtest/tldr-test.c new file mode 100644 index 00000000000..b20d44577af --- /dev/null +++ b/tests/qtest/tldr-test.c @@ -0,0 +1,124 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * QTest testcase for the data recorder (tldr) + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "util/tldr-internal.h" + + +static QTestState *qtldr_test_start(const char *crashfile) +{ + return qtest_initf("-object tldr-config,id=3Dtldr,crash-target=3D%s", = crashfile); +} + +static void test_crash(QTestCrashType type, int signo) +{ + QTestState *qts =3D NULL; + g_autofree char *crashfile =3D NULL; + g_autofree char *crashreport =3D NULL; + size_t crashlen =3D 0; + int fd =3D g_file_open_tmp("tldr-test-XXXXXX", + &crashfile, NULL); + assert(fd !=3D -1); + qts =3D qtldr_test_start(crashfile); + + qtest_crash(qts, type); + + assert(g_file_get_contents(crashfile, &crashreport, &crashlen, NULL)); + close(fd); + unlink(crashfile); + qtest_set_expected_signal(qts, signo); + qtest_quit(qts); + + assert(crashlen !=3D 0); + assert(strstr(crashreport, QTLDR_DUMP_LEADER)); + assert(strstr(crashreport, QTLDR_DUMP_TRIGGER_PREFIX)); + assert(strstr(crashreport, QTLDR_DUMP_MSG_BUCKET_PREFIX)); + assert(strstr(crashreport, QTLDR_DUMP_TRAILER)); +} + +static void test_crash_null_pointer(void) +{ + test_crash(QTEST_CRASH_NULL_POINTER, SIGSEGV); +} + +static void test_crash_invalid_addr(void) +{ + test_crash(QTEST_CRASH_INVALID_ADDR, SIGSEGV); +} + +static void test_crash_mapping_not_backed(void) +{ + test_crash(QTEST_CRASH_MAPPING_NOT_BACKED, SIGBUS); +} + +#if defined(__x86_64__) || defined(__aarch64__) +static void test_crash_bad_alignment(void) +{ + test_crash(QTEST_CRASH_BAD_ALIGNMENT, SIGBUS); +} +#endif + +static void test_crash_fpe_div_zero(void) +{ + test_crash(QTEST_CRASH_FPE_DIV_ZERO, SIGFPE); +} + + +static void test_crash_assert(void) +{ + test_crash(QTEST_CRASH_ASSERT, SIGABRT); +} + +static void test_crash_illegal_inst(void) +{ + test_crash(QTEST_CRASH_ILLEGAL_INST, SIGILL); +} + +static void test_qmp(void) +{ + QTestState *qts =3D NULL; + g_autofree char *crashfile =3D NULL; + g_autofree char *crashreport =3D NULL; + size_t crashlen =3D 0; + int fd =3D g_file_open_tmp("tldr-test-XXXXXX", + &crashfile, NULL); + assert(fd !=3D -1); + qts =3D qtldr_test_start(crashfile); + + qtest_qmp_assert_success( + qts, "{'execute':'tldr-dump','arguments':{'target': %s}}", + crashfile); + + assert(g_file_get_contents(crashfile, &crashreport, &crashlen, NULL)); + close(fd); + unlink(crashfile); + qtest_quit(qts); + + assert(crashlen !=3D 0); + assert(strstr(crashreport, QTLDR_DUMP_LEADER)); + assert(strstr(crashreport, QTLDR_DUMP_TRIGGER_PREFIX)); + assert(strstr(crashreport, QTLDR_DUMP_MSG_BUCKET_PREFIX)); + assert(strstr(crashreport, QTLDR_DUMP_TRAILER)); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/tldr/null-pointer", test_crash_null_pointer); + qtest_add_func("/tldr/invalid-addr", test_crash_invalid_addr); + qtest_add_func("/tldr/mapping-not-backed", test_crash_mapping_not_back= ed); +#if defined(__x86_64__) || defined(__aarch64__) + qtest_add_func("/tldr/bad-alignment", test_crash_bad_alignment); +#endif + qtest_add_func("/tldr/fpe-div-zero", test_crash_fpe_div_zero); + qtest_add_func("/tldr/assert", test_crash_assert); + qtest_add_func("/tldr/illegal-inst", test_crash_illegal_inst); + qtest_add_func("/tldr/qmp", test_qmp); + + return g_test_run(); +} --=20 2.56.0