block/export/export.c | 62 +++++++++++++--- blockdev.c | 9 ++- hw/block/dataplane/xen-block.c | 19 ++++- hw/block/virtio-blk.c | 21 ++++-- hw/scsi/virtio-scsi-dataplane.c | 22 ++++-- hw/vfio-user/pci.c | 2 +- hw/vfio-user/proxy.c | 20 +++++- hw/vfio-user/proxy.h | 4 +- hw/virtio/iothread-vq-mapping.c | 20 ++++-- hw/virtio/virtio-balloon.c | 21 ++++-- include/block/export.h | 5 ++ include/hw/virtio/iothread-vq-mapping.h | 6 +- include/hw/virtio/virtio-balloon.h | 1 + include/system/iothread.h | 38 +++++++++- iothread.c | 89 ++++++++++++++++++++++- monitor/hmp-cmds.c | 20 ++++++ monitor/monitor-internal.h | 7 +- monitor/monitor.c | 36 +++++++--- monitor/qmp.c | 14 ++-- net/colo-compare.c | 36 ++++++---- qapi/misc.json | 94 +++++++++++++++++++++---- 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 ++++-- 26 files changed, 508 insertions(+), 107 deletions(-)
### Motivation
Currently, the relationship between IOThreads and the resources using them is
opaque. From a management perspective, it is difficult to determine which
devices or block exports are currently associated with a specific IOThread
via QMP or HMP.
This series introduces a "holder" tracking mechanism based on QOM paths or
block exports to significantly improve IOThread observability.
In high-performance virtualization environments, users often pre-allocate
a set of IOThreads to serve as a persistent thread pool. During device
hotplug/unplug cycles, while IOThread objects remain persistent,
their attachment state changes dynamically.
By tracking these "holders," administrators can use `query-iothreads` to
monitor the real-time load distribution of the thread pool and identify which
specific devices (e.g., virtio-blk, BlockExport) are attached to which thread.
### Technical Overview
* Holder tracking
Add a QAPI holder list to each IOThread. A holder identifies either
a QOM object by its canonical path or a block export by its unique
BlockExportOptions ID.
* Explicit reference lifecycle
Add iothread_ref_and_get_aio_context() and the matching
iothread_unref_and_put_aio_context(). Acquiring an AioContext registers a
holder and keeps the IOThread alive until the matching put.
Legacy callers without a matching lifecycle use the explicitly named
iothread_unsafe_get_aio_context(). The ambiguous legacy
iothread_get_aio_context() is removed after all production callers
are migrated.
* Subsystem integration
Track holders for block exports, monitors, virtio-blk, virtio-scsi,
virtio queue mappings, virtio balloon thread pinning, COLO compare,
vfio-user proxy, and xen-block.
* Introspection
Extend IOThreadInfo with a holders array returned by
query-iothreads. Display the same information with info iothreads.
### V18 -> V17 Changelog
- Saved the COLO object's QOM path for finalization and guarded
holder cleanup against incomplete initialization.
- Used the owning PCI device's QOM path for vfio-user holders
and saved it for disconnect().
- Simplified the monitor QOM path field name and clarified
PATCH 12's commit message.
- Rebased on upstream and collected Reviewed-by tags.
### V17 -> V16 Changelog
- Rebase code to resolve code conflicts for patch 8:
"virtio-balloon: Update tracking iothread users with holder".
This issue caused by latest merged patch "fdc3f9a83d".
### V16 -> V15 Changelog
- Unified per-monitor IOThread checks and accesses through
mon->iothread after initialization.
- Simplified PATCH 13's commit message and clarified why blockdev
cannot use the holder-aware get/put APIs.
- Dropped the v15 Patch 1 in this series, It will be taken away
independently by trivial-patches tree.
### V15 -> V14 Changelog
- Moved monitor IOThread cleanup from unparent() to monitor_finalize(),
pairing complete() with instance finalization.
- Squashed V14 PATCH 04 and PATCH 14 into PATCH 13 and clarified the
blockdev lifetime assumption. Since the additional changes are minimal,
PATCH 13 retains Stefan's Reviewed-by from V14 PATCH 04.
- Rebased and adapted info iothreads to the MonitorHMP interface.
### V14 -> V13 Changelog
- Renamed patch 3 and clarified that it introduces holder-tracking
infrastructure, with users converted in subsequent patches.
- Documented that monitor holders are not visible to management
applications, while retaining the tracking for a consistent holder
and IOThread reference lifecycle.
- Rebased on the latest upstream.
### V13 -> V12 Changelog
- Refactored block export IOThread reference handling with shared
init/cleanup helpers and preserved the existing single-IOThread
driver arguments.
- Moved monitor IOThread cleanup to the QOM unparent callback,
where the canonical path is still available.
- Kept internal IOThreads hidden from query-iothreads.
- Made virtio queue-mapping holder arguments const.
- Improved some detail comments.
### V12 -> V11 Changelog
- Change the function name from the "iothread_put_aio_context()"
to "iothread_unref_and_put_aio_context()" match the
"iothread_unref_and_put_aio_context".
- Fix unnecessary char * cast since the holder variable is
declared const.
- Add detailed commit msg in patch 06/15.
- Optimize the HMP print in patch 13/15.
- Rebase code on upstream.
Zhang Chen (13):
iothread: introduce holder tracking
iothread: add holder-aware AioContext accessors
block/export: track IOThread references
monitor: track IOThread users with QOM paths
virtio-vq-mapping: track iothread-vq-mapping references using device
path
virtio: track IOThread references for thread pinning
net/colo: track IOThread references using path-based holder
virtio-balloon: Update tracking iothread users with holder
vfio-user/proxy: Update tracking iothread users with device QOM paths
xen-block: Update tracking iothread users with holder name
monitor/hmp: display IOThread holders
iothread: make legacy AioContext getter explicitly unsafe
tests/unit/iothread: update AioContext ref/put helpers
block/export/export.c | 62 +++++++++++++---
blockdev.c | 9 ++-
hw/block/dataplane/xen-block.c | 19 ++++-
hw/block/virtio-blk.c | 21 ++++--
hw/scsi/virtio-scsi-dataplane.c | 22 ++++--
hw/vfio-user/pci.c | 2 +-
hw/vfio-user/proxy.c | 20 +++++-
hw/vfio-user/proxy.h | 4 +-
hw/virtio/iothread-vq-mapping.c | 20 ++++--
hw/virtio/virtio-balloon.c | 21 ++++--
include/block/export.h | 5 ++
include/hw/virtio/iothread-vq-mapping.h | 6 +-
include/hw/virtio/virtio-balloon.h | 1 +
include/system/iothread.h | 38 +++++++++-
iothread.c | 89 ++++++++++++++++++++++-
monitor/hmp-cmds.c | 20 ++++++
monitor/monitor-internal.h | 7 +-
monitor/monitor.c | 36 +++++++---
monitor/qmp.c | 14 ++--
net/colo-compare.c | 36 ++++++----
qapi/misc.json | 94 +++++++++++++++++++++----
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 ++++--
26 files changed, 508 insertions(+), 107 deletions(-)
--
2.43.0
Please update docs/devel/multiple-iothreads.rst. It still refers to iothread_get_aio_context() instead of the new API. Thanks, Stefan
On Fri, Oct 23, 2026 at 4:16 AM Stefan Hajnoczi <stefanha@redhat.com> wrote: > > Please update docs/devel/multiple-iothreads.rst. It still refers to > iothread_get_aio_context() instead of the new API. > Hi Stefan, Thanks for pointing this out. Would it be okay to include the documentation update as a separate patch in the next revision like this? diff --git a/docs/devel/multiple-iothreads.rst b/docs/devel/multiple-iothreads.rst index a6eb046267..c184222d71 100644 --- a/docs/devel/multiple-iothreads.rst +++ b/docs/devel/multiple-iothreads.rst @@ -88,11 +88,20 @@ argument, which is used to check for and prevent re-entrancy problems. For BHs associated with devices, the reentrancy-guard is contained in the corresponding ``DeviceState`` and named ``mem_reentrancy_guard``. -The ``AioContext`` can be obtained from the ``IOThread`` using -``iothread_get_aio_context()`` or for the main loop using -``qemu_get_aio_context()``. Code that takes an ``AioContext`` argument -works both in ``IOThread``\ s or the main loop, depending on which ``AioContext`` -instance the caller passes in. +The ``AioContext`` can be obtained from an ``IOThread`` using +``iothread_ref_and_get_aio_context(iothread, holder)``, or from the main loop +using ``qemu_get_aio_context()``. Code accepting an ``AioContext`` works with +either event loop. + +The holder-aware get registers a holder and takes an IOThread reference. +After the caller has finished using the context, release the reference with +``iothread_unref_and_put_aio_context()``, passing the same IOThread and an +equivalent holder. Both calls require the BQL. No matching IOThread put is +needed for the main loop's context. + +``iothread_unsafe_get_aio_context()`` neither registers a holder nor takes a +reference. It is for legacy callers that ensure the IOThread's lifetime +themselves; new code must use the holder-aware API. How to synchronize with an ``IOThread`` --------------------------------------- When you have a chance, I'd also appreciate your review of the remaining patches that don't yet have Reviewed-by tags. Thanks Chen > Thanks, > Stefan >
On Fri, Oct 23, 2026 at 05:42:48PM +0800, Zhang Chen wrote: > On Fri, Oct 23, 2026 at 4:16 AM Stefan Hajnoczi <stefanha@redhat.com> wrote: > > > > Please update docs/devel/multiple-iothreads.rst. It still refers to > > iothread_get_aio_context() instead of the new API. > > > > Hi Stefan, > > Thanks for pointing this out. Would it be okay to include the documentation > update as a separate patch in the next revision like this? > > diff --git a/docs/devel/multiple-iothreads.rst > b/docs/devel/multiple-iothreads.rst > index a6eb046267..c184222d71 100644 > --- a/docs/devel/multiple-iothreads.rst > +++ b/docs/devel/multiple-iothreads.rst > @@ -88,11 +88,20 @@ argument, which is used to check for and prevent > re-entrancy problems. For > BHs associated with devices, the reentrancy-guard is contained in the > corresponding ``DeviceState`` and named ``mem_reentrancy_guard``. > > -The ``AioContext`` can be obtained from the ``IOThread`` using > -``iothread_get_aio_context()`` or for the main loop using > -``qemu_get_aio_context()``. Code that takes an ``AioContext`` argument > -works both in ``IOThread``\ s or the main loop, depending on which > ``AioContext`` > -instance the caller passes in. > +The ``AioContext`` can be obtained from an ``IOThread`` using > +``iothread_ref_and_get_aio_context(iothread, holder)``, or from the main loop > +using ``qemu_get_aio_context()``. Code accepting an ``AioContext`` works with > +either event loop. > + > +The holder-aware get registers a holder and takes an IOThread reference. I suggest ``iothread_ref_and_get_aio_context()`` instead of "The holder-aware get" so it's clear which API you are referring to. > +After the caller has finished using the context, release the reference with > +``iothread_unref_and_put_aio_context()``, passing the same IOThread and an > +equivalent holder. Both calls require the BQL. No matching IOThread put is > +needed for the main loop's context. > + > +``iothread_unsafe_get_aio_context()`` neither registers a holder nor takes a > +reference. It is for legacy callers that ensure the IOThread's lifetime > +themselves; new code must use the holder-aware API. Yes, this looks good. Thanks! > > How to synchronize with an ``IOThread`` > --------------------------------------- > > > When you have a chance, I'd also appreciate your review of the remaining > patches that don't yet have Reviewed-by tags. I will take a look! Stefan
On Wed, Oct 28, 2026 at 4:11 AM Stefan Hajnoczi <stefanha@redhat.com> wrote: > > On Fri, Oct 23, 2026 at 05:42:48PM +0800, Zhang Chen wrote: > > On Fri, Oct 23, 2026 at 4:16 AM Stefan Hajnoczi <stefanha@redhat.com> wrote: > > > > > > Please update docs/devel/multiple-iothreads.rst. It still refers to > > > iothread_get_aio_context() instead of the new API. > > > > > > > Hi Stefan, > > > > Thanks for pointing this out. Would it be okay to include the documentation > > update as a separate patch in the next revision like this? > > > > diff --git a/docs/devel/multiple-iothreads.rst > > b/docs/devel/multiple-iothreads.rst > > index a6eb046267..c184222d71 100644 > > --- a/docs/devel/multiple-iothreads.rst > > +++ b/docs/devel/multiple-iothreads.rst > > @@ -88,11 +88,20 @@ argument, which is used to check for and prevent > > re-entrancy problems. For > > BHs associated with devices, the reentrancy-guard is contained in the > > corresponding ``DeviceState`` and named ``mem_reentrancy_guard``. > > > > -The ``AioContext`` can be obtained from the ``IOThread`` using > > -``iothread_get_aio_context()`` or for the main loop using > > -``qemu_get_aio_context()``. Code that takes an ``AioContext`` argument > > -works both in ``IOThread``\ s or the main loop, depending on which > > ``AioContext`` > > -instance the caller passes in. > > +The ``AioContext`` can be obtained from an ``IOThread`` using > > +``iothread_ref_and_get_aio_context(iothread, holder)``, or from the main loop > > +using ``qemu_get_aio_context()``. Code accepting an ``AioContext`` works with > > +either event loop. > > + > > +The holder-aware get registers a holder and takes an IOThread reference. > > I suggest ``iothread_ref_and_get_aio_context()`` instead of "The > holder-aware get" so it's clear which API you are referring to. OK, I will update to V19. Thanks Chen > > > +After the caller has finished using the context, release the reference with > > +``iothread_unref_and_put_aio_context()``, passing the same IOThread and an > > +equivalent holder. Both calls require the BQL. No matching IOThread put is > > +needed for the main loop's context. > > + > > +``iothread_unsafe_get_aio_context()`` neither registers a holder nor takes a > > +reference. It is for legacy callers that ensure the IOThread's lifetime > > +themselves; new code must use the holder-aware API. > > Yes, this looks good. Thanks! > > > > > How to synchronize with an ``IOThread`` > > --------------------------------------- > > > > > > When you have a chance, I'd also appreciate your review of the remaining > > patches that don't yet have Reviewed-by tags. > > I will take a look! > > Stefan >
Hi all, A gentle ping on v18. Could you please take a look at the remaining patches, particularly the COLO and vfio-user changes addressing the previous review comments? Please let me know if anything else is needed to move this series forward. Thanks, Chen On Tue, Sep 29, 2026 at 4:44 PM Zhang Chen <zhangckid@gmail.com> wrote: > > ### Motivation > Currently, the relationship between IOThreads and the resources using them is > opaque. From a management perspective, it is difficult to determine which > devices or block exports are currently associated with a specific IOThread > via QMP or HMP. > > This series introduces a "holder" tracking mechanism based on QOM paths or > block exports to significantly improve IOThread observability. > In high-performance virtualization environments, users often pre-allocate > a set of IOThreads to serve as a persistent thread pool. During device > hotplug/unplug cycles, while IOThread objects remain persistent, > their attachment state changes dynamically. > > By tracking these "holders," administrators can use `query-iothreads` to > monitor the real-time load distribution of the thread pool and identify which > specific devices (e.g., virtio-blk, BlockExport) are attached to which thread. > > ### Technical Overview > * Holder tracking > > Add a QAPI holder list to each IOThread. A holder identifies either > a QOM object by its canonical path or a block export by its unique > BlockExportOptions ID. > > * Explicit reference lifecycle > > Add iothread_ref_and_get_aio_context() and the matching > iothread_unref_and_put_aio_context(). Acquiring an AioContext registers a > holder and keeps the IOThread alive until the matching put. > > Legacy callers without a matching lifecycle use the explicitly named > iothread_unsafe_get_aio_context(). The ambiguous legacy > iothread_get_aio_context() is removed after all production callers > are migrated. > > * Subsystem integration > > Track holders for block exports, monitors, virtio-blk, virtio-scsi, > virtio queue mappings, virtio balloon thread pinning, COLO compare, > vfio-user proxy, and xen-block. > > * Introspection > > Extend IOThreadInfo with a holders array returned by > query-iothreads. Display the same information with info iothreads. > > > ### V18 -> V17 Changelog > - Saved the COLO object's QOM path for finalization and guarded > holder cleanup against incomplete initialization. > - Used the owning PCI device's QOM path for vfio-user holders > and saved it for disconnect(). > - Simplified the monitor QOM path field name and clarified > PATCH 12's commit message. > - Rebased on upstream and collected Reviewed-by tags. > > ### V17 -> V16 Changelog > - Rebase code to resolve code conflicts for patch 8: > "virtio-balloon: Update tracking iothread users with holder". > This issue caused by latest merged patch "fdc3f9a83d". > > ### V16 -> V15 Changelog > - Unified per-monitor IOThread checks and accesses through > mon->iothread after initialization. > - Simplified PATCH 13's commit message and clarified why blockdev > cannot use the holder-aware get/put APIs. > - Dropped the v15 Patch 1 in this series, It will be taken away > independently by trivial-patches tree. > > ### V15 -> V14 Changelog > - Moved monitor IOThread cleanup from unparent() to monitor_finalize(), > pairing complete() with instance finalization. > - Squashed V14 PATCH 04 and PATCH 14 into PATCH 13 and clarified the > blockdev lifetime assumption. Since the additional changes are minimal, > PATCH 13 retains Stefan's Reviewed-by from V14 PATCH 04. > - Rebased and adapted info iothreads to the MonitorHMP interface. > > ### V14 -> V13 Changelog > - Renamed patch 3 and clarified that it introduces holder-tracking > infrastructure, with users converted in subsequent patches. > - Documented that monitor holders are not visible to management > applications, while retaining the tracking for a consistent holder > and IOThread reference lifecycle. > - Rebased on the latest upstream. > > ### V13 -> V12 Changelog > - Refactored block export IOThread reference handling with shared > init/cleanup helpers and preserved the existing single-IOThread > driver arguments. > - Moved monitor IOThread cleanup to the QOM unparent callback, > where the canonical path is still available. > - Kept internal IOThreads hidden from query-iothreads. > - Made virtio queue-mapping holder arguments const. > - Improved some detail comments. > > ### V12 -> V11 Changelog > - Change the function name from the "iothread_put_aio_context()" > to "iothread_unref_and_put_aio_context()" match the > "iothread_unref_and_put_aio_context". > - Fix unnecessary char * cast since the holder variable is > declared const. > - Add detailed commit msg in patch 06/15. > - Optimize the HMP print in patch 13/15. > - Rebase code on upstream. > > > Zhang Chen (13): > iothread: introduce holder tracking > iothread: add holder-aware AioContext accessors > block/export: track IOThread references > monitor: track IOThread users with QOM paths > virtio-vq-mapping: track iothread-vq-mapping references using device > path > virtio: track IOThread references for thread pinning > net/colo: track IOThread references using path-based holder > virtio-balloon: Update tracking iothread users with holder > vfio-user/proxy: Update tracking iothread users with device QOM paths > xen-block: Update tracking iothread users with holder name > monitor/hmp: display IOThread holders > iothread: make legacy AioContext getter explicitly unsafe > tests/unit/iothread: update AioContext ref/put helpers > > block/export/export.c | 62 +++++++++++++--- > blockdev.c | 9 ++- > hw/block/dataplane/xen-block.c | 19 ++++- > hw/block/virtio-blk.c | 21 ++++-- > hw/scsi/virtio-scsi-dataplane.c | 22 ++++-- > hw/vfio-user/pci.c | 2 +- > hw/vfio-user/proxy.c | 20 +++++- > hw/vfio-user/proxy.h | 4 +- > hw/virtio/iothread-vq-mapping.c | 20 ++++-- > hw/virtio/virtio-balloon.c | 21 ++++-- > include/block/export.h | 5 ++ > include/hw/virtio/iothread-vq-mapping.h | 6 +- > include/hw/virtio/virtio-balloon.h | 1 + > include/system/iothread.h | 38 +++++++++- > iothread.c | 89 ++++++++++++++++++++++- > monitor/hmp-cmds.c | 20 ++++++ > monitor/monitor-internal.h | 7 +- > monitor/monitor.c | 36 +++++++--- > monitor/qmp.c | 14 ++-- > net/colo-compare.c | 36 ++++++---- > qapi/misc.json | 94 +++++++++++++++++++++---- > 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 ++++-- > 26 files changed, 508 insertions(+), 107 deletions(-) > > -- > 2.43.0 >
© 2016 - 2026 Red Hat, Inc.