vfio/migration: Refactor vfio_devices_all_running_and_mig_active() logic
authorAvihai Horon <avihaih@nvidia.com>
Wed, 18 Dec 2024 13:40:18 +0000 (15:40 +0200)
committerCédric Le Goater <clg@redhat.com>
Thu, 26 Dec 2024 06:23:38 +0000 (07:23 +0100)
commit6e9df66e8afaa2e2fc98e7a3470edf00ffa16f03
tree08c2da0c57f146b6f1ee2e62395b2f8cfe573436
parent0ae05e087f99a8e4ca84537bdce65d25912d084e
vfio/migration: Refactor vfio_devices_all_running_and_mig_active() logic

During DMA unmap with vIOMMU, vfio_devices_all_running_and_mig_active()
is used to check whether a dirty page log sync of the unmapped pages is
required. Such log sync is needed during migration pre-copy phase, and
the current logic detects it by checking if migration is active and if
the VFIO devices are running.

However, recently there has been an effort to simplify the migration
status API and reduce it to a single migration_is_running() function.

To accommodate this, refactor vfio_devices_all_running_and_mig_active()
logic so it won't use migration_is_active(). Do it by simply checking if
dirty tracking has been started using internal VFIO flags.

This should be equivalent to the previous logic as during migration
dirty tracking is active and when the guest is stopped there shouldn't
be DMA unmaps coming from it.

As a side effect, now that migration status is no longer used, DMA unmap
log syncs are untied from migration. This will make calc-dirty-rate more
accurate as now it will also include VFIO dirty pages that were DMA
unmapped.

Also rename the function to properly reflect its new logic and extract
common code from vfio_devices_all_dirty_tracking().

Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
Tested-by: Joao Martins <joao.m.martins@oracle.com>
Link: https://lore.kernel.org/r/20241218134022.21264-4-avihaih@nvidia.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
hw/vfio/common.c
hw/vfio/container.c
include/hw/vfio/vfio-common.h