Skip to content

Commit ad72170

Browse files
Kirti Wankhedeawilliam
authored andcommitted
vfio iommu: Add migration capability to report supported features
Added migration capability in IOMMU info chain. User application should check IOMMU info chain for migration capability to use dirty page tracking feature provided by kernel module. User application must check page sizes supported and maximum dirty bitmap size returned by this capability structure for ioctls used to get dirty bitmap. Signed-off-by: Kirti Wankhede <[email protected]> Reviewed-by: Cornelia Huck <[email protected]> Reviewed-by: Yan Zhao <[email protected]> Signed-off-by: Alex Williamson <[email protected]>
1 parent 331e33d commit ad72170

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

drivers/vfio/vfio_iommu_type1.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,22 @@ static int vfio_iommu_iova_build_caps(struct vfio_iommu *iommu,
24232423
return ret;
24242424
}
24252425

2426+
static int vfio_iommu_migration_build_caps(struct vfio_iommu *iommu,
2427+
struct vfio_info_cap *caps)
2428+
{
2429+
struct vfio_iommu_type1_info_cap_migration cap_mig;
2430+
2431+
cap_mig.header.id = VFIO_IOMMU_TYPE1_INFO_CAP_MIGRATION;
2432+
cap_mig.header.version = 1;
2433+
2434+
cap_mig.flags = 0;
2435+
/* support minimum pgsize */
2436+
cap_mig.pgsize_bitmap = (size_t)1 << __ffs(iommu->pgsize_bitmap);
2437+
cap_mig.max_dirty_bitmap_size = DIRTY_BITMAP_SIZE_MAX;
2438+
2439+
return vfio_info_add_capability(caps, &cap_mig.header, sizeof(cap_mig));
2440+
}
2441+
24262442
static long vfio_iommu_type1_ioctl(void *iommu_data,
24272443
unsigned int cmd, unsigned long arg)
24282444
{
@@ -2469,8 +2485,13 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
24692485

24702486
info.iova_pgsizes = iommu->pgsize_bitmap;
24712487

2472-
ret = vfio_iommu_iova_build_caps(iommu, &caps);
2488+
ret = vfio_iommu_migration_build_caps(iommu, &caps);
2489+
2490+
if (!ret)
2491+
ret = vfio_iommu_iova_build_caps(iommu, &caps);
2492+
24732493
mutex_unlock(&iommu->lock);
2494+
24742495
if (ret)
24752496
return ret;
24762497

include/uapi/linux/vfio.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,29 @@ struct vfio_iommu_type1_info_cap_iova_range {
10131013
struct vfio_iova_range iova_ranges[];
10141014
};
10151015

1016+
/*
1017+
* The migration capability allows to report supported features for migration.
1018+
*
1019+
* The structures below define version 1 of this capability.
1020+
*
1021+
* The existence of this capability indicates that IOMMU kernel driver supports
1022+
* dirty page logging.
1023+
*
1024+
* pgsize_bitmap: Kernel driver returns bitmap of supported page sizes for dirty
1025+
* page logging.
1026+
* max_dirty_bitmap_size: Kernel driver returns maximum supported dirty bitmap
1027+
* size in bytes that can be used by user applications when getting the dirty
1028+
* bitmap.
1029+
*/
1030+
#define VFIO_IOMMU_TYPE1_INFO_CAP_MIGRATION 1
1031+
1032+
struct vfio_iommu_type1_info_cap_migration {
1033+
struct vfio_info_cap_header header;
1034+
__u32 flags;
1035+
__u64 pgsize_bitmap;
1036+
__u64 max_dirty_bitmap_size; /* in bytes */
1037+
};
1038+
10161039
#define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
10171040

10181041
/**

0 commit comments

Comments
 (0)