This series expands IOMMUFD series from Yi and Eric into supporting IOMMU Dirty Tracking. It adds both the emulated x86 IOMMUs, as well as IOMMUFD support that exercises said emulation (or H/W). It is organized into: * Patches 1 - 4: x86 IOMMU emulation that performs dirty tracking, useful for a nested guest exercising the IOMMUFD kernel counterpart for coverage and development. The caching of the PASID PTE root flags and AMD DTE is not exactly the cleanest, still wondering about a better way without having to lookup context/DTE prior to IOTLB lookup. * Patches 5 - 9: IOMMUFD backend support for dirty tracking; Sadly this wasn't exactly tested with VF Live Migration, but it adds (last 2 patches) a way to measure dirty rate via HMP and QMP. The IOMMUFD kernel patches go into extent on what each of the ioctls do, albeit the workflow is relatively simple: 1) Toggling dirty tracking via HWPT_SET_DIRTY or get -ENOTSUPP otherwise which voids any attempt of walking IO pagetables 2) Read-and-clear of Dirty IOVAs 3) Unmap vIOMMU-backed IOVAs and fetch its dirty state right-before-unmap. The series is still a WIP. The intend is to exercise the kernel side[0] aside from the selftests that provide some coverage. Comments, feedback, as always appreciated. Joao [0] https://lore.kernel.org/linux-iommu/20220428210933.3583-1-joao.m.martins@xxxxxxxxxx/ Joao Martins (10): amd-iommu: Cache PTE/DTE info in IOTLB amd-iommu: Access/Dirty bit support intel-iommu: Cache PASID entry flags intel_iommu: Second Stage Access Dirty bit support linux-headers: import iommufd.h hwpt extensions vfio/iommufd: Add HWPT_SET_DIRTY support vfio/iommufd: Add HWPT_GET_DIRTY_IOVA support vfio/iommufd: Add IOAS_UNMAP_DIRTY support migration/dirtyrate: Expand dirty_bitmap to be tracked separately for devices hw/vfio: Add nr of dirty pages to tracepoints accel/kvm/kvm-all.c | 12 +++ hmp-commands.hx | 5 +- hw/i386/amd_iommu.c | 76 +++++++++++++- hw/i386/amd_iommu.h | 11 +- hw/i386/intel_iommu.c | 103 +++++++++++++++++-- hw/i386/intel_iommu_internal.h | 4 + hw/i386/trace-events | 4 + hw/iommufd/iommufd.c | 63 ++++++++++++ hw/iommufd/trace-events | 3 + hw/vfio/container.c | 20 +++- hw/vfio/iommufd.c | 179 ++++++++++++++++++++++++++++++++- hw/vfio/trace-events | 3 +- include/exec/memory.h | 10 +- include/hw/i386/intel_iommu.h | 1 + include/hw/iommufd/iommufd.h | 6 ++ linux-headers/linux/iommufd.h | 78 ++++++++++++++ migration/dirtyrate.c | 59 ++++++++--- migration/dirtyrate.h | 1 + qapi/migration.json | 15 +++ softmmu/memory.c | 5 + 20 files changed, 618 insertions(+), 40 deletions(-) -- 2.17.2