From nobody Mon Nov 23 04:18:27 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=1793179725; cv=none; d=zohomail.com; s=zohoarc; b=lrER4u/cZt7IXLhfzcdThp5HQRWXFt4eu+V6ktUbXYvoPCGQUZhfjkER/ag9ISIgBnWljlm1Dl+hGbORl/naEIXpSCsYjk4LCJaPzYk78HCMU4ieC9IQrgmvURpz0ngzfekMH4w3IAOQKpfdYMp/b6OZelTP9LzmFxW04eDBEcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179725; 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=Krd7grsLTJX6cCkk0wUoy4Fk0r9YaYiEi+tyS6I7OD0=; b=PdcQUE/OJI+yLYzeb6t4Ygvrt0Rthh4vrIThOXMhCFsa4hfNSGZHXv4T/s3/P5x9plkZfMlMHuO83ACk1Waq8rROeJNRZT1w7Ijzy8ODfAINjZvehxE8A66TZZ5uloEZWmDYfGomfPp0hGjyINBElkipiDPQqmyxTFZnjZDfHSU= 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 1793179725698122.63994276523727; Wed, 28 Oct 2026 02:28:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzvd-0006t8-63; Wed, 28 Oct 2026 05:26:41 -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 1xLzvW-0006rw-R0 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:36 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzvU-0006ev-Mo for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:34 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2e95bd1c14cso5893165ad.2 for ; Wed, 28 Oct 2026 02:26:32 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:26:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179591; x=1793784391; 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=Krd7grsLTJX6cCkk0wUoy4Fk0r9YaYiEi+tyS6I7OD0=; b=jTyvbUG4Gf1gWsiMNfartB7z+0tBvKwfqy4pMwq1zXF/uhsdhCJtxg7VgD3/53S4Ol EJsHJwvguWvsLTRNrX4mrySn85V5X3uTtTgLjloyOkWDk0AntoxEqzSIrmc0tL57APIP O7pYmjsdhKF0vo8QeOCLJpNiMad5zU3jOn7PeekEqb5BTOvfv406b8Cj24L2icZlMlIh gx876nmjDjnqsu4aoQ+JUoycSeRK0mlGk6rzFGtIIZBmxoR6+cczFmk8x2v0H8C8Ld/p SUX6v8E6ibNOoakbrt5Y1ei6UNSKaGsHFHH4jGlm3hhn9esu5YFh86aC2Z3EqU7P1pwf q/9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179591; x=1793784391; 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=Krd7grsLTJX6cCkk0wUoy4Fk0r9YaYiEi+tyS6I7OD0=; b=QMtrGJba7BhZRkjwQ3UEaA6dZFxvYIEQNx1iFKg7lsK3+fELsXypHD2pTSPKKnQD0+ CFG5gUbPi854VIQ2Cvys66tVTDQnypuDAiAZ8u2VnQLoCGuR/L6hD9n1kEz7SwO61Wt3 BGcfJ3uapD1Hc3pRob2/sgEbd6V0ip8h5VfylXg1C6zSMWX16C5zjNHveZhreALLutgn Q9s9e2DBPV4y80GplVjnDt6j6itpVZHqZWEf+M+VWyOWPAL6/+zSj04sOi8OyJaf2kAA tE5pfWFtAXFlFC4RM5idGqyXzh4DYWbL4mTYUaQ353vs8apFI5/nBAzfVgGVBMcEEXfu kAXg== X-Gm-Message-State: AFq9FYITiDNpq11Wfi5FLcwEcrXIH7UxHuvoUKfVE+MWpwJzpTFRujfK mM3OI2cM4wMUjkAAFqJ9atNRosnBipMdZ8X2iv2GxCjaa3JJ0Sj05SSvWqHyScmB X-Gm-Gg: AYBFou33bHFkDk8Gx1SMFtNJWSn1KsTb9Bx2s3LzLnBZ5tBsW2pThkuK7hNpOQ4gGDj oGkh7ZLrvPTRExH/G14NZEOo/eQ60HbOLzKTb2+SQZjtBlwhSlkCPE5lPJBDNQ0QxCTj+QVX2uc C9Pu1FbrDWJ3YeGgm6SFNe5OLROdIUCP4SWgUnXU6Qh7md4T/Ok8Tqj3EdBA41wG8Xs+wq9WPJV HMNyrb2oBgpRBA21eU/QcQIdvyTk/kKJB7WObzKWvXID9PVJoZzhHG8SNAW6WRuovsaQlRq1DJH fHhypY/0jS75OathNVcLyTFRaLiFDQ5arMQ00042EH4BqJWmayT6AMLCnzE0Go7Iwf8b4iWVAUT 751opVWjmOOs4LZhKxGK/cunYCZpkvYALtt8gYi5gpPyF+1nbhX/wvyfznLcmpCOcg78tQCh0qW NpNS12ltKIWDNhD6kyGRbRMo1WpaqOLfpFajIIvpnF3OqOgeQAGKiqRv6BUQHiN/hsJlwPG5/KL 8xsLgeiIq03/i7RckdhjKt/7QPkfZeuU/hOC3GPL/bWhoKH6DfBKc5Fvbv8+zYMOR4O8gH+0Q4c EOLtSab/VUkGU3b3aCKdBZD37sOnWJSQUIw7Bc+9EEyhZaDRMbLyOW6wqf0= X-Received: by 2002:a17:903:3708:b0:2e9:3c24:999 with SMTP id d9443c01a7336-2eb0058e067mr18345325ad.40.1793179591006; Wed, 28 Oct 2026 02:26:31 -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 V19 01/14] iothread: introduce holder tracking Date: Wed, 28 Oct 2026 17:26:06 +0800 Message-ID: <20261028092619.1654474-2-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793179728910154100 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 Reviewed-by to patch 14 in the next revision. Please let me know if --- 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 4469e44d05..4a3eff4685 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -64,6 +64,55 @@ ## { 'command': 'query-name', 'returns': 'NameInfo', 'allow-preconfig': true } =20 +## +# @IOThreadHolderBlockExport: +# +# @export-id: The unique block export identifier. +# +# Since: 11.2 +# +## +{ 'struct': 'IOThreadHolderBlockExport', + 'data': { 'export-id': 'str' } } + +## +# @IOThreadHolderQomObject: +# +# @qom-path: Path to the object in the QOM tree. +# +# Since: 11.2 +# +## +{ 'struct': 'IOThreadHolderQomObject', + 'data': { 'qom-path': 'str' } } + +## +# @IOThreadHolderKind: +# +# @block-export: A block export. +# @qom-object: A QOM object. +# +# Since: 11.2 +## +{ 'enum': 'IOThreadHolderKind', + 'data': [ 'block-export', 'qom-object' ] } + +## +# @IOThreadHolder: +# +# The block export or QOM object holding the iothread. +# +# @type: the kind of iothread holder. +# +# Since: 11.2 +## +{ 'union': 'IOThreadHolder', + 'base': { 'type': 'IOThreadHolderKind' }, + 'discriminator': 'type', + 'data': { + 'block-export': 'IOThreadHolderBlockExport', + 'qom-object': 'IOThreadHolderQomObject' } } + ## # @IOThreadInfo: # Information about an iothread @@ -72,6 +121,10 @@ # # @thread-id: ID of the underlying host thread # +# @holders: the QOM objects or block exports currently holding this +# iothread. When a holder is detached or destroyed, it is removed +# from this list. (Since 11.2) +# # @poll-max-ns: maximum polling time in ns, 0 means polling is # disabled (since 2.9) # @@ -94,6 +147,7 @@ { 'struct': 'IOThreadInfo', 'data': {'id': 'str', 'thread-id': 'int', + 'holders': ['IOThreadHolder'], 'poll-max-ns': 'int', 'poll-grow': 'int', 'poll-shrink': 'int', @@ -117,20 +171,36 @@ # -> { "execute": "query-iothreads" } # <- { "return": [ # { -# "id":"iothread0", -# "thread-id":3134, -# "poll-max-ns":32768, -# "poll-grow":0, -# "poll-shrink":0, -# "aio-max-batch":0 +# "id": "iothread0", +# "thread-id": 3134, +# "holders": [ +# { +# "qom-path": "/machine/peripheral/blk1/virtio-bac= kend", +# "type": "qom-object" +# }, +# { +# "qom-path": "/machine/peripheral/blk2/virtio-bac= kend", +# "type": "qom-object" +# } +# ], +# "poll-max-ns": 32768, +# "poll-grow": 0, +# "poll-shrink": 0, +# "aio-max-batch": 0 # }, # { -# "id":"iothread1", -# "thread-id":3135, -# "poll-max-ns":32768, -# "poll-grow":0, -# "poll-shrink":0, -# "aio-max-batch":0 +# "id": "iothread1", +# "thread-id": 3135, +# "holders": [ +# { +# "export-id": "export0", +# "type": "block-export" +# } +# ], +# "poll-max-ns": 32768, +# "poll-grow": 0, +# "poll-shrink": 0, +# "aio-max-batch": 0 # } # ] # } --=20 2.53.0 From nobody Mon Nov 23 04:18:27 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=1793179741; cv=none; d=zohomail.com; s=zohoarc; b=LQL2hiCRdT+lcsBx6MaQZqDoa+NLM+DaL15+NchirxYy2jVLDpqxD8GxRTQUy4pHPOkm+obtSBeIoXd4kqDYLzaLhGeoVp6GGttExfoVxLUBIwJX4j/P4MrRFaaItzoq0GFZ1qnMcMMvLFA6M7DX2Eq/EJaYwycX61CGHVhHd4k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179741; 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=rIUTlELGNNNkAoHqgdJyqZqXtRy4dZzDoVcLYBQBIBU=; b=TMmj0VfK3oTAMZCM7O90BIP7FjhYi/coUZfglOASfvc/uhkJBV0UG9jJ90fjDO6WtMOZHiQf+rYaZEPhbOFZSiZY3KUfkc65EuyJVkCsq8dUTkQTUIJIe9h7vtJKH2cYZxZN46ATAViINyonIiMVwOHoFF68mWsEq6Q+e4nG9/M= 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 1793179741018657.7830909402734; Wed, 28 Oct 2026 02:29:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzvd-0006tA-Eb; Wed, 28 Oct 2026 05:26:41 -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 1xLzvb-0006sX-4W for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:40 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzvZ-0006fR-Dl for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:38 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2e812e2b31bso3883645ad.3 for ; Wed, 28 Oct 2026 02:26:36 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.26.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179595; x=1793784395; 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=rIUTlELGNNNkAoHqgdJyqZqXtRy4dZzDoVcLYBQBIBU=; b=TG11WZBC+IWee9ofRVJfX9/TldRBu2LLalWRPxH0rvkACvPEpOTdRHdJOBWKJAK5+D 0RCkVhMpwzwqhkknWvOdED9gmJTC2PKxv0eEc+hiC443ZecnFgeHVWhYEzhmNZ7A/DKi rRIQ7HLx8L6YG6HGOlqFzgv0682a8lF4XDqmowtiWngt85g87oJhreVteGVfW9cegfp9 xto0MseiQsnLj4Gd13t1P3hY2MUGO9TmvVkWyges2PFl3ZmNMOSMd+7byEkV+qYKdBPC 9jHrRNZkLfNLjr4QP27Qs6tIB/AXgGC9SZ9qyYekyfbhyMnSWRK/HT6gEWc3iir7F4nU Rg/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179595; x=1793784395; 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=rIUTlELGNNNkAoHqgdJyqZqXtRy4dZzDoVcLYBQBIBU=; b=EUT5lBU4lAghoNycQ3wmVCi0S5H64YCSu0B58MntHhm9UOPpHSV9aD0f0Z5tXBhp76 K+QG2TWe5pbfkvHbsmQXAQt7R3/zLz0HaOB4LZzhrIGfL9bXXDtptIvMafsGVD0M8r2Q 9s5lw2nF98BBs3/ehedkQsJ+pz6XzmtwH7bczR3zaYRSdxtiv1izP5f6WQrkJ7Gr+SWI vGyIbT+Dg1eFiZ/FlRpVl5U/Nc19ONqAmPBnqhzFhfMhO67RDNu/FSD0RPSfoRmPIbuc jlP0H1KG35bSWy6q195PtZBGQijMLYfrolb9LXYfSMieWIdp1JxYZpwKdb4PE90iHwmh WM3w== X-Gm-Message-State: AFq9FYL/LCCFb2l7qfkKwIsmyLui1/Jq1jwo18h6GI2nVsXgJT67QAlD OAWJ5qGiTUsAKskYlzHXvlsA/LqoWYjpfqBa9fkSAU8WI7KuKjMzUHU8FEN3YkL7 X-Gm-Gg: AYBFou0Utrt0T1YxGpPr2HBTy25Ly3m0IfSCE64EqQPxtWoBIUd5AFeNY8uqSGvn3yP xghiProBXKg+G0/orh/6Jc4Ja4oB/K+10zd96Ibc7IL0z5gamIH77sx7WpZC30hNOWDAMQyJY/1 vGEJsUdR7MkGUzNnFKlO/YiDMd7l71kiVE3ZWrfeLvgS3+lsB9wkZKturBptqyjn+YDH1B4d7j4 X3zBp87KIwih7OEW3Mc6IKLqv/zYOetFjp9klQlhTaGv/6uuBKtQ0vlO3jL/lZoiDVIWvFBWO/A 0yyPLjWcBoZp9l0Dx0u6WmT4LS/Vcp7PYx2+EOx5Rgn2M7544i/uy2EQlayiyhU+wY8uy68yg0/ zmnff980pS86KOXs7BFi7aVFX/Y/rWKBG673z3q8zd7l2CMd0Vg040TRlo3DOApkjbX+fpLNRfu URPSaVWn23KidacBep6QmtRB4RNzOARVsvdJHRjQ4QCmVjbMYihisFHoXa6IDSmdHlkymrmVyGD mlT07kE3uuhxUsHWPaQX7mpsUFRnI1tYmeqhDY2FWTWIh9aWi+yp+7ll3yC2lK/hfyCNkgvVRrD qUAPQrlmPkZAfMDEvfP4Zk1TFXD8j8/XfB4qG+wsd00+pTbTt/JHKosse/dMEJt2PjkJhC9JCmr kf3Fj X-Received: by 2002:a17:902:f707:b0:2ea:fcdf:9260 with SMTP id d9443c01a7336-2eb0042efb8mr18677135ad.53.1793179594916; Wed, 28 Oct 2026 02:26:34 -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 V19 02/14] iothread: add holder-aware AioContext accessors Date: Wed, 28 Oct 2026 17:26:07 +0800 Message-ID: <20261028092619.1654474-3-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793179743020154100 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 Reviewed-by to patch 14 in the next revision. Please let me know if --- 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.53.0 From nobody Mon Nov 23 04:18:27 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=1793179643; cv=none; d=zohomail.com; s=zohoarc; b=dTQ7G4bhDRj76dSlelidQNapSpI5Y0nzY3UWY0FUxUcAWE2H/mBhdDStdNue6TF0CEDgEsdd/5z2pGrQ6lLOk0BsDjYCdHtP8i4QrDWZucsKSWIQ28+yqaihIeGCaiuuZP20PekSdiVDFzfJ+tHH5ZREkREISs0hdeNrJs+pEa0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179643; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Z8x/Kjb3LFSKjH4X1E0LG5Wat9YzKYyvVsrKHxncOxM=; b=Gzt4JetSgxreXTzQUqmnBEmzdbFyeuI3dQibdOLsko4sH/MhNDr7YomQ5aQezoj+oiC3d2VUc63Zze3U5hyhT3pjH52zHd3tkr8HlHxygjU4vJ80612oAhsrb5F6L4OG7ETmXe/3W1lG6pkBDH4NFmQjgICbwIzvHZQ8uzFwtVo= 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 1793179643552485.15322296242164; Wed, 28 Oct 2026 02:27:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzvf-0006u4-NN; Wed, 28 Oct 2026 05:26:43 -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 1xLzvd-0006tD-UJ for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:42 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzvb-0006fq-Rr for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:41 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-2e7e742a2c7so4972145ad.0 for ; Wed, 28 Oct 2026 02:26:39 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179598; x=1793784398; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Z8x/Kjb3LFSKjH4X1E0LG5Wat9YzKYyvVsrKHxncOxM=; b=Oma58YCgOhIU3j2ihpDbk1gQpjISe/K/J6JDlVhexGDurkKUiTX2QMCRHODZee8TCe tw6TQeM57gPcuxzuBZrZcLhiT3rsgYAEXD0FXBpqHyzuXW2mPDTArjzz3bSijTWO8bfx UaLr3sKsRPxLuM+hTthyS300JYKNStiTUeW6t4i53uXFLEbSodo9sDDC2bLD28iZWvju Dsa0+lREpvo7d/2MxnFQuKYVhkHfe/tWxwmTddraPrErLfvsG0ufXDWRrRUaht335/qX +tdlqzbhpzxXolSrIDNSNO+LCV2XRxuMPcLCLTfrU+rHOknpu5K4MGSbqCd9RzyJWots FW5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179598; x=1793784398; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Z8x/Kjb3LFSKjH4X1E0LG5Wat9YzKYyvVsrKHxncOxM=; b=0kyjfYahiReJCOhKbm+qBhMq8pYBgTkZo4o5ypiptpPYh56VmSHfYumxMVtQU0dGcH xtyBq0puvTL5j3f4XqDxmBBTW+qcerNRPrwkrX5LZxr6A2j5IWPpGHVhRLrT+5NrxdR+ CTnWth0oBlaFZxtAjxWmuVxhgFsU3zt9lFENbhM6xA/ai5QDlE+twv3EiL9XVDQMjvhD N5lWkntA7vkZEDYXgrYcLR9n1VLlHc4roy8+dB7ijrgAoD6X8CbsqFYtWeBvaaRMEZuG 1t6TEgG4f+2puArb+yZJQfi9Ev5Cd9c6eYHCmO8BRURuikfAbq2Zpb/CD4EGhl1mG5Yj af2w== X-Gm-Message-State: AFq9FYLaFlBjAK/8b5R4wCKjR4cquhBiECxe+7qB48+M0BOGnoSGa9Qv LhK+f4rswWq6LQdqMB/smHmVcsXcGOt+TFhEDiETTYo1C1/NRJSvDcFvbvudA/Rj X-Gm-Gg: AYBFou3UcO1LhEYbkXxmbcFKyhgWoqHDTFnPIULPm12zVzteD5d2n+pqk4RvvgKqb5K rOZKmGPxhMDolI19i9fJPohAqQzlGFF5kLaKDRnUh9VsIvQIApFDNDst28p0HoprT2ngtcRnAhS f1Taqxd1L1+L9mBAPK7yNUEmgeEHN3oxmgKRi4mywPfwglhRe0NC2omZXpDS6leCQAokKn2NSlS BnOcUgaMicOUO9ZIPppkNfs85pqiVK3nCK7HtpnwioSH+lgKmcDV4Uikj8FRqiqh7n/WL2qtRkD thkW2px4810CNIwExHsTHZzlBRuz75xrZHdPD5N+AdGbxahLHvXMFZs40tlVoVf0aBvVJO4eARZ uBU3ETCnzA7OBklWLzjNjNO4zYw547YIRszNDKTWEqOinL9afYOOj3GOtvwKrN7PPL0V5057SE0 o1c2+brOldaiC0nMRlub5RJyTJ6/vvTUNb3SUfvmflR6gMRKfWd8RopqKq0YEVlVoXkotpGNRWq 2Nt/MJAFJmVO7+oyDe3YjgSXZtwt4BA5P5ccOENDp7iXjZV7zx/hM47VApaohogcC7/ZYCZGABS q+QZ/jBghWeWCGWYaoINlkYSrpoQekS1SY9bDd1Z4S4Ct+zS77ZDpICsPxP5+OHDK/9YxFrsvmc et0G2 X-Received: by 2002:a17:903:2446:b0:2dd:c053:b9cb with SMTP id d9443c01a7336-2eb074e2b94mr5088905ad.28.1793179598134; Wed, 28 Oct 2026 02:26: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 V19 03/14] block/export: track IOThread references Date: Wed, 28 Oct 2026 17:26:08 +0800 Message-ID: <20261028092619.1654474-4-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x633.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: 1793179645558154100 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 Reviewed-by to patch 14 in the next revision. Please let me know if --- block/export/export.c | 62 ++++++++++++++++++++++++++++++++++++------ include/block/export.h | 5 ++++ 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index b733f269f3..0e019545ef 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -15,7 +15,6 @@ =20 #include "block/block.h" #include "system/block-backend.h" -#include "system/iothread.h" #include "block/export.h" #include "block/fuse.h" #include "block/nbd.h" @@ -72,6 +71,32 @@ static const BlockExportDriver *blk_exp_find_driver(Bloc= kExportType type) return NULL; } =20 +static void init_iothreads(const char *holder_id, IOThread **iothreads, + size_t num_iothreads, AioContext **aio_ctxs) +{ + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_id =3D (char *)holder_id, + }; + + for (size_t i =3D 0; i < num_iothreads; i++) { + aio_ctxs[i] =3D iothread_ref_and_get_aio_context(iothreads[i], &ho= lder); + } +} + +static void cleanup_iothreads(const char *holder_id, IOThread **iothreads, + size_t num_iothreads) +{ + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_id =3D (char *)holder_id, + }; + + for (size_t i =3D 0; i < num_iothreads; i++) { + iothread_unref_and_put_aio_context(iothreads[i], &holder); + } +} + BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) { bool fixed_iothread =3D export->has_fixed_iothread && export->fixed_io= thread; @@ -85,6 +110,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Err= or **errp) AioContext *ctx; AioContext **multithread_ctxs =3D NULL; size_t multithread_count =3D 0; + g_autofree IOThread **local_iothreads =3D NULL; + size_t iothread_count =3D 0; uint64_t perm; int ret; =20 @@ -139,7 +166,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) goto fail; } =20 - new_ctx =3D iothread_get_aio_context(iothread); + local_iothreads =3D g_new0(IOThread *, 1); + local_iothreads[0] =3D iothread; + init_iothreads(export->id, local_iothreads, 1, &new_ctx); + iothread_count =3D 1; =20 /* Ignore errors with fixed-iothread=3Dfalse */ set_context_errp =3D fixed_iothread ? errp : NULL; @@ -163,8 +193,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) return NULL; } =20 + local_iothreads =3D g_new0(IOThread *, multithread_count); multithread_ctxs =3D g_new(AioContext *, multithread_count); i =3D 0; + for (strList *e =3D iothread_list; e; e =3D e->next) { IOThread *iothread =3D iothread_by_id(e->value); =20 @@ -172,9 +204,12 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) error_setg(errp, "iothread \"%s\" not found", e->value); goto fail; } - multithread_ctxs[i++] =3D iothread_get_aio_context(iothread); + local_iothreads[i++] =3D iothread; } assert(i =3D=3D multithread_count); + init_iothreads(export->id, local_iothreads, multithread_count, + multithread_ctxs); + iothread_count =3D multithread_count; } =20 bdrv_graph_rdlock_main_loop(); @@ -225,12 +260,14 @@ BlockExport *blk_exp_add(BlockExportOptions *export, = Error **errp) assert(drv->instance_size >=3D sizeof(BlockExport)); exp =3D g_malloc0(drv->instance_size); *exp =3D (BlockExport) { - .drv =3D drv, - .refcount =3D 1, - .user_owned =3D true, - .id =3D g_strdup(export->id), - .ctx =3D ctx, - .blk =3D blk, + .drv =3D drv, + .refcount =3D 1, + .user_owned =3D true, + .id =3D g_strdup(export->id), + .ctx =3D ctx, + .blk =3D blk, + .iothreads =3D g_steal_pointer(&local_iothreads), + .iothread_count =3D iothread_count, }; =20 ret =3D drv->create(exp, export, multithread_ctxs, multithread_count, = errp); @@ -250,8 +287,12 @@ fail: blk_unref(blk); } if (exp) { + cleanup_iothreads(exp->id, exp->iothreads, exp->iothread_count); + g_free(exp->iothreads); g_free(exp->id); g_free(exp); + } else { + cleanup_iothreads(export->id, local_iothreads, iothread_count); } g_free(multithread_ctxs); return NULL; @@ -273,6 +314,9 @@ static void blk_exp_delete_bh(void *opaque) exp->drv->delete(exp); blk_set_dev_ops(exp->blk, NULL, NULL); blk_unref(exp->blk); + + cleanup_iothreads(exp->id, exp->iothreads, exp->iothread_count); + g_free(exp->iothreads); qapi_event_send_block_export_deleted(exp->id); g_free(exp->id); g_free(exp); diff --git a/include/block/export.h b/include/block/export.h index ca45da928c..ce8e4eb604 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -16,6 +16,7 @@ =20 #include "qapi/qapi-types-block-export.h" #include "qemu/queue.h" +#include "system/iothread.h" =20 typedef struct BlockExport BlockExport; =20 @@ -89,6 +90,10 @@ struct BlockExport { =20 /* List entry for block_exports */ QLIST_ENTRY(BlockExport) next; + + /* The IOThreads utilized by this specific block export */ + IOThread **iothreads; + size_t iothread_count; }; =20 BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp); --=20 2.53.0 From nobody Mon Nov 23 04:18:27 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=1793179666; cv=none; d=zohomail.com; s=zohoarc; b=Wt0g3rQiwi7dROEEshwhwXhENS3BtNQ0jtFsRDgOYXj+QzzfzPis3SBFtjIFulNtdD35rNC1x9/3iLVn4A2Wgj0AKtKpfexDjdotyAjPGO7Q5vhZllVxHByNrTiuFvAzW/WdKw5jOp1NYjQvyboKEIDgAqQTvwUm8dEQp+zBL80= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179666; 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=z6NPgdWLsRUq67VzDfdjGLEAOiiCTDpko8uhmoQSOs0=; b=jW7wqJmFoG2kb52U8NYHUtflfie0NNtehqp/0bjzF70bauaOdlXlu+X67jYCEHF5WnpAuIGJcnsN62DzbjjfTCaUV2RkisOwPYWHnk496nzjCNrYH3PXg+nDiVWea008GuYbvG9vzuMrXFhVeFVdWswRpGa8Fo0k6jM1tZ9MilU= 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 1793179666522241.13615110687715; Wed, 28 Oct 2026 02:27:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzvi-0006uU-Dz; Wed, 28 Oct 2026 05:26: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 1xLzvh-0006uG-8M for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:45 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzvf-0006gs-Av for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:44 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-2e977109392so3944485ad.0 for ; Wed, 28 Oct 2026 02:26:42 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179602; x=1793784402; 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=z6NPgdWLsRUq67VzDfdjGLEAOiiCTDpko8uhmoQSOs0=; b=TepfgaW2+q6hbVhRzqICJUfWUsiAaN54LHtSOwtGpwkfGU2bMxvVZvzmcCz/SbBmpr mIj86WBD1VtsW/XoPpAZW5eb/lzXmDYLythWOTsqKW/O/bSXZ0/9/kGJUGDGZAFru3xp oe4cdje17Q0a8YQITaOLebSVUtFaKO5SicVl8wVaiNGdp+bJf+UfS7fv6kZY7Uirt2Hw v3kuI8NUOgxQY0FFEz8UeLTVgnSANKmQYdK6ke1wU45E82Do+k0h1ozGx3sTaIUpAxWG V+WAGX0c4O87JhlGup/hOVV6yrdU/aY35xUaE7mx7eZnIc3uFO+50Qnsz1WlMJvNjf+E MY5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179602; x=1793784402; 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=z6NPgdWLsRUq67VzDfdjGLEAOiiCTDpko8uhmoQSOs0=; b=UDVKK09W8x3ygNVksjY5QpbYeK29SHrg1E7qIN24g5xhjodhnD2NneAjRaGH+N/T++ cqoQ8PT4ZJ9tHd4rvVGxE6WC8QJmV7qb8AafwuEqjJ54n2zadLrjb5PrjluFI7b6afji z17TE0a4NrZbFwRdP4Wg3htZHaOLR9S1xnuhK+3Nwtkjh/yI/IIqX/cZJSs3GPKrnJ6h LRwt7VLDDCSAexiQeODH8LrZD4M6Ohf+0Up+uN+kBeoQoBmR+N1qcKQ0+07kBvccTRtQ 8PmV89533NG1dIY0FRjAv0bypRKN1dwwI6oDgv3rL0rqqHoX/f5l10DegGgOEY9KJ7WA 4u3g== X-Gm-Message-State: AFq9FYKpdsoPg76n5Xt+gZJh58at4yGSwF1tObtmYn70bfFKE+lSWWQU aWYja+VQRPBH+FxrydfQhAp7IyBIGeYjV8/BmjjdyTjfxRPf54+p1YoN16QS28EI X-Gm-Gg: AYBFou3N+L5E4DimvI1me6VZjfZRHgKPxq4YekM4qST6FugcF9f9ca2vymKjcGn4Z3K dFxbWXXA3zD9eHDGtFRDVm1FWJTc5YaKJhstiX0kcwUMJuMLojFEvGq+koHYoVNrZvPQkeozlrx 3/yT+GGMQlBPH/Sz2U+oV31aedO7gL5E1N1Hjh+eel9Qxeg3JqD/C+OTI6Wrz3/ZxWYntD1Zwl0 OPPC4F9LAnbsug2aO4S+u8bw/JpWgjWaWdI5Fa1Y0v+765m0Zvw1uMKdPhkFlSesJEzYDpLuWsb YMO56wRxquxnyELJyzThHb2r8bDSW3A+2Iwc4wrtfFlx2brnHQ74qs2ZF5gE591I8XZUfo2shck QyL+Y9Og9uEJOuO2mSoyXrwRBHOXZKk1MtrINqetGf3FMyET7pEbEaal3MsXZWd/9jx9hVwms70 OjgbC5ik1/VawFUulzlEgXyUXKfAf3pRXKlVchAN5Qhnqaoc5OwuNJuxFFB4OYEh2p3Nt1pjAyx CErtFFX2LAR/76YbPe5Q02vHPVFUsJk8tsaQHGhCqJ3BO09vl6ozZIxLXzqqhgzvwGw4aZsPzto RHG783sAU4ISq4pcI+Jc2LpO7MLGfHYtfyyv8rX01HDfCd0U1wU0KrdqnvY= X-Received: by 2002:a17:903:8c4:b0:2e2:e3aa:7a35 with SMTP id d9443c01a7336-2eb004fe87dmr17468265ad.36.1793179601713; Wed, 28 Oct 2026 02:26: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 V19 04/14] monitor: track IOThread users with QOM paths Date: Wed, 28 Oct 2026 17:26:09 +0800 Message-ID: <20261028092619.1654474-5-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62d.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: 1793179668988158500 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 Reviewed-by to patch 14 in the next revision. Please let me know if --- 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 eb44012643..b8c6c8b9d2 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) @@ -679,8 +679,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, @@ -718,7 +718,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. @@ -735,7 +735,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 { @@ -789,8 +789,8 @@ static bool monitor_qmp_prepare_delete(UserCreatable *u= c, Error **errp) } =20 /* Synchronize with in-flight iothread callbacks. */ - if (monitor_requires_iothread(mon)) { - aio_wait_bh_oneshot(iothread_get_aio_context(mon_iothread), + if (mon->iothread) { + aio_wait_bh_oneshot(mon->ctx, monitor_qmp_iothread_quiesce, NULL); } =20 --=20 2.53.0 From nobody Mon Nov 23 04:18:27 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=1793179678; cv=none; d=zohomail.com; s=zohoarc; b=gVZ5J6PgIjVn0ADpJVplq3rW5hnNBYAwFMpPDQhh0V4ggr9If+sZ7VsD4TfEe4e5IthIBqK3KVgztCewysQcxRk6lp9evdDDuOjSTFeVg3Ja3Dq/5+u/KKNYChB4qs9KxGMf5gl6lXK+YLq1lxdubu8x1/710xaP/r1skXpjbXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179678; 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=8NQuvScWPv6bnvpxQaV6jKoAN3yBXqmJVtB7VTNiBkM=; b=fg2lp3gBg5H1YE+jFSPJNcL8wsCB1FonCxnod6O/qdd+7uBHKHrOoP9GbmGrrIpbWQVhrwBhNyosicpfGNOJzQcteUcHyC1U7KPzMTkI/EseUjSYG/bIif2/bydMAVshCW8Wd9ERIbjIf8RLChjjIhVEEbYtJKZm4KpP9Ho2AtA= 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 1793179678648604.5282758966395; Wed, 28 Oct 2026 02:27:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzvm-0006v6-Si; Wed, 28 Oct 2026 05:26: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 1xLzvl-0006us-Ix for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:49 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzvj-0006hL-L2 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:49 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2e8246b13cbso5919585ad.2 for ; Wed, 28 Oct 2026 02:26:47 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.26.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179606; x=1793784406; 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=8NQuvScWPv6bnvpxQaV6jKoAN3yBXqmJVtB7VTNiBkM=; b=BA//82Kq6hs6MoLoK2TBOynwwGtH4+KLMzs+ZMSH9uSEdOyvi5NWVlZn8IFPyoeiOn 6oxjQ3Ic9GYyMD65bfO+xEXIOrdAyy2aLMIxj7oyMqjDafp4XOuSFkmPdcig5RngiMXr oZgjqHAjtU9Izwr6tegpRimJGS4IFJzWZspIwDpC5SxBnKTKp5Y4PtUUWc+aVAxl10F6 4YCWTkGkIEIBPC+N46VJuAgM5lCAg8JK33Xo/QTZSztn2FAQFifdEHX40vXNefHrUMb8 iFWR85bdXh3Q+k+C8etE4w0d8fdUUVax30rf+D21bPpw49OfW6qoFLGKxeX1lr6uufHA bnxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179606; x=1793784406; 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=8NQuvScWPv6bnvpxQaV6jKoAN3yBXqmJVtB7VTNiBkM=; b=pngue09TnBomFyhCAlyvp3AfHDEbIbV7WgS+dvPL1z23ut2xT7oW+3aFNEP2mJsWmH IK7lqA3B6FJ4Uy2S6E5e2Mn56UcQIjdbjYaZLLK6xCJK810aLK78iSsvZ7il6EUhDoqZ uIzaIxu5p8u2NiujJfSMbnXO3uV87JD9Y/ztRvO917HAMPv2jRrHK5mwF305D+uvd+03 WbpyofolHrrg3ZKAk9XuGNV0LNqO0sB/BwvHZkJRTmj9bTZXond8QceamY0CmNyYAqjv 1NkWmy0DWNzhfvLU4o8d2Xxx8Olxji4OonVueXg+cJ7gBfpdYG0Tr/ivgfXwIVqvQNcG /XyA== X-Gm-Message-State: AFq9FYIP/08HORiJFXyjAWL9krHS92Oteto0FHeBAkL2dFllwJQ1R/qp F1TGINtphAEVhIuGbtA86ON8HdLfsYR+67Ex+Ooj8EZ8HJsExHux+jIAv9hmu5rv X-Gm-Gg: AYBFou0KIQGGJJe8jrzxsxzWH07tTQuMBuwjUEs02ABUKQlNKnfwby1Gv6UOTpb8x6s 9PI2EEecCX5M5CUx9gKYb/nS7bTtZrngFXq54xwsu82HbaDVqMZrbCLyZTZA0CjHkeMIAQhoe8H t86KVg9W7q5dLBWup4fQzCuW3HIfsm0+qMdYFcTT7mN4xRLmEya4GhUY8SbltKFs2RjQe1uWFWI q3ZGacyiyvg5esyNmiHayVJNqiJ1oijEIukShL1umBiUHu70qxL2Vv76djEzAyUgUhEiFYdQupg niTldXcCGpJsPgJYg1W3Qj7kuMUoMnG64y03kK2t2VBr07nE3z53ayqZJvizZp0IXZTfyI5TYrn GuZEBv7bN761Zx4bpg4EOAzRdBYiRvCa2RR3m/8PlnzuXztul9fKgBCcUA3K+AyZDA5nnX8J6oS BbftVKjYXHkUinUcJVucoienY7HKu/GRUfPxCWSY8z14mZcHPrfABQdpn8lkiCJugplkGjYZUmB lMH6v8hN3jZBJZN6pijQOvvRqjGhs8oNkWKdXchKYSo7HULf7WEA/ieeuZwbRPbtbxlBEf0TuXy 9/tg2N9PhWNryKjWVfZ5kQzT1prP5/qq8i/oH0pOCqtJVIMv3PxZvyT/mUfr X-Received: by 2002:a17:902:da87:b0:2e9:628d:e9c1 with SMTP id d9443c01a7336-2eb003c916fmr18381995ad.26.1793179606160; Wed, 28 Oct 2026 02:26:46 -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 V19 05/14] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Wed, 28 Oct 2026 17:26:10 +0800 Message-ID: <20261028092619.1654474-6-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793179678983158500 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 Reviewed-by to patch 14 in the next revision. Please let me know if --- hw/block/virtio-blk.c | 8 +++++++- hw/scsi/virtio-scsi-dataplane.c | 9 +++++++-- hw/virtio/iothread-vq-mapping.c | 20 +++++++++++++++----- include/hw/virtio/iothread-vq-mapping.h | 6 +++++- iothread.c | 13 +++++++++++++ 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 536d71a91a..a960ae21f9 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1575,9 +1575,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; @@ -1609,7 +1612,10 @@ static void virtio_blk_vq_aio_context_cleanup(VirtIO= Block *s) assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index bcb6e44133..ac13f4a1ca 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -65,9 +65,11 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **= errp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); + if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], - vs->conf.num_queues, errp)) { + vs->conf.num_queues, path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; return; @@ -94,7 +96,10 @@ void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); =20 if (vs->conf.iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mappin= g.c index 55ce62986c..60e1d55005 100644 --- a/hw/virtio/iothread-vq-mapping.c +++ b/hw/virtio/iothread-vq-mapping.c @@ -77,6 +77,7 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp) { IOThreadVirtQueueMappingList *node; @@ -93,10 +94,13 @@ bool iothread_vq_mapping_apply( =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - AioContext *ctx =3D iothread_get_aio_context(iothread); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; =20 - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(iothread)); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, + &io_holder); =20 if (node->value->vqs) { uint16List *vq; @@ -120,13 +124,19 @@ bool iothread_vq_mapping_apply( return true; } =20 -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list) +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder) { IOThreadVirtQueueMappingList *node; =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - object_unref(OBJECT(iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; + + iothread_unref_and_put_aio_context(iothread, &io_holder); } } =20 diff --git a/include/hw/virtio/iothread-vq-mapping.h b/include/hw/virtio/io= thread-vq-mapping.h index 57335c3703..0d39caddf3 100644 --- a/include/hw/virtio/iothread-vq-mapping.h +++ b/include/hw/virtio/iothread-vq-mapping.h @@ -17,6 +17,7 @@ * @list: The mapping of virtqueues to IOThreads. * @vq_aio_context: The array of AioContext pointers to fill in. * @num_queues: The length of @vq_aio_context. + * @holder: The QOM paths for attached device. * @errp: If an error occurs, a pointer to the area to store the error. * * Fill in the AioContext for each virtqueue in the @vq_aio_context array = given @@ -31,15 +32,18 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp); =20 /** * iothread_vq_mapping_cleanup: * @list: The mapping of virtqueues to IOThreads. + * @holder: The QOM paths for attached device. * * Release IOThread object references that were acquired by * iothread_vq_mapping_apply(). */ -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list); +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder); =20 #endif /* HW_VIRTIO_IOTHREAD_VQ_MAPPING_H */ diff --git a/iothread.c b/iothread.c index 5a4291a2f0..5694e91bf7 100644 --- a/iothread.c +++ b/iothread.c @@ -376,12 +376,25 @@ static void iothread_set_poll_param(Object *obj, Visi= tor *v, } } =20 +static bool iothread_prepare_delete(EventLoopBase *base, Error **errp) +{ + IOThread *iothread =3D IOTHREAD(base); + + if (iothread->holders) { + error_setg(errp, "Cannot delete IOThread '%s' while it is in use", + object_get_canonical_path_component(OBJECT(iothread))); + return false; + } + return true; +} + static void iothread_class_init(ObjectClass *klass, const void *class_data) { EventLoopBaseClass *bc =3D EVENT_LOOP_BASE_CLASS(klass); =20 bc->init =3D iothread_init; bc->update_params =3D iothread_set_aio_context_params; + bc->prepare_delete =3D iothread_prepare_delete; =20 object_class_property_add(klass, "poll-max-ns", "int64", iothread_get_poll_param, --=20 2.53.0 From nobody Mon Nov 23 04:18:27 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=1793179635; cv=none; d=zohomail.com; s=zohoarc; b=VYIax4fTCtmsHuQWdqvKZoFz2tFBwTt5/4fiuRVlbZFFEAXs9FxibstkRyCi4TDhCqsL+y7QXE93KV9LH390sJz6chgTR5cbYiobaQMj1CmkTb8vpdImGk+t3uNA+f33arxnL1q6DQ7Gxz0h65OUHscRuyniIX53tRE0c7zrvOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179635; 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=IlPG56l5zWSU7QtZmzCX0cs9RiTDurY1OftoOXujfIc=; b=Fnd+qEifnD+9qL+U0X17550c0UVj+bOpr1CrcYzZtbDxDGaBEYrz8k7erX1/gFI0/8+7Fr8P0XZVXSrsW5l+U+OEdZ+BsQB0GmSnrfDfKxR8j+6NZfjqyUAmb6YubagFd6U2fz95gd25CZYi5Jbvrtg5j/8I+k6l1zdc4L4ybXA= 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 179317963516378.6922965415149; Wed, 28 Oct 2026 02:27:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzvq-0006vj-Sa; Wed, 28 Oct 2026 05:26:54 -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 1xLzvp-0006vU-HG for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:53 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzvn-0006hV-OD for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:53 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2e95bd1c14cso5895325ad.2 for ; Wed, 28 Oct 2026 02:26:51 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:26:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179610; x=1793784410; 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=IlPG56l5zWSU7QtZmzCX0cs9RiTDurY1OftoOXujfIc=; b=mpd0gRceG3fIzpECs9nwdTyOOa486tUx/1QDlSEblR3gYJkDxfPlZYm1A9rb6NyoL+ +j/xwEd/2er28bfJkGZe9gV817qlov4PfrguaRDmMMZX2ZMuFnBHIy6gEqt00xtOkhRO HTfBf3P+/sG5n0Z5YtjzAS/BMSkLQBk2/zli8aq1nIesVrdCeaNWU0uiXIw5piYp2NP4 lVyOu4C3LFzM/p4CBM+6jLirK3NA9D4YB8cw2Lw9ur0iyKNqUnBr0Bx9N8fwuUWRbOdn YIuAxqStb/ARoWqZOnMLaU7EoEB12S8uGZ3rEmYRKgTXCrFhAouk5/qiugq3Y6C+AIqT mDEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179610; x=1793784410; 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=IlPG56l5zWSU7QtZmzCX0cs9RiTDurY1OftoOXujfIc=; b=LExVghMdihuoElmTE9unZ3oe+fSSTE9ynCE6gwbh3QnV7/kVa810isY5n8BPjveyCO T+MSchAkBRU5oDi3pC+wPaZwJwvshjVfWltvb1W3xLemJmUby68Lvjfwpq+mNE5/WTtU TcncOicA6JLl1Qq7XtKXW4FxfVUr8os9Gtu+LbLdv0uwrSoBgO0eyAQeG2mAeVSTlqRH 0RX/heOjue/gAMKqU+okdLSaXn4c7bEwWn9ZWU26rNj4HOXVtOzlkf29xT2ulzg6CG54 67ErEXXfmGr/rNkwIb36V+Pii+nLZlFNy+mBquhEpINbjRU7OsCu4DEh42wwPDhqUXSr QCJQ== X-Gm-Message-State: AFq9FYKhmhxI3ykLuU/nEAYDHlNVQAMQTif/vtXCz2anBYA/xE0DnEhG reuAfOXiSjnLRsCk7WqsVduM6WOi39Jtix+MxHwF06j2YtU9y07p8rodi5x9w2Iq X-Gm-Gg: AYBFou1Zu5yevpPLxJFJdhI2qb9GtC2bqbCsrDbqQ4UtOyKVM+tkAjI/4yFvI09pq3Y ibP6ELUFGVM/b7kysIfoYpIrq5eHhcqSygJP/QY0lpw06vWcxV8jV1NVDuO8KaWz99VIXECXilg wtt0nDBXBrF0Jwlw/LmlIOLsYHyaTEBAn2g/iYnUseocICt5B4mRl2I+rKXNd7FR18Cy27i6S4w GJSoeEmkUhSMU381fPjHcSyDS/5T8cY/rSioV4kyblL6xZ1lJ+TZHrkm5ymlEXIRHTZ8cWnelWL muZJFJp/ozTcuFawajQcmCMjSboa2eKXafnQxMvgviRWuU3/pYqrWnJKUV1/4Iv5N0cSYVOXCea KwR+IkZI7Mliqbz39bgBU+L8tBHgZhyKDWILxUfTG0w23Qukw9rRW8p+KVwb2/9wtDcZEoQPEfR tyNM0W/OlqP5HSR7XJM5XldcslQHJHyLM+BDEZ7vjVyvOSJkLDYreR7DsoNCr02KiKqRZqRnp5c J0mx2pI96je88oCZzWNVAHBobCLj2Uor7cpeHr5/iyfuiVqTTRS4gELuWxvsToIOs6ZKVQFLF0F R54yWPCrDH+LL3D3AWnPteX14aNywEhDW5fWg5y9+ADo9uOQ/wVT2gCSHF4= X-Received: by 2002:a17:902:e88d:b0:2e9:5714:6081 with SMTP id d9443c01a7336-2eaffcc020bmr16974555ad.0.1793179610408; Wed, 28 Oct 2026 02:26:50 -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 V19 06/14] virtio: track IOThread references for thread pinning Date: Wed, 28 Oct 2026 17:26:11 +0800 Message-ID: <20261028092619.1654474-7-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793179637327154100 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 Reviewed-by to patch 14 in the next revision. Please let me know if --- 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 a960ae21f9..e6a35a78db 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1551,6 +1551,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, @@ -1575,8 +1576,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, @@ -1587,13 +1586,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++) { @@ -1608,18 +1609,20 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s) { VirtIOBlkConf *conf =3D &s->conf; + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { - object_unref(OBJECT(conf->iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + iothread_unref_and_put_aio_context(conf->iothread, &io_holder); } =20 g_free(s->vq_aio_context); diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index ac13f4a1ca..d66946f279 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -28,6 +28,7 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) VirtIODevice *vdev =3D VIRTIO_DEVICE(s); BusState *qbus =3D qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 if (vs->conf.iothread && vs->conf.iothread_vq_mapping_list) { error_setg(errp, @@ -65,8 +66,6 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); - if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], vs->conf.num_queues, path, errp)) { @@ -75,13 +74,15 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) return; } } else if (vs->conf.iothread) { - AioContext *ctx =3D iothread_get_aio_context(vs->conf.iothread); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, + &io_holder); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } - - /* Released in virtio_scsi_dataplane_cleanup() */ - object_ref(OBJECT(vs->conf.iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < vs->conf.num_queues; i++) { @@ -94,16 +95,18 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) { VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { - object_unref(OBJECT(vs->conf.iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + iothread_unref_and_put_aio_context(vs->conf.iothread, &io_holder); } =20 g_free(s->vq_aio_context); --=20 2.53.0 From nobody Mon Nov 23 04:18:27 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=1793179716; cv=none; d=zohomail.com; s=zohoarc; b=LkDjXWJNTmODOPxiSw2rRLxAqYZJMcJ/kDvVJfDcz0WBQWBGjbIMSV9nNectMLVQKCLRXGlCiBNAKsNCnfZtqZc3sRXCZvq6MiYrzYpZF+tIYEmESg6mPBuT3faRQloVkHAZeqXeZpL24jb6ldOX6qOBSO19deEg8r7OLzTtCLE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179716; 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=KGU/bxQqqI8Jedr+C0vr2XVXdkAsXqpI/Tim4ReJeJc=; b=A97EiqDYF2l0WyjAEXmHQE8EABFBhFgiBI7W1mI+40qYp0nZchRZVGOpdBmeyH4xaftdK3XZA3zeGdNRbPOgtbgal/QPZeCDcatEbTpxU7ikmGSlvdFAT8Ow7rUxGUBuRvvxgn4oclXvUyqOeh0ACb69BFUUsSQPrJ7zBEpQcM0= 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 1793179716594781.526166286251; Wed, 28 Oct 2026 02:28:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzvv-0006wZ-8n; Wed, 28 Oct 2026 05:26:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLzvt-0006w1-NZ for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:57 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzvr-0006hi-Ve for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:26:57 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2e812e2b31bso3885025ad.3 for ; Wed, 28 Oct 2026 02:26:55 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179614; x=1793784414; 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=KGU/bxQqqI8Jedr+C0vr2XVXdkAsXqpI/Tim4ReJeJc=; b=YhhJWOsEAy/HtxCRjMQ3YjvPCZgOz3+qqp8e0Ji1I46xdVx85+qfKcLo4vkKyClGJT PsRZTD6eiePPHEVDlyqat+PlySZ8tvxoxe1SbsyxD00SGXHgFag/FX/UfofiZs+0eyTD 9JBLQ7/O8slLHsK80RpNHTkubDCT9TcpNWroe35yEXqBywoSdAktoz1SqDfxG34LWxWf grvmJv2RKccRfSJWD6B3IY6z6zV920d9DW4evILk28OEsZcPb6iu4voI3gbAPzzcRReq 8KhWQ4WebeIevOYdCF9uKTgAxzEF4bmvuL4QrAiN1nicTED1Gehy1HKqzlMSKGOs+h+E /EUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179614; x=1793784414; 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=KGU/bxQqqI8Jedr+C0vr2XVXdkAsXqpI/Tim4ReJeJc=; b=rsZHEyErBXSGrGkc9i63MZOA8Xrp/9uEo/YaiutqTd6IkHJwc5yO/Pc03or5H8PYI4 0FdPOBm7vPtbo5X/23OXt4LrfoVcfhJmk8TAsJAcVvc+vU8GydcS3OF4ztL+k393Jia3 ge0UqG80nwkys2mF6q2Y+bn8jSd7CgOihLhjWY4uZdOwh/6NfSNuP1+2LxrZKXamtkmr Y9y80u+SvplVIEff4GegIvDp0cs0FxUuS20ZWn2gs6W7ChIJGSINiitBF5iey0aZJWEA tGtFQ4k6xW/uy/YZi9cen05Gq5dTn23k1V1CvO7KBnvbG4e3cLoak+Lf1BiviKdlqpu3 kRfg== X-Gm-Message-State: AFq9FYIuJQLaKnuGtA7jY5pY3HEGbIsfho9lHCdK7I5QHLRysuY+QVuu AqSFg0aTGArPg7ABlGlQxhFuaHU9nWm262mS2XGbGDA2IUkxeIkxC6OBj8XOaOF5 X-Gm-Gg: AYBFou1cuLr50UBucg2twQeSWz8ZRX/9B/9YPL6qYk3yZ+myj3w/uY2nIX44GvoS/wk FBTK778ZEk+DCwiccF/QbLlLLCdZb/7m1IL2TCjwXATjnw5KBZUGp68MbaAV8+ary11aFatMIzn W+mz26Q9mYRcFDPPADbo/bH20Rc6NQ8o+DulWLXDNQLJ11CJZlKX0nv6mTA/SNUUqfvzUw7dYlg TtulBsOAso2DBLY9w2Q2/KUUHDhBv9GPVZdO+iN8cQDJ4Rk7Ba1EXkIF2SCSkMyi+VkDZvzoa7B 8+VUrLvilzM7zcfGcvNp9zgSnK85eygf8fl9vrn7FqFnu7KZ2heQVRkWdojEzUsgVveXczdF6QW tsTf6pYrJi9q924nrmpdhSGvgX1LDHj/PGr5fhZnJ0cUOOg5/GHax3gApu0AyDwHGLYiYEuR86g FuiGelRHUkLumv4k0NGdRIOLXqMafw7O2EGp2Ve9eshqz5+EtqD7vru/ZJZm8M1I3gsf0HdSlA3 8DOTjotJ5TWxEeDZGC8wK5dNxwZ8zgoH4FDMTsM8MPlaFtlsYCXgv01qfO62XvFaigDEYQ18UKW /AKKqeqClDV+DGTNRa1qey+4bYgE20ic4iJBn0Bw5qavJb9KMK0u2HjHg9s= X-Received: by 2002:a17:902:d4c4:b0:2e6:4e5:b399 with SMTP id d9443c01a7336-2eb003763c3mr17992315ad.26.1793179614344; Wed, 28 Oct 2026 02:26:54 -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 V19 07/14] net/colo: track IOThread references using path-based holder Date: Wed, 28 Oct 2026 17:26:12 +0800 Message-ID: <20261028092619.1654474-8-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793179718620154100 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 Reviewed-by to patch 14 in the next revision. Please let me know if --- 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.53.0 From nobody Mon Nov 23 04:18:27 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=1793179632; cv=none; d=zohomail.com; s=zohoarc; b=KLWNiSflmNPLccB1kaBLC4hdYQQ0EBPhpkzzhaP6cHapfsjd9iGUihylGQIz6jGekArgTQeIbYeLP2Isd45t7tcnVKP0yRDtYO+8jFpa7sYEinD0RgUaDckp3o+6lTpg2ZXohnxeqj0hvmhBy4cF9h1QqQ5g/vh8gUmAw3o0fjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179632; 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=AiQGYq/AMrxdJEu7NCO1nhO4S/ZduwCJs4CIWfesvEQ=; b=kS55OgoNbzWLT61ZqwO9Kj0EP7NzGdWu/I4BkAMtxUAAiQJYSXq+7k8ubTHAb/09Ft/i31QXroV6HfT31O4813OnFTCu14w0c2Tt07I9qk+zr5LXxjp9U/qHLvmxizU6l9KPpNiwQzNx8B95GastgsWgPz65Gn7kQEjj5QoF/4g= 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 1793179632430933.7332220147816; Wed, 28 Oct 2026 02:27:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzvz-000738-GI; Wed, 28 Oct 2026 05:27:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLzvx-0006zr-Ij for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:01 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzvv-0006i0-T9 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:01 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-2e985106c0cso6140125ad.2 for ; Wed, 28 Oct 2026 02:26:59 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179618; x=1793784418; 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=AiQGYq/AMrxdJEu7NCO1nhO4S/ZduwCJs4CIWfesvEQ=; b=FF4T+S+L4BQhVMU3MU23zWSPXisZ1q2pqrWLALe7T5p10hvhX9HGXfi+RP+16ujrE9 AtPZFAA3ViKFfog1b0CdJPpT+Ds/5sM5pENcKuh/jkQxsdBEZUnnL6ExQAOFdF2JG/qB s/02D6zfYWb5UgFc2Tj297HS1OxCwgbdZB8JSNUm+hplLzaeZnjaniCNjuDSAo5gOkVj pCDgJtyeRRGVGwqcHyqdq++DUDzp9lzl9D046a1NuBiYKWZqJREMpYsrfMdKpK+z9YBU XvpXCWOzn/ilxpLFAmGMefflEIvCxxkizaJhoLSF/1KGk49lj/qMtR/57Ix6oGMlbrat /YjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179618; x=1793784418; 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=AiQGYq/AMrxdJEu7NCO1nhO4S/ZduwCJs4CIWfesvEQ=; b=sq3+bmSjRfN7dtfL2/whJ+mbfN5BAvJxdZixghhoYVoQq9YI7rc1NAa+/kJyVhSxmX 96hOHDIffvkHw9aVnYkjPPzjhGY3TvbFsXLR0tvQWFVFrONeQ/RbO81XedUtUTBBFmsV WECu5aH8kiOtwn+EKSLuURvosWyVlwzDaOPfgntkxvotckgdUmgukAn5KMoP4H+lmNK5 phWh9asL7f4Nv8G+bLsn4K4c4yl6fCYNqp6akBS1VIUr1ocXY0oQWEudCSo0XJaunmvk 4XpSzY6H7ZTDlZBhFQPZ176gK8VnncYxOcktVj7S7jOoMVxX6Qk9xfAlvpKf5YbRFJ4Z UGpA== X-Gm-Message-State: AFq9FYJVUHCiPeFK28h0vRRuJeToKRidb+fKGDYZy6CC5j4rf5/s2pTF 1vS9lmlm7DtbBuv8Jud0CgCVC6QWFVOPRI4Kiv4jrcBCdTzMu9F7E+4+G+m2IV+U X-Gm-Gg: AYBFou2HT5W43446DhR8LNjU8w6i/8BFRZtzrK1btLb/eSMFfAbR0tG7RZ6Js8vO8o9 pBdWbxkJsXcj0HNN3VIXynIw3CVYJVKG11LfexaI0x7bvpr+hgZhykMOr1YSzvaGOgQpZ19f27F skrWiluxvf+J+XqPaIRDmzvb5MpLXUoR4fs0Py4gNR1f7HUa7lmIm6SEV6X/+i0i9z/7h1DVHN7 kdhEySGqw1CCqTEernFMl9V0EHA2NJM9LP43sU2j0v2MS4yCnWFCofd+EHcYXnxcJXw0g7ll/tD +OnNUnzEM8BQB47bvPjV7nttFZgckK5vBIvEeyMJiAZqSEmwRinIpe84eYvDRsW8AZquNVjhJ1G 02jkP8Ep4tEUCkNtTv8bo2/GrPI/eGyQKy0EuxdTVxo90qY0SdJMSh0Mwd1pZAzvCoGDpg8xr3o OnTOu1b56UzQk1dfbQqp70TvC/m+UI//Sey/dSuLqQdDf6aFuPDXr1VTxPV6wP3ERThTSgoQnqO QpUCSGo6XrymBoNeCC8HAYE+dns2Rq70OF7OSmf/BOAQUY4N1rD+0qEwgmBAYaCLrpqyxxxLqWR 8C1KpsOOHCtVVjGyZTFmOjY9SupESJ1QJwyrKd2irhTTSDtMOKDY+SonDKg= X-Received: by 2002:a17:902:d485:b0:2dd:ad73:c93a with SMTP id d9443c01a7336-2eb004fc927mr15701715ad.27.1793179618544; Wed, 28 Oct 2026 02:26: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 V19 08/14] virtio-balloon: Update tracking iothread users with holder Date: Wed, 28 Oct 2026 17:26:13 +0800 Message-ID: <20261028092619.1654474-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x635.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: 1793179635584154100 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 Reviewed-by to patch 14 in the next revision. Please let me know if --- 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.53.0 From nobody Mon Nov 23 04:18:27 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=1793179746; cv=none; d=zohomail.com; s=zohoarc; b=avbCka8lIZDUxNBsp7yPq9w5jrzrOqNAnKV/OQN4x3KGr+dn3ixnFNUYhFtj1egDFswlpJ30vQRTv6RgS4smqUs1RgbfNSvqp7WYW7JUMMCu5I+3D/QXe3aeGKBlgwZR2ZNAXfAU15VGvXVCauCV5dk/lsLcE0lP9LOauQ6qaSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179746; 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=LDLbm7e0Y1nuSgmu6jeUNW1v4Qmthty4+pDhPxrnq+c=; b=T51k/+i2sp7+xmR2MYRad5L3wMxRV5VztgN4t4EomgxQwQgYs964X9yprh9J31CPdMc+cM0p7bFl7S0mKe2XwfNugwt1sgm1MeJIKB7FdvZudmVkGH8+9FDc1i2EaasAsysmHqfzwqmtg0843hVx/uPQXU618WhqggVwj1LSTzY= 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 1793179746472833.4992477802726; Wed, 28 Oct 2026 02:29:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzw3-0007G4-IT; Wed, 28 Oct 2026 05:27:07 -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 1xLzw1-00079v-J1 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:05 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzvz-0006iG-R7 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:05 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2eac4877accso2443345ad.2 for ; Wed, 28 Oct 2026 02:27:03 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:27:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179622; x=1793784422; 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=LDLbm7e0Y1nuSgmu6jeUNW1v4Qmthty4+pDhPxrnq+c=; b=cZ4jjTLOmxnsS9W/AC5FyMo0kVxwR5LZvjlgysjZM7r5pPJBr1lht/v/dDZxFKCBJe 5U1Dv7RPJUfuZ+Kl5kwhfmh5TQSeSemagZ9/3RDNtSsZS+rao6g0kW4NHQtrnzja6vVN tQYyoviGFLLhaDO7iUDCQPu9X9rFJoMFAMmVVT6uDyb8pzwoCz2JvgG+1wIgJZsvkxMD FsmQazuEnu2bAPwopHnfvA9UnezYp8JqtEMNoxtwcoVmS1t8CHa6rnUXsrhUBYzeYcYl Fb8yYqoTkFRcdbpnbjWiNxunYuD3Hq0ekOA4TTO9J1RIAawMkrOc6jF0ru9ttBbttp8R d3iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179622; x=1793784422; 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=LDLbm7e0Y1nuSgmu6jeUNW1v4Qmthty4+pDhPxrnq+c=; b=gPi+H6wkT4iADs4lHmsS4P9FqzNkWznRA8CUFnhbTi9waIfUvfHaOJJh9PvsAerjFs Swrv/fqbzZB2Wdlqocp5L7mMzRMWkRg2TT5xI1itxDYeLqbVo11LePLlnP02fZNbWyM0 iVVUDwjVL6AxmHq2+ltBkVXejg+DsWmcOXtITsNWNYeNls9px3mHUkdPai6+ue+hkJ2v B0uZaP9vaEq8CT8lhIU5SIscGcIB60LEv7KNZSECoUk9jIk5RKg/Jl5qfddSIPGHSWsb V3aNMPXxfysxhePWkiw7LyLIiNNrROq+cM210cyqh1S1nSnqLaZJlINpDdsbrndVRZNj Q4NA== X-Gm-Message-State: AFq9FYI93JIoSH207Qyf6SOCEs4oYKr7gSQpJTPKPOlBDidGAT+/vCcp 6uoulcykZqgLK0lJlufEU284WuwsnUnOaygQu5Ou/TKgmXRP+4NyUHkSYX75Apn1 X-Gm-Gg: AYBFou3LDUBsuT21xFCuuyOqNbyNStKiiyPNCMNclj08BfKg43CJ9B0CMAeIYIh2RoE IpGhlERELevQ0UEoSmLx7UOLTK9JX4bd5AeADYAMKspwYa+TJR1C++pqPc6NZkOuUnUdXIzylIU sEolbvxmUg4FLA2PKf5CxrOn5LW0V8V5SowqCHVAvMFXQCyZXlUYtPzAPOLxV9zF5NRztP5lD/t OXDeR53YPeR6Lh3ZCs6pYHKYPZ6tCQLQiM8YraosiLpjMJlNSW1u/CXIDgVWFt5TMfUNB7XDk9W AEml5O5Tbj9TyTfiUry4b3S7yDgcVhAuP3Feq+Nyf3DISoEMnKBExiWIktR+g3RkJqtD776d49m vsvG2gd8Kxu6bewDEiicwj7p6t67CbVsMkpYnhwAlIlExJpYK1VQMoVk3RbBOyKq5PGrTWkEzrU DfQz3gWIyHvtTNZQVIxgmWDdkFwmLa8Kov7k3j3Va4YzaFFN60mXdJjloLNsTyzJ9cCWUN4GipD 1m3ZiFKNqw4BRlWYcJ4qxOqHXwsoOhKfLXtZfNf7Y6DFge/j+whiiBy/cY01iA4HDbmHYXZSehU HMz+6CINtuCvLAwUpZ2/ufxf/Ibz8KKbNyM4Ng8vqGpCKuoPbgDjfqK9Fic= X-Received: by 2002:a17:902:ecc1:b0:2e6:13b1:e196 with SMTP id d9443c01a7336-2eb00577e95mr14035555ad.74.1793179622296; Wed, 28 Oct 2026 02:27: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 V19 09/14] vfio-user/proxy: Update tracking iothread users with device QOM paths Date: Wed, 28 Oct 2026 17:26:14 +0800 Message-ID: <20261028092619.1654474-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x634.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: 1793179749086154100 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 Reviewed-by to patch 14 in the next revision. Please let me know if --- 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 983e1d4ad4..59b18f4d11 100644 --- a/hw/vfio-user/pci.c +++ b/hw/vfio-user/pci.c @@ -278,7 +278,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.53.0 From nobody Mon Nov 23 04:18:27 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=1793179636; cv=none; d=zohomail.com; s=zohoarc; b=IAHzh+5Fovah34veTrBzbCO9uhLPjpRFv8i4rZ00EU1978bZlPDumrm5V8auGECrUD7VZOUuRoLsTo0rc5FIVd31tvWvJ0BG8gnfPYl8j0ASYl4TX3JDEZNs/XUl/IMmPyiJc5sT2/YA6wfyZCXmQS8DW06WsgCOUlPAMIMLM9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179636; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A+ZI9HPiEEreD00eCRzRf4GSQf4yCHaMnrIQJkGq+YM=; b=i3kjy3e8PeaTfELvNqBzIABc/ubvEGCzcJk/2fSkmvPvp5ARhbEpyCM9/PeoaIQyBgRRsGJTfhBSL5m7XMkk8flaDGcTgbVWgo0cLXIk/E5d7OULP24fft0Gt7QG06BfG2TAeRLGRxHDT+VUU+vuN6MX9f3TxirFa0LuHANfvmg= 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 1793179636889451.74768796635624; Wed, 28 Oct 2026 02:27:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzw6-0007N6-Li; Wed, 28 Oct 2026 05:27: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 1xLzw4-0007JQ-Iv for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:08 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzw3-0006iQ-0a for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:08 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2e8f2c3ad6bso4228105ad.1 for ; Wed, 28 Oct 2026 02:27:06 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.27.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179626; x=1793784426; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=A+ZI9HPiEEreD00eCRzRf4GSQf4yCHaMnrIQJkGq+YM=; b=JRXSdGX5mKtKTS+h/5aX//Rmk9yDHIGHanRvKu/oK2w60JPIKfhgWiJEUsdzerz3Go ZzFQrhkBkKyAP5C2G72cIH6IEm/MqoFWNLYDoBjO94XkgR8GKxwpYc8tuPQpjMf5nUFQ hEAYUpT7QW6SE2tbY8ale3AjwIjzHGFC5hBgjAMmNijTLPZbayqsvXJXHZxmIQ/VMwOh vkhMQ2fAjGZGhGjSSjjhcONzGOQ36+C68s8ry/NW88dztAX/UuUyXALi3tnzRbL4LNil I+k2Ox5G7GE/dJk6vxpptLiTUqUCOg79l+qQrOpkSiR1enne6c2vugdQG1NhgxR4+Gkz R/bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179626; x=1793784426; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=A+ZI9HPiEEreD00eCRzRf4GSQf4yCHaMnrIQJkGq+YM=; b=MMlCsNpz+hoP2SntnH5igHNfznPitXMmrgqa6sQS9bsHhkJBY7+UbUGjZCZh1Ai96h nTfyMaeT5VuZKxaU2DOKF6KjPaaVxXqgBt6Ri8oF5an8J1SmYNuhFJ7JfXH1+pyyd09U Wrn9QWQMmIyby97jpYMlbYKdo5k7ZNGnzMnEfO8zsrgnR0j0kxYbH0065EI2gigWJcdB E4G/LHdyJhabznoGSvNWv+syevKTmx763mLvSoN/18pnG+gIEkBiOgpQ4OqVXtcGpFTi K/8tcoSNdJ3t3owBVWHr6Cio2x8KQqpxLUVASVUvdXhRT+RcO30n+LE2AYsd86McTZDf IFBw== X-Gm-Message-State: AFq9FYI5Jd0LSEs/2ePa4XbuVCcpWQJafSVpAi96HsP8iPgxnnC4IFIj OrjGgwG1HjIoqPa9yPJSXIEYbfLx4ZH1Iyg0SWo6edvDFeDHSRuUC79r+JcmZQ/j X-Gm-Gg: AYBFou0aU21P5Jtjb8gIOcEfp3DO6OMK+jXXBzRXVyUarjudnQKg4YofG0vJodkBRMj AAcAx+9dxnYoCouvRDlB7RLuCnmqd1eMHZsySYu4C/dB6LRrxzkZrhzmEc4XI22wWPym3kLqn8F /LNRAVapAWFb0HU3qHlALRvYgpu3Wgk+m0Bd9/15luA6vs7Fu/m5Kwd2PV8jPRJsSfr/echwuPF IVhDvVqWoHqMufcJPGoZn6hz05Ck7HS+mZvB/N9qyNsNE8i3quTeSDJCZJ54MQGfWNz5Xdy56/B 7pLinYqcIDmsXzx2NWbVvm0QqN4o9Jblp8zqxVoZ7WEsV61mLE1/OkW6dWBGYD3fMS2aRyX4wol SVTsqrwn+9DDdNRXwdMAGxFyWXwimv3BkBIPJvzyaWAXXggigv29Q32Pt/432LZLaOg3d/0GBuC /Ybgod8WZUzGbqVk/eIA58IlSgIcPwOJ/NR/AzzUcScb10ldCgADOvFX1SiHhlAwGt9U6/HN1LM up6IrUJe2C0TjKtoqluWwfNCjDDh2zNTTjqiLW55x2UoNqg9tMruD2P2OT9ABbU+29gu4USI8z+ C1V2NoguwMLHQtO/OkknrOpzR9Lx6Lv5eSGL5KN9cW1CqYy04hpUyK8GEEo= X-Received: by 2002:a17:903:38c5:b0:2e9:61bf:6587 with SMTP id d9443c01a7336-2eb0042ae58mr17988115ad.49.1793179625585; Wed, 28 Oct 2026 02:27:05 -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 V19 10/14] xen-block: Update tracking iothread users with holder name Date: Wed, 28 Oct 2026 17:26:15 +0800 Message-ID: <20261028092619.1654474-11-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62b.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: 1793179638840158500 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 Reviewed-by to patch 14 in the next revision. Please let me know if --- hw/block/dataplane/xen-block.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 48c2e315f3..9dfe06e1be 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -621,9 +621,15 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevic= e *xendev, QLIST_INIT(&dataplane->freelist); =20 if (iothread) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(xendev)= ); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + dataplane->iothread =3D iothread; - object_ref(OBJECT(dataplane->iothread)); - dataplane->ctx =3D iothread_get_aio_context(dataplane->iothread); + dataplane->ctx =3D iothread_ref_and_get_aio_context(dataplane->iot= hread, + &io_holder); } else { dataplane->ctx =3D qemu_get_aio_context(); } @@ -652,7 +658,14 @@ void xen_block_dataplane_destroy(XenBlockDataPlane *da= taplane) =20 qemu_bh_delete(dataplane->bh); if (dataplane->iothread) { - object_unref(OBJECT(dataplane->iothread)); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(dataplane->xendev)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + + iothread_unref_and_put_aio_context(dataplane->iothread, &io_holder= ); } =20 g_free(dataplane); --=20 2.53.0 From nobody Mon Nov 23 04:18:27 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=1793179693; cv=none; d=zohomail.com; s=zohoarc; b=lhX3gFBOiaUynU5QU5yq0itZCWB22XFPMSvg3gVUIqsJIIBQ1KuyCrXHZyVsD8uP6GbyjkBHo5M9blAjaARga+UpV+xVgczAE0nxsU5eahZYittjtWyVuwUUvRtG8KsAMivg0KOuS2b2OfxtowrE7gs+ljLoDf3d6FBG1cfGc/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179693; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dL/Q6T4ShqA/qNYT5CLVTesugf9vIPbAH1J8Fz30V0c=; b=btE2YpSTDxvS2aYHOlcGXd24IUaoz/C0lZkOYjjlU1DbYgIcQzhHROJGUQCgcO9+nlMTH7OkHGJHpjGfNXYdgBtjChwQfrVJWh9vG2K4OXNtCGhK+en4bPh8nyeD8haCRS6HaoXBq7yD/YrLH7qYLbhJk+0YBFwIcrz6mv6jJhk= 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 1793179693125568.2274821029783; Wed, 28 Oct 2026 02:28:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzw9-0007Qa-7y; Wed, 28 Oct 2026 05:27:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLzw7-0007Ou-Q4 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:11 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzw6-0006ia-37 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:11 -0400 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-cd5d2dafeccso445230a12.2 for ; Wed, 28 Oct 2026 02:27:09 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.27.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179629; x=1793784429; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dL/Q6T4ShqA/qNYT5CLVTesugf9vIPbAH1J8Fz30V0c=; b=hnA0xwINsYoNIBmcDpQEJwoypiod6EnasGjTYDMx/TldfoO6m/U4ENal1fxyvxfXCV 2fn9hPVkcRR1iiKTjZCmFiPNBHHLKmnpOPlLeuOEjqN1DNEOJV5KzO0/iccAIcIB6Hl3 CBm8PmiRZAChrzYoXIqHF2fEY2zU9XHIBxZMKdDBbJiY9M144vFLorX/NtDrrjE6OX34 4z/PXMop1z/rLyc6eSYAayWv8iY8ugRMV6Dc19jKvwZyl47P3KE+J3nkqhiP3H3EQv01 qHGss2/xo4DoCGudXZZmhcobfG0xD6FOXlGHBeg7ELH9elhAVJbjogej3jRVBYffmUxa bkeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179629; x=1793784429; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=dL/Q6T4ShqA/qNYT5CLVTesugf9vIPbAH1J8Fz30V0c=; b=Lr/oRi5QJd8bKUX/NEH0m+9zrL09khoUJQmNSUQVvCNFijJUy1FWWGjj6dJA7o+ty/ IC0qPZUSpzoNDPJ/iE1fRDAS+eJIL9jVKbx64ylrUUZS3mE9+05TOH77d4haNYpE2vky 47OGAHkx26pBIvXrOUV3I6Ss5ZGVPeK+7Nm4Zae77PvYapkanN0GjVrJquBeLRaF0NJI QaFk939ZCVGK7u4ujEqMDdhklBtd75EnWe7hFeDM0N+NaLjvVxchRB7mRCUXx09DuSTa o3jTtB/cSjmx059HPWZ/ziqyXZNmwWfkZYQz/bv9ldb2cl4qrNlcdzaP2PjzvF2YFfG6 KZ9Q== X-Gm-Message-State: AFq9FYIWhlj3HmNQPmWXbwKrSk0BSv8qi1WeWmZmm2+D7fzZdj5vzlvN sHVS/k1bD8RBjM7gsMzzGFDqlFgEjO9SQY1A1DxXjUaN2n/9sBdlDBFBSFBosH26 X-Gm-Gg: AYBFou1giJMefG8NXntBxDbiA6Gu3iGp5UXrxS1a4G6SaLX7eqWSSASFEsHk+2AaG/2 pOPYke8u6nHxfmGwe8mgxdsbmV9p7ObQVziGH4vJc4nYiV0AE+KI+rjTt9fj1RNNz7gm8rdFkfZ z9QPvfUFmuYcyduA4gPcn1cT21BwWXgeOC2KlWb/0V8z9+uwlnr4Dp6iVNREyywkigcqBMXMQFU CqrbAn1pBMusDwXlDwC21N5+iAObCPC7WqSsKvMXnaqBxlGc3WKHag2yvNBGFP1SE9x17//9U2W nymadUDRXwPZK9WR8mH0vSC2vmjSTaF1lmT08ndMObkNTZY3/WiI1n0zxLbEvzOZOWhrCy5wJkA 4e1EUrvfKROzcqMLdRZON/m/5ydM7AF8yMdKKn9W0Kg0xDmehfvJtOEiuW4LLEIYJCYxtyEJUfC CRrgT/KiftE1wYFd7qZxGrRwdNj/lv4ohzWYuXJa4pxARZNcfYG+pTeWG9W0oqwceSa9kxm3drs PUECV2pUWyjIUURp7EVEE4P40PbhOMNA5TXWKxL+ueKK6EzqyRHs4g1OVI9r1WH100slI7aFtdo YP1KFjNcBbMPQc4laKVHQu1/xjp4EMTjShKS+5mL6CL6aiOB53X5hixq5xw= X-Received: by 2002:a17:902:ecc9:b0:2e9:660a:7946 with SMTP id d9443c01a7336-2eb004b353fmr15398215ad.28.1793179628684; Wed, 28 Oct 2026 02:27: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 V19 11/14] monitor/hmp: display IOThread holders Date: Wed, 28 Oct 2026 17:26:16 +0800 Message-ID: <20261028092619.1654474-12-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x529.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: 1793179695290158500 Content-Type: text/plain; charset="utf-8" Display holder information in info iothreads to aid manual debugging. Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen Reviewed-by to patch 14 in the next revision. Please let me know if --- monitor/hmp-cmds.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 9b1b94f8ea..7f1b6c35fb 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -247,11 +247,31 @@ void hmp_info_iothreads(MonitorHMP *hmp, const QDict = *qdict) IOThreadInfoList *info_list =3D qmp_query_iothreads(NULL); IOThreadInfoList *info; IOThreadInfo *value; + IOThreadHolderList *h; =20 for (info =3D info_list; info; info =3D info->next) { value =3D info->value; monitor_hmp_printf(hmp, "%s:\n", value->id); monitor_hmp_printf(hmp, " thread_id=3D%" PRId64 "\n", value->thre= ad_id); + monitor_hmp_printf(hmp, " holders=3D"); + for (h =3D value->holders; h; h =3D h->next) { + IOThreadHolder *holder =3D h->value; + + switch (holder->type) { + case IO_THREAD_HOLDER_KIND_BLOCK_EXPORT: + monitor_hmp_printf(hmp, "[block-export: %s]", + holder->u.block_export.export_id); + break; + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + monitor_hmp_printf(hmp, "[qom-path: %s]", + holder->u.qom_object.qom_path); + break; + default: + g_assert_not_reached(); + } + } + monitor_hmp_printf(hmp, "\n"); + monitor_hmp_printf(hmp, " poll-max-ns=3D%" PRId64 "\n", value->po= ll_max_ns); monitor_hmp_printf(hmp, " poll-grow=3D%" PRId64 "\n", value->poll= _grow); monitor_hmp_printf(hmp, " poll-shrink=3D%" PRId64 "\n", value->po= ll_shrink); --=20 2.53.0 From nobody Mon Nov 23 04:18:27 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=1793179736; cv=none; d=zohomail.com; s=zohoarc; b=fKG/VpXzHpUYze2g+F8XhdCUFSHSo56DMTEV3lNOGxlFmdNr2WZC+wKH90lBC6m26t4NteH41dhZgtFp9vHFseIetvMwR2D/7zoXOzPxmmyjCDPx7ZCVjiIYDTWEQwiSOOA1Pxe8oFnGyY1iKWMYiuxtE+xXFXfgAAgc6PO8MC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179736; 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=iabqbCKSqp1YNDA2MncmA1e5Jv4boGZeCS0JYhOjvkU=; b=LGLuB+D36resfNoroGAL2wWNqENjJckKvz0Ne24YaC/mI3JKa9+62QzWiyXlUfKjAlbIlMUIo9pRfXj253niwK7mwCl+bAW+ZdB+I4cs7a5GNnQhydtpvBa9Oc/dsF4t7v0auk9vDFvV238DUg1APA8LIdVNaSys3rpZKMwaXxc= 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 1793179736359892.8112829479489; Wed, 28 Oct 2026 02:28:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzwD-0007Wl-Jy; Wed, 28 Oct 2026 05:27:17 -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 1xLzwB-0007Uo-SD for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:15 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzwA-0006j1-5p for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:15 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2e8f2c3ad6bso4228895ad.1 for ; Wed, 28 Oct 2026 02:27:13 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:27:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179633; x=1793784433; 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=iabqbCKSqp1YNDA2MncmA1e5Jv4boGZeCS0JYhOjvkU=; b=OOFvvspnofBpmxT8aJUVZ5xXApBzCWVKPV9x01qh6UAu9hz92YyEnQNHnzc4ouZXeZ 6KqhIdrTxzHkmO9eWR26/8gDKVaUiSlzxHQELUu3UM1YGr4pSdItWDkWAwvZ3nPGpie5 WtFTXVMLp0RhJxwdu1s15TCldI5f1FkBzjyq6ZspkuDbCAl6dUOwN78ZOxj1TcsuyITR BZQQWLD7JfQj3qb+MlGaPYCj9lFuywecO87Sl6AQQrX+8wZK9HjfnHf+lOQ1ocsszRxK q5pmhDzz3/BOiwp6ybmyrVnljPidP1DZwHjQSAEqjJMNddKYSPItFYgx8fzH2pKjiOkm RgKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179633; x=1793784433; 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=iabqbCKSqp1YNDA2MncmA1e5Jv4boGZeCS0JYhOjvkU=; b=zCzh8+rRNFo8nKKJjU5W4Jd5Y2yEeGJtHUgtDbqtToz9NjxXXo8lI4CO7nJIgfbGs9 OAdQRJYeULixJZI6daEbDoS4U+rxNH3ny9ZRHr6elR5ctCneiXzQ7vMm0A54tkEUAUZZ FrDp0V9BuF3UgRyKNHczPKVGgjQf54eX/zCZa9ykPP0ytlVRbKTFWOlic9t8xedfHk/w QZgMYvRB41+T5phcAtSSWoKSRNFg/Xy0vKcnjxfq/SeBE/ZmZZuRMatM6CEMjPCztSau EhllopKclcHUv7q/Xt0fOIX0/ouDLNDysgiGJ/Jj2hGfx+8zcnt0iM5b3cdc3R1nDlKh IXfQ== X-Gm-Message-State: AFq9FYIOpdOU7C2lSWShl5xcUpD42pMC469qmX8NwH92yEemfp6ueV8v rJerziCYVn6Y4xLwxFlp3t3sqOuPl0ccujEyse+mE4QGZcRhThbFH9qkEby0YgYa X-Gm-Gg: AYBFou3+WUQWseR+VzqLvCeBoXY4Ep0pKV3zCT2fODpie1Ups3Ee9BPgVVO8zY+z3G9 pVoFhxHT4UY9lrtOOrXZYsjIjyAuuHnO+vK87YdHaaaVjOUy5nJlI9WmckB2o3XZ9eaTlPTNTs1 0W6kt9LYLpl6k1yxtrLRBEn9toMqtRyJQANSA0asjVQ5RoJruJtpu+TxhbLpPMfZvuvoyZdl/ms S4qTLB87+fGF+56VLXIM6pPDXGA0FU9C7NYN4dTlS4E6ETHIhctbpGwjclOZ5XGs5HftIhwfTf1 L6+t8EUWBZ2JXCcgUG/g/M5sJSjGsaTTuddzzTkODrajxRKNYoOlGMN55tz0znujlzSMEJlwKUM nySA8GD4g3OesUEMocL8kkx5n/uc+fhh5SAwSfaNqDNl0CHVRZ+cjOU0NqtnN/NS3ivpR7iv+hM JJ2eKtgmUtl8AEnKFWLWFrpMhHYNETWbVOfN+KfZ9S23dKprUqoNVdnrf0IoJGSUIMjAXOM4rlr TMMK1LgPe0oXKTn8WUSC52d2IB3xuy1FYtjlx4k/IzuRnOkw3QcmGFZ8E1CNXpY290u0XkwoWB0 cdKQ1vEyzIWuOQZjo1wpdSB7J01+WNnthQaPunD7lW84vC1UeP6t/fKazPg= X-Received: by 2002:a17:902:d48f:b0:2e6:7c6:8d40 with SMTP id d9443c01a7336-2eb0036c529mr18379735ad.27.1793179632700; Wed, 28 Oct 2026 02:27: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 V19 12/14] iothread: make legacy AioContext getter explicitly unsafe Date: Wed, 28 Oct 2026 17:26:17 +0800 Message-ID: <20261028092619.1654474-13-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793179738913154100 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 Reviewed-by to patch 14 in the next revision. Please let me know if --- 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 5694e91bf7..36a2aadd53 100644 --- a/iothread.c +++ b/iothread.c @@ -435,7 +435,7 @@ char *iothread_get_id(IOThread *iothread) return g_strdup(object_get_canonical_path_component(OBJECT(iothread))); } =20 -AioContext *iothread_get_aio_context(IOThread *iothread) +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread) { return iothread->ctx; } --=20 2.53.0 From nobody Mon Nov 23 04:18:27 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=1793179736; cv=none; d=zohomail.com; s=zohoarc; b=JMOyd92QlZuFM8R19Jhbwd7sT6XfU6CQwEZtlOgQMc45qyTmrD2TWfd9t7KGzCjpFKoA0/jigVUzOZFntci+11qwgNQ1NYHBfud+VTtzC5uH5QBacRRafwI5/5YUufTzhxOrxuPCkbvmj7EvVEacZZnryTKwlwg530OZWY3/SmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179736; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YuPzNNXhmAaT4UyWYgVuYBYlY5/Chqo6IDGzlmZ2kHE=; b=JRneZQXNgYKO1HfhpwslyelwVLii/zH4KhSKR7wR7kPClaDb8ipU9vFF5bscph2QUmjVp9IY2Ft3hQOWTp4mrde8fSWJ7me5rZtdYNDW7pNMq0gcef8si5QQ9zbaZXEfKmrgOq2vr4PXKnSDuymPWJmg+VE5+DEmA6IIYXN8Z6M= 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 1793179736941689.663076695266; Wed, 28 Oct 2026 02:28:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzwH-0007f6-IM; Wed, 28 Oct 2026 05:27:21 -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 1xLzwG-0007bu-4u for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:20 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzwD-0006jS-Bi for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:19 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2e8246b13cbso5921935ad.2 for ; Wed, 28 Oct 2026 02:27:17 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:27:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179636; x=1793784436; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=YuPzNNXhmAaT4UyWYgVuYBYlY5/Chqo6IDGzlmZ2kHE=; b=Xzbhk1gWB/DxiDGmgmNo4c/6VeHXkkakEQ3v24LXJngg7Bbg1pn2eGHHBs8DZvuRZa d1vIV5GCzx369bXbYtb5hSlFqwumJp5v+4NmrNX1aTDueYT3Sai4wCILxqvKCIPOCPDJ mTnTu9RaUBDGm3dg8bK0NxglXfQr0mWV+0z3tkscqVp2/ecmGz0efWgZOhxW+Z3YdhYn hkr7qFm13e8okjirCSTufnbH+rJ9LtyK75mzre6uK3gqDgOAZBbI5aL8H12KrBEwbvTB ljUBBdy8nGNJemxcrISrSU9b1tkREc26K2fJ+TGCF8HqrE6hshhXZ96X2xi+kwTqS4df ldvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179636; x=1793784436; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=YuPzNNXhmAaT4UyWYgVuYBYlY5/Chqo6IDGzlmZ2kHE=; b=qE1KCYCR1tvAPkpTG7RO2ieD2k1E1WjX1TwBPUVCyMH3xotQr3KRSOCNFPM8EEhv5g A2JjywK5rVZp5AQYA2poNpPItygvChmqsTWrULaKyMQtaEqy98gkpy86Se5MGdxuBkec 3RAwplj9M8uNrZSLR8IBBD3i7erbBpG5cU/mKmIhhfA52Hsd8EA29xDtvDarWBclGriB FuoAXi6uqK1nU/y4RjCs0BXjvmVlhRBsmEI2R7uqcvES4piF1tH2UwDLwE02YipDFaQb ZUCQVLL0O9hOHvwh3JwmeHQAl10clqRJ7kcwlmYALR7bWCyWG5WJ/egiqePFQVk/wJy/ PQuw== X-Gm-Message-State: AFq9FYKQw51quw6XAD/FJsYh545QwrKzvSn1bVdHw4qi7fYXanmiIOt/ kux5bPYPFFRENxm6riJdIdFzjGwLKK4UCtdS/iEKz8krMSWaj/Eat6tQSkVzUzrU X-Gm-Gg: AYBFou1oe5PAh+9jGt7nv4I0QlvX1uWrt1w7jiLXZe32YM/dDZ0QiJH3215uwc+RvNB 0asHBCWI48ojrExxsQwBltfyvL4cUEicx0X0mF0Wzx04PFdYF0gsGUlAocPgcfGYIr2Hhb8a3T7 uxiDfXrDlDz3vErLhFFC/7a+dWrEys++ocRtIu1XLciiGxmbQuQls0zvQVYLGuCvnas7DoZHKbK +WEmLTIrj7+7QXYw65XcFstQusXBJHEMh197q4CWI4xxMyU1g8zKoa3qAO5jbazKkjHd1f2MNH6 0/PO+8C/DiX6TLv+W1XTsJAEveS+NUG9m7bG7Uyk1HLnKNVdFXOuloIXHIKjBuqhoelUxbnfLZd CiBkrJqqQ7Dk+nQqF3R7WfpC9sKAvTxzYm4ZwyT3f6Hnhm4Iqh7OH0VaAHvXGAgBWn4+gF/89os 8WBEeXmzxlmKtor8nmEzZQ5AUWNdOiG2YdnszG8AWhpGo+U49XM+IA99MtXAEsEkn6bLlfaCkLI JsH6pddl1CHXnzb3HUdBKaICby41lKaW5+gDGp2SwKQviNf5xyR5h0xjkpgQjeoct+o+LtKIh0Z qIqVFRyYLZVSgD6qHlhdQLhLDhxBBewLdvQi/uGGRfyQknZgVBfvfDLXK5E= X-Received: by 2002:a17:903:94d:b0:2e3:598:75b8 with SMTP id d9443c01a7336-2eb003c59f6mr16981705ad.27.1793179635903; Wed, 28 Oct 2026 02:27:15 -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 V19 13/14] tests/unit/iothread: update AioContext ref/put helpers Date: Wed, 28 Oct 2026 17:26:18 +0800 Message-ID: <20261028092619.1654474-14-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793179737349158500 Content-Type: text/plain; charset="utf-8" Update the unit-test IOThread stubs and callers to use iothread_ref_and_get_aio_context() together with the matching iothread_unref_and_put_aio_context(). Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen Reviewed-by to patch 14 in the next revision. Please let me know if --- tests/unit/iothread.c | 18 ++++++++++++------ tests/unit/iothread.h | 7 ++++++- tests/unit/test-aio-multithread.c | 5 ++++- tests/unit/test-bdrv-drain.c | 18 +++++++++++++----- tests/unit/test-block-iothread.c | 21 ++++++++++++++------- 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/tests/unit/iothread.c b/tests/unit/iothread.c index a363bf8f70..790cd2dce7 100644 --- a/tests/unit/iothread.c +++ b/tests/unit/iothread.c @@ -30,12 +30,23 @@ struct IOThread { bool stopping; }; =20 +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + IOThreadHolder *holder) +{ + return iothread->ctx; +} + +void iothread_unref_and_put_aio_context(IOThread *iothread, + IOThreadHolder *holder) +{ +} + static void iothread_init_gcontext(IOThread *iothread) { GSource *source; =20 iothread->worker_context =3D g_main_context_new(); - source =3D aio_get_g_source(iothread_get_aio_context(iothread)); + source =3D aio_get_g_source(iothread->ctx); g_source_attach(source, iothread->worker_context); g_source_unref(source); iothread->main_loop =3D g_main_loop_new(iothread->worker_context, TRUE= ); @@ -113,8 +124,3 @@ IOThread *iothread_new(void) qemu_mutex_unlock(&iothread->init_done_lock); return iothread; } - -AioContext *iothread_get_aio_context(IOThread *iothread) -{ - return iothread->ctx; -} diff --git a/tests/unit/iothread.h b/tests/unit/iothread.h index eb4d0c77f8..9bdac074c0 100644 --- a/tests/unit/iothread.h +++ b/tests/unit/iothread.h @@ -17,9 +17,14 @@ #include "qemu/thread.h" =20 typedef struct IOThread IOThread; +typedef struct IOThreadHolder IOThreadHolder; + +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + IOThreadHolder *holder); +void iothread_unref_and_put_aio_context(IOThread *iothread, + IOThreadHolder *holder); =20 IOThread *iothread_new(void); void iothread_join(IOThread *iothread); -AioContext *iothread_get_aio_context(IOThread *iothread); =20 #endif diff --git a/tests/unit/test-aio-multithread.c b/tests/unit/test-aio-multit= hread.c index 9179cdc6a3..66ba5a466b 100644 --- a/tests/unit/test-aio-multithread.c +++ b/tests/unit/test-aio-multithread.c @@ -69,7 +69,7 @@ static void create_aio_contexts(void) =20 for (i =3D 0; i < NUM_CONTEXTS; i++) { threads[i] =3D iothread_new(); - ctx[i] =3D iothread_get_aio_context(threads[i]); + ctx[i] =3D iothread_ref_and_get_aio_context(threads[i], NULL); } =20 qemu_event_init(&done_event, false); @@ -87,6 +87,9 @@ static void join_aio_contexts(void) for (i =3D 0; i < NUM_CONTEXTS; i++) { aio_context_ref(ctx[i]); } + for (i =3D 0; i < NUM_CONTEXTS; i++) { + iothread_unref_and_put_aio_context(threads[i], NULL); + } for (i =3D 0; i < NUM_CONTEXTS; i++) { iothread_join(threads[i]); } diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 43b0ba8648..05c31ffca8 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -537,8 +537,8 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) =20 IOThread *a =3D iothread_new(); IOThread *b =3D iothread_new(); - AioContext *ctx_a =3D iothread_get_aio_context(a); - AioContext *ctx_b =3D iothread_get_aio_context(b); + AioContext *ctx_a =3D iothread_ref_and_get_aio_context(a, NULL); + AioContext *ctx_b =3D iothread_ref_and_get_aio_context(b, NULL); =20 QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); =20 @@ -612,6 +612,8 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) =20 bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(a, NULL); + iothread_unref_and_put_aio_context(b, NULL); =20 out: iothread_join(a); @@ -762,7 +764,7 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, AioContext *ctx; =20 iothread =3D iothread_new(); - ctx =3D iothread_get_aio_context(iothread); + ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); blk_set_aio_context(blk_src, ctx, &error_abort); } =20 @@ -892,6 +894,10 @@ static void test_blockjob_common_drain_node(enum drain= _type drain_type, bdrv_unref(src_overlay); bdrv_unref(target); =20 + if (use_iothread) { + iothread_unref_and_put_aio_context(iothread, NULL); + } + if (iothread) { iothread_join(iothread); } @@ -1398,8 +1404,8 @@ static void test_set_aio_context(void) BlockDriverState *bs; IOThread *a =3D iothread_new(); IOThread *b =3D iothread_new(); - AioContext *ctx_a =3D iothread_get_aio_context(a); - AioContext *ctx_b =3D iothread_get_aio_context(b); + AioContext *ctx_a =3D iothread_ref_and_get_aio_context(a, NULL); + AioContext *ctx_b =3D iothread_ref_and_get_aio_context(b, NULL); =20 bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, &error_abort); @@ -1410,6 +1416,8 @@ static void test_set_aio_context(void) bdrv_try_change_aio_context(bs, qemu_get_aio_context(), NULL, &error_a= bort); =20 bdrv_unref(bs); + iothread_unref_and_put_aio_context(a, NULL); + iothread_unref_and_put_aio_context(b, NULL); iothread_join(a); iothread_join(b); } diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 5273ff235a..fc9735d056 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -466,7 +466,7 @@ static void test_sync_op(const void *opaque) { const SyncOpTest *t =3D opaque; IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; BdrvChild *c; @@ -493,6 +493,7 @@ static void test_sync_op(const void *opaque) =20 bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 typedef struct TestBlockJob { @@ -549,7 +550,7 @@ BlockJobDriver test_job_driver =3D { static void test_attach_blockjob(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; TestBlockJob *tjob; @@ -595,6 +596,7 @@ static void test_attach_blockjob(void) =20 bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 /* @@ -612,7 +614,7 @@ static void test_attach_blockjob(void) static void test_propagate_basic(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx; BlockBackend *blk; BlockDriverState *bs_a, *bs_b, *bs_verify; @@ -658,6 +660,7 @@ static void test_propagate_basic(void) bdrv_unref(bs_b); bdrv_unref(bs_a); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 /* @@ -676,7 +679,7 @@ static void test_propagate_basic(void) static void test_propagate_diamond(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx; BlockBackend *blk; BlockDriverState *bs_a, *bs_b, *bs_c, *bs_verify; @@ -736,12 +739,13 @@ static void test_propagate_diamond(void) bdrv_unref(bs_c); bdrv_unref(bs_b); bdrv_unref(bs_a); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 static void test_propagate_mirror(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx =3D qemu_get_aio_context(); BlockDriverState *src, *target, *filter; BlockBackend *blk; @@ -807,12 +811,13 @@ static void test_propagate_mirror(void) blk_unref(blk); bdrv_unref(src); bdrv_unref(target); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 static void test_attach_second_node(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx =3D qemu_get_aio_context(); BlockBackend *blk; BlockDriverState *bs, *filter; @@ -840,12 +845,13 @@ static void test_attach_second_node(void) bdrv_unref(filter); bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 static void test_attach_preserve_blk_ctx(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; =20 @@ -871,6 +877,7 @@ static void test_attach_preserve_blk_ctx(void) blk_set_aio_context(blk, qemu_get_aio_context(), &error_abort); bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 int main(int argc, char **argv) --=20 2.53.0 From nobody Mon Nov 23 04:18:27 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=1793179735; cv=none; d=zohomail.com; s=zohoarc; b=BmRNOS38pnHJJDGIPbYp2f5J5DU6fAviQreFpwIVLgN4y6wGNvbOWGqsZcOdlT2+4qEhRg7pA0j/phNxkuNJnBmjp+KDcCfGgiL+xX7czuzYwC5WfPm9IKvDOSp+RFXg7plCrcFTg2nUT1uTaYWIKDnbGYTNibsjTvXc+uQ6mxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793179735; 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=z65zVelmLx1fFCAo4lDjRGL/KahgCS4BHF2UkQlOECk=; b=EeTRoNkQxIh+v1tpMRGVmVGbcfVLMhSfCzWNhcIngUnztowBQL/UudKn5zBk5tJzAdd7buDf3xHC3pycAJOQ/scGJgINI8Ddret/U8vfUjRyYrKVXlAwB+YmybHlcyuiaox0d2iX636R7QAQFle3Ez3fkqjWQ0Si3l+7kSOPlgk= 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 1793179735047268.23468606001234; Wed, 28 Oct 2026 02:28:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLzwK-0007l2-TW; Wed, 28 Oct 2026 05:27:24 -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 1xLzwI-0007gr-8L for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:22 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xLzwG-0006jz-Lw for qemu-devel@nongnu.org; Wed, 28 Oct 2026 05:27:22 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2ea1e7fad99so4430295ad.1 for ; Wed, 28 Oct 2026 02:27:20 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eae6b7a691sm19481635ad.26.2026.10.28.02.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 02:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793179639; x=1793784439; 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=z65zVelmLx1fFCAo4lDjRGL/KahgCS4BHF2UkQlOECk=; b=IaIkrcxmPLKzdsHsorn/fgrzMk3ibawvQMhw/DBw9Buz1QNundnzJkMYbtnyZ/vkK9 fOtNcx44G2fPPXIevEXubJzKar0R7JDA0ebFi9OqY9onkhW4P9s1Pdohwika0niYeNKR ElsP78Jc6sDVvow0+44YzmgMxen8D58F02VJOQqnvaNxWk8FyM5xF8ABuN6TyuJpwO6Z 9ov6Okvj8R6lBa2dZIAvvU5cG2XhdH/F5AStK2VagNPAxSGa66WbyhNYfF7jjqyrrCPQ iUO5YtmxomSfdeFYH7qnGzhbyfzmVH4DTFdy2v92Z7fD8aASQGcrKwr9ujLVy9SvcYyi k/Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793179639; x=1793784439; 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=z65zVelmLx1fFCAo4lDjRGL/KahgCS4BHF2UkQlOECk=; b=FffFTpj/TgrVi7OewvSNU77d60MSYrtn8DYBBZjxILZxDBuK9a7ByG2aEWoSCHlzS+ VSv1Bppz2ECQppr4LS+OMM0lZLIHD0nua8EEhNGWDNr2k7+eXzXsRYh0yzLZIu7E2k6i Fy41uYRwisYscQ7dk+j/o/C+1bbILXGdqsAybDqbbTSibshTZS1vC3v0tQQ/RJ6UT1nE MAsOKI1OXV04yyrdB1U0HRg8Hhg1KjWDOPZ8O4fPZJw3uwfC84TcusfZc9UpNqIZJVSJ fZ+bKpWWgCT/YNMzra1ldSdckn2PwTAM0RxOCNauTfrVdMV8j33S1Psu/FDXydBtTpnI 6Dwg== X-Gm-Message-State: AFq9FYJ+ye/37NQMvxnNxXYWqjJCfkVzgGPW6kbfTB8RTF90AZ9/to6l O41nvrB6kSaD8l/gfSab6inmjOCs7e9fDUFrlB/PRpp4mkBgP50STrk1B9QNlpwg X-Gm-Gg: AYBFou1v4cFRz9ekgN4cPX08pXjH8dQy2lwJkSv/fpfOmuD+9ai/Dk2al/C/AWwCYAX Emdye7tVu82tBCYerhcAA1IgnVBd+UBvFL2XuUP+6v5K0WhlEw4iWpofms+4N8m9Qnc+AGnQIwo rxaq6lJ27x1/ICxhiZv1zEd67mSWgQqnz75zVyikdAPH/oeGpnfp8VHaJ+nLSUbKmn5sxS88vt5 v/aZuslFH8Kpy8M6xP4Z8rYeqYjCuMDsWmXKhWDlfXy36a6c7mJNXTZZ9/k34Yq8KnThxzBDT8Y IuBjUeBYhS/JVWCxzXuI2KS29VMwSJUBwHBNdbIhi8oedw1T/iSK4JrjFKWC0e+WIRe9D723tho XoTZ+mTXcaAF6909NPpHmdYCEfHiPMT3sq8aKDiTQo/bqmNGfAOLv71JbDtAa2DI90arn7rDSev rK63xAWDBeSqQAt5BgnhjbET7TrBlmS4DIyAb2yKc6IX5G9RAHlaOxsIf4Ck7SL0U7RWQXkgqlP NiZOFeqxi7o/aKJ9hNH9CNDrfeAfC4LaSoSZori0FocWg9qKq1Rm2WoB6Wbotk9PV9GUKOfWJnr 1z+5YeGe1V9p5cdVb8P+rt5bAp30k1gQEH0S+5MIX92Aihabpof2EElzs73Gqu+0YIbUdtgEmE9 oqAvC X-Received: by 2002:a17:903:2f08:b0:2e8:3d48:4d80 with SMTP id d9443c01a7336-2eb004ed893mr15717005ad.45.1793179639393; Wed, 28 Oct 2026 02:27:19 -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 V19 14/14] docs/devel: document holder-aware IOThread AioContext APIs Date: Wed, 28 Oct 2026 17:26:19 +0800 Message-ID: <20261028092619.1654474-15-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261028092619.1654474-1-zhangckid@gmail.com> References: <20261028092619.1654474-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1793179735189158500 Content-Type: text/plain; charset="utf-8" Replace the obsolete iothread_get_aio_context() reference with the holder-aware API. Document matching get/put calls and their BQL requirements, and clarify that the unsafe accessor is for legacy callers only. Signed-off-by: Zhang Chen Reviewed-by to patch 14 in the next revision. Please let me know if --- docs/devel/multiple-iothreads.rst | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/devel/multiple-iothreads.rst b/docs/devel/multiple-iothre= ads.rst index a6eb046267..3bd8144ecc 100644 --- a/docs/devel/multiple-iothreads.rst +++ b/docs/devel/multiple-iothreads.rst @@ -88,11 +88,20 @@ argument, which is used to check for and prevent re-ent= rancy problems. For BHs associated with devices, the reentrancy-guard is contained in the corresponding ``DeviceState`` and named ``mem_reentrancy_guard``. =20 -The ``AioContext`` can be obtained from the ``IOThread`` using -``iothread_get_aio_context()`` or for the main loop using -``qemu_get_aio_context()``. Code that takes an ``AioContext`` argument -works both in ``IOThread``\ s or the main loop, depending on which ``AioCo= ntext`` -instance the caller passes in. +The ``AioContext`` can be obtained from an ``IOThread`` using +``iothread_ref_and_get_aio_context(iothread, holder)``, or from the main l= oop +using ``qemu_get_aio_context()``. Code accepting an ``AioContext`` works w= ith +either event loop. + +The ``iothread_ref_and_get_aio_context()`` registers a holder and takes +an IOThread reference. After the caller has finished using the context, +release the reference with ``iothread_unref_and_put_aio_context()``, passi= ng +the same IOThread and an equivalent holder. Both calls require the BQL. +No matching IOThread put is needed for the main loop's context. + +``iothread_unsafe_get_aio_context()`` neither registers a holder nor takes= a +reference. It is for legacy callers that ensure the IOThread's lifetime +themselves; new code must use the holder-aware API. =20 How to synchronize with an ``IOThread`` --------------------------------------- --=20 2.53.0