Hi Alistair,
On Tue, 1 Dec 2026 at 08:08, Alistair Popple apopple@nvidia.com wrote:
Currently the sg_table is used by dma-buf exporters to describe the range of physical addresses to map to the DMA API. This is then passed directly back to importers.
This is problematic for a number of reasons. It exposes exporter side information to importers and doesn't have the capability to describe memory that isn't backed by struct page which is what MMIO such as PCI BAR needs.
Add the dma-shared-buf as a library to handle this. A new type to replace the exporter's sg_table, struct dma_shared_buf, is added to describe a range of physical regions for mapping by the library. dma_shared_buf_map() can then be used to map this for a particular device.
The mapping function handles either direct P2P mappings using the PCI peer-to-peer core if a p2pdma provider is listed, or system memory otherwise. This allows dma-buf exporters to use common logic to create mappings instead of open-coding it which is hard to get right, especially for P2P cases with complex routing and IOMMU requirements.
This is kept in a file of its own as none of it depends on a DMA-buf and it could be a library elsewhere.
Signed-off-by: Alistair Popple apopple@nvidia.com
Thanks for your patch!
+/**
- struct dma_addr_list - Memory as a list of ranges of a device's DMA address
space
- @size: Sum of the range lengths
- @nr_ranges: Number of entries in @ranges
- @priv: For the owner of the list, which is whoever called
dma_shared_buf_map() or built the list itself
- @state: IOVA state when the list was linked into a single IOVA
- @attrs: The DMA attributes the list was mapped with
- @bus_addr: True when @ranges are PCI bus addresses, which needed no mapping
- @ranges: The DMA addresses covering the memory in order. For a mapped
dma_shared_buf that is one entry per range of it, or a single
entry when it was linked into one IOVA.
- Returned by dma_shared_buf_map() and released by dma_shared_buf_unmap(),
- which is all @state, @attrs and @bus_addr are for. Anyone the owner hands
- the list to reads @size, @nr_ranges and @ranges and nothing else.
- */
+struct dma_addr_list {
size_t size;unsigned int nr_ranges;void *priv;struct dma_iova_state state;unsigned long attrs;bool bus_addr;struct dma_addr_range ranges[] __counted_by(nr_ranges);+};
Please keep nr_ranges and bus_addr together, to reduce holes.
Gr{oetje,eeting}s,
Geert
linaro-mm-sig@lists.linaro.org