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 7F95CCDB479 for ; Wed, 24 Jun 2026 07:11:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wcHkx-0005bt-BQ; Wed, 24 Jun 2026 03:10: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 1wcHjy-00056f-3p for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:42 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wcHju-00035U-Vh for qemu-devel@nongnu.org; Wed, 24 Jun 2026 03:09:41 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-c8b49639fbaso458947a12.0 for ; Wed, 24 Jun 2026 00:09:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782284978; x=1782889778; 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; bh=31eqi3lh8ZxCXKz2hnzO9aMe8wTk2WViYcoK9qnefZM=; b=TncLBJemzOC+5pyJP8Mzmws8tJtT5We3fSrV+ORyimFs01HXm67gVRG8vwEHN6USFk AWnTMsfnrfMzBWlSNfC5saLz/Hw1JrOZTQWcvuCB2Is1bd0Gdh5Lmd3hxu2sWQN7FQP8 XIDMx0QY6uLbB7RnvvGfa5DJrDuHOLCqYKn6YiEdtjFnMyDa3Q5wiZ9ZIQnZaE2MFrKG qTOb+vjfXrbvb8rixdaf3uJf1XGXYgFZqJBJQXrgiGBjKTKgPuIZHjyq132VJQk1lvVC pkLFK07toQgNvkGpzbgcEOYRDN+3w3m3ER2XzDMMzTgx09onORXks/zyyIQs++tb5DYS r7Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782284978; x=1782889778; 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; bh=31eqi3lh8ZxCXKz2hnzO9aMe8wTk2WViYcoK9qnefZM=; b=QgRxItyUxJoILXIRhJl5YWoZZ89g/GU5hcpJ791Sjq/314O7Oilmycr4yo4DAHWikc JsraFEZn7ON7eJRGCqRzjkRpY+oCss03vYFjytS5ACMwcwsU53SqFMnkZlrrMOaL7jE0 Yy0dX9+r5tCyNEIPoSn4fv6mslsnnelvnd9cSt7oyFaUT9lkJB6kSYySDriC5DugtP7U xoQPzbTdk1Gd/zj9rjODzfUygO6wYSfnkhdXVuvgksP7CWENc7LRcoxowKEe4VW6q164 WaStSX8/p84ovMsnYenwvQY3Ck60dfOVdFfe7aIsAHkiWiB6l8vgaGR4MH+z27x908q9 3WbQ== X-Gm-Message-State: AOJu0YyH5fiKFgL1EN3ii1ch5qgkPWPFBIYzJ/Y9PwXJaUdZhG0dsp3U Hkf+iWTV1LVd16WugNQjwy8etLqy2o0BprTpDwJMYAHgOXXUiuDwaA2jc3Kz6Jk7KOI= X-Gm-Gg: AfdE7cm1ReQfYGHzME8t3ri4VkVyuZkxG292/Ogr77u1G0Gg9p2x7veTWC2Q/YGCk6+ F8ByujlxQFhY04ts58WQIWWOWKCRuE+XR8RTCK9+UU5gAJbn/b4ljgrwGEBwqOQn8ke9DByZq8l qaT+KvNikJYnOMNMH0UL/dVG726gXOO9Bam+4Jro9uTiGq71vAjddOYrsb4/z5zNpb9gDAKH5dA 8zZppcjt08h9ghKMUYPVtO5o5TU4KZEt0hx5h6R1TjzXT2l3vlvSQ35jbJequFJFA0CZViVP6DZ 9b3xd1d4sqK2GTonoaKMHGClrUI3t3Bzqgqmw8hOBGdfhvknYhSgqMHjZCv0oksSZRekIH2kRDs Z5dDUvt+pXB3jwRmI3xDknbHG8NTqf6pMXwG1z7rzQj8KCfmnZBUytuieAFrc6jZ1758+qRoquB KVGBTSqmYl3d2k6M/3B1bDnx44EEg4TpmEKPvjyuOIC/+w+Sew2cli X-Received: by 2002:a05:6a20:c916:b0:3b3:2703:124 with SMTP id adf61e73a8af0-3bd152357b7mr7792865637.39.1782284977684; Wed, 24 Jun 2026 00:09:37 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([2408:80e0:41fc:0:fe49::1277]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8bc2c8e92asm10736569a12.2.2026.06.24.00.09.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 24 Jun 2026 00:09:37 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf , Jason Wang , Fam Zheng Cc: Zhang Chen Subject: [PATCH V9 09/17] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Wed, 24 Jun 2026 15:08:43 +0800 Message-ID: <20260624070851.13342-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260624070851.13342-1-zhangckid@gmail.com> References: <20260624070851.13342-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x531.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+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 9cb9f1fb2b..30e9fcf870 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1487,9 +1487,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; @@ -1521,7 +1524,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.49.0