Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
From: Christian König
Date: Fri Nov 27 2026 - 03:04:53 EST
On 11/26/26 23:29, Dave Airlie wrote:
> On Thu, 26 Nov 2026 at 03:26, Christian König <christian.koenig@xxxxxxx> 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.