Transport link cleanup can free an MW still used by RX DMA or its completion path. QP-only cleanup retains the MW, but can restart RX on ring slots whose old completion callbacks have not yet cleared the headers. Wait for rx_post_q to empty before resetting the QP. ntb_complete_rxc() finishes its MW accesses before removing each entry under ntb_rx_q_lock, so cleanup can free the MW without racing with these RX accesses. Using dmaengine_terminate_sync() instead would not work with drivers such as IOAT that lack the required ops. Cookie-based waits would not work with DMA_COMPLETION_NO_ORDER either. DMA teardown in ntb_transport_free_queue() is unchanged. Fixes: 9143595a7e05 ("NTB: ntb_transport: Free MWs in ntb_transport_link_cleanup()") Cc: stable@vger.kernel.org Reported-by: Sashiko Link: https://lore.kernel.org/r/20260907144257.767281F00A3A@smtp.kernel.org/ Reviewed-by: Logan Gunthorpe Reviewed-by: Dave Jiang Signed-off-by: Koichiro Den --- Changes in v3: - Add Reviewed-by tag. No code changes. drivers/ntb/ntb_transport.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c index 9f71af97a8ef..8f1acf44bb53 100644 --- a/drivers/ntb/ntb_transport.c +++ b/drivers/ntb/ntb_transport.c @@ -950,6 +950,13 @@ static void ntb_transport_schedule_qp_link(struct ntb_transport_qp *qp, schedule_delayed_work(&qp->link_work, delay); } +static bool ntb_transport_rx_idle(struct ntb_transport_qp *qp) +{ + guard(spinlock_irqsave)(&qp->ntb_rx_q_lock); + + return list_empty(&qp->rx_post_q); +} + static void ntb_qp_link_cleanup(struct ntb_transport_qp *qp) { struct ntb_transport_ctx *nt = qp->transport; @@ -960,6 +967,17 @@ static void ntb_qp_link_cleanup(struct ntb_transport_qp *qp) disable_delayed_work_sync(&qp->link_work); ntb_transport_set_qp_active(qp, false); tasklet_kill(&qp->rxc_db_work); + /* + * Some DMA engines lack terminate/synchronize ops (e.g. IOAT), and + * DMA_COMPLETION_NO_ORDER rules out cookie-based waits. + * + * Waiting for rx_post_q to empty suffices: ntb_complete_rxc() finishes + * its MW accesses before removing each entry under ntb_rx_q_lock. + * qp->active is false and rxc_db_work is stopped, so no new RX DMA + * can be submitted. + */ + while (!ntb_transport_rx_idle(qp)) + fsleep(1000); ntb_qp_link_down_reset(qp); -- 2.51.0