On 11/24/26 07:23, Alistair Popple wrote:
On 2026-11-24 at 05:37 +1100, Christian König christian.koenig@amd.com wrote...
On 11/23/26 17:57, Jason Gunthorpe wrote:
On Mon, Nov 23, 2026 at 02:36:46PM +0100, Christian König wrote:
On 11/20/26 06:55, Alistair Popple wrote:
From: Jason Gunthorpe jgg@nvidia.com
The SGT (Scatter Gather Table) DMA mapping type represents the existing sg_table/scatterlist based DMA mapping. For now it continues to use a sg_table for map/unmap, but this will allow a future patch series to convert to using a different data structure for importers without having to convert all at once.
I strongly think we shouldn't have an SGT mapping type in the new DMA-buf mapping API.
Instead we should have something like either an array or an xarray of DMA addresses.
My plan was always to get there, but I don't think it is reasonable to start there? There are too many places all over the place that are just hardwired to do SGT right now.
Right. There are around 70 drivers upstream that make use of the sg_table handed down via a dma-buf import, so I don't think it's tractable to convert them all in one go. So obviously we will need some way of phasing this in to give time for each driver change to be implemented, reviewed, etc.
My suggestion is not to convert all drivers in one go, but rather to come up with some sane representation of the DMA addresses instead of using an SGT in the new interface.
Obviously some of those will share a common structure/helper and conversions will be similar, so that is an over-estimate. But based on an initial poke around there are plenty of drivers that bake the sg_table more deeply into their data structures.
Part of the design of this series was to allow the conversion away from SGT to be done incrementally without breaking compatibility.
Do you know the joke from the hitchhikers guide to the galaxy where the dolphins are happy for exactly the same reasons?
I'm pushing against this plan for exactly the same reason because I think it will make the conversation away from SGT even more problematic than it already is.
So it is effectively this:
The framework should then either connect the SGT directly if both importer and export are using the "classic" interface
Yeah but that should not be a separate mapping type, it's rather that we just convert back and forth from DMA addresses to SGT for compatibility reasons.
Right, I think this is actually fairly close to my plan, which is to provide a type for each address class an exporter can produce - either a CPU physical address or some device context + P2P/MMIO address but in future could be some other interconnect type.
The core then negotiates compatible types and adds converters between them,
I have strong objections to that plan and would potentially NAK it.
DMA-buf should *NEVER* accept CPU physical addresses nor provide conversion between different address types.
Keep in mind that DMA-buf is solely a container for DMA addresses, nothing else and it should not provide any mapping functionality whatsoever.
and having SGT as a type is what allows that. It only exists for unconverted exporters and importers and eventually goes away once everything is converted. The idea being we don't have to convert everything all at once, whilst also being able to add support for different interconnect types. Are you ok with the SGT type if it is just transitional?
Not really, it just complicate things.
What we should do with the mapping interface is to add the information in which domain the DMA addresses are to be used.
The conversion between SGT and DMA address array is an exception we can make to aid transition between the old and the new interface, but that is basically a 1 to 1 copy between different data structures.
As discussed a bit previously types also add enforcement of the rules around when the exporter type/location can change.
I do have most of this coded up, so can post a mega series of all patches if it's helpful to see the overall direction in code form. I didn't do that because this conversion of exporters to not return sg_tables makes it quite a large patch series, so I was going to post them as separate RFCs building on top of this. Not sure if you have a preference there?
I think we should have the core interface plus some test cases and at least one driver converted over as example of how the new interface would be used.
And this:
or convert from DMA-addr array to SGT and back if either of them are using this new interface.
look like Is something I imagined as a followup series.
As this is actually quite complicated and needs discussion exactly what it will look like.
Actually that is the easy step I think because quite a lot of drivers already convert the SGT to a DMA addr array outside of the DMA-buf framework anyway.
The more complicated one is then starting to come up with more bus types and doing optimization work.
Individually the actual data structure conversion isn't that hard, but there's a lot of them and the mapping types allow you to do them incrementally without breaking some unconverted importer importing from a converted exporter.
Breaking classic users is actually completely intentional because we most likely still have people abusing the struct page inside the SGT.
And those will need to be converted over to be using pure DMA addresses similar to how MSM has switched over recently.
So the whole idea is when you have classic to classic interface pass along the SGT between exporter and importer. Then move as much as possible drivers over to the new interface and start identifying where and why some drivers have problems.
Regards, Christian.
That is also why I think adding the types now rather than later is reasonable. The rules for when an exporter may change type or placement are what most of the previous review discussion has been about, and I didn't want to drop them.
Thanks for looking.
- Alistair
Christian.
Jason
On Tue, Nov 24, 2026 at 01:36:21PM +0100, Christian König wrote:
The core then negotiates compatible types and adds converters between them,
I have strong objections to that plan and would potentially NAK it.
DMA-buf should *NEVER* accept CPU physical addresses nor provide conversion between different address types.
Keep in mind that DMA-buf is solely a container for DMA addresses, nothing else and it should not provide any mapping functionality whatsoever.
dmabuf needs to provide support for drivers to help them use the interface, and going from physical to dma_addr_t is absolutely a common task every driver must do. I don't care how you call it, but it is a service that must be provided by *something* and matched to the needs of dmabuf.
I will definitely NAK any direction to open code dma mapping in every driver again. If we are going away from SGT then we are fixing all the DRM mistakes, including the wrong open coded DMA mapping, sketchy use of SGT, and abuse of P2P that seems to be endemic in drm.
Meaing the exporter constructs a phys_addr list, gets a P2P provider, and some common code constructs what is passed to the importer. I don't care if this is in "dmabuf" or some "dmabuf library" or *whatever* but it must exist as common shared code.
dma_buf_phys_vec_to_sgt() is the template how to implement this transformation.
and having SGT as a type is what allows that. It only exists for unconverted exporters and importers and eventually goes away once everything is converted. The idea being we don't have to convert everything all at once, whilst also being able to add support for different interconnect types. Are you ok with the SGT type if it is just transitional?
Not really, it just complicate things.
What we should do with the mapping interface is to add the information in which domain the DMA addresses are to be used.
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.
Jason
On 11/24/26 15:20, Jason Gunthorpe wrote:
On Tue, Nov 24, 2026 at 01:36:21PM +0100, Christian König wrote:
The core then negotiates compatible types and adds converters between them,
I have strong objections to that plan and would potentially NAK it.
DMA-buf should *NEVER* accept CPU physical addresses nor provide conversion between different address types.
Keep in mind that DMA-buf is solely a container for DMA addresses, nothing else and it should not provide any mapping functionality whatsoever.
dmabuf needs to provide support for drivers to help them use the interface, and going from physical to dma_addr_t is absolutely a common task every driver must do. I don't care how you call it, but it is a service that must be provided by *something* and matched to the needs of dmabuf.
I will definitely NAK any direction to open code dma mapping in every driver again. If we are going away from SGT then we are fixing all the DRM mistakes, including the wrong open coded DMA mapping, sketchy use of SGT, and abuse of P2P that seems to be endemic in drm.
Completely agree to that as well.
Meaing the exporter constructs a phys_addr list, gets a P2P provider, and some common code constructs what is passed to the importer. I don't care if this is in "dmabuf" or some "dmabuf library" or *whatever* but it must exist as common shared code.
dma_buf_phys_vec_to_sgt() is the template how to implement this transformation.
Well what I disagree with the dma_buf_ prefix here.
DMA-buf is just the container of the result of this process and it shouldn't hold any code to actually generate the addresses. That is simply not part of the job of transferring those information between drivers.
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).
I think we need something like a DMA P2P API which sits on top of the PCI and iova API.
and having SGT as a type is what allows that. It only exists for unconverted exporters and importers and eventually goes away once everything is converted. The idea being we don't have to convert everything all at once, whilst also being able to add support for different interconnect types. Are you ok with the SGT type if it is just transitional?
Not really, it just complicate things.
What we should do with the mapping interface is to add the information in which domain the DMA addresses are to be used.
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.
Christian.
Jason
linaro-mm-sig@lists.linaro.org