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 8196EC44515 for ; Thu, 16 Jul 2026 17:22:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkPme-0005vh-Uk; Thu, 16 Jul 2026 13:22:04 -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 1wkPmd-0005vH-DU for qemu-devel@nongnu.org; Thu, 16 Jul 2026 13:22:03 -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 1wkPmb-0000Uf-Oa for qemu-devel@nongnu.org; Thu, 16 Jul 2026 13:22:03 -0400 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-c9e607d81fcso2314782a12.2 for ; Thu, 16 Jul 2026 10:22:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784222520; x=1784827320; 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=j0mhc/RYVCfvpLXWToM2n3L+ExBKX6NiykYMZhvUJag=; b=Ebo8um1IOONkF+p7sj2oFdlw39fNAqw1nt/22Z3GcMaVjwnvqCbRF++71vS31kQ+9Y 4TwMvYGxl4vI9q/Pn3romiadfceO9SQJFcK4tlx3pwezBCke0xL2cDv97ucqlc5DL1an KLdXx56/y2Dg7FcjuctLs50wuXUiUiYLP11WoS9Q5ZTQZutVYquQM3NzWBrb4INtoQTI c6LtMPtK+w+3JINqkxFGYjo/SgL9N9OB6iwMtApXtlj+ZCW4hOy/vpLaUnSnjaqelueH Voi6zuc1yU3XKPy3wUzznFfeviG2qvcanFLwbhJgyH97JwvnrHMpq6bOA3VyERGYFnjR +XWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784222520; x=1784827320; 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=j0mhc/RYVCfvpLXWToM2n3L+ExBKX6NiykYMZhvUJag=; b=ZIjqCT2iS7OwAbSbrX3fhWIyrwCaXOFjslxdpD5w3X5Reazf7es3AUnGKcFjvQSHXZ f8c0mvRGo/AOz6ryYvzSqqNo1imOMrQ9kh7gGhb0PTcc3zcpW8ZMCPcaQ5DTnDpvPq6t KReD2iB5uPpCaFpzfiCAaPvclNAia1AuQaxSGHZ7iE+qI/68hQXsbb1vL21VcBufffg4 VZ5j5MD0aqEG4RUfHa0XiqylkgIMCY6P5RyyKOEImNsrIOG019OuNf0jsWWefHW/UumL NSCz2rCXnTbRrNugBOHaejiGyupCCwtdzH51Nav1o8afVfTMiAXHXVj81C1EZBCsE+iu x/Ig== X-Gm-Message-State: AOJu0YyoRUW6RqxsdbOnAIxHLGRKle+OhAwMO7PGIOI6WgULA1O1EG8I 9jYPNZPvl9enXNF0MPnx2K1SwVWcu2DreENePhcP9KeBAIeMT2GlHA+EHOxbOKaUw3I= X-Gm-Gg: AfdE7cko9amjm+6yTOjOYiGCk2d0bS8M/FOQFOTlS4wpmnBNm1nHfgWAH3xK+FaHXo/ xu5tqjDHoIS9QNeoDf9os5F4NsmveEi/CUqQ8+sPuvDZ65Kq+s48CYTljUtjzwkBef6WKWtkTC1 S3uv/kS3CjDxiK7nDIydFbUnn40FVtUe63FII5A4E/NkBuqOVsfFUVQ92S5HiIkZ0fSkWj+jpzt CTVaC36dYe7b2kG5AqHtNPbd85PDhT/oISv4cWpXwPV/lN8eZj3wPM39ir+Bab0V8q80iW4PqSU SvSFa9aormSToo7nE+6Jp+QdLMJ4qnIBe4VliPOHbhhJb/1IFXlkO0AalWG3rp/MIrrVJabQZNk vqNtVQNg3fj3GMxWUtWBqne/essCyW0ppbRHS1Qauum4E0Z1JcRuoBoM37ZeQdZo7uiMblRk7EM j8Jr72QGswhH28iM0qjbebIVeA5zbHvg== X-Received: by 2002:a05:6a20:d81b:b0:3c3:9746:1fcb with SMTP id adf61e73a8af0-3c3a5df94d5mr35673637.35.1784222520296; Thu, 16 Jul 2026 10:22:00 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.28.233.73]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3140e5326c0sm16800417eec.11.2026.07.16.10.21.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jul 2026 10:21:59 -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 , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Cc: Zhang Chen Subject: [RESEND PATCH V10 08/15] virtio: use iothread_get/put_aio_context for thread pinning Date: Fri, 17 Jul 2026 01:20:49 +0800 Message-ID: <20260716172108.87700-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260716172108.87700-1-zhangckid@gmail.com> References: <20260716172108.87700-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 Refactor virtio-blk and virtio-scsi to use the new iothread_get/put APIs for AioContext management. This ensures IOThread references are tracked via the device's canonical QOM path. Summary of changes: - Lift 'path' scope to cover both vq_mapping and single iothread cases. - Replace raw object_ref/unref with iothread_get/put_aio_context. - Ensure consistent memory cleanup of the QOM path string. Signed-off-by: Zhang Chen --- hw/block/virtio-blk.c | 24 +++++++++++++----------- hw/scsi/virtio-scsi-dataplane.c | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 4b2cf3d52f..1865890fad 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); + IOThreadHolder io_holder = { + .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path = (char *)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,21 +1527,22 @@ 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)); + IOThreadHolder io_holder = { + .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path = (char *)path, + }; + iothread_put_aio_context(conf->iothread, &io_holder); } - g_free(s->vq_aio_context); s->vq_aio_context = NULL; } diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c index 26ecefd547..c71f33b41e 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); + IOThreadHolder io_holder = { + .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path = (char *)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)); + IOThreadHolder io_holder = { + .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path = (char *)path, + }; + iothread_put_aio_context(vs->conf.iothread, &io_holder); } g_free(s->vq_aio_context); -- 2.49.0