On 2026-11-28 at 00:44 +1100, Christian König <[email protected]> wrote... > On 11/27/26 13:57, Jason Gunthorpe wrote: > > On Fri, Nov 27, 2026 at 09:04:15AM +0100, Christian König wrote: > > > >> If we somehow prevent the CPU physical address from being casted to > >> a struct page and/or used with vmf_insert_pfn/page/dma_map_page > >> etc.. then there is not much of a problem with passing around > >> physical addresses. > > > > I already offered that in v1 of the series using limits on > > EXPORT_SYMBOL and you NAK'd it too. > > Yes, because I think that this is not sufficient to prevent importers from > doing nasty things. > > >>> If we need to shared object backings and have clearly typed and > >>> negotiated on what the backing contains then we should allow it. > >>> However I mostly agree on the mapping thing, I'd want drivers to > >>> negotiate and natively support whatever backings they can rather than > >>> having an intermediate trying to handle the conversions Not saying the > >> > >> Yes, exactly that's my concern as well. We need to avoid this middle > >> layer trap. > > > > You avoid middle layers by having reasonable subsystem helpers for > > things to use to build their stuff, especially to encapsulate common > > patterns. These helpers are part of the subsystem, or in a related > > subysstem helper library. > > > > In Linux terms middle layer almost always means something wrapping a > > function pointer callback into a driver and enforcing specific actions > > on top of that. The recommended counter is to have the driver perform > > the actions with helpers and not wrapper the ops. It particularly came > > from the block world where they stuck something like SCSI after the > > block ops but before the driver. > > > > It is hard to see that DMABUF is anywhere close to a middle layer. > > > > This is also why we don't understand your remarks about > > dma_buf_phys_vec_to_sgt(). Of course it belongs in dmabuf, it produces > > the dmabuf spec'd mangled scatterlist that only dmabuf uses. Where > > else would you put this code? > > No, that doesn't even remotely belong to DMA-buf. > > What could be done inside DMA-buf is converting dma-addr[] and SGT. Because > we need that for backward compatibility. > > But creating the DMA addresses from the physical addresses is low level DMA > API and is not a task the DMA-buf framework should fulfill. > > Again: DMA-buf is just the utility which allows importers and exporters to > exchange information how to access a buffer. > > >>> code doing the conversions can't be a helper, bit it shouldn't ever be > >>> autoamtic or outside driver control. > > > > I think you do want it automatic, if an exporter is new and makes, > > say, a dma_addr_t[] and the importer is old and wants a sgt, why > > should we be open coding anything in every driver to deal with this? > > We shouldn't. That is not what I'm suggesting. > > > You can argue if it is automatic because the driver called a very > > general helper or automatic because the helper is wrapping a callback, > > but that should be a fairly minor quibble not a huge thread full of > > NAKs. > > > > Ultimately DMABUF has a fairly simple flow: > > 1) Allow importer/exporter to negotiate what kind of interconnect > > they want to use (PCI, ualink, etc) > > 2) Give the exporter enough information about the interconect path to > > make a placement decision > > 3) Describe the exporter's buffer so any mappings/translation/etc can > > be setup for the importer > > 4) Program the importers HW. > > > > Many of these have very common patterns, like PCI GPUs always make the > > same kind of VRAM placement decision in #2 based on P2P support. > > > > This should all be in helpers under the dmabuf umbrella and not open coded. > > Well I completely agree that this shouldn't be open coded in drivers, but it > also doesn't belong into DMA-buf. > > DMA-buf is just the utility which allows you to communicate the parameters > and the result of the mapping/translation back and forth between importer and > exporter. > > DMA-buf is not and should not be involved in creating the actually mapping, > that is the job of a low level DMA API.
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. - Alistair > Christian. > > > > > Jason >
