Skip to content

Commit 68132b3

Browse files
committed
Merge tag 'vfio-v6.10-rc4' of https://github.com/awilliam/linux-vfio
Pull VFIO fixes from Alex Williamson: "Fix long standing lockdep issue of using remap_pfn_range() from the vfio-pci fault handler for mapping device MMIO. Commit ba168b5 ("mm: use rwsem assertion macros for mmap_lock") now exposes this as a warning forcing this to be addressed. remap_pfn_range() was used here to efficiently map the entire vma, but it really never should have been used in the fault handler and doesn't handle concurrency, which introduced complex locking. We also needed to track vmas mapping the device memory in order to zap those vmas when the memory is disabled resulting in a vma list. Instead of all that mess, setup an address space on the device fd such that we can use unmap_mapping_range() for zapping to avoid the tracking overhead and use the standard vmf_insert_pfn() to insert mappings on fault. For now we'll iterate the vma and opportunistically try to insert mappings for the entire vma. This aligns with typical use cases, but hopefully in the future we can drop the iterative approach and make use of huge_fault instead, once vmf_insert_pfn{pud,pmd}() learn to handle pfnmaps" * tag 'vfio-v6.10-rc4' of https://github.com/awilliam/linux-vfio: vfio/pci: Insert full vma on mmap'd MMIO fault vfio/pci: Use unmap_mapping_range() vfio: Create vfio_fs_type with inode per device
2 parents c286c21 + d71a989 commit 68132b3

File tree

6 files changed

+125
-207
lines changed

6 files changed

+125
-207
lines changed

drivers/vfio/device_cdev.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ int vfio_device_fops_cdev_open(struct inode *inode, struct file *filep)
3939

4040
filep->private_data = df;
4141

42+
/*
43+
* Use the pseudo fs inode on the device to link all mmaps
44+
* to the same address space, allowing us to unmap all vmas
45+
* associated to this device using unmap_mapping_range().
46+
*/
47+
filep->f_mapping = device->inode->i_mapping;
48+
4249
return 0;
4350

4451
err_put_registration:

drivers/vfio/group.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,13 @@ static struct file *vfio_device_open_file(struct vfio_device *device)
286286
*/
287287
filep->f_mode |= (FMODE_PREAD | FMODE_PWRITE);
288288

289+
/*
290+
* Use the pseudo fs inode on the device to link all mmaps
291+
* to the same address space, allowing us to unmap all vmas
292+
* associated to this device using unmap_mapping_range().
293+
*/
294+
filep->f_mapping = device->inode->i_mapping;
295+
289296
if (device->group->type == VFIO_NO_IOMMU)
290297
dev_warn(device->dev, "vfio-noiommu device opened by user "
291298
"(%s:%d)\n", current->comm, task_pid_nr(current));

0 commit comments

Comments
 (0)