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

From: Cédric Le Goater
Date: Thu May 11 2023 - 03:33:22 EST


On 5/10/23 22:41, Jason Gunthorpe wrote:
On Mon, May 08, 2023 at 02:57:15PM -0600, Alex Williamson wrote:

We already try to set the flags in advance, but there are some
architectural flags like VM_PAT that make that tricky. Cedric has been
looking at inserting individual pages with vmf_insert_pfn(), but that
incurs a lot more faults and therefore latency vs remapping the entire
vma on fault. I'm not convinced that we shouldn't just attempt to
remove the fault handler entirely, but I haven't tried it yet to know
what gotchas are down that path. Thanks,

OTOH I didn't see any noticeable slowdowns in the tests I did with
NICs, IGD and NVIDIA GPU pass-through. I lack devices with large
BARs though. If anyone has some time for it, here are commits :

https://github.com/legoater/linux/commits/vfio

First does a one page insert and fixes the lockdep issues we are
seeing with the recent series:

https://lore.kernel.org/all/20230126193752.297968-1-surenb@xxxxxxxxxx/

Second adds some statistics. For the NVIDIA GPU, faults reach 800k.

Thanks,

C.

I thought we did it like this because there were races otherwise with
PTE insertion and zapping? I don't remember well anymore.

I vaugely remember the address_space conversion might help remove the
fault handler?

Jason