From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562030; cv=none; d=zohomail.com; s=zohoarc; b=R3EOOy46wHtcduIqF3VDnqqBP73Nfnf0vqdfS4eHHt7Q067eSchy8RtUPW/FDDA4vqmRn/F6kdcGu5tZ91yDjLv+QVwFQxMp2q6qvBkjzAW7MGp8W6KS/+vhcdkqnWbHpzssYlzPFs4eqmhIAXxXckz6q5WJdYUZdoxIlqElJFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562030; h=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=aPt1NnsuR8qHqD/7D5dJIAnQyTdLDa8FSzmcDxHlggQ=; b=RyxBCQY0AgevtBLJeJ7wbKVUJgsnTLdvwUDifv25TzZ0eeJvl/kuj5MOP6hBuKpP5vWae4XTw630q4ut7ZhOs7J+dMV7i9iSGrdhXNBVpk29VzDw6p8BeLZFeBY3QgxFdV+UgMAN/H7ckko45FWYY6ebw0zK45n9yW1cBJNiwa4= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562030242656.9968165877335; Fri, 13 Nov 2026 01:27:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYT-0000Y6-3s; Fri, 13 Nov 2026 04:26:46 -0500 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 1xRnYH-0000W0-8d for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:33 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYF-0005zF-7T for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:33 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2e9995ce866so11560705ad.0 for ; Fri, 13 Nov 2026 01:26:30 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:26:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794561990; x=1795166790; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=aPt1NnsuR8qHqD/7D5dJIAnQyTdLDa8FSzmcDxHlggQ=; b=Vkx8UZXOviMUWbHO6O4IN9t1ZwECB2PRw/Qb1QAUNmaz168Weq556BOhsJF6toX+pu iN1Zal6SPqkFsk43rSjuCyK/ZTGYxGmQ4msVBCP5ttIm9IK7qQOwfReJzPV+aVdyYdo+ 28xvo6JQJ0UXvVrHbr01WkEyYhevPSP/nqAyLeRCTBkTsiN6mBwi8teiSEo6uzcacpQT 9keltgwLGUmAzc6p7S7KJrP1VrOrEA5MM5cvrN9gqPXx5+C6s7BgxDN7qR0Hlnbq6DGU 6EFsxNEV1KRvF7dWQlQNp/qPyUmgahWKEgkqiPBZoXmrK7pTdaudSDCfrILjNwr8Mxlo VK6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794561990; x=1795166790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=aPt1NnsuR8qHqD/7D5dJIAnQyTdLDa8FSzmcDxHlggQ=; b=IVDpTmVb7Gwj7Rf8W8MerqG9NW6Rz09MYXB/Vhazhep9Zq9sN/wrkp5XZ6kkxR8ras INjU8nClzwJy/bjiQrcvfTSsuuz5N9Z4bK0ABDEfVFTMp/SpLDoiUNnt5GlEsvDNqids X/V7iF0JoVYHArygIy3RhTP3hfnxIY6JVdSFK2C/I+WWu+iR2xTany/VbQTZTfUKZd8p GnLVEZZPSC1M+KT6UV2Khd5/y+yVmnh6nwehb8o0YithjnD/xmFaw7WvvGmOkIo8vd6r XZ8r3FbRLhc0jJugq0l3s0iJDskIYW82a6Kyw7h7CWKrQMvIlPKbw0As00p6g6GLa8TU RSGw== X-Gm-Message-State: APuU4Z/J9tL/sPNe90oArKj+R42pP74+IK1V+hJMPUfn5NV0euZEvSbX va1FKjzNSsPqRLuuC3ao6//TngbidA+CHL+swJeAByGAWu/4+Uu9blnUPnBuWlIg X-Gm-Gg: AYBFou2LAM7otBEnEzgVfEjrU7hsI+i/tkIuOnDZ8kRhl/froAZwFEV/LkZcdj2jp9r 7218c9oMOYmSI0hjnYlQ2o2r1JBFvO9ElUwrNs6ZrOWrpg5b7e8kXyXKtwhCeDYXxTLplsSbG7H /wexo3KaTemrpZOOqhQNH9AtH33pwP9zvGqX7/zVVW0k6IQ0klGQ465oscGpDoF1XOoXzyOGhlH BFMcWg9zoE/Yw/ukEn4n8WVd3DTOawDB3/QltcuLIx5qBjULU6WfTz321ijLtE614vWAr+lxJIS mCc993ly7nmxr/vh9HV5i4QzokI3ZKyqz/4UZR5OCjmA0IkYtOIxEc6HwbAJtCbtYbiCgbDm3PJ nHl4vUWTZ/gtUxu1eEgVIFvJPkXVD2rZIYldT6uu537JCJE2LYSXMVrAeGjyaFEcY2aiIg5M1pr yBYT6/5XSn+oxpUKYFJYvE3gI78sLQCxzo9d4+A1ud8cvWLEy5VhU8+sw4EcsJrYwbCcjPZpgbC POt13ivj58Rg+lakg6WP4X6CHNXPGCfLHZt/JTjKgHkd1TTtl5MAC7wmk7KYN9THLQZF7naRQ8c jlDB73QhudgDzxBYbF2XVI6xUE7tkcdMzyPXM2GKHo4+ynltQr/v829pPQM= X-Received: by 2002:a17:902:da8d:b0:2e9:7719:40f0 with SMTP id d9443c01a7336-2ee0da9893amr20104315ad.19.1794561989455; Fri, 13 Nov 2026 01:26:29 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 01/14] iothread: introduce holder tracking Date: Fri, 13 Nov 2026 17:25:52 +0800 Message-ID: <20261113092605.942292-2-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::631; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x631.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562030967158500 Content-Type: text/plain; charset="utf-8" IOThreads do not record the QOM objects and block exports that use them, making runtime introspection and hotplug debugging difficult. Add: - holders: a list describing what is holding an iothread - iothread_ref(): add a holder to the list - iothread_unref(): remove a holder from the list A holder can identify either a QOM object or a block export. A later patch will expose this information through query-iothreads. Reviewed-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster Signed-off-by: Zhang Chen --- include/system/iothread.h | 5 +++ iothread.c | 63 ++++++++++++++++++++++++++ qapi/misc.json | 94 ++++++++++++++++++++++++++++++++++----- 3 files changed, 150 insertions(+), 12 deletions(-) diff --git a/include/system/iothread.h b/include/system/iothread.h index a1ef7696cb..b8aeb32b0e 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -18,6 +18,7 @@ #include "qemu/thread.h" #include "qom/object.h" #include "system/event-loop-base.h" +#include "qapi/qapi-types-misc.h" =20 #define TYPE_IOTHREAD "iothread" =20 @@ -50,6 +51,7 @@ struct IOThread { bool stopping; /* has iothread_stop() been called? */ bool running; /* should iothread_run() continue? */ int thread_id; + IOThreadHolderList *holders; =20 /* AioContext poll parameters */ int64_t poll_max_ns; @@ -82,4 +84,7 @@ void iothread_destroy(IOThread *iothread); */ bool qemu_in_iothread(void); =20 +void iothread_ref(IOThread *iothread, const IOThreadHolder *holder); +void iothread_unref(IOThread *iothread, const IOThreadHolder *holder); + #endif /* IOTHREAD_H */ diff --git a/iothread.c b/iothread.c index 3a1601e28b..b9889be845 100644 --- a/iothread.c +++ b/iothread.c @@ -22,10 +22,71 @@ #include "qapi/error.h" #include "qapi/qapi-builtin-type-infos.h" #include "qapi/qapi-commands-misc.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-misc.h" #include "qemu/error-report.h" #include "qemu/rcu.h" #include "qemu/main-loop.h" =20 +/* Add a deep copy of @holder to @iothread's list of holders. */ +void iothread_ref(IOThread *iothread, const IOThreadHolder *holder) +{ + assert(holder); + + QAPI_LIST_PREPEND(iothread->holders, QAPI_CLONE(IOThreadHolder, holder= )); +} + +static int iothread_holder_compare(const IOThreadHolder *holder_a, + const IOThreadHolder *holder_b) +{ + const char *name_a, *name_b; + + if (holder_a->type !=3D holder_b->type) { + return holder_a->type - holder_b->type; + } + + switch (holder_a->type) { + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + name_a =3D holder_a->u.qom_object.qom_path; + name_b =3D holder_b->u.qom_object.qom_path; + break; + case IO_THREAD_HOLDER_KIND_BLOCK_EXPORT: + name_a =3D holder_a->u.block_export.export_id; + name_b =3D holder_b->u.block_export.export_id; + break; + default: + g_assert_not_reached(); + } + + return strcmp(name_a, name_b); +} + +/* + * Remove @holder from @iothread's list of holders. + * + * It is a programming error if @holder is not present. + */ +void iothread_unref(IOThread *iothread, const IOThreadHolder *holder) +{ + IOThreadHolderList **prev =3D &iothread->holders; + IOThreadHolderList *curr; + + assert(holder); + + while (*prev) { + curr =3D *prev; + if (iothread_holder_compare(curr->value, holder) =3D=3D 0) { + *prev =3D curr->next; + curr->next =3D NULL; + qapi_free_IOThreadHolderList(curr); + return; + } + prev =3D &curr->next; + } + + g_assert_not_reached(); +} + static void *iothread_run(void *opaque) { IOThread *iothread =3D opaque; @@ -130,6 +191,7 @@ static void iothread_instance_finalize(Object *obj) iothread->main_loop =3D NULL; } qemu_sem_destroy(&iothread->init_done_sem); + qapi_free_IOThreadHolderList(iothread->holders); } =20 static void iothread_init_gcontext(IOThread *iothread, const char *thread_= name) @@ -374,6 +436,7 @@ static int query_one_iothread(Object *object, void *opa= que) info =3D g_new0(IOThreadInfo, 1); info->id =3D iothread_get_id(iothread); info->thread_id =3D iothread->thread_id; + info->holders =3D QAPI_CLONE(IOThreadHolderList, iothread->holders); info->poll_max_ns =3D iothread->poll_max_ns; info->poll_grow =3D iothread->poll_grow; info->poll_shrink =3D iothread->poll_shrink; diff --git a/qapi/misc.json b/qapi/misc.json index 4469e44d05..4a3eff4685 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -64,6 +64,55 @@ ## { 'command': 'query-name', 'returns': 'NameInfo', 'allow-preconfig': true } =20 +## +# @IOThreadHolderBlockExport: +# +# @export-id: The unique block export identifier. +# +# Since: 11.2 +# +## +{ 'struct': 'IOThreadHolderBlockExport', + 'data': { 'export-id': 'str' } } + +## +# @IOThreadHolderQomObject: +# +# @qom-path: Path to the object in the QOM tree. +# +# Since: 11.2 +# +## +{ 'struct': 'IOThreadHolderQomObject', + 'data': { 'qom-path': 'str' } } + +## +# @IOThreadHolderKind: +# +# @block-export: A block export. +# @qom-object: A QOM object. +# +# Since: 11.2 +## +{ 'enum': 'IOThreadHolderKind', + 'data': [ 'block-export', 'qom-object' ] } + +## +# @IOThreadHolder: +# +# The block export or QOM object holding the iothread. +# +# @type: the kind of iothread holder. +# +# Since: 11.2 +## +{ 'union': 'IOThreadHolder', + 'base': { 'type': 'IOThreadHolderKind' }, + 'discriminator': 'type', + 'data': { + 'block-export': 'IOThreadHolderBlockExport', + 'qom-object': 'IOThreadHolderQomObject' } } + ## # @IOThreadInfo: # Information about an iothread @@ -72,6 +121,10 @@ # # @thread-id: ID of the underlying host thread # +# @holders: the QOM objects or block exports currently holding this +# iothread. When a holder is detached or destroyed, it is removed +# from this list. (Since 11.2) +# # @poll-max-ns: maximum polling time in ns, 0 means polling is # disabled (since 2.9) # @@ -94,6 +147,7 @@ { 'struct': 'IOThreadInfo', 'data': {'id': 'str', 'thread-id': 'int', + 'holders': ['IOThreadHolder'], 'poll-max-ns': 'int', 'poll-grow': 'int', 'poll-shrink': 'int', @@ -117,20 +171,36 @@ # -> { "execute": "query-iothreads" } # <- { "return": [ # { -# "id":"iothread0", -# "thread-id":3134, -# "poll-max-ns":32768, -# "poll-grow":0, -# "poll-shrink":0, -# "aio-max-batch":0 +# "id": "iothread0", +# "thread-id": 3134, +# "holders": [ +# { +# "qom-path": "/machine/peripheral/blk1/virtio-bac= kend", +# "type": "qom-object" +# }, +# { +# "qom-path": "/machine/peripheral/blk2/virtio-bac= kend", +# "type": "qom-object" +# } +# ], +# "poll-max-ns": 32768, +# "poll-grow": 0, +# "poll-shrink": 0, +# "aio-max-batch": 0 # }, # { -# "id":"iothread1", -# "thread-id":3135, -# "poll-max-ns":32768, -# "poll-grow":0, -# "poll-shrink":0, -# "aio-max-batch":0 +# "id": "iothread1", +# "thread-id": 3135, +# "holders": [ +# { +# "export-id": "export0", +# "type": "block-export" +# } +# ], +# "poll-max-ns": 32768, +# "poll-grow": 0, +# "poll-shrink": 0, +# "aio-max-batch": 0 # } # ] # } --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562124; cv=none; d=zohomail.com; s=zohoarc; b=Kagj4o10hwFOnpQQG3OEt0cKzgSbIVSF8bOnIq2+sQQKQ/sCT5SVF7YQFctSIFk7q03nvZ4ioEX61QSTzv+zXt6nu88ZtmdG8J+V2PheOuU7d7Y8RL7bQmhfoWOUkL7eaSIKvo/knmAp4k3HWyxk5nGKfI9blbGe/Qpc2jywo54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562124; h=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=Aa1Se10rnJvM268DxeWKC18tnn8TJ+vPA37YY/Vutk4=; b=fPErnOzLIzKdsGHgtUNiZ7kO0yV+JPspQ2kJWCjEq7oUN//6cHqZZ07u7QjoXjmbazt80YD1BsFH4yUXXDVEKsdV5zEmFoWpJgwX/wJBzfWYYKBGVqvIicGxdv3vv1jWdNedWaCE+K+3mQSCBqE3RGn8qAW2MFf2S6LK0CwJ6KE= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562124242831.0585361256777; Fri, 13 Nov 2026 01:28:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYW-0000bQ-45; Fri, 13 Nov 2026 04:26:48 -0500 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 1xRnYL-0000WD-7P for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:39 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYJ-0005zO-HY for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:36 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2ed3d8877e6so10060015ad.3 for ; Fri, 13 Nov 2026 01:26:33 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:26:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794561993; x=1795166793; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Aa1Se10rnJvM268DxeWKC18tnn8TJ+vPA37YY/Vutk4=; b=hRWiov6z52UcwY+t7JuzrRCC7ZN+DXnZZj8+nPHHjoPC+AEW9Pw0wz8PC+n17huv19 nuaI23FAL9NWKvAQ411MFmeokocJp7PdoiNvzqpo9t2fXKOEVT/EURRJZPDa42U/DZd/ rwtIU9bFWmnP4t4qw+6iMOH9xy2BMX7Uo0KuJpcoLGOUjx75W8YAaeo2ioilEGbzrXuz QirvidpOKxlMc18C+ZCeK+imvkd6Jl/JF8wAUZVllne8/WFNvo+4BR+Vb5fNbYVfjHxz VObLH9pO/YMdqizMhm7fof0oX9w/J7jOZXw8QQuXf/DvWFQ5xMc2MsIL0DVWYajA51xr bOxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794561993; x=1795166793; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Aa1Se10rnJvM268DxeWKC18tnn8TJ+vPA37YY/Vutk4=; b=U+LTOZKap6KCW7pyDC+oU7xOpoWUxDvxznJ/G4J2Yys4KVywhqyejwApJd4rhGEoWH fyvsCCZJMijxoaq9MM8DGoP1pWE3QyQTnwT6mNJ28+rwcMUtB6xU9ceToiOCz2uGNuue FkpROOiEM9GF9R+5KT0uH96nXXBtiaPnn3XDKtyR+pCOgiWpMd5J2T/7Gg8sNdwaKL/L Pdgiib5Fs1jkaFTY1DlxvSMs/CB9TswlVGxWaq6oZCKUweTeCnEG1T8BEQwKrraQr6pS otLzCfw5NJqboWXawpE2eVkUdV2vWY4iE9iVZ0Kv6TkToNdARUaV2TgBFTEcI4t4CyNM I7Wg== X-Gm-Message-State: APuU4Z/47G7USoxITYoepVf4OUgSVW2Yoy5+VNOXBzTkkUtsNbBIBalm yvA6BpUzEJPsBrqi557dhNGX9uSQmD19MlBPymVf4lNcwQjR+DEAuLNNI8iY1mPZ X-Gm-Gg: AYBFou231SE/1sK75sXma1tj0jYF1ntxdS2iAHjKLLptYX/h0e2out3lXv5uO/ppYFp shq04UJ2Id0AVirdAuVTOgklCPwVyaCmqVPgYCsK+GxkxLXK1FAkLBRVgoBbNwv+fGcp2O3mEfo tZQGI4H0ZuS8frTFMUpH9YiUUFgE1QzHg8fQAick2xTbDRRNeBWK9oP2kcx0KBcRaMwU/0HMnIS bIwh838gY5QDJ1uJEKvqn5VrMlhOpykw6CclyyxNmZdMp5Npw1N0yYKTWrEg9ZuuPu9k/cbUnik fNd+0O08A4bjNXcxGYTtLmVd1EGeQAEY88czf/0d1kKMoR7P7urgqaW3MLhz4pGgO+hBD+yf3/C AiRP/Z/Amy39ukY00VSyGobg/UIk5vimduDtorJ0Fp0W1K8BRNCEDmkwQAP13qrhLaEW6i97LmC tB0MOR3FCqPwpT0LcpSFuzz1OJYkLArBTqvY+X1xLd8K/la4aMEZsCXM6oVr2Vl4dBcE1Hg8Nvy qltOErY2FBVvGQO/LKXSKyqBuiEmH24Y2Z9s3VJxOFVsByfydaRLxRxBtIkC8CiX8bOqx4/oNyV lYW2WM5otu9ZTRQmiPWnz5NJzJCqzPNjLnYCIYI0ACvl68C1noF1XHjh2uE= X-Received: by 2002:a17:903:1c2:b0:2ec:ff7f:6f8 with SMTP id d9443c01a7336-2ee0deed26amr23259825ad.57.1794561992589; Fri, 13 Nov 2026 01:26:32 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 02/14] iothread: add holder-aware AioContext accessors Date: Fri, 13 Nov 2026 17:25:53 +0800 Message-ID: <20261113092605.942292-3-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::630; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x630.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562125693158500 Content-Type: text/plain; charset="utf-8" Introduce iothread_ref_and_get_aio_context() with a holder argument and its counterpart iothread_unref_and_put_aio_context(). Previously, users of an IOThread AioContext did not explicitly record their identity, making it difficult to debug which devices or subsystems were pinning an IOThread. These new helpers provide the infrastructure for callers to register their identity. Subsequent patches convert existing users to the new helpers. Registering a holder takes an IOThread object reference so that the IOThread and its AioContext stay alive until the matching put operation. Document the ownership and BQL requirements. Reviewed-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster Signed-off-by: Zhang Chen --- include/system/iothread.h | 22 ++++++++++++++++++++++ iothread.c | 24 +++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/include/system/iothread.h b/include/system/iothread.h index b8aeb32b0e..f6c5f95dd9 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -67,6 +67,28 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); AioContext *iothread_get_aio_context(IOThread *iothread); + +/* + * Register @holder and return @iothread's AioContext. The holder is copi= ed, + * and a reference is taken on @iothread so that both the IOThread and its + * AioContext remain alive. + * + * The caller must eventually call iothread_unref_and_put_aio_context() wi= th an + * equivalent holder. This function is not thread-safe and must be called + * under the Big QEMU Lock (BQL). + */ +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder); + +/* + * Unregister @holder and release the corresponding reference on @iothread. + * Calling this function without a matching + * iothread_ref_and_get_aio_context() call is a programming error. + * + * This function is not thread-safe and must be called under the BQL. + */ +void iothread_unref_and_put_aio_context(IOThread *iothread, + const IOThreadHolder *holder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 /* diff --git a/iothread.c b/iothread.c index b9889be845..774c356b71 100644 --- a/iothread.c +++ b/iothread.c @@ -34,6 +34,11 @@ void iothread_ref(IOThread *iothread, const IOThreadHold= er *holder) assert(holder); =20 QAPI_LIST_PREPEND(iothread->holders, QAPI_CLONE(IOThreadHolder, holder= )); + /* + * This guarantees that the IOThread and its AioContext remain alive + * as long as there is a holder. + */ + object_ref(OBJECT(iothread)); } =20 static int iothread_holder_compare(const IOThreadHolder *holder_a, @@ -79,6 +84,7 @@ void iothread_unref(IOThread *iothread, const IOThreadHol= der *holder) *prev =3D curr->next; curr->next =3D NULL; qapi_free_IOThreadHolderList(curr); + object_unref(OBJECT(iothread)); return; } prev =3D &curr->next; @@ -200,7 +206,7 @@ static void iothread_init_gcontext(IOThread *iothread, = const char *thread_name) g_autofree char *name =3D g_strdup_printf("%s aio-context", thread_nam= e); =20 iothread->worker_context =3D g_main_context_new(); - source =3D aio_get_g_source(iothread_get_aio_context(iothread)); + source =3D aio_get_g_source(iothread->ctx); g_source_set_name(source, name); g_source_attach(source, iothread->worker_context); g_source_unref(source); @@ -422,6 +428,22 @@ AioContext *iothread_get_aio_context(IOThread *iothrea= d) return iothread->ctx; } =20 +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder) +{ + /* Add IOThreadHolder to the list */ + iothread_ref(iothread, holder); + + return iothread->ctx; +} + +void iothread_unref_and_put_aio_context(IOThread *iothread, + const IOThreadHolder *holder) +{ + /* Delete IOThreadHolder from the list */ + iothread_unref(iothread, holder); +} + static int query_one_iothread(Object *object, void *opaque) { IOThreadInfoList ***tail =3D opaque; --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562119; cv=none; d=zohomail.com; s=zohoarc; b=OEg6HzcqDoxuarT8XsCMPndgogfCO8ERBl6tGxjxocJx9pCdRJrqvZPU6DXjYlFsNiGB8Hdv+ZW0H3l6zMOcGg0SGcV8hx+Wx0/t76irixH9MywJdCn9yAcehSE1aVAi0Vvubroo0HGykSLPecMpmcgyXgabJHhW5TT0sPSKU9E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562119; h=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=Z8x/Kjb3LFSKjH4X1E0LG5Wat9YzKYyvVsrKHxncOxM=; b=MqnT1cmXKtAKun0LFn2oKSHfWWNpT5WtOV6IGblkenJP4BRWAgep+wcUBU38ZP/zHMFsCOl+FnvaSCOMpaOlQUv+5Te9qJh5nrA4DK5jdvuqc+HdO53WUjt2xdQ2stIKqQD0Tw8fB1dOkaQBhRpMF0QDIPneGEqMm3Q3P0rrmRE= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562119130569.8274451720876; Fri, 13 Nov 2026 01:28:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYW-0000ce-Og; Fri, 13 Nov 2026 04:26:48 -0500 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 1xRnYN-0000XE-J0 for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:41 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYL-0005ze-Sa for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:39 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2e9eb579c0eso4082915ad.3 for ; Fri, 13 Nov 2026 01:26:37 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:26:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794561996; x=1795166796; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Z8x/Kjb3LFSKjH4X1E0LG5Wat9YzKYyvVsrKHxncOxM=; b=OIIsskFeljCJ8rq9B6m2FFRDw6StGd+m6M4DuQzBe5W9CuTCpSa9U2Z5y79w4F+8QX d6aIMy1aexbttC1t6sW3/AHjzOum7pBiFU2TZtfa6dj3uzeiGc6PMvPS1JwR/4uzHzRJ +vnwucIz8LPGGRJ/rmh2qcUye/o1+1/WAKs51BcbwoK2PgzMR7JY/ebUVXbozoMLqhHX G50DsMhaQHiz/9sRN2EIPNqdMv2BDo6Wn9O4ZqXG63NLG+Kxc0FHpSd3pzUyoBZxNFuR mGcmjzx5oDDBuO4E8lzzkS95GlvjhkwnS30kbuCTQQPSSSE2lM0hfcFDYd2R24w8iph2 R1zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794561996; x=1795166796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Z8x/Kjb3LFSKjH4X1E0LG5Wat9YzKYyvVsrKHxncOxM=; b=IGtJlBEtiBjSgIYvYwNwR7n1a7qcnn01p696fDR/WRLIMmTYESQ0nmtD8Y2rFrrHQ/ xa4ofiHar97jz8I9azunvj/uKLcTrVyw0I+uDaa5qBsN8YSJKH/NExCrQs/MoHk5uJAT 2u7nT0e8qSPaLsNLe8JeZVBb4/6/dPJaXdMlu/OVGbhLmTAZNU9Lc+BvlTMeucij7djk Gxe9ZutXQiooxU1puOzEhd5AUkh71H7XRW4/TifZb3HODDD5gdQ8aFyUtybW1S+Wc7EF uzo6uqRpmiqr6YG2dMbSqUEpWQvyew2dnE0Oqkfvh0eKKCpLlE1hqpQgQKgl56oLPTWu EzCQ== X-Gm-Message-State: APuU4Z8ZcjTE6lqCmu/CZNJgxYARuMQM4O+/jN+YZnzDgAueI2jXc286 Z/BUtwOnoLi4f5tDHWlTDzUxVMfirLSI+j4NDNx68w9b4GQLJwYxxodSskb1CR0Q X-Gm-Gg: AYBFou2b0EaHHANDCu/4AVrNnwUQOZoZWZ1B99vENn9BSkKKKM62RypFbZpX6OgNGPT NQ6CPkufydzdct4sBSFi8Cc7Ak393vpXnd85NLEUwaqUGCnbZsoKVo+ObtTSjrQ9qLmIuHwkmdy junD9dUBkm0kuA38ucsp2yeVtDgYRUVcO7Gze+dNrFi5j78+9+vmZxATFdZVCSn5QEO6LnvOl8a IgsRRXK67C6/6yHbUbFv032INfvTzuGwcZircNyAE5BQIojJYoBeAeFb5y1C/cr5a+LazLiKTR5 zrtKssjzrkFdP2G9qDo3cADpVn+OjX/DceZTq+hhLFLPdoP2mhbtgXw9WjXO9zhUmtT3g8U/McP lrvS4OI6dJR2zVaB8ld7jB4WI/P/zhHe9HFDEOJIbpNcAcSI5ZB3ce3salcxwT2EBDyFj76lbxR fxnayF656bsJp8l6RDx/kSpW/uMNvwlYp4V2TAZviwOhyjQANauFyHbDdiDA5Hsxg8j8NMGX5J9 VEUtLMfNf8T8igjeSecJ9bDWpSVS3PW+uRp5CIBliMm9SpBhfXntAvrQ0crKxvrIkkOJZBvmC/Q 8hD+osnsvwMnlLkt638klOTgirMv1PgUUnhZjMoMbNMlDwy0s4kxEBIAQzw= X-Received: by 2002:a17:903:22c5:b0:2dd:c0ff:e72c with SMTP id d9443c01a7336-2ee0dcc8ea8mr18889945ad.62.1794561996540; Fri, 13 Nov 2026 01:26:36 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 03/14] block/export: track IOThread references Date: Fri, 13 Nov 2026 17:25:54 +0800 Message-ID: <20261113092605.942292-4-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::62c; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62c.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562119613158500 Content-Type: text/plain; charset="utf-8" Track the IOThreads used by a block export and identify the holder with the unique BlockExportOptions id. Acquire holder-aware references during export creation and release them on error or export deletion. Support both single- and multi-iothread exports. Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen --- block/export/export.c | 62 ++++++++++++++++++++++++++++++++++++------ include/block/export.h | 5 ++++ 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index b733f269f3..0e019545ef 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -15,7 +15,6 @@ =20 #include "block/block.h" #include "system/block-backend.h" -#include "system/iothread.h" #include "block/export.h" #include "block/fuse.h" #include "block/nbd.h" @@ -72,6 +71,32 @@ static const BlockExportDriver *blk_exp_find_driver(Bloc= kExportType type) return NULL; } =20 +static void init_iothreads(const char *holder_id, IOThread **iothreads, + size_t num_iothreads, AioContext **aio_ctxs) +{ + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_id =3D (char *)holder_id, + }; + + for (size_t i =3D 0; i < num_iothreads; i++) { + aio_ctxs[i] =3D iothread_ref_and_get_aio_context(iothreads[i], &ho= lder); + } +} + +static void cleanup_iothreads(const char *holder_id, IOThread **iothreads, + size_t num_iothreads) +{ + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_id =3D (char *)holder_id, + }; + + for (size_t i =3D 0; i < num_iothreads; i++) { + iothread_unref_and_put_aio_context(iothreads[i], &holder); + } +} + BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) { bool fixed_iothread =3D export->has_fixed_iothread && export->fixed_io= thread; @@ -85,6 +110,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Err= or **errp) AioContext *ctx; AioContext **multithread_ctxs =3D NULL; size_t multithread_count =3D 0; + g_autofree IOThread **local_iothreads =3D NULL; + size_t iothread_count =3D 0; uint64_t perm; int ret; =20 @@ -139,7 +166,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) goto fail; } =20 - new_ctx =3D iothread_get_aio_context(iothread); + local_iothreads =3D g_new0(IOThread *, 1); + local_iothreads[0] =3D iothread; + init_iothreads(export->id, local_iothreads, 1, &new_ctx); + iothread_count =3D 1; =20 /* Ignore errors with fixed-iothread=3Dfalse */ set_context_errp =3D fixed_iothread ? errp : NULL; @@ -163,8 +193,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) return NULL; } =20 + local_iothreads =3D g_new0(IOThread *, multithread_count); multithread_ctxs =3D g_new(AioContext *, multithread_count); i =3D 0; + for (strList *e =3D iothread_list; e; e =3D e->next) { IOThread *iothread =3D iothread_by_id(e->value); =20 @@ -172,9 +204,12 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) error_setg(errp, "iothread \"%s\" not found", e->value); goto fail; } - multithread_ctxs[i++] =3D iothread_get_aio_context(iothread); + local_iothreads[i++] =3D iothread; } assert(i =3D=3D multithread_count); + init_iothreads(export->id, local_iothreads, multithread_count, + multithread_ctxs); + iothread_count =3D multithread_count; } =20 bdrv_graph_rdlock_main_loop(); @@ -225,12 +260,14 @@ BlockExport *blk_exp_add(BlockExportOptions *export, = Error **errp) assert(drv->instance_size >=3D sizeof(BlockExport)); exp =3D g_malloc0(drv->instance_size); *exp =3D (BlockExport) { - .drv =3D drv, - .refcount =3D 1, - .user_owned =3D true, - .id =3D g_strdup(export->id), - .ctx =3D ctx, - .blk =3D blk, + .drv =3D drv, + .refcount =3D 1, + .user_owned =3D true, + .id =3D g_strdup(export->id), + .ctx =3D ctx, + .blk =3D blk, + .iothreads =3D g_steal_pointer(&local_iothreads), + .iothread_count =3D iothread_count, }; =20 ret =3D drv->create(exp, export, multithread_ctxs, multithread_count, = errp); @@ -250,8 +287,12 @@ fail: blk_unref(blk); } if (exp) { + cleanup_iothreads(exp->id, exp->iothreads, exp->iothread_count); + g_free(exp->iothreads); g_free(exp->id); g_free(exp); + } else { + cleanup_iothreads(export->id, local_iothreads, iothread_count); } g_free(multithread_ctxs); return NULL; @@ -273,6 +314,9 @@ static void blk_exp_delete_bh(void *opaque) exp->drv->delete(exp); blk_set_dev_ops(exp->blk, NULL, NULL); blk_unref(exp->blk); + + cleanup_iothreads(exp->id, exp->iothreads, exp->iothread_count); + g_free(exp->iothreads); qapi_event_send_block_export_deleted(exp->id); g_free(exp->id); g_free(exp); diff --git a/include/block/export.h b/include/block/export.h index ca45da928c..ce8e4eb604 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -16,6 +16,7 @@ =20 #include "qapi/qapi-types-block-export.h" #include "qemu/queue.h" +#include "system/iothread.h" =20 typedef struct BlockExport BlockExport; =20 @@ -89,6 +90,10 @@ struct BlockExport { =20 /* List entry for block_exports */ QLIST_ENTRY(BlockExport) next; + + /* The IOThreads utilized by this specific block export */ + IOThread **iothreads; + size_t iothread_count; }; =20 BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp); --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562042; cv=none; d=zohomail.com; s=zohoarc; b=W8feqHjB65j/7Ofvl2KOxZRJMjbNLIxxiJAVor8TeX6GLPEXVC9Vq0iaLa+TDDQSEoo2fbvP8YZCKWJPaOjEPOaidGN0Shd7l5anDvLrmnjh6olJcnNsBhTZleAu/b6Y2vY2P8JC43TxBl1E1EhQCvxKGE2652TrhabWEo2Qmok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562042; h=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=lmSXk9na7HUzn8TADoldzDrCh1LF9ANFf5sI+5rguhU=; b=Y35fxpjgCQdM+6cxQfC8MKhw0KB3q5XPuaOioTHtHhJkLsxJS07KuAQZaxYDiQ5WaepmUk2DMRlhBtUhYgP+27gojcxhuGAll08jiIWIJc5h2MmtIqsXqdOxypE41rqQTDp8SiOMh5BSbsQuQp0iZQbtvw7rzmgbRCpwSO/Xl30= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562042037112.94326356722229; Fri, 13 Nov 2026 01:27:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYY-0000dj-NR; Fri, 13 Nov 2026 04:26:50 -0500 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 1xRnYR-0000YJ-Bx for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:44 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYP-0005zw-EJ for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:43 -0500 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2e99b1e5b4cso4380495ad.0 for ; Fri, 13 Nov 2026 01:26:41 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:26:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794562000; x=1795166800; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lmSXk9na7HUzn8TADoldzDrCh1LF9ANFf5sI+5rguhU=; b=MnaXPdMdUG05L5wDJk0iqbz/kfc/EeU1uH+whpvXHBSG1GAJyGnP+R9ka6I+N+rqTa UIDKLT4QNy0DPRV/1WDDooeYzSt15DyoqxRCLuExM34aUX8MDa6a+NdYz3DDsyI1Kx03 Fve7aQOq7zOywCTo4BJWuNCxSUI9KHPN1CJRI+yzM0tnEtd/XypUh1aNP51tEj/uU+GR CrbwvOMw+SIA/2QD37Y36CY7wk5pf3uhrDBZmg/zRDAT/TToe3PDQZfZl8/+Z+a3xpzL tZ1wf3jlgLgx4RrWiCklUqiNLc3JZ4ia+ReAi56IgnJnxp1ARK6XoxLIwcCl6fAQ30Kk fcjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794562000; x=1795166800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=lmSXk9na7HUzn8TADoldzDrCh1LF9ANFf5sI+5rguhU=; b=1uq7BuneWtu6L2KiBydkUk5Wf9bkY+Sxwih6gwLCgHUT8NWwMgPW0bOUa4TKb2jduC 0cZwXVqCsx5TpfK7e8ZQ45GcbzNlI8R/yI2nZWqcD9PQ7zodCWURHNpRUh8uLLRj980W xPGT87xca3X1XIhqAnkl+u/3LQ0LqEm6rdFquxAv1vSMla7iluvulzEbPkpwq3y4//gr oE5tAmCk70yCgfL672Fzqy/iB2GTNFxN3SO02UzHhFU9jeWd6m+tzgBrzPsojoF/Cty0 62kQSO5a2X95BJznI1qAMuMHsxIlIWGKajiJEUMCgHuDgReaoyx1s7gTEVTQbOVWkyMA XpWQ== X-Gm-Message-State: APuU4Z9V00rX0C/M+2ckQh9Wi1MnMrnkrc6+s9i4y0+Q7KqBFrhml8Iq Ipuk1nNnwxo719Nl0qGgwGnu9YFJbmdvpR5EmRy7bAdhk9pqVBXN+pBcv/kbHNts X-Gm-Gg: AYBFou0z2RonlF39tAzEfHMES0C9blht0BClL1jShHIcdTdwS5ipbmTnVl7wi8LDQJT c0SohoxUWAfXkXmvR1whVYFhxXpGzo5ZDohT7V72ixA4eYoP6bqbPMtsGyEDnp4SEPxug1gpWPf Dt6ffEzy09vXWGsHKZcz7jBVC0OXCuKSraAzWamKpFHfca/CBIlHo1tE7Z8bZek/jaISqokONQk IfluljtSX3F7J2qNGkiltj38TVid5tmNMIyKYExUNksqbdR9s/F6u+ok+FLAaErfgs3CGTKJxSu lDf8Q+wAsGQj86pZwUn2B5Nb4depa87a/rkakPaMHhYduoE8up0SAMoQsVGkYPBGlPuDla1Z5vU m9EAnhdhBmHp07OowKd8E2gBsegCynwexGLXwPLYb9tehMFIvCn9vnweuRNrfONFqAiQ8mEx61b Xt+4QRLRc/jYDmRS0ziTZ/xHd1slMhAsQGmTUEQ3p5whLog9doLNqaYunK1hRmzjZulH0KVD5Ys 6X2GPIL2qMV5q2yuZcw13FptD2rOegP2l/t/0Bvsb3YougR0UKpghEoGiH38HhGEmUee6zQiRMK i3kWJE0qPChONJk+I2BKQF9YrKGPZ/tDOE7YOVnQR7nOJIJjixyutXxiCcY= X-Received: by 2002:a17:902:d512:b0:2e9:5ec6:bfc9 with SMTP id d9443c01a7336-2ee0da7bdc0mr17458705ad.9.1794561999778; Fri, 13 Nov 2026 01:26:39 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 04/14] monitor: track IOThread users with QOM paths Date: Fri, 13 Nov 2026 17:25:55 +0800 Message-ID: <20261113092605.942292-5-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::636; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x636.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562043200158500 Content-Type: text/plain; charset="utf-8" Monitors that require an IOThread share the internal mon_iothread. Account for each monitor explicitly in IOThread holder tracking, using the monitor's canonical QOM path to distinguish holders. Acquire the shared monitor IOThread AioContext once and store the IOThread and canonical QOM path so the holder can be released after the monitor has been removed from the QOM tree. Use the stored IOThread for per-monitor checks and accesses after initialization, and reuse the stored context for later operations. Release the holder from monitor_finalize(), after resources associated with the AioContext have been destroyed. This pairs the reference taken in complete() with instance finalization and keeps the IOThread alive throughout monitor teardown. The internal mon_iothread remains hidden from query-iothreads, as before. Management applications therefore cannot use it to determine which monitors are using the IOThread. Nevertheless, track the monitor holders so that they follow the same explicit holder and IOThread reference lifecycle as other AioContext users. Signed-off-by: Zhang Chen Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi --- monitor/monitor-internal.h | 7 +++++-- monitor/monitor.c | 36 ++++++++++++++++++++++++++---------- monitor/qmp.c | 14 +++++++------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 822a66d06d..856948067b 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -77,6 +77,11 @@ struct Monitor { GString *outbuf; guint out_watch; int mux_out; + + /* iothread context and holder identity */ + IOThread *iothread; + char *qom_path; + AioContext *ctx; }; =20 struct MonitorQMPClass { @@ -109,14 +114,12 @@ struct MonitorQMP { }; =20 typedef QTAILQ_HEAD(MonitorList, Monitor) MonitorList; -extern IOThread *mon_iothread; extern Coroutine *qmp_dispatcher_co; extern bool qmp_dispatcher_co_shutdown; extern QmpCommandList qmp_commands, qmp_cap_negotiation_commands; extern QemuMutex monitor_lock; extern MonitorList mon_list; =20 -bool monitor_requires_iothread(const Monitor *mon); int monitor_can_read(void *opaque); void monitor_cancel_out_watch(Monitor *mon); void monitor_list_append(Monitor *mon); diff --git a/monitor/monitor.c b/monitor/monitor.c index 2654b81890..4e2b96b2e8 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -55,7 +55,7 @@ typedef struct { } MonitorQAPIEventConf; =20 /* Shared monitor I/O thread */ -IOThread *mon_iothread; +static IOThread *mon_iothread; =20 /* Coroutine to dispatch the requests received from I/O thread */ Coroutine *qmp_dispatcher_co; @@ -93,6 +93,16 @@ static void monitor_finalize(Object *obj) qemu_chr_fe_deinit(&mon->chr, false); g_string_free(mon->outbuf, true); qemu_mutex_destroy(&mon->mon_lock); + + if (mon->iothread) { + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D mon->qom_path, + }; + + iothread_unref_and_put_aio_context(mon->iothread, &io_holder); + } + g_free(mon->qom_path); } =20 static char *monitor_get_chardev_id(Object *obj, Error **errp) @@ -164,7 +174,7 @@ Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) return old_monitor; } =20 -bool monitor_requires_iothread(const Monitor *mon) +static bool monitor_requires_iothread(const Monitor *mon) { MonitorClass *cls =3D MONITOR_GET_CLASS(mon); return cls->requires_iothread && cls->requires_iothread(mon); @@ -188,8 +198,8 @@ void monitor_cancel_out_watch(Monitor *mon) GMainContext *ctx =3D NULL; GSource *src; =20 - if (monitor_requires_iothread(mon)) { - ctx =3D iothread_get_g_main_context(mon_iothread); + if (mon->iothread) { + ctx =3D iothread_get_g_main_context(mon->iothread); } src =3D g_main_context_find_source_by_id(ctx, mon->out_watch); if (!src && ctx) { @@ -516,12 +526,12 @@ void monitor_suspend(Monitor *mon) { qatomic_inc(&mon->suspend_cnt); =20 - if (monitor_requires_iothread(mon)) { + if (mon->iothread) { /* * Kick I/O thread to make sure this takes effect. It'll be * evaluated again in prepare() of the watch object. */ - aio_notify(iothread_get_aio_context(mon_iothread)); + aio_notify(mon->ctx); } =20 trace_monitor_suspend(mon, 1); @@ -661,7 +671,6 @@ char *monitor_compat_id(void) static void monitor_complete(UserCreatable *uc, Error **errp) { Monitor *mon =3D MONITOR(uc); - AioContext *ctx; =20 if (mon->chardev_id) { Chardev *chr =3D qemu_chr_find(mon->chardev_id); @@ -680,11 +689,18 @@ static void monitor_complete(UserCreatable *uc, Error= **errp) mon_iothread =3D iothread_create("mon_iothread", &error_abort); } =20 - ctx =3D iothread_get_aio_context(mon_iothread); + mon->iothread =3D mon_iothread; + mon->qom_path =3D object_get_canonical_path(OBJECT(mon)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D mon->qom_path, + }; + + mon->ctx =3D iothread_ref_and_get_aio_context(mon->iothread, &io_h= older); } else { - ctx =3D qemu_get_aio_context(); + mon->ctx =3D qemu_get_aio_context(); } - mon->accept_input_bh =3D aio_bh_new(ctx, monitor_accept_input, mon); + mon->accept_input_bh =3D aio_bh_new(mon->ctx, monitor_accept_input, mo= n); } =20 int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp) diff --git a/monitor/qmp.c b/monitor/qmp.c index 2f66257e4a..e3edd17ca8 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -188,7 +188,7 @@ static void monitor_qmp_caps_reset(MonitorQMP *mon) memset(mon->capab_offered, 0, sizeof(mon->capab_offered)); memset(mon->capab, 0, sizeof(mon->capab)); mon->capab_offered[QMP_CAPABILITY_OOB] =3D - monitor_requires_iothread(MONITOR(mon)); + MONITOR(mon)->iothread !=3D NULL; } =20 static void qmp_request_free(QMPRequest *req) @@ -680,8 +680,8 @@ static void monitor_qmp_setup_handlers_bh(void *opaque) MonitorQMP *mon =3D opaque; GMainContext *context; =20 - assert(monitor_requires_iothread(MONITOR(mon))); - context =3D iothread_get_g_main_context(mon_iothread); + assert(MONITOR(mon)->iothread); + context =3D iothread_get_g_main_context(MONITOR(mon)->iothread); assert(context); qemu_chr_fe_set_handlers(&mon->parent_obj.chr, monitor_can_read, monitor_qmp_read, monitor_qmp_event, @@ -719,7 +719,7 @@ static void monitor_qmp_complete(UserCreatable *uc, Err= or **errp) =20 qemu_chr_fe_set_echo(&mon->parent_obj.chr, true); =20 - if (monitor_requires_iothread(MONITOR(mon))) { + if (MONITOR(mon)->iothread) { /* * Make sure the old iowatch is gone. It's possible when * e.g. the chardev is in client mode, with wait=3Don. @@ -736,7 +736,7 @@ static void monitor_qmp_complete(UserCreatable *uc, Err= or **errp) * thread. Schedule a bottom half. */ mon->setup_pending =3D true; - aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread), + aio_bh_schedule_oneshot(MONITOR(mon)->ctx, monitor_qmp_setup_handlers_bh, mon); /* The bottom half will add @mon to @mon_list */ } else { @@ -790,8 +790,8 @@ static bool monitor_qmp_prepare_delete(UserCreatable *u= c, Error **errp) } =20 /* Synchronize with in-flight iothread callbacks. */ - if (monitor_requires_iothread(mon)) { - aio_wait_bh_oneshot(iothread_get_aio_context(mon_iothread), + if (mon->iothread) { + aio_wait_bh_oneshot(mon->ctx, monitor_qmp_iothread_quiesce, NULL); } =20 --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562093; cv=none; d=zohomail.com; s=zohoarc; b=EJdRYCx54DYh8U9dEMVHXeeTB+P0xbz9NZoNs3jSn5TlfQ7zfDA5Vs4wProFcHAUza9ENcV9lHPhl0UmEKxz86DAjsydi4vYX6Er4Xo2eRyl86y8AsKL11g8rUS4pguhbcXj6dBS0baeoIP76X9fYtSdh56k68kC7t0hriYnHE8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562093; h=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=CWZOQqO+lHf+7x9HQxty2nhhjD/yR6AHU1HcExeqxHA=; b=Pzyg9h7fs4t6llKIO5ezf4laPjM73elR7I7xcIrOmFsxhCXZ1JMUOGAv0Zdsxcsozmdv4AJbVsYDBP1HqjunioTFlvyGJAMalI7bAq8SblitAAyxu6moBHFiSPtSrEh7DFm7XPcb+igJbbhOhAqLWg4j/FGDcMmV0cGB4KrP19k= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562093044276.34224707695387; Fri, 13 Nov 2026 01:28:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYY-0000dg-46; Fri, 13 Nov 2026 04:26:50 -0500 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 1xRnYV-0000cB-SC for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:48 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYT-00060C-RB for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:47 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2e9eb579c0eso4083705ad.3 for ; Fri, 13 Nov 2026 01:26:45 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:26:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794562004; x=1795166804; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=CWZOQqO+lHf+7x9HQxty2nhhjD/yR6AHU1HcExeqxHA=; b=OYEDtll+PElnrPnTdnYbZwaUc0D120JxkALnHNbohGNZfpPV0G/AjLwzdw2NxvfIgR ozT8dzYAi42y4j/edYxOiajbxRIe+1Tr10HFeDAOTEmUg/abUL+xSKcRgaUIxMRrpRuA OvqZGY8qxzaTDTxgkLzMDg1cNTFHN60RgXJgZbTrx1ek3MPINPeQHbMN9gw17D9w8V5u MrdZujCvcyX3zRbcaKjoaqLlzGFNZpTvPeVLxL7Is8zBWLgLzkzQAGasOEO0IHGOo49t CHl3rOhI9O1PHPqlNrSblntQsyC0e5afj31PLonbTknaVALcdADB+5c3A53GODmwT9hu WwMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794562004; x=1795166804; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=CWZOQqO+lHf+7x9HQxty2nhhjD/yR6AHU1HcExeqxHA=; b=u41Ayb7EG6I3JYBLXokqKLDqZi2bm4s3tGbXaIS904KYCXHQd15Nzc5b9dBp8vZHje szqBfpak3TgHtxyD9rxcEYnO0qDVWQMizClh7/KsqNviqGGqVlxrc2ZhGG5AEkjAFEVl 4qVXiB6j/V2qhxA2Ez4RdrX6i970J0XWHPa7CtjVIepQpCGgpGWZZvLSIcQsvEne6qUg rTBPN2e18NTJ2JLHJwfcHZ3GU154C9r0DswhaQyX4jg12oD6Jd47kdxMJBgH/ojnQPXG Zi9VDEHtTkBcN4YLb98W0Ee/miKuOSLTp4PeuuE9iyd1L75DZ53PU+9OQ4EeftG8rod1 rZWA== X-Gm-Message-State: APuU4Z8mdkvYkaOxkVmJkgDvcHg+uCbqn5mFcAk+6HBS9vWFrawFNjBc pT72vAJbqSuuQvalYd7LDGtmNg8o4FiTgFo/8UHg731B5uT91AtIWn1p5HMEdem6 X-Gm-Gg: AYBFou2oftxzc3dw9FEbB/ry5yT9BgpwONeahxhlYKd2S9vRjzRbOBt4yYnHweVbdCc EoeFht7xfQsPKNj0EFmeBtdvp9fOqhU+PUneinoI4MfcGHQXip3I2g11QdjeMR3y1ompy6669X1 zZP7nIGpuXog04sKcKfwXiDBxiD5NefO8myyH/GhmP6ZpvHbOmXXeoGON7Ms3S8V0ovs4ZXHF+l is0DEUisGrFa3okXGN6kx1EwTZCC5ltwLJbE7X8LyWkRRAnX6XlM3mPnY0+QXAR8oHmfr/TS5fx SLHayHl8IFeKHdx2QVsK9DYYe1vJ0m92LFtetDVAy8FWFwFOLVVgReOC1iIWpHzUSrOOPY80E9p 0MCAVymrBSlazuHDRyLhjBhH37xo8a3EGQJOBLJnB6z8ykxaVqLAcw8ejjBmNLzviDqznqyphzS Pc7RlSLxQEAc7/J32OPqNcrqQjHUtgESJuA/svbTLR6773DA3x1n15HIRBvUVZcd6tHcfJT029r CZ9ZJjMiulysXAV4h93mFX7FtNbQEQkgiX6eQ8pJ7ew/1tL8IG8VI+Iv5TIhsJMhOTqY5ML4op7 oTXoMaTg7/K3doEfC/231ScsDXNJC0E1QHB9SDqqGGhkDCLxTuBkL7qrMq0= X-Received: by 2002:a17:902:e84a:b0:2e9:7dda:bfc7 with SMTP id d9443c01a7336-2ee0dcd0647mr17167045ad.66.1794562004295; Fri, 13 Nov 2026 01:26:44 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 05/14] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Fri, 13 Nov 2026 17:25:56 +0800 Message-ID: <20261113092605.942292-6-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::62e; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62e.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562093427158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_ref_and_get/ unref_and_put_aio_context in iothread-vq-mapping. This allows tracking IOThread users via the device's canonical QOM path, improving lifecycle traceability for virtio-blk and virtio-scsi devices. Signed-off-by: Zhang Chen Reviewed-by: Stefan Hajnoczi --- hw/block/virtio-blk.c | 8 +++++++- hw/scsi/virtio-scsi-dataplane.c | 9 +++++++-- hw/virtio/iothread-vq-mapping.c | 20 +++++++++++++++----- include/hw/virtio/iothread-vq-mapping.h | 6 +++++- iothread.c | 13 +++++++++++++ 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 9b7c84fda6..6d1d19fa64 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1613,9 +1613,12 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlo= ck *s, Error **errp) s->vq_aio_context =3D g_new(AioContext *, conf->num_queues); =20 if (conf->iothread_vq_mapping_list) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); + if (!iothread_vq_mapping_apply(conf->iothread_vq_mapping_list, s->vq_aio_context, conf->num_queues, + path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; @@ -1647,7 +1650,10 @@ static void virtio_blk_vq_aio_context_cleanup(VirtIO= Block *s) assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index bcb6e44133..ac13f4a1ca 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -65,9 +65,11 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **= errp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); + if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], - vs->conf.num_queues, errp)) { + vs->conf.num_queues, path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; return; @@ -94,7 +96,10 @@ void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); =20 if (vs->conf.iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mappin= g.c index 55ce62986c..60e1d55005 100644 --- a/hw/virtio/iothread-vq-mapping.c +++ b/hw/virtio/iothread-vq-mapping.c @@ -77,6 +77,7 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp) { IOThreadVirtQueueMappingList *node; @@ -93,10 +94,13 @@ bool iothread_vq_mapping_apply( =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - AioContext *ctx =3D iothread_get_aio_context(iothread); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; =20 - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(iothread)); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, + &io_holder); =20 if (node->value->vqs) { uint16List *vq; @@ -120,13 +124,19 @@ bool iothread_vq_mapping_apply( return true; } =20 -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list) +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder) { IOThreadVirtQueueMappingList *node; =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - object_unref(OBJECT(iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; + + iothread_unref_and_put_aio_context(iothread, &io_holder); } } =20 diff --git a/include/hw/virtio/iothread-vq-mapping.h b/include/hw/virtio/io= thread-vq-mapping.h index 57335c3703..0d39caddf3 100644 --- a/include/hw/virtio/iothread-vq-mapping.h +++ b/include/hw/virtio/iothread-vq-mapping.h @@ -17,6 +17,7 @@ * @list: The mapping of virtqueues to IOThreads. * @vq_aio_context: The array of AioContext pointers to fill in. * @num_queues: The length of @vq_aio_context. + * @holder: The QOM paths for attached device. * @errp: If an error occurs, a pointer to the area to store the error. * * Fill in the AioContext for each virtqueue in the @vq_aio_context array = given @@ -31,15 +32,18 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp); =20 /** * iothread_vq_mapping_cleanup: * @list: The mapping of virtqueues to IOThreads. + * @holder: The QOM paths for attached device. * * Release IOThread object references that were acquired by * iothread_vq_mapping_apply(). */ -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list); +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder); =20 #endif /* HW_VIRTIO_IOTHREAD_VQ_MAPPING_H */ diff --git a/iothread.c b/iothread.c index 774c356b71..d4328fc214 100644 --- a/iothread.c +++ b/iothread.c @@ -377,12 +377,25 @@ static void iothread_set_poll_param(Object *obj, Visi= tor *v, } } =20 +static bool iothread_prepare_delete(EventLoopBase *base, Error **errp) +{ + IOThread *iothread =3D IOTHREAD(base); + + if (iothread->holders) { + error_setg(errp, "Cannot delete IOThread '%s' while it is in use", + object_get_canonical_path_component(OBJECT(iothread))); + return false; + } + return true; +} + static void iothread_class_init(ObjectClass *klass, const void *class_data) { EventLoopBaseClass *bc =3D EVENT_LOOP_BASE_CLASS(klass); =20 bc->init =3D iothread_init; bc->update_params =3D iothread_set_aio_context_params; + bc->prepare_delete =3D iothread_prepare_delete; =20 object_class_property_add(klass, "poll-max-ns", "int64", &int64_type_i= nfo, iothread_get_poll_param, --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562060; cv=none; d=zohomail.com; s=zohoarc; b=aqr1gwdSnszua9gn5hLFnMaxyT/GJcIPSpEDhE/UsBrU4QkvuRW61pdZ/jpmX4JGILI/ZE8LNgSJleMgfBHSERT6RQ9Oiqa0ZhtSkQuzcuab63A1YBqBC4MkyOovFCVQOdYwGoedIxGs5SZzW8BZOZVfml/4C7bROMjkdQkcUTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562060; h=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=jbDrwrBOQNI+7OEvgHCHB9D+OfHuqKqpedokOfaVpMM=; b=nubkD1BnWuh8uorYHKkjztSyRmuC7jKX22Ps2TYw6rYVJHw3erzymefMaMY7j6j983kT8NdlJVDcsgmwc2Ke176js9mcnE7hLOgChs6/lubGdX5Q3i5X1F8hgX0/urpbbiQoJ8VhUzgd9V5oNZvZniOIPK8dpQY6rfA2sG5oAuY= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562060550838.251464030685; Fri, 13 Nov 2026 01:27:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYc-0000eW-5p; Fri, 13 Nov 2026 04:26:54 -0500 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 1xRnYZ-0000dn-3S for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:51 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYX-00060R-8d for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:50 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2e946155442so11636295ad.3 for ; Fri, 13 Nov 2026 01:26:48 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.26.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:26:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794562008; x=1795166808; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=jbDrwrBOQNI+7OEvgHCHB9D+OfHuqKqpedokOfaVpMM=; b=cL9NDo6nV8eihfDRqFtFf1KsAnj+xawSpoMmXEEFbp1sJnqMimrjOtJs2H4KE196wW 6xj0YCkiJp4fbuvws8vmgVjEY3h7kCkWo1Ix1Afk2VYpxeSV0d+rybNLziBn9Q4llufu NUy6nEZUHWw5b2291QKZT9l8MfWt1tSsc0oH+/QM8SRsy6CMTPi7ROaip1EpOtjZZ8r8 5VNdIoa8gBk7aQfXwJnzC6tQTf00EVsDTOyQWiQMPFTetSrA1rG74F/dUcMukpW0rhqj BT+DjD4g7LM/jMNNqEUQiK7OeCS07XmhSOZYsrqTsMbOcx96o16q7tTwGlR0t69DMmHU xKEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794562008; x=1795166808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=jbDrwrBOQNI+7OEvgHCHB9D+OfHuqKqpedokOfaVpMM=; b=Yw3IUwwP5c9Nn4nUutdcZAJ4fDLVjCzffKf8YWy6ov+N8EhRAdGLYS4AkbZgs4GPYL chFtIdmfWFJ2upltZz/zcl/4Br38xDFvYQ0zhDSSjUf3UyoJ1y+2Orqpuym5RCPr7uik QM6N0AU5KUc1dV7PHhrYmADFVh6RVPTWporUhIGYK8vZowHBHe9/NNI8K1V2f/Qz5wR9 M0aQ2TNgrKOTqxDHBr26+usI1BpdQgK2w1tzn7It6Q8Cyt3w5wLKn3Zr+5FnkUfO03TW A3ICP7+5mN9l7zyFZ8vmtftDlQ0qWr49ZfLukQSryZsHhL7n6pD3SKTYdG738myydCGB bzhQ== X-Gm-Message-State: APuU4Z8M6RQLxuxaVTMuzpsCCgtF8M+hiJnyx5hHZz3rEaeprXGp9puM tuM+MS7b+pojkhJSB2pN0vwukW3STWqKMIsVIlsdgBZzwP8zcjgM6g7UMxtGbwVY X-Gm-Gg: AYBFou0RIyTYAHoK8Mc0wJZIuDpKovMIM4ugt7c6WlZwndsMEk1sN+bkuxshSTjg6P1 4t6aYHwIiuEYJBVNm4C2I0SrKTZjH/PJgmFEjxF8EG0xl0rH8Aom1aXV0wcn4N0r2ORhpJ/2rhg EySNobbq2mlToG6bXLRIELFHvUAp6AOiv5yqYlO0I2lRp3yRjWgDMnL3Pcjpwsdufuox8mTzlmS QlbRQQ17Tmb4dO/1JaHKN/miNyfxQtHr+25fthHQCD8a8pYKHcZwCxDlon5vPZlsqT3TlKKsGJF WdCxOrasiMg6KZZ3yvL+RMMOdiivVnbmaGG815GJayku+v15EkiDTv/5n/lfN4TPEQQHYPaJTRG zGn62DcV+QiyCO5nLhUPZiqbI0xHv2sZ2cwm5LjVlOXOGpMlQF5SozTXCjnO8PiI2Gl52UU5O9K QOksZh/GSmxiAqHEE/Wdcs67+GAdXmm2uWoqIeVIiZCudgViliJBVHJQJg6yrzlqN9wDpv997Cu kkxWab+M1yPMX2uO1FZ8CHmNfxPURl7yvP9uG/xbHzXXnAQoJy6XpUeh3dDJC4i9XPKJ9voCMIE y1dh296yeI8cFVxqBAsbz4E1rlHPHaNfucRNcnBPzBRHnPkGYdfP/ffh6+DY X-Received: by 2002:a17:903:249:b0:2e4:b112:14d with SMTP id d9443c01a7336-2ee0dcc6572mr18688915ad.54.1794562007768; Fri, 13 Nov 2026 01:26:47 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 06/14] virtio: track IOThread references for thread pinning Date: Fri, 13 Nov 2026 17:25:57 +0800 Message-ID: <20261113092605.942292-7-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::62c; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62c.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562061182158500 Content-Type: text/plain; charset="utf-8" Use the virtio device canonical QOM path as the holder when virtio-blk and virtio-scsi acquire an IOThread AioContext. Replace the raw object references with the holder-aware acquire/release helpers so the users are visible through IOThread introspection. Signed-off-by: Zhang Chen Reviewed-by: Stefan Hajnoczi --- hw/block/virtio-blk.c | 23 +++++++++++++---------- hw/scsi/virtio-scsi-dataplane.c | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 6d1d19fa64..933f147ab1 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1589,6 +1589,7 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) VirtIOBlkConf *conf =3D &s->conf; BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 if (conf->iothread && conf->iothread_vq_mapping_list) { error_setg(errp, @@ -1613,8 +1614,6 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) s->vq_aio_context =3D g_new(AioContext *, conf->num_queues); =20 if (conf->iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); - if (!iothread_vq_mapping_apply(conf->iothread_vq_mapping_list, s->vq_aio_context, conf->num_queues, @@ -1625,13 +1624,15 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) return false; } } else if (conf->iothread) { - AioContext *ctx =3D iothread_get_aio_context(conf->iothread); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, + &io_holder); for (unsigned i =3D 0; i < conf->num_queues; i++) { s->vq_aio_context[i] =3D ctx; } - - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(conf->iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < conf->num_queues; i++) { @@ -1646,18 +1647,20 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s) { VirtIOBlkConf *conf =3D &s->conf; + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { - object_unref(OBJECT(conf->iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + iothread_unref_and_put_aio_context(conf->iothread, &io_holder); } =20 g_free(s->vq_aio_context); diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index ac13f4a1ca..d66946f279 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -28,6 +28,7 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) VirtIODevice *vdev =3D VIRTIO_DEVICE(s); BusState *qbus =3D qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 if (vs->conf.iothread && vs->conf.iothread_vq_mapping_list) { error_setg(errp, @@ -65,8 +66,6 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); - if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], vs->conf.num_queues, path, errp)) { @@ -75,13 +74,15 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) return; } } else if (vs->conf.iothread) { - AioContext *ctx =3D iothread_get_aio_context(vs->conf.iothread); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, + &io_holder); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } - - /* Released in virtio_scsi_dataplane_cleanup() */ - object_ref(OBJECT(vs->conf.iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < vs->conf.num_queues; i++) { @@ -94,16 +95,18 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) { VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { - object_unref(OBJECT(vs->conf.iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + iothread_unref_and_put_aio_context(vs->conf.iothread, &io_holder); } =20 g_free(s->vq_aio_context); --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562099; cv=none; d=zohomail.com; s=zohoarc; b=i/8kkLILP9shQyiobHt6IgRtScGguq6c+43n+WyunZmsr9LzzzP7I7g/MJNM7Z8W2xEYN3XUAM6tKRTrxhDcfsCIapq5epsJzn5tJumPqeow4SGwO+1c6QaHr/FdtUcjA32kThSgXuSKqJLDsOqZ7jUG9xyJNrnjN4rRXvMtQOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562099; h=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=4ILsaE/RbsM3VNE0h9xHp+2rECK8FYcxQRFHjHqHcMg=; b=C5vN/pqP+v62WFE8gPcCcP19bfyA2XxDp5B87O/VljNCOLpMWx4NRV9AsCUJ4dwnWO4CiJI4rRMI7gFfjwPy2MO6A/eGuYzSBnfrBK87vMXjUzZg4UQdyqrEDaD7wFQtWHTxar2BIv+EmDuNKGH+COAYxL/5duFsvLdT90PEYyo= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562099161742.12062289323; Fri, 13 Nov 2026 01:28:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYd-0000f3-RO; Fri, 13 Nov 2026 04:26:55 -0500 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 1xRnYc-0000eY-Gd for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:54 -0500 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYa-00060h-S3 for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:54 -0500 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-3ac78f4c10bso322517a91.1 for ; Fri, 13 Nov 2026 01:26:52 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:26:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794562011; x=1795166811; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=4ILsaE/RbsM3VNE0h9xHp+2rECK8FYcxQRFHjHqHcMg=; b=ifIcZoNXOKEZzJIwse5Wngg1eEIyx7Jt7A8GFt2P0p6RNExdoQf8mh6q8Wh2Dc5iU7 zNN/RjyYIJDMM5Wvag0fjC0sEG3okUkwey8Ti+cQyTWSaqlXxVBjoQhu0gy6DCt092sY FY4P/RHNu7UY57iL2Id4GKem9jMh7uPfdi6Vht1xlg9ZlU1ncBaibhO7JGuFHkVzfCL1 mJvJ6n2N6X7dqSkF1KgVZXp/yCQBlXYnJTkiwnGYdyuIXUvg2rEx4CvKYNEZ7V8dVoeZ 2enyUeakg90a7Mvvb5Yr+6Pz6RHfvMnRGc2QEzKe/VdIOFmumq94b2+von6EraBfVb5t pesw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794562011; x=1795166811; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=4ILsaE/RbsM3VNE0h9xHp+2rECK8FYcxQRFHjHqHcMg=; b=B1He1rvcQk6oCtI4d5/VKWUYiFbXxQ1C+HxTpUGPhaKbAoozlNMumpPjQe/CLG24sq +C0CRW/8WrFosLMzBvLGku0xqZSXnd/ctZicZUGPoYyij5vF+uyA2fh2BKmk+cZiD6nq W6VSAEwgLt+3NqFhXyfoHKW9xktkjdWHjSQJAr6A14G4HlND+sTGIA2SAT4JstLLAcan 16aERt04oidQ88vajxu5X2jqKVa/HiiBpWAubTzCibx/Eo25AEEAqKR2hEmvMSU5BgWe SeGe0nh9BAm260aOZYNIadZJzUynUj06SL5wmWHzMDYr6sZc2JLDa2I7bhOrC4153ZjV 9qVg== X-Gm-Message-State: APuU4Z+t7EH9QqqAVZJkgqRoA81Acaf/eS4Xx3RbN8F/rmV1doDYs90Q 5ugdKiW0/YSYoTDz9CP1FvHE50NqBh0O/CUPQjiaizSkcM4qBA6oaFoqoosVJg== X-Gm-Gg: AYBFou0RUlOFgOTLChJVWMtaMa1udJ7kuFwGNsxLN6mW7RA2cV4qraWZ3DO2aH+4hQX 5Wwdwq08iBYcj4AiHS4DrP3qjnNZUjNLfbFrVlfeTBeir9xGLua22PUWFzaokq/oxzuxaez89u8 3GAZ7CBiTjuan+6sWa4yI0ZqCPrDDSReDfQhn3WVe1fgIy5vdbT5JRJ5tqnQ2cOveVqSbpq1vZd 4jqQ66WkhleUVzdmqTcUrC9n/10PMyWxKbVHc/PnEZMcZEe7wLMNs2vhqQGBiP6QnkjbENiVU9e DF5PS6kLN35fUNpWynFlCZ26DnboLLrPS98rZRqdHATe6vckG+HKHw1kAKkV4r2yHaVDZPEVgeI uyQNwtF1klPtuFOT7Vj8CAo+3l1EFJpHVp60CjKd7Q7JajkqgTANw20Zum7IDBUdP+65zVOi/3v okR6M+5slNoQkX1niNDYM8G0v8plstskACu+u6nXTnHWPTt5ZdXzqZ2nwDIfGbTYVh8hPWSSUo3 NuVoXqD1r93iE8cYkl1wAF34F+A+sw4rJusMxYeCMHWY2eZFXSE7fpdcszlMGv5D1b1XdwChaOp 7i30aocjDGl84Q3W4wXmPfHDpel2Hn5RcDXS14IFlYDfdInf2fd/BhjzjTY= X-Received: by 2002:a17:90b:4b84:b0:3ac:ad90:7090 with SMTP id 98e67ed59e1d1-3b1b0ccf3b1mr1914048a91.67.1794562011356; Fri, 13 Nov 2026 01:26:51 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 07/14] net/colo: track IOThread references using path-based holder Date: Fri, 13 Nov 2026 17:25:58 +0800 Message-ID: <20261113092605.942292-8-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::1031; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1031.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562099458158500 Content-Type: text/plain; charset="utf-8" Convert colo-compare to use the iothread_ref_and_get_aio_context() and iothread_unref_and_put_aio_context() APIs. This ensures that IOThread references are tracked using the COLO object's canonical QOM path as the holder ID. This refactoring improves IOThread lifecycle traceability and aligns the code with modern QEMU iothread reference management patterns. Signed-off-by: Zhang Chen Reviewed-by: Stefan Hajnoczi --- net/colo-compare.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 9b04b28484..c462284b99 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -131,6 +131,8 @@ struct CompareState { GHashTable *connection_track_table; =20 IOThread *iothread; + char *qom_path; + AioContext *iothread_ctx; GMainContext *worker_context; QEMUTimer *packet_check_timer; =20 @@ -923,9 +925,7 @@ void colo_notify_compares_event(void *opaque, int event= , Error **errp) =20 static void colo_compare_timer_init(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - - s->packet_check_timer =3D aio_timer_new(ctx, QEMU_CLOCK_HOST, + s->packet_check_timer =3D aio_timer_new(s->iothread_ctx, QEMU_CLOCK_HO= ST, SCALE_MS, check_old_packet_regular, s); timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) + @@ -965,8 +965,15 @@ static void colo_compare_handle_event(void *opaque) =20 static void colo_compare_iothread(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - object_ref(OBJECT(s->iothread)); + s->qom_path =3D object_get_canonical_path(OBJECT(s)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D s->qom_path, + }; + + s->iothread_ctx =3D iothread_ref_and_get_aio_context(s->iothread, + &io_holder); + s->worker_context =3D iothread_get_g_main_context(s->iothread); =20 qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read, @@ -982,7 +989,8 @@ static void colo_compare_iothread(CompareState *s) } =20 colo_compare_timer_init(s); - s->event_bh =3D aio_bh_new(ctx, colo_compare_handle_event, s); + s->event_bh =3D aio_bh_new(s->iothread_ctx, + colo_compare_handle_event, s); } =20 static char *compare_get_pri_indev(Object *obj, Error **errp) @@ -1430,20 +1438,24 @@ static void colo_compare_finalize(Object *obj) colo_compare_timer_del(s); g_clear_pointer(&s->event_bh, qemu_bh_delete); =20 - if (s->iothread) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - - AIO_WAIT_WHILE(ctx, !s->out_sendco.done); + /* Only wait and release the holder if initialization acquired it. */ + if (s->iothread_ctx) { + AIO_WAIT_WHILE(s->iothread_ctx, !s->out_sendco.done); if (s->notify_dev) { - AIO_WAIT_WHILE(ctx, !s->notify_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->notify_sendco.done); } =20 /* Release all unhandled packets after compare thread exited */ g_queue_foreach(&s->conn_list, colo_flush_packets, s); AIO_WAIT_WHILE(NULL, !s->out_sendco.done); =20 - object_unref(OBJECT(s->iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D s->qom_path, + }; + iothread_unref_and_put_aio_context(s->iothread, &io_holder); } + g_free(s->qom_path); =20 g_queue_clear(&s->conn_list); g_queue_clear(&s->out_sendco.send_list); --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562067; cv=none; d=zohomail.com; s=zohoarc; b=KHE4rLE8aULyt/TvkIZP6eTrp8gwaaJgPfmX4Sx7T7BAJk48KOSVjTabGS6vaWJnmuCiOJDEpvYTi0r2f38nbFAFEjVP11SOxMSXN3tddqtFra/nG11a38HjUc4YTeP40D4s8f6022DVo8p5DL7hS69WmLBUlk9wBuonx2iNph4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562067; h=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=pFOYRSr2lEA/XDAlOEnhBcCXZDLbuRVgFw78rMsTQ/o=; b=Sm3HIsDP9lVJRW/7t86iVrpGAQWACtMxPJVRZTBRykL1ktJhJndq5SX1eofsY7f++47wMETMnc4mKy/A6GjKFqRDTyIgd9eqEi7TUSv7AFwCS+ELAsa4lAnzIVJPQGCRjHJJOkQDF8s9d1PiN3LAKm/DRQV1Na4VPEPiaB30zFs= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179456206771672.71067645702351; Fri, 13 Nov 2026 01:27:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYi-0000fp-IP; Fri, 13 Nov 2026 04:27:00 -0500 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 1xRnYg-0000fZ-PW for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:58 -0500 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYf-00060v-8R for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:26:58 -0500 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2ede7cb02daso12975095ad.1 for ; Fri, 13 Nov 2026 01:26:56 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:26:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794562016; x=1795166816; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pFOYRSr2lEA/XDAlOEnhBcCXZDLbuRVgFw78rMsTQ/o=; b=kHbwOf+f60k4OWSPrHxlhpVfpEw8FEz7qIK0pWglUAB7tB26MRK2jZ5Wj1olkxl27O tJPHdI+1Rehb9HHJZC0Nkj7SOFHr0bZbfZXHuPzvDld/2s8dYApOioXFZd0+gk7nbQ/J 849xBIja6n3A51PeSRcr9dMMY1xpd/pCx4EpvGkaIFLt9dF7CjJb7/d7Q8rQ7cpP0t80 dw7PHngp7GoaDGJVgSziGEsmnGJiLsc8E7lTmDyCbJiLvWB0M8Q9vDx1S99E13913sKx 5ePtZ2+nDRJQzIWISdJjhOfQEDpTakrNmcefSPWewNcJtqs5gYy1EgESGVzcymOeWhx2 7M/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794562016; x=1795166816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=pFOYRSr2lEA/XDAlOEnhBcCXZDLbuRVgFw78rMsTQ/o=; b=b1oM7RJ0dS4NuwKlEl/x8RHBK1joXn0Yl6h2zJ3BIpLBR03FNx5neUDFi1FQkhSPbj E/NqswClZL5tQkuORCu/DlVzf6Yvytb8RCdEEgVUSgLWghZ5tTo/Mx7m4DkYR5NFCa6v ewz0KqcKE0d6SylEIBSr8pUaxN6Q7OEd+3haObYuJW7FkwcUCeOehcVjbnsKUmSjfTxM aft3ROsT0DffrklP0hrSXedCPJdSKKGH9iVs/F/UcxneIUA6rlfLBSKO8HStxf2oIct6 arTnCqiNY1ECGPZlmG6tKWXylRA0Y3vbVzNHajM0ZyRgT2ayFojdC/vYsn1x7aniEoFW bx+A== X-Gm-Message-State: APuU4Z89YVarGKyRMvVrDki9I57n/u7RYbW7ZWPzvjM/vXl9Whr1sNwF qrwu8vUG/7jR0Zi8xWpMi1gweDFMTGAfIJSRpg2t97+CUaKT96U9noan/XtgEIfN X-Gm-Gg: AYBFou29uGDIx4mvFf1XNHeGw7Dyd9JTKDDhYJF10mXPwxt0bJ6vTryzxHXclxoFltB ZaWodvtP+ZHZu+tC3uk6dIXEFcK5NEM8fq5nIe5h13VqKZ2NEg27qoRegsycUz4QF8uyfWibhfX x+2hlEeWrH2iupLNV3o+xBm0MAsd7ZPWrDRde+6ah4Y2Jtim04Kic661BX31UDsVViCh9BKmFvK wj/O7Zg6LjmPgfFCwXO53ZU8Mkj6UwqI/ALiyYrqT+AQhvJW+DEFl6WadsK+1GijN9bkP7hWmSr NRRHrSIZ8tSly/O5DClmJKPLULgNIzrza58Q1ef67OcM80XsURjG4xUGaXPOh2MbH9rXPgHGX84 KVDWD9nS4W2c2lh8wPuoOWN1OIG3nwHRiY20PhXtF7RKZ8+NbpxXnq2QeZMLBpN5CYutIkJ5RQ3 P3/eYmvc5W+gk7UCHf3udqHSIopyFO61PEyQRpjQ5q1kKA+hgAaU4cI65NjFPaHB6/z6ry6qVxy drDc9Jser45JnWcjH27CIqFQnBYIoAXvDurPtk0dCEo0a91GMYhJSeiDGgSnH68l1JC70FKwCIo gbttFuX+Ot7yxhYi01d2CFt9yQKjx05CDbNA/GSiCRoFgKTC5kvvoXYXG20= X-Received: by 2002:a17:903:1a28:b0:2df:5c13:b37c with SMTP id d9443c01a7336-2edf20f20b7mr38290825ad.26.1794562015710; Fri, 13 Nov 2026 01:26:55 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 08/14] virtio-balloon: Update tracking iothread users with holder Date: Fri, 13 Nov 2026 17:25:59 +0800 Message-ID: <20261113092605.942292-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::632; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x632.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562069233158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_ref_and_get/unref_and_put_aio_context. Signed-off-by: Zhang Chen Reviewed-by: Stefan Hajnoczi --- hw/virtio/virtio-balloon.c | 21 ++++++++++++++++----- include/hw/virtio/virtio-balloon.h | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 547173e035..ef694a17b2 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -871,12 +871,19 @@ static void virtio_balloon_device_realize(DeviceState= *dev, Error **errp) s->svq =3D virtio_add_queue(vdev, 128, virtio_balloon_receive_stats); =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_FREE_PAGE_HI= NT)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + s->free_page_vq =3D virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, virtio_balloon_handle_free_page= _vq); precopy_add_notifier(&s->free_page_hint_notify); =20 - object_ref(OBJECT(s->iothread)); - s->free_page_bh =3D aio_bh_new_guarded(iothread_get_aio_context(s-= >iothread), + s->free_page_ctx =3D iothread_ref_and_get_aio_context(s->iothread, + &io_holder); + s->free_page_bh =3D aio_bh_new_guarded(s->free_page_ctx, virtio_ballloon_get_free_page= _hints, s, &dev->mem_reentrancy_guard); } @@ -903,7 +910,11 @@ static void virtio_balloon_device_unrealize(DeviceStat= e *dev) =20 qemu_unregister_resettable(OBJECT(dev)); if (s->free_page_bh) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; =20 qemu_bh_delete(s->free_page_bh); =20 @@ -911,9 +922,9 @@ static void virtio_balloon_device_unrealize(DeviceState= *dev) s->free_page_hint_status =3D FREE_PAGE_HINT_S_UNREALIZE; qemu_cond_signal(&s->free_page_cond); qemu_mutex_unlock(&s->free_page_lock); - aio_wait_bh_oneshot(ctx, dummy_bh, NULL); + aio_wait_bh_oneshot(s->free_page_ctx, dummy_bh, NULL); =20 - object_unref(OBJECT(s->iothread)); + iothread_unref_and_put_aio_context(s->iothread, &io_holder); precopy_remove_notifier(&s->free_page_hint_notify); } balloon_stats_destroy_timer(s); diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-= balloon.h index 53bbaa4c9a..5c3731b3e9 100644 --- a/include/hw/virtio/virtio-balloon.h +++ b/include/hw/virtio/virtio-balloon.h @@ -54,6 +54,7 @@ struct VirtIOBalloon { size_t stats_vq_offset; QEMUTimer *stats_timer; IOThread *iothread; + AioContext *free_page_ctx; QEMUBH *free_page_bh; /* * Lock to synchronize threads to access the free page reporting relat= ed --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562080; cv=none; d=zohomail.com; s=zohoarc; b=e2rLe4vEP1Go7zHQVGf+5b3MhTP+i6V+69xSfMG6Djmc/nCJauaEDj7geQ9LpkwliGDHCymAPdf+AXgwb78C9dkjQFPMnIlsA44JMn+vV1/BX8ZyAzNk9CkXmr4E5ZFfbHEYQxzmKXRbNIR5xH+MLLApiW7Wk/jXYbQfgUMP4bw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562080; h=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=pxyUXo7Ru3xt0fI3PgpJjhvzJDljlv7M0kkgJXI2bac=; b=b7qBrGOn69EbWeBvSVKxvgyRUgWXwAqzEeS+3pKZ7JjxDdb23MlAR1R4JpzzU3Q6PAgkmmcnQfPY86uD6WLJAA1XnFXZlLlNjps16Q5yq7aBD7qrepR8x1qcr3+4z1vTxKhQRPol+5dLCCii6CJiNlp6pfhfxv5D/0YlI5IU/co= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562080348536.9743290205053; Fri, 13 Nov 2026 01:28:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYl-0000gQ-JJ; Fri, 13 Nov 2026 04:27:03 -0500 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 1xRnYk-0000g8-Dy for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:27:02 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYi-00061D-DD for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:27:02 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2e9eb579c0eso4084745ad.3 for ; Fri, 13 Nov 2026 01:26:59 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:26:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794562019; x=1795166819; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pxyUXo7Ru3xt0fI3PgpJjhvzJDljlv7M0kkgJXI2bac=; b=r+BI5oxoOjSWXzr1nEVDSS8HIk/Pl3YHsZuTd2uJloPMYzI5TAkNgKcn58XImAk0rZ UwZ3QN4GFUXwijwIsx2JY/HWFG4agt1CTzEBNvDQU5xOft2FdK1pwZFlw9JwjcPSd+kM dzyaT9dMJbtt8qggX+seMhD0g1LU+Y6kdDdWKikoLW/Mp6AimMcKd3P7ao/fo+rZtMXv dHK5A140b1Tbe9XKC8b1rjAz9KiyKAd4FyaWjoTjt1FjzRzg3VR2hgg0ncdi1BFVHAGX CuJXII/jywerSSbP+SKkKch6Ny7iZM8TN0fswFLv/lN2FigmTAmhd+EBHUrNBp0UGNXU u7Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794562019; x=1795166819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=pxyUXo7Ru3xt0fI3PgpJjhvzJDljlv7M0kkgJXI2bac=; b=hXwLtuwdQIVbxBxU4TOe4KtA+k/Eb+n1k+s+Wr+7HWR0sFMORuueMQzLUnJYH/nzuz 6AwPSkie49zeHQmblTJdNg77ti3krPu6rowVlwcOaaaoQq1rTYekBKtBJB5lfAHPg2Na lJqKm5DE0KuaT177bc0BdL30e8ipbz+0lFI9Gtf4RYORLG6x+7I2TkGmx5UD3O0/PqHX nJtHMmI3uVP8gY05MzhjsQ9CqcOultfffFLxga0J3Lc2R7NuCNQBIGnMERvyid21orbu /SrJHmlIeURdwu9vQdNj5uidMDAY9Fmjyb1UdcEzZjrpw5fnW5u+hxXMnaQFCPBLbc2T saCQ== X-Gm-Message-State: APuU4Z94steVuH5dVuEvN0AB4DOTT6nJwzANHgEPIXZxlUAa+b//Mlik fjNeHIB3XsnA5FQHEkPrwZ6gBbygniVf7UzqvHdZF0EBPqmVuKmDSts7K4bHpaK5 X-Gm-Gg: AYBFou2oZ8zwSPXI40GNB72tg4RSlcmvRLRmkXz/5igZX9Xqh3puc6fjQg6YUs00yTK AnvS8md67czC/IpUD8ZGDRzOWN1up5CFG8kXfVGgNx2jpDHIfAqgiTUeBzy/A5J1pfFze8zgA6/ O/kifQkVXqqydq7tkxKdiFpTuOdU5JYw2FEmrwrpBJtdk2ItNezoSYYIiLVhzJcCN+16R6sF7cD iY5wUR6MBhSrMAzG1YJyP+9DIsR+wy7wZiCl9s0gqRzCWpBXUP202mHZiz+ZeaHaeSiIHKobRkf hdHoAeZ6Yz/aRCYffKjCzuZfDHCelWPuleZOqgLAuZrUP374WiUdy/z+vH4+mnqlDBybE9lasFR qhCD5dTIIAn0JLGTLvg077Ro59WFH56BGX9Q6bF84cT9aIVfNqEHwKYdKU0wgk/0zyo17q7YeHM yFadN3DjsLoKEWL9nwQOcwLiHdPQID6VpTPhV4XciWkD7HNO43AEHBY4Ky6or4OMhFs8T6ncSX8 aOb38dgmLuU2rtwHYiIXBteTwPFmAFBheYQZ+McADc/DViU3KO+4D7aAhydC5W6YBYrHeQdXwbh WKWDgbxYpVW4XrnQ8X7aJwba2SHytyJrBBGUem7hyRw9M/GUEwX/y5wPEEw= X-Received: by 2002:a17:902:ef0b:b0:2ed:1e82:ab81 with SMTP id d9443c01a7336-2ee0dc97d44mr18202275ad.57.1794562018922; Fri, 13 Nov 2026 01:26:58 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 09/14] vfio-user/proxy: Update tracking iothread users with device QOM paths Date: Fri, 13 Nov 2026 17:26:00 +0800 Message-ID: <20261113092605.942292-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::62e; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62e.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562081336158500 Content-Type: text/plain; charset="utf-8" Use the holder-aware AioContext APIs to track each proxy's reference to the shared IOThread, using the owning PCI device's canonical QOM path as the holder identity. Because the IOChannel has no QOM parent and therefore cannot provide a canonical path. Signed-off-by: Zhang Chen Reviewed-by: Stefan Hajnoczi --- hw/vfio-user/pci.c | 2 +- hw/vfio-user/proxy.c | 20 ++++++++++++++++++-- hw/vfio-user/proxy.h | 4 +++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c index c749ff149f..d0760defdd 100644 --- a/hw/vfio-user/pci.c +++ b/hw/vfio-user/pci.c @@ -279,7 +279,7 @@ static void vfio_user_pci_realize(PCIDevice *pdev, Erro= r **errp) memset(&addr, 0, sizeof(addr)); addr.type =3D SOCKET_ADDRESS_TYPE_UNIX; addr.u.q_unix.path =3D (char *)sock_name; - proxy =3D vfio_user_connect_dev(&addr, errp); + proxy =3D vfio_user_connect_dev(&addr, OBJECT(pdev), errp); if (!proxy) { return; } diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index ba29085321..c104a3a6b3 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -917,7 +917,8 @@ vfio_user_disable_posted_writes(VFIOUserProxy *proxy) static QLIST_HEAD(, VFIOUserProxy) vfio_user_sockets =3D QLIST_HEAD_INITIALIZER(vfio_user_sockets); =20 -VFIOUserProxy *vfio_user_connect_dev(SocketAddress *addr, Error **errp) +VFIOUserProxy *vfio_user_connect_dev(SocketAddress *addr, Object *owner, + Error **errp) { VFIOUserProxy *proxy; QIOChannelSocket *sioc; @@ -942,6 +943,13 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *ad= dr, Error **errp) proxy =3D g_malloc0(sizeof(VFIOUserProxy)); proxy->sockname =3D g_strdup_printf("unix:%s", sockname); proxy->ioc =3D ioc; + /* The device may be unparented before disconnect releases the holder.= */ + proxy->qom_path =3D object_get_canonical_path(owner); + assert(proxy->qom_path); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D proxy->qom_path, + }; =20 /* init defaults */ proxy->max_xfer_size =3D VFIO_USER_DEF_MAX_XFER; @@ -961,7 +969,8 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) vfio_user_iothread =3D iothread_create("vfio-user", errp); } =20 - proxy->ctx =3D iothread_get_aio_context(vfio_user_iothread); + proxy->ctx =3D iothread_ref_and_get_aio_context(vfio_user_iothread, + &io_holder); proxy->req_bh =3D qemu_bh_new(vfio_user_request, proxy); =20 QTAILQ_INIT(&proxy->outgoing); @@ -993,6 +1002,10 @@ void vfio_user_disconnect(VFIOUserProxy *proxy) { VFIOUserMsg *r1, *r2; int i; + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D proxy->qom_path, + }; =20 qemu_mutex_lock(&proxy->lock); =20 @@ -1047,6 +1060,8 @@ void vfio_user_disconnect(VFIOUserProxy *proxy) qemu_cond_destroy(&proxy->close_cv); qemu_mutex_destroy(&proxy->lock); =20 + iothread_unref_and_put_aio_context(vfio_user_iothread, &io_holder); + QLIST_REMOVE(proxy, next); if (QLIST_EMPTY(&vfio_user_sockets)) { iothread_destroy(vfio_user_iothread); @@ -1057,6 +1072,7 @@ void vfio_user_disconnect(VFIOUserProxy *proxy) vfio_user_free_fds(proxy->region_fds[i]); } =20 + g_free(proxy->qom_path); g_free(proxy->sockname); g_free(proxy); } diff --git a/hw/vfio-user/proxy.h b/hw/vfio-user/proxy.h index 4b9834a436..5eade2f7f1 100644 --- a/hw/vfio-user/proxy.h +++ b/hw/vfio-user/proxy.h @@ -70,6 +70,7 @@ typedef struct VFIOUserProxy { uint32_t wait_time; QemuCond close_cv; AioContext *ctx; + char *qom_path; QEMUBH *req_bh; bool async_ops; VFIOUserFDs *region_fds[VFIO_USER_MAX_REGIONS]; @@ -103,7 +104,8 @@ typedef struct VFIOUserProxy { =20 typedef struct VFIODevice VFIODevice; =20 -VFIOUserProxy *vfio_user_connect_dev(SocketAddress *addr, Error **errp); +VFIOUserProxy *vfio_user_connect_dev(SocketAddress *addr, Object *owner, + Error **errp); void vfio_user_disconnect(VFIOUserProxy *proxy); void vfio_user_set_handler(VFIODevice *vbasedev, void (*handler)(void *opaque, VFIOUserMsg *msg), --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562101; cv=none; d=zohomail.com; s=zohoarc; b=DfjMfiVQ1lydjBMPaIdadrEQTERdAJFsLiMJSm0oBzDxJ88STS48CevYg9bfvXHsppcAIbcmaWqCQNwlbV4MuMrWeqr7eeOH//SJV0jK4/cBHghFLSx+08UWvrRayFO/BQPD7c5C8DbF8rmzklkML3jiYn66j2KpyrDD+YjYMcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562101; h=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=A+ZI9HPiEEreD00eCRzRf4GSQf4yCHaMnrIQJkGq+YM=; b=hUCqltJ4o4RV4m6mD5IL52jqSo0RGdQo/so/o7KLJZzD3xHdagErcEklQntiN/cjBDZI6brpvjrPHaH+TuyfGeCnspB6MlMZYUX+FtvWDjrXGquEJsB5JLAOYVJrQjdGMHeZBAw/PERywIktFolDCKXcwFBOwBqb4elhJeH/kt0= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562101518290.7537128197415; Fri, 13 Nov 2026 01:28:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYr-0000hE-1I; Fri, 13 Nov 2026 04:27:09 -0500 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 1xRnYp-0000gi-6I for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:27:07 -0500 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYn-00061V-NL for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:27:06 -0500 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2ed0e2015aaso4226655ad.3 for ; Fri, 13 Nov 2026 01:27:04 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:27:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794562023; x=1795166823; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=A+ZI9HPiEEreD00eCRzRf4GSQf4yCHaMnrIQJkGq+YM=; b=NHh1+IuSi4RNXz1DP22aZGhEG59+BzedS2hWyco5SI7HctMohdEZPDKqX9FTqU56xQ z8g2GJoavmHENuZY3cT9GzgOsxIS/ULoPrKzMGugcU+JLMfKgqgry3mKd3ZdERFCN/+i tKtfwvGQgaNkgy20pbDPZTSbLkwN/CRxdowMO+rS+JHaofULQgS6rrcuncXqYflUXzwC /XvW4eb5ab8qbwwN6vjja3sbXE05RNJ4D5j6VoXjB7JjH0slY8TLUIljlXjIyut+5m6k 1sVVe9XJZzDYZs7Ip3Zg65bXjF25D+KKLnX59WDMe4bGpgHCLkUbY5BOk2kRQJwpi4br 4c3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794562023; x=1795166823; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=A+ZI9HPiEEreD00eCRzRf4GSQf4yCHaMnrIQJkGq+YM=; b=IZkII/SkbcYJdh54AovxBDQSpFrDRWemxz2RCyTwiz3wXqm7PaI22UWwed9bpX8Z2+ 2AncT18N9RFRs7xVEGV1LtH28YRD4nhlxaUU50K8FhTVniIYjb+EvmRn4gRMe5AT3KVs PuYdqcwiK3XFMytC1okp2lIf5Ciomi2RTxLmN6QCCxtEzGk2nYuUaq5MlnDF4IhTSN7r jXux8zC8PI9JPYkChj7rSL01yxOab7V6ntz7vT+bigd/IBBA2bXmx8cQd9wpwlerrqrQ eirsYLFpPFMJlCLOlfvCyRMUTkGKSnC05DZeZ8VflO/Hiq0uI/os99WfRUY+ptiOe/6M KokQ== X-Gm-Message-State: APuU4Z/zkWfVZ+kxkE9i4CamwiAFMlmFByJEo9PqFNa+cL/9wGV3uIrS gK6C6En/lZXafUIKz4obBxuB9jzGH6unfaafAA3glSBiucPDTD8fTP5wct7FPvz2 X-Gm-Gg: AYBFou1355s6KVeSU80CqTdoZgSPZfovj/Klt6WNw7zAbT+fHlCbb//W5UiqrH+UmLe mFTTLh7iJfIZxHlsXHXflNxIM6w5Y1whrfmXC/yq+m9GbviilVNZVVEZfN0T0mWNzYtmw5pcd/a Ruj756w1QdUpb9dwas64s3up2a/1wY+iOVbTMLRRA2MGyJnNMgT9QSSPavp+yjtdrw4vwJYtm0m CPoggde7muk0dS97KT9r8iuTxdBPZ1K1t1vlcUo9oRDFmiUgjOM6zQHqs0d8GbVux+jnkf2T/ce bMKzfJrmUqeTuYUwG59ZsXgyfRaFAImNPEfCrbAELjbqvju6JivI0TiJkIK/yQx3Q0nbOSMlVW7 Y2isS7Blus4M55zgb+VQqu5M/jCezfjZlHVZHWgz0UL7Ywe++TIhOmhRPUbEAnDZv2ybFxVZyqp YX71+OO3nyLEBg3d2GwhcMTXdWUMcfwlZlBQPVLBhzXRkfMaMfP+GWurWnE4/Zlhj57SXE0vdGa v1w0wrovRPMSDIPA6/yDn26rWGnJXhZKAJh/0Md1AcjYcZNcdlgEl8+Bzgr3UDh3yE2kr7RsDCE XzOv82WNS1UVMBA1ayO1o7s8WppbpxijTazieGcr7P9jXRDbcqhx+MPsJI31Ay6TbhoVJcXOc/B zibMb8Q== X-Received: by 2002:a17:902:db0a:b0:2e3:1ed7:d5d3 with SMTP id d9443c01a7336-2ee0dde7066mr19645925ad.67.1794562023290; Fri, 13 Nov 2026 01:27:03 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 10/14] xen-block: Update tracking iothread users with holder name Date: Fri, 13 Nov 2026 17:26:01 +0800 Message-ID: <20261113092605.942292-11-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::632; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x632.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562103443158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_ref_and_get/unref_and_put_aio_context. Signed-off-by: Zhang Chen Reviewed-by: Stefan Hajnoczi --- hw/block/dataplane/xen-block.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 48c2e315f3..9dfe06e1be 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -621,9 +621,15 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevic= e *xendev, QLIST_INIT(&dataplane->freelist); =20 if (iothread) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(xendev)= ); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + dataplane->iothread =3D iothread; - object_ref(OBJECT(dataplane->iothread)); - dataplane->ctx =3D iothread_get_aio_context(dataplane->iothread); + dataplane->ctx =3D iothread_ref_and_get_aio_context(dataplane->iot= hread, + &io_holder); } else { dataplane->ctx =3D qemu_get_aio_context(); } @@ -652,7 +658,14 @@ void xen_block_dataplane_destroy(XenBlockDataPlane *da= taplane) =20 qemu_bh_delete(dataplane->bh); if (dataplane->iothread) { - object_unref(OBJECT(dataplane->iothread)); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(dataplane->xendev)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + + iothread_unref_and_put_aio_context(dataplane->iothread, &io_holder= ); } =20 g_free(dataplane); --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562082; cv=none; d=zohomail.com; s=zohoarc; b=fL35uaYfwT9JPvaN+1ibxYe+Sm7rYwsSpMUuHc1KJwjNlOzdYPUWYNe+LOxaeazFRuk7K9kt2EzU0THV4Nmwp/yFjM8+Y3rDmdzNluQ/7oWU+NiV8occeP2HhC9AM5JlUmsI1OYjg0YXxwG9reJE9Q1L+X0dOOnu2NcG8ZfI9Ho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562082; h=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=dL/Q6T4ShqA/qNYT5CLVTesugf9vIPbAH1J8Fz30V0c=; b=ba+1cDBS0ySwfBdxtTC6+bxO/uW8jUHL9szE+huV4oawcL74ZzDrtjhSqOHfp1LnlZyCIuQtTi80A9TAISVrSR3vzV6lkT/YReZWjZIXxbV4VPtmlK12exsl4X8URuPHy62ACAGbhLfY1R5OB58UiTwl7Q+6EQLZYizXM2vizNM= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562082000560.7821257203428; Fri, 13 Nov 2026 01:28:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYt-0000lL-A3; Fri, 13 Nov 2026 04:27:11 -0500 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 1xRnYr-0000k3-Sf for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:27:10 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYq-00061t-BR for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:27:09 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2ed2b4348fcso2408695ad.2 for ; Fri, 13 Nov 2026 01:27:07 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.27.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:27:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794562027; x=1795166827; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dL/Q6T4ShqA/qNYT5CLVTesugf9vIPbAH1J8Fz30V0c=; b=cFnTpDW6XI9BqkRWyTBluORyS78nbgqmLc8Gg6sh63IQz96mc/Utb2BNHn15BCxCx8 sTgNT6tgss2EijmdEMLDRQ76XyxtlkbBIC6r+n7eDKdPHjqHJxp0ApeMrLu9CwGI13yp CzFoIpaNgVtdtshRemKn+G6prZpZHGuMP+3ard3Z9jV2Pubc3T5+Yppt/N1NwFcLtWH6 zY+sgccDUOFijDd5Rud/PAL5QIdCIeb6z8mn4Z3eQFWZq7np6Z5xvTJTym9H89Z3/7XO t3uQ8rvcl4IfH2BqO7M+Oh5tsowpUv8QK9HZKyE/L+y+CQzwsI5ZiTgKLdctMti+DI0t Q6uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794562027; x=1795166827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=dL/Q6T4ShqA/qNYT5CLVTesugf9vIPbAH1J8Fz30V0c=; b=zYcrTBlypjx6jHGzibY1xaMLO4Z3nVBUksu4FlDPUfgAsp+sGHXbLWQKks2nIfRc43 4S86WdN4d/25HL+FIdC3HRg6iDuccRdOhI0onvbDguq0+78M6DxW5bRiJU87lmYI4aXk sL3fANWKk8jRkySB8P2smC9hNVrE4DsMqXxQkf+3DXh0Q14dOUzSg/FCHtlBA5B0n/oy d8psPMMzhIe8L0XBzBKL0ZodgXa+/e/LUiSYH8NojkDjU4IOi/Vpf/Iq7WVZOguzdpnu 1ijX4iDI5eJCS3B7rGDFW/69JQssSeB8o3UtaC2mG/xzLtQlUvnqP4bEkWA/+1HlF6iB 7fow== X-Gm-Message-State: APuU4Z/ftP4ScR+ZfrDL53tQPKRSIoo9UNDljeUZDRfFeCl4VgMz9p62 PjM17mNvOhsBaeWs+s12feh+Z2KrekbtL80Ksx1RYAcCGaBHRwYgeSj90N719twv X-Gm-Gg: AYBFou2on/iGvodwG3uuIeMNVHKwMeBIvtaSJPBjpEP4XdKMMHhFzMbZ8laanKyzGlH MeZF8AJ/YEntRpjQmj3CboC/mv6QFScVbesoc3ZcYedjSJKp+KCwMxk09sUxSoS6zRu15udyECJ Tq3eYwZsCLjr5zmrRw2VyWQ2RFrYTS8Y1f6SiL7D98N4sgP0NQpmXYcPkXc8pxhqFDg45mAmKqg Bgc7x7sG4hFk78rzwxjLIyb/sazkaIF6nxUbeYb/xAtwtFBkMPqQLLixfxonMPctfQnE1vSMjrX /7wLMTnu4oWFzWmCrfdjpq89WacJnwxmBONx1Cl3sJuOpi/GVaAcsA1wV6wazKRMy+cXPP/B2oo 6LXwr2oEHfelO/ZuO1OBGf8IGu3is4zct3or6NcKFMf6KpvaFsb08eXWSG9BsboTLzrHegdbzWd nbnNbLZlMaj7YnhJnmCIsK1eazS38LPY4PB1wwAA9KdZGDKfjPyTRbjG5ZpARIE3OU/YFrX9idm sspLZh1NzP5IQcINLEn5cz6gD8o4Gw23zKTM89I4XvYmvLwrWhJJCFFiljaFR0joryBWNIHfUFt VV79GkV4bQ2LS08Hr6AM75mcmihA1ZXCPMiC9Vpax4qGevE75c6aFSehgDU= X-Received: by 2002:a17:902:e542:b0:2e9:2a0e:aaaf with SMTP id d9443c01a7336-2ee0dccfa87mr20219185ad.57.1794562027060; Fri, 13 Nov 2026 01:27:07 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 11/14] monitor/hmp: display IOThread holders Date: Fri, 13 Nov 2026 17:26:02 +0800 Message-ID: <20261113092605.942292-12-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::631; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x631.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562083305158500 Content-Type: text/plain; charset="utf-8" Display holder information in info iothreads to aid manual debugging. Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen --- monitor/hmp-cmds.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 9b1b94f8ea..7f1b6c35fb 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -247,11 +247,31 @@ void hmp_info_iothreads(MonitorHMP *hmp, const QDict = *qdict) IOThreadInfoList *info_list =3D qmp_query_iothreads(NULL); IOThreadInfoList *info; IOThreadInfo *value; + IOThreadHolderList *h; =20 for (info =3D info_list; info; info =3D info->next) { value =3D info->value; monitor_hmp_printf(hmp, "%s:\n", value->id); monitor_hmp_printf(hmp, " thread_id=3D%" PRId64 "\n", value->thre= ad_id); + monitor_hmp_printf(hmp, " holders=3D"); + for (h =3D value->holders; h; h =3D h->next) { + IOThreadHolder *holder =3D h->value; + + switch (holder->type) { + case IO_THREAD_HOLDER_KIND_BLOCK_EXPORT: + monitor_hmp_printf(hmp, "[block-export: %s]", + holder->u.block_export.export_id); + break; + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + monitor_hmp_printf(hmp, "[qom-path: %s]", + holder->u.qom_object.qom_path); + break; + default: + g_assert_not_reached(); + } + } + monitor_hmp_printf(hmp, "\n"); + monitor_hmp_printf(hmp, " poll-max-ns=3D%" PRId64 "\n", value->po= ll_max_ns); monitor_hmp_printf(hmp, " poll-grow=3D%" PRId64 "\n", value->poll= _grow); monitor_hmp_printf(hmp, " poll-shrink=3D%" PRId64 "\n", value->po= ll_shrink); --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562114; cv=none; d=zohomail.com; s=zohoarc; b=D6hT96hC6IdgI+gW4XAslLg64hmEBy/6LfVq8dw/8uVQctRxi0mK419ARcgyYsb4F88fkLNuIUlzuj10ekDzdAxaDT8Wt3ygqY9ku1iEyPAqoZ0tRGReAGavgMM/y1K+JlAX35MIa+jMC0i/SK9yvazqy53uEcdVKxLDskqmJqY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562114; h=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=DXHsNxPWfAhBshyZgLvXP5fCtDHZuiJhPfU8c6CLgmY=; b=dMLg/PzIGhx2UNehf5XHR4EMc0lX26VrURGfRQTebBMeflw0HHGOj2HjOVdZMNxnpIn1l3yrLmkDCDyCBQCXflOfu05ueZSqD8dVYfXv7Bg5G5VWcM64nFTpokJKiq+we+y/gCVEzf6HI5vKXeHt3pH4QD3x0pniwbpQNGjnn7g= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562114164659.6552063396567; Fri, 13 Nov 2026 01:28:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnYy-00010g-HT; Fri, 13 Nov 2026 04:27:16 -0500 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 1xRnYw-0000v2-1m for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:27:14 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYu-00062I-Bj for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:27:13 -0500 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2e98798cbddso5948775ad.0 for ; Fri, 13 Nov 2026 01:27:11 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.27.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:27:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794562031; x=1795166831; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DXHsNxPWfAhBshyZgLvXP5fCtDHZuiJhPfU8c6CLgmY=; b=R/wpPAjL0DqDer4OznLj8+90u+fcCJgNNG4FWSafVfWoJVMBWC6g1ie8a6pPtnNxLn r2vluT5YyZtdwJA1POTaYWelGd02g/hctcuMd1Osghs+0ckyfL2zwO5mmIIvP34OKyKw aTT//O21nd8kM2RVGttNWF1yL6RDDpz0yhSmb5oIbBYGkcieW+0Eas7lHc04Shu2P204 j299PdggKqZFSP5lALszadXG61WGZJ1tSB4pKGCtZU9XIEkbV4xPao7Vhl0wmVnJ7Y6u rLQ+B00VCKZ2PIQgP+0MLXF22OC6ReEHLncgEAbsD737dbawZPOZvtXTdwU7vFJJnkQA BYSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794562031; x=1795166831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=DXHsNxPWfAhBshyZgLvXP5fCtDHZuiJhPfU8c6CLgmY=; b=pD3je9HXkfl199Yr2cmnISDRKDQ1mxnoj2tBSqux5UW7BEQY15CDxUqg/8hCDwegRx Faj9a36isonZTICtXpVT25bzTsVOP0YhmMhrByBhH3vBFCOMU/nTT5hC9MElYua9C1XD +ZGYKNjuWPiSA5CxB32VQCHTBZDTN98AoXK5RdV5AA++SS0b1zU+gw5UEbZ8nDvLhXLt zV19na/UZ7AzBmDCBV6dlHLAz3eVf27DRgZ3Un1J8eQX8bZfz/bQKDIDP526e65YONit T5Vn5d14pzUXF7PxYzxp6U7zIrIHVu2ElzX+sGs9D1BKN+0i8g4sBxaxxyLRNynDz2Pt JHAg== X-Gm-Message-State: APuU4Z9jacz38pvTUPrx3Mi+dUbKSZUln3ebzs9q1nc0tOpGfe5M9ed1 v5a58XETD4I5Hn3IXWGL28evRQkcdNw3dHCDWeyV0WllvwKBlmT5YDgjjk9T/iGA X-Gm-Gg: AYBFou1rqEDgGWIYmsF1NLLlF6kUp45Yd+rct3wVJX/xlnCKD7/u2CzY4nRoQ6mSHop 1uBjBh78sMGHr5ry55EZos1HhZIJ7JChCktQ8hR3IwYSfQ5crqTrFVgvacl3EitgCCb0BfJHRzq omPr/wzgFjjFU5I4TFjzu/7DrIwjyG7hnLymMygQGcJd3d9kLx8HMdeR1dw9FF1zqrqrEgqQsPy 5u0My/Hi5zEu+x22rzTHyCAwaMAv5AYCIjVFf9AGSnSTFOALia0z8T/7w/tWhrbAKHOObb43m9z xsOm1U3rV8MnoTrTqs85L5cjIWBVbEt5DCluWUy10HUD91PthEjyl7dYPBpIKV0WMmw1X6IgLW+ YeguGR9Vz9taQYAJ5VkAlVD060v80YCwd8eQcDrhPEgMsZHfueawyTx6V8Q9L1T4yZ6xNvI+Ma1 PJ487UFZ/VBFLqc2SS/CiGtbxWLDdkysrtn6GTdQWnno3e7Lucy3FjlXeG9nxe7T5Kr+rSpBdqc np5kNNwdyQFWoCJPABAB9Bpxf8fAD90NvwcAXoe+mgRLy6OF9Vu4kTWpo3ldTVvAcoklOX5rkz5 0jHsDUflbRHgaSwMPuMdo0ato28evzFF/6Cciaku4qHg0mPH5v8jvJNb8dw= X-Received: by 2002:a17:903:1a44:b0:2ea:9012:649 with SMTP id d9443c01a7336-2ee0e0e8b2bmr19558095ad.57.1794562030880; Fri, 13 Nov 2026 01:27:10 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 12/14] iothread: make legacy AioContext getter explicitly unsafe Date: Fri, 13 Nov 2026 17:26:03 +0800 Message-ID: <20261113092605.942292-13-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::62a; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62a.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562115558158500 Content-Type: text/plain; charset="utf-8" Now that holder-aware callers have been converted, rename iothread_get_aio_context() to iothread_unsafe_get_aio_context() and update qmp_x_blockdev_set_iothread(). The only remaining user is qmp_x_blockdev_set_iothread(). It cannot use iothread_ref_and_get_aio_context() as is, because it ties the AioContext to the block node, and iothread_unref_and_put_aio_context() would have to be called when that tie is broken. New code should use iothread_ref_and_get_aio_context(). Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen Reviewed-by: Markus Armbruster --- blockdev.c | 9 ++++++++- include/system/iothread.h | 11 ++++++++++- iothread.c | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 0f70973326..753bb89088 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3697,7 +3697,14 @@ void qmp_x_blockdev_set_iothread(const char *node_na= me, StrOrNull *iothread, goto out; } =20 - new_context =3D iothread_get_aio_context(obj); + /* + * We cannot use iothread_ref_and_get_aio_context() / + * iothread_unref_and_put_aio_context() here. The block graph stor= es + * the AioContext but not the IOThread, and continues using the + * context after this command returns. A matching put would need + * to be tied to the block graph's context lifecycle. + */ + new_context =3D iothread_unsafe_get_aio_context(obj); } else { new_context =3D qemu_get_aio_context(); } diff --git a/include/system/iothread.h b/include/system/iothread.h index f6c5f95dd9..9850cdb3dc 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -66,7 +66,16 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, =20 char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); -AioContext *iothread_get_aio_context(IOThread *iothread); + +/* + * Return @iothread's AioContext without registering a holder or taking a + * reference on @iothread. The caller must ensure that the IOThread remai= ns + * alive for as long as the returned AioContext is used. + * + * This API exists for legacy callers without a clear ref/unref lifecycle.= Do + * not use it in new code; use iothread_ref_and_get_aio_context() instead. + */ +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread); =20 /* * Register @holder and return @iothread's AioContext. The holder is copi= ed, diff --git a/iothread.c b/iothread.c index d4328fc214..10d40103fb 100644 --- a/iothread.c +++ b/iothread.c @@ -436,7 +436,7 @@ char *iothread_get_id(IOThread *iothread) return g_strdup(object_get_canonical_path_component(OBJECT(iothread))); } =20 -AioContext *iothread_get_aio_context(IOThread *iothread) +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread) { return iothread->ctx; } --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562089; cv=none; d=zohomail.com; s=zohoarc; b=dx6kcxvKRghWsmS6SqtLbkx+amiLTfLoetRRaCZKYvixiJESxcpJx+GM9Hpe2jhrJJppSz9kaU3nsWR8KR6g0BnNdKcrKvKyOL6ptCF+a1pn9sEFme3eWFxrudewu+cUR0YdvISKciL5GYABdeXLMhNwO+7EO2wZi4oD7Fh0mkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562089; h=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=YuPzNNXhmAaT4UyWYgVuYBYlY5/Chqo6IDGzlmZ2kHE=; b=OvbcQ6z12NrPFIBduHrDBdCk339tAmuHKtlfy21/0n++2rKP9WS/ZeJgXkWEoVC+zerB5OfhABSqVxkXhJ2TQpSWaXHPtrEwPfeOeeh5K2qhaGiy8oJ2PQ3JWlF7Jm58QmlYli+yUceBZe2w6pMfTGkXC09Deusbj45fS2MvBzA= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562089814599.9027391431373; Fri, 13 Nov 2026 01:28:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnZD-0001Rd-Fx; Fri, 13 Nov 2026 04:27:33 -0500 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 1xRnZ0-000152-Jm for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:27:19 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnYy-00062l-Ef for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:27:18 -0500 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2e95bd1c14cso14892845ad.2 for ; Fri, 13 Nov 2026 01:27:15 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.27.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:27:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794562035; x=1795166835; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=YuPzNNXhmAaT4UyWYgVuYBYlY5/Chqo6IDGzlmZ2kHE=; b=o1oGMcc4/X01XECfbz3x2+t61CNvBbtYW2jM5mmsUNH9nJZRxGKZArj9kiRwAgsj2S x3hQFJSBT7tCNyDolOfBIqj99V3hKHBorYz6u3n1GjsMV1ifla3Erg/kp+GsGYb57xB8 e1C7E2Ht9w9DRcKA45tXcXgMFdPhlR1jBK6gj/93doOSHpazVBQFn43WHdonL0rkjsiA YGK/nErzTYIL/nON0hLTx8yM81ZlWZ+GuGFQ9VC3E1kVwDjCisCcp2dLRp6kASwyBdRX +jTIwIEqDR6vtb/Zb0IJ3tXkbEKQQVgTTnO8oI8dMDpWgspoS2Ehqogpvl5qKCGgMz58 Xj6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794562035; x=1795166835; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=YuPzNNXhmAaT4UyWYgVuYBYlY5/Chqo6IDGzlmZ2kHE=; b=BooSkwQiC/Lctuq59Stq1Vw7mSQYKMOWYh/6aD/Kjz/YEOSzoTPMxdKV4TpYURtKrg REiWxtXKbvRkdiQ9PRaM4SP5oZYDijImyVlyLRCKnRPS1zH41wmCWbXKHMtq0U/Y7Wtw 2lZijMCFoXYBbBR0mQBPs/5GelUGDZ3zs55LDO9ZfG3ndzxuKSh13z1QM3v7OzB/YT+m 1n9R4Izbwu4nqh1DNg51DS9pXLwMJNKkHEBpWMvRPefVCSZWW/6U9ergBLoU4VMVb0/G i5nJAT3FTsRrUa1BDy6I3O0dRCvfX9za8QCFJA9XIleQ4l/LmTcHsmV878K05iABsyZV lWMQ== X-Gm-Message-State: APuU4Z9vZXDEIuh/IIcxzCTH4VUk9u4AcdL9azUyaCk0Y9XELccjw1hU GSTkZpo+TW6km3yx84fvkW//uGLkWkXktxI7+bEXQ5Ik079j9yyZcK6amYEP+gN9 X-Gm-Gg: AYBFou39JBJPEwAKIIZpMw+l7wNtdZnGccFroIXg/iPl2aS8xb89GIjVJXWF+QRxrdR D/9N7wtsZ6DmIHGoMDSpjh9QPHWxkrMSgGeri5zmYSqDEttN3yEzSj6eeZ4z/spSBcvc9sSrCZe bsmx6TGbLAJhU8D1g+tji5AhQEbp7IEixQgJPPOHTMuc/7Lgz/9dJP95/TR1VwkExPhjTb00Y9t 2L4MJYP628xWpsZiI9LP7rhnMcZiMWGj9DcVWdaQOaNnwtnDk24pWc4eIiAk5hHlYAJB3TX7ZQo kFgPCUgK3AaKPwB+rcRVuJk3L1H/+nxvGsDKgduIHVBWhbKG6YUv8hW1XO/AWeoCnvmIdpTNOHh d+hmSqMKq5xC57u0F6hMNMU7KCqvEaq9tF07noebpuT8sQrDS7kODS3Sj5X2iiU88PUV49pj41F eTG+15UkmOgbMZOZuEVw6WDPAXgLuq3xx+X/IML4SF7DV7M3zjw8g9yvBmYNt9kEzdcvAUMVB/X kO8RyG49Z0ZDyKXhw8H9eJ7th5/VEjFm0v4zmuDEUzf9h00QnrMmTmmk8P+gDtKY70G40vgQ6Pq 2bKA5MgNZYFlIXPtlcG9mBAowSzzBGOKFYtKoNRoXDvjjXlP1wF2ArRZwiY= X-Received: by 2002:a17:903:1aab:b0:2ed:3ca1:848d with SMTP id d9443c01a7336-2ee0ddb1fc5mr21098705ad.25.1794562034856; Fri, 13 Nov 2026 01:27:14 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 13/14] tests/unit/iothread: update AioContext ref/put helpers Date: Fri, 13 Nov 2026 17:26:04 +0800 Message-ID: <20261113092605.942292-14-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::62a; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62a.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562091492158500 Content-Type: text/plain; charset="utf-8" Update the unit-test IOThread stubs and callers to use iothread_ref_and_get_aio_context() together with the matching iothread_unref_and_put_aio_context(). Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen --- tests/unit/iothread.c | 18 ++++++++++++------ tests/unit/iothread.h | 7 ++++++- tests/unit/test-aio-multithread.c | 5 ++++- tests/unit/test-bdrv-drain.c | 18 +++++++++++++----- tests/unit/test-block-iothread.c | 21 ++++++++++++++------- 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/tests/unit/iothread.c b/tests/unit/iothread.c index a363bf8f70..790cd2dce7 100644 --- a/tests/unit/iothread.c +++ b/tests/unit/iothread.c @@ -30,12 +30,23 @@ struct IOThread { bool stopping; }; =20 +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + IOThreadHolder *holder) +{ + return iothread->ctx; +} + +void iothread_unref_and_put_aio_context(IOThread *iothread, + IOThreadHolder *holder) +{ +} + static void iothread_init_gcontext(IOThread *iothread) { GSource *source; =20 iothread->worker_context =3D g_main_context_new(); - source =3D aio_get_g_source(iothread_get_aio_context(iothread)); + source =3D aio_get_g_source(iothread->ctx); g_source_attach(source, iothread->worker_context); g_source_unref(source); iothread->main_loop =3D g_main_loop_new(iothread->worker_context, TRUE= ); @@ -113,8 +124,3 @@ IOThread *iothread_new(void) qemu_mutex_unlock(&iothread->init_done_lock); return iothread; } - -AioContext *iothread_get_aio_context(IOThread *iothread) -{ - return iothread->ctx; -} diff --git a/tests/unit/iothread.h b/tests/unit/iothread.h index eb4d0c77f8..9bdac074c0 100644 --- a/tests/unit/iothread.h +++ b/tests/unit/iothread.h @@ -17,9 +17,14 @@ #include "qemu/thread.h" =20 typedef struct IOThread IOThread; +typedef struct IOThreadHolder IOThreadHolder; + +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + IOThreadHolder *holder); +void iothread_unref_and_put_aio_context(IOThread *iothread, + IOThreadHolder *holder); =20 IOThread *iothread_new(void); void iothread_join(IOThread *iothread); -AioContext *iothread_get_aio_context(IOThread *iothread); =20 #endif diff --git a/tests/unit/test-aio-multithread.c b/tests/unit/test-aio-multit= hread.c index 9179cdc6a3..66ba5a466b 100644 --- a/tests/unit/test-aio-multithread.c +++ b/tests/unit/test-aio-multithread.c @@ -69,7 +69,7 @@ static void create_aio_contexts(void) =20 for (i =3D 0; i < NUM_CONTEXTS; i++) { threads[i] =3D iothread_new(); - ctx[i] =3D iothread_get_aio_context(threads[i]); + ctx[i] =3D iothread_ref_and_get_aio_context(threads[i], NULL); } =20 qemu_event_init(&done_event, false); @@ -87,6 +87,9 @@ static void join_aio_contexts(void) for (i =3D 0; i < NUM_CONTEXTS; i++) { aio_context_ref(ctx[i]); } + for (i =3D 0; i < NUM_CONTEXTS; i++) { + iothread_unref_and_put_aio_context(threads[i], NULL); + } for (i =3D 0; i < NUM_CONTEXTS; i++) { iothread_join(threads[i]); } diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 43b0ba8648..05c31ffca8 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -537,8 +537,8 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) =20 IOThread *a =3D iothread_new(); IOThread *b =3D iothread_new(); - AioContext *ctx_a =3D iothread_get_aio_context(a); - AioContext *ctx_b =3D iothread_get_aio_context(b); + AioContext *ctx_a =3D iothread_ref_and_get_aio_context(a, NULL); + AioContext *ctx_b =3D iothread_ref_and_get_aio_context(b, NULL); =20 QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); =20 @@ -612,6 +612,8 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) =20 bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(a, NULL); + iothread_unref_and_put_aio_context(b, NULL); =20 out: iothread_join(a); @@ -762,7 +764,7 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, AioContext *ctx; =20 iothread =3D iothread_new(); - ctx =3D iothread_get_aio_context(iothread); + ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); blk_set_aio_context(blk_src, ctx, &error_abort); } =20 @@ -892,6 +894,10 @@ static void test_blockjob_common_drain_node(enum drain= _type drain_type, bdrv_unref(src_overlay); bdrv_unref(target); =20 + if (use_iothread) { + iothread_unref_and_put_aio_context(iothread, NULL); + } + if (iothread) { iothread_join(iothread); } @@ -1398,8 +1404,8 @@ static void test_set_aio_context(void) BlockDriverState *bs; IOThread *a =3D iothread_new(); IOThread *b =3D iothread_new(); - AioContext *ctx_a =3D iothread_get_aio_context(a); - AioContext *ctx_b =3D iothread_get_aio_context(b); + AioContext *ctx_a =3D iothread_ref_and_get_aio_context(a, NULL); + AioContext *ctx_b =3D iothread_ref_and_get_aio_context(b, NULL); =20 bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, &error_abort); @@ -1410,6 +1416,8 @@ static void test_set_aio_context(void) bdrv_try_change_aio_context(bs, qemu_get_aio_context(), NULL, &error_a= bort); =20 bdrv_unref(bs); + iothread_unref_and_put_aio_context(a, NULL); + iothread_unref_and_put_aio_context(b, NULL); iothread_join(a); iothread_join(b); } diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 5273ff235a..fc9735d056 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -466,7 +466,7 @@ static void test_sync_op(const void *opaque) { const SyncOpTest *t =3D opaque; IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; BdrvChild *c; @@ -493,6 +493,7 @@ static void test_sync_op(const void *opaque) =20 bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 typedef struct TestBlockJob { @@ -549,7 +550,7 @@ BlockJobDriver test_job_driver =3D { static void test_attach_blockjob(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; TestBlockJob *tjob; @@ -595,6 +596,7 @@ static void test_attach_blockjob(void) =20 bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 /* @@ -612,7 +614,7 @@ static void test_attach_blockjob(void) static void test_propagate_basic(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx; BlockBackend *blk; BlockDriverState *bs_a, *bs_b, *bs_verify; @@ -658,6 +660,7 @@ static void test_propagate_basic(void) bdrv_unref(bs_b); bdrv_unref(bs_a); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 /* @@ -676,7 +679,7 @@ static void test_propagate_basic(void) static void test_propagate_diamond(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx; BlockBackend *blk; BlockDriverState *bs_a, *bs_b, *bs_c, *bs_verify; @@ -736,12 +739,13 @@ static void test_propagate_diamond(void) bdrv_unref(bs_c); bdrv_unref(bs_b); bdrv_unref(bs_a); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 static void test_propagate_mirror(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx =3D qemu_get_aio_context(); BlockDriverState *src, *target, *filter; BlockBackend *blk; @@ -807,12 +811,13 @@ static void test_propagate_mirror(void) blk_unref(blk); bdrv_unref(src); bdrv_unref(target); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 static void test_attach_second_node(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx =3D qemu_get_aio_context(); BlockBackend *blk; BlockDriverState *bs, *filter; @@ -840,12 +845,13 @@ static void test_attach_second_node(void) bdrv_unref(filter); bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 static void test_attach_preserve_blk_ctx(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; =20 @@ -871,6 +877,7 @@ static void test_attach_preserve_blk_ctx(void) blk_set_aio_context(blk, qemu_get_aio_context(), &error_abort); bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 int main(int argc, char **argv) --=20 2.53.0 From nobody Mon Nov 23 04:18:29 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1794562096; cv=none; d=zohomail.com; s=zohoarc; b=Jy5whsIbemjAePqrNcb+nQza6CRdbAH7GOl5Xdxm0ALM4tCjb7I8D2c7K+Aa64llSdx9X6zYTenW3pow0TwW9QNv5SONzQF4zMVfUHR0F036yZcA5XaaPNOR0uho4qwb2jaQLcbi+iwDLMnyX/zpzd5/cG8Jo48Stn9fTgwbDwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794562096; h=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=shgDA64rZZreNHgXJfZjEEX5dFaImNGkxX/JsRBR3Cg=; b=H4xP8+GkDPVeYScKycN1kb/g2HRdLY0f5AiwT5Kuy+nApKyGwl1mmGTt0HgQjKlreEUIioejqDs1kMDZZfApTUy6eWZjJEkZ4w+zL8VWPbs/VITKO+ynU9CXWfjioEUzDU8W0ghQSDyT8Jkhel62CMcUwUUr+AiO/ywaDXIxEus= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794562096284957.6187203248576; Fri, 13 Nov 2026 01:28:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRnZJ-0001du-Qg; Fri, 13 Nov 2026 04:27:37 -0500 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 1xRnZ3-0001BW-Q7 for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:27:25 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xRnZ2-000630-3X for qemu-devel@nongnu.org; Fri, 13 Nov 2026 04:27:21 -0500 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2ea7190aea1so2924835ad.1 for ; Fri, 13 Nov 2026 01:27:19 -0800 (PST) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ee0f7d0887sm7428605ad.32.2026.11.13.01.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 01:27:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794562039; x=1795166839; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=shgDA64rZZreNHgXJfZjEEX5dFaImNGkxX/JsRBR3Cg=; b=bgVCePZme/oc+ATjhBQAMEnkZkHh5yanRxzvGJNDv4douvn30FNek91o7avDNEDNaW xF2MwvUqhOIyeeIleNFsbKNG/F93qW0JtgNn91QYOTqxlId+d71ZlviscSm+2Jx1rz0h h2ZqBrRYJvhSClzkbv4indke58yUkIMIYLdkukG58NfBS9KzN3a3pMVJBqsCvHGCwR3b 5LANCdyTcJlUE2pJ4QubJK2kzvWPhXBYMOdOblBwfT9vdkA2Bi801Z2jDnIXcUA/Fmlv dRWEQd+IRR95Cjn2zMULIbrY3Zg2D7NUaq83v3MkRj4HZBI3E/T+j1YJWdGAWX6z5+bZ EFow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794562039; x=1795166839; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=shgDA64rZZreNHgXJfZjEEX5dFaImNGkxX/JsRBR3Cg=; b=q/aZNxAFHcZZkjCWa6wAqrpDr6s8ltQ9h4aJJOeiBuj/FEECKgcV7InHpXotXcClMF 67Hz7AlanQYLVvBnqL5ZG5weMlbZmVEOC/a68DC23alp7oL4pcqtJ7AfvggreRaRIsLE 2bbu3P8yvD25E99B3KkDE5Qc6+BQIKZfT3W8xl3YO940zfeCn50mSZmP0k02ecYwpToZ E2q+gOPQvfmtBDH/idJAoYpStD/W6ejAGe0DM9h9QFyb+6Z5Ep0RuJkDUZwCxJmxIIYg /VC84Z4c4WG0b23/PDUg+OcvwyRJzwSa8faKk6gZ0t/FGzrl/I7Z1ezQl21ytUGWayGM f+BQ== X-Gm-Message-State: APuU4Z8ZhdOPRb4afkDlS3K4jlUUYNYHs2kYiuX+SHtGgTjeilr+727q RpLQ/XTYreh8IA+uOHHjzrcIbCIJTwuCE9De/9d99sOe8slFvVjMs2Ljoos1nPMm X-Gm-Gg: AYBFou3oRa4q5ZmY02l6YsLfyiw6QAqdsjb1+MAbqWsoPchz7Se+F0SBE03ckRXxzOd 6QRMRZb7Ep2e6qx8kld5vB24qf5ZXnEiG/KDyoHJ+PV+H52qNzK8E96RjtfRLGNc/pB3Gjo1z0M J6YI41l41F9s9riMF7QYe6+M1ugx22KisLZjD6fi98Laya2/H36EbR0ruXnSGu5M8AIwQOChPDf iYgmfqAARvdCaoZCLNZCfZEb5ZyefAuifsoaR8o8eWw6CoWbPFhCyqTgyfHpcmPiYPzn8ecVGxG O0g0G+4+85FGV41akb2qRi+uyf0EH9Ao0E4s1qxmI8WKMl1yqyEwcw6AJgui4KlYYm7a9oM0i43 03uRPuKvFPAGEpRjgnnC5tK0V9u/THg6wUPu/iMIB+sjR2rIeTjOH7YZ7ocSWqHUPw0PZ0jUJMD wQEbM9D2TshgPbcY5b/zG8IBqhorMaHaXdU8LF7DcvniOsbp0vNHSSWhtw6hsCqF0vX8RnjXMMa JKvCqzRqq52veAgdzw5ffxdvuSZILrp2YfYqXz6UqM41TnRZB0GDFZAKX2WoNYRvjyIGrflqSLB kwdb3AZXGgmCkyvsSJcjNHDgkhpqH7W2zNMgullLfDHaZVhn9bWzN3AyVzA= X-Received: by 2002:a17:903:8c4:b0:2e9:7ff5:544c with SMTP id d9443c01a7336-2ee0da7fe45mr18475855ad.25.1794562038761; Fri, 13 Nov 2026 01:27:18 -0800 (PST) From: Zhang Chen To: qemu-devel , Eric Blake , Markus Armbruster , "'Michael S . Tsirkin'" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?=27Daniel=20P=20=2E=20Berrang=C3=A9=27?= , Jason Wang Cc: Zhang Chen Subject: [PATCH V20 14/14] docs/devel: document holder-aware IOThread AioContext APIs Date: Fri, 13 Nov 2026 17:26:05 +0800 Message-ID: <20261113092605.942292-15-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com> References: <20261113092605.942292-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::636; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x636.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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 @gmail.com) X-ZM-MESSAGEID: 1794562097415158500 Content-Type: text/plain; charset="utf-8" Replace the obsolete iothread_get_aio_context() reference with the holder-aware API. Document matching get/put calls and their BQL requirements, and clarify that the unsafe accessor is for legacy callers only. Signed-off-by: Zhang Chen Reviewed-by: Stefan Hajnoczi --- docs/devel/multiple-iothreads.rst | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/devel/multiple-iothreads.rst b/docs/devel/multiple-iothre= ads.rst index a6eb046267..3bd8144ecc 100644 --- a/docs/devel/multiple-iothreads.rst +++ b/docs/devel/multiple-iothreads.rst @@ -88,11 +88,20 @@ argument, which is used to check for and prevent re-ent= rancy problems. For BHs associated with devices, the reentrancy-guard is contained in the corresponding ``DeviceState`` and named ``mem_reentrancy_guard``. =20 -The ``AioContext`` can be obtained from the ``IOThread`` using -``iothread_get_aio_context()`` or for the main loop using -``qemu_get_aio_context()``. Code that takes an ``AioContext`` argument -works both in ``IOThread``\ s or the main loop, depending on which ``AioCo= ntext`` -instance the caller passes in. +The ``AioContext`` can be obtained from an ``IOThread`` using +``iothread_ref_and_get_aio_context(iothread, holder)``, or from the main l= oop +using ``qemu_get_aio_context()``. Code accepting an ``AioContext`` works w= ith +either event loop. + +The ``iothread_ref_and_get_aio_context()`` registers a holder and takes +an IOThread reference. After the caller has finished using the context, +release the reference with ``iothread_unref_and_put_aio_context()``, passi= ng +the same IOThread and an equivalent holder. Both calls require the BQL. +No matching IOThread put is needed for the main loop's context. + +``iothread_unsafe_get_aio_context()`` neither registers a holder nor takes= a +reference. It is for legacy callers that ensure the IOThread's lifetime +themselves; new code must use the holder-aware API. =20 How to synchronize with an ``IOThread`` --------------------------------------- --=20 2.53.0