dmaengine: xilinx: dpdma: Fix race condition in vsync IRQ
Subsystems (3)
PATCH 1/1 dmaengine: xilinx: dpdma: Fix race condition in vsync IRQ
Protected race condition of virtual DMA channel from channel queue transfer via vchan spin lock from the caller of xilinx_dpdma_chan_queue_transfer
--- drivers/dma/xilinx/xilinx_dpdma.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/dma/xilinx/xilinx_dpdma.c +4 -0
@@ -1102,7 +1102,9 @@ static void xilinx_dpdma_chan_vsync_irq(struct xilinx_dpdma_chan *chan) chan->desc.active = pending; chan->desc.pending =NULL ; +spin_lock (&chan->vchan.lock);xilinx_dpdma_chan_queue_transfer (chan); +spin_unlock (&chan->vchan.lock); out:spin_unlock_irqrestore (&chan->lock, flags);
@@ -1495,7 +1497,9 @@ static void xilinx_dpdma_chan_err_task(struct tasklet_struct *t) XILINX_DPDMA_EINTR_CHAN_ERR_MASK << chan->id);spin_lock_irqsave (&chan->lock, flags); +spin_lock (&chan->vchan.lock);xilinx_dpdma_chan_queue_transfer (chan); +spin_unlock (&chan->vchan.lock);spin_unlock_irqrestore (&chan->lock, flags); }
--
2.17.1
This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.
Laurent Pinchart
maintainerHi Neel,
Thank you for the patch.
Quoted 2 lines · Neel Gandhi
Protected race condition of virtual DMA channel from channel queue transfer via vchan spin lock from the caller of
xilinx_dpdma_chan_queue_transfer
This should explain what the race condition is, as it's not immediately apparent from the patch itself. You can write it as
The vchan_next_desc() function, called from xilinx_dpdma_chan_queue_transfer(), must be called with virt_dma_chan.lock held. This isn't correctly handled in all code paths, resulting in a race condition between the .device_issue_pending() handler and the IRQ handler which causes DMA to randomly stop. Fix it by taking the lock around xilinx_dpdma_chan_queue_transfer() calls that are missing it.
drivers/dma/xilinx/xilinx_dpdma.c static void xilinx_dpdma_chan_vsync_irq(struct xilinx_dpdma_chan *chan)
Quoted 10 lines
Signed-off-by Neel Gandhi <[email protected]>--- drivers/dma/xilinx/xilinx_dpdma.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/dma/xilinx/xilinx_dpdma.c +0
-0@@ -1102,7 +1102,9 @@ static void xilinx_dpdma_chan_vsync_irq(struct xilinx_dpdma_chan *chan)
Adding some context:
if (chan->desc.active) vchan_cookie_complete(&chan->desc.active->vdesc);
drivers/dma/xilinx/xilinx_dpdma.c static void xilinx_dpdma_chan_vsync_irq(struct xilinx_dpdma_chan *chan) · line 1107
Quoted 6 lines
drivers/dma/xilinx/xilinx_dpdma.c +2
-0chan->desc.active = pending; chan->desc.pending =NULL ; +spin_lock (&chan->vchan.lock);xilinx_dpdma_chan_queue_transfer (chan); +spin_unlock (&chan->vchan.lock);
There seems to be one more race condition here. vchan_cookie_complete() is documented as requiring the vchan.lock being held too. Moving the spin_lock() call before that should be enough to fix it.
It would probably be useful to revisit locking in this driver, but for now, with the issues pointed out here fixed, this patch should be good enough. Can you submit a v2 ?
Quoted 13 lines
drivers/dma/xilinx/xilinx_dpdma.c +2
-0out:spin_unlock_irqrestore (&chan->lock, flags);@@ -1495,7 +1497,9 @@ static void xilinx_dpdma_chan_err_task(struct tasklet_struct *t) XILINX_DPDMA_EINTR_CHAN_ERR_MASK << chan->id);spin_lock_irqsave (&chan->lock, flags); +spin_lock (&chan->vchan.lock);xilinx_dpdma_chan_queue_transfer (chan); +spin_unlock (&chan->vchan.lock);spin_unlock_irqrestore (&chan->lock, flags); }
Signature · 3 lines
Regards, Laurent Pinchart