cover-letter: Provide a new two step DMA API mapping API
This is complimentary part to the proposed LSF/MM topic.
https://lore.kernel.org/linux-rdma/
22df55f8-cf64-4aa8-8c0b-
b556c867b926@linux.dev/T/#m85672c860539fdbbc8fe0f5ccabdc05b40269057
-------------------------------------------------------------------------
Changelog:
v1:
* Rewrote cover letter
* Changed to API as proposed
https://lore.kernel.org/linux-rdma/
20240322184330.GL66976@ziepe.ca/
* Removed IB DMA wrappers and use DMA API directly
v0: https://lore.kernel.org/all/cover.
1709635535.git.leon@kernel.org
-------------------------------------------------------------------------
Currently the only efficient way to map a complex memory description through
the DMA API is by using the scatterlist APIs. The SG APIs are unique in that
they efficiently combine the two fundamental operations of sizing and allocating
a large IOVA window from the IOMMU and processing all the per-address
swiotlb/flushing/p2p/map details.
This uniqueness has been a long standing pain point as the scatterlist API
is mandatory, but expensive to use. It prevents any kind of optimization or
feature improvement (such as avoiding struct page for P2P) due to the impossibility
of improving the scatterlist.
Several approaches have been explored to expand the DMA API with additional
scatterlist-like structures (BIO[1], rlist[2]), instead split up the DMA API
to allow callers to bring their own data structure.
The API is split up into parts:
- dma_alloc_iova() / dma_free_iova()
To do any pre-allocation required. This is done based on the caller
supplying some details about how much IOMMU address space it would need
in worst case.
- dma_link_range() / dma_unlink_range()
Perform the actual mapping into the pre-allocated IOVA. This is very
similar to dma_map_page().
A driver will extent its mapping size using its own data structure, such as
BIO, to request the required IOVA. Then it will iterate directly over it's
data structure to DMA map each range. The result can then be stored directly
into the HW specific DMA list. No intermediate scatterlist is required.
In this series, examples of three users are converted to the new API to show
the benefits. Each user has a unique flow:
1. RDMA ODP is an example of "SVA mirroring" using HMM that needs to
dynamically map/unmap large numbers of single pages. This becomes
significantly faster in the IOMMU case as the map/unmap is now just
a page table walk, the IOVA allocation is pre-computed once. Significant
amounts of memory are saved as there is no longer a need to store the
dma_addr_t of each page.
2. VFIO PCI live migration code is building a very large "page list"
for the device. Instead of allocating a scatter list entry per allocated
page it can just allocate an array of 'struct page *', saving a large
amount of memory.
3. NVMe PCI demonstrates how a BIO can be converted to a HW scatter
list without having to allocate then populate an intermediate SG table.
This step is first along a path to provide alternatives to scatterlist and
solve some of the abuses and design mistakes, for instance in DMABUF's P2P
support.
The ODP and VFIO versions are complete and fully tested, they can be the users
of the new API to merge it. The NVMe requires more work.
[1] https://lore.kernel.org/all/
169772852492.5232.
17148564580779995849.stgit@klimt.1015granger.net/
[2] https://lore.kernel.org/all/ZD2lMvprVxu23BXZ@ziepe.ca/
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>