DMA Engine development
 help / color / mirror / Atom feed
* [PATCH] dmaengine: dmatest: terminate channel on timeout or error
@ 2026-11-18 10:08 Amita Mishra
  2026-11-18 10:16 ` sashiko-bot
  2026-11-18 17:04 ` Frank Li
  0 siblings, 2 replies; 3+ messages in thread
From: Amita Mishra @ 2026-11-18 10:08 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Frank Li, Dan Williams, dmaengine, linux-kernel, stable,
	Amita Mishra

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@vger.kernel.org
Signed-off-by: Amita Mishra <amitamishra@google.com>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] dmaengine: dmatest: terminate channel on timeout or error
  2026-11-18 10:08 [PATCH] dmaengine: dmatest: terminate channel on timeout or error Amita Mishra
@ 2026-11-18 10:16 ` sashiko-bot
  2026-11-18 17:04 ` Frank Li
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-18 10:16 UTC (permalink / raw)
  To: Amita Mishra; +Cc: dmaengine, vkoul, Frank.Li

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] dmaengine: dmatest: integer underflow in min_odd() [1]
--

commit 15e7b971cd84dccd06d2762018cf300f9236dc53
Author: Amita Mishra <amitamishra@google.com>

dmaengine: dmatest: terminate channel on timeout or error

This commit calls dmaengine_terminate_sync() before unmapping DMA buffers
when a transfer times out or completes with an error in dmatest_func().

> diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
> index 2ae3469397f37..950b7a9e77695 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,

[Severity: High]
This problem wasn't introduced by this patch, but can min_odd() underflow
when computing src->cnt earlier in dmatest_func() [1]?

drivers/dma/dmatest.c:min_odd() {
	unsigned int val = min(x, y);

	return val % 2 ? val : val - 1;
}

When a DMA device reports max_xor or max_pq as 0 (or xor_sources /
pq_sources is 0), val is 0 and min_odd() returns UINT_MAX.  That bypasses
the (src->cnt + dst->cnt) >= 255 check by wrapping around, after which
dmatest_alloc_test_data() passes d->cnt + 1 == 0 to kcalloc() and
dereferences ZERO_SIZE_PTR when writing d->raw[0].

[1] https://sashiko.dev/#/bug/linux-ca967586-4fc1-47a3-8616-4a9d21fe7455

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118100839.3090172-1-amitamishra@google.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] dmaengine: dmatest: terminate channel on timeout or error
  2026-11-18 10:08 [PATCH] dmaengine: dmatest: terminate channel on timeout or error Amita Mishra
  2026-11-18 10:16 ` sashiko-bot
@ 2026-11-18 17:04 ` Frank Li
  1 sibling, 0 replies; 3+ messages in thread
From: Frank Li @ 2026-11-18 17:04 UTC (permalink / raw)
  To: Amita Mishra
  Cc: Vinod Koul, Frank Li, Dan Williams, dmaengine, linux-kernel,
	stable

On Wed, Nov 18, 2026 at 10:08:39AM +0000, Amita Mishra wrote:
> [You don't often get email from amitamishra@google.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> 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@vger.kernel.org
> Signed-off-by: Amita Mishra <amitamishra@google.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-18 17:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 10:08 [PATCH] dmaengine: dmatest: terminate channel on timeout or error Amita Mishra
2026-11-18 10:16 ` sashiko-bot
2026-11-18 17:04 ` Frank Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox