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 B3849C5DF97 for ; Sat, 22 Aug 2026 21:35:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wxtMN-0003i3-Eb; Sat, 22 Aug 2026 17:34:39 -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 1wxtMK-0003hq-6m for qemu-devel@nongnu.org; Sat, 22 Aug 2026 17:34:36 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wxtMI-0000jT-G2 for qemu-devel@nongnu.org; Sat, 22 Aug 2026 17:34:35 -0400 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-c9e607d81fcso1334472a12.2 for ; Sat, 22 Aug 2026 14:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787434473; x=1788039273; 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=4pWn6FsJfOpSFK+gwenZ9GknoUKvDRZidZ6l+4QLqTg=; b=NPfI4kIE6v+A14Eq25VSgz19ryzymZvdo+iT9Hj1jExmAUe3MgkA1Sdw8uo8aytQB+ XxlcNbvYfKyxknz/rOS/czQQTdR6/Ot1IeIFTLDZ96eyIvyB339orULmuZsCvd33BOPv TYh/LpjY6s1owXQDJKoUd0Kr0buzrlnjnPieuz6FqHEQ2SfpSZx3i0LqAHMm/naH7Z6x xsefJs1lZQO0MoJo97GtZ20ELhAGjfwuwFbiNCSM3WGuTekDqyqyF6e3Wxwse6z/EVM9 h8UUbesw3fMkFsLllWJxhS+/IExUhw4rT15REHoyVADvJX+pueRHPgkzStPcHTDfCEds gR1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787434473; x=1788039273; 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=4pWn6FsJfOpSFK+gwenZ9GknoUKvDRZidZ6l+4QLqTg=; b=WaAU1JL4RkYhItYp7neU/TDK+v/eCGGp+/4hUwalJeR/D0Kh641LsT7PsziIIQ5HHo 0C1IInU61JIMmoeueVtkK3EZHFT5l9KXmgUY6Kck0Ru4fWA+Ovt322WKVG3Wlnydksog rPumILyZanErrI2FDhZT6jjGWP6peZ5tZbg5Sq14tOySUY2Q/qhQKe/tkA/tQmjoYOQ3 z1gDiYcoKPpmO1NjF9WkgARXKRoZWYNOx7/Sf56oUQDHS+Bfcd4di6mnrJMz/hPR1jod fmBcn96HY/2TrPUc5lIZIHBkp5+2r+WPW/kDiYorREIK8Wf43y4nF8M4DV1r1HJHpb9s 298g== X-Gm-Message-State: AFuF++md6VOLbzg7IirJxzgNiLRRt4xyfxlvnpyq8UJCaMQD/UtbelJk da1frYXYZHHFyGFd7nZGt21RrRy/dPXyDTBhWYxPsus6gPBpNNx+NfAHI2mcRWeh8DY8N+yX X-Gm-Gg: AR+sD10PYGiENh5pYzgDuSkEUNWI4xsOQfgkIny5IHPvblMflbWekXajaFAWStMnYln RDIatjp0ZQTtd0iC+sV4Px0M7zzntWjWs0MAz4/DT/SrN/8z4wEj0+UbJoT7gIr2UYHFBxBxJvk kh7toSxHmrTMqfDQZA3XB/EgKctX2+mNAC/blMkkGtCOy3uJg5aFBMaUMTFUb59F0wCyGOXWtnE V/9JG8gJ4TjtwKvMPJYjN84C//UpVs2s8efGAoXi/rlHteNNjyw0+cpi7L16Bb9MirCbfLYdjbx cJIr6s/TlTdSRcDVIGNIRDbNxRxkny7v/p6haMHIkvW71dqIuzJvl6OnHClGRBhfsYd/nxnOT4T CYuszPXXi9nFK4voMJOx9zCkpeVvaImfIatMWH/x2XGZrFnCvPZk1/3jvWiSZN7eIy8obz+K1u+ Xe9T+qBRnwTcF+bEnPvcQ5VNqXT2t36paYqhJ5KyvfpMQ81rFHHGeNFiZB+bE9u7D0/thQaf8mZ r3pnKz8 X-Received: by 2002:a05:6a20:3d1e:b0:3cc:92d9:80cb with SMTP id adf61e73a8af0-3cd3003b104mr28076738637.12.1787434473155; Sat, 22 Aug 2026 14:34:33 -0700 (PDT) Received: from catgo-fnos.taila0cd24.ts.net ([104.28.201.73]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-327f909c6c9sm11633181eec.6.2026.08.22.14.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Aug 2026 14:34:32 -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 V13 08/15] virtio: track IOThread references for thread pinning Date: Sun, 23 Aug 2026 05:33:31 +0800 Message-ID: <20260822213343.661939-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260822213343.661939-1-zhangckid@gmail.com> References: <20260822213343.661939-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=zhangckid@gmail.com; helo=mail-pg1-x533.google.com X-Spam_score_int: 26 X-Spam_score: 2.6 X-Spam_bar: ++ X-Spam_report: (2.6 / 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_BL_SPAMCOP_NET=1.347, 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 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 --- 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 4b2cf3d52f..db7f513da5 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1469,6 +1469,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, @@ -1493,8 +1494,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, @@ -1505,13 +1504,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++) { @@ -1526,18 +1527,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 26ecefd547..55bbf045ce 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.55.0