dmaengine: milbeaut-hdmac: Fix potential deadlock on &mc->vc.lock
Subsystems (2)
PATCH RESEND 1/1 dmaengine: milbeaut-hdmac: Fix potential deadlock on &mc->vc.lock
As &mc->vc.lock is acquired by milbeaut_hdmac_interrupt() under irq context, other acquisition of the same lock under process context should disable irq, otherwise deadlock could happen if the irq preempts the execution of process context code while the lock is held in process context on the same CPU.
milbeaut_hdmac_chan_config(), milbeaut_hdmac_chan_resume() and milbeaut_hdmac_chan_pause() are such callback functions not disable irq by default.
Possible deadlock scenario:milbeaut_hdmac_chan_config()
-> spin_lock(&mc->vc.lock)
<hard interruption>
-> milbeaut_hdmac_interrupt()
-> spin_lock(&mc->vc.lock); (deadlock here)This flaw was found by an experimental static analysis tool I am developing for irq-related deadlock.
The tentative patch fixes the potential deadlock by spin_lock_irqsave() in the three callback functions to disable irq while lock is held.
--- 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, struct dma_slave_config *cfg) {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 *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 *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.17.1
Hi maintainers,
May I ask if anyone would like to review the patch?
Thanks,
Chengfeng
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 34 lines · Chengfeng Ye
As
&mc->vc.lockis acquired bymilbeaut_hdmac_interrupt()under irq context, other acquisition of the same lock under process context should disable irq, otherwise deadlock could happen if the irq preempts the execution of process context code while the lock is held in process context on the same CPU.
milbeaut_hdmac_chan_config(),milbeaut_hdmac_chan_resume()andmilbeaut_hdmac_chan_pause()are such callback functions not disable irq by default.Possible deadlock scenario:
milbeaut_hdmac_chan_config()-> spin_lock(&mc->vc.lock) <hard interruption> -> milbeaut_hdmac_interrupt() -> spin_lock(&mc->vc.lock); (deadlock here)This flaw was found by an experimental static analysis tool I am developing for irq-related deadlock.
The tentative patch fixes the potential deadlock by
spin_lock_irqsave()in the three callback functions to disable irq while lock is held.Signed-off-by Chengfeng Ye <[email protected]>--- drivers/dma/milbeaut-hdmac.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/dma/milbeaut-hdmac.c +0
-0
drivers/dma/milbeaut-hdmac.c milbeaut_hdmac_chan_config(struct dma_chan *chan, struct dma_slave_config *cfg) · line 220
Quoted 8 lines
drivers/dma/milbeaut-hdmac.c +2
-1@@ -214,10 +214,11 @@ milbeaut_hdmac_chan_config(struct dma_chan *chan, struct dma_slave_config *cfg) {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);
while at it, maybe also use vc->lock, instead of mc->vc.lock here and in other two places, just like the rest of driver.
thanks.
Quoted 2 lines
while at it, maybe also use
vc->lock, instead ofmc->vc.lockhere and in other two places, just like the rest of driver.
Thanks for the review, v2 patch is just sent to address the problem.
Thanks,
Chengfeng
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel