migration: Drop/unexport migration_is_device() and migration_is_active()
cover migration: Drop/unexport migration_is_device() and migration_is_active()
Hello,
This follows up on Peter's series [1] to simplify migration status API to a single migration_is_running() function.
Peter's series tried to drop migration_is_device() and migration_is_active(), however VFIO used them to check if dirty page tracking has been started in order to avoid errors in log sync, so they couldn't simply be dropped without some preliminary cleanups.
This series handles these preliminary cleanups and eventually drops migration_is_device() and unexports migration_is_active().
The series has been migration tested with the following:
- VFIO device dirty tracking.
- Legacy VFIO iommu dirty tracking.
- vIOMMU + Legacy VFIO iommu dirty tracking (migration with vIOMMU is currently blocked, so I used a patched QEMU to allow it).
I didn't test it with iommu DPT as I don't have access to such HW. Cedric, I remember you said that you have such HW, it would be very helpful if you could test it.
Patch structure:
1-6: Refactor and clean up VFIO dirty page tracking helpers. 7: Refactor dirty limit code.
8-9: Drop/unexport migration_is_device() and migration_is_running().
Thanks.
[1]
https://lore.kernel.org/qemu-devel/[email protected]/
Avihai Horon (9):
vfio/container: Add dirty tracking started flag vfio/migration: Refactor vfio_devices_all_dirty_tracking() logic vfio/migration: Refactor vfio_devices_all_running_and_mig_active()
logic
vfio/migration: Add vfio_devices_all_dirty_tracking_started() helper vfio/migration: Drop vfio_dma_unmap_dirty_sync_needed() vfio/migration: Rename vfio_devices_all_dirty_tracking() system/dirtylimit: Don't use migration_is_active()
migration: Drop migration_is_device()
migration: Unexport migration_is_active()
include/hw/vfio/vfio-common.h | 4 +- include/hw/vfio/vfio-container-base.h | 1 + include/migration/misc.h | 2 - hw/vfio/common.c | 61 ++++++++++++--------------- hw/vfio/container-base.c | 8 +++- hw/vfio/container.c | 2 +- migration/migration.c | 23 ++++------ system/dirtylimit.c | 3 +- 8 files changed, 48 insertions(+), 56 deletions(-)
Signature · 1 line
2.40.1
PATCH 1/9 vfio/container: Add dirty tracking started flag
Add a flag to VFIOContainerBase that indicates whether dirty tracking has been started for the container or not.
This will be used in the following patches to allow dirty page syncs only if dirty tracking has been started.
--- include/hw/vfio/vfio-container-base.h | 1 + hw/vfio/container-base.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-)
include/hw/vfio/vfio-container-base.h +1 -0
@@ -44,6 +44,7 @@ typedef struct VFIOContainerBase {unsigned long pgsizes;unsigned int dma_max_mappings;bool dirty_pages_supported; +bool dirty_pages_started;/* Protected by BQL */ QLIST_HEAD(, VFIOGuestIOMMU) giommu_list; QLIST_HEAD(, VFIORamDiscardListener) vrdl_list;QLIST_ENTRY (VFIOContainerBase) next;
hw/vfio/container-base.c +7 -1
@@ -64,13 +64,19 @@ int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, bool start, Error **errp) { VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer); +int ret;if (!bcontainer->dirty_pages_supported) {return 0 ; }g_assert (vioc->set_dirty_page_tracking); -return vioc->set_dirty_page_tracking (bcontainer, start, errp); + ret = vioc->set_dirty_page_tracking (bcontainer, start, errp); +if (!ret) { + bcontainer->dirty_pages_started = start; + } + +return ret; } int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
Signature · 1 line
2.40.1
Re: [PATCH 1/9] vfio/container: Add dirty tracking started flag
Quoted 7 lines · Avihai Horon
Add a flag to VFIOContainerBase that indicates whether dirty tracking has been started for the container or not.
This will be used in the following patches to allow dirty page syncs only if dirty tracking has been started.
Signed-off-by Avihai Horon <[email protected]>
Just a nit below, but it's optional.
Quoted 22 lines
--- include/hw/vfio/vfio-container-base.h | 1 + hw/vfio/container-base.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-)include/hw/vfio/vfio-container-base.h +1
-0@@ -44,6 +44,7 @@ typedef struct VFIOContainerBase {unsigned long pgsizes;unsigned int dma_max_mappings;bool dirty_pages_supported; +bool dirty_pages_started;/* Protected by BQL */ QLIST_HEAD(, VFIOGuestIOMMU) giommu_list; QLIST_HEAD(, VFIORamDiscardListener) vrdl_list;QLIST_ENTRY (VFIOContainerBase) next;hw/vfio/container-base.c +0
-0
hw/vfio/container-base.c int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, · line 72
Quoted 9 lines
hw/vfio/container-base.c +1
-0@@ -64,13 +64,19 @@ int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, bool start, Error **errp) { VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer); +int ret;if (!bcontainer->dirty_pages_supported) {return 0 ; }
It's a nop when no state is changed; don't know if you wanna capture that here. Something like this below now that you track container dirty tracking status:
if (!(bcontainer->dirty_pages_started == start)) {
return 0;
}Quoted 13 lines
hw/vfio/container-base.c +6
-1g_assert (vioc->set_dirty_page_tracking); -return vioc->set_dirty_page_tracking (bcontainer, start, errp); + ret = vioc->set_dirty_page_tracking (bcontainer, start, errp); +if (!ret) { + bcontainer->dirty_pages_started = start; + } + +return ret; }int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
Re: [PATCH 1/9] vfio/container: Add dirty tracking started flag
Quoted 49 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 7 lines · Avihai Horon
Add a flag to VFIOContainerBase that indicates whether dirty tracking has been started for the container or not.
This will be used in the following patches to allow dirty page syncs only if dirty tracking has been started.
Signed-off-by Avihai Horon <[email protected]>Reviewed-by Joao Martins <[email protected]>Just a nit below, but it's optional.
Quoted 22 lines
--- include/hw/vfio/vfio-container-base.h | 1 + hw/vfio/container-base.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-)include/hw/vfio/vfio-container-base.h +1
-0@@ -44,6 +44,7 @@ typedef struct VFIOContainerBase {unsigned long pgsizes;unsigned int dma_max_mappings;bool dirty_pages_supported; +bool dirty_pages_started;/* Protected by BQL */ QLIST_HEAD(, VFIOGuestIOMMU) giommu_list; QLIST_HEAD(, VFIORamDiscardListener) vrdl_list;QLIST_ENTRY (VFIOContainerBase) next;hw/vfio/container-base.c +0
-0hw/vfio/container-base.c int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, · line 72
Quoted 9 lines
hw/vfio/container-base.c +1
-0@@ -64,13 +64,19 @@ int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, bool start, Error **errp) { VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer); +int ret;if (!bcontainer->dirty_pages_supported) {return 0 ; }It's a nop when no state is changed; don't know if you wanna capture that here. Something like this below now that you track container dirty tracking status:
Quoted 3 lines
if (!(bcontainer->dirty_pages_started == start)) {
return 0;
}I guess you mean:
if (bcontainer->dirty_pages_started == start) {
return 0;
}
Yes, I can add it.
Thanks!
Quoted 12 lines
Quoted 12 lines
hw/vfio/container-base.c +6
-1g_assert (vioc->set_dirty_page_tracking); -return vioc->set_dirty_page_tracking (bcontainer, start, errp); + ret = vioc->set_dirty_page_tracking (bcontainer, start, errp); +if (!ret) { + bcontainer->dirty_pages_started = start; + } + +return ret; } int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
PATCH 2/9 vfio/migration: Refactor vfio_devices_all_dirty_tracking() logic
In reply to Avihai HoronDuring dirty page log sync, vfio_devices_all_dirty_tracking() is used to check if dirty tracking has been started in order to avoid errors. The current logic checks if migration is in ACTIVE or DEVICE states to ensure dirty tracking has been started.
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_dirty_tracking() logic so it won't use migration_is_active() and migration_is_device(). Instead, use internal VFIO dirty tracking flags.
--- hw/vfio/common.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
hw/vfio/common.c +20 -1
@@ -170,11 +170,30 @@ bool vfio_device_state_is_precopy(VFIODevice *vbasedev) migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY_P2P ; } +static bool vfio_devices_all_device_dirty_tracking_started ( +const VFIOContainerBase *bcontainer) +{ +VFIODevice *vbasedev; + + QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { +if (!vbasedev->dirty_tracking) { +return false; + } + } + +return true; +} +static bool vfio_devices_all_dirty_tracking (VFIOContainerBase *bcontainer) {VFIODevice *vbasedev; -if (!migration_is_active () && !migration_is_device ()) { +if (!migration_is_running ()) { +return false; + } + +if (!(vfio_devices_all_device_dirty_tracking_started (bcontainer) || + bcontainer->dirty_pages_started)) {return false; }
Signature · 1 line
2.40.1
Re: [PATCH 2/9] vfio/migration: Refactor vfio_devices_all_dirty_tracking() logic
Quoted 5 lines · Avihai Horon
During dirty page log sync,
vfio_devices_all_dirty_tracking()is used to check if dirty tracking has been started in order to avoid errors. The current logic checks if migration is in ACTIVE or DEVICE states to ensure dirty tracking has been started.
Quoted 8 lines
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_dirty_tracking()logic so it won't usemigration_is_active()andmigration_is_device(). Instead, use internal VFIO dirty tracking flags.Signed-off-by Avihai Horon <[email protected]>
The refactor itself is fine except a pre-existing bug:
Quoted 25 lines
--- hw/vfio/common.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)hw/vfio/common.c +13
-0@@ -170,11 +170,30 @@ bool vfio_device_state_is_precopy(VFIODevice *vbasedev) migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY_P2P ; } +static bool vfio_devices_all_device_dirty_tracking_started ( +const VFIOContainerBase *bcontainer) +{ +VFIODevice *vbasedev; + + QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { +if (!vbasedev->dirty_tracking) { +return false; + } + } + +return true; +}
hw/vfio/common.c bool vfio_device_state_is_precopy(VFIODevice *vbasedev) · line 194
Quoted 10 lines
hw/vfio/common.c +5
-1+static bool vfio_devices_all_dirty_tracking (VFIOContainerBase *bcontainer) {VFIODevice *vbasedev; -if (!migration_is_active () && !migration_is_device ()) { +if (!migration_is_running ()) { +return false; + } +
Tieing to migration status means that non-KVM dirty trackers cannot be toggled unless somebody starts migration. When really your original intention behind commit ff180c6bd7 ("vfio/migration: Skip log_sync during migration SETUP state") was to avoid the setup state when you are indeed during a migration.
Now you can actually start/sync/stop dirty trackers without migration when you use calc-dirty-rate which is immensely useful to draw out how active a VM prior to starting migration.
The fix is simple and would be to flex the condition to be something like:
/* Migration status is 'none' with calc-dirty-rate */
if (!migration_is_none() && !migration_is_running()) {
return false;
}This is ortoghonal to your series of course, but given you are skimming around this area, sounded like a good idea to raise this. This patch below is what I had plan to send when the development window started, but this was before folks wanted to unexport migration status helpers. What would be the alternative idea forward?
-------------------->8---------------------
From ace22f29a0547353e4ed5a0db53292a77f79fa81 Mon Sep 17 00:00:00 2001
From: Joao Martins <[email protected]>
Date: Wed, 9 Oct 2024 00:27:46 +0100
Subject: [PATCH] vfio/migration: Allow dirty tracking reports with
MIGRATION_STATUS_NONE
Invoking calc-dirty-rate HMP/QMP method queries the VM dirty rate without starting a live migration, which is useful e.g. to understand how active guests are and even for testing purposes. calc-dirty-rate asks the dirty rate from the VM and it's not restricted to a particular dirty tracker.
However commit ff180c6bd7 ("vfio/migration: Skip log_sync during migration SETUP state")
didn't consider this and currently restricts that VF/IOMMU dirty info when migration is active to allow it to be skipped during SETUP stage.
The vfio dirty tracker is already started, the reports are just skipped based on migration status. So change vfio_devices_all_dirty_tracking() such that we include MIGRATION_STATUS_NONE to cover calc-dirty-rate case.
--- hw/vfio/common.c | 4 +++- include/migration/misc.h | 1 + migration/migration.c | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-)
hw/vfio/common.c +0 -0
@@ -174,7 +174,9 @@ static bool
vfio_devices_all_dirty_tracking(VFIOContainerBase *bcontainer)
{
VFIODevice *vbasedev;- if (!migration_is_active() && !migration_is_device()) {
+ /* Migration status is 'none' with calc-dirty-rate */
+ if (!migration_is_none() &&
+ !migration_is_active() && !migration_is_device()) {
return false;
}include/migration/misc.h +1 -0
@@ -53,6 +53,7 @@ void dump_vmstate_json_to_file(FILE *out_fp);void migration_object_init (void );void migration_shutdown (void ); +bool migration_is_none (void );bool migration_is_active (void );bool migration_is_device (void );bool migration_is_running (void );
migration/migration.c +7 -0
@@ -1637,6 +1637,13 @@ bool migration_in_bg_snapshot(void)return migrate_background_snapshot () &&migration_is_running (); } +bool migration_is_none (void ) +{ +MigrationState *s = current_migration; + +return s->state ==MIGRATION_STATUS_NONE ; +} +bool migration_is_active (void ) {MigrationState *s = current_migration;
--
2.39.3
Re: [PATCH 2/9] vfio/migration: Refactor vfio_devices_all_dirty_tracking() logic
Quoted 114 lines · Joao Martins
Quoted 5 lines · Avihai Horon
During dirty page log sync,
vfio_devices_all_dirty_tracking()is used to check if dirty tracking has been started in order to avoid errors. The current logic checks if migration is in ACTIVE or DEVICE states to ensure dirty tracking has been started.Quoted 8 lines
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_dirty_tracking()logic so it won't usemigration_is_active()andmigration_is_device(). Instead, use internal VFIO dirty tracking flags.Signed-off-by Avihai Horon <[email protected]>The refactor itself is fine except a pre-existing bug:
Reviewed-by Joao Martins <[email protected]>Quoted 25 lines
--- hw/vfio/common.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)hw/vfio/common.c +13
-0@@ -170,11 +170,30 @@ bool vfio_device_state_is_precopy(VFIODevice *vbasedev) migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY_P2P ; } +static bool vfio_devices_all_device_dirty_tracking_started ( +const VFIOContainerBase *bcontainer) +{ +VFIODevice *vbasedev; + + QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { +if (!vbasedev->dirty_tracking) { +return false; + } + } + +return true; +}hw/vfio/common.c bool vfio_device_state_is_precopy(VFIODevice *vbasedev) · line 194
Quoted 10 lines
hw/vfio/common.c +5
-1+static bool vfio_devices_all_dirty_tracking (VFIOContainerBase *bcontainer) {VFIODevice *vbasedev; -if (!migration_is_active () && !migration_is_device ()) { +if (!migration_is_running ()) { +return false; + } +Tieing to migration status means that non-KVM dirty trackers cannot be toggled unless somebody starts migration. When really your original intention behind commit
ff180c6bd7("vfio/migration: Skiplog_syncduring migration SETUP state") was to avoid the setup state when you are indeed during a migration.Now you can actually start/sync/stop dirty trackers without migration when you use calc-dirty-rate which is immensely useful to draw out how active a VM prior to starting migration.
The fix is simple and would be to flex the condition to be something like:
/* Migration status is 'none' with calc-dirty-rate */ if (!migration_is_none() && !migration_is_running()) { return false; }This is ortoghonal to your series of course, but given you are skimming around this area, sounded like a good idea to raise this. This patch below is what I had plan to send when the development window started, but this was before folks wanted to unexport migration status helpers. What would be the alternative idea forward?
-------------------->8---------------------
From
ace22f29a0547353e4ed5a0db53292a77f79fa81Mon Sep 17 00:00:00 2001
From: Joao Martins <[email protected]>
Date: Wed, 9 Oct 2024 00:27:46 +0100
Subject: [PATCH] vfio/migration: Allow dirty tracking reports with
MIGRATION_STATUS_NONEInvoking calc-dirty-rate HMP/QMP method queries the VM dirty rate without starting a live migration, which is useful e.g. to understand how active guests are and even for testing purposes. calc-dirty-rate asks the dirty rate from the VM and it's not restricted to a particular dirty tracker.
However commit
ff180c6bd7("vfio/migration: Skiplog_syncduring migration SETUP state")
didn't consider this and currently restricts that VF/IOMMU dirty info when migration is active to allow it to be skipped during SETUP stage.The vfio dirty tracker is already started, the reports are just skipped based on migration status. So change
vfio_devices_all_dirty_tracking()such that we includeMIGRATION_STATUS_NONEto cover calc-dirty-rate case.Fixes ff180c6bd7 ("vfio/migration: Skip log_sync during migration SETUP state")Signed-off-by Joao Martins <[email protected]>--- hw/vfio/common.c | 4 +++- include/migration/misc.h | 1 + migration/migration.c | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-)hw/vfio/common.c +0
-0
hw/vfio/common.c static bool · line 182
Quoted 10 lines
hw/vfio/common.c +3
-1@@ -174,7 +174,9 @@ static bool vfio_devices_all_dirty_tracking(VFIOContainerBase *bcontainer) {VFIODevice *vbasedev; -if (!migration_is_active () && !migration_is_device ()) { +/* Migration status is 'none' with calc-dirty-rate */ +if (!migration_is_none () && + !migration_is_active () && !migration_is_device ()) {return false; }
NB: The patch is obviously incomplete given that I missed the check in vfio_devices_all_running_and_mig_active()
Quoted 32 lines
include/migration/misc.h +1
-0@@ -53,6 +53,7 @@ void dump_vmstate_json_to_file(FILE *out_fp);void migration_object_init (void );void migration_shutdown (void ); +bool migration_is_none (void );bool migration_is_active (void );bool migration_is_device (void );bool migration_is_running (void );migration/migration.c +7
-1@@ -1637,6 +1637,13 @@ bool migration_in_bg_snapshot(void)return migrate_background_snapshot () &&migration_is_running (); } +bool migration_is_none (void ) +{ +MigrationState *s = current_migration; + +return s->state ==MIGRATION_STATUS_NONE ; +} +bool migration_is_active (void ) {MigrationState *s = current_migration; --2.39.3
Re: [PATCH 2/9] vfio/migration: Refactor vfio_devices_all_dirty_tracking() logic
In reply to Joao MartinsQuoted 51 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 5 lines · Avihai Horon
During dirty page log sync,
vfio_devices_all_dirty_tracking()is used to check if dirty tracking has been started in order to avoid errors. The current logic checks if migration is in ACTIVE or DEVICE states to ensure dirty tracking has been started.Quoted 8 lines
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_dirty_tracking()logic so it won't usemigration_is_active()andmigration_is_device(). Instead, use internal VFIO dirty tracking flags.Signed-off-by Avihai Horon <[email protected]>The refactor itself is fine except a pre-existing bug:
Reviewed-by Joao Martins <[email protected]>Quoted 30 lines
--- hw/vfio/common.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)hw/vfio/common.c +14
-0@@ -170,11 +170,30 @@ bool vfio_device_state_is_precopy(VFIODevice *vbasedev) migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY_P2P ; } +static bool vfio_devices_all_device_dirty_tracking_started ( +const VFIOContainerBase *bcontainer) +{ +VFIODevice *vbasedev; + + QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { +if (!vbasedev->dirty_tracking) { +return false; + } + } + +return true; +} +static bool vfio_devices_all_dirty_tracking (VFIOContainerBase *bcontainer) {VFIODevice *vbasedev;
Quoted 9 lines
hw/vfio/common.c bool vfio_device_state_is_precopy(VFIODevice *vbasedev) · line 194
Quoted 5 lines
hw/vfio/common.c +4
-1-if (!migration_is_active () && !migration_is_device ()) { +if (!migration_is_running ()) { +return false; + } +Tieing to migration status means that non-KVM dirty trackers cannot be toggled unless somebody starts migration. When really your original intention behind commit
ff180c6bd7("vfio/migration: Skiplog_syncduring migration SETUP state") was to avoid the setup state when you are indeed during a migration.
It was tied to migration even prior to this commit, as VFIO log syncs were restricted to run only during migration (we had "if (!migration_is_setup_or_active())" check). This commit only narrowed it down further to not run during SETUP.
Quoted 12 lines
Now you can actually start/sync/stop dirty trackers without migration when you use calc-dirty-rate which is immensely useful to draw out how active a VM prior to starting migration.
The fix is simple and would be to flex the condition to be something like:
/* Migration status is 'none' with calc-dirty-rate */ if (!migration_is_none() && !migration_is_running()) { return false; }
Quoted 4 lines
This is ortoghonal to your series of course, but given you are skimming around this area, sounded like a good idea to raise this. This patch below is what I had plan to send when the development window started, but this was before folks wanted to unexport migration status helpers.
I remember you had several patches that formally added VFIO DPT to calc-dirty-rate (with a new "-d" QMP parameter and everything). Are you still planning to send these?
Quoted 2 lines
What would be the alternative idea
forward?
Now we have an internal VFIO flag to indicate dirty tracking status, so that's one thing we can rely on. And we can also use the global dirty tracking flags in include/exec/memory.h:
/* Possible bits for global_dirty_log_{start|stop} */
/* Dirty tracking enabled because migration is running */ #define GLOBAL_DIRTY_MIGRATION (1U << 0)
/* Dirty tracking enabled because measuring dirty rate */ #define GLOBAL_DIRTY_DIRTY_RATE (1U << 1)
/* Dirty tracking enabled because dirty limit */ #define GLOBAL_DIRTY_LIMIT (1U << 2)
#define GLOBAL_DIRTY_MASK (0x7)
extern unsigned int global_dirty_tracking;
So I guess we can add some helpers to access global_dirty_tracking and use them in VFIO to decide when to allow log sync.
But as you wrote, I think that's orthogonal to this series.
Thanks.
Quoted 80 lines
-------------------->8---------------------
From
ace22f29a0547353e4ed5a0db53292a77f79fa81Mon Sep 17 00:00:00 2001
From: Joao Martins <[email protected]>
Date: Wed, 9 Oct 2024 00:27:46 +0100
Subject: [PATCH] vfio/migration: Allow dirty tracking reports with
MIGRATION_STATUS_NONEInvoking calc-dirty-rate HMP/QMP method queries the VM dirty rate without starting a live migration, which is useful e.g. to understand how active guests are and even for testing purposes. calc-dirty-rate asks the dirty rate from the VM and it's not restricted to a particular dirty tracker.
However commit
ff180c6bd7("vfio/migration: Skiplog_syncduring migration SETUP state")
didn't consider this and currently restricts that VF/IOMMU dirty info when migration is active to allow it to be skipped during SETUP stage.The vfio dirty tracker is already started, the reports are just skipped based on migration status. So change
vfio_devices_all_dirty_tracking()such that we includeMIGRATION_STATUS_NONEto cover calc-dirty-rate case.Fixes ff180c6bd7 ("vfio/migration: Skip log_sync during migration SETUP state")Signed-off-by Joao Martins <[email protected]>--- hw/vfio/common.c | 4 +++- include/migration/misc.h | 1 + migration/migration.c | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-)hw/vfio/common.c +3
-1@@ -174,7 +174,9 @@ static bool vfio_devices_all_dirty_tracking(VFIOContainerBase *bcontainer) {VFIODevice *vbasedev; -if (!migration_is_active () && !migration_is_device ()) { +/* Migration status is 'none' with calc-dirty-rate */ +if (!migration_is_none () && + !migration_is_active () && !migration_is_device ()) {return false; }include/migration/misc.h +1
-0@@ -53,6 +53,7 @@ void dump_vmstate_json_to_file(FILE *out_fp);void migration_object_init (void );void migration_shutdown (void ); +bool migration_is_none (void );bool migration_is_active (void );bool migration_is_device (void );bool migration_is_running (void );migration/migration.c +7
-1@@ -1637,6 +1637,13 @@ bool migration_in_bg_snapshot(void)return migrate_background_snapshot () &&migration_is_running (); } +bool migration_is_none (void ) +{ +MigrationState *s = current_migration; + +return s->state ==MIGRATION_STATUS_NONE ; +} +bool migration_is_active (void ) {MigrationState *s = current_migration; --2.39.3
Re: [PATCH 2/9] vfio/migration: Refactor vfio_devices_all_dirty_tracking() logic
Quoted 63 lines · Avihai Horon
Quoted 51 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 5 lines · Avihai Horon
During dirty page log sync,
vfio_devices_all_dirty_tracking()is used to check if dirty tracking has been started in order to avoid errors. The current logic checks if migration is in ACTIVE or DEVICE states to ensure dirty tracking has been started.Quoted 8 lines
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_dirty_tracking()logic so it won't usemigration_is_active()andmigration_is_device(). Instead, use internal VFIO dirty tracking flags.Signed-off-by Avihai Horon <[email protected]>The refactor itself is fine except a pre-existing bug:
Reviewed-by Joao Martins <[email protected]>Quoted 30 lines
---
hw/vfio/common.c| 21 ++++++++++++++++++++-1 file changed, 20 insertions(+), 1 deletion(-)hw/vfio/common.c +14
-0@@ -170,11 +170,30 @@ bool vfio_device_state_is_precopy(VFIODevice *vbasedev) migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P; } +static bool vfio_devices_all_device_dirty_tracking_started ( + const VFIOContainerBase *bcontainer) +{ + VFIODevice *vbasedev; + + QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { + if (!vbasedev->dirty_tracking) { + return false; + } + } + + return true; +} + static bool vfio_devices_all_dirty_tracking(VFIOContainerBase *bcontainer) { VFIODevice *vbasedev;Quoted 9 lines
hw/vfio/common.c bool vfio_device_state_is_precopy(VFIODevice *vbasedev) · line 194
Quoted 5 lines
hw/vfio/common.c +4
-1- if (!migration_is_active() && !migration_is_device()) { + if (!migration_is_running()) { + return false; + } +Tieing to migration status means that non-KVM dirty trackers cannot be toggled unless somebody starts migration. When really your original intention behind commit
ff180c6bd7("vfio/migration: Skiplog_syncduring migration SETUP state") was to avoid the setup state when you are indeed during a migration.
Quoted 5 lines
It was tied to migration even prior to this commit, as VFIO log syncs were restricted to run only during migration (we had "if (!
migration_is_setup_or_active())" check).
This commit only narrowed it down further to not run during SETUP.
Ok, good point.
Btw you are regressing from that behaviour with this change above, because if migration has state MIGRATION_STATUS_SETUP and migration_is_running() will return true and so you will log dirty pages.
Quoted 12 lines
Quoted 12 lines
Now you can actually start/sync/stop dirty trackers without migration when you use calc-dirty-rate which is immensely useful to draw out how active a VM prior to starting migration.
The fix is simple and would be to flex the condition to be something like:
/* Migration status is 'none' with calc-dirty-rate */ if (!migration_is_none() && !migration_is_running()) { return false;
}
Quoted 9 lines
Quoted 4 lines
This is ortoghonal to your series of course, but given you are skimming around this area, sounded like a good idea to raise this. This patch below is what I had plan to send when the development window started, but this was before folks wanted to unexport migration status helpers.
I remember you had several patches that formally added VFIO DPT to calc-dirty- rate (with a new "-d" QMP parameter and everything).
Are you still planning to send these?
calc-dirty-rate *implicitly* just logs KVM pages, but in theory it should be ortoghonal to any dirty tracker that is able to log pages. So in that line of thought it should be logging pages from all dirty trackers in use.
To actually include all dirty tracking data and while fix the performance issue to not account for setup migration state then the check is a simple condition for SETUP state *if* where's a migration started *or* no migration started at all.
I don't think the VF dirty trackers steer the data based on migration -- VFIO seems to be the only one IIUC. Hence fixing calc-dirty-rate seemed more accurate in my point of view, and optionally we could restrict scope of dirty tracking as a bonus
Quoted 18 lines
Quoted 2 lines
What would be the alternative idea
forward?Now we have an internal VFIO flag to indicate dirty tracking status, so that's one thing we can rely on.
And we can also use the global dirty tracking flags ininclude/exec/memory.h:/* Possible bits for global_dirty_log_{start|stop} */
/* Dirty tracking enabled because migration is running */ #define GLOBAL_DIRTY_MIGRATION (1U << 0)
/* Dirty tracking enabled because measuring dirty rate */ #define
GLOBAL_DIRTY_DIRTY_RATE(1U << 1)/* Dirty tracking enabled because dirty limit */ #define GLOBAL_DIRTY_LIMIT (1U << 2)
Quoted 9 lines
#define GLOBAL_DIRTY_MASK (
0x7)extern unsigned int
global_dirty_tracking;So I guess we can add some helpers to access
global_dirty_trackingand use them in VFIO to decide when to allow log sync.But as you wrote, I think that's orthogonal to this series.
Right I also had sketched it like this to reduce the scope of dirty tracking.
This problem preceeds your setup fix so don't wanna go offtopic. Anyway just wanted to understanding how migration status is going to be exported to see what's the way forward for that.
Quoted 83 lines
Thanks.
Quoted 81 lines
-------------------->8---------------------
From
ace22f29a0547353e4ed5a0db53292a77f79fa81Mon Sep 17 00:00:00 2001
From: Joao Martins <[email protected]>
Date: Wed, 9 Oct 2024 00:27:46 +0100
Subject: [PATCH] vfio/migration: Allow dirty tracking reports withMIGRATION_STATUS_NONEInvoking calc-dirty-rate HMP/QMP method queries the VM dirty rate without starting a live migration, which is useful e.g. to understand how active guests are and even for testing purposes. calc-dirty-rate asks the dirty rate from the VM and it's not restricted to a particular dirty tracker.
However commit
ff180c6bd7("vfio/migration: Skiplog_syncduring migration SETUP state")
didn't consider this and currently restricts that VF/IOMMU dirty info when migration
is active to allow it to be skipped during SETUP stage.The vfio dirty tracker is already started, the reports are just skipped based on migration status. So change
vfio_devices_all_dirty_tracking()such that we includeMIGRATION_STATUS_NONEto cover calc-dirty-rate case.Fixes ff180c6bd7 ("vfio/migration: Skip log_sync during migration SETUP state")Signed-off-by Joao Martins <[email protected]>---
hw/vfio/common.c | 4 +++-
include/migration/misc.h| 1 +
migration/migration.c | 7 +++++++3 files changed, 11 insertions(+), 1 deletion(-)hw/vfio/common.c +3
-1@@ -174,7 +174,9 @@ static boolvfio_devices_all_dirty_tracking (VFIOContainerBase *bcontainer) { VFIODevice *vbasedev; - if (!migration_is_active() && !migration_is_device()) { + /* Migration status is 'none' with calc-dirty-rate */ + if (!migration_is_none() && + !migration_is_active() && !migration_is_device()) { return false; }include/migration/misc.h +1
-0@@ -53,6 +53,7 @@ void dump_vmstate_json_to_file(FILE *out_fp); void migration_object_init(void); void migration_shutdown(void); +bool migration_is_none (void ); bool migration_is_active(void); bool migration_is_device(void); bool migration_is_running(void);migration/migration.c +7
-0@@ -1637,6 +1637,13 @@ bool migration_in_bg_snapshot(void) return migrate_background_snapshot() && migration_is_running(); } +bool migration_is_none (void ) +{ + MigrationState *s = current_migration; + + return s->state == MIGRATION_STATUS_NONE; +} + bool migration_is_active(void) { MigrationState *s = current_migration;Signature · 1 line
2.39.3
Re: [PATCH 2/9] vfio/migration: Refactor vfio_devices_all_dirty_tracking() logic
Quoted 70 lines · Joao Martins
Quoted 63 lines · Avihai Horon
Quoted 51 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 5 lines · Avihai Horon
During dirty page log sync,
vfio_devices_all_dirty_tracking()is used to check if dirty tracking has been started in order to avoid errors. The current logic checks if migration is in ACTIVE or DEVICE states to ensure dirty tracking has been started.Quoted 8 lines
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_dirty_tracking()logic so it won't usemigration_is_active()andmigration_is_device(). Instead, use internal VFIO dirty tracking flags.Signed-off-by Avihai Horon <[email protected]>The refactor itself is fine except a pre-existing bug:
Reviewed-by Joao Martins <[email protected]>Quoted 30 lines
---
hw/vfio/common.c| 21 ++++++++++++++++++++-1 file changed, 20 insertions(+), 1 deletion(-)hw/vfio/common.c +14
-0@@ -170,11 +170,30 @@ bool vfio_device_state_is_precopy(VFIODevice *vbasedev) migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P; } +static bool vfio_devices_all_device_dirty_tracking_started ( + const VFIOContainerBase *bcontainer) +{ + VFIODevice *vbasedev; + + QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { + if (!vbasedev->dirty_tracking) { + return false; + } + } + + return true; +} + static bool vfio_devices_all_dirty_tracking(VFIOContainerBase *bcontainer) { VFIODevice *vbasedev;Quoted 9 lines
hw/vfio/common.c bool vfio_device_state_is_precopy(VFIODevice *vbasedev) · line 194
Quoted 5 lines
hw/vfio/common.c +4
-1- if (!migration_is_active() && !migration_is_device()) { + if (!migration_is_running()) { + return false; + } +Tieing to migration status means that non-KVM dirty trackers cannot be toggled unless somebody starts migration. When really your original intention behind commit
ff180c6bd7("vfio/migration: Skiplog_syncduring migration SETUP state") was to avoid the setup state when you are indeed during a migration.Quoted 5 lines
It was tied to migration even prior to this commit, as VFIO log syncs were restricted to run only during migration (we had "if (!
migration_is_setup_or_active())" check).
This commit only narrowed it down further to not run during SETUP.
Quoted 6 lines
Ok, good point.
Btw you are regressing from that behaviour with this change above, because if migration has state
MIGRATION_STATUS_SETUPandmigration_is_running()will return true and so you will log dirty pages.
Nevermind this comment.
Just noticed that it was the point of the whole thread:
https://lore.kernel.org/qemu-devel/[email protected]/#r
... where you discuss this.
Re: [PATCH 2/9] vfio/migration: Refactor vfio_devices_all_dirty_tracking() logic
Quoted 78 lines · Joao Martins
Quoted 70 lines · Joao Martins
Quoted 63 lines · Avihai Horon
Quoted 51 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 5 lines · Avihai Horon
During dirty page log sync,
vfio_devices_all_dirty_tracking()is used to check if dirty tracking has been started in order to avoid errors. The current logic checks if migration is in ACTIVE or DEVICE states to ensure dirty tracking has been started.Quoted 8 lines
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_dirty_tracking()logic so it won't usemigration_is_active()andmigration_is_device(). Instead, use internal VFIO dirty tracking flags.Signed-off-by Avihai Horon <[email protected]>The refactor itself is fine except a pre-existing bug:
Reviewed-by Joao Martins <[email protected]>Quoted 30 lines
---
hw/vfio/common.c| 21 ++++++++++++++++++++-1 file changed, 20 insertions(+), 1 deletion(-)hw/vfio/common.c +14
-0@@ -170,11 +170,30 @@ bool vfio_device_state_is_precopy(VFIODevice *vbasedev) migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P; } +static bool vfio_devices_all_device_dirty_tracking_started ( + const VFIOContainerBase *bcontainer) +{ + VFIODevice *vbasedev; + + QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { + if (!vbasedev->dirty_tracking) { + return false; + } + } + + return true; +} + static bool vfio_devices_all_dirty_tracking(VFIOContainerBase *bcontainer) { VFIODevice *vbasedev;Quoted 9 lines
hw/vfio/common.c bool vfio_device_state_is_precopy(VFIODevice *vbasedev) · line 194
Quoted 5 lines
hw/vfio/common.c +4
-1- if (!migration_is_active() && !migration_is_device()) { + if (!migration_is_running()) { + return false; + } +Tieing to migration status means that non-KVM dirty trackers cannot be toggled unless somebody starts migration. When really your original intention behind commit
ff180c6bd7("vfio/migration: Skiplog_syncduring migration SETUP state") was to avoid the setup state when you are indeed during a migration.Quoted 5 lines
It was tied to migration even prior to this commit, as VFIO log syncs were restricted to run only during migration (we had "if (!
migration_is_setup_or_active())" check).
This commit only narrowed it down further to not run during SETUP.Quoted 6 lines
Ok, good point.
Btw you are regressing from that behaviour with this change above, because if migration has state
MIGRATION_STATUS_SETUPandmigration_is_running()will return true and so you will log dirty pages.
Quoted 8 lines
Nevermind this comment.
Just noticed that it was the point of the whole thread:
https://lore.kernel.org/qemu-devel/[email protected]/#r
... where you discuss this.
Actually, from the thread quoted in the cover letter[0], at the end of this series we rely on status of dirty tracking to go ahead with the syncs instead of relying on migration running or not.
Hence just removing migration_is_running() calls wouldn't regress the bug you fixed with commit ff180c6bd7, neither calc-dirty-rate would miss dirty data from its reports.
Re: [PATCH 2/9] vfio/migration: Refactor vfio_devices_all_dirty_tracking() logic
Quoted 84 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 80 lines · Joao Martins
Quoted 67 lines · Joao Martins
Quoted 61 lines · Avihai Horon
Quoted 51 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 5 lines · Avihai Horon
During dirty page log sync,
vfio_devices_all_dirty_tracking()is used to check if dirty tracking has been started in order to avoid errors. The current logic checks if migration is in ACTIVE or DEVICE states to ensure dirty tracking has been started.Quoted 8 lines
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_dirty_tracking()logic so it won't usemigration_is_active()andmigration_is_device(). Instead, use internal VFIO dirty tracking flags.Signed-off-by Avihai Horon <[email protected]>The refactor itself is fine except a pre-existing bug:
Reviewed-by Joao Martins <[email protected]>Quoted 30 lines
--- hw/vfio/common.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)hw/vfio/common.c +14
-0@@ -170,11 +170,30 @@ bool vfio_device_state_is_precopy(VFIODevice *vbasedev) migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY_P2P ; } +static bool vfio_devices_all_device_dirty_tracking_started ( +const VFIOContainerBase *bcontainer) +{ +VFIODevice *vbasedev; + + QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { +if (!vbasedev->dirty_tracking) { +return false; + } + } + +return true; +} +static bool vfio_devices_all_dirty_tracking (VFIOContainerBase *bcontainer) {VFIODevice *vbasedev;Quoted 9 lines
hw/vfio/common.c bool vfio_device_state_is_precopy(VFIODevice *vbasedev) · line 194
Quoted 5 lines
hw/vfio/common.c +4
-1-if (!migration_is_active () && !migration_is_device ()) { +if (!migration_is_running ()) { +return false; + } +Tieing to migration status means that non-KVM dirty trackers cannot be toggled unless somebody starts migration. When really your original intention behind commit
ff180c6bd7("vfio/migration: Skiplog_syncduring migration SETUP state") was to avoid the setup state when you are indeed during a migration.Quoted 5 lines
It was tied to migration even prior to this commit, as VFIO log syncs were restricted to run only during migration (we had "if (!
migration_is_setup_or_active())" check).
This commit only narrowed it down further to not run during SETUP.Quoted 6 lines
Ok, good point.
Btw you are regressing from that behaviour with this change above, because if migration has state
MIGRATION_STATUS_SETUPandmigration_is_running()will return true and so you will log dirty pages.Nevermind this comment.
Just noticed that it was the point of the whole thread:
Quoted 8 lines
Quoted 2 lines
... where you discuss this.
Actually, from the thread quoted in the cover letter[0], at the end of this series we rely on status of dirty tracking to go ahead with the syncs instead of relying on migration running or not.
Hence just removingmigration_is_running()calls wouldn't regress the bug you fixed with commitff180c6bd7, neither calc-dirty-rate would miss dirty data from its reports.
Right.
But since it was previously tied to migration and because I remembered you had the calc-dirty-rate series that also added the -d param to control the scope of dirty rate, I thought I should only stick to refactoring for the migration status API simplification and that the calc-dirty-rate series would come after.
But if we simply want to include VFIO DPT in calc-dirty-rate, then yes, I can untie it from migration in v2.
Quoted 2 lines
PATCH 3/9 vfio/migration: Refactor vfio_devices_all_running_and_mig_active() logic
In reply to Avihai HoronDuring 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 modifying the logic to check if migration is running and dirty tracking has been started. This should be equivalent to the previous logic because when the guest is stopped there shouldn't be DMA unmaps coming from it. Also rename the function properly.
--- include/hw/vfio/vfio-common.h | 3 +-- hw/vfio/common.c | 28 ++++------------------------ hw/vfio/container.c | 2 +- 3 files changed, 6 insertions(+), 27 deletions(-)
include/hw/vfio/vfio-common.h +1 -2
@@ -296,8 +296,7 @@ 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_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer);bool vfio_devices_all_device_dirty_tracking (const VFIOContainerBase *bcontainer); int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
hw/vfio/common.c +4 -24
@@ -229,34 +229,14 @@ 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) +bool vfio_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer) { -VFIODevice *vbasedev; - -if (!migration_is_active ()) { +if (!migration_is_running ()) {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; +return vfio_devices_all_device_dirty_tracking_started (bcontainer) || + bcontainer->dirty_pages_started; }static bool vfio_listener_skipped_section (MemoryRegionSection *section)
hw/vfio/container.c +1 -1
@@ -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_dma_unmap_dirty_sync_needed (bcontainer)) {if (!vfio_devices_all_device_dirty_tracking (bcontainer) && bcontainer->dirty_pages_supported) {return vfio_dma_unmap_bitmap (container, iova, size, iotlb);
Signature · 1 line
2.40.1
Re: [PATCH 3/9] vfio/migration: Refactor vfio_devices_all_running_and_mig_active() logic
Quoted 64 lines · Avihai Horon
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 usemigration_is_active().Do it by modifying the logic to check if migration is running and dirty tracking has been started. This should be equivalent to the previous logic because when the guest is stopped there shouldn't be DMA unmaps coming from it. Also rename the function properly.
Signed-off-by Avihai Horon <[email protected]>--- include/hw/vfio/vfio-common.h | 3 +-- hw/vfio/common.c | 28 ++++------------------------ hw/vfio/container.c | 2 +- 3 files changed, 6 insertions(+), 27 deletions(-)include/hw/vfio/vfio-common.h +1
-2@@ -296,8 +296,7 @@ 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_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer);bool vfio_devices_all_device_dirty_tracking (const VFIOContainerBase *bcontainer); int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,hw/vfio/common.c +2
-12@@ -229,34 +229,14 @@ 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) +bool vfio_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer) { -VFIODevice *vbasedev; - -if (!migration_is_active ()) { +if (!migration_is_running ()) {return false; } - QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { -VFIOMigration *migration = vbasedev->migration; -
hw/vfio/common.c bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer) · line 257
Quoted 10 lines
hw/vfio/common.c +0
-10-if (!migration) { -return false; - } - -if (vfio_device_state_is_running (vbasedev) || -vfio_device_state_is_precopy (vbasedev)) { -continue ; - }else { -return false; - }
Functionally the change implies that even if non-migratable VFIO devices behind IOMMUs with dirty tracking would still sync DMA bitmap. I think this is OK as it increases the coverage for calc-dirty-rate (provided my comment in an earlier patch) such that if you try to get a dirty rate included the IOMMU invalidations marking the bits accordingly.
Just stating the obvious in case this was non intended.
Quoted 12 lines
hw/vfio/common.c +2
-2- } -return true; +return vfio_devices_all_device_dirty_tracking_started (bcontainer) || + bcontainer->dirty_pages_started; }static bool vfio_listener_skipped_section (MemoryRegionSection *section)hw/vfio/container.c +0
-0
hw/vfio/container.c static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer, · line 137
Quoted 8 lines
hw/vfio/container.c +1
-1@@ -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_dma_unmap_dirty_sync_needed (bcontainer)) {if (!vfio_devices_all_device_dirty_tracking (bcontainer) && bcontainer->dirty_pages_supported) {return vfio_dma_unmap_bitmap (container, iova, size, iotlb);
Re: [PATCH 3/9] vfio/migration: Refactor vfio_devices_all_running_and_mig_active() logic
Quoted 75 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 71 lines · Avihai Horon
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 usemigration_is_active().Do it by modifying the logic to check if migration is running and dirty tracking has been started. This should be equivalent to the previous logic because when the guest is stopped there shouldn't be DMA unmaps coming from it. Also rename the function properly.
Signed-off-by Avihai Horon <[email protected]>--- include/hw/vfio/vfio-common.h | 3 +-- hw/vfio/common.c | 28 ++++------------------------ hw/vfio/container.c | 2 +- 3 files changed, 6 insertions(+), 27 deletions(-)include/hw/vfio/vfio-common.h +1
-2@@ -296,8 +296,7 @@ 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_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer);bool vfio_devices_all_device_dirty_tracking (const VFIOContainerBase *bcontainer); int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,hw/vfio/common.c +2
-19@@ -229,34 +229,14 @@ 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) +bool vfio_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer) { -VFIODevice *vbasedev; - -if (!migration_is_active ()) { +if (!migration_is_running ()) {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 ;
Quoted 8 lines
hw/vfio/common.c bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer) · line 257
Quoted 3 lines
hw/vfio/common.c +0
-3- }else { -return false; - }Functionally the change implies that even if non-migratable VFIO devices behind IOMMUs with dirty tracking would still sync DMA bitmap. I think this is OK as it increases the coverage for calc-dirty-rate (provided my comment in an earlier patch) such that if you try to get a dirty rate included the IOMMU invalidations marking the bits accordingly.
We still have the "if (!migration_is_running())" check above, so non-migratable VFIO devices won't sync. But that's a valid point for when we'll allow VFIO log syncs for clac-dirty-rate.
Quoted 18 lines
Just stating the obvious in case this was non intended.
Quoted 15 lines
hw/vfio/common.c +2
-2- } -return true; +return vfio_devices_all_device_dirty_tracking_started (bcontainer) || + bcontainer->dirty_pages_started; }static bool vfio_listener_skipped_section (MemoryRegionSection *section)hw/vfio/container.c +0
-0@@ -131,7 +131,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,int ret;Error *local_err =NULL ;
Quoted 6 lines
hw/vfio/container.c static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer, · line 137
Quoted 5 lines
hw/vfio/container.c +1
-1-if (iotlb &&vfio_devices_all_running_and_mig_active (bcontainer)) { +if (iotlb &&vfio_dma_unmap_dirty_sync_needed (bcontainer)) {if (!vfio_devices_all_device_dirty_tracking (bcontainer) && bcontainer->dirty_pages_supported) {return vfio_dma_unmap_bitmap (container, iova, size, iotlb);Reviewed-by Joao Martins <[email protected]>
Thanks!
Re: [PATCH 3/9] vfio/migration: Refactor vfio_devices_all_running_and_mig_active() logic
Quoted 88 lines · Avihai Horon
Quoted 77 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 73 lines · Avihai Horon
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 usemigration_is_active().Do it by modifying the logic to check if migration is running and dirty tracking has been started. This should be equivalent to the previous logic because when the guest is stopped there shouldn't be DMA unmaps coming from it. Also rename the function properly.
Signed-off-by Avihai Horon <[email protected]>---
include/hw/vfio/vfio-common.h| 3 +-- hw/vfio/common.c | 28 ++++------------------------ hw/vfio/container.c | 2 +-3 files changed, 6 insertions(+), 27 deletions(-)include/hw/vfio/vfio-common.h +1
-2@@ -296,8 +296,7 @@ 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_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer);bool
vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer); int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,hw/vfio/common.c +2
-19@@ -229,34 +229,14 @@ 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) +bool vfio_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer) { - VFIODevice *vbasedev; - - if (!migration_is_active()) { + if (!migration_is_running()) { 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;Quoted 8 lines
hw/vfio/common.c bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer) · line 257
Quoted 3 lines
hw/vfio/common.c +0
-3- } else { - return false; - }Functionally the change implies that even if non-migratable VFIO devices behind IOMMUs with dirty tracking would still sync DMA bitmap. I think this is OK as it increases the coverage for calc-dirty-rate (provided my comment in an earlier patch) such that if you try to get a dirty rate included the IOMMU invalidations marking the bits accordingly.
Quoted 4 lines
We still have the "if (!migration_is_running())" check above, so non-migratable VFIO devices won't sync.
But that's a valid point for when we'll allow VFIO log syncs for clac-dirty-rate.
It's the other way around :) This change helps calc-dirty-rate because you can use it and still account for DMA unmap based dirties.
migration_is_running just stops logs if migration is not running. And that doesn't care about VFIO migation support.
But if migration is running, whether the device supports migration or not... it will still sync for pages. It won't sync if it has no VF dirty tracking, but there's still the container dirty tracker.
Whereby previously, you skip checking all together if the VFIO migration state wasn't initialized and the VF was not in the right VF device-state.
Re: [PATCH 3/9] vfio/migration: Refactor vfio_devices_all_running_and_mig_active() logic
Quoted 94 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 86 lines · Avihai Horon
Quoted 77 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 73 lines · Avihai Horon
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 usemigration_is_active().Do it by modifying the logic to check if migration is running and dirty tracking has been started. This should be equivalent to the previous logic because when the guest is stopped there shouldn't be DMA unmaps coming from it. Also rename the function properly.
Signed-off-by Avihai Horon <[email protected]>--- include/hw/vfio/vfio-common.h | 3 +-- hw/vfio/common.c | 28 ++++------------------------ hw/vfio/container.c | 2 +- 3 files changed, 6 insertions(+), 27 deletions(-)include/hw/vfio/vfio-common.h +1
-2@@ -296,8 +296,7 @@ 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_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer);bool vfio_devices_all_device_dirty_tracking (const VFIOContainerBase *bcontainer);int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
hw/vfio/common.c +2
-19@@ -229,34 +229,14 @@ 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) +bool vfio_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer) { -VFIODevice *vbasedev; - -if (!migration_is_active ()) { +if (!migration_is_running ()) {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 ;Quoted 8 lines
hw/vfio/common.c bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer) · line 257
Quoted 3 lines
hw/vfio/common.c +0
-3- }else { -return false; - }Functionally the change implies that even if non-migratable VFIO devices behind IOMMUs with dirty tracking would still sync DMA bitmap. I think this is OK as it increases the coverage for calc-dirty-rate (provided my comment in an earlier patch) such that if you try to get a dirty rate included the IOMMU invalidations marking the bits accordingly.
Quoted 4 lines
We still have the "if (!migration_is_running())" check above, so non-migratable VFIO devices won't sync.
But that's a valid point for when we'll allow VFIO log syncs for clac-dirty-rate.
Quoted 7 lines
It's the other way around :) This change helps calc-dirty-rate because you can use it and still account for DMA unmap based dirties.
migration_is_runningjust stops logs if migration is not running. And that doesn't care about VFIO migation support.But if migration is running, whether the device supports migration or not...
If the device doesn't support migration then migration can't run, no?
But anyway, as we talked in the other thread, I can untie this from migration and then, as you said above, it may also dirty sync for non-migratable devices which will make calc-dirty-rate more accurate.
Quoted 6 lines
it
will still sync for pages. It won't sync if it has no VF dirty tracking, but there's still the container dirty tracker.Whereby previously, you skip checking all together if the VFIO migration state wasn't initialized and the VF was not in the right VF device-state.
Re: [PATCH 3/9] vfio/migration: Refactor vfio_devices_all_running_and_mig_active() logic
Quoted 37 lines · Avihai Horon
Quoted 37 lines
Quoted 29 lines
Quoted 21 lines
Quoted 21 lines
+bool
vfio_dma_unmap_dirty_sync_needed(const VFIOContainerBase *bcontainer){
- VFIODevice *vbasedev;
-
- if (!migration_is_active()) {
+ if (!migration_is_running()) {
return false;
}-
QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next){ - VFIOMigration *migration =vbasedev->migration;hw/vfio/common.c +0
-10- - if (!migration) { - return false; - } - - if (vfio_device_state_is_running(vbasedev) || - vfio_device_state_is_precopy(vbasedev)) { - continue; - } else { - return false;Quoted 8 lines
Quoted 1 line
- }
Functionally the change implies that even if non-migratable VFIO devices behind IOMMUs with dirty tracking would still sync DMA bitmap. I think this is OK as it
increases the coverage for calc-dirty-rate (provided my comment in an earlier patch) such that if you try to get a dirty rate included the IOMMU invalidations
marking the bits accordingly.Quoted 5 lines
We still have the "if (!migration_is_running())" check above, so non-migratable VFIO devices won't sync.
But that's a valid point for when we'll allow VFIO log syncs for clac-dirty- rate.It's the other way around :) This change helps calc-dirty-rate because you can use it and still account for DMA unmap based dirties.
Quoted 6 lines
Quoted 4 lines
migration_is_runningjust stops logs if migration is not running. And that doesn't care about VFIO migation support.But if migration is running, whether the device supports migration or not...
If the device doesn't support migration then migration can't run, no?
/facepalm yes :D
We still have migration blockers
Quoted 4 lines
But anyway, as we talked in the other thread, I can untie this from migration and then, as you said above, it may also dirty sync for non-migratable devices which will make calc-dirty-rate more accurate.
Yeap
PATCH 4/9 vfio/migration: Add vfio_devices_all_dirty_tracking_started() helper
In reply to Avihai Horonvfio_devices_all_dirty_tracking() and vfio_dma_unmap_dirty_sync_needed() share the same code that checks if dirty page tracking has been started.
Extract it to a common helper vfio_devices_all_dirty_tracking_started().
--- hw/vfio/common.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
hw/vfio/common.c +13 -12
@@ -184,16 +184,22 @@ static bool vfio_devices_all_device_dirty_tracking_started(return true; } +static bool +vfio_devices_all_dirty_tracking_started (const VFIOContainerBase *bcontainer) +{ +if (!migration_is_running ()) { +return false; + } + +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 (!migration_is_running ()) { -return false; - } - -if (!(vfio_devices_all_device_dirty_tracking_started (bcontainer) || - bcontainer->dirty_pages_started)) { +if (!vfio_devices_all_dirty_tracking_started (bcontainer)) {return false; }
@@ -231,12 +237,7 @@ bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer)bool vfio_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer) { -if (!migration_is_running ()) { -return false; - } - -return vfio_devices_all_device_dirty_tracking_started (bcontainer) || - bcontainer->dirty_pages_started; +return vfio_devices_all_dirty_tracking_started (bcontainer); }static bool vfio_listener_skipped_section (MemoryRegionSection *section)
Signature · 1 line
2.40.1
Re: [PATCH 4/9] vfio/migration: Add vfio_devices_all_dirty_tracking_started() helper
Quoted 6 lines · Avihai Horon
vfio_devices_all_dirty_tracking()andvfio_dma_unmap_dirty_sync_needed()share the same code that checks if dirty page tracking has been started.Extract it to a common helper
vfio_devices_all_dirty_tracking_started().Signed-off-by Avihai Horon <[email protected]>
Quoted 51 lines
--- hw/vfio/common.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)hw/vfio/common.c +13
-12@@ -184,16 +184,22 @@ static bool vfio_devices_all_device_dirty_tracking_started(return true; } +static bool +vfio_devices_all_dirty_tracking_started (const VFIOContainerBase *bcontainer) +{ +if (!migration_is_running ()) { +return false; + } + +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 (!migration_is_running ()) { -return false; - } - -if (!(vfio_devices_all_device_dirty_tracking_started (bcontainer) || - bcontainer->dirty_pages_started)) { +if (!vfio_devices_all_dirty_tracking_started (bcontainer)) {return false; }@@ -231,12 +237,7 @@ bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer)bool vfio_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer) { -if (!migration_is_running ()) { -return false; - } - -return vfio_devices_all_device_dirty_tracking_started (bcontainer) || - bcontainer->dirty_pages_started; +return vfio_devices_all_dirty_tracking_started (bcontainer); }static bool vfio_listener_skipped_section (MemoryRegionSection *section)
PATCH 5/9 vfio/migration: Drop vfio_dma_unmap_dirty_sync_needed()
In reply to Avihai HoronThere is no need for vfio_dma_unmap_dirty_sync_needed(), as it simply calls vfio_devices_all_dirty_tracking_started().
Drop vfio_dma_unmap_dirty_sync_needed(), export vfio_devices_all_dirty_tracking_started() and use it instead.
--- include/hw/vfio/vfio-common.h | 3 ++- hw/vfio/common.c | 9 ++------- hw/vfio/container.c | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-)
include/hw/vfio/vfio-common.h +2 -1
@@ -296,7 +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_dma_unmap_dirty_sync_needed (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,
hw/vfio/common.c +2 -7
@@ -184,8 +184,8 @@ static bool vfio_devices_all_device_dirty_tracking_started(return true; } -static bool -vfio_devices_all_dirty_tracking_started (const VFIOContainerBase *bcontainer) +bool vfio_devices_all_dirty_tracking_started ( +const VFIOContainerBase *bcontainer) {if (!migration_is_running ()) {return false;
@@ -235,11 +235,6 @@ bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer)return true; } -bool vfio_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer) -{ -return vfio_devices_all_dirty_tracking_started (bcontainer); -} -static bool vfio_listener_skipped_section (MemoryRegionSection *section) { return (!memory_region_is_ram(section->mr) &&
hw/vfio/container.c +1 -1
@@ -131,7 +131,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,int ret;Error *local_err =NULL ; -if (iotlb &&vfio_dma_unmap_dirty_sync_needed (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);
Signature · 1 line
2.40.1
Re: [PATCH 5/9] vfio/migration: Drop vfio_dma_unmap_dirty_sync_needed()
Quoted 43 lines · Avihai Horon
There is no need for
vfio_dma_unmap_dirty_sync_needed(), as it simply callsvfio_devices_all_dirty_tracking_started().Drop
vfio_dma_unmap_dirty_sync_needed(), exportvfio_devices_all_dirty_tracking_started()and use it instead.Signed-off-by Avihai Horon <[email protected]>--- include/hw/vfio/vfio-common.h | 3 ++- hw/vfio/common.c | 9 ++------- hw/vfio/container.c | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-)include/hw/vfio/vfio-common.h +2
-1@@ -296,7 +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_dma_unmap_dirty_sync_needed (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,hw/vfio/common.c +2
-2@@ -184,8 +184,8 @@ static bool vfio_devices_all_device_dirty_tracking_started(return true; } -static bool -vfio_devices_all_dirty_tracking_started (const VFIOContainerBase *bcontainer) +bool vfio_devices_all_dirty_tracking_started ( +const VFIOContainerBase *bcontainer) {if (!migration_is_running ()) {return false;
hw/vfio/common.c bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer) · line 242
Quoted 8 lines
hw/vfio/common.c +0
-5@@ -235,11 +235,6 @@ bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer)return true; } -bool vfio_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer) -{ -return vfio_devices_all_dirty_tracking_started (bcontainer); -} -
Why not just renaming vfio_dma_unmap_dirty_sync_needed to vfio_devices_all_dirty_tracking_started() off from the start? We are introducing that helper name to just remove it again. And this patch wouldn't be needed anymore
Quoted 16 lines
hw/vfio/common.c +0
-0static bool vfio_listener_skipped_section (MemoryRegionSection *section) { return (!memory_region_is_ram(section->mr) &&hw/vfio/container.c +1
-1@@ -131,7 +131,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,int ret;Error *local_err =NULL ; -if (iotlb &&vfio_dma_unmap_dirty_sync_needed (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);
Re: [PATCH 5/9] vfio/migration: Drop vfio_dma_unmap_dirty_sync_needed()
Quoted 50 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 46 lines · Avihai Horon
There is no need for
vfio_dma_unmap_dirty_sync_needed(), as it simply callsvfio_devices_all_dirty_tracking_started().Drop
vfio_dma_unmap_dirty_sync_needed(), exportvfio_devices_all_dirty_tracking_started()and use it instead.Signed-off-by Avihai Horon <[email protected]>--- include/hw/vfio/vfio-common.h | 3 ++- hw/vfio/common.c | 9 ++------- hw/vfio/container.c | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-)include/hw/vfio/vfio-common.h +2
-1@@ -296,7 +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_dma_unmap_dirty_sync_needed (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,hw/vfio/common.c +2
-2@@ -184,8 +184,8 @@ static bool vfio_devices_all_device_dirty_tracking_started(return true; } -static bool -vfio_devices_all_dirty_tracking_started (const VFIOContainerBase *bcontainer) +bool vfio_devices_all_dirty_tracking_started ( +const VFIOContainerBase *bcontainer) {if (!migration_is_running ()) {return false;@@ -235,11 +235,6 @@ bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer)return true; }
Quoted 8 lines
hw/vfio/common.c bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer) · line 242
Quoted 5 lines
hw/vfio/common.c +0
-5-bool vfio_dma_unmap_dirty_sync_needed (const VFIOContainerBase *bcontainer) -{ -return vfio_devices_all_dirty_tracking_started (bcontainer); -} -Why not just renaming
vfio_dma_unmap_dirty_sync_neededtovfio_devices_all_dirty_tracking_started()off from the start? We are introducing that helper name to just remove it again. And this patch wouldn't be needed anymore
That's what I did at first, however there are several DPT helpers with similar names that check similar things but with subtle differences, so I thought that having a few changes in a single commit might be confusing. To ease review and make it super clear I split it to be a step-by-step cleanup.
I like it this way, but if you think it's redundant I can merge it again.
Thanks.
Quoted 17 lines
Quoted 17 lines
hw/vfio/common.c +0
-0static bool vfio_listener_skipped_section (MemoryRegionSection *section) { return (!memory_region_is_ram(section->mr) &&hw/vfio/container.c +1
-1@@ -131,7 +131,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,int ret;Error *local_err =NULL ; -if (iotlb &&vfio_dma_unmap_dirty_sync_needed (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);
PATCH 6/9 vfio/migration: Rename vfio_devices_all_dirty_tracking()
In reply to Avihai Horonvfio_devices_all_dirty_tracking() is used to check if dirty page log sync is needed. However, besides checking the dirty page tracking status, it also checks the pre_copy_dirty_page_tracking flag.
Rename it to vfio_devices_log_sync_needed() which reflects its purpose more accurately and makes the code clearer as there are already several helpers with similar names.
--- hw/vfio/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/vfio/common.c +2 -2
@@ -195,7 +195,7 @@ bool vfio_devices_all_dirty_tracking_started( bcontainer->dirty_pages_started; } -static bool vfio_devices_all_dirty_tracking (VFIOContainerBase *bcontainer) +static bool vfio_log_sync_needed (const VFIOContainerBase *bcontainer) {VFIODevice *vbasedev;
@@ -1368,7 +1368,7 @@ static void vfio_listener_log_sync(MemoryListener *listener,return ; } -if (vfio_devices_all_dirty_tracking (bcontainer)) { +if (vfio_log_sync_needed (bcontainer)) { ret =vfio_sync_dirty_bitmap (bcontainer, section, &local_err);if (ret) {error_report_err (local_err);
Signature · 1 line
2.40.1
Re: [PATCH 6/9] vfio/migration: Rename vfio_devices_all_dirty_tracking()
Quoted 8 lines · Avihai Horon
vfio_devices_all_dirty_tracking()is used to check if dirty page log sync is needed. However, besides checking the dirty page tracking status, it also checks thepre_copy_dirty_page_trackingflag.Rename it to
vfio_devices_log_sync_needed()which reflects its purpose more accurately and makes the code clearer as there are already several helpers with similar names.
Yes! :)
Quoted 1 line
Signed-off-by Avihai Horon <[email protected]>
Quoted 26 lines
--- hw/vfio/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/vfio/common.c +2
-2@@ -195,7 +195,7 @@ bool vfio_devices_all_dirty_tracking_started( bcontainer->dirty_pages_started; } -static bool vfio_devices_all_dirty_tracking (VFIOContainerBase *bcontainer) +static bool vfio_log_sync_needed (const VFIOContainerBase *bcontainer) {VFIODevice *vbasedev;@@ -1368,7 +1368,7 @@ static void vfio_listener_log_sync(MemoryListener *listener,return ; } -if (vfio_devices_all_dirty_tracking (bcontainer)) { +if (vfio_log_sync_needed (bcontainer)) { ret =vfio_sync_dirty_bitmap (bcontainer, section, &local_err);if (ret) {error_report_err (local_err);
PATCH 7/9 system/dirtylimit: Don't use migration_is_active()
In reply to Avihai Horonvcpu_dirty_rate_stat_collect() uses migration_is_active() to detect whether migration is running or not, in order to get the correct dirty rate period value.
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, and since the same functionality can be achieved with migration_is_running(), use it instead of migration_is_active().
--- system/dirtylimit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
system/dirtylimit.c +1 -2
@@ -80,8 +80,7 @@ static void vcpu_dirty_rate_stat_collect(void)int i =0 ;int64_t period =DIRTYLIMIT_CALC_TIME_MS ; -if (migrate_dirty_limit () && -migration_is_active ()) { +if (migrate_dirty_limit () &&migration_is_running ()) { period =migrate_vcpu_dirty_limit_period (); }
Signature · 1 line
2.40.1
Re: [PATCH 7/9] system/dirtylimit: Don't use migration_is_active()
Quoted 7 lines · Avihai Horon
vcpu_dirty_rate_stat_collect()usesmigration_is_active()to detect whether migration is running or not, in order to get the correct dirty rate period value.However, recently there has been an effort to simplify the migration status API and reduce it to a single
migration_is_running()function.
Could you post the related links?
Quoted 27 lines
To accommodate this, and since the same functionality can be achieved with
migration_is_running(), use it instead ofmigration_is_active().Signed-off-by Avihai Horon <[email protected]>--- system/dirtylimit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)system/dirtylimit.c +1
-3@@ -80,8 +80,7 @@ static void vcpu_dirty_rate_stat_collect(void)int i =0 ;int64_t period =DIRTYLIMIT_CALC_TIME_MS ; -if (migrate_dirty_limit () && -migration_is_active ()) { +if (migrate_dirty_limit () &&migration_is_running ()) { period =migrate_vcpu_dirty_limit_period (); } --2.40.1
Signature · 1 line
Best regards
Re: [PATCH 7/9] system/dirtylimit: Don't use migration_is_active()
Quoted 11 lines · Yong Huang
*External email: Use caution opening links or attachments*
On Mon, Dec 16, 2024 at 5:47 PM Avihai Horon <[email protected]> wrote:
vcpu_dirty_rate_stat_collect()usesmigration_is_active()to detect whether migration is running or not, in order to get the correct dirty rate period value.
Quoted 5 lines
However, recently there has been an effort to simplify the migration status API and reduce it to a single
migration_is_running()function.Could you post the related links?
Sure, it's here: https://lore.kernel.org/qemu-devel/[email protected]/
Peter took only patches 1-5 of this series.
Thanks.
Quoted 30 lines
To accommodate this, and since the same functionality can be achieved with migration_is_running(), use it instead of migration_is_active(). Signed-off-by: Avihai Horon <[email protected]> --- system/dirtylimit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/system/dirtylimit.c b/system/dirtylimit.c index ab20da34bb..d7a855c603 100644 --- a/system/dirtylimit.c +++ b/system/dirtylimit.c @@ -80,8 +80,7 @@ static void vcpu_dirty_rate_stat_collect(void) int i = 0; int64_t period = DIRTYLIMIT_CALC_TIME_MS; - if (migrate_dirty_limit() && - migration_is_active()) { + if (migrate_dirty_limit() && migration_is_running()) { period = migrate_vcpu_dirty_limit_period(); } -- 2.40.1Signature · 1 line
Best regards
Yong Huang
Reviewed-byRe: [PATCH 7/9] system/dirtylimit: Don't use migration_is_active()
Quoted 20 lines · Avihai Horon
Quoted 9 lines · Yong Huang
*External email: Use caution opening links or attachments*
On Mon, Dec 16, 2024 at 5:47 PM Avihai Horon <[email protected]> wrote:
vcpu_dirty_rate_stat_collect()usesmigration_is_active()to detect whether migration is running or not, in order to get the correctdirty
Quoted 7 lines
rate period value.
However, recently there has been an effort to simplify the migration status API and reduce it to a single
migration_is_running()function.Could you post the related links?
Quoted 39 lines
Sure, it's here:
https://lore.kernel.org/qemu-devel/[email protected]/
Peter took only patches 1-5 of this series.
Thanks.
Quoted 30 lines
To accommodate this, and since the same functionality can be achieved with migration_is_running(), use it instead of migration_is_active(). Signed-off-by: Avihai Horon <[email protected]> --- system/dirtylimit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/system/dirtylimit.c b/system/dirtylimit.c index ab20da34bb..d7a855c603 100644 --- a/system/dirtylimit.c +++ b/system/dirtylimit.c @@ -80,8 +80,7 @@ static void vcpu_dirty_rate_stat_collect(void) int i = 0; int64_t period = DIRTYLIMIT_CALC_TIME_MS; - if (migrate_dirty_limit() && - migration_is_active()) { + if (migrate_dirty_limit() && migration_is_running()) { period = migrate_vcpu_dirty_limit_period(); } -- 2.40.1--
Best regards
Thanks,
Signature · 1 line
Best regards
PATCH 8/9 migration: Drop migration_is_device()
In reply to Avihai HoronAfter being removed from VFIO, migration_is_device() no longer has any users. Drop it.
--- include/migration/misc.h | 1 - migration/migration.c | 7 ------- 2 files changed, 8 deletions(-)
include/migration/misc.h +0 -1
@@ -54,7 +54,6 @@ void migration_object_init(void);void migration_shutdown (void );bool migration_is_active (void ); -bool migration_is_device (void );bool migration_is_running (void );bool migration_thread_is_self (void );
migration/migration.c +0 -7
@@ -1645,13 +1645,6 @@ bool migration_is_active(void) s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE); } -bool migration_is_device (void ) -{ -MigrationState *s = current_migration; - -return s->state ==MIGRATION_STATUS_DEVICE ; -} -bool migration_thread_is_self (void ) {MigrationState *s = current_migration;
Signature · 1 line
2.40.1
Re: [PATCH 8/9] migration: Drop migration_is_device()
Quoted 4 lines · Avihai Horon
After being removed from VFIO,
migration_is_device()no longer has any users. Drop it.Signed-off-by Avihai Horon <[email protected]>
Thanks,
C.
Quoted 35 lines
--- include/migration/misc.h | 1 - migration/migration.c | 7 ------- 2 files changed, 8 deletions(-)include/migration/misc.h +0
-1@@ -54,7 +54,6 @@ void migration_object_init(void);void migration_shutdown (void );bool migration_is_active (void ); -bool migration_is_device (void );bool migration_is_running (void );bool migration_thread_is_self (void );migration/migration.c +0
-7@@ -1645,13 +1645,6 @@ bool migration_is_active(void) s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE); } -bool migration_is_device (void ) -{ -MigrationState *s = current_migration; - -return s->state ==MIGRATION_STATUS_DEVICE ; -} -bool migration_thread_is_self (void ) {MigrationState *s = current_migration;
Re: [PATCH 8/9] migration: Drop migration_is_device()
In reply to Avihai HoronQuoted 4 lines · Avihai Horon
After being removed from VFIO,
migration_is_device()no longer has any users. Drop it.Signed-off-by Avihai Horon <[email protected]>
Thanks for working on this, Avihai!
Signature · 1 line
Peter Xu
PATCH 9/9 migration: Unexport migration_is_active()
In reply to Avihai HoronAfter being removed from VFIO and dirty limit, migration_is_active() no longer has any users outside the migration subsystem, and in fact, it's only used in migration.c.
Unexport it and also relocate it so it can be made static.
--- include/migration/misc.h | 1 - migration/migration.c | 16 ++++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-)
include/migration/misc.h +0 -1
@@ -53,7 +53,6 @@ void dump_vmstate_json_to_file(FILE *out_fp);void migration_object_init (void );void migration_shutdown (void ); -bool migration_is_active (void );bool migration_is_running (void );bool migration_thread_is_self (void );
migration/migration.c +8 -8
@@ -1139,6 +1139,14 @@ bool migration_is_running(void) } } +static bool migration_is_active (void ) +{ +MigrationState *s = current_migration; + +return (s->state ==MIGRATION_STATUS_ACTIVE || + s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ); +} +static bool migrate_show_downtime (MigrationState *s) {return (s->state ==MIGRATION_STATUS_COMPLETED ) ||migration_in_postcopy ();
@@ -1637,14 +1645,6 @@ bool migration_in_bg_snapshot(void)return migrate_background_snapshot () &&migration_is_running (); } -bool migration_is_active (void ) -{ -MigrationState *s = current_migration; - -return (s->state ==MIGRATION_STATUS_ACTIVE || - s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ); -} -bool migration_thread_is_self (void ) {MigrationState *s = current_migration;
Signature · 1 line
2.40.1
Re: [PATCH 9/9] migration: Unexport migration_is_active()
Quoted 7 lines · Avihai Horon
After being removed from VFIO and dirty limit,
migration_is_active()no longer has any users outside the migration subsystem, and in fact, it's only used inmigration.c.Unexport it and also relocate it so it can be made static.
Signed-off-by Avihai Horon <[email protected]>
Thanks,
C.
Quoted 51 lines
--- include/migration/misc.h | 1 - migration/migration.c | 16 ++++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-)include/migration/misc.h +0
-1@@ -53,7 +53,6 @@ void dump_vmstate_json_to_file(FILE *out_fp);void migration_object_init (void );void migration_shutdown (void ); -bool migration_is_active (void );bool migration_is_running (void );bool migration_thread_is_self (void );migration/migration.c +8
-8@@ -1139,6 +1139,14 @@ bool migration_is_running(void) } } +static bool migration_is_active (void ) +{ +MigrationState *s = current_migration; + +return (s->state ==MIGRATION_STATUS_ACTIVE || + s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ); +} +static bool migrate_show_downtime (MigrationState *s) {return (s->state ==MIGRATION_STATUS_COMPLETED ) ||migration_in_postcopy ();@@ -1637,14 +1645,6 @@ bool migration_in_bg_snapshot(void)return migrate_background_snapshot () &&migration_is_running (); } -bool migration_is_active (void ) -{ -MigrationState *s = current_migration; - -return (s->state ==MIGRATION_STATUS_ACTIVE || - s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ); -} -bool migration_thread_is_self (void ) {MigrationState *s = current_migration;
Re: [PATCH 9/9] migration: Unexport migration_is_active()
In reply to Avihai HoronQuoted 7 lines · Avihai Horon
After being removed from VFIO and dirty limit,
migration_is_active()no longer has any users outside the migration subsystem, and in fact, it's only used inmigration.c.Unexport it and also relocate it so it can be made static.
Signed-off-by Avihai Horon <[email protected]>
Signature · 1 line
Peter Xu
Quoted 10 lines · Avihai Horon
Hello,
This follows up on Peter's series [1] to simplify migration status API to a single
migration_is_running()function.Peter's series tried to drop
migration_is_device()andmigration_is_active(), however VFIO used them to check if dirty page tracking has been started in order to avoid errors in log sync, so they couldn't simply be dropped without some preliminary cleanups.
Quoted 9 lines
This series handles these preliminary cleanups and eventually drops
migration_is_device()and unexportsmigration_is_active().The series has been migration tested with the following:
- VFIO device dirty tracking.
- Legacy VFIO iommu dirty tracking.
- vIOMMU + Legacy VFIO iommu dirty tracking (migration with vIOMMU is currently blocked, so I used a patched QEMU to allow it).
vIOMMU on IOMMU HW doesn't suffer from the same problems of VF dirty tracking where there's a aggregate limit into how much VFs can track in terms of IOVA space. So we can lift some of those restrictions for IOMMU even right now provided we implement the last remaining pre-requisite. I also have a much smaller series for that sort of unblockage that I can give you a pointer. Though, eventually the optimizations we will do for VF dirty tracking for vIOMMU will apply to IOMMU HW too just so we minimize the amount of calls to get dirty bits.
Quoted 4 lines
I didn't test it with iommu DPT as I don't have access to such HW. Cedric, I remember you said that you have such HW, it would be very helpful if you could test it.
I am starting to prep the unblocking vIOMMU for Qemu 10, so I can validate if this series works as well -- but from what I have looked so far it should be all OK. If it helps I have some pending series that lets you test emulated x86 IOMMU DPT support (either on intel-iommu or amd-iommu) that can help you when you don't have the hardware to test.
Regarding this series, since you are looking at the the dirty tracking 'status' I'll comment here too as one of your original patches introduced it as it's related to the use of migration_is_running(). And since you're looking at this exact part of the code, might as well cover that too.
Quoted 23 lines · Joao Martins
External email: Use caution opening links or attachments
Quoted 10 lines · Avihai Horon
Hello,
This follows up on Peter's series [1] to simplify migration status API to a single
migration_is_running()function.Peter's series tried to drop
migration_is_device()andmigration_is_active(), however VFIO used them to check if dirty page tracking has been started in order to avoid errors in log sync, so they couldn't simply be dropped without some preliminary cleanups.Quoted 9 lines
This series handles these preliminary cleanups and eventually drops
migration_is_device()and unexportsmigration_is_active().The series has been migration tested with the following:
- VFIO device dirty tracking.
- Legacy VFIO iommu dirty tracking.
- vIOMMU + Legacy VFIO iommu dirty tracking (migration with vIOMMU is currently blocked, so I used a patched QEMU to allow it).
Quoted 4 lines
vIOMMU on IOMMU HW doesn't suffer from the same problems of VF dirty tracking where there's a aggregate limit into how much VFs can track in terms of IOVA space. So we can lift some of those restrictions for IOMMU even right now provided we implement the last remaining pre-requisite.
That would be helpful if there is a user who needs migration (with iommu DPT) + vIOMMU support right now. Otherwise, we don't have to rush and we can do it along with the optimizations or whatever we see fit. I only needed migration + vIOMMU to test the vIOMMU dma unmap flow.
Quoted 2 lines
I also have a much
smaller series for that sort of unblockage that I can give you a pointer.
Yes, if you have it at hand, that could be useful for testing next versions.
Quoted 11 lines
Though, eventually the optimizations we will do for VF dirty tracking for vIOMMU will apply to IOMMU HW too just so we minimize the amount of calls to get dirty bits.
Quoted 4 lines
I didn't test it with iommu DPT as I don't have access to such HW. Cedric, I remember you said that you have such HW, it would be very helpful if you could test it.
I am starting to prep the unblocking vIOMMU for Qemu 10, so I can validate if this series works as well -- but from what I have looked so far it should be all OK.
Thanks, that wouldn't hurt :)
Quoted 3 lines
If it helps I have some pending series that lets you test emulated x86 IOMMU DPT support (either on intel-iommu or amd-iommu) that can help you when you don't have the hardware to test.
That would be great, I didn't know such thing existed.
Thanks!
Quoted 5 lines
Regarding this series, since you are looking at the the dirty tracking 'status' I'll comment here too as one of your original patches introduced it as it's related to the use of
migration_is_running(). And since you're looking at this exact part of the code, might as well cover that too.
Quoted 19 lines · Avihai Horon
Quoted 3 lines · Joao Martins
On 16/12/2024 09:46, Avihai Horon wrote:
I also have a much
smaller series for that sort of unblockage that I can give you a pointer.Yes, if you have it at hand, that could be useful for testing next versions.
Quoted 11 lines
Though, eventually the optimizations we will do for VF dirty tracking for vIOMMU will apply to IOMMU HW too just so we minimize the amount of calls to get dirty bits.
Quoted 4 lines
I didn't test it with iommu DPT as I don't have access to such HW. Cedric, I remember you said that you have such HW, it would be very helpful if you could test it.
I am starting to prep the unblocking vIOMMU for Qemu 10, so I can validate if this series works as well -- but from what I have looked so far it should be all OK.
Quoted 8 lines
Thanks, that wouldn't hurt :)
Quoted 3 lines
If it helps I have some pending series that lets you test emulated x86 IOMMU DPT support (either on intel-iommu or amd-iommu) that can help you when you don't have the hardware to test.
That would be great, I didn't know such thing existed.
I did post it, but it was some time ago (2y). While I got some comments, but failed to follow-up:
https://lore.kernel.org/qemu-devel/[email protected]/#t
The link above has bugs, but let me conjure the version alongside vIOMMU and the other stuff I mentioned earlier.
Hello Joao,
Quoted 29 lines · Joao Martins
Quoted 19 lines · Avihai Horon
Quoted 3 lines · Joao Martins
On 16/12/2024 09:46, Avihai Horon wrote:
I also have a much
smaller series for that sort of unblockage that I can give you a pointer.Yes, if you have it at hand, that could be useful for testing next versions.
Quoted 11 lines
Though, eventually the optimizations we will do for VF dirty tracking for vIOMMU will apply to IOMMU HW too just so we minimize the amount of calls to get dirty bits.
Quoted 4 lines
I didn't test it with iommu DPT as I don't have access to such HW. Cedric, I remember you said that you have such HW, it would be very helpful if you could test it.
I am starting to prep the unblocking vIOMMU for Qemu 10, so I can validate if this series works as well -- but from what I have looked so far it should be all OK.
Quoted 8 lines
Thanks, that wouldn't hurt :)
Quoted 3 lines
If it helps I have some pending series that lets you test emulated x86 IOMMU DPT support (either on intel-iommu or amd-iommu) that can help you when you don't have the hardware to test.
That would be great, I didn't know such thing existed.
Quoted 7 lines
I did post it, but it was some time ago (2y). While I got some comments, but failed to follow-up:
https://lore.kernel.org/qemu-devel/[email protected]/#t
The link above has bugs, but let me conjure the version alongside vIOMMU and the other stuff I mentioned earlier.
Please Cc: me next time.
Thanks,
C.
Quoted 35 lines · Cédric Le Goater
Quoted 34 lines · Joao Martins
Quoted 21 lines · Avihai Horon
Quoted 3 lines · Joao Martins
On 16/12/2024 09:46, Avihai Horon wrote:
I also have a much
smaller series for that sort of unblockage that I can give you a pointer.Yes, if you have it at hand, that could be useful for testing next versions.
Quoted 5 lines
Though, eventually the optimizations we will do for VF dirty tracking for vIOMMU
will apply to IOMMU HW too just so we minimize the amount of calls to get dirty bits.Quoted 8 lines
Quoted 4 lines
I didn't test it with iommu DPT as I don't have access to such HW. Cedric, I remember you said that you have such HW, it would be very helpful if you could test it.
I am starting to prep the unblocking vIOMMU for Qemu 10, so I can validate if this series works as well -- but from what I have looked so far it should be all
OK.Quoted 8 lines
Thanks, that wouldn't hurt :)
Quoted 3 lines
If it helps I have some pending series that lets you test emulated x86 IOMMU DPT support (either on intel-iommu or amd-iommu) that can help you when you don't have the hardware to test.
That would be great, I didn't know such thing existed.
I did post it, but it was some time ago (2y). While I got some comments, but failed to follow-up:
Quoted 8 lines
Quoted 5 lines
https://lore.kernel.org/qemu-devel/20220428211351.3897-1-
[email protected]/#tThe link above has bugs, but let me conjure the version alongside vIOMMU and the other stuff I mentioned earlier.
Please Cc: me next time.
OK
Quoted 19 lines · Avihai Horon
Hello,
This follows up on Peter's series [1] to simplify migration status API to a single
migration_is_running()function.Peter's series tried to drop
migration_is_device()andmigration_is_active(), however VFIO used them to check if dirty page tracking has been started in order to avoid errors in log sync, so they couldn't simply be dropped without some preliminary cleanups.This series handles these preliminary cleanups and eventually drops
migration_is_device()and unexportsmigration_is_active().The series has been migration tested with the following:
- VFIO device dirty tracking.
- Legacy VFIO iommu dirty tracking.
- vIOMMU + Legacy VFIO iommu dirty tracking (migration with vIOMMU is currently blocked, so I used a patched QEMU to allow it).
Quoted 3 lines
I didn't test it with iommu DPT as I don't have access to such HW. Cedric, I remember you said that you have such HW, it would be very helpful if you could test it.
Yes. I can.
I am bit busy now and I only looked quickly at the comments. I understand from Joao that it shouldn't be too complex to change the VFIO dirty tracking engines to use calc-dirty-rate, which I agree would useful.
How far are we from that ? We are early in the QEMU cycle and this series looks ok, may be needs one respin. Should we merge it first ? I feel this would be good to have before the migration cleanups and the next version of Maciej's multifd series.
Thanks,
C.
Quoted 33 lines
Patch structure:
1-6: Refactor and clean up VFIO dirty page tracking helpers. 7: Refactor dirty limit code.
8-9: Drop/unexportmigration_is_device()andmigration_is_running().Thanks.
[1]
https://lore.kernel.org/qemu-devel/[email protected]/Avihai Horon (9):
vfio/container: Add dirty tracking started flag vfio/migration: Refactorvfio_devices_all_dirty_tracking()logic vfio/migration: Refactorvfio_devices_all_running_and_mig_active()
logic
vfio/migration: Addvfio_devices_all_dirty_tracking_started()helper vfio/migration: Dropvfio_dma_unmap_dirty_sync_needed()vfio/migration: Renamevfio_devices_all_dirty_tracking()system/dirtylimit: Don't usemigration_is_active()
migration: Dropmigration_is_device()
migration: Unexportmigration_is_active()include/hw/vfio/vfio-common.h | 4 +- include/hw/vfio/vfio-container-base.h | 1 + include/migration/misc.h | 2 - hw/vfio/common.c | 61 ++++++++++++--------------- hw/vfio/container-base.c | 8 +++- hw/vfio/container.c | 2 +- migration/migration.c | 23 ++++------ system/dirtylimit.c | 3 +- 8 files changed, 48 insertions(+), 56 deletions(-)
Quoted 23 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Quoted 19 lines · Avihai Horon
Hello,
This follows up on Peter's series [1] to simplify migration status API to a single
migration_is_running()function.Peter's series tried to drop
migration_is_device()andmigration_is_active(), however VFIO used them to check if dirty page tracking has been started in order to avoid errors in log sync, so they couldn't simply be dropped without some preliminary cleanups.This series handles these preliminary cleanups and eventually drops
migration_is_device()and unexportsmigration_is_active().The series has been migration tested with the following:
- VFIO device dirty tracking.
- Legacy VFIO iommu dirty tracking.
- vIOMMU + Legacy VFIO iommu dirty tracking (migration with vIOMMU is currently blocked, so I used a patched QEMU to allow it).
Quoted 5 lines
Quoted 3 lines
I didn't test it with iommu DPT as I don't have access to such HW. Cedric, I remember you said that you have such HW, it would be very helpful if you could test it.
Yes. I can.
Thanks.
Quoted 4 lines
I am bit busy now and I only looked quickly at the comments. I understand from Joao that it shouldn't be too complex to change the VFIO dirty tracking engines to use calc-dirty-rate, which I agree would useful.
Sure, will do.
Quoted 2 lines
How far are we from that ?
Not far, I hope I can send v2 later this week.
Quoted 5 lines
We are early in the QEMU cycle and this series
looks ok, may be needs one respin. Should we merge it first ? I feel this would be good to have before the migration cleanups and the next version of Maciej's multifd series.
Agreed.
Thanks.