[PATCH v2 0/3] NTB: Allow drivers to provide DMA mapping device
From: Koichiro Den
Date: Thu Mar 05 2026 - 22:15:22 EST
Hi,
Some NTB implementations are backed by a "virtual" PCI device, while the
actual DMA mapping context (IOMMU domain) belongs to a different device.
One example is vNTB, where the NTB device is represented as a virtual
PCI endpoint function, but DMA operations must be performed against the
EPC parent device, which owns the IOMMU context.
Currently, vNTB on an IOMMU-backed EPC does not work because the
"virtual" PCI device is used for DMA API operations, while the actual
IOMMU domain belongs to the EPC parent device. This series fixes that.
Note that there are two related but separable DMA-mapping issues in this
area:
1). Selecting the correct struct device for DMA API operations used for
MW translation setup and coherent buffer allocation.
2). The existing RX-side dmaengine path in ntb_transport, where the MW
source buffer may later be re-mapped against a per-queue dmaengine
device ("double mapping"). The current physically-contiguous
allocation workaround is about that existing issue.
This series is only about (1). It does not attempt to solve the larger
initialization-order / per-queue dmaengine issue behind (2), nor does it
change the current behavior of that path. In particular, this is not a
series to eliminate or redesign the existing "double mapping" behavior.
This series introduces an optional .get_dma_dev() callback in struct
ntb_dev_ops, together with a helper ntb_get_dma_dev(). If the callback
is not implemented, the helper falls back to the current default
behavior. Drivers that implement .get_dma_dev() must return a non-NULL
struct device.
- Patch 1/3: Add .get_dma_dev() to struct ntb_dev_ops and provide
ntb_get_dma_dev().
- Patch 2/3: Switch ntb_transport MW buffer allocation/free paths to use
ntb_get_dma_dev().
- Patch 3/3: Implement .get_dma_dev() for vNTB by returning the EPC
parent device.
As suggested by Dave at:
https://lore.kernel.org/all/17cdfa38-16d5-49cc-ac61-20b606a4308b@xxxxxxxxx/
I expect patch 1 and 2 to get NTB acks, patch 3 to get PCI EP ack, and
the full series to be taken through the PCI EP tree.
Best regards,
Koichiro
---
Changes since v1:
- Reworked the series so that the actual user (vNTB) is included in
the same series.
- Clarified in the cover letter that this series only addresses the
DMA-mapping device selection for MW translation, and does not
attempt to solve the existing RX-side dmaengine "double mapping"
issue.
Koichiro Den (3):
NTB: core: Add .get_dma_dev() callback to ntb_dev_ops
NTB: ntb_transport: Use ntb_get_dma_dev() for DMA buffers
PCI: endpoint: pci-epf-vntb: Implement .get_dma_dev()
drivers/ntb/ntb_transport.c | 14 +++++------
drivers/pci/endpoint/functions/pci-epf-vntb.c | 9 ++++++++
include/linux/ntb.h | 23 +++++++++++++++++++
3 files changed, 39 insertions(+), 7 deletions(-)
--
2.51.0