netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] netpoll: tx lock deadlock fix
@ 2007-05-30  0:32 Stephen Hemminger
  2007-06-27  7:40 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Hemminger @ 2007-05-30  0:32 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev, Andrew Morton

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.

Signed-off-by: Stephen Hemminger <shemminger@linux.foundation.org>


--- a/net/core/netpoll.c	2007-05-08 14:19:32.000000000 -0700
+++ b/net/core/netpoll.c	2007-05-29 15:28:22.000000000 -0700
@@ -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);
 	}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] netpoll: tx lock deadlock fix
  2007-05-30  0:32 [PATCH] netpoll: tx lock deadlock fix Stephen Hemminger
@ 2007-06-27  7:40 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2007-06-27  7:40 UTC (permalink / raw)
  To: shemminger; +Cc: netdev, akpm

From: Stephen Hemminger <shemminger@linux-foundation.org>
Date: Tue, 29 May 2007 17:32:21 -0700

> 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.
> 
> Signed-off-by: Stephen Hemminger <shemminger@linux.foundation.org>

Patch applied, thanks Stephen.

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

Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-06-27  7:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-30  0:32 [PATCH] netpoll: tx lock deadlock fix Stephen Hemminger
2007-06-27  7:40 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).