Hi guys,
On 12/1/26 08:13, Alistair Popple wrote:
On 2026-12-01 at 15:05 +1100, Dave Airlie airlied@gmail.com 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.
But I can't say either what the low level API needs to look like and one of the major reasons I want DMA-buf separated from that low level API is that it seems like this needs a different field of expertise and responsibilities.
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.
That sounds totally sane to me, yes.
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.
I've thought about that as well for a while but came to the conclusion that we most likely want some more differentiation here.
On the one hand we have the vendor agnostic things like PCI P2P, IOMMU, IOVAs, bus addresses, CPU physical addresses etc... which a vendor agnostic API should be dealing with.
On the other hand we have vendor specific things like XGMI, GDS/GWS/OA, I2C, I2S, doorbells, <just name the strange thing people stuffed into a DMA-buf> which only specific drivers understand.
The problem is now that those things at least partially overlap, for example a doorbell which is ringed by a PCI P2P write.
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.
Yes that is a requirement of ROCm as well and we have hacked around such things massively with the KFD and all the rat tail of consequences seen by it.
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-... - 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.
I would say that DMA-buf is the high level API which allows importers and exporters to exchange the data structures of the low level API.
Christian.
Dave.