[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v28 12/17] vfio: Add function to start and stop dirty pages track
From: |
Kirti Wankhede |
Subject: |
[PATCH v28 12/17] vfio: Add function to start and stop dirty pages tracking |
Date: |
Fri, 23 Oct 2020 16:10:38 +0530 |
Call VFIO_IOMMU_DIRTY_PAGES ioctl to start and stop dirty pages tracking
for VFIO devices.
Signed-off-by: Kirti Wankhede <kwankhede@nvidia.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
hw/vfio/migration.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index 0dc40e34a4de..d4ba24c2dfae 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -11,6 +11,7 @@
#include "qemu/main-loop.h"
#include "qemu/cutils.h"
#include <linux/vfio.h>
+#include <sys/ioctl.h>
#include "sysemu/runstate.h"
#include "hw/vfio/vfio-common.h"
@@ -391,10 +392,40 @@ static int vfio_load_device_config_state(QEMUFile *f,
void *opaque)
return qemu_file_get_error(f);
}
+static int vfio_set_dirty_page_tracking(VFIODevice *vbasedev, bool start)
+{
+ int ret;
+ VFIOMigration *migration = vbasedev->migration;
+ VFIOContainer *container = vbasedev->group->container;
+ struct vfio_iommu_type1_dirty_bitmap dirty = {
+ .argsz = sizeof(dirty),
+ };
+
+ if (start) {
+ if (migration->device_state & VFIO_DEVICE_STATE_SAVING) {
+ dirty.flags = VFIO_IOMMU_DIRTY_PAGES_FLAG_START;
+ } else {
+ return -EINVAL;
+ }
+ } 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 -errno;
+ }
+ return ret;
+}
+
static void vfio_migration_cleanup(VFIODevice *vbasedev)
{
VFIOMigration *migration = vbasedev->migration;
+ vfio_set_dirty_page_tracking(vbasedev, false);
+
if (migration->region.mmaps) {
vfio_region_unmap(&migration->region);
}
@@ -435,6 +466,11 @@ static int vfio_save_setup(QEMUFile *f, void *opaque)
return ret;
}
+ ret = vfio_set_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);
--
2.7.0
- [PATCH v28 07/17] vfio: Register SaveVMHandlers for VFIO device, (continued)
- [PATCH v28 07/17] vfio: Register SaveVMHandlers for VFIO device, Kirti Wankhede, 2020/10/23
- [PATCH v28 08/17] vfio: Add save state functions to SaveVMHandlers, Kirti Wankhede, 2020/10/23
- [PATCH v28 09/17] vfio: Add load state functions to SaveVMHandlers, Kirti Wankhede, 2020/10/23
- [PATCH v28 10/17] memory: Set DIRTY_MEMORY_MIGRATION when IOMMU is enabled, Kirti Wankhede, 2020/10/23
- [PATCH v28 11/17] vfio: Get migration capability flags for container, Kirti Wankhede, 2020/10/23
- [PATCH v28 12/17] vfio: Add function to start and stop dirty pages tracking,
Kirti Wankhede <=
- [PATCH v28 13/17] vfio: Add vfio_listener_log_sync to mark dirty pages, Kirti Wankhede, 2020/10/23
- [PATCH v28 14/17] vfio: Dirty page tracking when vIOMMU is enabled, Kirti Wankhede, 2020/10/23
- [PATCH v28 15/17] vfio: Add ioctl to get dirty pages bitmap during dma unmap, Kirti Wankhede, 2020/10/23
- [PATCH v28 16/17] vfio: Make vfio-pci device migration capable, Kirti Wankhede, 2020/10/23
- [PATCH v28 17/17] qapi: Add VFIO devices migration stats in Migration stats, Kirti Wankhede, 2020/10/23
- Re: [PATCH v28 00/17] Add migration support for VFIO devices, Philippe Mathieu-Daudé, 2020/10/24