Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type
From: Jason Gunthorpe
Date: Tue Dec 01 2026 - 20:30:50 EST
On Wed, Dec 02, 2026 at 10:47:28AM +1000, Dave Airlie wrote:
> 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.
If you change iommu mappings without telling the driver you will
create data corruption as new mappings can fall to places the device
is still doing DMA.
The driver MUST be involved in any reclaim/move/revoke process and
DMABUF already has APIs for that. Managing this lifetime is one of the
main things it does.
I don't like this notion we can trust one side more than the other, it
isn't like the exporter drivers are amazing clean things either. There
is a reasonable level of nannying..
Importers are expected to unmap. I think we have to consider any one
that doesn't to be broken. You can't fix broken with more broken
things like force DMA unmapping and hoping that there is an iommu,
then hoping no corruption happens to crash the system.
> 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 just saw someone in drivers/media do the most insane thing with the
new DMA API, unbelievable. No matter what we build someone will find a
creative way to abuse it.
We need to have a 3rd party "Switzerland" if you want to keep this
direction that limits the exposure of either side to the details.
> 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.
This was the entire idea behind the mapping type series, it came out
of Intel asking for support for ualink.
> 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.
No, the output is always a dma_addr_t, the dma api natively supports
P2P. You have to decorate it in a special flow to make it work.
Also nothing uses PCI BAR + offset/length. If you want to make that
you can in your own "Switzerland" <shrug> but it is an unnatural
interface in practice.
Even the P2P permitted placement selection shouldn't be open coded in
drivers, this is a bit tricky to do well and none of the DRM drivers
get there.
> for iommufd, import meta-data is the iommu_domain, the exporter maps,
> and hands back the correct table of addresses
FWIW it is a huge pita to make things work like this inside iommufd
and if it gets messed up then iommufd will explode in a bad way.
It is so much easier to feed through phys_addr_t since we already have
this infrastructure.
But if that end up being the only thing that we disagree on then fine,
but no giving it directly to any DRM drivers.
Jason