public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfio/pci: Don't export DMABUFs for unmappable BARs
@ 2026-04-15 18:16 Matt Evans
  2026-04-15 18:23 ` Leon Romanovsky
  2026-04-16  8:11 ` Leon Romanovsky
  0 siblings, 2 replies; 9+ messages in thread
From: Matt Evans @ 2026-04-15 18:16 UTC (permalink / raw)
  To: Alex Williamson, Matt Evans, Leon Romanovsky, Jason Gunthorpe,
	Kevin Tian, Vivek Kasireddy, Ankit Agrawal
  Cc: kvm, linux-kernel

Although vfio_pci_core_feature_dma_buf() validates that both requested
DMABUF ranges and the PCI resources being referenced are page-aligned,
there may be reasons other than alignment that cause a BAR to be
unmappable.

Add a check for vdev->bar_mmap_supported[index], similar to the VFIO
mmap 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 | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c
index f87fd32e4a01..4ccaf3531e02 100644
--- a/drivers/vfio/pci/vfio_pci_dmabuf.c
+++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
@@ -249,6 +249,9 @@ int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,
 	if (get_dma_buf.region_index >= VFIO_PCI_ROM_REGION_INDEX)
 		return -ENODEV;
 
+	if (!vdev->bar_mmap_supported[get_dma_buf.region_index])
+		return -EINVAL;
+
 	dma_ranges = memdup_array_user(&arg->dma_ranges, get_dma_buf.nr_ranges,
 				       sizeof(*dma_ranges));
 	if (IS_ERR(dma_ranges))
-- 
2.47.3


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

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

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 18:16 [PATCH] vfio/pci: Don't export DMABUFs for unmappable BARs Matt Evans
2026-04-15 18:23 ` Leon Romanovsky
2026-04-16  8:11 ` Leon Romanovsky
2026-04-16 13:05   ` Matt Evans
2026-04-16 13:14     ` Leon Romanovsky
2026-04-16 18:03       ` Matt Evans
2026-04-16 21:48         ` Alex Williamson
2026-04-17 14:25           ` Matt Evans
2026-04-17 22:31             ` Alex Williamson

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