[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v16 QEMU 13/16] vfio: Add function to start and stop dirty pages
From: |
Kirti Wankhede |
Subject: |
[PATCH v16 QEMU 13/16] vfio: Add function to start and stop dirty pages tracking |
Date: |
Wed, 25 Mar 2020 02:39:11 +0530 |
Call VFIO_IOMMU_DIRTY_PAGES ioctl to start and stop dirty pages tracking
for VFIO devices.
Signed-off-by: Kirti Wankhede <address@hidden>
---
hw/vfio/migration.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index ab295d25620e..1827b7cfb316 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -9,6 +9,7 @@
#include "qemu/osdep.h"
#include "qemu/main-loop.h"
+#include <sys/ioctl.h>
#include <linux/vfio.h>
#include "sysemu/runstate.h"
@@ -296,6 +297,32 @@ static int vfio_load_device_config_state(QEMUFile *f, void
*opaque)
return qemu_file_get_error(f);
}
+static int vfio_start_dirty_page_tracking(VFIODevice *vbasedev, bool start)
+{
+ int ret;
+ VFIOContainer *container = vbasedev->group->container;
+ struct vfio_iommu_type1_dirty_bitmap dirty = {
+ .argsz = sizeof(dirty),
+ };
+
+ if (start) {
+ if (vbasedev->device_state & VFIO_DEVICE_STATE_SAVING) {
+ dirty.flags = VFIO_IOMMU_DIRTY_PAGES_FLAG_START;
+ } else {
+ return 0;
+ }
+ } else {
+ dirty.flags = VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP;
+ }
+
+ ret = ioctl(container->fd, VFIO_IOMMU_DIRTY_PAGES, &dirty);
+ if (ret) {
+ error_report("Failed to set dirty tracking flag 0x%x errno: %d",
+ dirty.flags, errno);
+ }
+ return ret;
+}
+
/* ---------------------------------------------------------------------- */
static int vfio_save_setup(QEMUFile *f, void *opaque)
@@ -330,6 +357,11 @@ static int vfio_save_setup(QEMUFile *f, void *opaque)
*/
qemu_put_be64(f, migration->region.size);
+ ret = vfio_start_dirty_page_tracking(vbasedev, true);
+ if (ret) {
+ return ret;
+ }
+
qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE);
ret = qemu_file_get_error(f);
@@ -346,6 +378,8 @@ static void vfio_save_cleanup(void *opaque)
VFIODevice *vbasedev = opaque;
VFIOMigration *migration = vbasedev->migration;
+ vfio_start_dirty_page_tracking(vbasedev, false);
+
if (migration->region.mmaps) {
vfio_region_unmap(&migration->region);
}
@@ -669,6 +703,8 @@ static void vfio_migration_state_notifier(Notifier
*notifier, void *data)
if (ret) {
error_report("%s: Failed to set state RUNNING", vbasedev->name);
}
+
+ vfio_start_dirty_page_tracking(vbasedev, false);
}
}
--
2.7.0
- [PATCH v16 QEMU 06/16] vfio: Add VM state change handler to know state of VM, (continued)
- [PATCH v16 QEMU 06/16] vfio: Add VM state change handler to know state of VM, Kirti Wankhede, 2020/03/24
- [PATCH v16 QEMU 07/16] vfio: Add migration state change notifier, Kirti Wankhede, 2020/03/24
- [PATCH v16 QEMU 08/16] vfio: Register SaveVMHandlers for VFIO device, Kirti Wankhede, 2020/03/24
- [PATCH v16 QEMU 09/16] vfio: Add save state functions to SaveVMHandlers, Kirti Wankhede, 2020/03/24
- [PATCH v16 QEMU 10/16] vfio: Add load state functions to SaveVMHandlers, Kirti Wankhede, 2020/03/24
- [PATCH v16 QEMU 11/16] iommu: add callback to get address limit IOMMU supports, Kirti Wankhede, 2020/03/24
- [PATCH v16 QEMU 12/16] memory: Set DIRTY_MEMORY_MIGRATION when IOMMU is enabled, Kirti Wankhede, 2020/03/24
- [PATCH v16 QEMU 13/16] vfio: Add function to start and stop dirty pages tracking,
Kirti Wankhede <=
- [PATCH v16 QEMU 14/16] vfio: Add vfio_listener_log_sync to mark dirty pages, Kirti Wankhede, 2020/03/24
- [PATCH v16 QEMU 15/16] vfio: Add ioctl to get dirty pages bitmap during dma unmap., Kirti Wankhede, 2020/03/24
- [PATCH v16 QEMU 16/16] vfio: Make vfio-pci device migration capable, Kirti Wankhede, 2020/03/24
- Re: [PATCH v16 QEMU 00/16] Add migration support for VFIO devices, no-reply, 2020/03/24
- Re: [PATCH v16 QEMU 00/16] Add migration support for VFIO devices, Alex Williamson, 2020/03/31