On Wed, Dec 02, 2026 at 11:41:46AM +1000, Dave Airlie wrote:
On Wed, 2 Dec 2026 at 11:30, Jason Gunthorpe jgg@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 own their DMA mappings and are the only things that should ever be touching them. That is the way we expect DMA APIU to be used, it is why Rust has the DMA API wrapped with the bound driver concept.
It is an extremely abnormal lifetime to suggest that some driver should be operating the DMA API of someone elses device.
I don't agree at all that having exporters operating the DMA API of importer devices makes any sense from a kernel lifetime perspective.
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.
We have that already.
What the importer does in the invalidate is up to it, but the exporter controls the resource lifetime and any things bound to it.
Once the exporter asks for it to be invalidated it gets to assume nothing is touching it anymore.
There is no reason for it to operate the DMA API of another driver, and doing so doesn't give more protections or a better life time design.
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.
It really can't. Without an iommu the dma unmap does nothing. If you unmap while DMA is still running you risk random corruption from future maps.
Choosing to unmap without synchronizing in the HW is an extreme dangerous action, and IMHO, accepting this buggy choice should be in side the driver that is doing it, not hidden in layers of software.
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,
Why not? This thread had several offers of some kind of dmabuf related mapping library whatever you want to call it.
That's a fine Switzerland.
but we should at least be speaking in terms of ownership and lifetime of resources and what can reasonable be defended against.
IMHO most of the problem here is the push to make unreasonable and difficult design choices because we have to defend against other drivers in the kernel. While somehow, against all reason, insisting that the exporting DRM drivers should be given the most sensitive access of everything.
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,
I think UALINK type devices you want a VRAM offset relative to the end point. That gets converted into a fabric address through the fabric mapping hardware.
but maybe dma_addr_t can encapsulate that, but for some things it
No. Do not abuse dma_addr_t for things that do not come from the DMA API, I think this has been said many times over the years. :(
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?
Lack of abstractions in dmabuf to help manage all of this, IMHO.
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.
Ridiculous. iommufd can be trusted to honor the existing invalidate callback. Far more than we can trust a random DRM driver to operate the iommu API correctly.
It is completely lifetime inappropriate for any other drivers to be reaching into the iommu_domain object entirely and fully controlled by iommufd. It breaks the encapsulation, complicates the code, and invites creative abuses from the GPU drivers.
Do not use lifetimes as a justification for this backwards design.
Jason