[PATCH v3] dmaengine: sun6i: Fix potential deadlock on &sdev->lock

From: Nguyen Minh Tien

Date: Sat Sep 26 2026 - 13:11:15 EST


From: Chengfeng Ye <dg573847474@xxxxxxxxx>

As &sdev->lock is taken by the tasklet sun6i_dma_tasklet() in softirq
context, other users of the lock in process context should disable
interrupts, otherwise the tasklet can preempt a holder of the lock on
the same CPU and deadlock. sun6i_dma_terminate_all() and
sun6i_dma_pause() take it without disabling interrupts.

This was found by an experimental static analysis tool for irq-related
deadlocks. Lockdep reports it too on an Allwinner T113, where the lock
is also taken inside the HARDIRQ-safe vc->lock:

[ 299.389380] WARNING: possible irq lock inversion dependency detected
[ 299.411196] c7109568 (&sdc->lock){+.-.}-{3:3}, at: sun6i_dma_terminate_all+0x40/0x2c4
[ 299.419137] but this lock was taken by another, HARDIRQ-safe lock in the past:
[ 299.426398] (&vc->lock){-.-.}-{3:3}

Use spin_lock_irqsave() in both places, as
sun6i_dma_free_chan_resources() already does.

Fixes: 555859308723 ("dmaengine: sun6i: Add driver for the Allwinner A31 DMA controller")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Chengfeng Ye <dg573847474@xxxxxxxxx>
[tien: rebased, added the lockdep report from a T113, Fixes and Cc stable]
Signed-off-by: Nguyen Minh Tien <tien.nguyenminh@xxxxxxxxxxxxxxxxxx>
---
I ran into this on a MangoPi MQ-Dual (Allwinner T113-S3): with lockdep
on, stopping dmatest set off the report above in
sun6i_dma_terminate_all(), and a small test module set it off in
sun6i_dma_pause(). While looking for a fix I found Chengfeng's v2 from
2023. It never got a review and no longer applies, so I rebased it on
dmaengine next and added the lockdep report, a Fixes tag and Cc stable.
Chengfeng, I hope you don't mind me picking it up.

With it, lockdep stays quiet on both paths on 7.3-rc4, and dmatest on
four channels passes while another channel is paused, resumed and
terminated in a loop.

v2: https://lore.kernel.org/20230726051727.64088-1-dg573847474@xxxxxxxxx

drivers/dma/sun6i-dma.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
index 5ad9d01cf..aee32363c 100644
--- a/drivers/dma/sun6i-dma.c
+++ b/drivers/dma/sun6i-dma.c
@@ -887,6 +887,7 @@ static int sun6i_dma_pause(struct dma_chan *chan)
struct sun6i_dma_dev *sdev = to_sun6i_dma_dev(chan->device);
struct sun6i_vchan *vchan = to_sun6i_vchan(chan);
struct sun6i_pchan *pchan = vchan->phy;
+ unsigned long flags;

dev_dbg(dmaengine_chan_dev(chan), "vchan %p: pause\n", &vchan->vc);

@@ -894,9 +895,9 @@ static int sun6i_dma_pause(struct dma_chan *chan)
writel(DMA_CHAN_PAUSE_PAUSE,
pchan->base + DMA_CHAN_PAUSE);
} else {
- spin_lock(&sdev->lock);
+ spin_lock_irqsave(&sdev->lock, flags);
list_del_init(&vchan->node);
- spin_unlock(&sdev->lock);
+ spin_unlock_irqrestore(&sdev->lock, flags);
}

return 0;
@@ -935,9 +936,9 @@ static int sun6i_dma_terminate_all(struct dma_chan *chan)
unsigned long flags;
LIST_HEAD(head);

- spin_lock(&sdev->lock);
+ spin_lock_irqsave(&sdev->lock, flags);
list_del_init(&vchan->node);
- spin_unlock(&sdev->lock);
+ spin_unlock_irqrestore(&sdev->lock, flags);

spin_lock_irqsave(&vchan->vc.lock, flags);


base-commit: 0a8dda0a15d3926422d286567f945a05328a4ac6
--
2.34.1