From: Zhenzhong Duan <[email protected]> Commit e46883204c38 ("vfio/migration: Block migration with vIOMMU") introduces a migration blocker when vIOMMU is enabled, because we need to calculate the IOVA ranges for device dirty tracking. But this is unnecessary for iommu dirty tracking.
Limit the vfio_viommu_preset() check to those devices which use device dirty tracking. This allows live migration with VFIO devices which use iommu dirty tracking. Suggested-by: Jason Zeng <[email protected]> Co-developed-by: Joao Martins <[email protected]> Signed-off-by: Joao Martins <[email protected]> Signed-off-by: Zhenzhong Duan <[email protected]> Reviewed-by: Yi Liu <[email protected]> Tested-by: Xudong Hao <[email protected]> Tested-by: Giovannio Cabiddu <[email protected]> Tested-by: Rohith S R <[email protected]> Link: https://lore.kernel.org/qemu-devel/[email protected] Signed-off-by: Cédric Le Goater <[email protected]> --- include/hw/vfio/vfio-device.h | 10 ++++++++++ hw/vfio/container.c | 5 +---- hw/vfio/device.c | 6 ++++++ hw/vfio/migration.c | 6 +++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 0bc877ff62f9473d49782ce7c2ee1eb943175821..48d00c7bc47a2fd11a522a1ad09b051f16342545 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -148,6 +148,16 @@ bool vfio_device_irq_set_signaling(VFIODevice *vbasedev, int index, int subindex void vfio_device_reset_handler(void *opaque); bool vfio_device_is_mdev(VFIODevice *vbasedev); +/** + * vfio_device_dirty_pages_disabled: Check if device dirty tracking will be + * used for a VFIO device + * + * @vbasedev: The VFIODevice to transform + * + * Return: true if either @vbasedev doesn't support device dirty tracking or + * is forcedly disabled from command line, otherwise false. + */ +bool vfio_device_dirty_pages_disabled(VFIODevice *vbasedev); bool vfio_device_hiod_create_and_realize(VFIODevice *vbasedev, const char *typename, Error **errp); bool vfio_device_attach(char *name, VFIODevice *vbasedev, diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 9881f5df2cc34262ae6aa88aa937659e7b197cd2..af16cd14db069882cc5fcf6349b433af3867f40c 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -178,10 +178,7 @@ bool vfio_container_devices_dirty_tracking_is_supported( VFIODevice *vbasedev; QLIST_FOREACH(vbasedev, &bcontainer->device_list, container_next) { - if (vbasedev->device_dirty_page_tracking == ON_OFF_AUTO_OFF) { - return false; - } - if (!vbasedev->dirty_pages_supported) { + if (vfio_device_dirty_pages_disabled(vbasedev)) { return false; } } diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 100532f35d9ad14bf14c8d6d783f7b06aa85245a..3bab082322633f7cbd4295b4e91717c83fbb48da 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -412,6 +412,12 @@ bool vfio_device_is_mdev(VFIODevice *vbasedev) return subsys && (strcmp(subsys, "/sys/bus/mdev") == 0); } +bool vfio_device_dirty_pages_disabled(VFIODevice *vbasedev) +{ + return (!vbasedev->dirty_pages_supported || + vbasedev->device_dirty_page_tracking == ON_OFF_AUTO_OFF); +} + bool vfio_device_hiod_create_and_realize(VFIODevice *vbasedev, const char *typename, Error **errp) { diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index e1c25ba90703e9574fdd69275ae2705684396697..f857dc25ed4d0f824bdabc168228a5e925ac7dbe 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -1210,8 +1210,7 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp) return !vfio_block_migration(vbasedev, err, errp); } - if ((!vbasedev->dirty_pages_supported || - vbasedev->device_dirty_page_tracking == ON_OFF_AUTO_OFF) && + if (vfio_device_dirty_pages_disabled(vbasedev) && !vbasedev->iommu_dirty_tracking) { if (vbasedev->enable_migration == ON_OFF_AUTO_AUTO) { error_setg(&err, @@ -1236,7 +1235,8 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp) goto out_deinit; } - if (vfio_viommu_preset(vbasedev)) { + if (!vfio_device_dirty_pages_disabled(vbasedev) && + vfio_viommu_preset(vbasedev)) { error_setg(&err, "%s: Migration is currently not supported " "with vIOMMU enabled", vbasedev->name); goto add_blocker; -- 2.52.0
