On 11/25/26 08:18, Alistair Popple wrote:
On 2026-11-25 at 06:46 +1100, Jason Gunthorpe jgg@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.
Yes, exactly that.
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.
Right.
DMA-buf is the high level API/uAPI importers and exporters talk to interchange information how to access the buffer, handle locking, handle lifetime, handle a generic driver independent uAPI....
The low level API which talks for example to the IOMMU driver for creating the information how to access the buffer is simply not the task at hand for that framework. The stuff we already handle is more than complicated enough.
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:
- Introduce a new C data type (dma_phys_list?) for exporters to pass physical location info and context for mapping.
Something like this maybe?
struct { u32 mapping_type; u32 num_entries; union { dma_addr_t *dma_addr; u64 *generic_64bit_addr; ... }; } ....
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.
Move dma_buf_phys_vec_to_sgt() somewhere other than drivers/dma-buf and rename it dma_phys_list_to_sgt().
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.
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.
I think a whole bunch of other drivers would be really happy to use that interface as well, yes.
- 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.
That totally sounds like a plan to me.
Regards, Christian.
Regards,
Alistair