History

vfio iommu: Update UNMAP_DMA ioctl to get dirty bitmap before unmap

DMA mapped pages, including those pinned by mdev vendor drivers, might get unpinned and unmapped while migration is active and device is still running. For example, in pre-copy phase while guest driver could access those pages, host device or vendor driver can dirty these mapped pages. Such pages should be marked dirty so as to maintain memory consistency for a user making use of dirty page tracking. To get bitmap during unmap, user should allocate memory for bitmap, set it all zeros, set size of allocated memory, set page size to be considered for bitmap and set flag VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP.

Kirti Wankhede committed 6 years ago

Commit 331e33d1 parent d6a4c182 files · +61 −11Browse files

Showing the changes to include/uapi/linux (1 of 2 files). Show all

Unified · Split

include/uapi/linux/vfio.h+11−0
@@ -1048,12 +1048,23 @@ struct vfio_bitmap { · 1047 unmodified lines
1048 * field. No guarantee is made to the user that arbitrary unmaps of iova1048 * field. No guarantee is made to the user that arbitrary unmaps of iova
1049 * or size different from those used in the original mapping call will1049 * or size different from those used in the original mapping call will
1050 * succeed.1050 * succeed.
1051 * VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP should be set to get the dirty bitmap
1052 * before unmapping IO virtual addresses. When this flag is set, the user must
1053 * provide a struct vfio_bitmap in data[]. User must provide zero-allocated
1054 * memory via vfio_bitmap.data and its size in the vfio_bitmap.size field.
1055 * A bit in the bitmap represents one page, of user provided page size in
1056 * vfio_bitmap.pgsize field, consecutively starting from iova offset. Bit set
1057 * indicates that the page at that offset from iova is dirty. A Bitmap of the
1058 * pages in the range of unmapped size is returned in the user-provided
1059 * vfio_bitmap.data.
1051 */1060 */
1052struct vfio_iommu_type1_dma_unmap {1061struct vfio_iommu_type1_dma_unmap {
1053 __u32 argsz;1062 __u32 argsz;
1054 __u32 flags;1063 __u32 flags;
1064#define VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP (1 << 0)
1055 __u64 iova; /* IO virtual address */1065 __u64 iova; /* IO virtual address */
1056 __u64 size; /* Size of mapping (bytes) */1066 __u64 size; /* Size of mapping (bytes) */
1067 __u8 data[];
1057};1068};
1058 1069
1059#define VFIO_IOMMU_UNMAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 14)1070#define VFIO_IOMMU_UNMAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 14)