[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 17/17] vfio/migration: Query device data size in vfio_save_pen
From: |
Avihai Horon |
Subject: |
[PATCH v3 17/17] vfio/migration: Query device data size in vfio_save_pending() |
Date: |
Thu, 3 Nov 2022 18:16:20 +0200 |
Use VFIO_DEVICE_FEATURE_MIG_DATA_SIZE uAPI to query the device data size
and report it in vfio_save_pending() instead of the hardcoded value that
is currently used.
Signed-off-by: Avihai Horon <avihaih@nvidia.com>
---
hw/vfio/migration.c | 27 ++++++++++++++++++++-------
linux-headers/linux/vfio.h | 13 +++++++++++++
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index e8068b9147..8ade901383 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -225,14 +225,27 @@ static void vfio_save_pending(void *opaque, uint64_t
threshold_size,
uint64_t *res_precopy, uint64_t *res_postcopy)
{
VFIODevice *vbasedev = opaque;
+ uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature) +
+ sizeof(struct vfio_device_feature_mig_data_size),
+ sizeof(uint64_t))] = {};
+ struct vfio_device_feature *feature = (void *)buf;
+ struct vfio_device_feature_mig_data_size *mig_data_size =
+ (void *)feature->data;
+
+ feature->argsz = sizeof(buf);
+ feature->flags =
+ VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_MIG_DATA_SIZE;
- /*
- * VFIO migration protocol v2 currently doesn't have an API to get pending
- * device state size. Until such API is introduced, report some big
- * arbitrary pending size so the device will be taken into account for
- * downtime limit calculations.
- */
- *res_postcopy += VFIO_MIG_PENDING_SIZE;
+ if (ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature)) {
+ if (errno != ENOTTY) {
+ return;
+ }
+
+ /* Kernel doesn't support VFIO_DEVICE_FEATURE_MIG_DATA_SIZE */
+ *res_postcopy += VFIO_MIG_PENDING_SIZE;
+ } else {
+ *res_postcopy += mig_data_size->stop_copy_length;
+ }
trace_vfio_save_pending(vbasedev->name, *res_precopy, *res_postcopy);
}
diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
index ede44b5572..5c4ddf424f 100644
--- a/linux-headers/linux/vfio.h
+++ b/linux-headers/linux/vfio.h
@@ -986,6 +986,19 @@ enum vfio_device_mig_state {
VFIO_DEVICE_STATE_RUNNING_P2P = 5,
};
+/*
+ * Upon VFIO_DEVICE_FEATURE_GET read back the estimated data length that will
+ * be required to complete stop copy.
+ *
+ * Note: Can be called on each device state.
+ */
+
+struct vfio_device_feature_mig_data_size {
+ __aligned_u64 stop_copy_length;
+};
+
+#define VFIO_DEVICE_FEATURE_MIG_DATA_SIZE 9
+
/* -------- API for Type1 VFIO IOMMU -------- */
/**
--
2.21.3
- Re: [PATCH v3 10/17] vfio/migration: Move migration v1 logic to vfio_migration_init(), (continued)
[PATCH v3 17/17] vfio/migration: Query device data size in vfio_save_pending(),
Avihai Horon <=
[PATCH v3 15/17] vfio: Alphabetize migration section of VFIO trace-events file, Avihai Horon, 2022/11/03
[PATCH v3 02/17] migration: No save_live_pending() method uses the QEMUFile parameter, Avihai Horon, 2022/11/03
[PATCH v3 16/17] docs/devel: Align vfio-migration docs to VFIO migration v2, Avihai Horon, 2022/11/03
[PATCH v3 09/17] vfio/common: Change vfio_devices_all_running_and_saving() logic to equivalent one, Avihai Horon, 2022/11/03
[PATCH v3 12/17] vfio/migration: Implement VFIO migration protocol v2, Avihai Horon, 2022/11/03