public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] vfio/pci: Set up VFIO barmap before creating a DMABUF
@ 2026-04-15 18:14 Matt Evans
  2026-04-15 18:14 ` [PATCH 2/2] vfio/pci: Serialise vfio_pci_core_setup_barmap() Matt Evans
  2026-04-16 22:44 ` [PATCH 1/2] vfio/pci: Set up VFIO barmap before creating a DMABUF Alex Williamson
  0 siblings, 2 replies; 5+ messages in thread
From: Matt Evans @ 2026-04-15 18:14 UTC (permalink / raw)
  To: Alex Williamson, Ankit Agrawal, Jason Gunthorpe, Yishai Hadas,
	Shameer Kolothum, Kevin Tian
  Cc: Alistair Popple, Leon Romanovsky, Vivek Kasireddy, Kees Cook,
	Zhi Wang, Peter Xu, Alexey Kardashevskiy, Eric Auger, kvm,
	linux-kernel, virtualization

A DMABUF exports access to BAR resources which need to be requested
before the DMABUF is handed out.  Usually the resources are requested
when setting up the barmap when the VFIO device fd is mmap()ed, but
there's no guarantee that's done before a DMABUF is created.

Set up the barmap (and so request resources) in the DMABUF-creation
path.

Fixes: 5d74781ebc86c ("vfio/pci: Add dma-buf export support for MMIO regions")
Signed-off-by: Matt Evans <mattev@meta.com>
---
 drivers/vfio/pci/vfio_pci_dmabuf.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c
index 4ccaf3531e02..fefe7cf4256b 100644
--- a/drivers/vfio/pci/vfio_pci_dmabuf.c
+++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
@@ -272,6 +272,15 @@ int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,
 		goto err_free_priv;
 	}
 
+	/*
+	 * See comment in vfio_pci_core_mmap(); ensure PCI regions
+	 * were requested before returning DMABUFs that reference
+	 * them.  Barmap setup does this:
+	 */
+	ret = vfio_pci_core_setup_barmap(vdev, get_dma_buf.region_index);
+	if (ret)
+		goto err_free_phys;
+
 	priv->vdev = vdev;
 	priv->nr_ranges = get_dma_buf.nr_ranges;
 	priv->size = length;
-- 
2.47.3


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

end of thread, other threads:[~2026-04-17 19:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 18:14 [PATCH 1/2] vfio/pci: Set up VFIO barmap before creating a DMABUF Matt Evans
2026-04-15 18:14 ` [PATCH 2/2] vfio/pci: Serialise vfio_pci_core_setup_barmap() Matt Evans
2026-04-16 22:44 ` [PATCH 1/2] vfio/pci: Set up VFIO barmap before creating a DMABUF Alex Williamson
2026-04-17  5:16   ` Tian, Kevin
2026-04-17 19:11     ` Matt Evans

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