Re: [PATCH v2] dmaengine: dmatest: fix race between wait for thread and thread start
From: Frank Li
Date: Mon Oct 12 2026 - 12:08:29 EST
On Fri, Aug 28, 2026 at 06:10:24PM +0300, Cosmin Tanislav wrote:
> [You don't often get email from cosmin-gabriel.tanislav.xa@xxxxxxxxxxx. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> Each dmatest worker thread has a pending and a done flag which describe
> the thread's lifecycle.
>
> pending is initialized to true when the thread is added to the threads
> list. pending is set to false once the thread is actually running. done
> is set to true once the thread has finished its testing.
>
> When the wait module parameter is set to true, dmatest_init() waits for
> the !is_threaded_test_run() condition to become true.
>
> If the worker thread is not started and running by the time
> dmatest_init() waits, the !is_threaded_test_run() condition will be true
> and the wait will stop early, before the worker thread is even started.
> dmatest_init() exits, defeating the whole purpose of the wait.
>
> If then we try to remove the module, kthread_stop() will try to cleanup
> the worker threads, interrupting wait_event_freezable_timeout(), which
> will return -ERESTARTSYS, causing the "test timed out" message to be
> printed.
>
> Clear the pending flag once we wake up the worker thread to avoid this
> race.
>
> Fixes: d53513d5dc28 ("dmaengine: dmatest: Add support for multi channel testing")
> Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@xxxxxxxxxxx>
> ---
Reviewed-by: Frank Li <Frank.Li@xxxxxxx>
>
> V2:
> * move pending = false before wake_up_process() as suggested by Sashiko
>
> drivers/dma/dmatest.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
> index 2ae3469397f3..f654a00e0040 100644
> --- a/drivers/dma/dmatest.c
> +++ b/drivers/dma/dmatest.c
> @@ -610,7 +610,6 @@ static int dmatest_func(void *data)
> ret = -ENOMEM;
>
> smp_rmb();
> - thread->pending = false;
> info = thread->info;
> params = &info->params;
> chan = thread->chan;
> @@ -1141,6 +1140,7 @@ static void run_pending_tests(struct dmatest_info *info)
>
> thread_count = 0;
> list_for_each_entry(thread, &dtc->threads, node) {
> + thread->pending = false;
> wake_up_process(thread->task);
> thread_count++;
> }
> --
> 2.55.0