public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] vfio/pci: Request resources and map BARs at enable time
@ 2026-04-23 18:25 Matt Evans
  2026-04-23 18:25 ` [PATCH v2 1/3] vfio/pci: Set up bar resources and maps in vfio_pci_core_enable() Matt Evans
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Matt Evans @ 2026-04-23 18:25 UTC (permalink / raw)
  To: Alex Williamson, Kevin Tian, Jason Gunthorpe, Ankit Agrawal,
	Alistair Popple, Leon Romanovsky, Kees Cook, Shameer Kolothum,
	Yishai Hadas
  Cc: Alexey Kardashevskiy, Eric Auger, Peter Xu, Vivek Kasireddy,
	Zhi Wang, kvm, linux-kernel, virtualization

Hi,

This is a replacement for these patches posted to set up the
VFIO barmap in the DMABUF export path, and add serialisation:

 https://lore.kernel.org/kvm/20260415181423.1008458-1-mattev@meta.com

Those patches were motivated by the DMABUF export originally missing a
call to vfio_pci_core_setup_barmap() and so possibly exporting a range
for which resources weren't yet requested.

Responses in the thread indicated there wasn't a strong historical
reason to require the bar-mapping to be performed on-demand at BAR
reference time.  It's much simpler to move this to
vfio_pci_core_enable(), and that then avoids having to deal with
concurrent lazy requests.

The first patch requests PCI resources and pci_iomap() of the BARs in
vfio_pci_core_enable(), moving this out of
vfio_pci_core_setup_barmap().

Some callers relied on vfio_pci_core_setup_barmap() for its ioremap()
effect, and other callers use it for its resource-acquiring effect.
The function remains in the first patch, containing a cheap check that
both these actions have occurred and keeping the same error behaviour.

The second patch then removes calls to vfio_pci_core_setup_barmap(),
in favour of two small helper functions which make it clearer to
distinguish code that needs just the resource (e.g. mmap) and code
that needs the iomap as well (e.g. the rdwr routines, or virtio).

The third patch adds the resource check to VFIO DMABUF export, which
was previously able to export an unrequested resource.  Although patch
1 at first appears to fix this by requesting resources at enable time,
code using the BAR still needs to check the resource really was
acquired.

In future we could reconsider performing all the ioremap()s at startup
time, since a lot of VFIO users will never access BARs in-kernel and
won't need them.  Mapping huge BARs will cost some time & memory, and
if necessary this could be reduced by doing the ioremap() portion on
demand.

=== Changes ===

v2:

 - Don't fail if resources can't be requested or iomapped, even for
   valid BARs, as this would change the userspace-observable error
   behaviour.  Specifically, if there was an issue with one particular
   BAR which happened to never be used, then userspace would never
   encounter an error for it.  Track iomap and resource-acquisition
   status per BAR.

 - Break out the checks for resource success from those for iomap
   success, in the form of the two new helpers.

 - Third patch to add the check to VFIO DMABUF export, because
   init-time requests can now fail.

v1:
  https://lore.kernel.org/kvm/20260421174143.3883579-1-mattev@meta.com/

Matt Evans (3):
  vfio/pci: Set up bar resources and maps in vfio_pci_core_enable()
  vfio/pci: Replace vfio_pci_core_setup_barmap() with checks for
    resource/map
  vfio/pci: Check BAR resources before exporting a DMABUF

 drivers/vfio/pci/nvgrace-gpu/main.c |  8 ++--
 drivers/vfio/pci/vfio_pci_core.c    | 66 +++++++++++++++++++++++------
 drivers/vfio/pci/vfio_pci_dmabuf.c  |  6 ++-
 drivers/vfio/pci/vfio_pci_rdwr.c    | 29 +------------
 drivers/vfio/pci/virtio/legacy_io.c |  4 +-
 include/linux/vfio_pci_core.h       | 24 ++++++++++-
 6 files changed, 88 insertions(+), 49 deletions(-)

-- 
2.47.3


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-04-23 21:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-23 18:25 [PATCH v2 0/3] vfio/pci: Request resources and map BARs at enable time Matt Evans
2026-04-23 18:25 ` [PATCH v2 1/3] vfio/pci: Set up bar resources and maps in vfio_pci_core_enable() Matt Evans
2026-04-23 21:30   ` Alex Williamson
2026-04-23 18:25 ` [PATCH v2 2/3] vfio/pci: Replace vfio_pci_core_setup_barmap() with checks for resource/map Matt Evans
2026-04-23 21:30   ` Alex Williamson
2026-04-23 18:25 ` [PATCH v2 3/3] vfio/pci: Check BAR resources before exporting a DMABUF Matt Evans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox