[PATCH] dmaengine: dmatest: terminate channel on timeout or error
From: Amita Mishra
Date: Wed Nov 18 2026 - 05:09:15 EST
In interrupt mode (!params->polled), when wait_event_freezable_timeout()
times out (!done->done) or dma_async_is_tx_complete() reports a
non-DMA_COMPLETE status, dmatest_func() jumps to error_unmap_continue and
calls dmaengine_unmap_put() without terminating the DMA channel first.
Channel termination via dmaengine_terminate_sync() only happens later
when the test thread exits, unlike the polled path which terminates the
channel immediately after dma_sync_wait().
If the DMA controller is still actively transferring when the source and
destination buffers are unmapped, an IOMMU-backed DMA engine will trigger
use-after-unmap translation faults, or overwrite the buffers while the
next iteration reinitializes them. In addition, if the timed-out transfer
completes during a subsequent iteration, its callback sets the shared
per-thread done flag and wakes done_wait prematurely, causing the next
iteration to fail with "completion busy status".
Terminate the channel with dmaengine_terminate_sync() on both the timeout
and non-DMA_COMPLETE error paths before unmapping the buffers, skipping
the redundant call on timeout when params->polled has already terminated
the channel.
Fixes: 4076e755dbec ("dmatest: convert to dmaengine_unmap_data")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Amita Mishra <amitamishra@xxxxxxxxxx>
---
drivers/dma/dmatest.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
index 2ae3469397f3..950b7a9e7769 100644
--- a/drivers/dma/dmatest.c
+++ b/drivers/dma/dmatest.c
@@ -852,6 +852,8 @@ static int dmatest_func(void *data)
}
if (!done->done) {
+ if (!params->polled)
+ dmaengine_terminate_sync(chan);
result("test timed out", total_tests, src->off, dst->off,
len, 0);
goto error_unmap_continue;
@@ -859,6 +861,7 @@ static int dmatest_func(void *data)
!(dma_has_cap(DMA_COMPLETION_NO_ORDER,
dev->cap_mask) &&
status == DMA_OUT_OF_ORDER)) {
+ dmaengine_terminate_sync(chan);
result(status == DMA_ERROR ?
"completion error status" :
"completion busy status", total_tests, src->off,
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.56.1.703.gf848ed807c-goog