[PATCH v7 00/17] Provide a new two step DMA mapping API
Jason Gunthorpe
jgg at ziepe.ca
Mon Mar 31 12:10:49 PDT 2025
On Fri, Mar 28, 2025 at 03:18:39PM +0100, Marek Szyprowski wrote:
> What kind of a fix is needed to dma_map_resource()/dma_unmap_resource()
> API to make it usable with P2P DMA? It looks that this API is closest to
> the mentioned dma_map_phys() and has little clients, so potentially
> changing the function signature should be quite easy.
I looked at this once, actually it was one of my first ideas to get
the VFIO DMABUF side going. I gave up on it pretty fast because of how
hard it would be to actually use..
Something like this:
dma_addr_t dma_map_p2p(struct device *dma_dev, struct device *mmio_dev,
phys_addr_t phys_addr, u8 *unmap_flags, size_t size,
enum dma_data_direction dir, unsigned long attrs);
void dma_unmap_p2p(struct device *dev, dma_addr_t addr, u8 *unmap_flags,
size_t size, enum dma_data_direction dir,
unsigned long attrs);
Where 'unmap_flags' would have to be carried by the caller between map
and unmap. mmio_dev is part of the P2P metadata that dma_map_sg gets
out of the struct page via the pgmap.
unmap_flags is the big challenge, there is not an easy data structure
to put that u8 as a per-call array into in the DMABUF space. It could
maybe work not bad for VFIO, but the DRM DMABUF drivers would be a
PITA to store and this wouldn't be some trivial conversion I could do
to all drivers in a few hours.
But, the big killer is that such an API would not be suitable for
performance path, so even DMABUF might not want to use it.
If we start to fix the performance things then we end up back to this
series's API design where you have the notion of DMA transaction. The
more of the micro optimizations that this series has the closer the
APIs will be..
So, IDK, we could make some small painfull progress for VFIO with the
above, but replacing scatterlist would be off the table, we'd have to
continue to live with the DMABUF scatterlist abuse, and there is no
advancement toward a performance struct-page-less DMA API.
Jason
More information about the Linux-nvme
mailing list