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. Christian. > > Jason
