v2: - Implement the changes as agreed in [0] - The redundant tests in vma_to_pfn() are removed as these are already performed in vfio_pci_core_mmap(). - The vma_to_pfn() function is updated to return the pfn directly (proposed void return in thread but this makes more sense). - Comment preceding vfio_pci_dev_set_hot_reset() is removed, comment in loop is updated as proposed. - Kept R-b as these are minor changes. [0]https://lore.kernel.org/all/BN9PR11MB5276289D3F06F90E3F9E71618CF32@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/ v1: Upstream commit ba168b52bf8e ("mm: use rwsem assertion macros for mmap_lock") changes a long standing lockdep issue where we call io_remap_pfn_range() from within the vm_ops fault handler callback without the proper write lock[1], generating a WARN_ON that we can no longer stall to fix. Attaching an address space to the vfio device file has been discussed for some time as a way to make use of unmap_mapping_range(), which provides an easy mechanism for zapping all vmas mapping a section of the device file, for example mmaps to PCI BARs. This means that we no longer need to track those vmas for the purpose of zapping, which removes a bunch of really ugly locking. This vma list was also used to avoid duplicate mappings for concurrent faults to the same vma. As a result, we now use the more acceptable vmf_insert_pfn() which actually manages locking correctly from the fault handler versus io_remap_pfn_range(). The unfortunate side effect of this is that we now fault per page rather than populate the entire vma with a single fault. While this overhead is fairly insignificant for average BAR sizes, it is notable. There's potentially quite ugly code we could use to walk the vmas in the address space to proactively reinsert mappings to avoid this, but the simpler solution seems to be to teach vmf_insert_pfn_{pmd,pud}() about pfnmaps such that we can extend the faulting behavior to include vm_ops huge_fault to both vastly reduce the number of faults as well as reducing tlb usage. The above commit seems to require an iterative solution where we introduce the address space, remove the vma tracking, and make use of vmf_insert_pfn() in the short term and work on the mm aspects to enable huge_fault in the long term. This series is intended for v6.10 given the WARN_ON now encountered for all vfio-pci uses. Thanks, Alex [1]https://lore.kernel.org/all/20230508125842.28193-1-yan.y.zhao@xxxxxxxxx/ Alex Williamson (2): vfio: Create vfio_fs_type with inode per device vfio/pci: Use unmap_mapping_range() drivers/vfio/device_cdev.c | 7 + drivers/vfio/group.c | 7 + drivers/vfio/pci/vfio_pci_core.c | 264 +++++++------------------------ drivers/vfio/vfio_main.c | 44 ++++++ include/linux/vfio.h | 1 + include/linux/vfio_pci_core.h | 2 - 6 files changed, 114 insertions(+), 211 deletions(-) -- 2.45.0