From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C7ECAC5AC67 for ; Thu, 6 Aug 2026 20:27:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ws4gD-00046Q-OG; Thu, 06 Aug 2026 16:27:05 -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 1ws4g5-0003xy-QP for qemu-devel@nongnu.org; Thu, 06 Aug 2026 16:26:59 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ws4g3-00050i-Nn for qemu-devel@nongnu.org; Thu, 06 Aug 2026 16:26:57 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-8486ac3f347so1561673b3a.1 for ; Thu, 06 Aug 2026 13:26:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786048014; x=1786652814; 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=roMLuC4QA71TtSV8k+RZp39kgVvreNxkTYnoEYN3Thk=; b=einJoHRH8oqvQscA7MjkWBKoxRjlpzYRm0yhCAVoCNSElHbQ9yxMo6EKRsL5mBakgr MOZXqFyfWmL5JX8gT1tW5/F6UxtKqWwUgmOXDKMXfYuIFZ+RJCbMySe9QQBEhJ/Qo8L1 sxFqkA6Qzs+6N2v/niOWYmrtoZAz74mHIn4/mT0m7ddrq1zw3aZHO/rObZCPxMtfH7ui PPUNaG4scnIPQlY0I/DynCInM//GQKHHHSPY0ARfbVD9x5cNdhi/xuUzoHAh9zrISVCG HJVM+78EI+LfO49DS16KPICozwmFJ6giWvs9Se6/59SdEPfsBOY9APWezNSV0IEpBfyD tK7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786048014; x=1786652814; 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=roMLuC4QA71TtSV8k+RZp39kgVvreNxkTYnoEYN3Thk=; b=N/00H4uZS8/7a1mENQH0KehPYupzU89ADn+hrg5TKu1oDjrEm535nCYh/bPcsEMshO WogzYJaxoVtiubctaSD2hJVVyDrODwkrGfVpZR2jzFrVC3Fj/cfwumkru/9hV6B4kZhH Ket6YDfsB7h+24TP2w4sWOuuNUdyMYcJl7pTje8xNia6pN9GW1M3QiRV/aqgRKZyLoj4 3JeIzZFqJYMo6q7AT4Jynuj/BUEAdJy+vbi6qEXejx8NHlk23TK73JV62oSBaPUYA0CI 8/6IMH84dHmZRJVmBdIJQ0ynA9aqyGfeVZ3No+omWUxOiAqdEeyVrDEcUrg91u7D4nz5 YSnw== X-Gm-Message-State: AOJu0Ywte9MaZjJjtx6W99Gf5mb83Yc42oEvKAcdFV1tYOW8ZPWk57w6 m9qx1/PHm/njE/xWQuxN9Ob/TrLXYxnLBcH8VEWwJ6SmYYzRLWPxsliBgcbrDYjmEc/0V65f X-Gm-Gg: AR+sD12O/J3iSRPGtQTbDdd1n3A1yX3F1o48EoK7HQ6/NjPxCgfhKjWdIeXcdkb32QD 9az/9/M0KAHRBlLfoPloQ5d8dZz4aUpWPL6or9b1DIFOjtq86bLm6wtI7AizkqqwzW+1NAsgMKJ 1wRdiEUQKddUE7hgMgMr8zmyTVV+YsnizAQthucFUlmywnrmZhdNLAcCsCnrUh+/k9MK5L04rfD MaqnCO3VKObiccl6HDTh5t9J29CeMQqA2IpPMLoPDJzPM/79qAJIZu7bL1kBwQVV0U6a5Ba15EE W5U3q/5JKahXnW5xGZ5UoaBCBrVTL9nfTojZY7aEuoYLtrk+a4/53vLbI93/VpFFhQhvLrdgd1N 31uWb0HVZquX8luZ0X0S8adV40+ZWLNFSDPuspBKOkd0+zoxbjOFBrsJrtRJeOb7h3aRWvg9c7V BCU4T678XGHGDGGnHCLGBttox5Rroem1QvPH1f7AHWa4yJ38Gq+BixFN27lL4Euc/NrzEmgfElM eHXKB619N25fRLZ X-Received: by 2002:a05:6a21:9cc8:b0:3b4:7459:85a0 with SMTP id adf61e73a8af0-3cb9c291f2bmr12091110637.18.1786048014323; Thu, 06 Aug 2026 13:26:54 -0700 (PDT) Received: from t-kidd-X299-AORUS-Gaming-3-Pro.lan ([104.28.201.73]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-315863fd2b3sm33140471eec.7.2026.08.06.13.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 13:26:53 -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 V11 07/15] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Fri, 7 Aug 2026 04:25:16 +0800 Message-ID: <20260806202531.243806-8-zhangckid@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260806202531.243806-1-zhangckid@gmail.com> References: <20260806202531.243806-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=zhangckid@gmail.com; helo=mail-pf1-x431.google.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Replace raw object_ref/unref calls with iothread_get/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 --- hw/block/virtio-blk.c | 8 +++++++- hw/scsi/virtio-scsi-dataplane.c | 9 +++++++-- hw/virtio/iothread-vq-mapping.c | 20 +++++++++++++++----- include/hw/virtio/iothread-vq-mapping.h | 6 +++++- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 6b92066aff..4b2cf3d52f 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1493,9 +1493,12 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlock *s, Error **errp) s->vq_aio_context = g_new(AioContext *, conf->num_queues); if (conf->iothread_vq_mapping_list) { + g_autofree char *path = 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 = NULL; @@ -1527,7 +1530,10 @@ static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s) assert(!s->ioeventfd_started); if (conf->iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list); + g_autofree char *path = object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } if (conf->iothread) { diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c index 95f13fb7c2..26ecefd547 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] = qemu_get_aio_context(); if (vs->conf.iothread_vq_mapping_list) { + g_autofree char *path = 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 = NULL; return; @@ -94,7 +96,10 @@ void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s); if (vs->conf.iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list); + g_autofree char *path = object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, path); } if (vs->conf.iothread) { diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mapping.c index 55ce62986c..2cb48dd387 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( for (node = list; node; node = node->next) { IOThread *iothread = iothread_by_id(node->value->iothread); - AioContext *ctx = iothread_get_aio_context(iothread); + IOThreadHolder io_holder = { + .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path = (char *)holder, + }; - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(iothread)); + AioContext *ctx = iothread_ref_and_get_aio_context(iothread, + &io_holder); if (node->value->vqs) { uint16List *vq; @@ -120,13 +124,19 @@ bool iothread_vq_mapping_apply( return true; } -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list) +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder) { IOThreadVirtQueueMappingList *node; for (node = list; node; node = node->next) { IOThread *iothread = iothread_by_id(node->value->iothread); - object_unref(OBJECT(iothread)); + IOThreadHolder io_holder = { + .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path = (char *)holder, + }; + + iothread_put_aio_context(iothread, &io_holder); } } diff --git a/include/hw/virtio/iothread-vq-mapping.h b/include/hw/virtio/iothread-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); /** * 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); #endif /* HW_VIRTIO_IOTHREAD_VQ_MAPPING_H */ -- 2.53.0