> The problem is I can't figure out how to build that low level API. > > 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. > > 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.
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. Now maybe we can't call this dma-buf, but I think dma-buf is a subset of this. Dave.