mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RFC 00/16] dma-buf: Introduce dma_shared_buf and dma_addr_list to replace sg_table
@ 2026-12-01  7:06 Alistair Popple
  2026-12-01  7:06 ` [PATCH RFC 01/16] treewide: Rename dma_buf_(un)map_attachment() to dma_buf_(un)map_sgt() Alistair Popple
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: Alistair Popple @ 2026-12-01  7:06 UTC (permalink / raw)
  To: Karol Wachowski, Sumit Semwal, Christian König,
	Philipp Stanner, David Airlie, Simona Vetter, Rodrigo Vivi,
	Matthew Brost, Thomas Hellström, Jason Gunthorpe,
	Leon Romanovsky, Kees Cook, Gustavo A. R. Silva, Alex Williamson,
	Kevin Tian, Joerg Roedel (AMD),
	Will Deacon, Robin Murphy
  Cc: dri-devel, linux-media, linaro-mm-sig, intel-xe, linux-rdma,
	linux-kernel, linux-hardening, kvm, iommu, Alexey Kardashevskiy,
	Mina Almasry, Baolu Lu, chaitanyak, Dongwon Kim, Felix Kuehling,
	jhubbard, Karl Mehltretter, Vivek Kasireddy, Xu Yilun, zhipingz,
	Alistair Popple, Jason Gunthorpe

This series is an RFC to assist with figuring out a path forward for
removing the sg_table usage from dma-buf whilst also removing the
private interconnect hack in iommufd. This also allows iommufd to map
other dma-bufs. As this is a prototype of the design I have not fully
tested it nor polished all the details as I'd rather get general
agreement on the direction before spending too much time doing that.

It is a simplification of the dma mapping types series [1] following the
rough plan from [2] which was not immediately NACK'ed. Instead of trying
to solve both the data-type and buffer placement problem in a single
series it focusses on the data-types and the usage model for those.
Buffer placement can be dealt with at a later time.

The Intel Xe driver is converted to the new interfaces as an example of
how an importer and exporter can be converted to not use sg_table. Other
exporters are converted as well.

The basic flow of the patches is:

1) Introduce a dma_shared_buf data-type to represent a buffer that an
   exporter wants to share via dma-buf. This contains:

   a) A list of physical locations (PCIe MMIO or system RAM) to export.
   b) An optional P2PDMA provider only if PCIe MMIO.

2) Introduce a new dma_addr_list data-type that contains a list of the
   DMA ranges importers need to program hardware. For simplicity this
   contains fields the importer shouldn't see, but that could be fixed
   if we want to proceed with this design.

3) Add helpers to convert a dma_addr_list into a sg_table which allows
   unconverted importers to continue to function with converted
   exporters.

4) Add two new dma_buf_ops - map_dma_shared_buf() and
   unmap_dma_shared_buf() - which allows exporters to return the new
   data-type instead of a table.

5) Add functions dma_buf_map_dma_list() and dma_buf_unmap_dma_list()
   that converted/new importers supporting dma_addr_list use to create
   a mapping. This handles converting the results of unconverted
   sg_table exporters to the new format.

6) Convert some exporters (vfio/pci, RDMA/uverbs and Xe) to use the
   dma_shared_buf instead of sg_tables.

7) Let iommufd map dma_shared_buf through the dma-shared-buf core.

8) Convert an importer (Intel Xe) to map via the dma-shared-buf core as
   an example.

Once all the exporter and importer conversions are done this would
permit the removal of sg_table from dma-buf entirely.

Overall I think this ends up being quite nice, and I _think_ other than
where mapping happens it addresses most of the feedback at least as I
understand it. So I would be interested in any code level comments on
what specifics should change to make it better.

In particular it deals with isolating importer and exporter data-types
from each other. Christian quite reasonably didn't want importers
obtaining physical addresses, and Jason didn't want importer specific
context being available from exporters. This creates a single layer,
called dma-shared-buf inspired by Dave, which is the only layer handling
both importer and exporter data thus isolating them from each other and
minimising the risk of abuse. It also deals with converting to/from
sg_table so that importers and exporters can be converted incrementally.

[1] - https://lore.kernel.org/dri-devel/20261120-dma_mapping_type_v4-v3-0-c0183a409bdf@nvidia.com/
[2] - https://lore.kernel.org/dri-devel/awZ_Os1pXelOGaFP@nvdebian.thelocal/

Signed-off-by: Alistair Popple <apopple@nvidia.com>
---
Alistair Popple (15):
      dma-shared-buf: Add struct dma_shared_buf
      dma-shared-buf: Add dma_shared_buf_iommu_map()
      dma-shared-buf: Add dma_addr_list_to_sgt()
      dma-shared-buf: Add dma_shared_buf_from_pages()
      dma-buf: Allow exporters to hand out a dma_shared_buf
      dma-buf: Add dma_buf_iommu_map() for IOMMU domain importers
      dma-buf: Factor out the pin and fence wait around the exporter's map
      dma-buf: Add dma_buf_map_dma_list() for DMA address only importers
      vfio/pci: Export a dma_shared_buf instead of mapping the buffer
      RDMA/uverbs: Export a dma_shared_buf instead of mapping the buffer
      dma-buf: Remove dma_buf_phys_vec_to_sgt() and dma_buf_free_sgt()
      iommufd: Map DMA-bufs through dma_buf_iommu_map()
      vfio/pci: Remove vfio_pci_dma_buf_iommufd_map()
      drm/xe/dma-buf: Export a dma_shared_buf instead of mapping the buffer
      drm/xe: Import DMA-bufs as a DMA address list

Jason Gunthorpe (1):
      treewide: Rename dma_buf_(un)map_attachment() to dma_buf_(un)map_sgt()

 MAINTAINERS                                        |   1 +
 drivers/accel/amdxdna/amdxdna_gem.c                |   6 +-
 drivers/accel/ivpu/ivpu_gem.c                      |   6 +-
 drivers/accel/qaic/qaic_data.c                     |   6 +-
 drivers/dma-buf/Makefile                           |   3 +-
 drivers/dma-buf/dma-buf-mapping.c                  | 316 +++++---------
 drivers/dma-buf/dma-buf.c                          | 452 ++++++++++++++++++---
 drivers/dma-buf/dma-shared-buf.c                   | 348 ++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c            |   4 +-
 drivers/gpu/drm/armada/armada_gem.c                |  16 +-
 drivers/gpu/drm/drm_prime.c                        |   6 +-
 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c         |   8 +-
 drivers/gpu/drm/i915/gem/i915_gem_object.c         |   2 +-
 .../gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c   |   4 +-
 drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c          |   4 +-
 drivers/gpu/drm/tegra/gem.c                        |  14 +-
 drivers/gpu/drm/virtio/virtgpu_prime.c             |   8 +-
 drivers/gpu/drm/xe/xe_bo.c                         |  52 +--
 drivers/gpu/drm/xe/xe_bo_types.h                   |   6 +
 drivers/gpu/drm/xe/xe_dma_buf.c                    |  55 +--
 drivers/gpu/drm/xe/xe_ggtt.c                       |   2 +-
 drivers/gpu/drm/xe/xe_pt.c                         |   4 +-
 drivers/gpu/drm/xe/xe_res_cursor.h                 |  78 ++++
 drivers/gpu/drm/xe/xe_ttm_vram_mgr.c               | 117 ++----
 drivers/gpu/drm/xe/xe_ttm_vram_mgr.h               |  13 +-
 drivers/gpu/drm/xe/xe_vram.c                       |  21 +
 drivers/gpu/drm/xe/xe_vram.h                       |   2 +
 drivers/iio/industrialio-buffer.c                  |   6 +-
 drivers/infiniband/core/umem_dmabuf.c              |   8 +-
 drivers/infiniband/core/uverbs_std_types_dmabuf.c  |  37 +-
 drivers/iommu/iommufd/io_pagetable.c               |   1 +
 drivers/iommu/iommufd/io_pagetable.h               |  27 +-
 drivers/iommu/iommufd/iommufd_private.h            |   8 -
 drivers/iommu/iommufd/pages.c                      | 219 +++++-----
 drivers/iommu/iommufd/selftest.c                   |  66 +--
 drivers/media/common/videobuf2/videobuf2-core.c    |   2 +-
 .../media/common/videobuf2/videobuf2-dma-contig.c  |   8 +-
 drivers/media/common/videobuf2/videobuf2-dma-sg.c  |   4 +-
 .../media/platform/nvidia/tegra-vde/dmabuf-cache.c |   6 +-
 drivers/misc/fastrpc.c                             |   6 +-
 drivers/nvme/host/pci-dmabuf.c                     |   6 +-
 drivers/usb/gadget/function/f_fs.c                 |   4 +-
 drivers/vfio/pci/vfio_pci_dmabuf.c                 |  73 +---
 drivers/xen/gntdev-dmabuf.c                        |   8 +-
 include/linux/dma-buf-mapping.h                    |  21 +-
 include/linux/dma-buf.h                            |  69 +++-
 include/linux/dma-shared-buf.h                     |  88 ++++
 include/linux/vfio_pci_core.h                      |   3 -
 io_uring/zcrx.c                                    |   6 +-
 net/core/devmem.c                                  |   8 +-
 50 files changed, 1462 insertions(+), 776 deletions(-)
---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261201-dmabuf_shared_buf_v1_xe_rc5-7069e70697a4

Best regards,
--  
Alistair Popple <apopple@nvidia.com>


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

end of thread, other threads:[~2026-12-01  7:08 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01  7:06 [PATCH RFC 00/16] dma-buf: Introduce dma_shared_buf and dma_addr_list to replace sg_table Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 01/16] treewide: Rename dma_buf_(un)map_attachment() to dma_buf_(un)map_sgt() Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 02/16] dma-shared-buf: Add struct dma_shared_buf Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 03/16] dma-shared-buf: Add dma_shared_buf_iommu_map() Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 04/16] dma-shared-buf: Add dma_addr_list_to_sgt() Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 05/16] dma-shared-buf: Add dma_shared_buf_from_pages() Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 06/16] dma-buf: Allow exporters to hand out a dma_shared_buf Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 07/16] dma-buf: Add dma_buf_iommu_map() for IOMMU domain importers Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 08/16] dma-buf: Factor out the pin and fence wait around the exporter's map Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 09/16] dma-buf: Add dma_buf_map_dma_list() for DMA address only importers Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 10/16] vfio/pci: Export a dma_shared_buf instead of mapping the buffer Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 11/16] RDMA/uverbs: " Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 12/16] dma-buf: Remove dma_buf_phys_vec_to_sgt() and dma_buf_free_sgt() Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 13/16] iommufd: Map DMA-bufs through dma_buf_iommu_map() Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 14/16] vfio/pci: Remove vfio_pci_dma_buf_iommufd_map() Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 15/16] drm/xe/dma-buf: Export a dma_shared_buf instead of mapping the buffer Alistair Popple
2026-12-01  7:06 ` [PATCH RFC 16/16] drm/xe: Import DMA-bufs as a DMA address list Alistair Popple

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

all inboxes | Powered by JetHome®