From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763175; cv=none; d=zohomail.com; s=zohoarc; b=npxdEzOEShGB8gzsd83L8VBSaAYeZUe/fHyn5h04vkARDFWxeE/PnF29V04qve9Q4llc3+3pzejoeXFfOc6OdrjI9vH+FY6lFAHd36nd5d60weDi/tpnLoJ0MAc7196qlC70+HNXANsz5SICKr8BGEXAaJGZ/IhQdlKMfO3V3hg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763175; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8VZvJfwzEx83my0luzHgdVUOYxehjQZN8hTGEXB0zHU=; b=RAjJlrwr4H0CeAs79OdS9dFHvUWks6x6M5E5+FbIESoadcXjkv+tXFctK14/1Q+6AG5Kg5XrpfRw8Flt+BOnaVBIKB+F3FhYjJLtXp9LmueivQM1iyJWZ6NgoOr+ngl3vKe1wBNF24r5kziQt+LHSj2YTrI7glbg+ZWUMqVME3Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763175410480.9666583890778; Sun, 6 Sep 2026 23:39:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3SzI-0005f6-6P; Mon, 07 Sep 2026 02:37:52 -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 1x3SzG-0005eg-R4 for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:37:50 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3SzF-00065L-C8 for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:37:50 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-2d715f4a587so45936515ad.2 for ; Sun, 06 Sep 2026 23:37:49 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763068; x=1789367868; 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=8VZvJfwzEx83my0luzHgdVUOYxehjQZN8hTGEXB0zHU=; b=eHHisUDr2rXX/Aa+2RR8osQDVk1+rN8aoY6gf14g0yTOoU462DXIkad7St6AMA020S 9MgRMQk0asrXwoJe9hwro4Fgw12ongHtPIGQ/ve3PmL7U9yaMzuDgsBTtg4KJMoB9HkH L3eP6SX4/U2s9rjRVs2MGIgWX1l+1rCjfNR4EQbc0e/I8p3B9Li7o3MJe3B0JVOCwGO8 WX533DwBB7+CBSEucfEqqsMq11WOyNtcZO58UkkhXQaJLRNO1rp5M9wWoqNb4MgutFrj 5fmIUddoSz6S6g/+XMnn9+fFzg9FmO8X2X3scF86Iz7TiqhAlehquUdNOkSWfZ+fYzfK PcZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763068; x=1789367868; 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=8VZvJfwzEx83my0luzHgdVUOYxehjQZN8hTGEXB0zHU=; b=LTeUvOQLULH7ZZJvoMfhOCKRZijchIemZUC0SNm++DOLq1AvPkr2LL+WOJC47L52OD 4ThhZHG2CFrj83MOsiVRx7RzBU64KJyycGUlZr+pHfueAMwjqTJ+0cXpqbClgCrgZOLn EtFh0NCqg9cy9DqZIbm+3OYJlw6yO3JNxM8PLDVd1q1tfD3nFZRlMlrj+Hzyq4CTBWcI lTOkWkzED+nAf3mHwIYsahhWOinf6GFpypibi5KqiBWp6JpEbq440gGAZ3AUwD+DYeFC swEjUzQhOGO5IVGztuQcVY66BgI3S5gk8T75OMdfrXGqjofe5rdUrg35qqQGJEGXwraT 8Pkg== X-Gm-Message-State: AFuF++kKyjZaIV7j9bEn/vijZ9hL9yCA8Eayr3rkt11sTK6sAiV4MhaX 9PZcRjwdxXztEsiYp2+By3Y0wzjhBIqB2t1DyM+se9qdspXxWFlXXc8HW47WZ5d8He/uYA== X-Gm-Gg: AYBFou2Ft607sOaVX0XXQmhF4OwJj/jEOy5CjssR9Kfi+2AghIGxlDbtAosAKp98YJ/ zwcECOHBxTjjNxIPvS55zdzNdyT9VelUZ93B6mdFFlLdiZuvw8OFcvb6cGBYi9AAHessL7eo+QV TUHsphBiCuYPDXYNq71qa2MM75T7fJ78vntclgzzlf1DB4sh4QnOxYrOVyOrB5Bf5TxibxDMFfo fCizbPpujFRUTcutC1jNOAcWa7iyqDBli2ZR4EKE1Z2SqlTeZFclNUZS2GzKuKtPwgeEDgLirQZ qVSdaR7aJ28wBlFwyKXRYAU+971ksDclqBUILhNwZF3R/JftHRMB7Zfll+1ndjy48kzWvANRfWZ pJHAsuEra5FdrNZiNagarkM/nX1Ykoj5J6aZtLtUJXbXEs3CD+ib8R7UFYdnlnVK70jDnFxt8+p Tp6+ph5msEvD+yUo8xVtA4Fi2jx+uvKcoLN0jcDzSCOjvQjQe+Cr0d54OiUXI16NHvPXkezP3QH OaXhaiQxirlfzPy X-Received: by 2002:a17:903:468d:b0:2d9:56d8:75f with SMTP id d9443c01a7336-2db1266772dmr334377145ad.9.1788763067940; Sun, 06 Sep 2026 23:37:47 -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 , qemu-stable@nongnu.org Subject: [PATCH V15 01/14] qapi/misc: Fix missed query-iothreads items Date: Mon, 7 Sep 2026 14:37:12 +0800 Message-ID: <20260907063725.626685-2-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763176740154100 Content-Type: text/plain; charset="utf-8" The example is incomplete: it misses members @poll-max-ns, @poll-grow, @poll-shrink, @aio-max-batch. Messed up in commit 5fc00480ab1 (monitor: add poll-* properties into query-iothreads result) and commit 1793ad0247c (iothread: add aio-max-batch parameter). cc: qemu-stable@nongnu.org Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen --- qapi/misc.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qapi/misc.json b/qapi/misc.json index a21ba61b96..baa50cc844 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -123,11 +123,19 @@ # <- { "return": [ # { # "id":"iothread0", -# "thread-id":3134 +# "thread-id":3134, +# "poll-max-ns":32768, +# "poll-grow":0, +# "poll-shrink":0, +# "aio-max-batch":0 # }, # { # "id":"iothread1", -# "thread-id":3135 +# "thread-id":3135, +# "poll-max-ns":32768, +# "poll-grow":0, +# "poll-shrink":0, +# "aio-max-batch":0 # } # ] # } --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763103; cv=none; d=zohomail.com; s=zohoarc; b=Xnp/SH20aMc6tA9Go1+THCx8hS/kV3zkE1ClMP3HVbvmCcrpEo7+c36tOjyVJRGMlA8YPFkU2iDnaNxuthGGiZ9paLEZ5dCM0vnvvMA3z7X8ZN3uFzv5n4cJBSLihpIHCLV4gy4rTjcVHQxxDvyzlKyCfUj7ST/6ngmXiL+2vw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763103; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oseK8j5bYgRDO/3pjj5kj8+f5w/39DM9IAFzzThU830=; b=hsi77Es6YdaXPvHxIF7Zh03jAUMJphKzlLvnVtMOffEdGfpMU+sNrDUgg+aoihiqaFGEH7Bk/5L/Y1KRazBlpW88PhrBs1RVM/UrAkugjQpQ0LMn0SYcZkVSqh9kInyHuCOkGyhp3pqGRZNbzSHKv23AiGt/J2Xaosj+/K0DyX0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763103337151.4582154731504; Sun, 6 Sep 2026 23:38:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3SzM-0005ft-RR; Mon, 07 Sep 2026 02:37:56 -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 1x3SzL-0005fk-9w for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:37:55 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3SzJ-00067w-9x for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:37:55 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2db3305f94fso19848805ad.0 for ; Sun, 06 Sep 2026 23:37:52 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:37:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763072; x=1789367872; 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=oseK8j5bYgRDO/3pjj5kj8+f5w/39DM9IAFzzThU830=; b=faJc2wPV9kFbCQM6Yo+oG4DPn6ogzVRZ+QgZmFY65bW21gvaBCQsqUI7MTcwUgWVud fNUOqnTSy81Rzc5bfTkkjMOQ2NVy/N/cmSbGqL4ADXcQpSlsUS401wvCPAZ/rlkmdcpH hHPKqaLhTC19Y66lYM0Yecz6Hz/twS1jYktQDXnlcU4z7HV4gIC3PnDnciMbGgR4ETM/ MwrlsNlKvM9XBHo8K9LUeY1B3qpdZTP/xFXkpMIMHtEcxP/wWac04aF3T4yyBTYmT7Kv cxEJfTHSd2yLQLDrhww26wasP2zGpJQd/I0UIOM24yO8t5gUAzioK4rbo+F6cmd+9/oc rqfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763072; x=1789367872; 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=oseK8j5bYgRDO/3pjj5kj8+f5w/39DM9IAFzzThU830=; b=AuWbR+rJkyPQEKtOAmPuuk2MAE0zmJmZy/1I9CmD2YerstWjugOe96Uo6BOJiZNS/I 97L5/TC+756ztM4JapPKSl8R/Y0nyiL4auD4L/YeMnHIhGvN3bdGoL8dS1gYiL56NwMe 3f2DtXE74/uR+t7dBh29NH9HPDRKysiwEMgDd8Byr4qRSnUVSYALfdW4xTpHwfNt+crq XFOgEt+0dCMT2aofFK9x+uSaCSw+OyTN+TTDq/NaWbIuimaap3/4kfwjwnlqrJ/PLMgT NTQr/sd7x2zayxz58wh8WhL4yYZ6BKu9s6zQQfNjcsTBYCBF4SVa53awevuKq6Nd9p3D itVw== X-Gm-Message-State: AFuF++njNeOOV8bH5Ypb/D+xNEx5gOOM2IpHbaSIywO/wzJdc25GlCbf RWs2dt/ItjVeyWprHIykOu0Dk5wPHqNjMGYnA4NJsDlO+WKzX5mBhsNP8hCrB7xn3aZImA== X-Gm-Gg: AYBFou0NAJwpadgejpvVdyvqvwT6mPqzMWE2d0YH3HExkrQMUg+0IoXjhAZMHeahaOI B79jEgWreEUZM9YZzvIVBD1dwsF6T4fRpwr7G3uhrSZBqZa7dH6lq2rYwTmXHj1DKf5ykv7A+vt 0h7aL0q9NjEv3gOpSFSc0jlz0xBe3tikxdiZZQJmwYa3QVWtsUW2qyX5IgD/bqXwCzORxv6E1dZ 3rV2VS7NMqvEXi8XO7vPOltPu5SQr8RKTaEbklmyFJDPLzwrF5Z7YggevT7yvuCPZmzlyjzbFrf K58wTTsIzpS83OO90Q51PpZ1otSY5E3CzuYmf3jrOIgmA1t88qDpVB0l406D+pfCxhGHEcGIrig oyJt5YhE5C5jBrda9et/aa3FunGzXVTqU1zwdRg5+SOpU+GDD1b3wFsvbGE4IU6goOnvi3/p8D8 Dndg8r5Z1GeXuvxk5weEX0KKhiQASG2T+QzyBrvwDZ78gu3FijYqe8mhlT7O496ULVQ9ziDHh5L 6apmi5Xo59604ZC X-Received: by 2002:a17:903:3b54:b0:2ca:d91d:d3a7 with SMTP id d9443c01a7336-2db127c02a1mr218429635ad.10.1788763071874; Sun, 06 Sep 2026 23:37:51 -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 V15 02/14] iothread: introduce holder tracking Date: Mon, 7 Sep 2026 14:37:13 +0800 Message-ID: <20260907063725.626685-3-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x634.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763106458154100 Content-Type: text/plain; charset="utf-8" IOThreads do not record the QOM objects and block exports that use them, making runtime introspection and hotplug debugging difficult. Add: - holders: a list describing what is holding an iothread - iothread_ref(): add a holder to the list - iothread_unref(): remove a holder from the list A holder can identify either a QOM object or a block export. A later patch will expose this information through query-iothreads. Reviewed-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster Signed-off-by: Zhang Chen --- include/system/iothread.h | 5 +++ iothread.c | 63 ++++++++++++++++++++++++++ qapi/misc.json | 94 ++++++++++++++++++++++++++++++++++----- 3 files changed, 150 insertions(+), 12 deletions(-) diff --git a/include/system/iothread.h b/include/system/iothread.h index a1ef7696cb..b8aeb32b0e 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -18,6 +18,7 @@ #include "qemu/thread.h" #include "qom/object.h" #include "system/event-loop-base.h" +#include "qapi/qapi-types-misc.h" =20 #define TYPE_IOTHREAD "iothread" =20 @@ -50,6 +51,7 @@ struct IOThread { bool stopping; /* has iothread_stop() been called? */ bool running; /* should iothread_run() continue? */ int thread_id; + IOThreadHolderList *holders; =20 /* AioContext poll parameters */ int64_t poll_max_ns; @@ -82,4 +84,7 @@ void iothread_destroy(IOThread *iothread); */ bool qemu_in_iothread(void); =20 +void iothread_ref(IOThread *iothread, const IOThreadHolder *holder); +void iothread_unref(IOThread *iothread, const IOThreadHolder *holder); + #endif /* IOTHREAD_H */ diff --git a/iothread.c b/iothread.c index 3558535b40..66dfde626e 100644 --- a/iothread.c +++ b/iothread.c @@ -21,10 +21,71 @@ #include "system/iothread.h" #include "qapi/error.h" #include "qapi/qapi-commands-misc.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-misc.h" #include "qemu/error-report.h" #include "qemu/rcu.h" #include "qemu/main-loop.h" =20 +/* Add a deep copy of @holder to @iothread's list of holders. */ +void iothread_ref(IOThread *iothread, const IOThreadHolder *holder) +{ + assert(holder); + + QAPI_LIST_PREPEND(iothread->holders, QAPI_CLONE(IOThreadHolder, holder= )); +} + +static int iothread_holder_compare(const IOThreadHolder *holder_a, + const IOThreadHolder *holder_b) +{ + const char *name_a, *name_b; + + if (holder_a->type !=3D holder_b->type) { + return holder_a->type - holder_b->type; + } + + switch (holder_a->type) { + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + name_a =3D holder_a->u.qom_object.qom_path; + name_b =3D holder_b->u.qom_object.qom_path; + break; + case IO_THREAD_HOLDER_KIND_BLOCK_EXPORT: + name_a =3D holder_a->u.block_export.export_id; + name_b =3D holder_b->u.block_export.export_id; + break; + default: + g_assert_not_reached(); + } + + return strcmp(name_a, name_b); +} + +/* + * Remove @holder from @iothread's list of holders. + * + * It is a programming error if @holder is not present. + */ +void iothread_unref(IOThread *iothread, const IOThreadHolder *holder) +{ + IOThreadHolderList **prev =3D &iothread->holders; + IOThreadHolderList *curr; + + assert(holder); + + while (*prev) { + curr =3D *prev; + if (iothread_holder_compare(curr->value, holder) =3D=3D 0) { + *prev =3D curr->next; + curr->next =3D NULL; + qapi_free_IOThreadHolderList(curr); + return; + } + prev =3D &curr->next; + } + + g_assert_not_reached(); +} + static void *iothread_run(void *opaque) { IOThread *iothread =3D opaque; @@ -129,6 +190,7 @@ static void iothread_instance_finalize(Object *obj) iothread->main_loop =3D NULL; } qemu_sem_destroy(&iothread->init_done_sem); + qapi_free_IOThreadHolderList(iothread->holders); } =20 static void iothread_init_gcontext(IOThread *iothread, const char *thread_= name) @@ -373,6 +435,7 @@ static int query_one_iothread(Object *object, void *opa= que) info =3D g_new0(IOThreadInfo, 1); info->id =3D iothread_get_id(iothread); info->thread_id =3D iothread->thread_id; + info->holders =3D QAPI_CLONE(IOThreadHolderList, iothread->holders); info->poll_max_ns =3D iothread->poll_max_ns; info->poll_grow =3D iothread->poll_grow; info->poll_shrink =3D iothread->poll_shrink; diff --git a/qapi/misc.json b/qapi/misc.json index baa50cc844..bb49969b4b 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -67,6 +67,55 @@ ## { 'command': 'query-name', 'returns': 'NameInfo', 'allow-preconfig': true } =20 +## +# @IOThreadHolderBlockExport: +# +# @export-id: The unique block export identifier. +# +# Since: 11.2 +# +## +{ 'struct': 'IOThreadHolderBlockExport', + 'data': { 'export-id': 'str' } } + +## +# @IOThreadHolderQomObject: +# +# @qom-path: Path to the object in the QOM tree. +# +# Since: 11.2 +# +## +{ 'struct': 'IOThreadHolderQomObject', + 'data': { 'qom-path': 'str' } } + +## +# @IOThreadHolderKind: +# +# @block-export: A block export. +# @qom-object: A QOM object. +# +# Since: 11.2 +## +{ 'enum': 'IOThreadHolderKind', + 'data': [ 'block-export', 'qom-object' ] } + +## +# @IOThreadHolder: +# +# The block export or QOM object holding the iothread. +# +# @type: the kind of iothread holder. +# +# Since: 11.2 +## +{ 'union': 'IOThreadHolder', + 'base': { 'type': 'IOThreadHolderKind' }, + 'discriminator': 'type', + 'data': { + 'block-export': 'IOThreadHolderBlockExport', + 'qom-object': 'IOThreadHolderQomObject' } } + ## # @IOThreadInfo: # @@ -76,6 +125,10 @@ # # @thread-id: ID of the underlying host thread # +# @holders: the QOM objects or block exports currently holding this +# iothread. When a holder is detached or destroyed, it is removed +# from this list. (Since 11.2) +# # @poll-max-ns: maximum polling time in ns, 0 means polling is # disabled (since 2.9) # @@ -98,6 +151,7 @@ { 'struct': 'IOThreadInfo', 'data': {'id': 'str', 'thread-id': 'int', + 'holders': ['IOThreadHolder'], 'poll-max-ns': 'int', 'poll-grow': 'int', 'poll-shrink': 'int', @@ -122,20 +176,36 @@ # -> { "execute": "query-iothreads" } # <- { "return": [ # { -# "id":"iothread0", -# "thread-id":3134, -# "poll-max-ns":32768, -# "poll-grow":0, -# "poll-shrink":0, -# "aio-max-batch":0 +# "id": "iothread0", +# "thread-id": 3134, +# "holders": [ +# { +# "qom-path": "/machine/peripheral/blk1/virtio-bac= kend", +# "type": "qom-object" +# }, +# { +# "qom-path": "/machine/peripheral/blk2/virtio-bac= kend", +# "type": "qom-object" +# } +# ], +# "poll-max-ns": 32768, +# "poll-grow": 0, +# "poll-shrink": 0, +# "aio-max-batch": 0 # }, # { -# "id":"iothread1", -# "thread-id":3135, -# "poll-max-ns":32768, -# "poll-grow":0, -# "poll-shrink":0, -# "aio-max-batch":0 +# "id": "iothread1", +# "thread-id": 3135, +# "holders": [ +# { +# "export-id": "export0", +# "type": "block-export" +# } +# ], +# "poll-max-ns": 32768, +# "poll-grow": 0, +# "poll-shrink": 0, +# "aio-max-batch": 0 # } # ] # } --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763103; cv=none; d=zohomail.com; s=zohoarc; b=TCbcMwab1P4a3dQ33RbYPwYU3Ho71I5NtB3duXJDg8vl/AHCqyZxTiVcAILAxiC/zNlma0OK/WRFUYoMmCCdikc3yb9b1Ksf1SXzL3NvOLaqhzs0fMwLidmJVmPqo5AO/s/TSVryQf+yCtMrsvf/z5nTuL9NL1JzqFM9EY0JBMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763103; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Pz3DcON57YEbbfHibWzK/oVMwkZxaS7iLzoMd5bKkPw=; b=P7sS8iBs2FBrN84dNDt60gyst+QL+YFCg+ZdA8PQqYGiNBzrMVizR1LFxpX6E/e6A1R/hnC64RpNIiyETotmdTI67Eyb6J++EWHfA7Yr+Og6lGIdubXbcDOh9m56o4Y57oFS1Kt5oAffiOhDa3osDFoDFDx1bzd2WWPgVmZrChQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763103930816.9083821345451; Sun, 6 Sep 2026 23:38:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3SzQ-0005gs-Lx; Mon, 07 Sep 2026 02:38:00 -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 1x3SzP-0005gS-4U for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:37:59 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3SzN-00068A-9q for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:37:58 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-2d9004f39d3so39436035ad.2 for ; Sun, 06 Sep 2026 23:37:56 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:37:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763075; x=1789367875; 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=Pz3DcON57YEbbfHibWzK/oVMwkZxaS7iLzoMd5bKkPw=; b=I8oMiyZEBFmHeuVJXcL6fKI0XCokEnolvP+/VR4X5QJIJcoOwipjHJn26yTVYZIIds uhDIW2C8M96/mbD7uIAdPDbq/pEFLM2q6VzxnSSC6pDMWcnSwObSX+98VuIpj+1aJbLt +23P+8LP7CROgEB+wcbkUAKQBZzk7dRUC4N2+5yWDKAE4A3PJxyUyMI8BFwK90xZPTmx ETvvllhlZxMfBpzNSmcb39+yTU9tMvyU/UlzJ+ttr5cZK4d9Xenuw7bDt2BtxXs0rU1P KGNHXnEbFoAXdLsRrlJvv3tYzoyt4u54H6am3QJt3nyUf5VKBSkKIPPz+dRWm0zqtSLC 9EuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763075; x=1789367875; 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=Pz3DcON57YEbbfHibWzK/oVMwkZxaS7iLzoMd5bKkPw=; b=meP5e1XyKOvhEEpvHWW5sqNHb4rthGPHJ+h7orj46izGYHzblr8foPQcxlOvuMIkmE CJgAszljlFbl16iKt3KiaD65jxjjzFuTftv7rnRRTxEybyHxSqhB2KBD7TjzZwmf8RNn xn1l6rLW1kL1+NQzpr1gSTTtmVlg93rY1zTNAtCAaYilONU0opuvsi+XLgfznflStojs USQq2NPDfkXnPgy9GDbQoQlBYk55cN8dzl48pQjao14fKk4PiEIXWBsFgcvDYSrnqeEW 7wWOU7YdSf77/d+Ryt/26KGCYVJ+MkrMTtiqKoZbbCUWhJuqUhEjv6ffMVv4//YQ3aaI VYYQ== X-Gm-Message-State: AFuF++nI8gnZuQONUNSXRjZTiqyiRC8sDF7L/qt4V5SVdYeCoJjvB2xZ WL/c6flySwTeVV+p5azE2WswAd2xmDbmbrpCBNLyckOCPgE4ND1BtT1OT+u08LvBJ2FU0g== X-Gm-Gg: AYBFou23kKMNQV5Il+lNZC9VT7UuT0791MysfoqbZjYV6fTfOUDlPFLg57rk4p6Vz7Z 6o+ubNuiFeotg1jHsZMFxa+c1/JnAn0YDaMcqx+BdX1F4DEsHNG01zGXQWZpe2LzCUDHhvsm0ms jW6mW7nSYebtQ0jtv1Ox7/Cq5Ytm6ko3cQkoxXeMYPl1nFLT7R1sWTvDFRo9qIMdHxqbDzIgCQJ EPU8jv1mrad84yJXHd6AqBeD/7g1AtdSkPnNqZLczK7xY7szmxh2yuP7y6xzkiClP40J271AddG C22GFvVwH98z8udVK7K1dOjk5x7y7VYTJsKBo4OvEEYFmSmvTXm1yUtFo3yLpJB8jefijLD1dbO OOFupmqHrlz1gF5v6mbGI3mJ2nojZMveU8ix9y6uo+eVqLK5jeE1LhHLoMyzKuSfZqPD1+w3KmQ 1xYTYYVvHNrwHux9Qjnnj0n2j0snKsZD7+N2QJNGSWq5u/a1+QMPaSHtns/38Zeb3prI1nyn90f A7r2v5qthPsG7H7NRXI0BkjQhQ= X-Received: by 2002:a17:902:c40f:b0:2d7:107c:917b with SMTP id d9443c01a7336-2db1212ee51mr291909715ad.0.1788763075408; Sun, 06 Sep 2026 23:37:55 -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 V15 03/14] iothread: add holder-aware AioContext accessors Date: Mon, 7 Sep 2026 14:37:14 +0800 Message-ID: <20260907063725.626685-4-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x635.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763104929158500 Content-Type: text/plain; charset="utf-8" Introduce iothread_ref_and_get_aio_context() with a holder argument and its counterpart iothread_unref_and_put_aio_context(). Previously, users of an IOThread AioContext did not explicitly record their identity, making it difficult to debug which devices or subsystems were pinning an IOThread. These new helpers provide the infrastructure for callers to register their identity. Subsequent patches convert existing users to the new helpers. Registering a holder takes an IOThread object reference so that the IOThread and its AioContext stay alive until the matching put operation. Document the ownership and BQL requirements. Reviewed-by: Stefan Hajnoczi Reviewed-by: Markus Armbruster Signed-off-by: Zhang Chen --- include/system/iothread.h | 22 ++++++++++++++++++++++ iothread.c | 24 +++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/include/system/iothread.h b/include/system/iothread.h index b8aeb32b0e..f6c5f95dd9 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -67,6 +67,28 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); AioContext *iothread_get_aio_context(IOThread *iothread); + +/* + * Register @holder and return @iothread's AioContext. The holder is copi= ed, + * and a reference is taken on @iothread so that both the IOThread and its + * AioContext remain alive. + * + * The caller must eventually call iothread_unref_and_put_aio_context() wi= th an + * equivalent holder. This function is not thread-safe and must be called + * under the Big QEMU Lock (BQL). + */ +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder); + +/* + * Unregister @holder and release the corresponding reference on @iothread. + * Calling this function without a matching + * iothread_ref_and_get_aio_context() call is a programming error. + * + * This function is not thread-safe and must be called under the BQL. + */ +void iothread_unref_and_put_aio_context(IOThread *iothread, + const IOThreadHolder *holder); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 /* diff --git a/iothread.c b/iothread.c index 66dfde626e..58dace351c 100644 --- a/iothread.c +++ b/iothread.c @@ -33,6 +33,11 @@ void iothread_ref(IOThread *iothread, const IOThreadHold= er *holder) assert(holder); =20 QAPI_LIST_PREPEND(iothread->holders, QAPI_CLONE(IOThreadHolder, holder= )); + /* + * This guarantees that the IOThread and its AioContext remain alive + * as long as there is a holder. + */ + object_ref(OBJECT(iothread)); } =20 static int iothread_holder_compare(const IOThreadHolder *holder_a, @@ -78,6 +83,7 @@ void iothread_unref(IOThread *iothread, const IOThreadHol= der *holder) *prev =3D curr->next; curr->next =3D NULL; qapi_free_IOThreadHolderList(curr); + object_unref(OBJECT(iothread)); return; } prev =3D &curr->next; @@ -199,7 +205,7 @@ static void iothread_init_gcontext(IOThread *iothread, = const char *thread_name) g_autofree char *name =3D g_strdup_printf("%s aio-context", thread_nam= e); =20 iothread->worker_context =3D g_main_context_new(); - source =3D aio_get_g_source(iothread_get_aio_context(iothread)); + source =3D aio_get_g_source(iothread->ctx); g_source_set_name(source, name); g_source_attach(source, iothread->worker_context); g_source_unref(source); @@ -421,6 +427,22 @@ AioContext *iothread_get_aio_context(IOThread *iothrea= d) return iothread->ctx; } =20 +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + const IOThreadHolder *holder) +{ + /* Add IOThreadHolder to the list */ + iothread_ref(iothread, holder); + + return iothread->ctx; +} + +void iothread_unref_and_put_aio_context(IOThread *iothread, + const IOThreadHolder *holder) +{ + /* Delete IOThreadHolder from the list */ + iothread_unref(iothread, holder); +} + static int query_one_iothread(Object *object, void *opaque) { IOThreadInfoList ***tail =3D opaque; --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763103; cv=none; d=zohomail.com; s=zohoarc; b=F/XcCIc+vHIprhGxuRXFyIWposiPfeHCeHhoJIy/Y8JpPrd/b33TxYbNJdpLZl+9q9sKosghpkpCU5eqmzWkJUha9XfQBcQzGP5vw1Z2KaywgMxDwVgmjFSJDOog+r5u3995xwPvWGl7nomBozM/IABrnRZPqYx+GZX7hY4FEZg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763103; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oeURIEcCI8TbII/h58ISje3mK5oO8wJcPqe347GxoX0=; b=KBQJNeUhx76ClH+bjQWj4DnLZQttnk/2FoUEaMwkQfdOrFYRD+bmWu64NFfvVkAA/zSSu0yAs0+3or6Dqswn/wdV3L3LLIId0MOC1vfsyij8vadBCqvU3c4gcbLyrv3yPpjxh47MzLr2pt6h9AavA3opFNPdPGShV6TASjFQs/0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763103668710.1351752759102; Sun, 6 Sep 2026 23:38:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3SzT-0005hJ-Dr; Mon, 07 Sep 2026 02:38:03 -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 1x3SzS-0005h2-4R for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:02 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3SzQ-00068R-CV for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:01 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2caced6038eso30590125ad.0 for ; Sun, 06 Sep 2026 23:38:00 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:37:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763079; x=1789367879; 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=oeURIEcCI8TbII/h58ISje3mK5oO8wJcPqe347GxoX0=; b=WT9sNaR6W8bDC0JkMA7G47n7VJ2afWfzgc1E30PJ1kkpqSt/XCGUwWsF4+/im6oVt6 78EuLOPrrgTn20IUn1Skw/KoZOFf39/8q1beajYEwfbdXvZOB2PtPtdGzzmFjrJ97pl6 uwqKJgx89RCm9/xZpBwVwdho1zkaAMnPgLgfUmSUD11Grt8BvVqSGU3BkeIGkVxBy7rN G6D0MC2tHbR+mu4MoBITjDN3fJmEXu4/FGXxGaCti/ydBUquUjB9LwpFTAtMQgeMJlsF dqi8TrssJrmX0KSPhheCIRhXk07AN4/PMnsGzdvo/841edR0jjZYcZRlyEkgaRdGIDwk XMJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763079; x=1789367879; 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=oeURIEcCI8TbII/h58ISje3mK5oO8wJcPqe347GxoX0=; b=gPLgVSJhb0fTh+Q5+sha1d+YN564pISHwkunq1gpGcunDzwqvdPvZ5Bvh5QoBFX9ah bBzhG1l2Hyw54xPaPb5O2psgjU6yqKcAMEUVeo+IaFdj+DZ/dYSgQClxF8AQiGcfRF66 JZrKFZuACxKGPy2gTjSCMawcs3sDZBOxXLlxJp8rmADTUw5RXG6HxC823IUxzkqlmLol kHbc3VJ8RLCg4SNaZpYQEib2ziNteCdvkpAsPNnjd4aRgI+qFeIyNM/ngvHZRX/78vuz 3Ul9Uv1iFzTwJfJDt/l00+DLGWfR8VMMiBl2pOCBCuvK801PttsjXI8J5cP5DdHzYdm3 3n8A== X-Gm-Message-State: AFuF++nA7Br3TeaZ6NZ1xh1U4KT8QwHAwa48/qfdI46pyDJaidAPSl6p jyxrSQfDYLLb/khpM7vAr31ZMc6Y3//p9cyZTMagwBzbQ96UHZL/8kT/nHio9j1s4Y/2aw== X-Gm-Gg: AYBFou1wfL8pFURoKt8NJ7ZP+fwsHofgbSmPP97tBtlBe3YjG6eyWiRRKEw1Jx05rZL DzPuaLStDV1b25YTcN5USbcDWoLU3PQ9X2hXdFnH58aSp/vWxdk9Xvu1nvpi1crUtjm8hX1Leau 60u8qlx8vlnpn2f1tsoHBvaukFyXywYMo6BS5wuIrlRJE9pYNC4/72AYFsTZzqpSNou81qAYgU2 SP+728NnCs/rfJ+DvSxz4iyP0eeYgDymfCvHjXT8vgd+sMmB9OvFLwrWeozrkbUB7x7WOEq+GsC ktQACbOhpL8Tbd5C9zdOzLXyxchTNIL1df0iPNpa5M4f5Z0pAF78wm0q5yGinJtUdgKn1B/01dr 4vmQMyBzclCMbXT46w53yiPCCHbhlAjJf4xqRVjisSQXbs8VscomcWzvWCkiaI98Sn9X8kGU2P3 WaIBcg5kylQurKKhhTe5NjrJy5BX/6NqNWZsMn13Sr4/nZN+RJcOZgywCz0fepP+d9FQp0cbTVP gySRvrnP7j7/ExVKg== X-Received: by 2002:a17:903:8d0:b0:2d6:fddf:a890 with SMTP id d9443c01a7336-2dafaf31cedmr268653095ad.6.1788763079005; Sun, 06 Sep 2026 23:37:59 -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 V15 04/14] block/export: track IOThread references Date: Mon, 7 Sep 2026 14:37:15 +0800 Message-ID: <20260907063725.626685-5-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763106476158500 Content-Type: text/plain; charset="utf-8" Track the IOThreads used by a block export and identify the holder with the unique BlockExportOptions id. Acquire holder-aware references during export creation and release them on error or export deletion. Support both single- and multi-iothread exports. Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen --- block/export/export.c | 62 ++++++++++++++++++++++++++++++++++++------ include/block/export.h | 5 ++++ 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index b733f269f3..0e019545ef 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -15,7 +15,6 @@ =20 #include "block/block.h" #include "system/block-backend.h" -#include "system/iothread.h" #include "block/export.h" #include "block/fuse.h" #include "block/nbd.h" @@ -72,6 +71,32 @@ static const BlockExportDriver *blk_exp_find_driver(Bloc= kExportType type) return NULL; } =20 +static void init_iothreads(const char *holder_id, IOThread **iothreads, + size_t num_iothreads, AioContext **aio_ctxs) +{ + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_id =3D (char *)holder_id, + }; + + for (size_t i =3D 0; i < num_iothreads; i++) { + aio_ctxs[i] =3D iothread_ref_and_get_aio_context(iothreads[i], &ho= lder); + } +} + +static void cleanup_iothreads(const char *holder_id, IOThread **iothreads, + size_t num_iothreads) +{ + const IOThreadHolder holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_BLOCK_EXPORT, + .u.block_export.export_id =3D (char *)holder_id, + }; + + for (size_t i =3D 0; i < num_iothreads; i++) { + iothread_unref_and_put_aio_context(iothreads[i], &holder); + } +} + BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) { bool fixed_iothread =3D export->has_fixed_iothread && export->fixed_io= thread; @@ -85,6 +110,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Err= or **errp) AioContext *ctx; AioContext **multithread_ctxs =3D NULL; size_t multithread_count =3D 0; + g_autofree IOThread **local_iothreads =3D NULL; + size_t iothread_count =3D 0; uint64_t perm; int ret; =20 @@ -139,7 +166,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) goto fail; } =20 - new_ctx =3D iothread_get_aio_context(iothread); + local_iothreads =3D g_new0(IOThread *, 1); + local_iothreads[0] =3D iothread; + init_iothreads(export->id, local_iothreads, 1, &new_ctx); + iothread_count =3D 1; =20 /* Ignore errors with fixed-iothread=3Dfalse */ set_context_errp =3D fixed_iothread ? errp : NULL; @@ -163,8 +193,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) return NULL; } =20 + local_iothreads =3D g_new0(IOThread *, multithread_count); multithread_ctxs =3D g_new(AioContext *, multithread_count); i =3D 0; + for (strList *e =3D iothread_list; e; e =3D e->next) { IOThread *iothread =3D iothread_by_id(e->value); =20 @@ -172,9 +204,12 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) error_setg(errp, "iothread \"%s\" not found", e->value); goto fail; } - multithread_ctxs[i++] =3D iothread_get_aio_context(iothread); + local_iothreads[i++] =3D iothread; } assert(i =3D=3D multithread_count); + init_iothreads(export->id, local_iothreads, multithread_count, + multithread_ctxs); + iothread_count =3D multithread_count; } =20 bdrv_graph_rdlock_main_loop(); @@ -225,12 +260,14 @@ BlockExport *blk_exp_add(BlockExportOptions *export, = Error **errp) assert(drv->instance_size >=3D sizeof(BlockExport)); exp =3D g_malloc0(drv->instance_size); *exp =3D (BlockExport) { - .drv =3D drv, - .refcount =3D 1, - .user_owned =3D true, - .id =3D g_strdup(export->id), - .ctx =3D ctx, - .blk =3D blk, + .drv =3D drv, + .refcount =3D 1, + .user_owned =3D true, + .id =3D g_strdup(export->id), + .ctx =3D ctx, + .blk =3D blk, + .iothreads =3D g_steal_pointer(&local_iothreads), + .iothread_count =3D iothread_count, }; =20 ret =3D drv->create(exp, export, multithread_ctxs, multithread_count, = errp); @@ -250,8 +287,12 @@ fail: blk_unref(blk); } if (exp) { + cleanup_iothreads(exp->id, exp->iothreads, exp->iothread_count); + g_free(exp->iothreads); g_free(exp->id); g_free(exp); + } else { + cleanup_iothreads(export->id, local_iothreads, iothread_count); } g_free(multithread_ctxs); return NULL; @@ -273,6 +314,9 @@ static void blk_exp_delete_bh(void *opaque) exp->drv->delete(exp); blk_set_dev_ops(exp->blk, NULL, NULL); blk_unref(exp->blk); + + cleanup_iothreads(exp->id, exp->iothreads, exp->iothread_count); + g_free(exp->iothreads); qapi_event_send_block_export_deleted(exp->id); g_free(exp->id); g_free(exp); diff --git a/include/block/export.h b/include/block/export.h index ca45da928c..ce8e4eb604 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -16,6 +16,7 @@ =20 #include "qapi/qapi-types-block-export.h" #include "qemu/queue.h" +#include "system/iothread.h" =20 typedef struct BlockExport BlockExport; =20 @@ -89,6 +90,10 @@ struct BlockExport { =20 /* List entry for block_exports */ QLIST_ENTRY(BlockExport) next; + + /* The IOThreads utilized by this specific block export */ + IOThread **iothreads; + size_t iothread_count; }; =20 BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp); --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763204; cv=none; d=zohomail.com; s=zohoarc; b=TC7MhRIGlgqABRe0fIUEt03Z5GPXigGe3gC5AvWM8JvRIc65Q8UUjyzhHUkHeaOHXOrwJC0GQppBUGcMn3yh7B8abIPm68q+PBrOzF1jlIJ+X87MjeFJyOIVMe4QR+3kR8nbxZFf7dOgwKS0AGrrcDQpQq6Tn7jL0QEJ5zlEI1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763204; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A98whTvdVRQzMIBod4u+GjQWUac5pbRmbOiKgjUuYUQ=; b=KA7a1pCag86wHw2gFk46RgLRGUAKjAlcci2bPuGZJoJXxJt1SbC3GzHbYZra6ZIlPivsvdSsBTazTKWrcXVoR2wsOVFQxpo43Ml4St+9aPs+TuMdWhFEKSQ9KgWR6/2Jy7GviwPYowml0JK572Ncg48QyfWd0Qs7L4XnvAeUPKc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763204403167.43419596713738; Sun, 6 Sep 2026 23:40:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3SzX-0005hs-R3; Mon, 07 Sep 2026 02:38:07 -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 1x3SzW-0005hf-Kx for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:06 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3SzV-00068c-0g for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:06 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2d9b60c652aso37675775ad.1 for ; Sun, 06 Sep 2026 23:38:04 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.37.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:38:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763083; x=1789367883; 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=A98whTvdVRQzMIBod4u+GjQWUac5pbRmbOiKgjUuYUQ=; b=MW5KAkbiT3tqtddThd7p/k8LrUNdr5iOT/Pxng3Y6k15IYhNq0wVTqtegUD4jmMNww DO5DMjdowdMgKPvXLOFK30Y38vu1Ai+1vM+UY5ZJ7N7WguJXapi0YrXc4ua0/A0FyK8P xE5tvXVD/FGGe1qq2DiOvqaqxIHvR2OgDSwYUMA+PreA7LAvKOz1OPLPy9oWEjiUp7yC IAGmK+lkWs8abgaO5XTRJYYNUp7qiDSSWsUOXsYHX4YKM0HN/0JnN9DJscy2hAUCFSv+ Olt4gkJdzoPNGmWmYANRbyXVNbwZpORIHdxdiaDvE+LHnvbEfdbfiPLysfompWn2Qi1p Xgdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763083; x=1789367883; 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=A98whTvdVRQzMIBod4u+GjQWUac5pbRmbOiKgjUuYUQ=; b=iKTUeDe9Uqiqp07HNs9NIiwgUl9sqgZe6dr24JFFlGGNPbaPJAGwtNC4jsDbulfjaa zkAXeKTlTiiRR7xOl0OG4VWUIoRG1ydk/zkg9tZT7Mu5RNnRQr5yVu/Wrh2JNIbiHi3P 150sIwJsCe9Y5g84v4hxHV+I5L7wmE2oLzVqGHWOnQaUzNj0PtA66TwHrMDuUAmsqOt5 FUgk2K+ii/FA+qsHThV0SZ31bdIKnrCkrEmdk+oJ4d6BORkBhOMcQNfuEFI5pbzkur21 opiYXpkRXcy26gdd9P5H6ehlGmWa2MiI1QTvPpXmGbmkkf5IcfDIwLVzh3ixl5Jx36LZ Mh3A== X-Gm-Message-State: AFuF++nqy4HIbId1EqhCJkys6XH/gcvLB36lSCS1KMoAyeE9t5cJRzvO toA6vb6UkCj8lT2cdrRpn6QcBJGOcvQNTodlyfAnyzyM5PF8mHej9FvBoaIilJiBucVbYg== X-Gm-Gg: AYBFou1c4imOLyzNHtslwxhHG43ujfmjsiE0WAB9xHq3jICtDVCI98E2kMfJ9B/WyNu jQ1+IgMfSn1j6p7Rna9QXhvJC38Hh70z2JtB3sn0F88QNa2NuOcerpfqyNbSC7OJf3GmuPA/lYa vKFuM5OemnxPfi8r9ywKWnL2Rh8Kg3xY9p5PeC1XU1VHs/sZ0io5JMXzsyqS4gYxzB5VPpMqSlB lTVANsi35PEKvBla4DH+IrOTT961QFI674OKPs3XRcIULoJUhYG9nSncTu+34a4XFnTmkHe1+eb LJ0y+0EOZFYYRxGp3Y04tFzmSrT7+7FynVsTAFsg8jaQJN8fgRHdyYGUSpg+WV7RT3aJDRozg3F 5XYJUruptSEcZOTtuN7T5moPSKxnF3AdoQwmoTVAKkNYitcUPDt/SjMvFRx/bVVPd1/toJeMn+H stwZQNP7MeEn7bNKvBlYnzuaVH9jx0pT0wHLG4kA/fqPPdxYDZWGhLibCAHEGyns5RG/9BAhu2O LsAysRFFEgrOaxo X-Received: by 2002:a17:902:bb88:b0:2d3:716e:e2ae with SMTP id d9443c01a7336-2db1261df71mr223346885ad.6.1788763083303; Sun, 06 Sep 2026 23:38:03 -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 V15 05/14] monitor: track IOThread users with QOM paths Date: Mon, 7 Sep 2026 14:37:16 +0800 Message-ID: <20260907063725.626685-6-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62c.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763205019158500 Content-Type: text/plain; charset="utf-8" Monitors that require an IOThread share the internal mon_iothread. Account for each monitor explicitly in IOThread holder tracking, using the monitor's canonical QOM path to distinguish holders. Acquire the shared monitor IOThread AioContext once and store the IOThread and canonical QOM path so the holder can be released after the monitor has been removed from the QOM tree. Reuse the stored context for later operations. Release the holder from monitor_finalize(), after resources associated with the AioContext have been destroyed. This pairs the reference taken in complete() with instance finalization and keeps the IOThread alive throughout monitor teardown. The internal mon_iothread remains hidden from query-iothreads, as before. Management applications therefore cannot use it to determine which monitors are using the IOThread. Nevertheless, track the monitor holders so that they follow the same explicit holder and IOThread reference lifecycle as other AioContext users. Signed-off-by: Zhang Chen --- monitor/monitor-internal.h | 5 +++++ monitor/monitor.c | 26 +++++++++++++++++++++----- monitor/qmp.c | 5 +++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 822a66d06d..1d5aeae5e6 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -77,6 +77,11 @@ struct Monitor { GString *outbuf; guint out_watch; int mux_out; + + /* iothread context and holder identity */ + IOThread *iothread; + char *iothread_qom_path; + AioContext *ctx; }; =20 struct MonitorQMPClass { diff --git a/monitor/monitor.c b/monitor/monitor.c index 2654b81890..cc7f6785b5 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -93,6 +93,16 @@ static void monitor_finalize(Object *obj) qemu_chr_fe_deinit(&mon->chr, false); g_string_free(mon->outbuf, true); qemu_mutex_destroy(&mon->mon_lock); + + if (mon->iothread) { + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D mon->iothread_qom_path, + }; + + iothread_unref_and_put_aio_context(mon->iothread, &io_holder); + } + g_free(mon->iothread_qom_path); } =20 static char *monitor_get_chardev_id(Object *obj, Error **errp) @@ -521,7 +531,7 @@ void monitor_suspend(Monitor *mon) * Kick I/O thread to make sure this takes effect. It'll be * evaluated again in prepare() of the watch object. */ - aio_notify(iothread_get_aio_context(mon_iothread)); + aio_notify(mon->ctx); } =20 trace_monitor_suspend(mon, 1); @@ -661,7 +671,6 @@ char *monitor_compat_id(void) static void monitor_complete(UserCreatable *uc, Error **errp) { Monitor *mon =3D MONITOR(uc); - AioContext *ctx; =20 if (mon->chardev_id) { Chardev *chr =3D qemu_chr_find(mon->chardev_id); @@ -680,11 +689,18 @@ static void monitor_complete(UserCreatable *uc, Error= **errp) mon_iothread =3D iothread_create("mon_iothread", &error_abort); } =20 - ctx =3D iothread_get_aio_context(mon_iothread); + mon->iothread =3D mon_iothread; + mon->iothread_qom_path =3D object_get_canonical_path(OBJECT(mon)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D mon->iothread_qom_path, + }; + + mon->ctx =3D iothread_ref_and_get_aio_context(mon->iothread, &io_h= older); } else { - ctx =3D qemu_get_aio_context(); + mon->ctx =3D qemu_get_aio_context(); } - mon->accept_input_bh =3D aio_bh_new(ctx, monitor_accept_input, mon); + mon->accept_input_bh =3D aio_bh_new(mon->ctx, monitor_accept_input, mo= n); } =20 int monitor_new(MonitorOptions *opts, bool allow_hmp, Error **errp) diff --git a/monitor/qmp.c b/monitor/qmp.c index aec0315775..de56345456 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -734,7 +734,8 @@ static void monitor_qmp_complete(UserCreatable *uc, Err= or **errp) * thread. Schedule a bottom half. */ mon->setup_pending =3D true; - aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread), + + aio_bh_schedule_oneshot(MONITOR(mon)->ctx, monitor_qmp_setup_handlers_bh, mon); /* The bottom half will add @mon to @mon_list */ } else { @@ -789,7 +790,7 @@ static bool monitor_qmp_prepare_delete(UserCreatable *u= c, Error **errp) =20 /* Synchronize with in-flight iothread callbacks. */ if (monitor_requires_iothread(mon)) { - aio_wait_bh_oneshot(iothread_get_aio_context(mon_iothread), + aio_wait_bh_oneshot(MONITOR(mon)->ctx, monitor_qmp_iothread_quiesce, NULL); } =20 --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763103; cv=none; d=zohomail.com; s=zohoarc; b=gFWYeE3SMvKgAdw6AZk/6NPLqQOpWBr7B2DFzh4yenkp6J4IuCfTVvykWMwGriTN74Wdw3cfliQWp4NWBVDA5txecHGi7NkBthJDgACQJoPUVeSk9MZ9oJW4Q8WEpD6++wndXB7rN1kVxmmD2+FefytWd1Nm1ZK/xHTmm3q3wEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763103; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=y4Ly304K5RRD8FDCK8Kyv4PpWyXS/MRy2p4mFYN+SIU=; b=HvEltA7TfD1GZEGwAux5Kd2gLFLoj1iM5BDJ493qNPyr21A2KCzq6/btmoJ0O0svO5FxrrK1Y26WgvOBB4CR/jVHKWaH1LQ36OqQ2rgl7fa1RZugmVPwPuJ/b+cxZq4VHPJ8peq+pdueJqLjt2vRsbbixNPTJgIptjkAGOFfVJs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763103933368.81918508537126; Sun, 6 Sep 2026 23:38:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3Szb-0005iK-JS; Mon, 07 Sep 2026 02:38:11 -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 1x3Sza-0005i9-KM for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:10 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3SzY-00068q-VP for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:10 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2d942c7cc2fso24995345ad.3 for ; Sun, 06 Sep 2026 23:38:08 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:38:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763088; x=1789367888; 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=y4Ly304K5RRD8FDCK8Kyv4PpWyXS/MRy2p4mFYN+SIU=; b=PIZYCHTmsVIXsx+RAFWKtAD6pbgn903WlXQgJKVezPU+hvdvutqgnyoF6Uu8c/ZjoC 6g/Q4+TB44rGg1p5xzPbKGf9WMWYUMddfeiw07PFUvwKwdp0SDyaA4EPqWt/TAthjZ/7 UU7HCdlOLZZSIEy0NBsTrJ8rocgDTLgkqMYg3FYzv9axQxq6F54Fw8TFpPnKbweWjzJG awrEqY/YhdW9ZL9dbDhrSb3V8YByBfnOUIT8dvzIZCinhYxQqizxIxUSrUswy8/AtKwJ nKJ0ustwOfYnY5TEhDe9RsfKYwH2c1m3QT3PhjKihnFH55YO5YzEXWaWl5ddue/sHEUm YBfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763088; x=1789367888; 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=y4Ly304K5RRD8FDCK8Kyv4PpWyXS/MRy2p4mFYN+SIU=; b=dpvr12i2oFrIHPVNiMAXRYd0UmOA+LuczLtWkKOWNDDIB6d14ooEEWeiSU7z87+zit FUeQGVZArJdtBVaXkq7ix7M63hg3OdqdDGO1bRa0D4VWjjNaoSFKe6Y8lQVEjoLlrsya Ilquh9QJWxavlEMnGFty6SSRMLMnlwD4GzgmXeSqP8/FNp+jEj8KpBnKnPwkni5XQOXj HYvNU3UJ9UhQX2KO7lhFdEmPd2T2w9ekoVyF780D3hgeTXKSYB/7SEnrVbApPYkUCX0+ QkIcyju/3mHtn/02JEUb+Y7HeGthaP0Jo9EQZi9aAaTVMIUi1e+28D7imD5aGXwIsBMz s24A== X-Gm-Message-State: AFuF++myzsulwxdax5XYvdU8iLsf8rQdrXPg5b15M3NuOW9xyAWjfAly Qx0I5KcHZ4I1PXuQ7FZ8EpdMSZ4V8FYcvljE4RdMFAPTESjgBKcnFbKn7V/RgkRWy4rOxA== X-Gm-Gg: AYBFou0ydFzvCLtgmogSTBkmjKfUD/GtKNFahr2QaveoCBVoPnesb4DrX4ycb4RjOG+ kJMnvfNUHwcH1z4Lw+WapktLgrT1cJiyLmfzAi9GGcnNDwOfyKD8qFahXCY1urQbZ6ZaItMrzA8 bB/1LTMs8HJFRKz9RUcSEqdppwElxN37+xm7TymIuiKakBYbKsHyWTF62dtW2Z/9fyG4H44gW6F 1I7E06scsLquiYGr3i+TSikx0keJJezfz5aqu+NuCiZ4MY4N02ME9hxQozI4KXBWZtBDVe7FnfZ cXs2FiFi+0zG4YYTSelK89mhk/QmTthv2iplB5BQgIqibcORxsevzo7AVgFU+tL9VWBMubG4H5L 25QPIhckWPze7LJE+6AOhr3AVHkq3SAr1leEeNmwhvCz8c8WlW7TWSDkLoeZs77xq9EFXsyc/xr CpufFmrQD8BZlI7FlnKyC5XB75yulOCZQZl2pnQN6aC1XVNKi13mjY9nkW8L/xqyJ8icnGDZeW1 N7++oAA31Gb8ZA4huNLkD7Zhqo= X-Received: by 2002:a17:902:e804:b0:2d6:ff5f:eeda with SMTP id d9443c01a7336-2db1256cfa1mr300115995ad.6.1788763087558; Sun, 06 Sep 2026 23:38:07 -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 V15 06/14] virtio-vq-mapping: track iothread-vq-mapping references using device path Date: Mon, 7 Sep 2026 14:37:17 +0800 Message-ID: <20260907063725.626685-7-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x632.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763106480158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_ref_and_get/ unref_and_put_aio_context in iothread-vq-mapping. This allows tracking IOThread users via the device's canonical QOM path, improving lifecycle traceability for virtio-blk and virtio-scsi devices. Signed-off-by: Zhang Chen --- hw/block/virtio-blk.c | 8 +++++++- hw/scsi/virtio-scsi-dataplane.c | 9 +++++++-- hw/virtio/iothread-vq-mapping.c | 20 +++++++++++++++----- include/hw/virtio/iothread-vq-mapping.h | 6 +++++- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 6b92066aff..4b2cf3d52f 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1493,9 +1493,12 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlo= ck *s, Error **errp) s->vq_aio_context =3D g_new(AioContext *, conf->num_queues); =20 if (conf->iothread_vq_mapping_list) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); + if (!iothread_vq_mapping_apply(conf->iothread_vq_mapping_list, s->vq_aio_context, conf->num_queues, + path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; @@ -1527,7 +1530,10 @@ static void virtio_blk_vq_aio_context_cleanup(VirtIO= Block *s) assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 95f13fb7c2..26ecefd547 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -65,9 +65,11 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **= errp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { + g_autofree char *path =3D 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, errp)) { + vs->conf.num_queues, path, errp)) { g_free(s->vq_aio_context); s->vq_aio_context =3D NULL; return; @@ -94,7 +96,10 @@ void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); =20 if (vs->conf.iothread_vq_mapping_list) { - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(VIRTIO_DEVICE(s))); + + iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mappin= g.c index 55ce62986c..60e1d55005 100644 --- a/hw/virtio/iothread-vq-mapping.c +++ b/hw/virtio/iothread-vq-mapping.c @@ -77,6 +77,7 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp) { IOThreadVirtQueueMappingList *node; @@ -93,10 +94,13 @@ bool iothread_vq_mapping_apply( =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - AioContext *ctx =3D iothread_get_aio_context(iothread); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; =20 - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(iothread)); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, + &io_holder); =20 if (node->value->vqs) { uint16List *vq; @@ -120,13 +124,19 @@ bool iothread_vq_mapping_apply( return true; } =20 -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list) +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder) { IOThreadVirtQueueMappingList *node; =20 for (node =3D list; node; node =3D node->next) { IOThread *iothread =3D iothread_by_id(node->value->iothread); - object_unref(OBJECT(iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D (char *)holder, + }; + + iothread_unref_and_put_aio_context(iothread, &io_holder); } } =20 diff --git a/include/hw/virtio/iothread-vq-mapping.h b/include/hw/virtio/io= thread-vq-mapping.h index 57335c3703..0d39caddf3 100644 --- a/include/hw/virtio/iothread-vq-mapping.h +++ b/include/hw/virtio/iothread-vq-mapping.h @@ -17,6 +17,7 @@ * @list: The mapping of virtqueues to IOThreads. * @vq_aio_context: The array of AioContext pointers to fill in. * @num_queues: The length of @vq_aio_context. + * @holder: The QOM paths for attached device. * @errp: If an error occurs, a pointer to the area to store the error. * * Fill in the AioContext for each virtqueue in the @vq_aio_context array = given @@ -31,15 +32,18 @@ bool iothread_vq_mapping_apply( IOThreadVirtQueueMappingList *list, AioContext **vq_aio_context, uint16_t num_queues, + const char *holder, Error **errp); =20 /** * iothread_vq_mapping_cleanup: * @list: The mapping of virtqueues to IOThreads. + * @holder: The QOM paths for attached device. * * Release IOThread object references that were acquired by * iothread_vq_mapping_apply(). */ -void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list); +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list, + const char *holder); =20 #endif /* HW_VIRTIO_IOTHREAD_VQ_MAPPING_H */ --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763173; cv=none; d=zohomail.com; s=zohoarc; b=cc8rybzX0vhSJOyldKVLWNXgTOlkltcuUHWNy/UsqxJQB6nXArs8UQIIiDy+Ki4/AK02M3vI/1Xc3nhONelUO4MFx8Tvco09YkfKO99C7jgkr47svEVLjwJEmmtzM16KaSYEuh/pamcdG3ZAy3+u8AWtmy4xyswhAalCFyxW1ko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763173; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GCwys0A7wABlzdjCSJp+U9W8UOKwT+jGbbtakz7i/jE=; b=TF8SzNh/M14Yug1GizpFzMOrST2olgRUj5mJZyEbv3NEDS2qx1sdSQQVvbqO3W4M09tjBi1EMybqDqW8WZOgQGUqjnE2JjcqZYLr2x1VivFnEeX7lFDc11jJwMRG5lm/VhTkBV5EYQ6ThZbA4SWdTHsPjZh8H+lPvQvyAysa5+U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763173613352.2299100932379; Sun, 6 Sep 2026 23:39:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3Szh-0005jI-JM; Mon, 07 Sep 2026 02:38:17 -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 1x3Szf-0005io-3z for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:15 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3Szd-00069B-9o for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:14 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2d7195706f1so34063555ad.0 for ; Sun, 06 Sep 2026 23:38:12 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:38:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763091; x=1789367891; 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=TV4u1iDgmnk75lDAMg+L9gpLB65Y+p3rPzHXDbt1scoCbMI0D9fxkcnS3ChVoJk89T GmcSlh+ytA85ucKe03Jl6FFR6/6+tojUD4hXw8HBRnSLN8SHtgCj46Ye57uDMI4Cz8Ah 244lF4ypBaQtaBO/iyFbillvEB4Vpt66eL8b5HPdvIaqR3qZTd1Jvwc35ZuiKcP1HT1y KNyg2Wz2VGE0RHq8qHWs3j3jlj4HMwWmGxPZTPaN2SSAyxO3CIeRkhKoumU7QuZsqixp QrbOb5jXuCpbWZUyV1dS5qC6tpBLXo/HDronSYoyAO8XA8KY15T0eL2wjG2MgOwKrfWa MoTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763091; x=1789367891; 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=DOdnezJIaMp9RDor82JrE0wdjaxal+Shyqk6H3mLWpyT2/6vWtJ/5FjJHmP3cW3ziR zQDmGjq1b3wg2s1ttzbFBpIvEZZJ4poz2hCfYe8ttk5KJlSWUAARyA4aNhS1jFhR72t4 uGrn/pKvmA+E0T7dKLnD/u9IeeE47teaoXzgGhu5dmIsl3ZuvYV+PXegNNMZdgx8qh3A 3xuN1NiEKCmWnXuleokx4DqaYxVQcD/Sgxwv774o6hD3JfoVE8z2TZmnp5glltmBULqR ic/s7zqgR0G9QNmqH+bK6jKFMnMFRzG84juOS3O/87JzGu6Iqi8F5Kg1eUZjtQS+nf/Y pi6w== X-Gm-Message-State: AFuF++mvdUDUWnmpj4S0spUcVcMr2KkkpgPqqXp4xNOQsuM8Gg4TU+V0 18iefZb2sb4lMXa30+Bpc6rX8+9fYR2hqCmWAI7V8OJwVhnCj4wtgo3S19TFIP2Bgaurqg== X-Gm-Gg: AYBFou0t/dVdFNSfbNSppABpCYYYgEQThnNZJUoDYToZmgdGnqV9rV1gaL4jvbf5RdK IWhxm5ytOE3MDgMFLJjbamNkumZeHHmkzDREy7TNRI2xuzcXCvah8KYT1n3PNQRguFpIlo+cqGf Jq3E202J22F9k/B8lbyMxxJHXdqux2riDDc7PLW11SBCTOVTLuYLNILp871MaPaiyDsdtQPMisr 5tVfW2uR/iPwiIaapelQfXvrg/NaXxCS/HY5LSk+bQXAOhmQOnei07o2ScKYDpx5lCg8ILlgNkj EIhpOr6fxNAl+DHkMWmAPLuJ0rZs/m1XdHWnFO22mMgZ9jmZhhV2VF60FwEx20SnZfMySKkYjTs k/pW2IwQ6w/YXpqtXB+er76C9ebriK0mJ1eF5sdgG2SIZg6gT+odHdKqUND66s6fhEHfW5qUSkI OLc4c7uK+4vppdmO7XPd/rNg/NyGrx9OqWZh0RmS1mPhmvYQfQot6UhA4VvDeIGSsauMQS5Be41 3j9rp9laOg9ipv4 X-Received: by 2002:a17:903:2349:b0:2d0:cc92:f7a3 with SMTP id d9443c01a7336-2db125a5535mr309971395ad.2.1788763091497; Sun, 06 Sep 2026 23:38:11 -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 V15 07/14] virtio: track IOThread references for thread pinning Date: Mon, 7 Sep 2026 14:37:18 +0800 Message-ID: <20260907063725.626685-8-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763174699154100 Content-Type: text/plain; charset="utf-8" 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(VirtIOBloc= k *s, Error **errp) VirtIOBlkConf *conf =3D &s->conf; BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 if (conf->iothread && conf->iothread_vq_mapping_list) { error_setg(errp, @@ -1493,8 +1494,6 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBloc= k *s, Error **errp) s->vq_aio_context =3D g_new(AioContext *, conf->num_queues); =20 if (conf->iothread_vq_mapping_list) { - g_autofree char *path =3D 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(VirtIOBl= ock *s, Error **errp) return false; } } else if (conf->iothread) { - AioContext *ctx =3D iothread_get_aio_context(conf->iothread); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(conf->iothrea= d, + &io_holder); for (unsigned i =3D 0; i < conf->num_queues; i++) { s->vq_aio_context[i] =3D ctx; } - - /* Released in virtio_blk_vq_aio_context_cleanup() */ - object_ref(OBJECT(conf->iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 0; i < conf->num_queues; i++) { @@ -1526,18 +1527,20 @@ static bool virtio_blk_vq_aio_context_init(VirtIOBl= ock *s, Error **errp) static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s) { VirtIOBlkConf *conf =3D &s->conf; + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 assert(!s->ioeventfd_started); =20 if (conf->iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list, path); } =20 if (conf->iothread) { - object_unref(OBJECT(conf->iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + iothread_unref_and_put_aio_context(conf->iothread, &io_holder); } =20 g_free(s->vq_aio_context); diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.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 **e= rrp) VirtIODevice *vdev =3D VIRTIO_DEVICE(s); BusState *qbus =3D qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + g_autofree char *path =3D object_get_canonical_path(OBJECT(vdev)); =20 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 **e= rrp) s->vq_aio_context[1] =3D qemu_get_aio_context(); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D 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 =3D iothread_get_aio_context(vs->conf.iothread); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + AioContext *ctx =3D iothread_ref_and_get_aio_context(vs->conf.ioth= read, + &io_holder); for (uint16_t i =3D 0; i < vs->conf.num_queues; i++) { s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] =3D ctx; } - - /* Released in virtio_scsi_dataplane_cleanup() */ - object_ref(OBJECT(vs->conf.iothread)); } else { AioContext *ctx =3D qemu_get_aio_context(); for (unsigned i =3D 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 =3D VIRTIO_SCSI_COMMON(s); + g_autofree char *path =3D object_get_canonical_path(OBJECT(VIRTIO_DEVI= CE(s))); =20 if (vs->conf.iothread_vq_mapping_list) { - g_autofree char *path =3D object_get_canonical_path( - OBJECT(VIRTIO_DEVICE(s))); - iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list, pat= h); } =20 if (vs->conf.iothread) { - object_unref(OBJECT(vs->conf.iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + iothread_unref_and_put_aio_context(vs->conf.iothread, &io_holder); } =20 g_free(s->vq_aio_context); --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763173; cv=none; d=zohomail.com; s=zohoarc; b=mO15jaAiW8aljQA8tD+OMivJpxGBcw7rtGnSLw739Zh/D77qvNIY/sUK0o+JHwewf6HvgSSCCSha+cNbHqTQSN+OmSokgqYEfIKIhBQlCu7jBHuBz4YQNox4vO7NxupwBIvl2L0qxcgC9WYoMvcQ9YP0IUASV5clza2EztsGts4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763173; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yEaJNJW0M3RfOG4LVNk4cR5m8NBuIru80hqnsp5wPiU=; b=O/oZl5KSqAvHggxhYW8EaWcEoFBl14UXK5TbwecuBtyjLU6RbwZoquToK4UyM6Y69H+gCApGCAUk8efbEoULdlsPmGgd2IyzvVdVir46dpkKObAijLfc6Y+AZoCpjrG9qu76PS4p+YfQtDSCW8LpbyQfGuFCgogeT79UQg8OM6Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763173492719.621621694134; Sun, 6 Sep 2026 23:39:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3Szj-0005jf-0T; Mon, 07 Sep 2026 02:38:19 -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 1x3Szh-0005jJ-Qt for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:17 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3Szg-00069N-7j for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:17 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2db18e5cb56so28404265ad.0 for ; Sun, 06 Sep 2026 23:38:15 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.38.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763095; x=1789367895; 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=yEaJNJW0M3RfOG4LVNk4cR5m8NBuIru80hqnsp5wPiU=; b=LvIrDQ8Iou+29XBm0h5ONDwJDGEkeW1knRyQU9iApGqX0otrvpT/NKo4aEMEX2/foY N3I/QBQzNfl5pKcJDC46zO4bHo5k44ZzYEoS5VQgFDX/SMI/sAg+IfAzVhK1YUOL/dC9 LBdUq5UVY7UR6WCvLCAhtire50YempHF31dVgv9zIv7dsgAKrCWsTZoBSqFBp9YaWOsr 363X/G6PqhqjP5O7fEtmKD06Mk4kmEPG3+/rdcBPVeLN+fRbIAsUzdsnpUndb1rekLkh tudbtBBNgaajff14Yr3RiXJI9CHxB0RYJYBukzI+Sg+SIoyqYHuVaLJIXzHtfxLcYVYh Wp4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763095; x=1789367895; 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=yEaJNJW0M3RfOG4LVNk4cR5m8NBuIru80hqnsp5wPiU=; b=Dpz7PmF8Qo/+bx+3S2cPdNZSOJoE8x/ELrad3JRndOAfIsOj04vStTeVOg+0xvfKBU cM3X4rQUKBMNHSwXG/ss4QZXscabs4gZJWQU0gCt7o0RLn8n/JmM/l4GG4LvDzQ3NPPG buuXOm9bnC2Wrz8htHvaPmXOxOWB1Uhev1LVR1NkvHI4B3X13R+ZcolN3FwsyS7B14di vkCr0Sfp6AEPuMpPY/QDzO75JWxCWnZ2vSXa+P1pjn8tXVy4rF9dVEZkg74u83kajzeJ IsYxxamfvLMes6tK7Y0ziqYdDb2vjUy6LsAS2F9Idi7omnJaGLkH1XfZLaOdUBdJwdsf zRSA== X-Gm-Message-State: AFuF++mX+723De1m9Uvj+PLtFJlBo9a9ZDBFR4+m4ZGHbpYP8FKKenBo 7N2aZwM1EKANsT4T+hzrywaw4ntQLLShBEPoUS15Krq3Z8xHQ7svmJPcShz4YlinYtLYlw== X-Gm-Gg: AYBFou2jRMfidRqMKbLERbCrYvYD4XZ+dwFLREQB5iIMp/lJkVd29xTeO1H9QOBhpiA YoVb2wQYad1Xf5tiHMABlPdB1XmASfaDuyoBezuIfjzjDCTYz26YJOgskya1QnWS5TdOXpaWMdo ZmH42pftkdAo1Tntz/9eguYIDIbkSsZve4K7FzC3a1LfOmFKOCMY7j5MVRPd8Xsm8E+XVLRuVos 6np/1dMG0zimo+xykWxpUZEymDdeRjkceBYMClcjqsRmIbFnuKSbXgsFZ5+L9Z3q0Age6fgL+K+ H5CGA8Hi7KZWbB/ajAN4fQbwXrnOFl50wfiOKtHLkdPvAA7IZPlvLnvDw/QxpTZ65L8L/Of1MuJ qrpsWHEHivycqDgVLnRgokEAl59EVOE5rw0A9QzpERULSzKadIPUpHYvvCOP/gjVHW6/H9Ltp0K j3plfrcrMJvQM4PrEQu1LB0sCHRqnkqAX0G+0LEGQinaGjDgJ0RS6hoOyReP8/FHULRGU1iIBcp dO/zA9L78M4DjxK X-Received: by 2002:a17:902:c1d4:b0:2d8:d4d0:792e with SMTP id d9443c01a7336-2db128816cdmr198036915ad.18.1788763094905; Sun, 06 Sep 2026 23:38:14 -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 V15 08/14] net/colo: track IOThread references using path-based holder Date: Mon, 7 Sep 2026 14:37:19 +0800 Message-ID: <20260907063725.626685-9-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x632.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763174654154100 Content-Type: text/plain; charset="utf-8" Convert colo-compare to use the iothread_ref_and_get_aio_context() and iothread_unref_and_put_aio_context() APIs. This ensures that IOThread references are tracked using the COLO object's canonical QOM path as the holder ID. This refactoring improves IOThread lifecycle traceability and aligns the code with modern QEMU iothread reference management patterns. Signed-off-by: Zhang Chen --- net/colo-compare.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 5986fb1e88..361ee32729 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -130,6 +130,7 @@ struct CompareState { GHashTable *connection_track_table; =20 IOThread *iothread; + AioContext *iothread_ctx; GMainContext *worker_context; QEMUTimer *packet_check_timer; =20 @@ -922,9 +923,7 @@ void colo_notify_compares_event(void *opaque, int event= , Error **errp) =20 static void colo_compare_timer_init(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - - s->packet_check_timer =3D aio_timer_new(ctx, QEMU_CLOCK_HOST, + s->packet_check_timer =3D aio_timer_new(s->iothread_ctx, QEMU_CLOCK_HO= ST, SCALE_MS, check_old_packet_regular, s); timer_mod(s->packet_check_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) + @@ -964,8 +963,15 @@ static void colo_compare_handle_event(void *opaque) =20 static void colo_compare_iothread(CompareState *s) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - object_ref(OBJECT(s->iothread)); + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + + AioContext *ctx =3D iothread_ref_and_get_aio_context(s->iothread, &io_= holder); + + s->iothread_ctx =3D ctx; s->worker_context =3D iothread_get_g_main_context(s->iothread); =20 qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read, @@ -1404,6 +1410,7 @@ static void colo_compare_finalize(Object *obj) { CompareState *s =3D COLO_COMPARE(obj); CompareState *tmp; + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); =20 qemu_mutex_lock(&colo_compare_mutex); QTAILQ_FOREACH(tmp, &net_compares, next) { @@ -1430,18 +1437,20 @@ static void colo_compare_finalize(Object *obj) g_clear_pointer(&s->event_bh, qemu_bh_delete); =20 if (s->iothread) { - AioContext *ctx =3D iothread_get_aio_context(s->iothread); - - AIO_WAIT_WHILE(ctx, !s->out_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->out_sendco.done); if (s->notify_dev) { - AIO_WAIT_WHILE(ctx, !s->notify_sendco.done); + AIO_WAIT_WHILE(s->iothread_ctx, !s->notify_sendco.done); } =20 /* Release all unhandled packets after compare thread exited */ g_queue_foreach(&s->conn_list, colo_flush_packets, s); AIO_WAIT_WHILE(NULL, !s->out_sendco.done); =20 - object_unref(OBJECT(s->iothread)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + iothread_unref_and_put_aio_context(s->iothread, &io_holder); } =20 g_queue_clear(&s->conn_list); --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763179; cv=none; d=zohomail.com; s=zohoarc; b=aV81v6w0qdMX2vZEiQhUi6hF3qA21IISADcfZMEmW7D6NX7v+7+514TeFvUq4oHuZU7nAvoqyCTFJBYbUH5qZjl3XoPh50kkyapPjrf0iz5MYcTVxNZdxO2itj4jWKmvW3Et+/s12xeDsMm/sQAqhJyMjjEhTZDfIkqCALXpXD0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763179; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mf9E5O+vpQ3XA+Jie+/p9nC3sGIPSjge6K4hjAZVK9U=; b=jrIrEYNFCwUoOgn6nCjz0qcI9C3mmC9vmuOl5z8xAP7mKyWA4e3B3p/5hgILffwlbycY29+zOQdJrg6HarATe3g1HhGY00ETVpiotEHUY858c2TnY+8ogAKlhAM193m/e9mfZ5CS5PTx98gXCLUVj9gb9fBW6WHlDfqaZf3wWXc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178876317953512.494319591173394; Sun, 6 Sep 2026 23:39:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3Szn-0005tJ-1w; Mon, 07 Sep 2026 02:38:23 -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 1x3Szm-0005nU-4r for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:22 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3Szk-00069d-KV for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:21 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2cace91f112so26032235ad.0 for ; Sun, 06 Sep 2026 23:38:20 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.38.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:38:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763099; x=1789367899; 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=mf9E5O+vpQ3XA+Jie+/p9nC3sGIPSjge6K4hjAZVK9U=; b=CnN/ScZqkJbEbr/QT3byAXnuMt8tQPWdjXwHQX7MKCcgNng+U/h5QarB9SXZr93xA7 GRskhy9roV4K81xu2nhLD1uwYH2F0EOPWikoo8gi51AV3UwUI129wV3RIzzIXQpsAZaa VaW4e1W3VaGP/EP6KaIrUCRU2W0T9Uf2wlZXjKGcvoABKII4r2J00hSrI8e2koJgCuSj saFrJRB03yANYACVe0ySlLueAPB3gv7ap8LA1p0ckcv978fGiw2/vz3hZj3aItECXq0l yb9clhyiTsvKrukWOFXJGlqvh4ePa4mxiy5ARF8hV8j4nDnP+tgcSeW/v98JxwWte7Zs yZsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763099; x=1789367899; 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=mf9E5O+vpQ3XA+Jie+/p9nC3sGIPSjge6K4hjAZVK9U=; b=L8VFf65IV00zQd/TJoTxdPoflm9viWgwIUBwvzConDMO+x+g/DAnMD9C7k5QRuCA5y vSjETrXMpB3H5ILhUJZPt3aWWNoaEDGNzGNyLN1XRRsxsDHAWSi3M4g1mvov2Yuq7cB5 Cm8QX+BXb9e/8cAhfDOipaaVtydme9dEhddQ83pjDW6cU/FQackrQiiBQYUlCpRFvj2q YEDXYgpMnfAJp9vZJM7Huw0jlqohKcxIk+lNePY84n5aOP4oZ9N01vZufkZHRTFRGvOX ka1YPF86hCUNO/H4W3CnXzWV9xobf3mrG0gAXcOf51K/yQOv3HdB/DNPwbY/NgTPf9Ys dHaQ== X-Gm-Message-State: AFuF++moWAD3JZ3y6QYlresdoxmbIzV6m4C8zWVRy8qEBlMlurbPDuVv oT5h0MsUKU0LTQlOcHBXM043PzDGpsahGMXzN06XKP3/upfweN0iRUdDXxHUuNVjj62hug== X-Gm-Gg: AYBFou1IHjOTCvIdibtk6ul532MaHpLCtVqiyfMvy5cYRERQB3k8E9MhAiUDsB/+gLF nWjyZtD7jKUR9VvQ2M7X5kxbgxIk5FSIq0ZSjQGQzVVHkW6eiCSnnE2lNo5W1RK0ecCqazfIxOC ww9h3qc2sQDzkxj1/Zo+2Iy9zURJuP6fWs/zoF1n6DWXfLGW3w/9CgRIBZh/6io4kfbcChuIec4 tzBFaq6L80fLP2mEgTctX0LpbI1cx/qmWdUJ6LFB1rIIX4idQ8OF4c86/o4QmgMsfx+icFIfEyO IMqEaRHatIE46ek8wYx1xOi8VOXHouH8cYc7tC40XLEbiU/5edz6Wddfx1KimG4FLUqth7SigzR dUKY5LJN6u6x1ZZEzrBtK3A4tGOekkFPYC5OCMW6u8+ggb9TcxUMFITAH1srKhhCHWPZjeaLLsE D262t4WbRmAx0Wn31vLsAS3EsnrsPgMGz/xnV+syKHOSs2l+kjp8gppQb/hcyPbXpaFWPWCLP04 QihJ5ZFJbSAXvgc X-Received: by 2002:a17:903:3c24:b0:2db:479a:5127 with SMTP id d9443c01a7336-2db479a55c8mr89297985ad.19.1788763099063; Sun, 06 Sep 2026 23:38:19 -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 V15 09/14] virtio-balloon: Update tracking iothread users with holder Date: Mon, 7 Sep 2026 14:37:20 +0800 Message-ID: <20260907063725.626685-10-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x631.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763180844158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_ref_and_get/unref_and_put_aio_context. Signed-off-by: Zhang Chen --- hw/virtio/virtio-balloon.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 4c5f486ba2..7c9c8d2a41 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -892,14 +892,20 @@ static void virtio_balloon_device_realize(DeviceState= *dev, Error **errp) s->svq =3D virtio_add_queue(vdev, 128, virtio_balloon_receive_stats); =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_FREE_PAGE_HI= NT)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + s->free_page_vq =3D virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE, virtio_balloon_handle_free_page= _vq); precopy_add_notifier(&s->free_page_hint_notify); =20 - object_ref(OBJECT(s->iothread)); - s->free_page_bh =3D aio_bh_new_guarded(iothread_get_aio_context(s-= >iothread), - virtio_ballloon_get_free_page= _hints, s, - &dev->mem_reentrancy_guard); + s->free_page_bh =3D aio_bh_new_guarded( + iothread_ref_and_get_aio_context(s->iothread, &io_ho= lder), + virtio_ballloon_get_free_page_hints, s, + &dev->mem_reentrancy_guard); } =20 if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_REPORTING)) { @@ -919,9 +925,15 @@ static void virtio_balloon_device_unrealize(DeviceStat= e *dev) =20 qemu_unregister_resettable(OBJECT(dev)); if (s->free_page_bh) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + qemu_bh_delete(s->free_page_bh); - object_unref(OBJECT(s->iothread)); virtio_balloon_free_page_stop(s); + iothread_unref_and_put_aio_context(s->iothread, &io_holder); precopy_remove_notifier(&s->free_page_hint_notify); } balloon_stats_destroy_timer(s); --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763200; cv=none; d=zohomail.com; s=zohoarc; b=YRmlGEHbwQlu0zxmXknyWcwQ4cJerf5RKOekMsyzRPn8Nt1eDikr33ALJxDp7PeiKY6NF0We8y9YmhqOxxjoVwbX2DOxTdLPPsSHIxnIZmPvI7bCPgW47p938ITFjvcuRYAUvi6VYEJUi8QvyPKd8+JEBc6CxH6UN94g+jrISso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763200; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zNkftpkxFVpDoZUxzARQ6dpOC1MsUJSxg+vsslS00BI=; b=InNktQzRS1iYNzVAr56YvoaWT+zIAs0IAASN7muLW3WdvEIjOacbnNaF8GB0XDWGk3XNX2AqCt1tUyg8R3aGDhXX+ERQLSvSyG6vgLlgnH7B55LKUH89rwYQgoki3g6XJftowbdQKHVLgQ8lj1vb0JFdAvbYarORyoWSowNsJ+8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763200947329.77243016520595; Sun, 6 Sep 2026 23:40:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3Szs-0005yI-36; Mon, 07 Sep 2026 02:38:28 -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 1x3Szr-0005y2-8l for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:27 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3Szp-00069w-J6 for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:26 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-2d9520b9155so27595665ad.3 for ; Sun, 06 Sep 2026 23:38:25 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.38.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:38:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763104; x=1789367904; 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=zNkftpkxFVpDoZUxzARQ6dpOC1MsUJSxg+vsslS00BI=; b=kBdAbJr3gygehGa+LkqYjU8LNjsoReEHIr5HW4kQrVVoCRze4xF3TV7uib+v/TuCGw Ph0WdCf91B6SRkG+fzEoAAdIu498C1dgBrINMsTmWj4ARcT6/iodnxxTfVfpzk3dX3x2 Z9zbvVEjmuhNWuMiFyKkMA77NH4+B6Mc2KJdrQrK3xy752Xav4JlBib90XzgxQq4FC15 enRpXH0WJb2Fp26zUWNnMRpbaGc0/6EiYsscRHo8NkEXvg/9DuBCkagVgq51ogWeMcaE tJ9IGn4AJEydHCr1PC0E/IB98SLm94YEQkcUZjra4MiJBLP+aMuhtNUaCOe5oH8V6xpk ruEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763104; x=1789367904; 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=zNkftpkxFVpDoZUxzARQ6dpOC1MsUJSxg+vsslS00BI=; b=rkgu5isVyCeDLbcZPbV8hR2LtXlcOEK9zpO3fpfIwui6jnolF+vhzeVYhJpPczablR Kh83+quQ5lWt69/5QnaeRvGVdna1P32vO63e35oitVmlQGxWf8k/Gv8cS/WUn0BqplQX 6TcUj93bJX8INjR+sDHlObjQzWdANub3t3qndyCS/ERluQwxFUE0nfwOrXf+eD17KxoR CJyXPf5OJIIrLQeWghbWrsWjKOlh4C8C3N9vYUp8TwykbY6LufXexQcDMcmIfa8cbg3R oTPhZfd3oesjG25gwJf86eeBHyjsLJJK0fyAKOE9jPUEzj+aJhcJqY9lEalsRdQngP8D Jaqw== X-Gm-Message-State: AFuF++n6F2mTurWkQ7QSyUT8nbfN8bHIGZx/WWnXS5gubci42loJqbWq kjELXWGjH+aRW0uOH4nLP+hfS0cevdQqOXpBMt3rzN33Hsl9xv54/LO7EC/CXObtOUvq5w== X-Gm-Gg: AYBFou3r0zpWi2kgPgQEchAYkH5RWK4AlS3NM/lAtjMRr0Qe43v34KWNwE2xhsB9iW6 i2Dz6RVu6Zgf+Xg0QxNo2HVWCeb1+2Q+iapVjMyOb9tI+SJOKqxSOe1YIaG4EC11hf85V8u+DbW 3OwReUyaZgnCeiroS4lLFh4oCwiEtPU19OM1ZKks8KOg+Rzrvtoxfnhyfp5WN2n2IClLvbs+8XP 6RMQCiBQLW9BQQJp1V6SG4Iosd4s/WgShKa5FSeuNokEaq5jb3w5nmk+2USJZ6tDW3IERxaGxkA KK6/zrUYYlofGpZNz+7ppEhg323gI7iy0qjjzF6euIFPdGxPcuuQwnlkukVzk8rfYTyeHkjbN1H Iy+dh9G9DRY5NHoy/IJWdQXkk377AGve4Vji3TUC67fw4U8RcWuZSfBpNOrlT4dHyK/Sxo7bNPF T/1HJte00voTLNW90OEG2dFj7sGnAYolc54VC4p1y1AbsKSmrQAbG2IBT1eIUnylzZG96tIs5kr UT3da9bE2Ylh+83 X-Received: by 2002:a17:903:3803:b0:2d7:7cb:a44a with SMTP id d9443c01a7336-2db127bf3damr337859395ad.11.1788763104149; Sun, 06 Sep 2026 23:38:24 -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 V15 10/14] vfio-user/proxy: Update tracking iothread users with holder name Date: Mon, 7 Sep 2026 14:37:21 +0800 Message-ID: <20260907063725.626685-11-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x629.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763203114154100 Content-Type: text/plain; charset="utf-8" Add object_ref/unref calls with iothread_ref_and_get/unref_and_put_aio_context. Signed-off-by: Zhang Chen --- hw/vfio-user/proxy.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/vfio-user/proxy.c b/hw/vfio-user/proxy.c index 197aee07bf..e642fb0ad3 100644 --- a/hw/vfio-user/proxy.c +++ b/hw/vfio-user/proxy.c @@ -898,6 +898,7 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) QIOChannelSocket *sioc; QIOChannel *ioc; char *sockname; + g_autofree char *path =3D NULL; =20 if (addr->type !=3D SOCKET_ADDRESS_TYPE_UNIX) { error_setg(errp, "vfio_user_connect - bad address family"); @@ -917,6 +918,11 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *ad= dr, Error **errp) proxy =3D g_malloc0(sizeof(VFIOUserProxy)); proxy->sockname =3D g_strdup_printf("unix:%s", sockname); proxy->ioc =3D ioc; + path =3D object_get_canonical_path(OBJECT(proxy->ioc)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; =20 /* init defaults */ proxy->max_xfer_size =3D VFIO_USER_DEF_MAX_XFER; @@ -936,7 +942,8 @@ VFIOUserProxy *vfio_user_connect_dev(SocketAddress *add= r, Error **errp) vfio_user_iothread =3D iothread_create("vfio-user", errp); } =20 - proxy->ctx =3D iothread_get_aio_context(vfio_user_iothread); + proxy->ctx =3D iothread_ref_and_get_aio_context(vfio_user_iothread, + &io_holder); proxy->req_bh =3D qemu_bh_new(vfio_user_request, proxy); =20 QTAILQ_INIT(&proxy->outgoing); @@ -967,6 +974,11 @@ void vfio_user_set_handler(VFIODevice *vbasedev, void vfio_user_disconnect(VFIOUserProxy *proxy) { VFIOUserMsg *r1, *r2; + g_autofree char *path =3D object_get_canonical_path(OBJECT(proxy->ioc)= ); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; =20 qemu_mutex_lock(&proxy->lock); =20 @@ -1021,6 +1033,8 @@ void vfio_user_disconnect(VFIOUserProxy *proxy) qemu_cond_destroy(&proxy->close_cv); qemu_mutex_destroy(&proxy->lock); =20 + iothread_unref_and_put_aio_context(vfio_user_iothread, &io_holder); + QLIST_REMOVE(proxy, next); if (QLIST_EMPTY(&vfio_user_sockets)) { iothread_destroy(vfio_user_iothread); --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763186; cv=none; d=zohomail.com; s=zohoarc; b=hcO9BQScDo1jZzVizwS/Eqzbu2/b19XsWL61gqq7x/zYcJAeLkgY0gQHjbGUP6+oVMXIL6CP74bz2YnB8lq8lV0p+k+tlNZKWZ6FKMcRyXp9+Ktmg65htxpLARpwkY1lWwaFi3vCGYcFheJ4muj+8dEsZSLrEza4leugmknKSvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763186; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=F8RfjQjVOX1tJDdARKFAxVYWhrl5wDLHiadJICm/sXU=; b=ETqWlQ7u4c0YLLxWe84JWuUthWNdHZhD5dzoX1y5t9BatZJLXTWlIEZqWPHTbGUDoFf1IrXf29lWTH0/PcUmMfmFSySWF1lX3GWh83AHrbBhm2DzyBOJdKdIh3WtA78C+viNF7lGl6z3GW189dXP+8a58dMVYxganvPzQ2maePw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763186518137.6166157303228; Sun, 6 Sep 2026 23:39:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3Szx-00060I-Hu; Mon, 07 Sep 2026 02:38:33 -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 1x3Szv-0005zR-Gx for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:31 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3Szu-0006AC-3C for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:31 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-2d715f4a587so45944335ad.2 for ; Sun, 06 Sep 2026 23:38:29 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763109; x=1789367909; 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=F8RfjQjVOX1tJDdARKFAxVYWhrl5wDLHiadJICm/sXU=; b=WUtReERJa/M0MP4mkeq0uJti6Dmr67bF1XkcZ5XUCRnDopEsSGD5Iru8hQmAxeNt9v PnNBcdoLKRiN8P2z/LVunz49sK7WZTR1/MHlhG/svXaj7KYWctS2R17kAfCha9CInrMp 5jdLL082XnizM3b8fOzwr7C8mQdlAgiX4Ly7w/e8T/MvCgbk/WAWclEx2/0yGYjt9Q9v ePpZaGZaQkb0iuOYOZS61PVJ/w256b1rWrjCU3jxziocuXUX8KfmPtptLCxoVOQ4rrUq 9k5knH/hGDq8uXa+EtiAB7ARfPWscwRiwSQJQvv8x3xuQ9rrBnAril0iTP5l5EE70752 6eLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763109; x=1789367909; 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=F8RfjQjVOX1tJDdARKFAxVYWhrl5wDLHiadJICm/sXU=; b=SJdelPbHs/YZgeNdIaa7OqUGQm7EWwCc6V3BWXfpqesekUrYR1NoPZPRXWG2LMmIdA 18i7pqmC/KhLSYgpMlrrYJBO2fRLqn3LA0BLgL21e/pgBc2SXGuNNCSdmSm5aWrlScTF qpcJTozsV2UdZnKy/+0QfUMsGrJvwEvy2j3F7/296+yOmXjdfovOF6kwFdqVTwpVSAg7 SHhGLfL4eLVTXdnUoVs7ay1jshwVFJKO7HIDSL01+eMUGLRHsCRJQyvc6ipgrEDxSgNx iw4mJV2A46MdUvB6o8idd0k9glLiCfI8xKjy15rdPZkuG0BcLkX38v8CDz7Os0b5VmCN B0Pw== X-Gm-Message-State: AFuF++niZO4ncWki7HskcaWpGhcLGXFxeUTqrYX1sYyFNojHwmxvdmrC uk1zdhzHV1l5zTx7axjzSZQF0AUkFVvbWM5yJkW4L4rsba4n9b0n38rTmyK2WYw82Vx2Eg== X-Gm-Gg: AYBFou1JS4fx0yEKLXv/UHOzGkFVqBMDMc2OtWSepD1gcd8N/i54C0U7hqAlnGREJWY p66aJa84Vt4vxhmfa3hT/hM39UyecZbqVYNGmvoXNgP19R+hV/ZzaVcsF6aneM7l2zzs+qm566t 136tLEkniVapsI03GwvOocOJAD3MqHqSPN9mLzWLLhqDLHOv0k1W5oF2xSu9LuWpzkDID7NMNlX Bnq5wDugWX0ejCjsaRWXL60nKxz+g+b+0yRKtGrw2WzLEENTHjoQyuBB4fC3xo6Vyoo+nIJtFLs 972gWJY8qhm5PAL5vjYEAcQig/M5FQMTAW5cZ3LJ9+a0GGOOTRmEcHrX27/pms2jYLHflpq/nr+ baAIujO6pgcn9SUHfPojCPnesf1AgwgDYQZHhK0CKGij6JdrFQ2DgbyBBdPBKjQvyJ7XdHM+N6T itaa6lfd7DmJEQnNe7L2cAEXX4lN9owCln6TbVMS+PbrDYd6vhuhtkdp5G79IUx2xPOZWOSOAgt rOt7Wqyoyin4uBD X-Received: by 2002:a17:903:198e:b0:2d9:383a:30f1 with SMTP id d9443c01a7336-2db125ce07cmr357668705ad.4.1788763108763; Sun, 06 Sep 2026 23:38:28 -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 V15 11/14] xen-block: Update tracking iothread users with holder name Date: Mon, 7 Sep 2026 14:37:22 +0800 Message-ID: <20260907063725.626685-12-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763188771158500 Content-Type: text/plain; charset="utf-8" Replace raw object_ref/unref calls with iothread_ref_and_get/unref_and_put_aio_context. Signed-off-by: Zhang Chen --- hw/block/dataplane/xen-block.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 48c2e315f3..9dfe06e1be 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -621,9 +621,15 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevic= e *xendev, QLIST_INIT(&dataplane->freelist); =20 if (iothread) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(xendev)= ); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + dataplane->iothread =3D iothread; - object_ref(OBJECT(dataplane->iothread)); - dataplane->ctx =3D iothread_get_aio_context(dataplane->iothread); + dataplane->ctx =3D iothread_ref_and_get_aio_context(dataplane->iot= hread, + &io_holder); } else { dataplane->ctx =3D qemu_get_aio_context(); } @@ -652,7 +658,14 @@ void xen_block_dataplane_destroy(XenBlockDataPlane *da= taplane) =20 qemu_bh_delete(dataplane->bh); if (dataplane->iothread) { - object_unref(OBJECT(dataplane->iothread)); + g_autofree char *path =3D object_get_canonical_path( + OBJECT(dataplane->xendev)); + const IOThreadHolder io_holder =3D { + .type =3D IO_THREAD_HOLDER_KIND_QOM_OBJECT, + .u.qom_object.qom_path =3D path, + }; + + iothread_unref_and_put_aio_context(dataplane->iothread, &io_holder= ); } =20 g_free(dataplane); --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763175; cv=none; d=zohomail.com; s=zohoarc; b=mDFrANDqXfZv3TKVzK03YNI2ehUB+fdtV62kCNDdVLHD46HW907+HITO9Yi6W9ZWrl2K3dcWucIJX7H3/t5v4b4peIA4rzFFpk2WWUVeg9asndIyFQhth00ywfDOJ1jXt9fU+XifW5ci+QMPXE/EPHzSDV51CC12ZIeGVHaj5Ck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763175; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=l5YVe05pjG97AGrI1ym/t5dZv++HeTZWtnHCxE2pueI=; b=bx8wMjWfOpJaCqdl4JTb2JEc/p5ob3yY19/1vZv66JQNIWo/DJ107YJI53nCEvdXNwSoPGwwlxqMgZsb/7nUyDwV2gKTdiV8Vd9euf4KWpZM4QsMqFAnVUJlAM+/nu3Z2q5ap9OusqTZJozjjIOif1/6lVr/Ya/1AyMnsqbRCKg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763175039955.6439618551047; Sun, 6 Sep 2026 23:39:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3T01-00061b-Dk; Mon, 07 Sep 2026 02:38:37 -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 1x3Szz-000610-L5 for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:35 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3Szy-0006AQ-1h for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:35 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-2caced6038eso30594985ad.0 for ; Sun, 06 Sep 2026 23:38:33 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.38.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:38:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763113; x=1789367913; 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=l5YVe05pjG97AGrI1ym/t5dZv++HeTZWtnHCxE2pueI=; b=KUGE5K0HLAK11lqlQagQltcP0s9lxyGJLsQy+uD4xpdOhaW3D4MvNwH7MPybARgluM 0B9lsSOByDBzacaN6re3DbckJy5WBvht17KRn62oyn9shY1EbxScq8pw+Y93goUfq1Fs fYq3YXBe/OXScxKhfMZ+xuhIEEVGf5TL7aQj1nHnJPlBUHhKfac0X/Hwsj6mvzKGml0i PVgHHU//M2kMfyJSPHjIlh15+ETzMGte1lL8GLGMMqSCcT8v+ZAtfAL5mtzv6B/up0W8 iMT2Hnz6etxvxmHqBBDn6je8tA9kgRwQwIjn0281LwY045d90SoGxEBsvHIjh9Wlsqy1 QFMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763113; x=1789367913; 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=l5YVe05pjG97AGrI1ym/t5dZv++HeTZWtnHCxE2pueI=; b=DM9BKothFBnKu6jSLE5iV6gXhspFb9iIJ7xqCtQZLR9te1XfrjtOjcXGcCFKWhlwAp yHaso784Vg7dU5UEvQWTZ4p5bmNHGzsNBBtljxkjx3zcC8dEk1lELbu7i8SFigPQq3rm ArAdjCh20x4eUcpMEnrJvXYOMYPJZKRDmJ8PfubOaSuK4oig2OhT1kTxpHpyVrT4cJ+C Bizh4cbYGONYEz30I66ERZN82rnLB//RqCYuBjypxxTLmrVTpBpyeArXxTuo34ZoMi0i SnjpX5SxELvlEqhvOPA8DFnVwu5GM2Pp8G8nJr7cagFsMnllGbXP9p6hzx5v3+acmxvs q2PA== X-Gm-Message-State: AFuF++mPaR/HdSQVllIfu4QuPqZevtEZqEuOKXY3zouIaoAPcvvChPzr JivA+BIzpJzUP53SJ9YZVLL8zF03MHWC5aTVM6Jj7rl9YdxDSkA4D/goqc7tjVC0jtxpag== X-Gm-Gg: AYBFou3L/VMXLvYrc2/mJSGrGR8KRhOE509SXWxSdblsfqvQeryqFPSQ5d5USv5ktw7 Gm+hSyVWYwSAe4qljmcrWkpPUYBhtg3suuFfBK+7ZQA+iHW1oaNBgTjtqShEL7zIEfbeI+Y+NYd J9eIE9HFxk55AeJxMvHHy5EuGC9NDWAF5W42j9+SS9zYSNyWAUlIDd/ihx9rFXib0rGZAsWVBB3 DxaGydKPUCn1f3kkjtQEQf5h8IROKj7BHNNyzUwW8UZujpFl+Zspr7UTxj09UzVhw/KORM7QgLV 5StEIuPijhS6ZS2bJfRR7CZ5wvQpXCMz/VA0nlR/1ENsVmKRqgWhoptNfHZ78qWhd5Roi1cV7up XTsH7fK8taFjKgccAH7ogwob0we8QtuJtIQ3YHRvnfMGPolZT8hg7hb666iudqHxD17TGvFP78p ++LS5OzoTt65FH5VaTTmd0cxTlqMDfA1KmEIcnoCTOE5xch6EkAGxZs/Hpkl59XSQLv+btO5cRW p2VUhlsU8M6J7cPfVn/CK80viQ= X-Received: by 2002:a17:902:da85:b0:2bd:2c3a:2a36 with SMTP id d9443c01a7336-2dafad14a8fmr247945635ad.0.1788763112636; Sun, 06 Sep 2026 23:38: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 V15 12/14] monitor/hmp: display IOThread holders Date: Mon, 7 Sep 2026 14:37:23 +0800 Message-ID: <20260907063725.626685-13-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x633.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763176741158500 Content-Type: text/plain; charset="utf-8" Display holder information in info iothreads to aid manual debugging. Reviewed-by: Markus Armbruster Signed-off-by: Zhang Chen --- monitor/hmp-cmds.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 91701ddf33..d7dd24d951 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -246,11 +246,31 @@ void hmp_info_iothreads(MonitorHMP *hmp, const QDict = *qdict) IOThreadInfoList *info_list =3D qmp_query_iothreads(NULL); IOThreadInfoList *info; IOThreadInfo *value; + IOThreadHolderList *h; =20 for (info =3D info_list; info; info =3D info->next) { value =3D info->value; monitor_hmp_printf(hmp, "%s:\n", value->id); monitor_hmp_printf(hmp, " thread_id=3D%" PRId64 "\n", value->thre= ad_id); + monitor_hmp_printf(hmp, " holders=3D"); + for (h =3D value->holders; h; h =3D h->next) { + IOThreadHolder *holder =3D h->value; + + switch (holder->type) { + case IO_THREAD_HOLDER_KIND_BLOCK_EXPORT: + monitor_hmp_printf(hmp, "[block-export: %s]", + holder->u.block_export.export_id); + break; + case IO_THREAD_HOLDER_KIND_QOM_OBJECT: + monitor_hmp_printf(hmp, "[qom-path: %s]", + holder->u.qom_object.qom_path); + break; + default: + g_assert_not_reached(); + } + } + monitor_hmp_printf(hmp, "\n"); + monitor_hmp_printf(hmp, " poll-max-ns=3D%" PRId64 "\n", value->po= ll_max_ns); monitor_hmp_printf(hmp, " poll-grow=3D%" PRId64 "\n", value->poll= _grow); monitor_hmp_printf(hmp, " poll-shrink=3D%" PRId64 "\n", value->po= ll_shrink); --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763174; cv=none; d=zohomail.com; s=zohoarc; b=cdqxIxZv1EvH8iSY3RVEodsGiSac2uBRzh63Cxm7V3HPMGfGRMqqmuK4pMZFawcRdyFnMT9FDr8+Zcc4onG7ulpsCMvWBt0K1UxV4GQuQ24c6kaG6TLFpyuOlQJ6OtB/JgK82VJ7OAqnukiyy09HHoGNlZxl+JSsJbjxmXNFUEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763174; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=80gGLHUNp9a2qS0zepvCgbYVB3aORrvxr/A17drJBkg=; b=OdebD/eLdQ1H0P3pV6jM7Fcd10SPEP71qLuSxYdCTK4n6JahrBOSrs4mcJD4vl5HZUcArWRjOzOIegHDseOLftpGKaZ8nHeio6jwTLCKfYi8eDVyHpp3o6B/UVLL5znhc4rWWtdgT3UBWmv3OU0UZ5IG18V9I7sajt/xnPzwXAI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763174610494.61795223668173; Sun, 6 Sep 2026 23:39:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3T05-00061m-RU; Mon, 07 Sep 2026 02:38:41 -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 1x3T04-00061e-5L for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:40 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3T02-0006Ag-H6 for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:39 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2d942c7cc2fso25000115ad.3 for ; Sun, 06 Sep 2026 23:38:37 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763117; x=1789367917; 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=80gGLHUNp9a2qS0zepvCgbYVB3aORrvxr/A17drJBkg=; b=gUBEFDji1yI/HvOx/vIsKOPcRuoWRsf0uj7mH/q9vtq4BlOlc5CCbZMPTPtbJeWxvq GD0ckgvodgAU/xm2mpF6Zlah5Dzs5i/NKK8V/H237th588O7oHbSPiX3H4IpTGJMS7ur i32AGxOnlhdrJjFOeUgWyF+eOCfHg89tTxbzIbUCbGRngieLLL2xI+OFrD34IGQbATmi x4J590cNfdLKk/8dWRN9p8N/D1j+YgT4iF9kPOKzNKI6LYcCB97Ryheo89ksAu3dB3bg iloqRqokYLTCICGGBGHGrpNfMnYpWTWTV8O9/+2sR1G5Mij1gQBOsey/IDi4bHjpkNAD tDng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763117; x=1789367917; 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=80gGLHUNp9a2qS0zepvCgbYVB3aORrvxr/A17drJBkg=; b=bBZMw3SSXezrqjTn6fG266U0uMtemmOyhAV61NRfkVjn54JM1NTlqcDX19Z0y9Li/j k2Yo2PIC4Vgyb5Eo8yGHWLoBhVhCfjl8uXqmvIxcZfOSxw4zhVQEtWWCImKcJnCH+gqn rxyYLarKs7FxtbwUnP7H4slolSAE2hc+9HnTeq5pU19ZATLKajuYhbHn3EgZq/pf2Czz R9rehDr9UabrGHr2vXaRsvmvbW4fZrWw49ix/IZtu+MwmAZyAwEpMf4dtOdXDwNH09ZP 8ePAskFg6VszTGTP65bptZVdlwIRr1cVsX/3qKeWKwoYnab3wDqRQ0/E6iB2L0VrwOvO fN4w== X-Gm-Message-State: AFuF++kOSbCu87Bf1h4Bj2B3ykwhGdB9xuKvwe9tIMQmF2vzkuH9+TQk RdrEzWnltea5nKcAVlNZ+22QMpbLt6Rt7NCjcM/Osz0kqXpfwphYqsttMWvMAvhcXKCAcQ== X-Gm-Gg: AYBFou2RnTSMnfQvB1EL6SvX5dr6PVn6V4kYZr+186CieIUaMEQ1WzzcrYjrg+GOR/g j0awogMOTfO/yQqk5CLHpvcJi7+RrZvEPITGgCW9jNJALm1NtJFDP7x0tH2CuXGHVhGVTl19Y7h FVMG80OKPlaVrT+qABtHo5j/5JDT5tW94n3jlz9h8aKawmQJX+MoGMXO4tV9tkZ7hLBMn/CXLJy 3Ar8c+qWmLPLxIriaRSDIH4kjUKNfjX85pnRMVgB27/K1WfflSarOAvIBkPbOR/iTsOpkzZwBgq SSYcXqGLXkLiNVSuXiRkvqpBTJeCB4tSj2NhIvdMdfLqBZd45IDHgRvHz8YN8voGcM9JzOP37u+ Vcq6YgX2bRxOJc37a1VwilM3C7lYYNBki9uuGsqT35G9ugGSjvP88CP9I4apEIr4HhZRQ7FXtJw yYUlwClnP3xNjuenlP1WOWpM0DJrdkPmoL5JEQRCgqYL+CgAM+sBAbJCAS7idIkjmXKSJyTWBFW q9V2JXf6ebIYX5G X-Received: by 2002:a17:902:ed8b:b0:2c8:2808:3ec9 with SMTP id d9443c01a7336-2db126d8fc2mr198500665ad.12.1788763116472; Sun, 06 Sep 2026 23:38:36 -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 V15 13/14] iothread: make legacy AioContext getter explicitly unsafe Date: Mon, 7 Sep 2026 14:37:24 +0800 Message-ID: <20260907063725.626685-14-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x630.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763176756154100 Content-Type: text/plain; charset="utf-8" Now that holder-aware callers have been converted, rename iothread_get_aio_context() to iothread_unsafe_get_aio_context() and update qmp_x_blockdev_set_iothread(). This avoids adding a duplicate accessor only to remove the old one later. The block graph retains only the AioContext, while detachment happens outside qmp_x_blockdev_set_iothread(), so this call site cannot provide a matching holder lifecycle. The new name makes its existing lifetime assumption explicit. New code should use iothread_ref_and_get_aio_context(). Reviewed-by: Stefan Hajnoczi Signed-off-by: Zhang Chen --- blockdev.c | 7 ++++++- include/system/iothread.h | 11 ++++++++++- iothread.c | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 6e86c6262f..97d161079a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3683,7 +3683,12 @@ void qmp_x_blockdev_set_iothread(const char *node_na= me, StrOrNull *iothread, goto out; } =20 - new_context =3D iothread_get_aio_context(obj); + /* + * The block graph retains only the AioContext, not the IOThread. + * Context detachment happens outside this command, so there is no + * point here where a matching IOThread holder can be released. + */ + new_context =3D iothread_unsafe_get_aio_context(obj); } else { new_context =3D qemu_get_aio_context(); } diff --git a/include/system/iothread.h b/include/system/iothread.h index f6c5f95dd9..9850cdb3dc 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -66,7 +66,16 @@ DECLARE_INSTANCE_CHECKER(IOThread, IOTHREAD, =20 char *iothread_get_id(IOThread *iothread); IOThread *iothread_by_id(const char *id); -AioContext *iothread_get_aio_context(IOThread *iothread); + +/* + * Return @iothread's AioContext without registering a holder or taking a + * reference on @iothread. The caller must ensure that the IOThread remai= ns + * alive for as long as the returned AioContext is used. + * + * This API exists for legacy callers without a clear ref/unref lifecycle.= Do + * not use it in new code; use iothread_ref_and_get_aio_context() instead. + */ +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread); =20 /* * Register @holder and return @iothread's AioContext. The holder is copi= ed, diff --git a/iothread.c b/iothread.c index 58dace351c..ae9290c733 100644 --- a/iothread.c +++ b/iothread.c @@ -422,7 +422,7 @@ char *iothread_get_id(IOThread *iothread) return g_strdup(object_get_canonical_path_component(OBJECT(iothread))); } =20 -AioContext *iothread_get_aio_context(IOThread *iothread) +AioContext *iothread_unsafe_get_aio_context(IOThread *iothread) { return iothread->ctx; } --=20 2.43.0 From nobody Sat Sep 26 20:00:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1788763173; cv=none; d=zohomail.com; s=zohoarc; b=HCUWTcwls0xI81U6DFxEcRfo2zTmaQOs50PMvWnmeJhk6Lf//g4yq4V1M7EYtAYfpVbMOKSEVNbb1BkFUkJRcVaKtO2ts46qlPwS+yuQi0OeYijvEkWC6N3sqaD79tWrsiHgQtHy+r5z7+MDxf6cT9BEz4iGS1OTzoAiE1cYINM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788763173; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8HA0URDqzo40kYUGgC9BRkSZVXz0Ja8B7EI4ZLWVnOM=; b=K7mhRaszMKKPrSkzlE83B6pHNnTVT24p2dynB0VGc2C35AERVN+qMJw4Ltej2M2OUKdLeOOtomNjq09GomV/GjRmPrPW7SMeEeMg4+5v72BIYpnMnp7H9kWuc0CZp03PJ58btP7pZPDZ3EPNgPHD3xtEO8+O56QPLr4Sz1ghm8c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788763173594425.80537708082295; Sun, 6 Sep 2026 23:39:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3T08-00062H-V9; Mon, 07 Sep 2026 02:38:44 -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 1x3T07-000628-Jw for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:43 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x3T05-0006Au-GH for qemu-devel@nongnu.org; Mon, 07 Sep 2026 02:38:43 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2d5335cf904so31040875ad.2 for ; Sun, 06 Sep 2026 23:38:41 -0700 (PDT) Received: from hades-NUC8i7HVK.taila0cd24.ts.net ([222.72.128.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db1499f06fsm38502555ad.54.2026.09.06.23.38.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2026 23:38:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788763120; x=1789367920; 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=8HA0URDqzo40kYUGgC9BRkSZVXz0Ja8B7EI4ZLWVnOM=; b=KtCGY+8EEBZGQnJMgehz6bdvi5cXe5HMLymoMhDEGNxTiAvNPlXWInk8KddUXWRXav 7VyvA/NUZFrNJWxk4LcZE4Ry1xg6KsV0i4Y9yld8WIYNb3YDIsQalCU3easBSVJWSC8f LPRIoCWUtkeU0MFRcaX1xyG3BqWTcdDebxGiyO4imO3qf/ObkqgjrpIIqZACVOkMo13E bvdG5eUYzmALAtKu/KM5fJpzoJNOIf1qpdV+d/fg3zDZsMick0w8e/NE7YQZC42m7Dpq ey5ClgwBXzMXSfG4pwiA7Dkrk0qjvyyt1lytUI3w6qmlUDV8VbeGib5ZfqEcUYGLG0I+ EswQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788763120; x=1789367920; 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=8HA0URDqzo40kYUGgC9BRkSZVXz0Ja8B7EI4ZLWVnOM=; b=a9zEbdi0JMy2AWgs8A7tAzZbZfCvb2RDQzk7M9O9Y9fD3JNThX/IQ4UTdDNR15vz7Y 89ci9oPE4vFJ87zWhbaakOQobyza7OkVBU0/IE2N5fEsoy97yclCfCDr6yG/ye16Qw9Q REhYlTE3e27Um4+gzvR+VQK5C15uYO+LXx0fDR8dfJ69JKmEW5KI7h4jIwnrSmPeaKt5 oljt9uV0RV73b+UIq0c1faWv1vzY3fyV/z/kpidYmo9ciE75kUNOxZEJRVEuDtZhXpG4 0f4Yk3r9zrB2drpf349rX9HDeEpHJKg03dvQMT7ZXOwKkxczyIE6Pif3XPJNMDEri3Wb qdJw== X-Gm-Message-State: AFuF++lhpKmDjZAsPru4o0kMB22nzfQwzn3oemOc0xfKwdaSwyWhDCDC FMJm31CqF6ZWwptwXkctvuZlrMF1QXqLmWMoAha1fHjpjxMrGYoDexP9xmGaOP+/CAEqkg== X-Gm-Gg: AYBFou1ztiopSmKqttppjtg810/GvGJfcudtAjNly4rfv4fYT6xeCI4yaEg2KjuWHYH rEMPw93qLs7tL0tqwqrgx6JJuqKv58G15/hrOaqq70Q0TH9Sj164IV44mf+ew35Gz4Li17+FjsK VI8a/K0FRk+bh7+fMSp9iTXnBgLaai3jTAE2RRzUXVFg1KX4ZIzbSydp0PPEeThlHrpCkerIzhX xdi6KxqdQFiwRwo2uCzixPFBQ26EjBMeWFcZjch6qYY3nKEjJG2Q/wtqCKVzlNDmsjV9z0kHEBP TIKY1CtZvdgep4Pc0k8cBaEJ/kEsXLsvN3dOUZ9ocJS02eZiXW2XAbhWp4n39+lfK4hCM2AtX1U HwNPNBZV3i/q/3bh2DuR3t9cAyJj3EPk7BJtPnxgfv4o8H5iTfsQ9/70FDj6mxhwVjmXEOmjrlW 2TBFaMmSo9kbKlYyhc0lgJj/sIJPhzopdkZ028/NThDL9+IRgs74LU5H5vp7X4UPF/rMGhPpQaG kzL33k6m+UuLAEZ X-Received: by 2002:a17:902:e80f:b0:2db:359e:799c with SMTP id d9443c01a7336-2db359e800bmr108967795ad.22.1788763120204; Sun, 06 Sep 2026 23:38:40 -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 V15 14/14] tests/unit/iothread: update AioContext ref/put helpers Date: Mon, 7 Sep 2026 14:37:25 +0800 Message-ID: <20260907063725.626685-15-zhangckid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260907063725.626685-1-zhangckid@gmail.com> References: <20260907063725.626685-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=zhangckid@gmail.com; helo=mail-pl1-x62e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1788763174775154100 Content-Type: text/plain; charset="utf-8" Update the unit-test IOThread stubs and callers to use iothread_ref_and_get_aio_context() together with the matching iothread_unref_and_put_aio_context(). Signed-off-by: Zhang Chen --- tests/unit/iothread.c | 18 ++++++++++++------ tests/unit/iothread.h | 7 ++++++- tests/unit/test-aio-multithread.c | 5 ++++- tests/unit/test-bdrv-drain.c | 18 +++++++++++++----- tests/unit/test-block-iothread.c | 21 ++++++++++++++------- 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/tests/unit/iothread.c b/tests/unit/iothread.c index a363bf8f70..790cd2dce7 100644 --- a/tests/unit/iothread.c +++ b/tests/unit/iothread.c @@ -30,12 +30,23 @@ struct IOThread { bool stopping; }; =20 +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + IOThreadHolder *holder) +{ + return iothread->ctx; +} + +void iothread_unref_and_put_aio_context(IOThread *iothread, + IOThreadHolder *holder) +{ +} + static void iothread_init_gcontext(IOThread *iothread) { GSource *source; =20 iothread->worker_context =3D g_main_context_new(); - source =3D aio_get_g_source(iothread_get_aio_context(iothread)); + source =3D aio_get_g_source(iothread->ctx); g_source_attach(source, iothread->worker_context); g_source_unref(source); iothread->main_loop =3D g_main_loop_new(iothread->worker_context, TRUE= ); @@ -113,8 +124,3 @@ IOThread *iothread_new(void) qemu_mutex_unlock(&iothread->init_done_lock); return iothread; } - -AioContext *iothread_get_aio_context(IOThread *iothread) -{ - return iothread->ctx; -} diff --git a/tests/unit/iothread.h b/tests/unit/iothread.h index eb4d0c77f8..9bdac074c0 100644 --- a/tests/unit/iothread.h +++ b/tests/unit/iothread.h @@ -17,9 +17,14 @@ #include "qemu/thread.h" =20 typedef struct IOThread IOThread; +typedef struct IOThreadHolder IOThreadHolder; + +AioContext *iothread_ref_and_get_aio_context(IOThread *iothread, + IOThreadHolder *holder); +void iothread_unref_and_put_aio_context(IOThread *iothread, + IOThreadHolder *holder); =20 IOThread *iothread_new(void); void iothread_join(IOThread *iothread); -AioContext *iothread_get_aio_context(IOThread *iothread); =20 #endif diff --git a/tests/unit/test-aio-multithread.c b/tests/unit/test-aio-multit= hread.c index 9179cdc6a3..66ba5a466b 100644 --- a/tests/unit/test-aio-multithread.c +++ b/tests/unit/test-aio-multithread.c @@ -69,7 +69,7 @@ static void create_aio_contexts(void) =20 for (i =3D 0; i < NUM_CONTEXTS; i++) { threads[i] =3D iothread_new(); - ctx[i] =3D iothread_get_aio_context(threads[i]); + ctx[i] =3D iothread_ref_and_get_aio_context(threads[i], NULL); } =20 qemu_event_init(&done_event, false); @@ -87,6 +87,9 @@ static void join_aio_contexts(void) for (i =3D 0; i < NUM_CONTEXTS; i++) { aio_context_ref(ctx[i]); } + for (i =3D 0; i < NUM_CONTEXTS; i++) { + iothread_unref_and_put_aio_context(threads[i], NULL); + } for (i =3D 0; i < NUM_CONTEXTS; i++) { iothread_join(threads[i]); } diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 43b0ba8648..05c31ffca8 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -537,8 +537,8 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) =20 IOThread *a =3D iothread_new(); IOThread *b =3D iothread_new(); - AioContext *ctx_a =3D iothread_get_aio_context(a); - AioContext *ctx_b =3D iothread_get_aio_context(b); + AioContext *ctx_a =3D iothread_ref_and_get_aio_context(a, NULL); + AioContext *ctx_b =3D iothread_ref_and_get_aio_context(b, NULL); =20 QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); =20 @@ -612,6 +612,8 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) =20 bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(a, NULL); + iothread_unref_and_put_aio_context(b, NULL); =20 out: iothread_join(a); @@ -762,7 +764,7 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, AioContext *ctx; =20 iothread =3D iothread_new(); - ctx =3D iothread_get_aio_context(iothread); + ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); blk_set_aio_context(blk_src, ctx, &error_abort); } =20 @@ -892,6 +894,10 @@ static void test_blockjob_common_drain_node(enum drain= _type drain_type, bdrv_unref(src_overlay); bdrv_unref(target); =20 + if (use_iothread) { + iothread_unref_and_put_aio_context(iothread, NULL); + } + if (iothread) { iothread_join(iothread); } @@ -1398,8 +1404,8 @@ static void test_set_aio_context(void) BlockDriverState *bs; IOThread *a =3D iothread_new(); IOThread *b =3D iothread_new(); - AioContext *ctx_a =3D iothread_get_aio_context(a); - AioContext *ctx_b =3D iothread_get_aio_context(b); + AioContext *ctx_a =3D iothread_ref_and_get_aio_context(a, NULL); + AioContext *ctx_b =3D iothread_ref_and_get_aio_context(b, NULL); =20 bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, &error_abort); @@ -1410,6 +1416,8 @@ static void test_set_aio_context(void) bdrv_try_change_aio_context(bs, qemu_get_aio_context(), NULL, &error_a= bort); =20 bdrv_unref(bs); + iothread_unref_and_put_aio_context(a, NULL); + iothread_unref_and_put_aio_context(b, NULL); iothread_join(a); iothread_join(b); } diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 5273ff235a..fc9735d056 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -466,7 +466,7 @@ static void test_sync_op(const void *opaque) { const SyncOpTest *t =3D opaque; IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; BdrvChild *c; @@ -493,6 +493,7 @@ static void test_sync_op(const void *opaque) =20 bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 typedef struct TestBlockJob { @@ -549,7 +550,7 @@ BlockJobDriver test_job_driver =3D { static void test_attach_blockjob(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; TestBlockJob *tjob; @@ -595,6 +596,7 @@ static void test_attach_blockjob(void) =20 bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 /* @@ -612,7 +614,7 @@ static void test_attach_blockjob(void) static void test_propagate_basic(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx; BlockBackend *blk; BlockDriverState *bs_a, *bs_b, *bs_verify; @@ -658,6 +660,7 @@ static void test_propagate_basic(void) bdrv_unref(bs_b); bdrv_unref(bs_a); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 /* @@ -676,7 +679,7 @@ static void test_propagate_basic(void) static void test_propagate_diamond(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx; BlockBackend *blk; BlockDriverState *bs_a, *bs_b, *bs_c, *bs_verify; @@ -736,12 +739,13 @@ static void test_propagate_diamond(void) bdrv_unref(bs_c); bdrv_unref(bs_b); bdrv_unref(bs_a); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 static void test_propagate_mirror(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx =3D qemu_get_aio_context(); BlockDriverState *src, *target, *filter; BlockBackend *blk; @@ -807,12 +811,13 @@ static void test_propagate_mirror(void) blk_unref(blk); bdrv_unref(src); bdrv_unref(target); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 static void test_attach_second_node(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); AioContext *main_ctx =3D qemu_get_aio_context(); BlockBackend *blk; BlockDriverState *bs, *filter; @@ -840,12 +845,13 @@ static void test_attach_second_node(void) bdrv_unref(filter); bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 static void test_attach_preserve_blk_ctx(void) { IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + AioContext *ctx =3D iothread_ref_and_get_aio_context(iothread, NULL); BlockBackend *blk; BlockDriverState *bs; =20 @@ -871,6 +877,7 @@ static void test_attach_preserve_blk_ctx(void) blk_set_aio_context(blk, qemu_get_aio_context(), &error_abort); bdrv_unref(bs); blk_unref(blk); + iothread_unref_and_put_aio_context(iothread, NULL); } =20 int main(int argc, char **argv) --=20 2.43.0