{"id":2221995,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2221995/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260410150457.85190-7-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-7-zhangckid@gmail.com>","date":"2026-04-10T15:04:49","name":"[V6,06/14] monitor: Update tracking iothread users with holder name","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"44b4abfe054d76dfc6940094d654811a5551dbeb","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-7-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/2221995/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2221995/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=a1FslxY2;\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 4fsg9k3zR5z1yGS\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 11 Apr 2026 01:06:18 +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 1wBDQO-0006yv-Ty; Fri, 10 Apr 2026 11:05:36 -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 1wBDQN-0006yX-6e\n for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:35 -0400","from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036])\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 1wBDQL-0002S0-Gy\n for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:34 -0400","by mail-pj1-x1036.google.com with SMTP id\n 98e67ed59e1d1-3590042fa8eso1729726a91.1\n for <qemu-devel@nongnu.org>; Fri, 10 Apr 2026 08:05:33 -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.27\n (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);\n Fri, 10 Apr 2026 08:05:30 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1775833532; x=1776438332; 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=x69ooA9/Ciku7C9KOIVP3A4OcWl7JOZ863rt2HmRx3I=;\n b=a1FslxY2KL7qIN8v4urhyxoTiSB8Eg6C5Bvd1Gzt/gAgdfwYdCOaguX9bf2kW/Be9k\n 7qQ2kODsxP92AbAhPRVSozVNXwtom6GYhhkJjTEtA6x/FfriIUnSdRTDA5Y1holLjcCP\n nBqao/7qDrh7S2Ms1eutxqpRKkTVrZA+fvtZVxiWL+Qkl+8veYaCDlbf17JT7JfIn3+k\n OwL2WjuvMwWSGbdJ90CY0uwX8UZELBhFHDhEcwNqfISAMLHxxvZZaCeJCgj1UaBmaLmm\n 2aqqFD0lYxXDz/K7lIbzEuHaEac4Fn4mT67yXlMjqwQD83BLKLt2ZzKgBg/FFrC/zD3s\n ckdQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775833532; x=1776438332;\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=x69ooA9/Ciku7C9KOIVP3A4OcWl7JOZ863rt2HmRx3I=;\n b=dEFIQMOLsaMebT8zUbKuwBaQGr0/BJMJWxNh+LjeaTY2Fp13x3H7K+5ElUBAWfAFm9\n mVaWZRvGIdANmrSU9jxHxiooh7kxOAgMlWuDlmg0hNLfRSRQ4AxIdSxxCuEF+ixBSRSN\n w6LNufpZSQD6Xqw9/c2jPErmwCMFL2X6AO3Av9IY3JCA000xw72qzAnhpDh4XwIGuxzY\n kORngbT7hMHqpe8m0gKawja8BnPMZB4nxqMTNy8i5TUXFD4dxxyG7DRcmUGX6EiAIGl8\n LAzANRiH0QsL7OuqVJB1JUItTWtPfvSN3w9WnGuvSNjlo3YaVs0GyvBbsfnhZbE95k1b\n KKaA==","X-Gm-Message-State":"AOJu0YzqTdWGuQoe0zf4SKrNpxvjJlHp6BEvJ2sqP72ipKP91XhkkrFl\n V5ksaj+/M3d3XpKkA6EJ1W25NFPHlYY668EuhOrKs3bSBTgFw5/UF88OJ206UeCJ","X-Gm-Gg":"AeBDietEMkzYHSfgEUHeiswluUAGR4NIj0zOGZCR//Yr9zIdJupWvtvzQ4guskC8hOp\n VutF0KQ3iH/9K+qOJP+YLU6lLq92ufBki82agvpxd1ih0zaliUGd5L/V5Q8kDwjhOWaloFQel8D\n XTxFPJinm303tsf8ipNU+qYjDQ7zJ3sGdzPp+gdKrpHYtY9Qy9tsPbV6X3EWS2cBaTv1hKI0B7k\n Y5UIgkt102tg7+rPIyp+nWUUCB8s5g2/fyLO0DmS8wS9mXC+BnC3LKMfusn+1L0s2YurcivWTvr\n 4Oypu7fqwZuy9ZxAAxYugyoEX2xFBRMnX1lrFeieQ68gVK36vI0nfgot1DnBWLkxWi7na0+hL8o\n rl8KxFFfKNfex2lZN/+20YCt2Y9jHz6O+0JJx7ym7HuFGQeR6q9W5b7fFl6BehCoqy2Wqqu10JD\n uNPG7u8GDCSSWhpv1eQyOdSyf1vjQx0V3EdiNe1FhuBF7sZx3MWKUm","X-Received":"by 2002:a17:90b:268b:b0:35c:30a8:322 with SMTP id\n 98e67ed59e1d1-35e4245a667mr3694581a91.0.1775833531337;\n Fri, 10 Apr 2026 08:05:31 -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 06/14] monitor: Update tracking iothread users with holder\n name","Date":"Fri, 10 Apr 2026 23:04:49 +0800","Message-ID":"<20260410150457.85190-7-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::1036;\n envelope-from=zhangckid@gmail.com; helo=mail-pj1-x1036.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":"Since the Monitor struct is not a QOM Object, we cannot use\nobject_get_canonical_path(). Instead, this patch uses the monitor's\nname (or a default type-based name) as the holder identifier.\n\nCache the AioContext in the Monitor struct to avoid repeated calls to\niothread_get_aio_context() and ensure symmetrical ref/unref during\nmonitor lifecycle.\n\nSigned-off-by: Zhang Chen <zhangckid@gmail.com>\n---\n monitor/monitor-internal.h |  3 +++\n monitor/monitor.c          | 24 ++++++++++++++++++++++--\n monitor/qmp.c              |  3 ++-\n 3 files changed, 27 insertions(+), 3 deletions(-)","diff":"diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h\nindex feca111ae3..51cedf90e4 100644\n--- a/monitor/monitor-internal.h\n+++ b/monitor/monitor-internal.h\n@@ -116,6 +116,9 @@ struct Monitor {\n     guint out_watch;\n     int mux_out;\n     int reset_seen;\n+\n+    /* iothread context */\n+    AioContext *ctx;\n };\n \n struct MonitorHMP {\ndiff --git a/monitor/monitor.c b/monitor/monitor.c\nindex 00b93ed612..b6efe776d6 100644\n--- a/monitor/monitor.c\n+++ b/monitor/monitor.c\n@@ -529,7 +529,7 @@ int monitor_suspend(Monitor *mon)\n          * Kick I/O thread to make sure this takes effect.  It'll be\n          * evaluated again in prepare() of the watch object.\n          */\n-        aio_notify(iothread_get_aio_context(mon_iothread));\n+        aio_notify(mon->ctx);\n     }\n \n     trace_monitor_suspend(mon, 1);\n@@ -564,7 +564,7 @@ void monitor_resume(Monitor *mon)\n         AioContext *ctx;\n \n         if (mon->use_io_thread) {\n-            ctx = iothread_get_aio_context(mon_iothread);\n+            ctx = mon->ctx;\n         } else {\n             ctx = qemu_get_aio_context();\n         }\n@@ -612,6 +612,18 @@ void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,\n {\n     if (use_io_thread && !mon_iothread) {\n         monitor_iothread_init();\n+        /*\n+         * Because of current Monitor is not a QOM Object,\n+         * so using OBJECT(mon) is undefined behavior and may crash.\n+         * Try using a hard-coded future implementation of the qom path instead.\n+         * (Like the name of the \"mon_iothread\").\n+         * long-term solution would be making Monitor QOM, after that change\n+         * here to:\n+         * g_autofree path = object_get_canonical_path(OBJECT(mon));\n+         */\n+        g_autofree char *path = g_strdup(is_qmp ? \"/monitor/qmp_mon0\" :\n+                                                  \"/monitor/hmp_mon0\");\n+        mon->ctx = iothread_ref_and_get_aio_context(mon_iothread, path);\n     }\n     qemu_mutex_init(&mon->mon_lock);\n     mon->is_qmp = is_qmp;\n@@ -631,6 +643,14 @@ void monitor_data_destroy(Monitor *mon)\n     }\n     g_string_free(mon->outbuf, true);\n     qemu_mutex_destroy(&mon->mon_lock);\n+\n+    if (mon->ctx && mon_iothread) {\n+        g_autofree char *path = g_strdup(monitor_is_qmp(mon) ?\n+                                        \"/monitor/qmp_mon0\" :\n+                                        \"/monitor/hmp_mon0\");\n+        iothread_put_aio_context(mon_iothread, path);\n+        mon->ctx = NULL;\n+    }\n }\n \n void monitor_cleanup(void)\ndiff --git a/monitor/qmp.c b/monitor/qmp.c\nindex 687019811f..8e4a775fac 100644\n--- a/monitor/qmp.c\n+++ b/monitor/qmp.c\n@@ -549,7 +549,8 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp)\n          * since chardev might be running in the monitor I/O\n          * thread.  Schedule a bottom half.\n          */\n-        aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread),\n+        Monitor *mon_p = &mon->common;\n+        aio_bh_schedule_oneshot(mon_p->ctx,\n                                 monitor_qmp_setup_handlers_bh, mon);\n         /* The bottom half will add @mon to @mon_list */\n     } else {\n","prefixes":["V6","06/14"]}