[PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type

Alistair Popple apopple at nvidia.com
Tue Nov 24 23:18:25 PST 2026


On 2026-11-25 at 06:46 +1100, Jason Gunthorpe <jgg at ziepe.ca> wrote...
> On Tue, Nov 24, 2026 at 05:02:31PM +0100, Christian König wrote:
> > The whole conversion from phys_vec to DMA addresses is something
> > some API should provide based on the data the exporter/importer have
> > negotiated (e.g. p2pdma_provider for example).
> 
> Yeah, probably, and this is exactly why I think it will take some
> time. Building a new something in lib/ like this is not a
> straightforward task.
> 
> But also, this:
> 
> > > You need to negotiate the actual C data types too, especially if you
> > > want to do that nasty idea where dmabuf populates an iommu domain.
> > 
> > Yeah agree as well, but to be honest that task is negligible. We
> > first need to figure out where to put the code.
> 
> Means you need to get the phys_addr_t into the dma-buf code so it can
> do this conversion.

We all agreed that open-coding DMA mapping of buffers in every exporter is
something we don't want to do. The disagreement now seems to be where the code
converting between physical locations provided by an exporter to DMA addresses
usable by an importer lives.

> I'm still absolutely NAKity against allowing any DRM driver visibility
> to an importer's iommu_domain if we do this hack.
> 
> I don't see how to meet all these concerns without making dma-buf into
> a "converter" framework...

Right, something has to do the conversion and we've agreed that shouldn't be
in either the exporters or the importers. The main objection seems to be having
dma-buf do that, and instead having some DMA/library code to do it.

If I drop the type/placement negotiation for now and focus on SGT removal I can
simplify things a lot. Plan would be something like:

1) Introduce a new C data type (dma_phys_list?) for exporters to pass physical
   location info and context for mapping.

2) Introduce two new dma_buf_ops - map_dma_phys_list() and unmap_dma_phys_list()
   - which are replacements for {un}map_dma_buf that converted exporters use to
   return a dma_phys_list instead of returning a sg_table.

3) Move dma_buf_phys_vec_to_sgt() somewhere other than drivers/dma-buf and
   rename it dma_phys_list_to_sgt().

4) Update dma_buf_{un}map_sgt() to call the new map_dma_phys_list() ops and
   dma_phys_list_to_sgt() to create an sg_table for unconverted importers
   importing from a converted exporter.

5) Add dma_buf_iommu_map() taking a IOMMU domain/iova/offset/size to be called
   from iommufd for mapping an attachment into an IOMMU domain.

6) Add a new C data type (dma_map_list?) containing DMA address regions
   an importer should program HW with and new dma-buf functions to replace
   dma_buf_{un}map_sgt().

Names are really just placeholders, so easily changed if you don't like them.
Let me know what you think, thanks.

Regards,

Alistair



More information about the Linux-nvme mailing list