From nobody Mon Nov 23 05:10:02 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=1790671607; cv=none; d=zohomail.com; s=zohoarc; b=ZeB159fXUrUSpW8pB9yN2Gw4ndC2s3/BTvTpwklDx+SYzH6Prol4bETtyiWY1KxuadqsOsIYsQQ9pF3bf46+IV2DgyQn27bKIn1COJIbagIyt0dEJXPaTwoqReR9WU5tXiT/jZk8oyz3xTZ8jpq1B28cVCkNTRa1vuh1u8Jm3zc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671607; 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=Er4P8E9bwo23WMOqnc3KMSVAUjE4O4btiiMlCHE7dwc=; b=gCEvFbTPVc2YCz0FKJjCIHee8XW0gg51ZJBoYaAaPioMGLp2GxvBC7hE4ssRzAVfM2qvGnFLC3Bb3ZbXbhWywuaJtgb4PCbp/Xww5jkhgQpkDVFZC3IF8a36PbLKDDWzKo6PZopB9hd1aWWPyIAbv45CHkkhJh1Xi69cWMhUrNA= 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 1790671607339147.95586226866521; Tue, 29 Sep 2026 01:46:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTSA-0005kr-QP; Tue, 29 Sep 2026 04:44:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTRu-0005j9-Ol for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:33 -0400 Received: from mail-pj2-x0c.google.com ([2607:f8b0:4864:39::c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTRs-0003l0-V7 for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:30 -0400 Received: by mail-pj2-x0c.google.com with SMTP id 98e67ed59e1d1-3a2adb9bc3cso1193986a91.2 for ; Tue, 29 Sep 2026 01:44:28 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:44:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671467; x=1791276267; 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=Er4P8E9bwo23WMOqnc3KMSVAUjE4O4btiiMlCHE7dwc=; b=CqPRuCObnIwouxFI2O3Wnws2oEuVXmYxugGol811XWvCMCgSffaaxHfviMpvGLHXwo 739SudBeR6rTEg5YLCBwwM6cfPhUyugSzevrbFJL4+IZroqo8spxCXOR79J0ZxexcvEP tYzCmw2kYHxOGYbfZ6L6V33+2c2I3mENQ5zoABYf6fymqcPRJEAIr4MPU+xVQqh21cO4 YjdcogXZ52z6R8+TqEjm3ODcEkMyhc7YKH8BOOdFVzv35W2+u4zUsrn85IUNgARGO68d YOYcqt1nrp6SUuDk0KBy1f9iFIZrtftLFmFpnjo7Iq7IKPLoRi2PPFz4GfbOy5O8HXGv r9EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671467; x=1791276267; 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=Er4P8E9bwo23WMOqnc3KMSVAUjE4O4btiiMlCHE7dwc=; b=f9i0T6zsXGtMJEy2a8Kb+dXuQx3POYranCT+zVPortCAFPsdlHk/O0zuU2HAc38hlO Ixmmb2tTeNuHediN8NU+xTA9UO0DL4GsC5VMcAKZSSroi0ZMdTIKKk//E+FFi9ia53Wi 1wjDexEcbr/aDbS/wIdBlxz+4VJ+chyAHVJk01mznc3mt83xbp8KTC4k6c7NCFirDQe4 OgkVQxdnAtmBSBwGKF1dnQwa54Pm3eUCOroa7iGqWCvzuObKy4OoUmox+UkdZfx/QNTO SWBtm/bPqOfUGaVOATNJo/52So9ffz+Attq0LicNLlZ5/NSWNwQl0aA8B4lNhbRx/7fS 3M2A== X-Gm-Message-State: AFq9FYI4LB0h61o30FRrlV9T75yoA89cxRJKszMTtcKGkk/m3VMj7fgn rA8YmcvqPM8fSBpNC6vqo1vN0hDPIdNyi9kVZARiBEOnWFacswVaHy/qICgFrQSe X-Gm-Gg: AYBFou0CEWjneQdpaYW1QOwLqaW3gvdsXU/0SqrfTdPpdN8nKdHayUYjIwso25couGg S78PDEKw602OGulL0Wy4ww7FUmriy7AfzzRfZ7/gOCfuC9KDu3ezgf7dRkLyimp6CBvakCNLcle G9drU2YnfzmuU3vxq40ZoG/PAFPCvk3r/j2en0R9Ziy7+Ni+PUht6bl8tIxryfoYYML92JDnIiR q3vFmq3j3Huvs/PUDEpBP1V3VNIXLRnRM2HvqSzzjMEPIhbXOOR3VJzZBkl8lC0fFoyXKxokSaj gRIvGRNWMunqdyh+qT0uDlrGghKGgdToiVkLLxdfQD+depfJXMEbQPgTqYPutYn6WDT1FEl2fj1 OWsmx/MXhIF3XhQ5h1rmvG6QYf2YLXnhsHVtFdhC1p6X+XoDnU52uPL6CsS+N5Z7GS5Mjrm9u6m qnhoB91eP4cecVw+VlheuZCKlyvksNpjBDdfjU4c34/5D0J70yNM38Udc/tEMQjAv/PIrIDLUCz nKFB9/bpn/OhuZWPSwgoBpc6yU= X-Received: by 2002:a17:90b:440e:b0:3a0:bf0a:c9d0 with SMTP id 98e67ed59e1d1-3a0bf0ad1bcmr7265997a91.16.1790671467198; Tue, 29 Sep 2026 01:44:27 -0700 (PDT) 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 V18 01/13] iothread: introduce holder tracking Date: Tue, 29 Sep 2026 16:44:04 +0800 Message-ID: <20260929084416.1600199-2-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:39::c; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x0c.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: 1790671607962158500 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 76eea6df38..6b0a7c557a 100644 --- a/iothread.c +++ b/iothread.c @@ -21,10 +21,71 @@ #include "system/iothread.h" #include "qapi/error.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; @@ -129,6 +190,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) @@ -373,6 +435,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 baa50cc844..bb49969b4b 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -67,6 +67,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: # @@ -76,6 +125,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) # @@ -98,6 +151,7 @@ { 'struct': 'IOThreadInfo', 'data': {'id': 'str', 'thread-id': 'int', + 'holders': ['IOThreadHolder'], 'poll-max-ns': 'int', 'poll-grow': 'int', 'poll-shrink': 'int', @@ -122,20 +176,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.43.0 From nobody Mon Nov 23 05:10:02 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=1790671537; cv=none; d=zohomail.com; s=zohoarc; b=nyUmRVqYS6Why/YdKyYNOPuGKGoy+9YxnmDnn6gG1trZhXPr4DaZ2ULza1j6s2ZdcupS0N+nLH0CzfQVkw9bRrhqW+H2IvzHW25C81LwSo2+I0wkArcVlCtzqra9DQYRJy+lQH8iuvMTvRZKT46J6bnOXS+VIUnyvuhPjIn6/oU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671537; 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=ffn71e+pIgrmkpZMSuNM3s3wiDknQ8z6eWqR0ElZS0U=; b=b9m+7g/K8PRz0rviKpAAToVO7XVVD1g4D8ULO8bMmiBOi9AMWKJExcuerS1r3uPmfhQEEKb0g2zUpIsCX+mwrwdr2XfEpbtRHgQq8ZN1hEkgHSz57UlUErUkxm/GFMdxV+zUsf3LUcAWSEMJHh0GUeMwj4+/NggEXPycyu5dRGo= 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 1790671537167796.390760826615; Tue, 29 Sep 2026 01:45:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTS7-0005jo-Cj; Tue, 29 Sep 2026 04:44:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTRy-0005jF-CN for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:35 -0400 Received: from mail-pj2-x0d.google.com ([2607:f8b0:4864:39::d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTRw-0003lE-H4 for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:34 -0400 Received: by mail-pj2-x0d.google.com with SMTP id 98e67ed59e1d1-3a0bcdf41a3so2062248a91.2 for ; Tue, 29 Sep 2026 01:44:32 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.44.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:44:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671471; x=1791276271; 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=ffn71e+pIgrmkpZMSuNM3s3wiDknQ8z6eWqR0ElZS0U=; b=iIpli9QbL8/iTfYlG02uky2uBgeIKRd7pIUduF6u7iHsKoaZG33+ipG7ZXiYl/05Nu +uFof/+a7wZQWSEWqLHVhPngP+76kY/c422VCZZTpB7JGMcx8VYXlhcoEsR1NgIO50dK gMAkcdMxuIAaG5ESHl5KjlQ/MQeP/7PbuzIBhJ89PEfRtt2X2jVm3OC2MN9lSXczBqWy Xd9x6AXLEfddrxXv4gx9TnesUevBmCn0IUxPeYm0Y1XnlojYWKlcJesPhehWTBFcIvoo QrXl5aBrNiX7PnhrS+v1JFD+PkhQ0P60dFKRYTmkk1LkvfDYG63Z/Ab2+Lb7xXACT9+/ tFKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671471; x=1791276271; 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=ffn71e+pIgrmkpZMSuNM3s3wiDknQ8z6eWqR0ElZS0U=; b=XUxoCGoByv3WcrbKDtF/GfxaE0ZEfrgml9IL54UuW+CDGimami3iqj9oypHp8t1Xd4 qYYLTANLFiEDi0Aqvp0gdgInPaZ47/xPZCcbC6Apc5bJ8QjOmnNmCyVlw0MQlQ0t2sxh VFVNPSkWkf2Z7Va2nR1o+ebVz+BAiveNReAcdTncMueUw0Ni49+sCg5sHrxVljbMO8rO z3KnLATIYZP0uJcIdyucfUFLw0NXQ3ZOTyY+1lNN/P6dvp3Na2oGmNwAade0T36bdXgx nL4JUVlblbFyOsrLmjnTainDEpAWxJqRnAVMdmyF8ZIUF8rciPFVv1PSYWi47ejp17iT J28g== X-Gm-Message-State: AFq9FYKGKRKhkf5le9/ekw/zw4mJgYXOZhTkDO92V3oaFuy8toDuT1fb 2t/3zq5Gm+LjumMRU2824dPBeDG/avYVFOxGPzLfxDuz4FwcDznqcVWgYm4w+9eh X-Gm-Gg: AYBFou17ltH7lGImLXG7SV+Sw03YcHNqJgrbg2odAf/XTzClhrd40hSgHy67yoXqFnF qwAuZSigy7YxoEsnRBAKk8iD6quAmhTpbu2oTEb+cWenVt/1JLtc/GLwlUuzWeMi3Cfkv/w+z5D ULRFQuYe/L6czqNcZNKrz2KyAJBkfsL5WAtUq6exsOoufWF5YIrVAHNG3ctmCpmOJ5OCYqsLK+1 H8gJfGselTj7ojb71PYguGOoCyTCLTC78fw6DhjIAPJuWgJ2y3OvEs2vNV0FmTIrEDRZKpV06em zgHsBIEKwgomU3N66h642wnOWqJDpMXXr8X3qLiZwJ7G8L+nro+DVSdMs+UUuRc5K5virwM3pCF 4RfcPSYfvSrwNDaikaKNbwXiucIlqcTb676UZFwf6THk8NCztL8akyWEcNCimkngfhdv6YrNQRP M+61HrskdSUs5qvIgAbhDd605i01SRvGDKWWyPuab7qmugVjoMx4BF52DQmRQ5USDC27mTIlF3G HWziUBmrIFpzaAsGREeYAjI/B8= X-Received: by 2002:a17:90b:1b08:b0:3a4:a064:a487 with SMTP id 98e67ed59e1d1-3a4a064c554mr1148326a91.28.1790671470972; Tue, 29 Sep 2026 01:44:30 -0700 (PDT) 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 V18 02/13] iothread: add holder-aware AioContext accessors Date: Tue, 29 Sep 2026 16:44:05 +0800 Message-ID: <20260929084416.1600199-3-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:39::d; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x0d.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, 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: 1790671537702158500 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 6b0a7c557a..5a4291a2f0 100644 --- a/iothread.c +++ b/iothread.c @@ -33,6 +33,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, @@ -78,6 +83,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; @@ -199,7 +205,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); @@ -421,6 +427,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.43.0 From nobody Mon Nov 23 05:10:02 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=1790671568; cv=none; d=zohomail.com; s=zohoarc; b=mPJvAnMMNIonRDiWVGOT82Zkey9VIRxdyschgBvHrcCnehpGaXRWTzQsGoRlq1dAguDQE2HWZlRB4AP+lSt132sUBNxDfyO8m+GXrTtal4Xw+UMwtvH5oi21c/DihtEWRcAiJmuu2e6bCNAO9VvB/HbLd520hiXmpKuut9NsqNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671568; 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=oeURIEcCI8TbII/h58ISje3mK5oO8wJcPqe347GxoX0=; b=NH34k0Gc0HHC91hZg0S4qsi8HdWPb5S/kE8Phzid/wScwvbH0cGMmyYCgB4apN2hiLO3f+Uisq7h/2Cgz/60Ahnw4dIiyGd3GIpxMwSwWXn3udB1yvhTft2PEGXa4ZQFlUf9WHSxHJt97Tde0dkUSmBhaMwkjGATxbIGLlS10TQ= 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 1790671568846862.6008363845798; Tue, 29 Sep 2026 01:46:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTSC-0005l3-Cy; Tue, 29 Sep 2026 04:44:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTS2-0005jc-JY for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:40 -0400 Received: from mail-pz2-x2a.google.com ([2607:f8b0:4864:3b::2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTS0-0003lN-GA for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:37 -0400 Received: by mail-pz2-x2a.google.com with SMTP id 41be03b00d2f7-cc79f8a6170so965116a12.1 for ; Tue, 29 Sep 2026 01:44:36 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671475; x=1791276275; 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=oeURIEcCI8TbII/h58ISje3mK5oO8wJcPqe347GxoX0=; b=Pr2rgGOE8maB1RV09bBFzcZXE71//tnpv1slH/RT6eAttFxsZomESVGeEsu4BLBiXM cZNoXQZSx+jnKxSZetahZ42m9Y7+aDbMRNblnX1lDrmLXukL5OgBjhwU+Przid9cQIR8 /FmsM52uETaHje1wV7fM+gc0PljYSU8hBXLMsOX8h4EhgwAY1IbVq3oi7Zj1E8ZbIyO4 A7CJnMypvNEf4oCHfqKAgHrMT6RS+16B8HJJms5ouxieXoDB41583KmLCpFS8G+s8/gi 0zpduym4FPzn4PtTwhrYaJeGKm9HZ9BDovMOJSrNAvOWTsWcbYB40MHTtW2qiKHT/Yxy Fx1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671475; x=1791276275; 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=oeURIEcCI8TbII/h58ISje3mK5oO8wJcPqe347GxoX0=; b=Nk9Fe1zXzJFKaCSZhLZ8uP7Shlt/RL3bDzgMEdVLLSfDrr9fVms+WDlFaPFvpIOaKT WQwmQzNBU0MsQZ5N4ZeA+COXQAFrCFfP/iZ6DlxNzs+/blTRN6Q251F8CaXTeC+rruLd 1ByzNNi2uX/jl7n60oSKCjzd5VdpFLs4Dwa9j4qJMa0TX6rlGKf1jV8srl82aCCZxrPr lwjiAp/mVo3Ss4fCrFLqNV9POc7JNHGopJGYv6poU8KsT6qqvYEgShrHUVr6BP3TU7tE KAZ19c5JsW5uUrBHgsSCLLjp7J95IVApwQgg3nVGJ6t0zHeSWW3oOknECcnancqSnfKj 9YXw== X-Gm-Message-State: AFq9FYIN3Kz9Jf6ciRLgdEIcaWTWbxB49M88XxrQSQeGnUOh4HyXzGl5 VouxgPVGDrlpD8amJ64jpm0bpFiDUde6aA0EYxd6BFX5gcjuBTaNHQyINMPGzPbk X-Gm-Gg: AYBFou0E6cn53PecBAhOt9zxE046/fvrnkBC4OXVbS6LG2K0NE7xUZpW/x/rn6WhLab 7gzKbGKzoLEknO12HqynIsPiM93CeYPaqphktdwmZYYurwTmxI6ufuGC2D9D+dxI8oBuv76K2QW +f2ACt55J/jNBK2zsjnQ1fhbmjEFKuSuct7k6v0r+710bL77nYb+JCItsAFnthHzAgPAFOnfh1/ Z6ZBt/sKlVtCmDXXBoE+8aTLC7NOs9n7/EvPH6NVWpYKTUJQtjTZMsZK4LSRBXQBJP9OL9NpHxQ iMbzR8InZKwYtobnICXjNC9hwZOto4Wi1KjgC5+BG1/UTRCf730HitvH+hx6HtZOd2lTRh741x3 Hskuk4+1Rttqp9K4IMufXNdykknbAQge5ZUoHyDLIGESOMiWAbPaO7lZz4f9SWoKLFKeabC8pyI wBcbQymTaCHkIzlBpqBWXcpvsqayfXRjneo7lhK1EGgUx6ySJo/SCpcYh7BMkh21xnZ5De3AN+4 Mwn/x2QaMzYGlPIPOWqdo8R99ik X-Received: by 2002:a17:90b:57c6:b0:3a0:22bd:6ef6 with SMTP id 98e67ed59e1d1-3a09853a6cdmr9957310a91.2.1790671475170; Tue, 29 Sep 2026 01:44:35 -0700 (PDT) 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 V18 03/13] block/export: track IOThread references Date: Tue, 29 Sep 2026 16:44:06 +0800 Message-ID: <20260929084416.1600199-4-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:3b::2a; envelope-from=zhangckid@gmail.com; helo=mail-pz2-x2a.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: 1790671569837158501 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.43.0 From nobody Mon Nov 23 05:10:02 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=1790671514; cv=none; d=zohomail.com; s=zohoarc; b=N3BPWaxMryunDYuFpg68Kg1Yae0gLi2KMb/AbIYiuq0Fk4l/ZZ6uwEgI6iqZUjJwDydaWDa/2ySRAI2wVaX3k5JNyckTl7b8t/Jg8Wu/nLyrUngTnEFnggqUHoMMsMyPhfFWbV8d4aZELf0N+kATSri4JVR5BplRDH0FmMUFpEc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671514; 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=kPvkjh+FJiA8189c+U9dDH41UE3ppPuy9lNP+qAHayQ=; b=YHqYzD/35f7nz3GRafDWxkoABGDs9WCdLvJhWM1XsnYOna3TSXCqjerBAKyhZp9wH4Ybw/mXQVtaaTqI1eB+ec6/eTKafBPVbxVAHFLOT8PO44SmhLODNYG4PtVZnPcWiqftlY46Jxg145NtiDvK7+7eXbq+7xtiK8XiFz60qS0= 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 1790671514339628.752860104043; Tue, 29 Sep 2026 01:45:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTSB-0005l1-T7; Tue, 29 Sep 2026 04:44:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTS6-0005jz-6D for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:43 -0400 Received: from mail-pz2-x0c.google.com ([2607:f8b0:4864:3b::c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTS4-0003lY-78 for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:41 -0400 Received: by mail-pz2-x0c.google.com with SMTP id 41be03b00d2f7-cc74520b20bso989419a12.1 for ; Tue, 29 Sep 2026 01:44:39 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:44:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671479; x=1791276279; 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=kPvkjh+FJiA8189c+U9dDH41UE3ppPuy9lNP+qAHayQ=; b=Z4DldHprkyDME+CnJ6n68oF61A8RMR+AQwQfwzB9UGIm8caSCsO8PJzLWeyEhP7dt0 EqN9CJoTU1b9ObYiqInnnWX/+fyjWxfmMaJSGg7Uu/g2QZg1BVIm7G4sOXxInC+VqLSo 5GSIh0bhiicAa0ui1jA4EKrLUFOhTsvbeeBRCX3AwSFKP5lJlDSCaD4Ti7uk+FjPn9Nn milwmFOy0MnKFMoJKDveqSE/Y8TCc6NFQOQzrbZnoR+9A8PeJag7fnHSxV23K0jfMYqE h0ptObo6qWWG6+fKDaSHTqG9HLY1M8Qcjmu+/VyovKrZIG8K4u+l5zk+h/9f3CnnFiQs ywzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671479; x=1791276279; 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=kPvkjh+FJiA8189c+U9dDH41UE3ppPuy9lNP+qAHayQ=; b=Bp360XSNdXjjW2IfPXeYdQz25tGeCc76qKYicWfBy+gir6hRg+IGTQGcogld6RsA/n In0DxDAxWjhIPIxNBlWpc1IGsM7UB3ITGAzXmk24T/R0EzcB9H+75GYqWlz1Oo9xG5I4 scpIq78lZ4KSpdMSy0pFiOgmzIAeoI9klmr72ErIeZLsi4zw+CeQnCl5DsxZPEO+W3a8 DkWqLEOlDd1gRIm7T5XGfOVHLiQp8jxi5JfLprG8FsM8ti5qWqWu6rGWtLOy9AwG93gN KrysRUFq0AoYMdwcYacL7jG68gnwC3ngKXYwhbfeTN0N7DENbA6Xmf6LVpCqOb46DRW5 PU0g== X-Gm-Message-State: AFq9FYIK+ikBewFT576l/LBB+4WTM+R2On0RsnthQkwL6/CWVpulN3IA Di65a1PXV1TzN8SVNRty86y/W8PBvQpqrWmlMfCOaJbO5Q96dEPhsV+hLPUyi0nD X-Gm-Gg: AYBFou0zpi0rR96cmIj94H5OSX/7zBCgnFCRPIoPWxb3BAkOgl0ji4bTaB2B550NyAs L2E33h5QwRSEepdD44xSGshDjwepjjQynJdnBjM69GOXzdYMEfnOmDlZt06ZjTv6IHNGmq492XV pgGKnjlXwIcAYXmW0R0IrqULdNWzd4Fj4Y7KKsYpkH7NRAqgX+BUuUmkCY2hw6PpaFH26sJljU2 VQe64m1Qiq3O63lTRWdVb6Uhj4WMSNW83Sboy3c86inKCQ77i6UV4k7g0ME8Ky9+6jCX6THIJnW O/cVzhzLTjc0JTn88C0Xd8aGH0pbWG0EgBn5rTlbildBIVNo7Z+IZ2AOhegKZ42/s5xjuSev0Sw WnTC/IDyd9Bx5LTO139YrE0PkgWVh5ET639vvLMw9phWSmogqcpI5igQ7SxnFddOi/BLRH01vTq 70wrGPSZQVJtwIrhFR6/CAT+NXlZSX58E3KOWlfnKuLd2GHEcepNkLGGIw1ctIagqu/Y0rnwrv2 TbrfbpN7HPEsNOB/VNKr5enTOg= X-Received: by 2002:a17:90a:e7cb:b0:3a0:f4ee:d2b2 with SMTP id 98e67ed59e1d1-3a49c1a1183mr1065468a91.32.1790671478637; Tue, 29 Sep 2026 01:44:38 -0700 (PDT) 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 V18 04/13] monitor: track IOThread users with QOM paths Date: Tue, 29 Sep 2026 16:44:07 +0800 Message-ID: <20260929084416.1600199-5-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:3b::c; envelope-from=zhangckid@gmail.com; helo=mail-pz2-x0c.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: 1790671516037158500 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 aec0315775..e235302fb3 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -187,7 +187,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) @@ -678,8 +678,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, @@ -717,7 +717,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. @@ -734,7 +734,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 { @@ -788,8 +788,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.43.0 From nobody Mon Nov 23 05:10:02 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=1790671568; cv=none; d=zohomail.com; s=zohoarc; b=TCR8WVtdjuT6t7g5AfbAHUUrkNR6vkw8JY/Tt84lrx1G/PEDi62CNt1PYgm9J3pf6VMQR+g6hSaOldI0xQ7QW/AwlXPJR3+03eXYhAhhz/5qaPvvEoU6y+jj7xA9drWaveAnvH0SmWnkGKjqEQ0qCloRMxdqNWawB0XtYph0bFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671568; 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=+hZDiQJvaOmf+Qn0tSyuAWF2wzjzOq5r5lnSqYHWVac=; b=TnxoeJhnSufLcpCCmc8PWd+RXTyC1LRGQKKykkRnpO+PQR8y4MoSm41NBKlsP3FT9+cjVuzw+sp+h4SbR8dSPOqGN3rKOn7a8wcmYNjfYOdK6mC3ORDXjmCY54uN3YDsyahwjyuyPJgcieuEHQtHR2p9O7+pd5weV3e1xyBnsys= 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 1790671568401155.95915297380748; Tue, 29 Sep 2026 01:46:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTSD-0005ln-Cj; Tue, 29 Sep 2026 04:44:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTSA-0005ks-SN for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:46 -0400 Received: from mail-pj2-x0f.google.com ([2607:f8b0:4864:39::f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTS7-0003lk-5Y for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:46 -0400 Received: by mail-pj2-x0f.google.com with SMTP id 98e67ed59e1d1-396ccafb751so1834472a91.2 for ; Tue, 29 Sep 2026 01:44:42 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671482; x=1791276282; 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=+hZDiQJvaOmf+Qn0tSyuAWF2wzjzOq5r5lnSqYHWVac=; b=GQpXhWoPcsknuvoiKf3ocH6rj180PVS1dSAX8QPwly6yqcZbhwGwZGGLVcnTt6j1Bu 5deRHvkYWuvtOCn47a0+WE5wOfa0Y290WIqNrMqZvnHUvpAi8MQPP99HOetywVisxBlf ec8An4tA5qGjBs4RYEGh9cd5rhWkvMYxEvxcHH8sOpqbcM/djOL37E5LYlglN4p5O8hm nkyGRrpcZmI601IH1yo2f3XtO22Uf0tfrjdDv0ty0J4Vl7g4dGFa1435S8vOO6rJg2MM bCucP3tdviNaNZ8criIedq5dWZv8/nGJ+JNx7Ns0DD73+d2pgElns09b9lbxybSVXUQk 4I4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671482; x=1791276282; 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=+hZDiQJvaOmf+Qn0tSyuAWF2wzjzOq5r5lnSqYHWVac=; b=HXoM+y6r5byArE58uzZ7S9w4TpDreatDUE65/6l98XqR4iQIGND6SsazO26qa9sgp1 VVV498tdpweGmWQp5rjhT7ftRdFeq1Xio9a19ZZ0XelAyaqZjpEqpdDK5/3op9z1giQM MEPZVap3zkRG9r8i+sKBvZtkbxPYJAEiurkMEKuwcCdmT7P4XKrJk3dcBPYUgvDL9Uoj KY30cG2ET3nQpcZp1huZ4DlSR4xZlXr0DdEH0Vi4NroHXRrRspwdEm2F103MQ9h2urqH Akt+iDPv/8NckznTpBUb6pfSPD/ksflvj2jS0Zse0lF8pzkneR32ia1b3VyUs7GRIC+o t1Iw== X-Gm-Message-State: AFq9FYKduQNfHlN2dOYmEu0yhQO1HBcj7I8MnvjHMbp+h9c5MZNqd7Qk lt4nKF/rzeJTXa4Dcek+6ury50vZB20imJ5u41t4O84K67hYlE6Qi9SNZD5Dh4MO X-Gm-Gg: AYBFou35fTEstm1w+I4s2oxga+Cg8qOW1voJyo/7Z2+j/qTyMyBJjs0P7zEjpExiGbS Yf6Koe6z1091IOwh9Zm56qp5q3BFe7d5fUDQvTwkDEfJOCxYcNzatSN5E0bTpX6tbYF/cZGox8d psyHdTmPSFo69reIsb2QpJZl1GRgkduzJsAOFxbBgoz2TCTM/r+efIUuzyoZ3znIGS1xILmuTSC BjdgIaL5goiapRXrsLAfGF14Q8CqmaQKvXyljSmtwsh9TCQSjGYQAJ78ShNBHOQ7+h0TzBVePkg Fes2oIKXZsU0GQCTSHQdNOIbC1teYBU2iwh6K6FmeXtrpxfTUMO/+gA6uR+Yz18krfcnc+a3TRo BymtWHtzJd/JEvwYUcDunG4+jUiTEk6dDeQ5XXQCr+3leapmP7pOfDpsVUus9uoSF2mbX5C6yaf 2duJUMf/2QFMXwRYB/8PWBggqhJMcYHnZ5U8aTAQX2rL/pAirce4ay7vuzVjU3Ynnh8gqz22Qnz /xdd9tYSoYc9sinlBopXguwYzQ= X-Received: by 2002:a17:90b:2e8c:b0:3a2:b09e:784d with SMTP id 98e67ed59e1d1-3a2b09e7a74mr3147898a91.45.1790671481715; Tue, 29 Sep 2026 01:44:41 -0700 (PDT) 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 V18 05/13] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Tue, 29 Sep 2026 16:44:08 +0800 Message-ID: <20260929084416.1600199-6-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:39::f; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x0f.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: 1790671569839158500 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 +++++- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 61c341ce2c..b2887d74f9 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1499,9 +1499,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; @@ -1533,7 +1536,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 */ --=20 2.43.0 From nobody Mon Nov 23 05:10:02 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=1790671614; cv=none; d=zohomail.com; s=zohoarc; b=gAgYl60v4t9J7/5SwUwZorA5ZLZLubGdyuT9SI7M167dZp7YUT89+99M/Ny1FHdwZpzwdWi5DAERy6IQHtyoPVOH7/cByejuZjxogRGkGqH0I4nmusWKpFk4ftbzSqsIthqkdamZWhNAJpU54uUDG5QqqfdgJstk29TaDlNi1D0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671614; 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=bQ1xMXHGriuVI38M0jNZNv0jqCh3rYIFg5oTVX3Y34Q=; b=k8VB0uVackVP5kwWULHKZGuByEQr9ZuIkAe1TsXd2JyLacIUekq1eboihRqJLAW0QoJO1CuzRdKjSRWomXRT7cAlbqn2/5aXcSWVIxafqME6c96/tykg4/LV8V1hDlhMUD29qO8dxu3kWyHfMNyOJlFdsd3aZrmPpcSwLm8Py5E= 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 1790671614915778.2741833423645; Tue, 29 Sep 2026 01:46:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTSE-0005nV-Dy; Tue, 29 Sep 2026 04:44:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTSC-0005lH-GC for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:48 -0400 Received: from mail-pj2-x10.google.com ([2607:f8b0:4864:39::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTSA-0003ls-LH for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:48 -0400 Received: by mail-pj2-x10.google.com with SMTP id 98e67ed59e1d1-39b2ad83dc6so2612231a91.0 for ; Tue, 29 Sep 2026 01:44:45 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671485; x=1791276285; 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=bQ1xMXHGriuVI38M0jNZNv0jqCh3rYIFg5oTVX3Y34Q=; b=VBk1/jDA5BOFRFkfiiVCMpAgjLOQnJ5RPegf6rxgEz8dUpKup1LZy/33dQH0nhelv1 wtBLWlyR2T9m06XigdChn/hTq4S/cP6VrDklbwkv62hc02YpjiLNAbE+D5mjL6nbCA8y uD278xIAMtFJf1f18DQvcm0VDHD7vWIZEfUHxt7sQKuaGNKXzXc+i++ol5Ga28cSKMY8 c101XObWJBp1bK9ypL0YjktGNhgdKSqrz3NWYLy2g/+n6PSPPlPsLLdeOU2a1810ydct 1Yh1d5h9GsSOI/XhhNqTLJbCCHXZ7m7sL2+GfntHexHvg3DWjAcQVB7D5V41rQ+J1yAD RgPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671485; x=1791276285; 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=bQ1xMXHGriuVI38M0jNZNv0jqCh3rYIFg5oTVX3Y34Q=; b=zVkZviKV9KTY7o5gRplQC/btQS7+l6nbvsUOwwOh9N88UonqIj8HN7a95K+VLP/BXf MOGZLESAMucR3rAIf2xCrikHRLaPQJZOOlwqC1Opr0N/A2P8BwWUONK0d4elXsPSc8en GItcjDIUP8P62AXu4nvZ8cNwc23nhlZ82dmMBKS18iyjIJkGWUVSUkkJdmIgIwqebV8U aBywqvBzdR/eUyQ5CZzvjLdot4wFi7AuhkN0gAYBnBypA6LjK3e6Q0FPxir+EoXfRI+y mab54rWO9W522v4Ufv22Y75ODvEGtf6NmFIDUaX0itCbu/LkQV3S5hOHh6AHoPmyCR2Q h39w== X-Gm-Message-State: AFq9FYLJoKjYCUoDjsCZm1mTEbkAytoAZRd5sNIBjm/R6G+6X9PXniuF NrCJdBUb/4QqvgiUtq+GsiUGHnf6wHseXA4cpxPlSl7uYuWK8WgfSFxkKiO6W1oW X-Gm-Gg: AYBFou1gJpJNCbrtRCGQpZfKHxLCe0I2wkkQrtQiAMOktO0XUW8yYt99M9fZIl7Vm+m ndjtVSWsjjHKtEXkc+xyMhF6p/1mW5DdEzTk2LEZxizIheW71yT89ihr0Dq5LJ3U08Vv0f8BhIB 2aTusWQYEORsPFahISZEDqeB0LWG+POeE301DW/AkgThBWTBxQD48yzhfv9R3Z3jvlsd4GU5RRy JogaAn6w31+NuTHrsuE35K5UabxO4cfLYlQUbWhvkCbT/HPb8mX10HlByiw+Ss9D3X0TkH519YU PMrvb/kurIUmHFo0pK0mYvHVLnFLFb/43ffFTlhQ3r83TTvUbXQpud/ceMkiZePwL761LkM27oI XHBX+Qbftoi2IDsGg1T3bw+HpA0juC4+1HwBru78n98+L5FzE3B0cv05sGRxkLI1e6FFUQL0LO8 mhgtkwzkrzCzeeJprtnkxEEvvLfVXY4RG8EfPbOJWuZkBqvUtj9vCZacEc9NDqAyrbOMMQwkUwX sN8/qSfBkBY078d0zVMBWERXQDFel6TKrJyGA== X-Received: by 2002:a17:90a:1c89:b0:3a0:a259:c67d with SMTP id 98e67ed59e1d1-3a0a259c7a2mr8454750a91.20.1790671484804; Tue, 29 Sep 2026 01:44:44 -0700 (PDT) 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 V18 06/13] virtio: track IOThread references for thread pinning Date: Tue, 29 Sep 2026 16:44:09 +0800 Message-ID: <20260929084416.1600199-7-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:39::10; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x10.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: 1790671615975158500 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 b2887d74f9..9f567f4c65 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1475,6 +1475,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, @@ -1499,8 +1500,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, @@ -1511,13 +1510,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++) { @@ -1532,18 +1533,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.43.0 From nobody Mon Nov 23 05:10:02 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=1790671569; cv=none; d=zohomail.com; s=zohoarc; b=bd3X9oZuQMxmEwUW1+gln33pRVor6sVH+JQVEH+yWCGaMMYfF3bM9G22cnHMlRQYCDVu9puHJL0dOeuPm/6a2n76hOWWyR2SSnTuAVf7t1teUJwcT6vnUtxrJ8tpMdcZIPeFjFOC6S6QvFdzdnz3JHi4CsWUsLdNYU2YEW6vm7g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671569; 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=tgB8UHMviU6AGL0Oo+1NRKolrlklycCTQp3aiug74lo=; b=BF6ON4UHMlJuOKx+hrS+5IiYlrSbXj+uJKoYIWdjrqzu9/mXHu1IHEipvE7AE5+WFZ5bdp/rt5qrHQFjvrBeicKDnYBuwBsTeD7Yzk+gc79CQVEOwCqNoNrWGAVJuHoDjVOPXznSYFTh9mmVsCS4Waq0QllS9LERZRuQJuMZySY= 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 1790671569026750.1170465983328; Tue, 29 Sep 2026 01:46:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTSK-0005p9-00; Tue, 29 Sep 2026 04:44:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTSF-0005oD-Mp for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:51 -0400 Received: from mail-pz2-x29.google.com ([2607:f8b0:4864:3b::29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTSD-0003m8-AZ for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:50 -0400 Received: by mail-pz2-x29.google.com with SMTP id 41be03b00d2f7-cc7c4c92477so242891a12.0 for ; Tue, 29 Sep 2026 01:44:48 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:44:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671488; x=1791276288; 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=tgB8UHMviU6AGL0Oo+1NRKolrlklycCTQp3aiug74lo=; b=FwS8m4LfWholmarPke8sonN8gf6EDHBHwzVNY2UwEbOrAtYIhQxqb4Ppf+YqxavT3w XpW98JnBb0DZcwAEwhScEfRGWwpb8vupRJjPZdOoUdDzDqFPbMifP2v1uK0i788CWuQ3 fqKDR4Vc7sALLv/iuzFKhW1ObRwE/tYfZstu1YCNEchMHxidu8w/oleMrOzlRKwVmgCG P7us4FjFeOnRwMP2PieQG9tC8C2sdtqx2JRQQi496JsY3cUBATrnKxmcY6Ki+HFZoQbW 2WHkzi1CTsbGfQCvunOfBBFu2V7dcZ+DPJr8A70HJT0mF8e6bJqa69K740uWhmJ0GP29 qhZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671488; x=1791276288; 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=tgB8UHMviU6AGL0Oo+1NRKolrlklycCTQp3aiug74lo=; b=msOTy71eJG4sioaUjDHCMCtEN6PGzmHYy9vHup2OA7P10/o0bOZfsCO+pcBcLR15o7 f2DJMG9q47Zekm/JNLtSbFzYH1w2+nJ/3ejfckwGra04s2LktM1m3r4dZRqeycKI3AFh CRYBAzl61LUrG/ylc9gAoXxLsFOkJ0yy7Z4T6wHlkBvoQwd6rS93VhVAzx+PZJdydkMN 4UQ4VqfR4l2HE0Xwu3mxEaPOrqDjrH0+4kJ9h4eSHuNlsr1oS4IhqWv9ZwC0td+tnWBk P9TkrOw8Hk5/whwTElHeJaf3CCABPHe1cmWHOLMZlkUkULWVfsgIcE3E4bRwxu19btzZ /6CQ== X-Gm-Message-State: AFq9FYKTOOBuXkPs4hFZhS+X04dbblAUyfHnqLLpxPPtYKYzpjHDrGMW Qt4pwQqzte43oRB46bNINLiXqR6JnBQpMOKndV7A0GNqPerzc6DMZICt+YttQSYa X-Gm-Gg: AYBFou1IQ0NBAB4Qy/In6aNDNxqdTCQa2LyyG8QyHMY/XVevd+bvAE33gSq7k8/W8ZD f1SvtTQeez1Qb7hnuljYQ+QV8Jk3yamP9Bnfmcl8NoSMsV4ryR/LSdf0w8N5InGjqSsCswGmTc6 HPDeQdTraIW3ED9BDrYOSZTNR9xgu/k/u+zvW8lxhHiFdKGeR4/Y/rg01q0sgUnr7u4/MwsNS6r C0XM2/xUARh1svRdngHCpMpX1sLHj8IAzEaGKJ6oBikWsCpXvVwnrzAN+DicVqw7gVihNztUSza eESmw7Woq1RwJhALHDejTZKAcwsuPmv4ISduDLtbFclq1OWp71Jaie+vPRUFR0Y/Jr8fm26uVtC m0I8LYLKpUe4Qq5YoDfikHXaJxUGbejWTC+qhWNvN/fMcXgBFSYNvKaiQUnubpEyYkdka6UfXeZ DQHyeD/N8Y03mUlmgf0jVJlaGWV0PcMXYzqbP9g94NTrQ0Hz5kry2vF/iFdgs8Q5bGx4Cl0f/Kc Tg3UBrV/YUap9sNlM4wlXbFFzvDMbMpRQorGA== X-Received: by 2002:a17:90a:b81:b0:3a0:a259:c678 with SMTP id 98e67ed59e1d1-3a0a259c8a6mr8811189a91.28.1790671487812; Tue, 29 Sep 2026 01:44:47 -0700 (PDT) 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 V18 07/13] net/colo: track IOThread references using path-based holder Date: Tue, 29 Sep 2026 16:44:10 +0800 Message-ID: <20260929084416.1600199-8-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:3b::29; envelope-from=zhangckid@gmail.com; helo=mail-pz2-x29.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: 1790671569806158500 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 5986fb1e88..4a7e7d8012 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -130,6 +130,8 @@ struct CompareState { GHashTable *connection_track_table; =20 IOThread *iothread; + char *qom_path; + AioContext *iothread_ctx; GMainContext *worker_context; QEMUTimer *packet_check_timer; =20 @@ -922,9 +924,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) + @@ -964,8 +964,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, @@ -981,7 +988,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) @@ -1429,20 +1437,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.43.0 From nobody Mon Nov 23 05:10:02 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=1790671583; cv=none; d=zohomail.com; s=zohoarc; b=QWcgDzOsgjLTKE3cU7cE6CBWhMT/V13GgQXt7K3xCPq/4JWnJ/0b5SjK9Ansc6fQGQa1iRO80QMCJOkeSS/O3sV4CdbwiFF327n7MAxZf7EPqkjmK8UWATbXEzrRN+ht+AjBztyhV+991ek5AA/gqVu54bF+Fe2aHBLHyHDkFKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671583; 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=FlA2nQmoOrWyu92q9uY7bri1KbAe5YqKC3sra4MmyoI=; b=mEmsrxwAHCNavbp9HPG6OCbQFh6cDUxaXllVX1lfhxm66aNlDBE2sqNLfqXHC7IQSZphI6xP3CUjwgGBW1YtIRO1lTiskOsT0LybXgTSZ6jXEG/6Ah0sZywI29z0Rbh3p+I4ec557nTLELnJFzcGd5OBL68gwC9rzr+hlt0lqQw= 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 1790671583333403.7174420919479; Tue, 29 Sep 2026 01:46:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTSU-0005rK-Io; Tue, 29 Sep 2026 04:45:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTSI-0005pK-ND for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:55 -0400 Received: from mail-pz2-x0e.google.com ([2607:f8b0:4864:3b::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTSH-0003nY-6a for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:54 -0400 Received: by mail-pz2-x0e.google.com with SMTP id 41be03b00d2f7-cc4c08393b0so1647141a12.0 for ; Tue, 29 Sep 2026 01:44:52 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:44:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671491; x=1791276291; 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=FlA2nQmoOrWyu92q9uY7bri1KbAe5YqKC3sra4MmyoI=; b=JpuyrkXBXJVbKEHT482Tq1eYbSQN+xVK5cggZwCd429EPyhBBHgKgV32niKDC9Evta Y8mzqw/5qFg1OlTmpAG0wjAnHIcFLMziwdjSuOpykcYEMLJFmWyZcRp20C54TzQdxLD6 IjfrkB2yC1L3hO6vFLWJwtp1E23CXXkFb062fXDth6ayD0QS6+DIVC1Ya9XFQfi2q0J8 hNZxTIHYAakWQO7m9tOynYiWW9dKbmf4gWufcQLMltJ4tAL/7amAHR0cxgtGVQka5QRE SX+mkkPdb+K0JDRr1VMQpR6ptx0jjmFrjhbBamvwyX86jK641u0mGtjfNltOO643G1+A QWWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671491; x=1791276291; 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=FlA2nQmoOrWyu92q9uY7bri1KbAe5YqKC3sra4MmyoI=; b=AU5oQITHs87YevnZHBxNDf+AKT7Psk4ZWc5ZG2qWIFW/9wyGu3BFOsbfK7TUiGKVq0 ijGFZhNyxtRNMtDNs8yftSGRXdqvDEWT1mXVlKCDtNzT9NYwBavNeofPveSXDWnsKNU+ DIRrrw1J3srwXCveaCXR9ZYVq7Dq8pJ5ITBfVR3XwnZOpOtTplrveTwwgObxmz9JIYek d+1lrt9CcYhRZmGwG9h3PEXH9sCCKxAw++JN0Xnc7qdxc6ael/pxDHKpeoNm+Orz6Svq rZUSNyaqFBkqIn19BuPcGqtjdFwksourlwHl9VF6xnlF3+0KcDeITHNvYD+OvVYjDSPY +uow== X-Gm-Message-State: AFq9FYKuhCiEvPAgTiwTspCXJwqHWuHESPGZCJANyVjkq95LCPLTr2+B em3Wn29B+IMbeFGY/KmQrwklddfCDIyxt1hzo5XKjfvO4bcpSpFz+rgMWWTrLpzH X-Gm-Gg: AYBFou2Zp6LqvMyESiaZvUy1tHZB7NDd0iBWzU79MIH+46p8uFCuP7nJRKkXZV4Gj2o FwG42w5OihoEnQapJcudzjljp6bG6Jes3oAzg3fwjit7wJTmJP/XMGRfDyGzGq94XaePM1IrKBK NGorpkmz7k1921+L/AGBI40EH7Mssl5Aud3GEYZyrPG5JTge0xEhetf0yXIuNAwF5Flj9E3KTO2 b1VeHD90QM1l/UVTDMA2lhnPyE6u8djVpWNJPqYSFtJ47KbKSaeagFdgDwFI9iwTkhjiVl95x/C El5KadkIepLxXv4ec4zGztIn8piuCM4JgiCTdSb0MCjmaqFYg5paYzlITfszNBu0m0qW0U5QBBV Y/DKT5Z0i/Zr+/JcrJX5b+TU4tZHAVUK+LfumAFBx01NvtMGRXFNrhihcj+qTXi2B/DUyB2U/W/ K99fAzKn+oTvtVdgIxZEvXzHOPi4q2jkrULrp1UgNxgsm6/9NgX+aydyAhFGkwG2hBEj9u8lilf fzCsYYaKEZqcfvz8RsUmDDKkzU= X-Received: by 2002:a17:90b:1c8a:b0:39e:6c69:34d5 with SMTP id 98e67ed59e1d1-3a098e900e7mr14307870a91.57.1790671491637; Tue, 29 Sep 2026 01:44:51 -0700 (PDT) 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 V18 08/13] virtio-balloon: Update tracking iothread users with holder Date: Tue, 29 Sep 2026 16:44:11 +0800 Message-ID: <20260929084416.1600199-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:3b::e; envelope-from=zhangckid@gmail.com; helo=mail-pz2-x0e.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: 1790671583819158500 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 07d519cf6d..cfc581940e 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -896,12 +896,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); } @@ -928,7 +935,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 @@ -936,9 +947,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.43.0 From nobody Mon Nov 23 05:10:02 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=1790671567; cv=none; d=zohomail.com; s=zohoarc; b=N9/igFAbYZGNVfKXUl5RFGnVb1F8YiuAXl2MJn0tCjnu71uVDSR2sMuXfyYUwVABZgXKAfPhZU/ZEEzAexf/Qw4oTh4Bj47R5qDH0VJ7X2pfcfYmtyWyayAVDiYQpJ3ZvgslpkFb4ae5+LY2fbwYw7yEyXfkE3rpjeLKUv+Bkk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671567; 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=LaoH3WqcUPD5qd54Je+ZT9uQvS4DmV/3LHGVO+3n+k8=; b=ByGaC70IF2wa4UJfWH1nalmIcU2zDjzP2bbfgCYxZTA3I2+kJZNg2HzrabttHTXpQVdQUNtCqtMkkggRh2OR5lz/CLQD99orJtlMbtEZ3rDjCvSuBx+vuF48+9IShDu+upewtKQqa6uqiweK+OSi5rFJmSYybv2gDUSLPebEDlg= 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 1790671567952559.7587933243958; Tue, 29 Sep 2026 01:46:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTSV-0005rS-Hv; Tue, 29 Sep 2026 04:45:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTSM-0005pU-EO for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:45:00 -0400 Received: from mail-pj2-x10.google.com ([2607:f8b0:4864:39::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTSK-0003oy-RF for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:44:58 -0400 Received: by mail-pj2-x10.google.com with SMTP id 98e67ed59e1d1-398cb5615deso3167812a91.3 for ; Tue, 29 Sep 2026 01:44:56 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671495; x=1791276295; 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=LaoH3WqcUPD5qd54Je+ZT9uQvS4DmV/3LHGVO+3n+k8=; b=Qf9CLcV0Eg8AetHImnv6sSJtOmbXtHG4oz5AF/Wp11Lx0LwYIvQ+FkdqCKPnm5PT1M vpqs9RXKBohkGtrwicbWBbFhFwRDOfXZ4Vr9yJQGtLMA46QKwLQ9jbK5QoYq2EobEFTz TvqwSM+A99kxCZxPNVlb9YNAcR6xyi3om/a5eRf2S6JAPCLqUFLdv5uxQFAmoeoZcQzt ybS9hLQ5ozesOOzq+0DEFhCoYDvKEs6a1NSjLgrkjDBOGKhI/h8LqtMblQom7EQKPgBQ ceTJ3RfcOBOSMHIFsjHWqY7SkopIE4JLbM+ZHjdyqA8uUAbg2RZ3QHh4EDY5rb+OjZPZ ghtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671495; x=1791276295; 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=LaoH3WqcUPD5qd54Je+ZT9uQvS4DmV/3LHGVO+3n+k8=; b=lR6b0Hh9MPUArkxtxLXpdrGJnw0XWEGlWtJgfSU+pxK+ruVgs8cuTa0P629AxOcsou G1wT4mADO505EADZUcwcgbiFx3xZC15e6v4tjCW1PCW9GpwYsVgN1Et+qR5Na7hp9hc1 s6kMOtJ53f6udcln44b2BQgkiUYAQ6fxgUdZHXOEHTypaerBV2ifbYH5dZN7HES6sKbu HOfqj+bHJCIV/8afbzYA5MTxmgGp1vz2TjLi/s3BOnDeZPrf8zRXFVpJX1rYjuIeTe88 tQcgs0e8iJ9fpvzzUv/pCa/LSFtb/A7nJnYYCZHYDA+JQ3EornwIG7LpKNlCgsSuxxqf j6eA== X-Gm-Message-State: AFq9FYKMm9IU3QEr9o3BU9Atsh4m+dARW8hoDlz1TwRk91nlV2rVTL8w SNrX0bNpUN6UwVPFIk152t+5XerkkwAsBAR9HpV9m26mGELe8MJ30e/+WNaaXuVz X-Gm-Gg: AYBFou09F/jx2IEgECpQ3QAyGAcqGmmU39JO/bfkB7XpPp7yPzM0BKf0GD4jPLgROhp UAu4Uage8UMQCh0bQz7TNg3mK4HLFbxfmRiwGooQ6dOqoK+FFifb7bJgqNgmhR0SiZP/K+/wG0H Sef5TMs1cxGj8BAxdd0L6g1amXgY/vZHv7SCDTzmyco2zFmWr+1W7alxAjH81yrmDVPIqZMV0L7 AWPQ2R/qbCCMHhiJTpkSGLbVGiJwtMvsRFob6sBT2W3eLqyHgfkxFiAwPQCxOQBVYmwWtVHTEzK 1ISaYze2FbdfUycbV3kKEAk0v5skTENB2iyQ0ztShseyK9TdKLhGRY/TthQZEsMULk+ourRJ+Yz OiSA2uMzgNT5ns3BLS3B1egXO1wVVWhqaxUznXkVTXtJKsv76xV/XgLlfuSlh/hI8Vr2wZ0uTAn 3Cud65i+Y/l9TqSrdJz/NQXW2CsRPU5ndsomzUf26nRWxVGar3G1ZXnRI11Rj/HB37zYJYObd9i W8vV1/UGMFLGe33Xhxp87gQbNCzOZluWAKEXg== X-Received: by 2002:a17:90b:1f8a:b0:39e:6a82:afda with SMTP id 98e67ed59e1d1-3a098fe651cmr11916434a91.44.1790671495499; Tue, 29 Sep 2026 01:44:55 -0700 (PDT) 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 V18 09/13] vfio-user/proxy: Update tracking iothread users with device QOM paths Date: Tue, 29 Sep 2026 16:44:12 +0800 Message-ID: <20260929084416.1600199-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:39::10; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x10.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: 1790671569837158500 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 e7573d4a9f..126dfdc897 100644 --- a/hw/vfio-user/pci.c +++ b/hw/vfio-user/pci.c @@ -273,7 +273,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 197aee07bf..e48873c0fb 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -892,7 +892,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; @@ -917,6 +918,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; @@ -936,7 +944,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); @@ -967,6 +976,10 @@ void vfio_user_set_handler(VFIODevice *vbasedev, void vfio_user_disconnect(VFIOUserProxy *proxy) { VFIOUserMsg *r1, *r2; + 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 @@ -1021,12 +1034,15 @@ 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); vfio_user_iothread =3D NULL; } =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 7b97460cc5..dbdbcfabcb 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; =20 @@ -102,7 +103,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.43.0 From nobody Mon Nov 23 05:10:02 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=1790671615; cv=none; d=zohomail.com; s=zohoarc; b=EFPLl6EqLKnIwqX67TqkhIVEMD2zxLBbGWZxqrY8Vws3If2jeDTkHRfCit0PgxKAjK4xz+FBptHoAOtYiYMsAH3v6Q3qV7jnmYUxolW97mQrrJ48aJD9+1OGyNLcseWDBVKO/osLaCfyGpNn6urASW3wyt8WAqazmtMbCCfPjMg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671615; 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=jVxHr521NDdsP0576c5KkwGFcCZcrMwIiK5zVjnjcKY=; b=MduZa5g/ITz/4M2UC03cmy0Ee3auYDsC2QMIAyiwnTqu4fr+3EqniWHog9Wg7bbr6RaZ7IVbF0Z/+ZXbSgh3r0M0V+gXcSDWf7W/W7QDTWXFORsF5arkqyaIdCE6bKFzaE42k1C6b1RBhk3pRKKzb3h7y0ebducqYQqK1yG6s/Y= 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 1790671615108584.1926971577182; Tue, 29 Sep 2026 01:46:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTSW-0005ra-3w; Tue, 29 Sep 2026 04:45:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTSP-0005pz-AX for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:45:02 -0400 Received: from mail-pz2-x16.google.com ([2607:f8b0:4864:3b::16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTSN-0003pA-Us for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:45:01 -0400 Received: by mail-pz2-x16.google.com with SMTP id 41be03b00d2f7-cc4bdf8abaaso2323978a12.2 for ; Tue, 29 Sep 2026 01:44:59 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671499; x=1791276299; 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=jVxHr521NDdsP0576c5KkwGFcCZcrMwIiK5zVjnjcKY=; b=Rs9kQNgbrahMnySn6B9jz5nFD/BwqZ0Gr/rd3Hk6VJiZBSNKR1aWk+yJ5d5qEF2eky 9/voFTy1dwzPnHc1/9+aX3a4W2zvJfGx6Ng0fFvVwQkhuCDnK2AJx1+bn1ooJA5UKtVJ EhUkluTKEbBGnhFamu9fQRL+ZjNUvdqYMmS+T+otU1T84Jw9ExD3U7Bn3kKRLQa4WYxF VZNlF/563t5pDR6eC3GJ9pVpxdbZWqNciSqYIlPWKn1UmGFilcDxd1JeBPFTgXwbARV5 fwZQ/jYihsLoaMFxs0uaOhan0KMTzjTmnknURbFyPzvsg+9eQRT/hhMevxIuiauwhvL5 L71A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671499; x=1791276299; 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=jVxHr521NDdsP0576c5KkwGFcCZcrMwIiK5zVjnjcKY=; b=OI3T9CjlaxfSrZ6sgS8X5lDxaHPZ3tw2mSCnixxu5tWcA2Y5zjpDeQoPadroGiQv+1 J98VsP9X/RuOiHLDRLSEw720OKxbGk4ZEpdzIykpF+/cNv8auV/EtbAGL9Z0S+uHj/QF 2j27+AT58KrK9ASgiUvF2NDR/ZbDFllPA8msPXUTlSLSsRd44o2MRpMrP6FU2jFu3cE4 mOs54/VXo1Ci1RRZQ00JMG9UFURp9QTJZTwvfU1169RXwopVaj84fzgZq7v8LyL9SMGA yWbEzjGm8eIdKGg4MRBtvc9PZIlvqvMqxwF7AerEeWJXDSwvWAAyCGEA2vbHVhU1RrCj 5LIA== X-Gm-Message-State: AFq9FYK+txT9omj5VE2R1bZdfli4KmFo3T6XiamtOoeuWbIkufaIK0bM JcW1WyDg+u9NkE1KD9d4bbgrpyJiuiMZKr0RNEud3pXmtWKvjrQM73WDF49vwv5r X-Gm-Gg: AYBFou2NOEARzpJ2siEGL3Ert9w6YLEpW5pWmPiHMA3A/63XXpycx+dNff8g3SBIVpf 2yEnZxmPvA+m3iRHWHGrwtl93mwUnjLMPPEEPbQ4FEUZgohPfdAVRpzs3qo/OxQRGDo3XrnOEst rBIWF0nWrIfAl2vE1PLUpk4pyVr6SdvUSuc6A+915lDXMPMwlbd9NbFFhF/NKEpzpKCgcqEpD0a zLDX5b8lwRoh6CwcwQaZeQuTqca9gnpYk7M4Zis21cyHbWY7OGGoyNtfYbGsHldOVVniSpPVtMx Vchj6pyhG/GB7QBtzLdEbrpxNPtjzCMPtzmpPFsbESil9imc6z0W+bZlrfQdb2dLTVSKHBWgTJ4 wv+Y4LKkApYauDJGMlYfoWTk4QC8TaSjx7ip7XA/Fq/VeqeDyoTk6y/gZcHoDswEG/RwDCGaByD WwKHDzzX5vvp+/WTdDiVz5g7TSbIEfS0Zl2fU1EqnyTv84xks4NNCemdVXdX51vrNXtR4oF0B1m yRNxbcg8pHLGsRWdVJgav1Fg2M= X-Received: by 2002:a17:90b:3909:b0:3a4:ad5c:d48a with SMTP id 98e67ed59e1d1-3a4ad5cdc9dmr296045a91.67.1790671498596; Tue, 29 Sep 2026 01:44:58 -0700 (PDT) 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 V18 10/13] xen-block: Update tracking iothread users with holder name Date: Tue, 29 Sep 2026 16:44:13 +0800 Message-ID: <20260929084416.1600199-11-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:3b::16; envelope-from=zhangckid@gmail.com; helo=mail-pz2-x16.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: 1790671615974158500 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.43.0 From nobody Mon Nov 23 05:10:02 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=1790671584; cv=none; d=zohomail.com; s=zohoarc; b=QYnhLk8c9SRKPAxn0HU0ezEFjzBAvaEkqERHJ/R95LlJ96XraXUSfWyRz5MfVsKsVBfDY7S9xvTe9eyvKQKR7967WtWddPQn1yz50fhj91Fv2u9EFaqpN/h8YPhvS3TSaX2QU4ly6tC6KzWYlBh7BvfzmqMMgRLEEFgLFSjVJmc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671584; 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=iPmOtLIRXjhOE0Iym+HCcfkISTVUslh658pj6SzglRU=; b=Tplu/QvInevmbc2Z/o9IZdTuDMARj1ZW/2BZM3E2kUMyNei/eM1MmLE+C2mESI9trwtAdJZ7e75NXx/CYxoXYUWftjusLNc9duCZlLxLstQYitx/MMfH7RLr46klIv7a0OmXa+3sQ70+gEPnwsbalHBfrpwvRjPCNwJmOsGD9/8= 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 1790671584635270.84885419489774; Tue, 29 Sep 2026 01:46:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTSd-0005xt-T0; Tue, 29 Sep 2026 04:45:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTST-0005rI-GO for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:45:06 -0400 Received: from mail-pj2-x2b.google.com ([2607:f8b0:4864:39::2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTSR-0003vf-So for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:45:05 -0400 Received: by mail-pj2-x2b.google.com with SMTP id 98e67ed59e1d1-3a49b6bb21eso409531a91.3 for ; Tue, 29 Sep 2026 01:45:03 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:45:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671502; x=1791276302; 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=iPmOtLIRXjhOE0Iym+HCcfkISTVUslh658pj6SzglRU=; b=kGU0RVFTlMmkoMqjmSBDUS6RRB4hijFhczI3IEOc3u2rhvCKrhM8Sew2KSPWm+o6XW VyCWA/ARvfHkt4boQ0lGmr1nv+Jy4nOA5N9DJYz0BFMPKvNLm1TcICh2Crbpagru73lt 58Jaq9xVmblkZ9aSV04AsZ5vKldGFLSaoajkN4+JoHGezWuaIxkKDBYxBXq5FMMDbdIL /adO4uiKY17PK/wI42Of5fPA3bdpV8Hp9wCNB7gwIAzauQFl8LSzvseAeT67Z8sZI6TY jayrkLdpZKWp98Y4pWwOX2OndQztY3peQTZfFNp+opVE1r6mheqaQ+rrpE+HbOi+zy4X jjuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671502; x=1791276302; 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=iPmOtLIRXjhOE0Iym+HCcfkISTVUslh658pj6SzglRU=; b=ynTuhb/4huXdQ9zc8d7ZsL6zoWAjDY7rPQtV0kkjX2yDd54qBltJQp53Xt9kO1MfGQ aUGTwSkRl1+Tbsy+ZDP9/N1AkRHJnsI+cS1NXez1TsMEiTTQet8MejlqBMBjZuJ8cCiL 0VBbNLK7NiV0ZvPyJCf1VQLEcjYyWwEws3xuNmtsCSuUr7VOCKHFjdsdR87YM3TiNlcA M2AvR2lgOspD1/U5gueNeVwhkKMCZV9JoE3leuc3zRIkOJkivn+zbLAd9wmSLQvBP/c6 3wVn1JHprkVq72kxw7fnLWEaEgbqIwkC5r0qZp+z1hTSR4LRaOBLj+rqQF0KGR/nCnpc wybg== X-Gm-Message-State: AFq9FYKAWjel4MfcSjFkECiG6giqiJA1aYWaJhV2vIJEvMumvsQmBbK3 Jch6KdUG7G8jexpwk6BEd7x7+czAmkszVUkw+YL6uMlCrfxKYfPosNdCRrJNXhAz X-Gm-Gg: AYBFou2AuDltv7b1acoC/M/XYShs6opxrY8BWA7Gh3RKvtigyf/FD7vc//akiLYXRit 1bL9TBaMQxondFuJb8YIMQps6lmB5PsJkV1NK7UEw/kRmKHJaXHUJPWQCB4GNKrecGTBC+vSe9W f9dn5Qgd6rX3WWESN9ijsv59+vVsjso8GNngs/wJ/TtZX01uRqoOx1VCnHZgrR8mXsJbKmGrKj8 lyutJxvBQv/BQiqMmjO1dNHv8clEH0lzzS7chESsoVgArCa1HXTfocxXOVZCtzHqdMOffN5F88g Z2nig8s7aXRJOOYrwPRQAtY5ZNFONRMPoaiI0tIalPBWZWSByrGPrPuxR8IqFupbzGUQdYynsfy 0u1+00XR18sKaVNyRz8l8s/z86VHkMEOyJ/Y7OSz3/JnT5Bj9M3onwHvHA+nCDqVGRoZj8xpFrQ v0TNZwmCmYdIwphJjVHmfAkLosjkM3xki3eOMYHYUK6Bi/goGSzvtvmcDlc0rmK0D2kdj+y2HNn /e6GQ6yuE3bzrExSG5JaAEKmtI= X-Received: by 2002:a17:90b:530d:b0:3a4:a370:d888 with SMTP id 98e67ed59e1d1-3a4a370f2cemr566728a91.20.1790671502235; Tue, 29 Sep 2026 01:45:02 -0700 (PDT) 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 V18 11/13] monitor/hmp: display IOThread holders Date: Tue, 29 Sep 2026 16:44:14 +0800 Message-ID: <20260929084416.1600199-12-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:39::2b; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x2b.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: 1790671585766158500 Content-Type: text/plain; charset="utf-8" Display holder information in info iothreads to aid manual debugging. Reviewed-by: Markus Armbruster Signed-off-by: Zhang Chen Reviewed-by: Stefan Hajnoczi --- 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.43.0 From nobody Mon Nov 23 05:10:02 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=1790671534; cv=none; d=zohomail.com; s=zohoarc; b=LKBdg+1sCkeEA0aUnMOQZ25f3Gr+DdOlVrkj5J9Jzb5dTed/tMYB4rO155bUX0Vr2J8T48H2s4/N0I7lD2yfzNf7QZdn3+g9bRqFBVeFLgeqsl4wdUbI6mC9U0woRPWObyVYQycQQTSDcjwX102LKReqs0vv6t9eSzF+NCrguZI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671534; 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=tSwqmMZQEjC0Trxhzu56bKX57rueCWfNPzUcXcWo2UQ=; b=d2wwoOQDUKkRTOF3bBcYoqCiPp8RUfYAF/SOnemULD74nODxbP3o1IHuRmtbmzhZDYoASBxAh9Zr046c2iKXkIIvvuwS11m3yJOp6d0Ls2WwEzUBYiY+qBJ+oDh1C7UGeS+n4Qi5e3OtdEPOuAtdQdohxP2apuZCpEy0IH9sxCM= 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 1790671534620133.17131459391135; Tue, 29 Sep 2026 01:45:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTSg-0005zi-PN; Tue, 29 Sep 2026 04:45:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTSa-0005sU-DY for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:45:12 -0400 Received: from mail-pj2-x0e.google.com ([2607:f8b0:4864:39::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTSY-00041C-4h for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:45:11 -0400 Received: by mail-pj2-x0e.google.com with SMTP id 98e67ed59e1d1-398cb5615deso3167912a91.3 for ; Tue, 29 Sep 2026 01:45:09 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:45:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671509; x=1791276309; 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=tSwqmMZQEjC0Trxhzu56bKX57rueCWfNPzUcXcWo2UQ=; b=dBu0uPbHWVv/tQ0nvM+00kebRaUbFTxmmip88Mm8ZL0z+X61jnqZ5PHOjZX9nzB2dj e5vH3ScUDOIoT8yRJm31MHyuaw71qaccckY3MDptloCWHFt/mUx+ij/rpx0pnDR1xlV2 sHbksm4/XI+rrBIUnn5FKu3v2rm6C8Dd0hs59tBYb/LNi+Xm24lTQaTc4ONb7XPTN+OH GZgb4WndCFKBYWFK35F7BDoxS7e+QK0azMiPSnv9EuACFcNkwRWZzF9euTDcMg/JY4HF nz6zPoP3eIK8YpUnKQNT5YpXziqe3Vxkx1CwQzrkHForJ5OWRB+6QzEf22fHbM2oyktb zM5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671509; x=1791276309; 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=tSwqmMZQEjC0Trxhzu56bKX57rueCWfNPzUcXcWo2UQ=; b=Zq6yN+kIaWu2ED0WwBEQ4D6JycRw0s2RwAN58t/M7/fVo1sl3zy7x51a2wYcCn4T/R dY6XwDkVY1jD57FXfCWzGrNUcRqPmR4X3F83kNNUkLzMr47p+s3QuOsn/vkgnMUYPUCc KDuyyoEefX6f1aTJUiBw7+oPpb9b8OZtlHyZH7FSLeTbzKHUlmUCZZCwRBGWUAAl+kr4 vD8cG79yKAhHFFBerYL9Na/aPe2mFKWNFHg02RlCwoyeGsxrhKqBo6RoJ5RoDDWzK/5e rUDpX6BSLM011iL7GGmIlxVag0MF6qmiVxc8T88t2+VnKb142KLKIFX9dsviT4KR2itc aL4Q== X-Gm-Message-State: AFq9FYJ2dYjHDEYo74JFFkAmxCynIRqyZ0ZoUWPDWi/uhnGL+IASRlsA r1jvM7ECrKJH5ljd4eywkkDQpe9TR4iW6lHOyqqD9tzLM4pHbomgyLgf3SppjzWA X-Gm-Gg: AYBFou1pWMFXLIXojPkmLJHLIgn/3UYV/mUNURTGJFFRn//AfnEzjN0jCjotUReidoZ wNAI0oGha3F9VAB+EyV8iZIJl2yjvqVS2x/125QEepH+YUGkuxE+rhfnJwK7eTBvPyUz4bE//aa Kc5diO6CWpemxpFXEUvxmGCUqwmoRvCgffJwgxsyJ90Ag601n6mvEhAk7IOZHjSkEtgJtZuE5zm L8ZJr79ObBEZYluuaCuRDIsqomLP3hnd96T0FhChZKQgunSEMSieXUl0qy+VyWZ47uwWDEl3tKP ts6dyYsAssLIgfIT96Pc8U0uT0NbJD8ryxjFEr/VnYuqHQAPwbnqmF+TG9ycgZIMVUWjFCTkWhj VuurodGMv5mAY7Lh4BabqCQO9VovxYOK13K6aKH3Ft5Fjm7nZ8Q6yBw8BRbPRdd5xeZ3ZCjDt1d whZRnbZtZCumtDh43ezVSwJJHNvjVwr4K0mr9Zebb6W/RmDhBFIy99PLHAMZexoF+QAEhuFzH/9 /IGQxqRTls2gJfquvKpAjU/xCOu X-Received: by 2002:a17:90b:1f8a:b0:39e:6a82:afda with SMTP id 98e67ed59e1d1-3a098fe651cmr11916679a91.44.1790671508643; Tue, 29 Sep 2026 01:45:08 -0700 (PDT) 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 V18 12/13] iothread: make legacy AioContext getter explicitly unsafe Date: Tue, 29 Sep 2026 16:44:15 +0800 Message-ID: <20260929084416.1600199-13-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:39::e; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x0e.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: 1790671535675158500 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 6e86c6262f..3bd32feb39 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3683,7 +3683,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 5a4291a2f0..28460afb3f 100644 --- a/iothread.c +++ b/iothread.c @@ -422,7 +422,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.43.0 From nobody Mon Nov 23 05:10:02 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=1790671535; cv=none; d=zohomail.com; s=zohoarc; b=HwLzblbXJ/GmWOce1MA9/QUolEA/4FCFGA6xHWZRzqDKMQea75JRd9gWfNavqW3YsEK57w+nyZI4/O+2J5dA1jisYl+NUsnzG4RV8SLy8T9Lb4NtxDY1Qci+806tnWbgzDKkZxIqJo3Rs/OQ3D8CygUH8e4R9fViCqRbBdj6GBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790671535; 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=8HA0URDqzo40kYUGgC9BRkSZVXz0Ja8B7EI4ZLWVnOM=; b=YmX7Jp8zbj6iteg9cGmsIROXagNJsoP+qdq6qpwU3UXAVS6w3jNqndRAlm7kAwz9quuy6VBUBtAW0/uennOmdU3flxcloXKPYfmea2ZKwPbvGTjOXKHenCmz45Z7jD9w2tLZgiOGOXt6PtMiZC8VgtzcXaNHCbl8YoMVdcXPJuY= 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 1790671535766821.734343752479; Tue, 29 Sep 2026 01:45:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBTSk-000605-62; Tue, 29 Sep 2026 04:45:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBTSd-0005y4-VP for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:45:16 -0400 Received: from mail-pj2-x0f.google.com ([2607:f8b0:4864:39::f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBTSb-00041W-JI for qemu-devel@nongnu.org; Tue, 29 Sep 2026 04:45:15 -0400 Received: by mail-pj2-x0f.google.com with SMTP id 98e67ed59e1d1-3a49573b8bdso597313a91.2 for ; Tue, 29 Sep 2026 01:45:13 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a497e942eesm5163120a91.4.2026.09.29.01.45.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 01:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790671512; x=1791276312; 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=8HA0URDqzo40kYUGgC9BRkSZVXz0Ja8B7EI4ZLWVnOM=; b=LNCICU75VZ6ujzrZNCPjnB5fzv28rYCnWwQiXRJaFg4BofYE8hWwiLqronRxDFVeKJ 99kj9pYt/73nthuBQQyN6TxcbS/5AXtHSMPYAFC8SbPsODfh9Tge+CgzcjPnlFt2zaSl qXWMtOe25i9YbfhAlCOd9eHsLJ/YAUCICDtX9yFPxI/n3O/FoqD7UiSyeo5DKq66Nrs/ u6Oq2tNSdMbTg5gqfQLv7en1geCwQOJFJQHXqKoPkl/5bL9hYbWwZguMzo42Oodz5tPT Am19Wir7xMA41M3mqiQsSIySDWXRScmr7wj+284WqMras09XQm0N7XUK/XqGu9oBC9Ij wdiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790671512; x=1791276312; 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=8HA0URDqzo40kYUGgC9BRkSZVXz0Ja8B7EI4ZLWVnOM=; b=x2LBdtkRI3lfenmYnzPjORwPEMTl/tIGpbt1LFXtr+xfnvD4nzi+deY3e7CCflzVEW 9bEhzYTpeBtXGYYF5gj5tUkbb0D8eSnx9Ajbe31P57ghY0GHXXMfKc87dykYKoqSqESm 7vrZn/8q7yAA4IS5LdIgh3dtig7WQSszT6kA/bA4DqdIGkyf7lvX5w3c4mx3aGyV0EcM 3pnmSDErD0rsjz6jV9JsOd0zW7xtojMkkat3jCXLUaLVOzVArZiu7oVPo9Z/WlGJTj5S p2pBc8tPmvW1/e8kukZAOejv3m2oWmRyMN+OjzMjnvjH+qqN47cJfGFZ6VpLO71uqMi9 jv6Q== X-Gm-Message-State: AFq9FYJ+LkqNLLlHfK5yq3Cj5kKD92cnVUYtXkcfQBMDESc9sEwdyJpi CKPm9qCgy/Bf6AHguPB8XwlMxCMCglcz2/VsaQhESoRZZcfVe240Fzcif7+NbCVR X-Gm-Gg: AYBFou1Aefxx/KzP2xt3z6VB+L1+eZZuHMIH5EtBRUl9oHztlfU4stCw0YBqrmZLp05 5fu/QuCxPQXu3A4pvcEifxa6+WT+inG2nm2jtDzbTapFJf7Zu86X6fHFsLcr33dgZ0zjOIJi4qP jh37fThDg8MvnL53ftA1w5eD0IQWS1NMZ+XKQjWjEDweteXt2NaU3pG2PASPdaLyc19EHVFeWBt UjTYchKEv1o5DHDA5S+jTMuSJJePecCoc9fmDXL1YWC4I+k2sZuzBqEsoCiWK2Alp0FQ7EKqYMB BwhKOcMbQOSIJSy4tBGzqf+n8C4q2eRvlJVY17x7USHRtYeL+MxN/M9a8tbn/pHYtB9hJrS+/5g I0qmBX/ERQlBB3lOKfQOmmtxAkRy+N5Wn0joz4JrxbRiguBCZbG8VjywiFux07e/eoWM18meAEO PkUQ8doimW+o9D2uE1tDra2J/YIjX1D/NkUznmewAyfAtVYT7BpTk6+TXQdbL5UybldWTb6P1so 98mMdOWw24w2ls5DdLOzkA5TII= X-Received: by 2002:a17:90a:ce:b0:3a0:4146:2955 with SMTP id 98e67ed59e1d1-3a0bb6596f3mr6702873a91.61.1790671512139; Tue, 29 Sep 2026 01:45:12 -0700 (PDT) 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 V18 13/13] tests/unit/iothread: update AioContext ref/put helpers Date: Tue, 29 Sep 2026 16:44:16 +0800 Message-ID: <20260929084416.1600199-14-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260929084416.1600199-1-zhangckid@gmail.com> References: <20260929084416.1600199-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:39::f; envelope-from=zhangckid@gmail.com; helo=mail-pj2-x0f.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: 1790671537789158500 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(). Signed-off-by: Zhang Chen Reviewed-by: Stefan Hajnoczi --- 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.43.0