Skip to contentSkip to conversation

netpoll: tx lock deadlock fix

PATCH In review Stephen Hemminger 2 participants 2 messages May 30, 2007 – Jun 27, 2007

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

PATCH 1/1 netpoll: tx lock deadlock fix

If sky2 device poll routine is called from netpoll_send_skb, it would deadlock. The netpoll_send_skb held the netif_tx_lock, and the poll routine could acquire it to clean up skb's. Other drivers might use same locking model.

The driver is correct, netpoll should not introduce more locking problems than it causes already. So change the code to drop lock before calling poll handler.

net/core/netpoll.c +10 -9
@@ -250,22 +250,23 @@ static void netpoll_send_skb(struct netp
 		unsigned long flags;
 
 		local_irq_save(flags);
-		if (netif_tx_trylock(dev)) {
-			/* try until next clock tick */
-			for (tries = jiffies_to_usecs(1)/USEC_PER_POLL;
-					tries > 0; --tries) {
+		/* try until next clock tick */
+		for (tries = jiffies_to_usecs(1)/USEC_PER_POLL;
+		     tries > 0; --tries) {
+			if (netif_tx_trylock(dev)) {
 				if (!netif_queue_stopped(dev))
 					status = dev->hard_start_xmit(skb, dev);
+				netif_tx_unlock(dev);
 
 				if (status == NETDEV_TX_OK)
 					break;
 
-				/* tickle device maybe there is some cleanup */
-				netpoll_poll(np);
-
-				udelay(USEC_PER_POLL);
 			}
-			netif_tx_unlock(dev);
+
+			/* tickle device maybe there is some cleanup */
+			netpoll_poll(np);
+
+			udelay(USEC_PER_POLL);
 		}
 		local_irq_restore(flags);
 	}
maintainer
#1 lore raw

From: Stephen Hemminger <[email protected]>
Date: Tue, 29 May 2007 17:32:21 -0700

Quoted 10 lines

If sky2 device poll routine is called from netpoll_send_skb, it would deadlock. The netpoll_send_skb held the netif_tx_lock, and the poll routine could acquire it to clean up skb's. Other drivers might use same locking model.

The driver is correct, netpoll should not introduce more locking problems than it causes already. So change the code to drop lock before calling poll handler.

Patch applied, thanks Stephen.

Once I get this to Linus would you like me to toss it over to the -stable folks too?

Thanks.