Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dmaengine: mediatek: Fix deadlock caused by synchronize_irq()

The synchronize_irq(c->irq) will not return until the IRQ handler
mtk_uart_apdma_irq_handler() is completed. If the synchronize_irq()
holds a spin_lock and waits the IRQ handler to complete, but the
IRQ handler also needs the same spin_lock. The deadlock will happen.
The process is shown below:

cpu0 cpu1
mtk_uart_apdma_device_pause() | mtk_uart_apdma_irq_handler()
spin_lock_irqsave() |
| spin_lock_irqsave()
//hold the lock to wait |
synchronize_irq() |

This patch reorders the synchronize_irq(c->irq) outside the spin_lock
in order to mitigate the bug.

Fixes: 9135408c3ace ("dmaengine: mediatek: Add MediaTek UART APDMA support")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Reviewed-by: Eugen Hristev <eugen.hristev@collabora.com>
Link: https://lore.kernel.org/r/20230806032511.45263-1-duoming@zju.edu.cn
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Duoming Zhou and committed by
Vinod Koul
01f1ae27 c0409dd3

+1 -2
+1 -2
drivers/dma/mediatek/mtk-uart-apdma.c
··· 450 450 mtk_uart_apdma_write(c, VFF_EN, VFF_EN_CLR_B); 451 451 mtk_uart_apdma_write(c, VFF_INT_EN, VFF_INT_EN_CLR_B); 452 452 453 - synchronize_irq(c->irq); 454 - 455 453 spin_unlock_irqrestore(&c->vc.lock, flags); 454 + synchronize_irq(c->irq); 456 455 457 456 return 0; 458 457 }