Skip to content

Commit 9e43e61

Browse files
author
Alex Williamson
committed
vfio: Add an option to get migration data size
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2158549 Conflicts: Partial, RHEL does not currently include hisi_acc or mlx5 vfio-pci variant drivers. Context, DMA dirty logging feature support via 80c4b92 ("vfio: Introduce the DMA logging feature support") not yet included. commit 4e016f9 Author: Yishai Hadas <yishaih@nvidia.com> Date: Sun Nov 6 19:46:18 2022 +0200 vfio: Add an option to get migration data size Add an option to get migration data size by introducing a new migration feature named VFIO_DEVICE_FEATURE_MIG_DATA_SIZE. Upon VFIO_DEVICE_FEATURE_GET the estimated data length that will be required to complete STOP_COPY is returned. This option may better enable user space to consider before moving to STOP_COPY whether it can meet the downtime SLA based on the returned data. The patch also includes the implementation for mlx5 and hisi for this new option to make it feature complete for the existing drivers in this area. Signed-off-by: Yishai Hadas <yishaih@nvidia.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Longfang Liu <liulongfang@huawei.com> Link: https://lore.kernel.org/r/20221106174630.25909-2-yishaih@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 8cd76f7 commit 9e43e61

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

drivers/vfio/pci/vfio_pci_core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,8 @@ int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev)
18651865

18661866
if (vdev->vdev.mig_ops) {
18671867
if (!(vdev->vdev.mig_ops->migration_get_state &&
1868-
vdev->vdev.mig_ops->migration_set_state) ||
1868+
vdev->vdev.mig_ops->migration_set_state &&
1869+
vdev->vdev.mig_ops->migration_get_data_size) ||
18691870
!(vdev->vdev.migration_flags & VFIO_MIGRATION_STOP_COPY))
18701871
return -EINVAL;
18711872
}

drivers/vfio/vfio_main.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,34 @@ vfio_ioctl_device_feature_mig_device_state(struct vfio_device *device,
16301630
return 0;
16311631
}
16321632

1633+
static int
1634+
vfio_ioctl_device_feature_migration_data_size(struct vfio_device *device,
1635+
u32 flags, void __user *arg,
1636+
size_t argsz)
1637+
{
1638+
struct vfio_device_feature_mig_data_size data_size = {};
1639+
unsigned long stop_copy_length;
1640+
int ret;
1641+
1642+
if (!device->mig_ops)
1643+
return -ENOTTY;
1644+
1645+
ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET,
1646+
sizeof(data_size));
1647+
if (ret != 1)
1648+
return ret;
1649+
1650+
ret = device->mig_ops->migration_get_data_size(device, &stop_copy_length);
1651+
if (ret)
1652+
return ret;
1653+
1654+
data_size.stop_copy_length = stop_copy_length;
1655+
if (copy_to_user(arg, &data_size, sizeof(data_size)))
1656+
return -EFAULT;
1657+
1658+
return 0;
1659+
}
1660+
16331661
static int vfio_ioctl_device_feature_migration(struct vfio_device *device,
16341662
u32 flags, void __user *arg,
16351663
size_t argsz)
@@ -1684,6 +1712,10 @@ static int vfio_ioctl_device_feature(struct vfio_device *device,
16841712
return vfio_ioctl_device_feature_mig_device_state(
16851713
device, feature.flags, arg->data,
16861714
feature.argsz - minsz);
1715+
case VFIO_DEVICE_FEATURE_MIG_DATA_SIZE:
1716+
return vfio_ioctl_device_feature_migration_data_size(
1717+
device, feature.flags, arg->data,
1718+
feature.argsz - minsz);
16871719
default:
16881720
if (unlikely(!device->ops->device_feature))
16891721
return -EINVAL;

include/linux/vfio.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,18 @@ struct vfio_device_ops {
9999
* @migration_get_state: Optional callback to get the migration state for
100100
* devices that support migration. It's mandatory for
101101
* VFIO_DEVICE_FEATURE_MIGRATION migration support.
102+
* @migration_get_data_size: Optional callback to get the estimated data
103+
* length that will be required to complete stop copy. It's mandatory for
104+
* VFIO_DEVICE_FEATURE_MIGRATION migration support.
102105
*/
103106
struct vfio_migration_ops {
104107
struct file *(*migration_set_state)(
105108
struct vfio_device *device,
106109
enum vfio_device_mig_state new_state);
107110
int (*migration_get_state)(struct vfio_device *device,
108111
enum vfio_device_mig_state *curr_state);
112+
int (*migration_get_data_size)(struct vfio_device *device,
113+
unsigned long *stop_copy_length);
109114
};
110115

111116
/**

include/uapi/linux/vfio.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,19 @@ enum vfio_device_mig_state {
986986
VFIO_DEVICE_STATE_RUNNING_P2P = 5,
987987
};
988988

989+
/*
990+
* Upon VFIO_DEVICE_FEATURE_GET read back the estimated data length that will
991+
* be required to complete stop copy.
992+
*
993+
* Note: Can be called on each device state.
994+
*/
995+
996+
struct vfio_device_feature_mig_data_size {
997+
__aligned_u64 stop_copy_length;
998+
};
999+
1000+
#define VFIO_DEVICE_FEATURE_MIG_DATA_SIZE 9
1001+
9891002
/* -------- API for Type1 VFIO IOMMU -------- */
9901003

9911004
/**

0 commit comments

Comments
 (0)