From nobody Sun Jul 26 11:51:04 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; arc=pass (i=1 dmarc=pass fromdomain=openchip.com); dmarc=pass(p=quarantine dis=none) header.from=openchip.com ARC-Seal: i=2; a=rsa-sha256; t=1784194928; cv=pass; d=zohomail.com; s=zohoarc; b=Ib2DscaqgXRDuYJQyKm1q2BItv6HOTcT6y/WdRGmDS/8nyVwcqAIuHDlLA+UqBdpXL9ebZ41gDsep4C9kZRx9AwNFYjmz2czshmY9hVdBqrE0Cuh6AgJ+LdNgHJPLGcYFyWnlrO2GwSQfPHf3gw4tN0BevqU9n2LTahezIfaECg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784194928; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CpCzWY5tiUgIPiLPumDlsQIlukWz2ii4OV5AwM+R4t0=; b=AAgCk7xkUUrb0KGoWxgXrtKbdjuW4lP1m3G06Yb7qQB5Jc7q9A6JcA9KTLu4n/jmwN97N/GurifkmLW+nZokjKukKJpw563W3f70/t3yxm0Grj1eubmNIo6ESSisvKu465FR6ELXaYQm2gjzTmkjjg+lcptkyD7CeHr2heg/Tn4= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=openchip.com); 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 1784194928558695.1360198169449; Thu, 16 Jul 2026 02:42:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkIbG-0001hv-5f; Thu, 16 Jul 2026 05:41: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 1wkIbE-0001fb-J4 for qemu-devel@nongnu.org; Thu, 16 Jul 2026 05:41:48 -0400 Received: from mail-westeuropeazlp170110003.outbound.protection.outlook.com ([2a01:111:f403:c201::3] helo=AS8PR04CU009.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkIbC-0000Nl-JW for qemu-devel@nongnu.org; Thu, 16 Jul 2026 05:41:48 -0400 Received: from GV2P192MB3464.EURP192.PROD.OUTLOOK.COM (2603:10a6:150:328::6) by VI1P192MB2186.EURP192.PROD.OUTLOOK.COM (2603:10a6:800:1c9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.202.18; Thu, 16 Jul 2026 09:41:43 +0000 Received: from GV2P192MB3464.EURP192.PROD.OUTLOOK.COM ([fe80::7ed0:3600:9df4:af64]) by GV2P192MB3464.EURP192.PROD.OUTLOOK.COM ([fe80::7ed0:3600:9df4:af64%6]) with mapi id 15.21.0223.008; Thu, 16 Jul 2026 09:41:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ivM5jMau31bKUDf/98ENKG0M14ITGka/t7ehMO3o2WfrsyoJMptz8VIMqqsytTLVQzPbXrMHBnj6dju2SL4m396sEybBx1x7VIuPU2ESPjdPj5eAhp9Bfm8Ija+r/7Nrrp+WQqKzVdDnNj5pHX/FqVUoQQjbsq9l3gEv8A2qim7StIC1SYN09R5hiodlKQrK3VC9llbqoDziTf89o+EICUnZvs3UUBlaCfGzzpqlklRlbEqhm6mGfJOhEJFOx5oF8Ak1IZv87Y0nQxfoff3BgyM7OOXeSi+aDNX92BLNTTG5QCdzFAJpZImHKliEqKZbYTijrVKFLUChDERTGY6GUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CpCzWY5tiUgIPiLPumDlsQIlukWz2ii4OV5AwM+R4t0=; b=YQFg/lPKPDlcVt3XSLehWUwNTN7qAA1E22JRlqAQg4BbPtJ1iTg7u9w5ucN/txN0PNnH8SEcTlYunjw/vE21IyaPe8sBddot5Dh7dq2kPrDjrNyJ1wisjeGvFxCa/ozeHLcLpS3xxDYSf2EPPDw+eSdbjPvNbB6D9ZV7shV8irZxe2eSaTNWRzqPDXUV+Wwu2eT1pfGRuZ576bJX/w5R2Ep+whQWjmXGuykxicN6vk2eozQLQCeVYAVvOpKHVVUI+wWvjFq7aSDktXUaVeZfJKWd31gBCSeFBxuE+IGo1BBlQ4/JCHdUaI6bXXv/f1okZ1lg4jHyHZN/jIlXJmLcnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=openchip.com; dmarc=pass action=none header.from=openchip.com; dkim=pass header.d=openchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openchip.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CpCzWY5tiUgIPiLPumDlsQIlukWz2ii4OV5AwM+R4t0=; b=jVPic4DfcV+8+XUjInlAoMQ0HX4KYOAeGxEs47ylVXFLp/BCaZgyEsE6ySKXCMJflehsmebPXRDHqc6MdwyixO1xQyjZWcDR2nqYV+Rtqtu3F/0KRMNhO125Xk233HyegSfGRIPaCNawGCwyXeQ0Dsl6Y0lnffdB8NPgPq4R8JuqMIpOB27owF7bbb19rOF+mtoLUl9QqjpAnuX997/l5cUUbjkXYEe+Uv9wOg3ags3K7Re71JFeQ8jvapp4Yi8iWjzU9A9DfIiP2BTvkTJqQNPRLPrdjUsu8nUv73IPIyiGwEYWJ2hsUgdoc52gtF8LOJhGssuw2VFuPeD58n7QVw== From: Harry van Haaren To: "qemu-devel@nongnu.org" CC: BALATON Zoltan , Alexandre Iooss , Pierrick Bouvier , =?utf-8?B?QWxleCBCZW5uw6ll?= , Harry van Haaren Subject: [PATCH v2 1/2] plugins/execlog: fix segfault/race-cond on per-vCPU structures Thread-Topic: [PATCH v2 1/2] plugins/execlog: fix segfault/race-cond on per-vCPU structures Thread-Index: AQHdFQdOnD/4vwTCVkm2dflPMglRtQ== Date: Thu, 16 Jul 2026 09:41:42 +0000 Message-ID: <20260716094126.787556-2-harry.vanhaaren@openchip.com> References: <20260616161242.267315-1-harry.vanhaaren@openchip.com> <20260716094126.787556-1-harry.vanhaaren@openchip.com> In-Reply-To: <20260716094126.787556-1-harry.vanhaaren@openchip.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=openchip.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: GV2P192MB3464:EE_|VI1P192MB2186:EE_ x-ms-office365-filtering-correlation-id: 36bf1b31-865f-431d-7bef-08dee31e7162 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|23010399003|1800799024|366016|376014|3023799007|6133799003|4143699003|11063799006|56012099006|10067099003|22082099003|38070700021|18002099003; x-microsoft-antispam-message-info: lBqdxEotsIXe7Zq++CCBDODxzA7LHEw7LZ8oc+bPYmtK+ZY6v9CQA8vmMAd4jQlwdMqR2D9Oc0Yqz8mq19qMOF2SuU5Yx8p0l0OTUkOLbC35Y7rG7CBhLf+RbVhAOaHSyOW7bnkIjPoYjog4rk4xePFFB0xoejgkUTAN9wSTijA/MpVdzWkHpkIFg5SkbBk86kBjbCSiisa6gknbDtlKgZyjR7NA+w8+2/gktH8OOOQaEF7nrIpfzaKKZ8pAKjGA67nKKwkA1vRQuwd/AHiljJk7eq78nGC5cT2hIo7ud0yrqQf1lr3Zp+dK/uDS+SkNSdgjnLRgy/43d0krfbFiBXYYZE61IbpZhRfwmxgYNxdTaGq+i+I0uvNudPogW56NPRW9aOnZkOja3YEEI0Iec8oRH4Je0L5UAIY11chU2GydHvQdkosCY4tiKXiIS3F77gWk5e+JY+6eZSMJ6uE1iEAeAZIHirtb3qUrvGKZTvuc/p60/GuIGIOMPK8EWfw/OY/QX1XTKYfbFIoqlEE5RN+J6hgYO1SRV+ojyDzpehbEJgEK6LCsQUekp6vYvmXqJPmf/jxa0fF8vAHPCFnKto9eY5LZ2CCZXO4EOntjdArihqqj9jVNJTJ/WzlYwAyyII6ppqvKf07KUT/GKLdRazHUd4DK6YbWgi4Udy0Wao5de3aO8QB2/eCvSu1lPEDhfDzadn4xfusmPs2EM2Cg+u+cU27iBwQMTsxiUSvHW4g= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:GV2P192MB3464.EURP192.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230040)(23010399003)(1800799024)(366016)(376014)(3023799007)(6133799003)(4143699003)(11063799006)(56012099006)(10067099003)(22082099003)(38070700021)(18002099003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?B?ZUxZQm12RGV2dDNHVE9KWHc4WWM3azdXNTBtUFE5ME9uTlRTWUVaUnphUUwx?= =?utf-8?B?Y3o5TzFMUHVBcVdQVjN4WWp3cjRBZ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HVuY20wVExKS2ZJT3U3d0xlK0JROEd1a201U3dvd2E0MklV?= =?utf-8?B?Q0hJZFo4c0hQM09jb2hGV2tJKytZOGROUmlsaGVMWENiNmhoOHhZUXNzWVRW?= =?utf-8?B?OEw0Ry85MDk1V29JNEpOOHNtOG1DKzVNWTlDV1B5dks1bWthcFF6ZTBGRHls?= =?utf-8?B?WDF0T2pNNzVKeXBLNmhEeGx2S1hQK1pCOHpsRjA4cFRXZXhCTHdMaE4veWFF?= =?utf-8?B?aEV2aUVjTGRMUVpvQ0FrNFVTQ01PakZPcG4yMHRGNXN2ckVtcnR3UFlaOTBI?= =?utf-8?B?MlkyOXB6eWpzTnB5NExCQjBPU0NNWktXVmtwU0ZSOVk4V2xES24rNFRIUDNq?= =?utf-8?B?VDEyeFIrV2pjcUNPYllFQ2Q5MFBPU3psRW93ZzFFN0dWSmlmS0lwVWVYYnpm?= =?utf-8?B?czlOVXoybVFUbTBiU2VBaVkwbkVDVVFVZmh3U1Zrc2tOL0p1djNXQT09?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: openchip.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: GV2P192MB3464.EURP192.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 36bf1b31-865f-431d-7bef-08dee31e7162 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Jul 2026 09:41:42.3837 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: dfdd4aff-e2c9-4e1a-8642-7f6cc6bbbe6d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: MwUvrW8gVzGCaoha69vOSNh6QpjMn01jTNd7X6NMZEUedj87c9kFpEjX5j2XBwodRgLJ4ysbIy/j6JNxa6KXqlPMG/+zb+0EmuhVEHUuWP4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1P192MB2186 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=2a01:111:f403:c201::3; envelope-from=harry.vanhaaren@openchip.com; helo=AS8PR04CU009.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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 @openchip.com) X-ZM-MESSAGEID: 1784194930976158500 From: Harry van Haaren The existing code in execlog was never upgraded to the Scoreboard API, resulting in a bespoke implementation of per-vCPU datastructure handling. This had some race-conditions, and causes segfaults with a simple multi-threaded program and two instances of execlog running. The patch here refactors the custom GArray and GRWLock code away, and uses the scoreboard APIs like the other plugins. This solves the "printing while expanding" race-condition of two plugins with multiple threads in the guest, and hence fixes a segfault. Output remains atomic per instruction by building the full line (including the trailing newline) in the per-vCPU GString before making a single qemu_plugin_outs() call, relying on QEMU's own log locking rather than an additional mutex. Signed-off-by: Harry van Haaren Reviewed-by: Pierrick Bouvier Tested-by: Pierrick Bouvier --- contrib/plugins/execlog.c | 68 +++++++++++++-------------------------- 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c index 74325495cc..dfe00bf836 100644 --- a/contrib/plugins/execlog.c +++ b/contrib/plugins/execlog.c @@ -31,8 +31,12 @@ typedef struct CPU { =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 -static GArray *cpus; -static GRWLock expand_array_lock; +/* + * Per-vCPU state stored in a qemu_plugin_scoreboard. The scoreboard manag= es + * per-vCPU storage automatically, eliminating the need for manual array + * growth, locks, or pointer-stability workarounds. + */ +static struct qemu_plugin_scoreboard *cpus; =20 static GPtrArray *imatches; static GArray *amatches; @@ -41,23 +45,13 @@ static bool disas_assist; static GMutex add_reg_name_lock; static GPtrArray *all_reg_names; =20 -static CPU *get_cpu(int vcpu_index) -{ - CPU *c; - g_rw_lock_reader_lock(&expand_array_lock); - c =3D &g_array_index(cpus, CPU, vcpu_index); - g_rw_lock_reader_unlock(&expand_array_lock); - - return c; -} - /** * Add memory read or write information to current instruction log */ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t info, uint64_t vaddr, void *udata) { - CPU *c =3D get_cpu(cpu_index); + CPU *c =3D qemu_plugin_scoreboard_find(cpus, cpu_index); GString *s =3D c->last_exec; =20 /* Find vCPU in array */ @@ -117,7 +111,7 @@ static void insn_check_regs(CPU *cpu) /* Log last instruction while checking registers */ static void vcpu_insn_exec_with_regs(unsigned int cpu_index, void *udata) { - CPU *cpu =3D get_cpu(cpu_index); + CPU *cpu =3D qemu_plugin_scoreboard_find(cpus, cpu_index); =20 /* Print previous instruction in cache */ if (cpu->last_exec->len) { @@ -125,8 +119,8 @@ static void vcpu_insn_exec_with_regs(unsigned int cpu_i= ndex, void *udata) insn_check_regs(cpu); } =20 + g_string_append_c(cpu->last_exec, '\n'); qemu_plugin_outs(cpu->last_exec->str); - qemu_plugin_outs("\n"); } =20 /* Store new instruction in cache */ @@ -138,7 +132,7 @@ static void vcpu_insn_exec_with_regs(unsigned int cpu_i= ndex, void *udata) /* Log last instruction while checking registers, ignore next */ static void vcpu_insn_exec_only_regs(unsigned int cpu_index, void *udata) { - CPU *cpu =3D get_cpu(cpu_index); + CPU *cpu =3D qemu_plugin_scoreboard_find(cpus, cpu_index); =20 /* Print previous instruction in cache */ if (cpu->last_exec->len) { @@ -146,8 +140,8 @@ static void vcpu_insn_exec_only_regs(unsigned int cpu_i= ndex, void *udata) insn_check_regs(cpu); } =20 + g_string_append_c(cpu->last_exec, '\n'); qemu_plugin_outs(cpu->last_exec->str); - qemu_plugin_outs("\n"); } =20 /* reset */ @@ -157,12 +151,12 @@ static void vcpu_insn_exec_only_regs(unsigned int cpu= _index, void *udata) /* Log last instruction without checking regs, setup next */ static void vcpu_insn_exec(unsigned int cpu_index, void *udata) { - CPU *cpu =3D get_cpu(cpu_index); + CPU *cpu =3D qemu_plugin_scoreboard_find(cpus, cpu_index); =20 /* Print previous instruction in cache */ if (cpu->last_exec->len) { + g_string_append_c(cpu->last_exec, '\n'); qemu_plugin_outs(cpu->last_exec->str); - qemu_plugin_outs("\n"); } =20 /* Store new instruction in cache */ @@ -378,40 +372,28 @@ static GPtrArray *registers_init(int vcpu_index) * - last_exec tracking data * - list of tracked registers * - initial value of registers - * - * As we could have multiple threads trying to do this we need to - * serialise the expansion under a lock. */ static void vcpu_init(unsigned int vcpu_index, void *userdata) { - CPU *c; - - g_rw_lock_writer_lock(&expand_array_lock); - if (vcpu_index >=3D cpus->len) { - g_array_set_size(cpus, vcpu_index + 1); - } - g_rw_lock_writer_unlock(&expand_array_lock); - - c =3D get_cpu(vcpu_index); + CPU *c =3D qemu_plugin_scoreboard_find(cpus, vcpu_index); c->last_exec =3D g_string_new(NULL); c->registers =3D registers_init(vcpu_index); } =20 /** - * On plugin exit, print last instruction in cache + * On plugin exit, flush any remaining cached instructions and free state. */ static void plugin_exit(void *p) { - guint i; - g_rw_lock_reader_lock(&expand_array_lock); - for (i =3D 0; i < cpus->len; i++) { - CPU *c =3D get_cpu(i); - if (c->last_exec && c->last_exec->str) { + int n =3D qemu_plugin_num_vcpus(); + for (int i =3D 0; i < n; i++) { + CPU *c =3D qemu_plugin_scoreboard_find(cpus, i); + if (c->last_exec && c->last_exec->len) { + g_string_append_c(c->last_exec, '\n'); qemu_plugin_outs(c->last_exec->str); - qemu_plugin_outs("\n"); } } - g_rw_lock_reader_unlock(&expand_array_lock); + qemu_plugin_scoreboard_free(cpus); } =20 /* Add a match to the array of matches */ @@ -452,12 +434,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, const qemu_info_t *info, int ar= gc, char **argv) { - /* - * Initialize dynamic array to cache vCPU instruction. In user mode - * we don't know the size before emulation. - */ - cpus =3D g_array_sized_new(true, true, sizeof(CPU), - info->system_emulation ? info->system.max_vcp= us : 1); + /* Initialize scoreboard to cache per-vCPU instruction state. */ + cpus =3D qemu_plugin_scoreboard_new(sizeof(CPU)); =20 for (int i =3D 0; i < argc; i++) { char *opt =3D argv[i]; --=20 2.54.0 From nobody Sun Jul 26 11:51:04 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; arc=pass (i=1 dmarc=pass fromdomain=openchip.com); dmarc=pass(p=quarantine dis=none) header.from=openchip.com ARC-Seal: i=2; a=rsa-sha256; t=1784194943; cv=pass; d=zohomail.com; s=zohoarc; b=Ay1UDLBwEUvv2yC1davvBxssRCKvUEHWSB+8zG2UUg4TWptSe+99KIX0vlwz0AM0vjIncLvCNexO/dkfP+QAonpEJB1JjjXxJs75ZqbWwsq55G9Ps2ruQQRSX885UFJ8bq1MqwYco7r5aJ58D8rc2+E2cGUYATkon/0sa13d4Uw= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784194943; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=09MFqSeoKXjoALxqoVcrzwepF2cOL9rFEWmTk+rZKYc=; b=It95+sXL4yQNzRKQJG2WcOmY5skXxjbRBbtDZRB7k0wujAJOiWvD6hH3xILTiefgknp3lAnVYHSO8i2HWBZgBgdOCLHBQlfvEhXIWz+SBBvU6vCK3DGCL1P9dgJiDAzOywlE4FKkfQakq0bW3ThEN/OXhhhTUjrw+/cezsL3QGU= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=openchip.com); 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 1784194943634705.9691531125513; Thu, 16 Jul 2026 02:42:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkIbS-0001kl-Gb; Thu, 16 Jul 2026 05:42: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 1wkIbR-0001kZ-E6 for qemu-devel@nongnu.org; Thu, 16 Jul 2026 05:42:01 -0400 Received: from mail-francesouthazlp170110003.outbound.protection.outlook.com ([2a01:111:f403:c207::3] helo=MRWPR03CU001.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkIbP-0000PF-Sh for qemu-devel@nongnu.org; Thu, 16 Jul 2026 05:42:01 -0400 Received: from GV2P192MB3464.EURP192.PROD.OUTLOOK.COM (2603:10a6:150:328::6) by VI1P192MB2186.EURP192.PROD.OUTLOOK.COM (2603:10a6:800:1c9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.202.18; Thu, 16 Jul 2026 09:41:54 +0000 Received: from GV2P192MB3464.EURP192.PROD.OUTLOOK.COM ([fe80::7ed0:3600:9df4:af64]) by GV2P192MB3464.EURP192.PROD.OUTLOOK.COM ([fe80::7ed0:3600:9df4:af64%6]) with mapi id 15.21.0223.008; Thu, 16 Jul 2026 09:41:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iJlh6K4xwEBozAktrzBYJWxDx3PibE0swsb3O6u2kz2svx1DZByWfIQ2YiGMbVc8H35i0xb+65L7YvtxHn7yCtGa4VJeCcXD0K5ygIdbBP+D1+1N3VPY6bmLjCi+EXDxLov2P0M7Kf94EZAUAOZAP0A3aBHCdDMlukpebRGNOq1rV/jgwJqyT4hyLqpLwOk3R0ADWn/0Af1v/VIlBPvfxlMc/6A6CCi6dM7XEnUhDxdjwlGcwxGelx0gm5UzLuc4UCX60JZ9uuSqHQiYyp2j+JYl34VOs85UlqrmG9J2Nyi/Fka+Fn4QVTAqG7Sv4dvXDjl3L9woT35szB1UqKSDxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=09MFqSeoKXjoALxqoVcrzwepF2cOL9rFEWmTk+rZKYc=; b=FADPBhr6sfWlhAtwyA0TnMS+ClC+WDLm2I8WtlIcibwDRe0EM+5vaCxoU++2zVzGEjLFUSia1tysE9tRu+iyXOOzQ1BhAJDn2NDRw0WyX2aohEKfKF+X0e9l+zD3VuMkCowbdDuN/R3reIb9Tzm7xJCrEXYD6cj1YcUP1UuiZ/wHGDTRrP8oBlLaMewFYF69IDGpdqS6ivLlfrgvid2635CG4xbXUyfXFRbBoGE3U+l0oLeKyddXb/j5PLZSkj5NZFA0EVQSsa230oJ77ztUnbTXG0IYWHfXLwA3kyLyJUt6Vokv1q2UwmEjZARvvqhjb73Oybk8WGqh2AVNko+gkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=openchip.com; dmarc=pass action=none header.from=openchip.com; dkim=pass header.d=openchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openchip.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=09MFqSeoKXjoALxqoVcrzwepF2cOL9rFEWmTk+rZKYc=; b=dz+Tq6q2Tp59UojuNE3q2N25RrgGMYmSRZNtE/db7bls3jxRNel0rfiJUGjxV0wpeUBUowH3oKItZEmCsqUSLh0wPih4GMEEp/JtYFNqn6KAKJoqcqdj8sxgBbivQ9c7NIl9TNLJWKGyYFN8a9DGkpVp7SiCvx7WpbPBn7h7O2VeAb+DdRc1cuV9QpN5sMJVq83ZNf8IStTaVvGvyMeR18WS1/+RYtqaO8HcxTOW7ZiFZe7tO6rIU0Bg7hLo7sNgayERO1WDY7qXtotU2SnXV8LJFGJHMHNTh+EWcnWWDDVTNlxKFmVHmF5vuUw71hMQkS3vNPEC08ogHO328U7a4g== From: Harry van Haaren To: "qemu-devel@nongnu.org" CC: BALATON Zoltan , Alexandre Iooss , Pierrick Bouvier , =?utf-8?B?QWxleCBCZW5uw6ll?= , Harry van Haaren Subject: [PATCH v2 2/2] plugins/execlog: fix execlog vcpu_exit execution print loss Thread-Topic: [PATCH v2 2/2] plugins/execlog: fix execlog vcpu_exit execution print loss Thread-Index: AQHdFQdVLKYSBNRzCUKYrDmbyMMPWQ== Date: Thu, 16 Jul 2026 09:41:53 +0000 Message-ID: <20260716094126.787556-3-harry.vanhaaren@openchip.com> References: <20260616161242.267315-1-harry.vanhaaren@openchip.com> <20260716094126.787556-1-harry.vanhaaren@openchip.com> In-Reply-To: <20260716094126.787556-1-harry.vanhaaren@openchip.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=openchip.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: GV2P192MB3464:EE_|VI1P192MB2186:EE_ x-ms-office365-filtering-correlation-id: ebf5bbd7-b609-4ffd-7d00-08dee31e77d2 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|23010399003|1800799024|366016|376014|3023799007|6133799003|4143699003|11063799006|56012099006|10067099003|22082099003|38070700021|18002099003; x-microsoft-antispam-message-info: QRoJOW6HDhhiP7gsI9yUmWqiIr/YLTYI9KM2KbFVt41AyQwqxb6y9aOtF0RVY1VV3WJciSW6pdvuFIWyIIt9/fdJxNn7zkftwukm4DG5nz4hP5Eq+pGwVQhaL/SGs09EpD9MfoFniASrTM11mBVvCKE2MkSqEwTZacPZxv6SPWZi3M0H3nYf4AGXUy1ZrGafckjkaP9+jGaNwlCQJ4rWZ51lN90+8SnN5Rt6z1dEavYNcdPKScOF7Ym2rH0Uw2GgdEQHZgD/BTBLrBQk8N12ijgUVtklY0EGAcpGS8VR+JhEQw8ar0TF+zdC8x4U/vfuFWyiicvALTgaWp3g//MULBAp1X+XaKPWfc2RzFgEGFyNoSLnPb+bIaQU7hx5MpucMRO+k3AerYNHSIvzzyXuQKW8U4ppI1BwZnw+RdUiNn4cnNoom8V2JQv/KZ87uIxlGYzHsymi7OzC8N06hC1RDjlxWtQ6M5myNkeK6avVxsFAny8LLY+372iqqSW/PnPMK0sJI4YPEQ5HfiD7/D4EsGF9eyygFCepYMJ7ukUo0Mfcx6nkbrixPh2JR9zIK5zCLi/6tmwufKf7VBZdDDvd3rVfldMVgV6N+5l+H1PXB/N91E1+wInW1evbv30yH0A69iSXDyBvI7eTvgfj7/phYcozUZAsgBgh2HxTr7nDI22ccZ4hdki5Z7P/wtZsNjIwfwae+Sjee3TlaD/ZesArhWS9veDmmcgYecZY5qZ79RM= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:GV2P192MB3464.EURP192.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230040)(23010399003)(1800799024)(366016)(376014)(3023799007)(6133799003)(4143699003)(11063799006)(56012099006)(10067099003)(22082099003)(38070700021)(18002099003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?B?NFZwTVVTeXFFK2JKWERLbnZaWmVONjNGQjU5NDg1VS9FN0ovZHRWVTJ5Lzkz?= =?utf-8?B?QXB2ZkdJTTQ4VDBMeFYydmVLNXc1MncwNDh1Ukt3SktMbjh6WHFEWkptRGhx?= =?utf-8?B?NTYyUzRYSCt4QVVqVjN0bzdGSUwwd0ZEVDRMUE9vTklZSTgyVkgyTCtCbG0v?= =?utf-8?B?aTFDMzZYRVcrRjlXRFB3TkY1d2pCa0FZSVBOVTF3bER4YzRVRmJHTjVkR3BV?= =?utf-8?B?bW9Kd0ZTRDZkQ09IVnVlbllFd3UweWVwM28wQmc4NnZtTmZ5VkY0M1pBZ2t1?= =?utf-8?B?a0NMTi9RNHlxd2J6V3YzTnJ4V2pKajFlQ2tjdjg2Y0JUL2RJMnlEb1lWekxt?= =?utf-8?B?V3phV3dhQ1puUjVkQzlOQllLWDFuaTcwMTdqY0JiU1VrZmI5emk3ZmpML0tx?= =?utf-8?B?L0IrK21MRWRZakZCYWZ4VVljZTBSby9ObnBGOU9zN0E2OVJHT1JsNEh4VzZF?= =?utf-8?B?L1Z3akYyVlp3c0xZVC92bUdqaGt5WnZCR0lFakdIUHQ2WDZSQkhzUThLaDUz?= =?utf-8?B?RkNXUm1OVE5hdkx6VTRWZ01pcUN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T09?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: openchip.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: GV2P192MB3464.EURP192.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: ebf5bbd7-b609-4ffd-7d00-08dee31e77d2 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Jul 2026 09:41:53.1961 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: dfdd4aff-e2c9-4e1a-8642-7f6cc6bbbe6d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Z80QRfAx3tTihrmKr+ColdQkhc7UayEleT4tlUTBJgv7D7/Q+lkmAxyGMJiJGaY43Q051lJuGXUpCwbqWL2nXbcJTSRDljeaeRRlxSZaB9s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1P192MB2186 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=2a01:111:f403:c207::3; envelope-from=harry.vanhaaren@openchip.com; helo=MRWPR03CU001.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @openchip.com) X-ZM-MESSAGEID: 1784194944841158500 From: Harry van Haaren Executed instructions are cached in string format inside the execlog plugin. These strings are flushed on exit of a TB, improving performance. This causes executed instructions to be lost when an 'ecall' (riscv system call) occurs that causes the thread to terminate. The fix in this patch registers a 'vcpu_exit' callback, and flushes any content in the c->last_exec buffer, to ensure all instructions are present in the final instruction log. Signed-off-by: Harry van Haaren Reviewed-by: Pierrick Bouvier Tested-by: Pierrick Bouvier --- contrib/plugins/execlog.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c index dfe00bf836..cb0bd399d8 100644 --- a/contrib/plugins/execlog.c +++ b/contrib/plugins/execlog.c @@ -380,6 +380,25 @@ static void vcpu_init(unsigned int vcpu_index, void *u= serdata) c->registers =3D registers_init(vcpu_index); } =20 +/** + * On vCPU exit, flush the last cached instruction for this vCPU. + * + * The one-instruction-delay pattern stores each instruction in last_exec = and + * only prints it when the *next* callback fires. When a thread exits via + * syscall (e.g. ecall/exit), no subsequent callback fires for that vCPU a= nd + * the final instruction is silently dropped. Flushing here guarantees it = is + * written before the vCPU is torn down. + */ +static void vcpu_exit(unsigned int vcpu_index, void *udata) +{ + CPU *c =3D qemu_plugin_scoreboard_find(cpus, vcpu_index); + if (c->last_exec && c->last_exec->len) { + g_string_append_c(c->last_exec, '\n'); + qemu_plugin_outs(c->last_exec->str); + g_string_truncate(c->last_exec, 0); + } +} + /** * On plugin exit, flush any remaining cached instructions and free state. */ @@ -461,6 +480,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, /* Register init, translation block and exit callbacks */ qemu_plugin_register_vcpu_init_cb(id, vcpu_init, NULL); qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans, NULL); + qemu_plugin_register_vcpu_exit_cb(id, vcpu_exit, NULL); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); =20 return 0; --=20 2.54.0