On Wed, 2 Dec 2026 at 11:30, Jason Gunthorpe <j…@ziepe.ca> wrote:
> > 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..
This isn't just about trust, it's about lifetime and ownership. If the exporter owns the resource, the exporter should have all necessary information to invalidate the resource and give it back to the system.
> 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.
But we should allow the exporter to tell the imported to invalidate, wait for a response and then have the exporter free it. What the importer does in the invalidate is up to it, but the exporter controls the resource lifetime and any things bound to it. If the importer fails to invalidate the resource then that is a clear problem. But an exporter can at least control all the mappings for the resource and tear them down without leaking things.
> > 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.
If I had rust for this I'd be happier, but we don't get a switzerland, but we should at least be speaking in terms of ownership and lifetime of resources and what can reasonable be defended against.
>
> > 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.
Okay maybe on that one we can give in, I do think path + offset/length lists might make sense for things like NVLINK/UALINK though were there is more arbitrary path to the resource than just what is CPU visible, but maybe dma_addr_t can encapsulate that, but for some things it might still make sense. A lot of this ends up being just "path cookie" + offset/length pairs of arbitary address that make sense for that path.
> 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.
Because nobody has written the code to do it?
>
> > 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.
It's easier, but you don't respect lifetimes then.
> But if that end up being the only thing that we disagree on then fine, > but no giving it directly to any DRM drivers.
Most likely DRM drivers or any exporter will just want to add it to the mapping list and call a generic iommu interface to do the work. The big thing being they can control undoing it later. Dave.