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 DD79FC88E4C for ; Fri, 11 Sep 2026 10:08:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4yAw-0006Xu-CH; Fri, 11 Sep 2026 06:08:06 -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 1x4yAf-0006QW-AA for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:49 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x4yAd-0007HA-9B for qemu-devel@nongnu.org; Fri, 11 Sep 2026 06:07:48 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2cc891373e0so7151215ad.2 for ; Fri, 11 Sep 2026 03:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789121266; x=1789726066; 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=GCwys0A7wABlzdjCSJp+U9W8UOKwT+jGbbtakz7i/jE=; b=U5NcfII/2VP63IVM8XtduNsK85ZgLukfO1jToSCfZ/b2CQ1SZ+2smg41/Q/kCIvs/4 lVa02/T4lEgaogJt5S/qpDOFkTw5xOrmugSpwqbpJiJpeMsIzPulF1DQy1mUyDhPuODZ HlJ1kRxFSZA6EcYcOTJgpOqVNnOkbP6PYMdWTpNvdUn9vNjViIrI1tBCi4vYLp2i4sXR ObclyBc1FicIhc4dDjs/rvIuIQdxZ6y7S1J2dbNLxCbYNYjZwQ3gtKpVS0n871zT66ds DU01dEWCzv178sk+/dJWa1NMkUu1o9N6pEKy81iPYyMTowLPToOmYMgZJ9h6Ehqi3VKQ 1cJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789121266; x=1789726066; 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=GCwys0A7wABlzdjCSJp+U9W8UOKwT+jGbbtakz7i/jE=; b=BlBIn//ME7OU9yVIuTMBwhQRFdSmo3rNwLe3YCxvDmAp3rL6GG2t4yLaVXrtkQZYdB ujOJ7MkaVdCYZm0hUc6jylOup3CubMCj0RrM1aV+K37aNFoXv3FyvrnloJsJ16FHZb0k hhp+gCqTa2NYbT0WCWsIqKGmcj16qayJVEZ/Zru/Qu0Qe3NnxO0qnPkFTo36sLnruINS IeOPq7Klw4nhDGBu3ka8WrWepTxkebFcoXSIXsLOVXecC5opi+QOEvj0BfPvLRIKYEoQ ZbBR5ibGAHhptbNhDKrwBGZ9hLLuXFmVM0UvvQb0ckD2VKhjGlpZwrUpcQ5crXsEHHZM RQMg== X-Gm-Message-State: AFuF++kBN7+xnMZ8tWE+zONMoReLVO1XdI3uCJLQf1Fn8Mpcv9Y9NI17 /biCOHhfd3SJJjSMUFrDCOu0c/qsMZSxXwAh1bXkF4wO3BdBR8lTJBP0k7uh0A== X-Gm-Gg: AYBFou3ZMOfzBW0kHe4/+ULE9gNPAc0e1ofHW0XZ8mg9NPoctZkthp840o5sf+H/Q0d Anz8vw8uKYUg8QHCncwVueuvrVV4JkoxvQ2r6xiwcoUnQhQEJ7OLWyLZ6YmDdTpeL/NBgLJhtxs fcXzTL6MPpjx2rWiYR+aDglg9amZq8jiZHDVvwH+YhmAyFGGl4cMT5lrjE38c/EVovtLZv3EgOe EDSS1N66i2Fe32IJdNRXO3nWTqQWZohYB/71TdDZ27efUfb6tSRNZ6AH30TDd0X0APnqkKLA4s5 BIU+GTuLW+gc6rnBAOtPTkB3yuCaYOanyQx9ydLbQhq2U3YSHkN5HQCjcXcg6g3cn+KYRl6JSrO wg8waNZFVHPtcrIMopoPyCX/a9qsDIlCEBFc8Zs8gc2mMQ+emaH8g1MBuTOCFg7azNO/T0cs/g5 4ttVRfgNtkOrt0RX0JAE8J1l0pgKRlIRYdijMn8bFemiDvj8KktQKsQ8+e0azwKzrGRzQ5g+8Ff dyl93kmBH2idQeEG21EG7oGdxc= X-Received: by 2002:a17:90b:518f:b0:38e:97f0:aa4b with SMTP id 98e67ed59e1d1-39d9c1bef27mr6038784a91.13.1789121265714; Fri, 11 Sep 2026 03:07:45 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39d951d6b08sm4514800a91.8.2026.09.11.03.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 03:07:45 -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 V16 06/13] virtio: track IOThread references for thread pinning Date: Fri, 11 Sep 2026 18:07:02 +0800 Message-ID: <20260911100709.726366-7-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260911100709.726366-1-zhangckid@gmail.com> References: <20260911100709.726366-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62a.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 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.43.0