Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E6C5606A31A for ; Wed, 28 Oct 2026 09:27:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=mpd0gRce 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) 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) 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) 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> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Use the virtio device canonical QOM path as the holder when virtio-blk and virtio-scsi acquire an IOThread AioContext. Replace the raw object references with the holder-aware acquire/release helpers so the users are visible through IOThread introspection. Signed-off-by: Zhang Chen Reviewed-by: Stefan Hajnoczi --- hw/block/virtio-blk.c | 23 +++++++++++++---------- hw/scsi/virtio-scsi-dataplane.c | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 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(VirtIOBlock *s, Error **errp) VirtIOBlkConf *conf = &s->conf; BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path = object_get_canonical_path(OBJECT(vdev)); if (conf->iothread && conf->iothread_vq_mapping_list) { error_setg(errp, @@ -1575,8 +1576,6 @@ 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, @@ -1587,13 +1586,15 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlock *s, Error **errp) return false; } } else if (conf->iothread) { - AioContext *ctx = iothread_get_aio_context(conf->iothread); + const IOThreadHolder io_holder = { + .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path = path, + }; + AioContext *ctx = iothread_ref_and_get_aio_context(conf->iothread, + &io_holder); for (unsigned i = 0; i < conf->num_queues; i++) { s->vq_aio_context[i] = ctx; } - - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(conf->iothread)); } else { AioContext *ctx = qemu_get_aio_context(); for (unsigned i = 0; i < conf->num_queues; i++) { @@ -1608,18 +1609,20 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlock *s, Error **errp) static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s) { VirtIOBlkConf *conf = &s->conf; + g_autofree char *path = object_get_canonical_path(OBJECT(VIRTIO_DEVICE(s))); assert(!s->ioeventfd_started); if (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) { - object_unref(OBJECT(conf->iothread)); + const IOThreadHolder io_holder = { + .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path = path, + }; + iothread_unref_and_put_aio_context(conf->iothread, &io_holder); } g_free(s->vq_aio_context); diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.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 **errp) VirtIODevice *vdev = VIRTIO_DEVICE(s); BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path = object_get_canonical_path(OBJECT(vdev)); 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 **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, path, errp)) { @@ -75,13 +74,15 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp) return; } } else if (vs->conf.iothread) { - AioContext *ctx = iothread_get_aio_context(vs->conf.iothread); + const IOThreadHolder io_holder = { + .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path = path, + }; + AioContext *ctx = iothread_ref_and_get_aio_context(vs->conf.iothread, + &io_holder); for (uint16_t i = 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] = ctx; } - - /* Released in virtio_scsi_dataplane_cleanup() */ - object_ref(OBJECT(vs->conf.iothread)); } else { AioContext *ctx = qemu_get_aio_context(); for (unsigned i = 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 = VIRTIO_SCSI_COMMON(s); + g_autofree char *path = object_get_canonical_path(OBJECT(VIRTIO_DEVICE(s))); if (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) { - object_unref(OBJECT(vs->conf.iothread)); + const IOThreadHolder io_holder = { + .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path = path, + }; + iothread_unref_and_put_aio_context(vs->conf.iothread, &io_holder); } g_free(s->vq_aio_context); -- 2.53.0