Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
From: Dave Airlie
Date: Thu Nov 26 2026 - 17:30:09 EST
On Thu, 26 Nov 2026 at 03:26, Christian König <christian.koenig@xxxxxxx> wrote:
>
> On 11/24/26 07:23, Alistair Popple wrote:
> > On 2026-11-24 at 05:37 +1100, Christian König <christian.koenig@xxxxxxx> 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@xxxxxxxxxx>
> >>>>>
> >>>>> 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.
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.
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.
Dave.