On 11/26/26 23:29, Dave Airlie wrote:
On Thu, 26 Nov 2026 at 03:26, Christian König christian.koenig@amd.com 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.
Is that because it's called dma-buf, if we just called it's shared-buf would that alleviate things? I just feel like there are use-cases where it containing CPU physical addresses might be what is optimal for a certain scenario, and re-creating a whole parallel infrastructure that ends up being 'I-can't-believe-it's-not-dma-buf' would end up being bad.
Well the problem is not so much transmitting CPU physical addresses between exporter and importer, but rather what the importer and DMA-buf layer should or should not be doing with them.
One of the few things which the DMA-buf design got right from the beginning is to avoid to much middle layering.
In other words the exporter is in control what is done with it's buffers and what isn't, so for example errors which come up while creating the mapping can be handled gracefully by the exporter. The map_attachment() callback either returns a fully populated mapping or an error code, nothing in between.
If we somehow prevent the CPU physical address from being casted to a struct page and/or used with vmf_insert_pfn/page/dma_map_page etc.. then there is not much of a problem with passing around physical addresses.
And if two drivers really need the system memory semantics with fine grained page faults, struct page refcounting etc... we still have memfd for that.
If we need to shared object backings and have clearly typed and negotiated on what the backing contains then we should allow it. However I mostly agree on the mapping thing, I'd want drivers to negotiate and natively support whatever backings they can rather than having an intermediate trying to handle the conversions Not saying the code doing the conversions can't be a helper, bit it shouldn't ever be autoamtic or outside driver control.
Yes, exactly that's my concern as well. We need to avoid this middle layer trap.
Christian.
Dave.
On Fri, Nov 27, 2026 at 09:04:15AM +0100, Christian König wrote:
If we somehow prevent the CPU physical address from being casted to a struct page and/or used with vmf_insert_pfn/page/dma_map_page etc.. then there is not much of a problem with passing around physical addresses.
I already offered that in v1 of the series using limits on EXPORT_SYMBOL and you NAK'd it too.
If we need to shared object backings and have clearly typed and negotiated on what the backing contains then we should allow it. However I mostly agree on the mapping thing, I'd want drivers to negotiate and natively support whatever backings they can rather than having an intermediate trying to handle the conversions Not saying the
Yes, exactly that's my concern as well. We need to avoid this middle layer trap.
You avoid middle layers by having reasonable subsystem helpers for things to use to build their stuff, especially to encapsulate common patterns. These helpers are part of the subsystem, or in a related subysstem helper library.
In Linux terms middle layer almost always means something wrapping a function pointer callback into a driver and enforcing specific actions on top of that. The recommended counter is to have the driver perform the actions with helpers and not wrapper the ops. It particularly came from the block world where they stuck something like SCSI after the block ops but before the driver.
It is hard to see that DMABUF is anywhere close to a middle layer.
This is also why we don't understand your remarks about dma_buf_phys_vec_to_sgt(). Of course it belongs in dmabuf, it produces the dmabuf spec'd mangled scatterlist that only dmabuf uses. Where else would you put this code?
code doing the conversions can't be a helper, bit it shouldn't ever be autoamtic or outside driver control.
I think you do want it automatic, if an exporter is new and makes, say, a dma_addr_t[] and the importer is old and wants a sgt, why should we be open coding anything in every driver to deal with this?
You can argue if it is automatic because the driver called a very general helper or automatic because the helper is wrapping a callback, but that should be a fairly minor quibble not a huge thread full of NAKs.
Ultimately DMABUF has a fairly simple flow: 1) Allow importer/exporter to negotiate what kind of interconnect they want to use (PCI, ualink, etc) 2) Give the exporter enough information about the interconect path to make a placement decision 3) Describe the exporter's buffer so any mappings/translation/etc can be setup for the importer 4) Program the importers HW.
Many of these have very common patterns, like PCI GPUs always make the same kind of VRAM placement decision in #2 based on P2P support. This should all be in helpers under the dmabuf umbrella and not open coded.
Jason
On 11/27/26 13:57, Jason Gunthorpe wrote:
On Fri, Nov 27, 2026 at 09:04:15AM +0100, Christian König wrote:
If we somehow prevent the CPU physical address from being casted to a struct page and/or used with vmf_insert_pfn/page/dma_map_page etc.. then there is not much of a problem with passing around physical addresses.
I already offered that in v1 of the series using limits on EXPORT_SYMBOL and you NAK'd it too.
Yes, because I think that this is not sufficient to prevent importers from doing nasty things.
If we need to shared object backings and have clearly typed and negotiated on what the backing contains then we should allow it. However I mostly agree on the mapping thing, I'd want drivers to negotiate and natively support whatever backings they can rather than having an intermediate trying to handle the conversions Not saying the
Yes, exactly that's my concern as well. We need to avoid this middle layer trap.
You avoid middle layers by having reasonable subsystem helpers for things to use to build their stuff, especially to encapsulate common patterns. These helpers are part of the subsystem, or in a related subysstem helper library.
In Linux terms middle layer almost always means something wrapping a function pointer callback into a driver and enforcing specific actions on top of that. The recommended counter is to have the driver perform the actions with helpers and not wrapper the ops. It particularly came from the block world where they stuck something like SCSI after the block ops but before the driver.
It is hard to see that DMABUF is anywhere close to a middle layer.
This is also why we don't understand your remarks about dma_buf_phys_vec_to_sgt(). Of course it belongs in dmabuf, it produces the dmabuf spec'd mangled scatterlist that only dmabuf uses. Where else would you put this code?
No, that doesn't even remotely belong to DMA-buf.
What could be done inside DMA-buf is converting dma-addr[] and SGT. Because we need that for backward compatibility.
But creating the DMA addresses from the physical addresses is low level DMA API and is not a task the DMA-buf framework should fulfill.
Again: DMA-buf is just the utility which allows importers and exporters to exchange information how to access a buffer.
code doing the conversions can't be a helper, bit it shouldn't ever be autoamtic or outside driver control.
I think you do want it automatic, if an exporter is new and makes, say, a dma_addr_t[] and the importer is old and wants a sgt, why should we be open coding anything in every driver to deal with this?
We shouldn't. That is not what I'm suggesting.
You can argue if it is automatic because the driver called a very general helper or automatic because the helper is wrapping a callback, but that should be a fairly minor quibble not a huge thread full of NAKs.
Ultimately DMABUF has a fairly simple flow:
- Allow importer/exporter to negotiate what kind of interconnect they want to use (PCI, ualink, etc)
- Give the exporter enough information about the interconect path to make a placement decision
- Describe the exporter's buffer so any mappings/translation/etc can be setup for the importer
- Program the importers HW.
Many of these have very common patterns, like PCI GPUs always make the same kind of VRAM placement decision in #2 based on P2P support.
This should all be in helpers under the dmabuf umbrella and not open coded.
Well I completely agree that this shouldn't be open coded in drivers, but it also doesn't belong into DMA-buf.
DMA-buf is just the utility which allows you to communicate the parameters and the result of the mapping/translation back and forth between importer and exporter.
DMA-buf is not and should not be involved in creating the actually mapping, that is the job of a low level DMA API.
Christian.
Jason
linaro-mm-sig@lists.linaro.org