patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] Initial DMABUF support for iommufd
@ 2025-11-07 16:49 Jason Gunthorpe
  2025-11-07 16:49 ` [PATCH 1/9] vfio/pci: Add vfio_pci_dma_buf_iommufd_map() Jason Gunthorpe
                   ` (10 more replies)
  0 siblings, 11 replies; 45+ messages in thread
From: Jason Gunthorpe @ 2025-11-07 16:49 UTC (permalink / raw)
  To: Alex Williamson, Christian König, dri-devel, iommu,
	Joerg Roedel, Kevin Tian, kvm, linaro-mm-sig, linux-kselftest,
	linux-media, Robin Murphy, Shuah Khan, Sumit Semwal, Will Deacon
  Cc: Krishnakant Jaju, Leon Romanovsky, Matt Ochs, Nicolin Chen,
	patches, Simona Vetter, Vivek Kasireddy, Xu Yilun

This series is the start of adding full DMABUF support to
iommufd. Currently it is limited to only work with VFIO's DMABUF exporter.
It sits on top of Leon's series to add a DMABUF exporter to VFIO:

  https://lore.kernel.org/r/20251106-dmabuf-vfio-v7-0-2503bf390699@nvidia.com

The existing IOMMU_IOAS_MAP_FILE is enhanced to detect DMABUF fd's, but
otherwise works the same as it does today for a memfd. The user can select
a slice of the FD to map into the ioas and if the underliyng alignment
requirements are met it will be placed in the iommu_domain.

Though limited, it is enough to allow a VMM like QEMU to connect MMIO BAR
memory from VFIO to an iommu_domain controlled by iommufd. This is used
for PCI Peer to Peer support in VMs, and is the last feature that the VFIO
type 1 container has that iommufd couldn't do.

The VFIO type1 version extracts raw PFNs from VMAs, which has no lifetime
control and is a use-after-free security problem.

Instead iommufd relies on revokable DMABUFs. Whenever VFIO thinks there
should be no access to the MMIO it can shoot down the mapping in iommufd
which will unmap it from the iommu_domain. There is no automatic remap,
this is a safety protocol so the kernel doesn't get stuck. Userspace is
expected to know it is doing something that will revoke the dmabuf and
map/unmap it around the activity. Eg when QEMU goes to issue FLR it should
do the map/unmap to iommufd.

Since DMABUF is missing some key general features for this use case it
relies on a "private interconnect" between VFIO and iommufd via the
vfio_pci_dma_buf_iommufd_map() call.

The call confirms the DMABUF has revoke semantics and delivers a phys_addr
for the memory suitable for use with iommu_map().

Medium term there is a desire to expand the supported DMABUFs to include
GPU drivers to support DPDK/SPDK type use cases so future series will work
to add a general concept of revoke and a general negotiation of
interconnect to remove vfio_pci_dma_buf_iommufd_map().

I also plan another series to modify iommufd's vfio_compat to
transparently pull a dmabuf out of a VFIO VMA to emulate more of the uAPI
of type1.

The latest series for interconnect negotation to exchange a phys_addr is:
 https://lore.kernel.org/r/20251027044712.1676175-1-vivek.kasireddy@intel.com

And the discussion for design of revoke is here:
 https://lore.kernel.org/dri-devel/20250114173103.GE5556@nvidia.com/

This is on github: https://github.com/jgunthorpe/linux/commits/iommufd_dmabuf

v2:
 - Rebase on Leon's v7
 - Fix mislocking in an iopt_fill_domain() error path
v1: https://patch.msgid.link/r/0-v1-64bed2430cdb+31b-iommufd_dmabuf_jgg@nvidia.com

Jason Gunthorpe (9):
  vfio/pci: Add vfio_pci_dma_buf_iommufd_map()
  iommufd: Add DMABUF to iopt_pages
  iommufd: Do not map/unmap revoked DMABUFs
  iommufd: Allow a DMABUF to be revoked
  iommufd: Allow MMIO pages in a batch
  iommufd: Have pfn_reader process DMABUF iopt_pages
  iommufd: Have iopt_map_file_pages convert the fd to a file
  iommufd: Accept a DMABUF through IOMMU_IOAS_MAP_FILE
  iommufd/selftest: Add some tests for the dmabuf flow

 drivers/iommu/iommufd/io_pagetable.c          |  78 +++-
 drivers/iommu/iommufd/io_pagetable.h          |  53 ++-
 drivers/iommu/iommufd/ioas.c                  |   8 +-
 drivers/iommu/iommufd/iommufd_private.h       |  14 +-
 drivers/iommu/iommufd/iommufd_test.h          |  10 +
 drivers/iommu/iommufd/main.c                  |  10 +
 drivers/iommu/iommufd/pages.c                 | 407 ++++++++++++++++--
 drivers/iommu/iommufd/selftest.c              | 142 ++++++
 drivers/vfio/pci/vfio_pci_dmabuf.c            |  34 ++
 include/linux/vfio_pci_core.h                 |   4 +
 tools/testing/selftests/iommu/iommufd.c       |  43 ++
 tools/testing/selftests/iommu/iommufd_utils.h |  44 ++
 12 files changed, 781 insertions(+), 66 deletions(-)


base-commit: bb04e92c86b44b3e36532099b68de1e889acfee7
-- 
2.43.0


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

end of thread, other threads:[~2025-11-21 14:33 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-07 16:49 [PATCH 0/9] Initial DMABUF support for iommufd Jason Gunthorpe
2025-11-07 16:49 ` [PATCH 1/9] vfio/pci: Add vfio_pci_dma_buf_iommufd_map() Jason Gunthorpe
2025-11-20  7:49   ` Tian, Kevin
2025-11-20 17:34   ` Nicolin Chen
2025-11-07 16:49 ` [PATCH 2/9] iommufd: Add DMABUF to iopt_pages Jason Gunthorpe
2025-11-07 18:02   ` Nicolin Chen
2025-11-20  7:55   ` Tian, Kevin
2025-11-21 14:27     ` Jason Gunthorpe
2025-11-07 16:49 ` [PATCH 3/9] iommufd: Do not map/unmap revoked DMABUFs Jason Gunthorpe
2025-11-07 18:30   ` Nicolin Chen
2025-11-20  7:56   ` Tian, Kevin
2025-11-07 16:49 ` [PATCH 4/9] iommufd: Allow a DMABUF to be revoked Jason Gunthorpe
2025-11-13 23:26   ` Nicolin Chen
2025-11-20  7:58   ` Tian, Kevin
2025-11-07 16:49 ` [PATCH 5/9] iommufd: Allow MMIO pages in a batch Jason Gunthorpe
2025-11-13 23:28   ` Nicolin Chen
2025-11-20  7:59   ` Tian, Kevin
2025-11-20 14:59     ` Jason Gunthorpe
2025-11-07 16:49 ` [PATCH 6/9] iommufd: Have pfn_reader process DMABUF iopt_pages Jason Gunthorpe
2025-11-13 23:39   ` Nicolin Chen
2025-11-18 19:38     ` Jason Gunthorpe
2025-11-20  8:04   ` Tian, Kevin
2025-11-21  0:47     ` Jason Gunthorpe
2025-11-21 14:33       ` Jason Gunthorpe
2025-11-07 16:49 ` [PATCH 7/9] iommufd: Have iopt_map_file_pages convert the fd to a file Jason Gunthorpe
2025-11-13 23:43   ` Nicolin Chen
2025-11-20  8:05   ` Tian, Kevin
2025-11-07 16:49 ` [PATCH 8/9] iommufd: Accept a DMABUF through IOMMU_IOAS_MAP_FILE Jason Gunthorpe
2025-11-14  0:05   ` Nicolin Chen
2025-11-18 19:44     ` Jason Gunthorpe
2025-11-18 19:57       ` Nicolin Chen
2025-11-20  8:06   ` Tian, Kevin
2025-11-07 16:49 ` [PATCH 9/9] iommufd/selftest: Add some tests for the dmabuf flow Jason Gunthorpe
2025-11-07 19:43   ` Nicolin Chen
2025-11-18 19:25     ` Jason Gunthorpe
2025-11-20  8:06       ` Tian, Kevin
2025-11-07 17:52 ` [PATCH 0/9] Initial DMABUF support for iommufd Nicolin Chen
2025-11-13  6:33   ` Shuai Xue
2025-11-13  7:34     ` Nicolin Chen
2025-11-13 11:32       ` Shuai Xue
2025-11-13 17:44         ` Nicolin Chen
2025-11-13 18:37 ` Alex Williamson
2025-11-17 15:50   ` Jason Gunthorpe
2025-11-18  5:37     ` Kasireddy, Vivek
2025-11-18 14:59       ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).