From nobody Mon Aug 24 22:48:38 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=1781168658; cv=none; d=zohomail.com; s=zohoarc; b=cvVC5nLxe3rIvG8CO86l7v52hSVqdovCRVBTmnQgCtffwOtdd+Bq18sb/gyGkV+Zn7f2pPj9BnM3jv5CcDzWEuWEU3QQ9PDO1JdDutmkDPYDSAZhuRqdnTLNU9jy6e6mRwG34ZJLKWmZr1Ke8bs6z1x9o4Zz3sOESoc3sE22TuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781168658; 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=Smidf6FMOj3LuQCqpb0c6LifDKbvfiyh56oQEfYvK00=; b=mRIXDILDG9fqTFeo6MxIUXhZj8HPmdmcnNqQTQSplhXP7SmDZx5NpySF28ZfmmaBBCjlJSVUtVqvf1r0Gnw+kl5dqE6yY2Qz0h4qJmFLdvIQ76DKp8f1J/ywBdnEslG7AuEVEG4Zh89JEmccYrbFykGC9PY63VFw/ygwPkwo/xI= 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 1781168658274229.58110848212698; Thu, 11 Jun 2026 02:04:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wXbKV-000074-Si; Thu, 11 Jun 2026 05:04:03 -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 1wXbKU-00006r-Hv for qemu-devel@nongnu.org; Thu, 11 Jun 2026 05:04: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 1wXbKS-0004WA-Q0 for qemu-devel@nongnu.org; Thu, 11 Jun 2026 05:04:02 -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-587-Zs8AfaNpP7-digZY3Tad2w-1; Thu, 11 Jun 2026 05:03:56 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 3AB6019560A1; Thu, 11 Jun 2026 09:03:55 +0000 (UTC) Received: from localhost (unknown [10.44.24.21]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 664DD19541B2; Thu, 11 Jun 2026 09:03:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781168640; 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=Smidf6FMOj3LuQCqpb0c6LifDKbvfiyh56oQEfYvK00=; b=TYZNuqXP9lx8azGrv2Bq4vZ5TGlQiJQOHmgB3zAxAUCSXq4ubVgZDIvUBTfpfoPbCEHi/a jsBJk1eFvAKRYwSaXH3UXnwMx07+zhMAtZVQJM+q+FLxSXGM8fUZkEA9qYD1tEBzmWyqei UJs6HEdpmy2PLyxyH8v1kux/0u0tf10= X-MC-Unique: Zs8AfaNpP7-digZY3Tad2w-1 X-Mimecast-MFC-AGG-ID: Zs8AfaNpP7-digZY3Tad2w_1781168635 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 11 Jun 2026 13:03:18 +0400 Subject: [PATCH v3 03/35] irq: add per-IRQ observer to fix qemu_irq_intercept_in leak MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260611-b4-ui-v3-3-72bcbbea0fae@redhat.com> References: <20260611-b4-ui-v3-0-72bcbbea0fae@redhat.com> In-Reply-To: <20260611-b4-ui-v3-0-72bcbbea0fae@redhat.com> To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Peter Maydell , Akihiko Odaki , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=4758; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=AgfY59Jw3FWwwFgiVCxaDztJQCKR319w+PzxgVpWWCs=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqKnndGPJZOIJsbGpAfn8IeXH89XuarbByT8S5m hwl8xDjIm6JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaip53QAKCRDa6OEJdZac 5YCOD/9Yt88JPH/wzCnpf1kwyN2iI51uAwkjqzYBIlBgDcJ1JvDUxokEExEVFQ1oJAyhSWVwvuV aJTaag/GKjjouwlAKVUF8yiMoo8sDF3wP0qY7Gkxo/8ttkkW5aPTKxg8qzsc/jCMl0JWkULjodw 2S/J2zCIjwnrUdclj8eB63xey2p1fMyv3v8v7wCMz08klNcVbaMs/tfyzEW5OUF2Wffqy8Yndxl SKEnCv1ROdnLJNASWbemeiJfoylCrphMIom1K8qwqQ4eEXpGc7XV4z/UInGoQ1o8iEM4TQBafHt T3olxQPYgMTFQjcKsrhQmAFZdybnh2rPyNsRuI5MXgZWrMHZlRclGl/dhX3xaHxvfDNI49oi2lh oysbBOKnkzJWyQ6iqbpnHQfEWvxDA3lCiyFp5bGZLHdW9QRy4ou8bxRRIZav1fLZJODq9fJv/ml pdibDwqiNw3B6+ociPn+0qwPB7l8eFSPrc20f3xKTZ//BoK+5IcNRrmk0muyVMGz2wlbi6xhmU0 pCmgGjDAXYtvIAMXqW+XdNXKnJyeYqIk3YKvmKpHl6WoIcsNwieimJmBICEUR2IniaLxp+9lusd j+PQ2+327ez7+tccBF9U7QArk2b3V3jeoAZaaruSTEIpS9HRJSWY1z7RwMkL8CTmAXM5UQEdt+w BLasrAXhP7c2++A== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, 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: 1781168660895158500 qemu_irq_intercept_in() saves original IRQ handlers by allocating new QOM objects, which are never freed. On a PC machine, this leaks IRQ objects (one per IOAPIC pin) on every qtest run. Rather than tracking allocations to free later, avoid them: add an "observer" field to IRQState, called by qemu_set_irq() after the real handler. Interception sets the observer instead of rewriting handlers, so there's nothing to save and nothing to leak. Fix qemu_notirq() to route through qemu_set_irq() so inverted IRQs trigger observers too. Drop the LSan suppression. Reviewed-by: Fabiano Rosas Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/core/irq.h | 6 +++--- hw/core/irq.c | 12 ++++++------ system/qtest.c | 5 +---- scripts/lsan_suppressions.txt | 8 -------- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/include/hw/core/irq.h b/include/hw/core/irq.h index 291fdd67df4..299a4a9a8ce 100644 --- a/include/hw/core/irq.h +++ b/include/hw/core/irq.h @@ -14,6 +14,7 @@ struct IRQState { qemu_irq_handler handler; void *opaque; int n; + qemu_irq_handler observer; }; =20 void qemu_set_irq(qemu_irq irq, int level); @@ -96,9 +97,8 @@ void qemu_free_irq(qemu_irq irq); /* Returns a new IRQ with opposite polarity. */ qemu_irq qemu_irq_invert(qemu_irq irq); =20 -/* For internal use in qtest. Similar to qemu_irq_split, but operating - on an existing vector of qemu_irq. */ -void qemu_irq_intercept_in(qemu_irq *gpio_in, qemu_irq_handler handler, in= t n); +/* For internal use in qtest. */ +void qemu_irq_set_observer(qemu_irq *gpio_in, qemu_irq_handler handler, in= t n); =20 /** * qemu_irq_is_connected: Return true if IRQ line is wired up diff --git a/hw/core/irq.c b/hw/core/irq.c index 106805e2417..1b610e75e15 100644 --- a/hw/core/irq.c +++ b/hw/core/irq.c @@ -32,6 +32,9 @@ void qemu_set_irq(qemu_irq irq, int level) return; =20 irq->handler(irq->opaque, irq->n, level); + if (unlikely(irq->observer)) { + irq->observer(irq->opaque, irq->n, level); + } } =20 static void init_irq_fields(IRQState *irq, qemu_irq_handler handler, @@ -111,7 +114,7 @@ static void qemu_notirq(void *opaque, int line, int lev= el) { IRQState *irq =3D opaque; =20 - irq->handler(irq->opaque, irq->n, !level); + qemu_set_irq(irq, !level); } =20 qemu_irq qemu_irq_invert(qemu_irq irq) @@ -121,14 +124,11 @@ qemu_irq qemu_irq_invert(qemu_irq irq) return qemu_allocate_irq(qemu_notirq, irq, 0); } =20 -void qemu_irq_intercept_in(qemu_irq *gpio_in, qemu_irq_handler handler, in= t n) +void qemu_irq_set_observer(qemu_irq *gpio_in, qemu_irq_handler handler, in= t n) { int i; - qemu_irq *old_irqs =3D qemu_allocate_irqs(NULL, NULL, n); for (i =3D 0; i < n; i++) { - *old_irqs[i] =3D *gpio_in[i]; - gpio_in[i]->handler =3D handler; - gpio_in[i]->opaque =3D &old_irqs[i]; + gpio_in[i]->observer =3D handler; } } =20 diff --git a/system/qtest.c b/system/qtest.c index fd37bcbfaab..cf301239177 100644 --- a/system/qtest.c +++ b/system/qtest.c @@ -326,9 +326,6 @@ void qtest_sendf(CharFrontend *chr, const char *fmt, ..= .) =20 static void qtest_irq_handler(void *opaque, int n, int level) { - qemu_irq old_irq =3D *(qemu_irq *)opaque; - qemu_set_irq(old_irq, level); - if (irq_levels[n] !=3D level) { CharFrontend *chr =3D &qtest->qtest_chr; irq_levels[n] =3D level; @@ -421,7 +418,7 @@ static void qtest_process_command(CharFrontend *chr, gc= har **words) interception_succeeded =3D true; } } else { - qemu_irq_intercept_in(ngl->in, qtest_irq_handler, + qemu_irq_set_observer(ngl->in, qtest_irq_handler, ngl->num_in); interception_succeeded =3D true; } diff --git a/scripts/lsan_suppressions.txt b/scripts/lsan_suppressions.txt index f88bbab18b8..30256bc6d01 100644 --- a/scripts/lsan_suppressions.txt +++ b/scripts/lsan_suppressions.txt @@ -16,11 +16,3 @@ leak:/lib64/libxkbcommon.so.0 # https://github.com/GNOME/glib/blob/main/tools/glib.supp # This avoids false positive leak reports for the qga-ssh-test. leak:g_set_user_dirs - -# qemu_irq_intercept_in is only used by the qtest harness, and -# its API inherently involves a leak. -# While we could keep track of the old IRQ data structure -# in order to free it, it doesn't seem very important to fix -# since it is only used by the qtest test harness. -# Just ignore the leak, at least for the moment. -leak:qemu_irq_intercept_in --=20 2.54.0