Re: [PATCH] vfio/pci: take mmap write lock for io_remap_pfn_range

From: Andrew Jones
Date: Wed May 22 2024 - 12:56:44 EST


On Mon, May 08, 2023 at 08:58:42PM GMT, Yan Zhao wrote:
> In VFIO type1, vaddr_get_pfns() will try fault in MMIO PFNs after
> pin_user_pages_remote() returns -EFAULT.
>
> follow_fault_pfn
> fixup_user_fault
> handle_mm_fault
> handle_mm_fault
> do_fault
> do_shared_fault
> do_fault
> __do_fault
> vfio_pci_mmap_fault
> io_remap_pfn_range
> remap_pfn_range
> track_pfn_remap
> vm_flags_set ==> mmap_assert_write_locked(vma->vm_mm)
> remap_pfn_range_notrack
> vm_flags_set ==> mmap_assert_write_locked(vma->vm_mm)
>
> As io_remap_pfn_range() will call vm_flags_set() to update vm_flags [1],
> holding of mmap write lock is required.
> So, update vfio_pci_mmap_fault() to drop mmap read lock and take mmap
> write lock.
>
> [1] https://lkml.kernel.org/r/20230126193752.297968-3-surenb@xxxxxxxxxx
> commit bc292ab00f6c ("mm: introduce vma->vm_flags wrapper functions")
> commit 1c71222e5f23
> ("mm: replace vma->vm_flags direct modifications with modifier calls")
>

With linux-next I started noticing traces similar to the above without
lockdep, since it has ba168b52bf8e ("mm: use rwsem assertion macros for
mmap_lock"). Were there any follow ups to this? Sorry if my quick
searching missed it.

Thanks,
drew