dmaengine: milbeaut-hdmac: Fix deadlock with the channel IRQ handler
Subsystems (3)
PATCH 1/1 dmaengine: milbeaut-hdmac: Fix deadlock with the channel IRQ handler
milbeaut_hdmac_interrupt() is a hardirq handler and takes mc->vc.lock with a plain spin_lock() for the whole time it runs. interrupts are disabled locally in that context, so the handler itself is fine.
milbeaut_hdmac_chan_config(), milbeaut_hdmac_chan_pause() and milbeaut_hdmac_chan_resume() are called from process context and take the same lock with a plain spin_lock() as well, so interrupts stay enabled while the lock is held.
If a channel interrupt is delivered on the CPU that is inside one of those critical sections, milbeaut_hdmac_interrupt() spins on a lock that the interrupted code is holding and can never release, and the CPU hangs.
Take mc->vc.lock with spin_lock_irqsave() in those three functions, as milbeaut_hdmac_issue_pending() and the other process context users of this lock already do.
--- drivers/dma/milbeaut-hdmac.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/dma/milbeaut-hdmac.c +9 -6
@@ -214,10 +214,11 @@ milbeaut_hdmac_chan_config(struct dma_chan *chan, stru {struct virt_dma_chan *vc =to_virt_chan (chan);struct milbeaut_hdmac_chan *mc =to_milbeaut_hdmac_chan (vc); +unsigned long flags; -spin_lock (&mc->vc.lock); +spin_lock_irqsave (&mc->vc.lock, flags); mc->cfg = *cfg; -spin_unlock (&mc->vc.lock); +spin_unlock_irqrestore (&mc->vc.lock, flags);return 0 ; }
@@ -226,13 +227,14 @@ static int milbeaut_hdmac_chan_pause(struct dma_chan * {struct virt_dma_chan *vc =to_virt_chan (chan);struct milbeaut_hdmac_chan *mc =to_milbeaut_hdmac_chan (vc); +unsigned long flags;u32 val; -spin_lock (&mc->vc.lock); +spin_lock_irqsave (&mc->vc.lock, flags); val =readl_relaxed (mc->reg_ch_base +MLB_HDMAC_DMACA ); val |=MLB_HDMAC_PB ;writel_relaxed (val, mc->reg_ch_base +MLB_HDMAC_DMACA ); -spin_unlock (&mc->vc.lock); +spin_unlock_irqrestore (&mc->vc.lock, flags);return 0 ; }
@@ -241,13 +243,14 @@ static int milbeaut_hdmac_chan_resume(struct dma_chan {struct virt_dma_chan *vc =to_virt_chan (chan);struct milbeaut_hdmac_chan *mc =to_milbeaut_hdmac_chan (vc); +unsigned long flags;u32 val; -spin_lock (&mc->vc.lock); +spin_lock_irqsave (&mc->vc.lock, flags); val =readl_relaxed (mc->reg_ch_base +MLB_HDMAC_DMACA ); val &= ~MLB_HDMAC_PB ;writel_relaxed (val, mc->reg_ch_base +MLB_HDMAC_DMACA ); -spin_unlock (&mc->vc.lock); +spin_unlock_irqrestore (&mc->vc.lock, flags);return 0 ; }
Signature · 1 line
2.43.0
Quoted 15 lines · Ginger Li
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
milbeaut_hdmac_interrupt()is a hardirq handler and takesmc->vc.lockwith a plainspin_lock()for the whole time it runs. interrupts are disabled locally in that context, so the handler itself is fine.
milbeaut_hdmac_chan_config(),milbeaut_hdmac_chan_pause()andmilbeaut_hdmac_chan_resume()are called from process context and take the same lock with a plainspin_lock()as well, so interrupts stay enabled while the lock is held.If a channel interrupt is delivered on the CPU that is inside one of those critical sections,
milbeaut_hdmac_interrupt()spins on a lock that the interrupted code is holding and can never release, and the CPU hangs.
Quoted 7 lines
Take
mc->vc.lockwithspin_lock_irqsave()in those three functions, asmilbeaut_hdmac_issue_pending()and the other process context users of this lock already do.Fixes 6c3214e698e4 ("dmaengine: milbeaut-hdmac: Add HDMAC driver for Milbeaut platforms")Signed-off-by Ginger Li <[email protected]>---
Quoted 57 lines
drivers/dma/milbeaut-hdmac.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/dma/milbeaut-hdmac.c +9
-7@@ -214,10 +214,11 @@ milbeaut_hdmac_chan_config(struct dma_chan *chan, stru {struct virt_dma_chan *vc =to_virt_chan (chan);struct milbeaut_hdmac_chan *mc =to_milbeaut_hdmac_chan (vc); +unsigned long flags; -spin_lock (&mc->vc.lock); +spin_lock_irqsave (&mc->vc.lock, flags); mc->cfg = *cfg; -spin_unlock (&mc->vc.lock); +spin_unlock_irqrestore (&mc->vc.lock, flags);return 0 ; }@@ -226,13 +227,14 @@ static int milbeaut_hdmac_chan_pause(struct dma_chan * {struct virt_dma_chan *vc =to_virt_chan (chan);struct milbeaut_hdmac_chan *mc =to_milbeaut_hdmac_chan (vc); +unsigned long flags;u32 val; -spin_lock (&mc->vc.lock); +spin_lock_irqsave (&mc->vc.lock, flags); val =readl_relaxed (mc->reg_ch_base +MLB_HDMAC_DMACA ); val |=MLB_HDMAC_PB ;writel_relaxed (val, mc->reg_ch_base +MLB_HDMAC_DMACA ); -spin_unlock (&mc->vc.lock); +spin_unlock_irqrestore (&mc->vc.lock, flags);return 0 ; }@@ -241,13 +243,14 @@ static int milbeaut_hdmac_chan_resume(struct dma_chan {struct virt_dma_chan *vc =to_virt_chan (chan);struct milbeaut_hdmac_chan *mc =to_milbeaut_hdmac_chan (vc); +unsigned long flags;u32 val; -spin_lock (&mc->vc.lock); +spin_lock_irqsave (&mc->vc.lock, flags); val =readl_relaxed (mc->reg_ch_base +MLB_HDMAC_DMACA ); val &= ~MLB_HDMAC_PB ;writel_relaxed (val, mc->reg_ch_base +MLB_HDMAC_DMACA ); -spin_unlock (&mc->vc.lock); +spin_unlock_irqrestore (&mc->vc.lock, flags);return 0 ; } --2.43.0
Vinod Koul
maintainerQuoted 9 lines · Ginger Li
milbeaut_hdmac_interrupt()is a hardirq handler and takesmc->vc.lockwith a plainspin_lock()for the whole time it runs. interrupts are disabled locally in that context, so the handler itself is fine.
milbeaut_hdmac_chan_config(),milbeaut_hdmac_chan_pause()andmilbeaut_hdmac_chan_resume()are called from process context and take the same lock with a plainspin_lock()as well, so interrupts stay enabled while the lock is held.
Quoted 7 lines
If a channel interrupt is delivered on the CPU that is inside one of those critical sections,
milbeaut_hdmac_interrupt()spins on a lock that the interrupted code is holding and can never release, and the CPU hangs.Take
mc->vc.lockwithspin_lock_irqsave()in those three functions, asmilbeaut_hdmac_issue_pending()and the other process context users of this lock already do.
Have you seen this deadlock in reallife, any logs?
Signature · 1 line
~Vinod