Skip to contentSkip to conversation

net: davinci_emac: fix spinlock bug with dma channel cleanup

PATCH In review Sriramakrishnan A G 2 participants 2 messages Apr 12, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: davinci_emac: fix spinlock bug with dma channel cleanup

The DMA cleanup function was holding the spinlock across a busy loop where it waits for HW to indicate teardown is complete. This generates a backtrace, when DEBUG_SPINLOCK is enabled. Make the locking more granular.

---
 drivers/net/davinci_cpdma.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/net/davinci_cpdma.c +3 -0
index ae47f23..57fd0fc 100644
@@ -824,6 +824,8 @@ int cpdma_chan_stop(struct cpdma_chan *chan)
 	/* trigger teardown */
 	dma_reg_write(ctlr, chan->td, chan->chan_num);
 
+	spin_unlock_irqrestore(&chan->lock, flags);
+
 	/* wait for teardown complete */
 	timeout = jiffies + HZ/10;	/* 100 msec */
 	while (time_before(jiffies, timeout)) {
@@ -843,6 +845,7 @@ int cpdma_chan_stop(struct cpdma_chan *chan)
 	} while ((ret & CPDMA_DESC_TD_COMPLETE) == 0);
 
 	/* remaining packets haven't been tx/rx'ed, clean them up */
+	spin_lock_irqsave(&chan->lock, flags);
 	while (chan->head) {
 		struct cpdma_desc __iomem *desc = chan->head;
 		dma_addr_t next_dma;
Signature · 1 line
1.6.2.4
maintainer
#1 lore raw

From: Sriramakrishnan A G <[email protected]>
Date: Tue, 12 Apr 2011 10:12:31 +0530

Quoted 6 lines

The DMA cleanup function was holding the spinlock across a busy loop where it waits for HW to indicate teardown is complete. This generates a backtrace, when DEBUG_SPINLOCK is enabled. Make the locking more granular.

You can't really sleep in this function at all.

For example, it gets invoked from the ->ndo_tx_timeout() method in davinci_emac.c, which runs from a timer.

So even if you hack the spinlock usage, there are still major issues here.

We could conditionalize the timeout handling, but I don't think so much complexity is worth it here.

Just do a udelay()/mdelay() or similar, instead of the timed sleeps.

Thanks.