@samitouri / QOSamiQemu / commits / 6234505ce8

vfio/migration: Fix incorrect reporting for VFIO pending data

VFIO reports different things in its fast/slow version of query pending results. It was because it wants to make sure precopy data can reach 0, which is needed to make sure sync queries will happen periodically over time. Now with stopcopy size reporting facility it doesn't need this hack anymore. Fix this by reporting the same values in fast/slow versions of query pending request, except that the slow version will do a slow sync with the hardwares. When at it, removing the special casing for vfio_device_state_is_precopy() which may reporting nothing in a fast query. Then ther reporting will be consistent to VFIO devices that do not support precopy phase. Copy stable might be too much; just skip it and skip the Fixes. Reviewed-by: Avihai Horon <avihaih@nvidia.com> Tested-by: Avihai Horon <avihaih@nvidia.com> Link: https://lore.kernel.org/r/20260421202110.306051-9-peterx@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com>

Peter Xu committed Apr 21, 2026 at 16:21 UTC 6234505ce848634d3f95b3a7554e225f104f87f5
1 file changed +11 -7
hw/vfio/migration.c
+11 -7
@@ -587,19 +587,23 @@ static void vfio_state_pending(void *opaque, MigPendingData *pending,
587 {
588 VFIODevice *vbasedev = opaque;
589 VFIOMigration *migration = vbasedev->migration;
590 - uint64_t remain;
590 + uint64_t precopy_size, stopcopy_size;
591
592 if (exact) {
593 vfio_state_pending_sync(vbasedev);
594 - remain = migration->stopcopy_size;
594 + }
595 +
596 + precopy_size =
597 + migration->precopy_init_size + migration->precopy_dirty_size;
598 +
599 + if (migration->stopcopy_size > precopy_size) {
600 + stopcopy_size = migration->stopcopy_size - precopy_size;
601 } else {
596 - if (!vfio_device_state_is_precopy(vbasedev)) {
597 - return;
598 - }
599 - remain = migration->precopy_init_size + migration->precopy_dirty_size;
602 + stopcopy_size = 0;
603 }
604
602 - pending->precopy_bytes += remain;
605 + pending->precopy_bytes += precopy_size;
606 + pending->stopcopy_bytes += stopcopy_size;
607
608 trace_vfio_state_pending(vbasedev->name, migration->stopcopy_size,
609 migration->precopy_init_size,