All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhang Chen <zhangckid@gmail.com>
To: qemu-devel <qemu-devel@nongnu.org>,
	"Eric Blake" <eblake@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"'Michael S . Tsirkin'" <mst@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"'Daniel P . Berrangé'" <berrange@redhat.com>,
	"Jason Wang" <jasowangio@gmail.com>
Cc: Zhang Chen <zhangckid@gmail.com>
Subject: [PATCH V20 08/14] virtio-balloon: Update tracking iothread users with holder
Date: Fri, 13 Nov 2026 17:25:59 +0800	[thread overview]
Message-ID: <20261113092605.942292-9-zhangckid@gmail.com> (raw)
In-Reply-To: <20261113092605.942292-1-zhangckid@gmail.com>

Replace raw object_ref/unref calls with
iothread_ref_and_get/unref_and_put_aio_context.

Signed-off-by: Zhang Chen <zhangckid@gmail.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/virtio/virtio-balloon.c         | 21 ++++++++++++++++-----
 include/hw/virtio/virtio-balloon.h |  1 +
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 547173e035..ef694a17b2 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -871,12 +871,19 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
     s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats);
 
     if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
+        g_autofree char *path = object_get_canonical_path(OBJECT(s));
+        const IOThreadHolder io_holder = {
+            .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT,
+            .u.qom_object.qom_path = path,
+        };
+
         s->free_page_vq = virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE,
                                            virtio_balloon_handle_free_page_vq);
         precopy_add_notifier(&s->free_page_hint_notify);
 
-        object_ref(OBJECT(s->iothread));
-        s->free_page_bh = aio_bh_new_guarded(iothread_get_aio_context(s->iothread),
+        s->free_page_ctx = iothread_ref_and_get_aio_context(s->iothread,
+                                                          &io_holder);
+        s->free_page_bh = aio_bh_new_guarded(s->free_page_ctx,
                                              virtio_ballloon_get_free_page_hints, s,
                                              &dev->mem_reentrancy_guard);
     }
@@ -903,7 +910,11 @@ static void virtio_balloon_device_unrealize(DeviceState *dev)
 
     qemu_unregister_resettable(OBJECT(dev));
     if (s->free_page_bh) {
-        AioContext *ctx = iothread_get_aio_context(s->iothread);
+        g_autofree char *path = object_get_canonical_path(OBJECT(s));
+        const IOThreadHolder io_holder = {
+            .type = IO_THREAD_HOLDER_KIND_QOM_OBJECT,
+            .u.qom_object.qom_path = path,
+        };
 
         qemu_bh_delete(s->free_page_bh);
 
@@ -911,9 +922,9 @@ static void virtio_balloon_device_unrealize(DeviceState *dev)
         s->free_page_hint_status = FREE_PAGE_HINT_S_UNREALIZE;
         qemu_cond_signal(&s->free_page_cond);
         qemu_mutex_unlock(&s->free_page_lock);
-        aio_wait_bh_oneshot(ctx, dummy_bh, NULL);
+        aio_wait_bh_oneshot(s->free_page_ctx, dummy_bh, NULL);
 
-        object_unref(OBJECT(s->iothread));
+        iothread_unref_and_put_aio_context(s->iothread, &io_holder);
         precopy_remove_notifier(&s->free_page_hint_notify);
     }
     balloon_stats_destroy_timer(s);
diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h
index 53bbaa4c9a..5c3731b3e9 100644
--- a/include/hw/virtio/virtio-balloon.h
+++ b/include/hw/virtio/virtio-balloon.h
@@ -54,6 +54,7 @@ struct VirtIOBalloon {
     size_t stats_vq_offset;
     QEMUTimer *stats_timer;
     IOThread *iothread;
+    AioContext *free_page_ctx;
     QEMUBH *free_page_bh;
     /*
      * Lock to synchronize threads to access the free page reporting related
-- 
2.53.0



  parent reply	other threads:[~2026-11-13  9:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  9:25 [PATCH V20 00/14] iothread: Support tracking and querying IOThread holder Zhang Chen
2026-11-13  9:25 ` [PATCH V20 01/14] iothread: introduce holder tracking Zhang Chen
2026-11-13  9:25 ` [PATCH V20 02/14] iothread: add holder-aware AioContext accessors Zhang Chen
2026-11-13  9:25 ` [PATCH V20 03/14] block/export: track IOThread references Zhang Chen
2026-11-13  9:25 ` [PATCH V20 04/14] monitor: track IOThread users with QOM paths Zhang Chen
2026-11-13  9:25 ` [PATCH V20 05/14] virtio-vq-mapping: track iothread-vq-mapping references using device path Zhang Chen
2026-11-13  9:25 ` [PATCH V20 06/14] virtio: track IOThread references for thread pinning Zhang Chen
2026-11-13  9:25 ` [PATCH V20 07/14] net/colo: track IOThread references using path-based holder Zhang Chen
2026-11-13  9:25 ` Zhang Chen [this message]
2026-11-13  9:26 ` [PATCH V20 09/14] vfio-user/proxy: Update tracking iothread users with device QOM paths Zhang Chen
2026-11-13  9:26 ` [PATCH V20 10/14] xen-block: Update tracking iothread users with holder name Zhang Chen
2026-11-13  9:26 ` [PATCH V20 11/14] monitor/hmp: display IOThread holders Zhang Chen
2026-11-13  9:26 ` [PATCH V20 12/14] iothread: make legacy AioContext getter explicitly unsafe Zhang Chen
2026-11-13  9:26 ` [PATCH V20 13/14] tests/unit/iothread: update AioContext ref/put helpers Zhang Chen
2026-11-13  9:26 ` [PATCH V20 14/14] docs/devel: document holder-aware IOThread AioContext APIs Zhang Chen
2026-11-24  6:09 ` [PATCH V20 00/14] iothread: Support tracking and querying IOThread holder Zhang Chen
2026-11-24  8:47   ` Markus Armbruster
2026-11-24 20:06     ` Stefan Hajnoczi
2026-11-25 18:19 ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261113092605.942292-9-zhangckid@gmail.com \
    --to=zhangckid@gmail.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jasowangio@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.