Skip to content

Commit b704fd1

Browse files
Kirti Wankhedeawilliam
authored andcommitted
vfio iommu: Add ioctl definition for dirty pages tracking
IOMMU container maintains a list of all pages pinned by vfio_pin_pages API. All pages pinned by vendor driver through this API should be considered as dirty during migration. When container consists of IOMMU capable device and all pages are pinned and mapped, then all pages are marked dirty. Added support to start/stop dirtied pages tracking and to get bitmap of all dirtied pages for requested IO virtual address range. Signed-off-by: Kirti Wankhede <[email protected]> Reviewed-by: Neo Jia <[email protected]> Reviewed-by: Cornelia Huck <[email protected]> Reviewed-by: Yan Zhao <[email protected]> Signed-off-by: Alex Williamson <[email protected]>
1 parent cade075 commit b704fd1

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

include/uapi/linux/vfio.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,12 @@ struct vfio_iommu_type1_dma_map {
10331033

10341034
#define VFIO_IOMMU_MAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 13)
10351035

1036+
struct vfio_bitmap {
1037+
__u64 pgsize; /* page size for bitmap in bytes */
1038+
__u64 size; /* in bytes */
1039+
__u64 __user *data; /* one bit per page */
1040+
};
1041+
10361042
/**
10371043
* VFIO_IOMMU_UNMAP_DMA - _IOWR(VFIO_TYPE, VFIO_BASE + 14,
10381044
* struct vfio_dma_unmap)
@@ -1059,6 +1065,57 @@ struct vfio_iommu_type1_dma_unmap {
10591065
#define VFIO_IOMMU_ENABLE _IO(VFIO_TYPE, VFIO_BASE + 15)
10601066
#define VFIO_IOMMU_DISABLE _IO(VFIO_TYPE, VFIO_BASE + 16)
10611067

1068+
/**
1069+
* VFIO_IOMMU_DIRTY_PAGES - _IOWR(VFIO_TYPE, VFIO_BASE + 17,
1070+
* struct vfio_iommu_type1_dirty_bitmap)
1071+
* IOCTL is used for dirty pages logging.
1072+
* Caller should set flag depending on which operation to perform, details as
1073+
* below:
1074+
*
1075+
* Calling the IOCTL with VFIO_IOMMU_DIRTY_PAGES_FLAG_START flag set, instructs
1076+
* the IOMMU driver to log pages that are dirtied or potentially dirtied by
1077+
* the device; designed to be used when a migration is in progress. Dirty pages
1078+
* are logged until logging is disabled by user application by calling the IOCTL
1079+
* with VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP flag.
1080+
*
1081+
* Calling the IOCTL with VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP flag set, instructs
1082+
* the IOMMU driver to stop logging dirtied pages.
1083+
*
1084+
* Calling the IOCTL with VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP flag set
1085+
* returns the dirty pages bitmap for IOMMU container for a given IOVA range.
1086+
* The user must specify the IOVA range and the pgsize through the structure
1087+
* vfio_iommu_type1_dirty_bitmap_get in the data[] portion. This interface
1088+
* supports getting a bitmap of the smallest supported pgsize only and can be
1089+
* modified in future to get a bitmap of any specified supported pgsize. The
1090+
* user must provide a zeroed memory area for the bitmap memory and specify its
1091+
* size in bitmap.size. One bit is used to represent one page consecutively
1092+
* starting from iova offset. The user should provide page size in bitmap.pgsize
1093+
* field. A bit set in the bitmap indicates that the page at that offset from
1094+
* iova is dirty. The caller must set argsz to a value including the size of
1095+
* structure vfio_iommu_type1_dirty_bitmap_get, but excluding the size of the
1096+
* actual bitmap. If dirty pages logging is not enabled, an error will be
1097+
* returned.
1098+
*
1099+
* Only one of the flags _START, _STOP and _GET may be specified at a time.
1100+
*
1101+
*/
1102+
struct vfio_iommu_type1_dirty_bitmap {
1103+
__u32 argsz;
1104+
__u32 flags;
1105+
#define VFIO_IOMMU_DIRTY_PAGES_FLAG_START (1 << 0)
1106+
#define VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP (1 << 1)
1107+
#define VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP (1 << 2)
1108+
__u8 data[];
1109+
};
1110+
1111+
struct vfio_iommu_type1_dirty_bitmap_get {
1112+
__u64 iova; /* IO virtual address */
1113+
__u64 size; /* Size of iova range */
1114+
struct vfio_bitmap bitmap;
1115+
};
1116+
1117+
#define VFIO_IOMMU_DIRTY_PAGES _IO(VFIO_TYPE, VFIO_BASE + 17)
1118+
10621119
/* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */
10631120

10641121
/*

0 commit comments

Comments
 (0)