Skip to content

Multifd 🔀 device state transfer support with VFIO consumer

Maciej S. Szmigiero qemu-devel 6 versions – Applied

Status from this message: Applied to vfio-next with changes for documentation.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest36 patches 42 repliesApplied
  2. v536 patches 83 repliesSuperseded
  3. v433 patches 103 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v324 patches115 repliesSuperseded
v217 patches110 repliesSuperseded
v113 patches15 repliesSuperseded

Changes in v6 from the cover letter · 25 lines

* Add bql_locked() assertion to migration_incoming_state_destroy() with a comment describing why holding BQL there is necessary.

* Add SPDX-License-Identifier to newly added files.

* Move consistency of multfd transfer settings check to the patch adding x-migration-multifd-transfer property.

* Change packet->idx == UINT32_MAX message to the suggested one.

* Use WITH_QEMU_LOCK_GUARD() in vfio_load_state_buffer().

* Add vfio_load_bufs_thread_{start,end} trace events.

* Invert "ret" value computation logic in vfio_load_bufs_thread() and vfio_multifd_save_complete_precopy_thread() - initialize "ret" to false at definition, remove "ret = false" at every failure/early exit block and add "ret = true" just before the early exit jump label.

* Make vfio_load_bufs_thread_load_config() return a bool and take an "Error **" parameter.

* Make vfio_multifd_setup() (previously called vfio_multifd_transfer_setup()) allocate struct VFIOMultifd if requested by "alloc_multifd" parameter.

* Add vfio_multifd_cleanup() call to vfio_save_cleanup() (for consistency with the load code), with a comment describing that it is currently a NOP there.

* Move vfio_multifd_cleanup() to migration-multifd.c.

* Move general multifd migration description in docs/devel/migration/vfio.rst from the top section to new "Multifd" section at the bottom.

* Add comment describing why x-migration-multifd-transfer needs to be a custom property above the variable containing that custom property type in register_vfio_pci_dev_type().

* Add object_class_property_set_description() description for all 3 newly added parameters: x-migration-multifd-transfer, x-migration-load-config-after-iter and x-migration-max-queued-buffers.

* Split out wiring vfio_multifd_setup() and vfio_multifd_cleanup() into general VFIO load/save setup and cleanup methods into a brand new patch/commit.

* Squash the patch introducing VFIOStateBuffer(s) into the "received buffers queuing" commit to fix building the interim code form at the time of this patch with "-Werror".

* Change device state packet "idstr" field to NULL-terminated and drop QEMU_NONSTRING marking from its definition.

* Add vbasedev->name to VFIO error messages to know which device caused that error.

* Move BQL lock ordering assert closer to the other lock in the lock order in vfio_load_state_buffer().

* Drop orphan "QemuThread load_bufs_thread" VFIOMultifd member leftover from the days of the version 2 of this patch set.

* Change "guint" into an "unsigned int" where it was present in this patch set.

* Use g_autoptr() for QEMUFile also in vfio_load_bufs_thread_load_config().

* Call multifd_abort_device_state_save_threads() if a migration error is already set in the save path to avoid needlessly waiting for the remaining threads to do all of their normal work.

* Other minor changes that should not have functional impact, like:
renamed functions/labels, moved code lines between patches contained in this patch set, added review tags, code formatting, rebased on top of the latest QEMU git master, etc.

Patches in v6 Applied

#Subject and filesSizeRepliesApplied
1/36migration: Clarify that {load, save}_cleanup handlers can run without setupinclude/migration/register.h+5 -10 replies
2/36thread-pool: Remove thread_pool_submit() functioninclude/block/thread-pool.h tests/unit/test-thread-pool.c util/thread-pool.c +1 more+6 -120 replies
3/36thread-pool: Rename AIO pool functions to *_aio() and data types to *Aioinclude/block/aio.h include/block/thread-pool.h util/async.c +2 more+42 -420 replies
4/36thread-pool: Implement generic (non-AIO) pool supportinclude/block/thread-pool.h util/thread-pool.c+170 -00 replies
5/36migration: Add MIG_CMD_SWITCHOVER_START and its load handlerhw/core/machine.c include/migration/client-options.h include/migration/register.h +9 more+87 -00 replies
6/36migration: Add qemu_loadvm_load_state_buffer() and its handlerinclude/migration/register.h migration/savevm.c migration/savevm.h+41 -00 replies
7/36migration: postcopy_ram_listen_thread() should take BQL for some callsmigration/migration.c migration/savevm.c+20 -05 replies
8/36error: define g_autoptr() cleanup function for the Error typeinclude/qapi/error.h+2 -00 replies
9/36migration: Add thread pool of optional load threadsinclude/migration/misc.h include/qemu/typedefs.h migration/migration.c +3 more+105 -40 replies
10/36migration/multifd: Split packet into header and RAM datamigration/multifd.c migration/multifd.h+49 -110 replies
11/36migration/multifd: Device state transfer support - receive sidemigration/multifd.c migration/multifd.h+108 -120 replies
12/36migration/multifd: Make multifd_send() thread safemigration/multifd.c+8 -00 replies
13/36migration/multifd: Add an explicit MultiFDSendData destructormigration/multifd-nocomp.c migration/multifd.c migration/multifd.h+34 -50 replies
14/36migration/multifd: Device state transfer support - send sideinclude/migration/misc.h migration/meson.build migration/multifd-device-state.c +3 more+197 -160 replies
15/36migration/multifd: Make MultiFDSendData a structmigration/multifd-device-state.c migration/multifd-nocomp.c migration/multifd.c +1 more+22 -362 replies
16/36migration/multifd: Add multifd_device_state_supported()include/migration/misc.h migration/multifd-device-state.c+8 -00 replies
17/36migration: Add save_live_complete_precopy_thread handlerinclude/migration/misc.h include/migration/register.h include/qemu/typedefs.h +2 more+170 -11 reply
18/36vfio/migration: Add load_device_config_state_start trace eventhw/vfio/migration.c hw/vfio/trace-events+5 -20 replies
19/36vfio/migration: Convert bytes_transferred counter to atomichw/vfio/migration.c+4 -40 replies
20/36vfio/migration: Add vfio_add_bytes_transferred()hw/vfio/migration.c include/hw/vfio/vfio-common.h+7 -11 reply
21/36vfio/migration: Move migration channel flags to vfio-common.h header filehw/vfio/migration.c include/hw/vfio/vfio-common.h+17 -170 replies
22/36vfio/migration: Multifd device state transfer support - basic typeshw/vfio/meson.build hw/vfio/migration-multifd.c hw/vfio/migration-multifd.h +1 more+52 -01 reply
23/36vfio/migration: Multifd device state transfer - add support checking functionhw/vfio/migration-multifd.c hw/vfio/migration-multifd.h+8 -00 replies
24/36vfio/migration: Multifd setup/cleanup functions and associated VFIOMultifdhw/vfio/migration-multifd.c hw/vfio/migration-multifd.h include/hw/vfio/vfio-common.h+51 -01 reply
25/36vfio/migration: Setup and cleanup multifd transfer in these general methodshw/vfio/migration.c+22 -26 replies
26/36vfio/migration: Multifd device state transfer support - received buffers queuinghw/vfio/migration-multifd.c hw/vfio/migration-multifd.h hw/vfio/migration.c +1 more+168 -01 reply
27/36vfio/migration: Multifd device state transfer support - load threadhw/vfio/migration-multifd.c hw/vfio/migration-multifd.h hw/vfio/migration.c +1 more+247 -01 reply
28/36migration/qemu-file: Define g_autoptr() cleanup function for QEMUFilemigration/qemu-file.h+2 -00 replies
29/36vfio/migration: Multifd device state transfer support - config loading supporthw/vfio/migration-multifd.c hw/vfio/migration.c include/hw/vfio/vfio-common.h+57 -31 reply
30/36vfio/migration: Multifd device state transfer support - send sidehw/vfio/migration-multifd.c hw/vfio/migration-multifd.h hw/vfio/migration.c +2 more+172 -69 replies
31/36vfio/migration: Add x-migration-multifd-transfer VFIO propertyhw/vfio/migration-multifd.c hw/vfio/pci.c include/hw/vfio/vfio-common.h+27 -11 reply
32/36vfio/migration: Make x-migration-multifd-transfer VFIO property mutablehw/vfio/migration-multifd.c hw/vfio/pci.c+21 -31 reply
33/36hw/core/machine: Add compat for x-migration-multifd-transfer VFIO propertyhw/core/machine.c+1 -00 replies
34/36vfio/migration: Max in-flight VFIO device state buffer count limithw/vfio/migration-multifd.c hw/vfio/pci.c include/hw/vfio/vfio-common.h+26 -04 replies
35/36vfio/migration: Add x-migration-load-config-after-iter VFIO propertyhw/vfio/migration-multifd.c hw/vfio/migration-multifd.h hw/vfio/migration.c +2 more+114 -10 replies
36/36vfio/migration: Update VFIO migration documentationdocs/devel/migration/vfio.rst+72 -71 reply

Reviews trailers per patch

33 of 36 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchFabiano RosasZhang ChenPeter XuCédric Le GoaterAvihai Horon
SeriesA-b R-b
1/36R-b R-b
2/36A-b R-b R-b
3/36A-b R-b R-b
4/36R-b R-b
5/36R-b R-b
6/36R-b R-b
7/36A-b
8/36R-b
9/36R-b
10/36R-b R-b
11/36R-b
12/36R-b
13/36R-b R-b
14/36R-b
15/36A-b
16/36R-b R-b
17/36R-b
18/36R-b
19/36R-b
20/36R-b
21/36R-b
22/36R-b
23/36R-b
24/36R-b
25/36R-b
26/36R-b
27/36R-b
28/36R-b R-b
29/36R-b
30/36R-b
31/36R-b
32/36R-b
33/36R-b
34/36
35/36
36/36

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v6 thread

Cover letter [PATCH v6 00/36] Multifd 🔀 device state transfer support with VFIO consumer

From: "Maciej S. Szmigiero" <[email protected]>

This is an updated v6 patch series of the v5 series located here:
https://lore.kernel.org/qemu-devel/[email protected]/

What this patch set is about?
Current live migration device state transfer is done via the main (single) migration channel, which reduces performance and severally impacts the migration downtime for VMs having large device state that needs to be transferred during the switchover phase.

Example devices that have such large switchover phase device state are some types of VFIO SmartNICs and GPUs.

This patch set allows parallelizing this transfer by using multifd channels for it.
It also introduces new load and save threads per VFIO device for decoupling these operations from the main migration thread.
These threads run on newly introduced generic (non-AIO) thread pools, instantiated by the core migration core.

Changes from v5:
* Add bql_locked() assertion to migration_incoming_state_destroy() with a comment describing why holding BQL there is necessary.

* Add SPDX-License-Identifier to newly added files.

* Move consistency of multfd transfer settings check to the patch adding x-migration-multifd-transfer property.

* Change packet->idx == UINT32_MAX message to the suggested one.

* Use WITH_QEMU_LOCK_GUARD() in vfio_load_state_buffer().

* Add vfio_load_bufs_thread_{start,end} trace events.

* Invert "ret" value computation logic in vfio_load_bufs_thread() and vfio_multifd_save_complete_precopy_thread() - initialize "ret" to false at definition, remove "ret = false" at every failure/early exit block and add "ret = true" just before the early exit jump label.

* Make vfio_load_bufs_thread_load_config() return a bool and take an "Error **" parameter.

* Make vfio_multifd_setup() (previously called vfio_multifd_transfer_setup()) allocate struct VFIOMultifd if requested by "alloc_multifd" parameter.

* Add vfio_multifd_cleanup() call to vfio_save_cleanup() (for consistency with the load code), with a comment describing that it is currently a NOP there.

* Move vfio_multifd_cleanup() to migration-multifd.c.

* Move general multifd migration description in docs/devel/migration/vfio.rst from the top section to new "Multifd" section at the bottom.

* Add comment describing why x-migration-multifd-transfer needs to be a custom property above the variable containing that custom property type in register_vfio_pci_dev_type().

* Add object_class_property_set_description() description for all 3 newly added parameters: x-migration-multifd-transfer, x-migration-load-config-after-iter and x-migration-max-queued-buffers.

* Split out wiring vfio_multifd_setup() and vfio_multifd_cleanup() into general VFIO load/save setup and cleanup methods into a brand new patch/commit.

* Squash the patch introducing VFIOStateBuffer(s) into the "received buffers queuing" commit to fix building the interim code form at the time of this patch with "-Werror".

* Change device state packet "idstr" field to NULL-terminated and drop QEMU_NONSTRING marking from its definition.

* Add vbasedev->name to VFIO error messages to know which device caused that error.

* Move BQL lock ordering assert closer to the other lock in the lock order in vfio_load_state_buffer().

* Drop orphan "QemuThread load_bufs_thread" VFIOMultifd member leftover from the days of the version 2 of this patch set.

* Change "guint" into an "unsigned int" where it was present in this patch set.

* Use g_autoptr() for QEMUFile also in vfio_load_bufs_thread_load_config().

* Call multifd_abort_device_state_save_threads() if a migration error is already set in the save path to avoid needlessly waiting for the remaining threads to do all of their normal work.

* Other minor changes that should not have functional impact, like:
renamed functions/labels, moved code lines between patches contained in this patch set, added review tags, code formatting, rebased on top of the latest QEMU git master, etc.

========================================================================

This patch set is targeting QEMU 10.0.

It is also exported as a git tree:
https://gitlab.com/maciejsszmigiero/qemu/-/commits/multifd-device-state-transfer-vfio

========================================================================

Maciej S. Szmigiero (35):
migration: Clarify that {load,save}_cleanup handlers can run without
setup
thread-pool: Remove thread_pool_submit() function
thread-pool: Rename AIO pool functions to *_aio() and data types to
*Aio
thread-pool: Implement generic (non-AIO) pool support
migration: Add MIG_CMD_SWITCHOVER_START and its load handler
migration: Add qemu_loadvm_load_state_buffer() and its handler
migration: postcopy_ram_listen_thread() should take BQL for some calls
error: define g_autoptr() cleanup function for the Error type
migration: Add thread pool of optional load threads migration/multifd: Split packet into header and RAM data migration/multifd: Device state transfer support - receive side migration/multifd: Make multifd_send() thread safe migration/multifd: Add an explicit MultiFDSendData destructor migration/multifd: Device state transfer support - send side migration/multifd: Add multifd_device_state_supported()
migration: Add save_live_complete_precopy_thread handler vfio/migration: Add load_device_config_state_start trace event vfio/migration: Convert bytes_transferred counter to atomic vfio/migration: Add vfio_add_bytes_transferred() vfio/migration: Move migration channel flags to vfio-common.h header
file
vfio/migration: Multifd device state transfer support - basic types vfio/migration: Multifd device state transfer - add support checking
function
vfio/migration: Multifd setup/cleanup functions and associated
VFIOMultifd
vfio/migration: Setup and cleanup multifd transfer in these general
methods
vfio/migration: Multifd device state transfer support - received
buffers queuing
vfio/migration: Multifd device state transfer support - load thread migration/qemu-file: Define g_autoptr() cleanup function for QEMUFile vfio/migration: Multifd device state transfer support - config loading
support
vfio/migration: Multifd device state transfer support - send side vfio/migration: Add x-migration-multifd-transfer VFIO property vfio/migration: Make x-migration-multifd-transfer VFIO property
mutable
hw/core/machine: Add compat for x-migration-multifd-transfer VFIO
property
vfio/migration: Max in-flight VFIO device state buffer count limit vfio/migration: Add x-migration-load-config-after-iter VFIO property vfio/migration: Update VFIO migration documentation

Peter Xu (1):
migration/multifd: Make MultiFDSendData a struct

 docs/devel/migration/vfio.rst      |  79 ++-
 hw/core/machine.c                  |   2 +
 hw/vfio/meson.build                |   1 +
 hw/vfio/migration-multifd.c        | 786 +++++++++++++++++++++++++++++
 hw/vfio/migration-multifd.h        |  37 ++
 hw/vfio/migration.c                | 111 ++--
 hw/vfio/pci.c                      |  40 ++
 hw/vfio/trace-events               |  13 +-
 include/block/aio.h                |   8 +-
 include/block/thread-pool.h        |  62 ++-
 include/hw/vfio/vfio-common.h      |  34 ++
 include/migration/client-options.h |   4 +
 include/migration/misc.h           |  25 +
 include/migration/register.h       |  52 +-
 include/qapi/error.h               |   2 +
 include/qemu/typedefs.h            |   5 +
 migration/colo.c                   |   3 +
 migration/meson.build              |   1 +
 migration/migration-hmp-cmds.c     |   2 +
 migration/migration.c              |  20 +-
 migration/migration.h              |   7 +
 migration/multifd-device-state.c   | 212 ++++++++
 migration/multifd-nocomp.c         |  30 +-
 migration/multifd.c                | 248 +++++++--
 migration/multifd.h                |  74 ++-
 migration/options.c                |   9 +
 migration/qemu-file.h              |   2 +
 migration/savevm.c                 | 201 +++++++-
 migration/savevm.h                 |   6 +-
 migration/trace-events             |   1 +
 scripts/analyze-migration.py       |  11 +
 tests/unit/test-thread-pool.c      |   6 +-
 util/async.c                       |   6 +-
 util/thread-pool.c                 | 184 +++++--
 util/trace-events                  |   6 +-
 35 files changed, 2125 insertions(+), 165 deletions(-)
 create mode 100644 hw/vfio/migration-multifd.c
 create mode 100644 hw/vfio/migration-multifd.h
 create mode 100644 migration/multifd-device-state.c