Skip to content

Commit

Permalink
vfio iommu: Add migration capability to report supported features
Browse files Browse the repository at this point in the history
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 <kwankhede@nvidia.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Yan Zhao <yan.y.zhao@intel.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
  • Loading branch information
Kirti Wankhede authored and awilliam committed May 28, 2020
1 parent 331e33d commit ad72170
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
23 changes: 22 additions & 1 deletion drivers/vfio/vfio_iommu_type1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,22 @@ static int vfio_iommu_iova_build_caps(struct vfio_iommu *iommu,
return ret;
}

static int vfio_iommu_migration_build_caps(struct vfio_iommu *iommu,
struct vfio_info_cap *caps)
{
struct vfio_iommu_type1_info_cap_migration cap_mig;

cap_mig.header.id = VFIO_IOMMU_TYPE1_INFO_CAP_MIGRATION;
cap_mig.header.version = 1;

cap_mig.flags = 0;
/* support minimum pgsize */
cap_mig.pgsize_bitmap = (size_t)1 << __ffs(iommu->pgsize_bitmap);
cap_mig.max_dirty_bitmap_size = DIRTY_BITMAP_SIZE_MAX;

return vfio_info_add_capability(caps, &cap_mig.header, sizeof(cap_mig));
}

static long vfio_iommu_type1_ioctl(void *iommu_data,
unsigned int cmd, unsigned long arg)
{
Expand Down Expand Up @@ -2469,8 +2485,13 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,

info.iova_pgsizes = iommu->pgsize_bitmap;

ret = vfio_iommu_iova_build_caps(iommu, &caps);
ret = vfio_iommu_migration_build_caps(iommu, &caps);

if (!ret)
ret = vfio_iommu_iova_build_caps(iommu, &caps);

mutex_unlock(&iommu->lock);

if (ret)
return ret;

Expand Down
23 changes: 23 additions & 0 deletions include/uapi/linux/vfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,29 @@ struct vfio_iommu_type1_info_cap_iova_range {
struct vfio_iova_range iova_ranges[];
};

/*
* The migration capability allows to report supported features for migration.
*
* The structures below define version 1 of this capability.
*
* The existence of this capability indicates that IOMMU kernel driver supports
* dirty page logging.
*
* pgsize_bitmap: Kernel driver returns bitmap of supported page sizes for dirty
* page logging.
* max_dirty_bitmap_size: Kernel driver returns maximum supported dirty bitmap
* size in bytes that can be used by user applications when getting the dirty
* bitmap.
*/
#define VFIO_IOMMU_TYPE1_INFO_CAP_MIGRATION 1

struct vfio_iommu_type1_info_cap_migration {
struct vfio_info_cap_header header;
__u32 flags;
__u64 pgsize_bitmap;
__u64 max_dirty_bitmap_size; /* in bytes */
};

#define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)

/**
Expand Down

0 comments on commit ad72170

Please sign in to comment.