* [PATCH 5.10/5.15 0/3] Backport NTB DMA release fix
@ 2026-11-05 12:20 Mikhail Dmitrichenko
2026-11-05 12:20 ` [PATCH 5.10/5.15 1/3] NTB: core: Add .get_dma_dev() callback to ntb_dev_ops Mikhail Dmitrichenko
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Mikhail Dmitrichenko @ 2026-11-05 12:20 UTC (permalink / raw)
To: stable, Greg Kroah-Hartman
Cc: Mikhail Dmitrichenko, Jon Mason, Dave Jiang, Allen Hubbe,
Koichiro Den, Leon Romanovsky, Marek Szyprowski, Frank Li,
Manivannan Sadhasivam, Bjorn Helgaas, ntb, linux-kernel,
lvc-project
When the NTB receive buffer needs manual alignment, ntb_transport
keeps the aligned DMA address and later passes it to dma_free_coherent()
along with the original CPU address. Preserve the original DMA handle
and use it when releasing the allocation.
The fix is needed in 5.10.y and 5.15.y. Include two prerequisites so the
upstream fix applies without changes. Existing hardware drivers do not
implement get_dma_dev, so the new helper returns ntb->dev.parent, which
ntb_register_device() sets to &ntb->pdev->dev in both branches.
The same prerequisite series and fix are present in 6.1.y and newer
stable branches.
All three commits apply cleanly to v5.10.273 and v5.15.224.
Build-tested only.
Fix for CVE-2026-80884.
Koichiro Den (2):
NTB: core: Add .get_dma_dev() callback to ntb_dev_ops
NTB: ntb_transport: Use ntb_get_dma_dev() for DMA buffers
Leon Romanovsky (1):
ntb: Store original DMA address for future release
drivers/ntb/ntb_transport.c | 18 ++++++++++--------
include/linux/ntb.h | 24 ++++++++++++++++++++++++
2 files changed, 34 insertions(+), 8 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 5.10/5.15 1/3] NTB: core: Add .get_dma_dev() callback to ntb_dev_ops
2026-11-05 12:20 [PATCH 5.10/5.15 0/3] Backport NTB DMA release fix Mikhail Dmitrichenko
@ 2026-11-05 12:20 ` Mikhail Dmitrichenko
2026-11-05 12:20 ` [PATCH 5.10/5.15 2/3] NTB: ntb_transport: Use ntb_get_dma_dev() for DMA buffers Mikhail Dmitrichenko
2026-11-05 12:20 ` [PATCH 5.10/5.15 3/3] ntb: Store original DMA address for future release Mikhail Dmitrichenko
2 siblings, 0 replies; 4+ messages in thread
From: Mikhail Dmitrichenko @ 2026-11-05 12:20 UTC (permalink / raw)
To: stable, Greg Kroah-Hartman
Cc: Mikhail Dmitrichenko, Jon Mason, Dave Jiang, Allen Hubbe,
Koichiro Den, Leon Romanovsky, Marek Szyprowski, Frank Li,
Manivannan Sadhasivam, Bjorn Helgaas, ntb, linux-kernel,
lvc-project
From: Koichiro Den <den@valinux.co.jp>
commit 362a4549f2acfb03390ddfcd91041e65a11a739f upstream.
Some NTB implementations are backed by a PCI function that is not the right
struct device to use with DMA API helpers (e.g. due to IOMMU topology, or
because the NTB device is virtual).
Add an optional .get_dma_dev() callback to struct ntb_dev_ops and provide a
helper, ntb_get_dma_dev(), so NTB clients can use the appropriate struct
device for DMA allocations and mappings.
If the callback is not implemented, ntb_get_dma_dev() returns the current
default (ntb->dev.parent). Drivers that implement .get_dma_dev() must
return a non-NULL device.
Suggested-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Koichiro Den <den@valinux.co.jp>
Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
[bhelgaas: format doc]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Link: https://patch.msgid.link/20260306031443.1911860-2-den@valinux.co.jp
Stable-dep-of: da6d997ac556 ("ntb: Store original DMA address for future release")
Signed-off-by: Mikhail Dmitrichenko <mdmitrichenko@astralinux.ru>
---
Prerequisite for the CVE-2026-80884 fix.
include/linux/ntb.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/include/linux/ntb.h b/include/linux/ntb.h
index 191b524e5c0dc..5c29e904a9c52 100644
--- a/include/linux/ntb.h
+++ b/include/linux/ntb.h
@@ -256,6 +256,7 @@ static inline int ntb_ctx_ops_is_valid(const struct ntb_ctx_ops *ops)
* @msg_clear_mask: See ntb_msg_clear_mask().
* @msg_read: See ntb_msg_read().
* @peer_msg_write: See ntb_peer_msg_write().
+ * @get_dma_dev: See ntb_get_dma_dev().
*/
struct ntb_dev_ops {
int (*port_number)(struct ntb_dev *ntb);
@@ -329,6 +330,7 @@ struct ntb_dev_ops {
int (*msg_clear_mask)(struct ntb_dev *ntb, u64 mask_bits);
u32 (*msg_read)(struct ntb_dev *ntb, int *pidx, int midx);
int (*peer_msg_write)(struct ntb_dev *ntb, int pidx, int midx, u32 msg);
+ struct device *(*get_dma_dev)(struct ntb_dev *ntb);
};
static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops *ops)
@@ -391,6 +393,8 @@ static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops *ops)
/* !ops->msg_clear_mask == !ops->msg_count && */
!ops->msg_read == !ops->msg_count &&
!ops->peer_msg_write == !ops->msg_count &&
+
+ /* ops->get_dma_dev is optional */
1;
}
@@ -1563,6 +1567,26 @@ static inline int ntb_peer_msg_write(struct ntb_dev *ntb, int pidx, int midx,
return ntb->ops->peer_msg_write(ntb, pidx, midx, msg);
}
+/**
+ * ntb_get_dma_dev() - get the device to use for DMA allocations/mappings
+ * @ntb: NTB device context.
+ *
+ * Return a struct device suitable for DMA API allocations and mappings.
+ * This is typically the parent of the NTB device, but may be overridden by a
+ * driver by implementing .get_dma_dev().
+ *
+ * Drivers that implement .get_dma_dev() must return a non-NULL pointer.
+ *
+ * Return: device pointer to use for DMA operations.
+ */
+static inline struct device *ntb_get_dma_dev(struct ntb_dev *ntb)
+{
+ if (!ntb->ops->get_dma_dev)
+ return ntb->dev.parent;
+
+ return ntb->ops->get_dma_dev(ntb);
+}
+
/**
* ntb_peer_resource_idx() - get a resource index for a given peer idx
* @ntb: NTB device context.
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 5.10/5.15 2/3] NTB: ntb_transport: Use ntb_get_dma_dev() for DMA buffers
2026-11-05 12:20 [PATCH 5.10/5.15 0/3] Backport NTB DMA release fix Mikhail Dmitrichenko
2026-11-05 12:20 ` [PATCH 5.10/5.15 1/3] NTB: core: Add .get_dma_dev() callback to ntb_dev_ops Mikhail Dmitrichenko
@ 2026-11-05 12:20 ` Mikhail Dmitrichenko
2026-11-05 12:20 ` [PATCH 5.10/5.15 3/3] ntb: Store original DMA address for future release Mikhail Dmitrichenko
2 siblings, 0 replies; 4+ messages in thread
From: Mikhail Dmitrichenko @ 2026-11-05 12:20 UTC (permalink / raw)
To: stable, Greg Kroah-Hartman
Cc: Mikhail Dmitrichenko, Jon Mason, Dave Jiang, Allen Hubbe,
Koichiro Den, Leon Romanovsky, Marek Szyprowski, Frank Li,
Manivannan Sadhasivam, Bjorn Helgaas, ntb, linux-kernel,
lvc-project
From: Koichiro Den <den@valinux.co.jp>
commit 852b94ff92cbe26a0dbb15eed9474f5493767f3b upstream.
ntb_transport currently uses ndev->pdev->dev for coherent allocations
and frees.
Switch the coherent buffer allocation/free paths to use
ntb_get_dma_dev(), so ntb_transport can work with NTB implementations
where the NTB PCI function is not the right device to use for DMA
mappings.
Suggested-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Koichiro Den <den@valinux.co.jp>
Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Link: https://patch.msgid.link/20260306031443.1911860-3-den@valinux.co.jp
Stable-dep-of: da6d997ac556 ("ntb: Store original DMA address for future release")
Signed-off-by: Mikhail Dmitrichenko <mdmitrichenko@astralinux.ru>
---
Prerequisite for the CVE-2026-80884 fix.
drivers/ntb/ntb_transport.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 94a8e294b7f21..2fca53b8e486d 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -793,13 +793,13 @@ static void ntb_transport_msi_desc_changed(void *data)
static void ntb_free_mw(struct ntb_transport_ctx *nt, int num_mw)
{
struct ntb_transport_mw *mw = &nt->mw_vec[num_mw];
- struct pci_dev *pdev = nt->ndev->pdev;
+ struct device *dma_dev = ntb_get_dma_dev(nt->ndev);
if (!mw->virt_addr)
return;
ntb_mw_clear_trans(nt->ndev, PIDX, num_mw);
- dma_free_coherent(&pdev->dev, mw->alloc_size,
+ dma_free_coherent(dma_dev, mw->alloc_size,
mw->alloc_addr, mw->dma_addr);
mw->xlat_size = 0;
mw->buff_size = 0;
@@ -856,7 +856,7 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw,
resource_size_t size)
{
struct ntb_transport_mw *mw = &nt->mw_vec[num_mw];
- struct pci_dev *pdev = nt->ndev->pdev;
+ struct device *dma_dev = ntb_get_dma_dev(nt->ndev);
size_t xlat_size, buff_size;
resource_size_t xlat_align;
resource_size_t xlat_align_size;
@@ -885,12 +885,12 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw,
mw->buff_size = buff_size;
mw->alloc_size = buff_size;
- rc = ntb_alloc_mw_buffer(mw, &pdev->dev, xlat_align);
+ rc = ntb_alloc_mw_buffer(mw, dma_dev, xlat_align);
if (rc) {
mw->alloc_size *= 2;
- rc = ntb_alloc_mw_buffer(mw, &pdev->dev, xlat_align);
+ rc = ntb_alloc_mw_buffer(mw, dma_dev, xlat_align);
if (rc) {
- dev_err(&pdev->dev,
+ dev_err(dma_dev,
"Unable to alloc aligned MW buff\n");
mw->xlat_size = 0;
mw->buff_size = 0;
@@ -903,7 +903,7 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw,
rc = ntb_mw_set_trans(nt->ndev, PIDX, num_mw, mw->dma_addr,
mw->xlat_size);
if (rc) {
- dev_err(&pdev->dev, "Unable to set mw%d translation", num_mw);
+ dev_err(dma_dev, "Unable to set mw%d translation", num_mw);
ntb_free_mw(nt, num_mw);
return -EIO;
}
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 5.10/5.15 3/3] ntb: Store original DMA address for future release
2026-11-05 12:20 [PATCH 5.10/5.15 0/3] Backport NTB DMA release fix Mikhail Dmitrichenko
2026-11-05 12:20 ` [PATCH 5.10/5.15 1/3] NTB: core: Add .get_dma_dev() callback to ntb_dev_ops Mikhail Dmitrichenko
2026-11-05 12:20 ` [PATCH 5.10/5.15 2/3] NTB: ntb_transport: Use ntb_get_dma_dev() for DMA buffers Mikhail Dmitrichenko
@ 2026-11-05 12:20 ` Mikhail Dmitrichenko
2 siblings, 0 replies; 4+ messages in thread
From: Mikhail Dmitrichenko @ 2026-11-05 12:20 UTC (permalink / raw)
To: stable, Greg Kroah-Hartman
Cc: Mikhail Dmitrichenko, Jon Mason, Dave Jiang, Allen Hubbe,
Koichiro Den, Leon Romanovsky, Marek Szyprowski, Frank Li,
Manivannan Sadhasivam, Bjorn Helgaas, ntb, linux-kernel,
lvc-project
From: Leon Romanovsky <leonro@nvidia.com>
commit da6d997ac556479c112554ab5d95cbd04683eb11 upstream.
The DMA API requires that dma_free_attrs receive the exact dma_handle
originally returned by the allocation function. Do not modify it.
Fixes: fc5d1829f9bf ("NTB: transport: Try harder to alloc an aligned MW buffer")
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/20260501-dma-attrs-debug-v2-1-8dbac75cd501@nvidia.com
Signed-off-by: Mikhail Dmitrichenko <mdmitrichenko@astralinux.ru>
---
Backport fix for CVE-2026-80884.
drivers/ntb/ntb_transport.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 2fca53b8e486d..fd3af0058f08c 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -211,6 +211,7 @@ struct ntb_transport_mw {
void *alloc_addr;
void *virt_addr;
dma_addr_t dma_addr;
+ dma_addr_t original_dma_addr;
};
struct ntb_transport_client_dev {
@@ -800,7 +801,7 @@ static void ntb_free_mw(struct ntb_transport_ctx *nt, int num_mw)
ntb_mw_clear_trans(nt->ndev, PIDX, num_mw);
dma_free_coherent(dma_dev, mw->alloc_size,
- mw->alloc_addr, mw->dma_addr);
+ mw->alloc_addr, mw->original_dma_addr);
mw->xlat_size = 0;
mw->buff_size = 0;
mw->alloc_size = 0;
@@ -823,6 +824,7 @@ static int ntb_alloc_mw_buffer(struct ntb_transport_mw *mw,
return -ENOMEM;
}
virt_addr = alloc_addr;
+ mw->original_dma_addr = dma_addr;
/*
* we must ensure that the memory address allocated is BAR size
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-05 12:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05 12:20 [PATCH 5.10/5.15 0/3] Backport NTB DMA release fix Mikhail Dmitrichenko
2026-11-05 12:20 ` [PATCH 5.10/5.15 1/3] NTB: core: Add .get_dma_dev() callback to ntb_dev_ops Mikhail Dmitrichenko
2026-11-05 12:20 ` [PATCH 5.10/5.15 2/3] NTB: ntb_transport: Use ntb_get_dma_dev() for DMA buffers Mikhail Dmitrichenko
2026-11-05 12:20 ` [PATCH 5.10/5.15 3/3] ntb: Store original DMA address for future release Mikhail Dmitrichenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®