History

iommufd: Add IOMMU_HWPT_GET_DIRTY_BITMAP

Connect a hw_pagetable to the IOMMU core dirty tracking read_and_clear_dirty iommu domain op. It exposes all of the functionality for the UAPI that read the dirtied IOVAs while clearing the Dirty bits from the PTEs. In doing so, add an IO pagetable API iopt_read_and_clear_dirty_data() that performs the reading of dirty IOPTEs for a given IOVA range and then copying back to userspace bitmap. Underneath it uses the IOMMU domain kernel API which will read the dirty bits, as well as atomically clearing the IOPTE dirty bit and flushing the IOTLB at the end. The IOVA bitmaps usage takes care of the iteration of the bitmaps user pages efficiently and without copies. Within the iterator function we iterate over io-pagetable contigous areas that have been mapped. Contrary to past incantation of a similar interface in VFIO the IOVA range to be scanned is tied in to the bitmap size, thus the application needs to pass a appropriately sized bitmap address taking into account the iova range being passed *and* page size ... as opposed to allowing bitmap-iova != iova.

Joao Martins committed 3 years ago

Commit b9a60d61 parent e2a4b295 files · +184 −0Browse files

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

Unified · Split

include/uapi/linux/iommufd.h+35−0
@@ -48,6 +48,7 @@ enum { · 47 unmodified lines
4848 IOMMUFD_CMD_HWPT_ALLOC,
4949 IOMMUFD_CMD_GET_HW_INFO,
5050 IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING,
51+ IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP,
5152 };
5253
5354 /**
@@ -481,4 +482,38 @@ struct iommu_hwpt_set_dirty_tracking { · 427 unmodified lines
481482 };
482483 #define IOMMU_HWPT_SET_DIRTY_TRACKING _IO(IOMMUFD_TYPE, \
483484 IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING)
485+
486+/**
487+ * struct iommu_hwpt_get_dirty_bitmap - ioctl(IOMMU_HWPT_GET_DIRTY_BITMAP)
488+ * @size: sizeof(struct iommu_hwpt_get_dirty_bitmap)
489+ * @hwpt_id: HW pagetable ID that represents the IOMMU domain
490+ * @flags: Must be zero
491+ * @__reserved: Must be 0
492+ * @iova: base IOVA of the bitmap first bit
493+ * @length: IOVA range size
494+ * @page_size: page size granularity of each bit in the bitmap
495+ * @data: bitmap where to set the dirty bits. The bitmap bits each
496+ * represent a page_size which you deviate from an arbitrary iova.
497+ *
498+ * Checking a given IOVA is dirty:
499+ *
500+ * data[(iova / page_size) / 64] & (1ULL << ((iova / page_size) % 64))
501+ *
502+ * Walk the IOMMU pagetables for a given IOVA range to return a bitmap
503+ * with the dirty IOVAs. In doing so it will also by default clear any
504+ * dirty bit metadata set in the IOPTE.
505+ */
506+struct iommu_hwpt_get_dirty_bitmap {
507+ __u32 size;
508+ __u32 hwpt_id;
509+ __u32 flags;
510+ __u32 __reserved;
511+ __aligned_u64 iova;
512+ __aligned_u64 length;
513+ __aligned_u64 page_size;
514+ __aligned_u64 data;
515+};
516+#define IOMMU_HWPT_GET_DIRTY_BITMAP _IO(IOMMUFD_TYPE, \
517+ IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP)
518+
484519 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t