{"id":2222004,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2222004/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260410150457.85190-9-zhangckid@gmail.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.1/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260410150457.85190-9-zhangckid@gmail.com>","date":"2026-04-10T15:04:51","name":"[V6,08/14] virtio: use iothread_get/put_aio_context for thread pinning","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"677deaedcfbcc344b8b8ad8ee57a064c50398cbc","submitter":{"id":72278,"url":"http://patchwork.ozlabs.org/api/1.1/people/72278/?format=json","name":"Zhang Chen","email":"zhangckid@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260410150457.85190-9-zhangckid@gmail.com/mbox/","series":[{"id":499477,"url":"http://patchwork.ozlabs.org/api/1.1/series/499477/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=499477","date":"2026-04-10T15:04:43","name":"iothread: Support tracking and querying IOThread holders","version":6,"mbox":"http://patchwork.ozlabs.org/series/499477/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2222004/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2222004/checks/","tags":{},"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=Jpj2arBb;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fsgBf1LDLz1yGS\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 11 Apr 2026 01:07:06 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wBDQW-00079K-N6; Fri, 10 Apr 2026 11:05:44 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <zhangckid@gmail.com>)\n id 1wBDQV-00078M-EF\n for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:43 -0400","from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <zhangckid@gmail.com>)\n id 1wBDQT-0002XR-MT\n for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:43 -0400","by mail-pg1-x52a.google.com with SMTP id\n 41be03b00d2f7-c76eea1672aso798083a12.1\n for <qemu-devel@nongnu.org>; Fri, 10 Apr 2026 08:05:41 -0700 (PDT)","from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121])\n by smtp.gmail.com with ESMTPSA id\n 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.35\n (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);\n Fri, 10 Apr 2026 08:05:38 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1775833540; x=1776438340; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=ZF3Zfhgg1+dMZbKh+1FfG0J0Eo/81Bufn7es25E8QL8=;\n b=Jpj2arBbdkkXMQ37iSs19A3axuxn67y6YIqvu04KfxDs2Lo2LYYrs9JdkhemKVlap4\n sFPlGsZubmRZdJLbUYTgj+GDPPEYWdggpnvVGKzDZ8JPoXHd9frNPp3VkDCjtXnoh89m\n VaOmUoK0bWZXre3xHx9fntVmuqI1A+S3H7lFOY9LdOkP6Im3uoNAHS2inmlRXKkK/PVN\n MJl89wMtEgc2dF4y4zytlpk7iOLkR+NSm1Ls1GFFG0cpyjYqsq++1BN3laBNHbgkXF8f\n dlwoyICqZzG5KdIDJTH683fTmoch641cj9KuBifaHhevuILIQSJqCwK4sgm/BmF9P4Iw\n zzmg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775833540; x=1776438340;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=ZF3Zfhgg1+dMZbKh+1FfG0J0Eo/81Bufn7es25E8QL8=;\n b=d87e+Q1XqkHgJ8H6TIxr0MQsnkOJeBCGg4I5a5fPrApKp99g05WDKMfYTEh4osChsY\n /urCYz/N5+yINYsXiaPQf4v8xsGu5wAVAPZQUnseSftR7HMIFHJ+2GvkJw6McZHD1d+f\n fsskqtAt4FbfglGJcQTZ4DSoKBmYUtlqeMPH4MZ5n1SmHACnNaDmA9PLa7Ha6n2EuOxM\n GEBLYlIE+Zmg/J+iP0v2QuhZTmIXE1hT23t5PyK8efKo5B7W04uvpt4tGtPVBoFFE9pS\n I69YfHvG7Hwy/4WmQz38hVDoTGW/XC+JzmTD/20HXMhoxJeZnZPTJcYjdMtCH8G/zNY+\n /yVA==","X-Gm-Message-State":"AOJu0YzK1aG7rIFTAeetPYGfzM8I0TCTn+5ao9DC0VtjZd0LS5cSkSix\n yHTE6lqdHxEK4saLPxF4lAhROJQomKgrT2+ZR3qS4gKn+W1SCDGzu2e2To9x3koQ","X-Gm-Gg":"AeBDievSr15qzo3u2FhgaJ/oljyP07y0Be3zadxdioqT86Ax3gxtsl/qfRfjU5QpP0a\n XdVSnfbFTiWsSla5pqwWUMeFAJjdziXrIfrWNBP/KmYVU6xHqNZo7izDCAIRCB0LLy6zm67PjQ/\n wfjp//2SpKz2GfSIeaQgaSktU6Ih9LKFx3whtcjVijA6p8KKEmcWLhDmH0nz4KGVyP7OO55C2gf\n m0bUjMJo0ykMt2XQZsQF3Q/IQYC3zGoQW5RqTf2d91b4g/faQda+XsiUdub8PFT43vkKxwnldOg\n Z51aOvEdtlwho6x2QTTLXiwMY5kJFel77XJNMJFPZgKm2xjHOBvksPF6qcpo/qMiMPSHNODLUZF\n szBxdYdw/mjyJtCTGCO5f09cdJ2eacLKv9twm6gp8KU9baEADa03irtiH0fnfhwzLzmt8BTTD10\n SdBN8okSBUhfyMd3gNhmuY8oxlgLTMltA/fgX3M1Iv+gsdZiPxvqh1","X-Received":"by 2002:a17:90b:3950:b0:35e:30bc:804d with SMTP id\n 98e67ed59e1d1-35e42846535mr3353354a91.15.1775833539525;\n Fri, 10 Apr 2026 08:05:39 -0700 (PDT)","From":"Zhang Chen <zhangckid@gmail.com>","To":"qemu-devel <qemu-devel@nongnu.org>,\n \"Dr . David Alan Gilbert\" <dave@treblig.org>,\n Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>,\n \"Michael S . Tsirkin\" <mst@redhat.com>,\n Stefan Hajnoczi <stefanha@redhat.com>","Cc":"Zhang Chen <zhangckid@gmail.com>","Subject":"[PATCH V6 08/14] virtio: use iothread_get/put_aio_context for thread\n pinning","Date":"Fri, 10 Apr 2026 23:04:51 +0800","Message-ID":"<20260410150457.85190-9-zhangckid@gmail.com>","X-Mailer":"git-send-email 2.49.0","In-Reply-To":"<20260410150457.85190-1-zhangckid@gmail.com>","References":"<20260410150457.85190-1-zhangckid@gmail.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=2607:f8b0:4864:20::52a;\n envelope-from=zhangckid@gmail.com; helo=mail-pg1-x52a.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,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n 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 <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"Refactor virtio-blk and virtio-scsi to use the new iothread_get/put\nAPIs for AioContext management. This ensures IOThread references\nare tracked via the device's canonical QOM path.\n\nSummary of changes:\n- Lift 'path' scope to cover both vq_mapping and single iothread cases.\n- Replace raw object_ref/unref with iothread_get/put_aio_context.\n- Ensure consistent memory cleanup of the QOM path string.\n\nSigned-off-by: Zhang Chen <zhangckid@gmail.com>\n---\n hw/block/virtio-blk.c           | 16 +++++-----------\n hw/scsi/virtio-scsi-dataplane.c | 15 +++++----------\n 2 files changed, 10 insertions(+), 21 deletions(-)","diff":"diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c\nindex 762714f4ba..70fc85bdde 100644\n--- a/hw/block/virtio-blk.c\n+++ b/hw/block/virtio-blk.c\n@@ -1429,6 +1429,7 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlock *s, Error **errp)\n     VirtIOBlkConf *conf = &s->conf;\n     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));\n     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);\n+    g_autofree char *path = object_get_canonical_path(OBJECT(vdev));\n \n     if (conf->iothread && conf->iothread_vq_mapping_list) {\n         error_setg(errp,\n@@ -1453,8 +1454,6 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlock *s, Error **errp)\n     s->vq_aio_context = g_new(AioContext *, conf->num_queues);\n \n     if (conf->iothread_vq_mapping_list) {\n-        g_autofree char *path = object_get_canonical_path(OBJECT(vdev));\n-\n         if (!iothread_vq_mapping_apply(conf->iothread_vq_mapping_list,\n                                        s->vq_aio_context,\n                                        conf->num_queues,\n@@ -1465,13 +1464,11 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlock *s, Error **errp)\n             return false;\n         }\n     } else if (conf->iothread) {\n-        AioContext *ctx = iothread_get_aio_context(conf->iothread);\n+        AioContext *ctx = iothread_ref_and_get_aio_context(conf->iothread,\n+                                                           path);\n         for (unsigned i = 0; i < conf->num_queues; i++) {\n             s->vq_aio_context[i] = ctx;\n         }\n-\n-        /* Released in virtio_blk_vq_aio_context_cleanup() */\n-        object_ref(OBJECT(conf->iothread));\n     } else {\n         AioContext *ctx = qemu_get_aio_context();\n         for (unsigned i = 0; i < conf->num_queues; i++) {\n@@ -1486,21 +1483,18 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlock *s, Error **errp)\n static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s)\n {\n     VirtIOBlkConf *conf = &s->conf;\n+    g_autofree char *path = object_get_canonical_path(OBJECT(VIRTIO_DEVICE(s)));\n \n     assert(!s->ioeventfd_started);\n \n     if (conf->iothread_vq_mapping_list) {\n-        g_autofree char *path = object_get_canonical_path(\n-                                OBJECT(VIRTIO_DEVICE(s)));\n-\n         iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path);\n     }\n \n     if (conf->iothread) {\n-        object_unref(OBJECT(conf->iothread));\n+        iothread_put_aio_context(conf->iothread, path);\n     }\n \n-    g_free(s->vq_aio_context);\n     s->vq_aio_context = NULL;\n }\n \ndiff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c\nindex 26ecefd547..cc318162f5 100644\n--- a/hw/scsi/virtio-scsi-dataplane.c\n+++ b/hw/scsi/virtio-scsi-dataplane.c\n@@ -28,6 +28,7 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp)\n     VirtIODevice *vdev = VIRTIO_DEVICE(s);\n     BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));\n     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);\n+    g_autofree char *path = object_get_canonical_path(OBJECT(vdev));\n \n     if (vs->conf.iothread && vs->conf.iothread_vq_mapping_list) {\n         error_setg(errp,\n@@ -65,8 +66,6 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp)\n     s->vq_aio_context[1] = qemu_get_aio_context();\n \n     if (vs->conf.iothread_vq_mapping_list) {\n-        g_autofree char *path = object_get_canonical_path(OBJECT(vdev));\n-\n         if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list,\n                     &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED],\n                     vs->conf.num_queues, path, errp)) {\n@@ -75,13 +74,11 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp)\n             return;\n         }\n     } else if (vs->conf.iothread) {\n-        AioContext *ctx = iothread_get_aio_context(vs->conf.iothread);\n+        AioContext *ctx = iothread_ref_and_get_aio_context(vs->conf.iothread,\n+                                                           path);\n         for (uint16_t i = 0; i < vs->conf.num_queues; i++) {\n             s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] = ctx;\n         }\n-\n-        /* Released in virtio_scsi_dataplane_cleanup() */\n-        object_ref(OBJECT(vs->conf.iothread));\n     } else {\n         AioContext *ctx = qemu_get_aio_context();\n         for (unsigned i = 0; i < vs->conf.num_queues; i++) {\n@@ -94,16 +91,14 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp)\n void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s)\n {\n     VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);\n+    g_autofree char *path = object_get_canonical_path(OBJECT(VIRTIO_DEVICE(s)));\n \n     if (vs->conf.iothread_vq_mapping_list) {\n-        g_autofree char *path = object_get_canonical_path(\n-                                OBJECT(VIRTIO_DEVICE(s)));\n-\n         iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, path);\n     }\n \n     if (vs->conf.iothread) {\n-        object_unref(OBJECT(vs->conf.iothread));\n+        iothread_put_aio_context(vs->conf.iothread, path);\n     }\n \n     g_free(s->vq_aio_context);\n","prefixes":["V6","08/14"]}