[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 13/17] vfio/migration: Refactor vfio_devices_all_running_and_mig_a
From: |
Cédric Le Goater |
Subject: |
[PULL 13/17] vfio/migration: Refactor vfio_devices_all_running_and_mig_active() logic |
Date: |
Tue, 24 Dec 2024 16:15:43 +0100 |
From: Avihai Horon <avihaih@nvidia.com>
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: 20241218134022.21264-4-avihaih@nvidia.com">https://lore.kernel.org/r/20241218134022.21264-4-avihaih@nvidia.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
include/hw/vfio/vfio-common.h | 4 ++--
hw/vfio/common.c | 40 +++++++----------------------------
hw/vfio/container.c | 2 +-
3 files changed, 11 insertions(+), 35 deletions(-)
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index
a9a68e3fd9a2a570856193cb290cc252b46093de..0c60be5b15c70168f4f94ad7054d9bd750a162d3
100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -296,8 +296,8 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Error
**errp);
void vfio_migration_exit(VFIODevice *vbasedev);
int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size);
-bool
-vfio_devices_all_running_and_mig_active(const VFIOContainerBase *bcontainer);
+bool vfio_devices_all_dirty_tracking_started(
+ const VFIOContainerBase *bcontainer);
bool
vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer);
int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index
fd24b7ced83d241445c0b3dbd014b125b41a0927..9b5524377ce01a0a982157b314ad60add371bac6
100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -184,12 +184,18 @@ static bool
vfio_devices_all_device_dirty_tracking_started(
return true;
}
+bool vfio_devices_all_dirty_tracking_started(
+ const VFIOContainerBase *bcontainer)
+{
+ return vfio_devices_all_device_dirty_tracking_started(bcontainer) ||
+ bcontainer->dirty_pages_started;
+}
+
static bool vfio_devices_all_dirty_tracking(VFIOContainerBase *bcontainer)
{
VFIODevice *vbasedev;
- if (!(vfio_devices_all_device_dirty_tracking_started(bcontainer) ||
- bcontainer->dirty_pages_started)) {
+ if (!vfio_devices_all_dirty_tracking_started(bcontainer)) {
return false;
}
@@ -225,36 +231,6 @@ bool vfio_devices_all_device_dirty_tracking(const
VFIOContainerBase *bcontainer)
return true;
}
-/*
- * Check if all VFIO devices are running and migration is active, which is
- * essentially equivalent to the migration being in pre-copy phase.
- */
-bool
-vfio_devices_all_running_and_mig_active(const VFIOContainerBase *bcontainer)
-{
- VFIODevice *vbasedev;
-
- if (!migration_is_active()) {
- return false;
- }
-
- QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) {
- VFIOMigration *migration = vbasedev->migration;
-
- if (!migration) {
- return false;
- }
-
- if (vfio_device_state_is_running(vbasedev) ||
- vfio_device_state_is_precopy(vbasedev)) {
- continue;
- } else {
- return false;
- }
- }
- return true;
-}
-
static bool vfio_listener_skipped_section(MemoryRegionSection *section)
{
return (!memory_region_is_ram(section->mr) &&
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index
78a3c2d55fcd0f53c9b679167ad8d1b557f72358..4ebb5268088d0a2006e0ed04afec0ee746ed2c1d
100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -131,7 +131,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase
*bcontainer,
int ret;
Error *local_err = NULL;
- if (iotlb && vfio_devices_all_running_and_mig_active(bcontainer)) {
+ if (iotlb && vfio_devices_all_dirty_tracking_started(bcontainer)) {
if (!vfio_devices_all_device_dirty_tracking(bcontainer) &&
bcontainer->dirty_pages_supported) {
return vfio_dma_unmap_bitmap(container, iova, size, iotlb);
--
2.47.1
- [PULL 01/17] vfio/igd: fix GTT stolen memory size calculation for gen 8+, (continued)
- [PULL 01/17] vfio/igd: fix GTT stolen memory size calculation for gen 8+, Cédric Le Goater, 2024/12/24
- [PULL 02/17] vfio/igd: remove unsupported device ids, Cédric Le Goater, 2024/12/24
- [PULL 04/17] vfio/igd: canonicalize memory size calculations, Cédric Le Goater, 2024/12/24
- [PULL 05/17] vfio/igd: add Gemini Lake and Comet Lake device ids, Cédric Le Goater, 2024/12/24
- [PULL 03/17] vfio/igd: align generation with i915 kernel driver, Cédric Le Goater, 2024/12/24
- [PULL 06/17] vfio/igd: add Alder/Raptor/Rocket/Ice/Jasper Lake device ids, Cédric Le Goater, 2024/12/24
- [PULL 08/17] vfio/igd: emulate GGC register in mmio bar0, Cédric Le Goater, 2024/12/24
- [PULL 10/17] vfio/igd: add x-igd-gms option back to set DSM region size for guest, Cédric Le Goater, 2024/12/24
- [PULL 09/17] vfio/igd: emulate BDSM in mmio bar0 for gen 6-10 devices, Cédric Le Goater, 2024/12/24
- [PULL 12/17] vfio/migration: Refactor vfio_devices_all_dirty_tracking() logic, Cédric Le Goater, 2024/12/24
- [PULL 13/17] vfio/migration: Refactor vfio_devices_all_running_and_mig_active() logic,
Cédric Le Goater <=
- [PULL 07/17] vfio/igd: add macro for declaring mirrored registers, Cédric Le Goater, 2024/12/24
- [PULL 11/17] vfio/container: Add dirty tracking started flag, Cédric Le Goater, 2024/12/24
- [PULL 14/17] vfio/migration: Rename vfio_devices_all_dirty_tracking(), Cédric Le Goater, 2024/12/24
- [PULL 16/17] migration: Drop migration_is_device(), Cédric Le Goater, 2024/12/24
- [PULL 15/17] system/dirtylimit: Don't use migration_is_active(), Cédric Le Goater, 2024/12/24
- [PULL 17/17] migration: Unexport migration_is_active(), Cédric Le Goater, 2024/12/24
- Re: [PULL 00/17] vfio queue, Stefan Hajnoczi, 2024/12/25