Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
From: Alistair Popple
Date: Tue Dec 01 2026 - 02:13:22 EST
On 2026-12-01 at 15:05 +1100, Dave Airlie <airlied@xxxxxxxxx> wrote...
> > The problem is I can't figure out how to build that low level API.
> >
> > The current low level DMA API can't correctly handle PCIe P2P, or IOMMUFD, or
> > the KVM/confidential compute use-cases (I'm less familiar with those). It can
> > only handle creating a DMA mapping for system memory for a specific importing
> > device.
> >
> > So I assume you are talking about some new API. Following Dave's lead lets call
> > that shared_buf_map(). That would need to take some importing device context
> > so that it could dispatch to the correct mapping code and a list of physical
> > locations the exporter needs mapped.
> >
> > At a high level something like:
> >
> > struct dma_addr_list *shared_buf_map(import_context, location_list);
> >
> > Where the import_context is some importer specific struct opaque to the exporter
> > and the location list is a list of either PCIe MMIO or system RAM physical
> > addresses.
> >
> > Every exporter ->map_dma_buf() should call shared_buf_map() instead of
> > open-coding their own mapping code, as I think we all agree we don't want that
> > open-coded.
> >
> > Placement selection can be dealt with as a separate topic, so setting that
> > aside means passing in the same location list regardless of importing device.
> > shared_buf_map() then has to dispatch to the correct mapping generation code -
> > either DMA API, PCIe peer-to-peer API, IOMMUFD API, KVM API or maybe some other
> > importing device/driver specific API.
> >
> > I could see how that could be made to work, but it seems more complex than
> > a dma_buf exporter op that returns a list of physical locations and a helper
> > library that importers call to do the mapping into whatever importer specific
> > context is needed. Instead you would have to add importer specific callbacks
> > that the shared_buf_map code could call along with plumbing the importer context
> > through.
>
> This is where I got to thinking it might end up, not that we have an
> export function that actually exports anything, but merely advertises
> this provider has an object with this fd and it can export it in these
> ways.
>
> Then on import we'd have to go into the exporter and setup the object
> that gets shared between that specific importer/exporter combination
> and not always have a singular export, but one per import, that I
> suppose could be refcounted per export if lots of importers wanted the
> same thing.
That sounds reasonably complex. Do you have a vague plan, ideally in the form
of data-structures/API definitions, that would help explain what it would look
like?
For now I have sent a simplified RFC series -
https://lore.kernel.org/dri-devel/20261201-dmabuf_shared_buf_v1_xe_rc5-v1-0-b672717c7fc9@xxxxxxxxxx/T/#t - that drops the placement
bits and implements the rough plan I outlined in
https://lore.kernel.org/dri-devel/awZ_Os1pXelOGaFP@nvdebian.thelocal/ . I'm not
sure it addresses everything, but I'd be interested in getting feedback on what
it gets right and what specifically needs fixing/changing, and how, to satisfy
the design constraints.
Thanks.
- Alistair
> Now maybe we can't call this dma-buf, but I think dma-buf is a subset of this.
>
> Dave.