Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
From: Dave Airlie
Date: Tue Dec 01 2026 - 19:47:56 EST
On Tue, 1 Dec 2026 at 23:25, Christian König <christian.koenig@xxxxxxx> wrote:
>
> On 12/1/26 10:33, Alistair Popple wrote:
> > On 2026-12-01 at 19:11 +1100, Christian König <christian.koenig@xxxxxxx> wrote...
> >> On 12/1/26 08:13, Alistair Popple wrote:
> >>> 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.
> >>
> >> Seconded.
> >>
> >> I can give you quite a bunch of requirements based on what the high level DMA-buf API and uAPI has on functionality and based on what I have seen on use cases in the wild.
> >
> > I think a bunch of requirements would be helpful, because they've kind of been
> > scattered across threads at this point and I concluded it was kind of impossible
> > to build given the constraints.
> >
> > In particular the one thing that PCIe P2P, IOMMUFD, KVM, etc. all need is the
> > physical address. That is the vendor agnostic thing below but providing that has
> > been consistently NACKed and I can't see how you can make any low level API work
> > without having the physical address.
>
> Yeah good point, let's start with that one. There are multiple problems with using physical addresses.
>
> First of all a physical address is only what the CPU can see, but there are a lot of use cases where you need to access resources the CPU can't reach. For example hidden device memory or even system memory where the CPU intentionally has no address for because of digital rights management reasons etc... Taking a look at all the use cases I have seen I would say that DMA-buf actually contains more non CPU accessible resources than CPU accessible ones.
>
> Then especially for PCI a physical address is only halve the information you need. The importer can also need additional info to stitch together the TLP, like SH, snooping bit, atomic access ops etc....
>
> Then there is the reason that we have seen a tremendous amount of cases where importers abused the physical address and/or struct page pointer which was unfortunately accessible through the SGT. To be honest I can't count the number of CVE entries given to such bugs.
>
> There are some use cases for KVM for example which need physical addresses, but to be honest they look like corner cases.
>
> Ideally even the exporter shouldn't work with physically addresses I think. For example even when you have a PCI P2P API which fills in your mapping it should work with PCI BAR, offset and length and and not a physical address into the BAR.
>
> > I know in the past you've suggested passing all the importer context through to
> > the exporter, but that is also a complete non-starter. It lets arbitrary drivers
> > implement the mapping wrong and likely get all the life-times, which belong to
> > the importer, wrong. So until we can solve that I'm not really seeing much of
> > way forward here.
>
> WOW, wait a second. With the exception of the old interface which pins things down the lifetime of the mapping belongs to the exporter and not the importer!
I think this is clearly where the divide is. I'm with Christian here,
the exporter allocate the resource, then it owns the lifetime of the
resource. In order for it to have complete ownership of the lifetime
of the resource it needs the ability to remove the resource from other
users (i.e. importers). If the exporter wasn't to free some pages, it
should have all the information necessary to do so but traversing a
list of places the object has been imported and a method to forcible
unlink it from that side.
This directly conflicts with Jason's idea that I'm not giving
exporters the importers iommu_domain. I think we have to break this
deadlock to move forward.
I think I'm still with Christian though. I think you need to export a
"dma-buf" with a list of supported both platform and device specific
types that it can be imported into.
Then the importer has to give the exporter the "dma-buf", the type of
import and a set of meta-data about the type so the exporter can
create the mapping and track it, so it can clean it up later no matter
what the importer does. The exporter owns the lifetime of the object
and all things created from it. The exporter then gives back to the
importer a result of per-type meta-data.
for dma-buf the import meta-data is the struct device, the output
meta-data is a mapped sg for that device.
for PCI P2P, import meta-data might be just the PCI address of the
importer, snooping, atomic access?, maybe we validate it can be
reached, but then we return PCI BAR + offset/length lists.
for iommufd, import meta-data is the iommu_domain, the exporter maps,
and hands back the correct table of addresses
for UALINK, import meta-data is some ualink handle, and the result is
some other ualink handle.
The common theme being the exporter has enough information to always
be able to clean up anything it exported.
If neither side gives on this I think it will continue to be stuck.
Dave.