Skip to content

Commit d4828d8

Browse files
herbertxDavid S. Miller
authored andcommitted
[NET]: Prevent transmission after dev_deactivate
The dev_deactivate function has bit-rotted since the introduction of lockless drivers. In particular, the spin_unlock_wait call at the end has no effect on the xmit routine of lockless drivers. With a little bit of work, we can make it much more useful by providing the guarantee that when it returns, no more calls to the xmit routine of the underlying driver will be made. The idea is simple. There are two entry points in to the xmit routine. The first comes from dev_queue_xmit. That one is easily stopped by using synchronize_rcu. This works because we set the qdisc to noop_qdisc before the synchronize_rcu call. That in turn causes all subsequent packets sent to dev_queue_xmit to be dropped. The synchronize_rcu call also ensures all outstanding calls leave their critical section. The other entry point is from qdisc_run. Since we now have a bit that indicates whether it's running, all we have to do is to wait until the bit is off. I've removed the loop to wait for __LINK_STATE_SCHED to clear. This is useless because netif_wake_queue can cause it to be set again. It is also harmless because we've disarmed qdisc_run. I've also removed the spin_unlock_wait on xmit_lock because its only purpose of making sure that all outstanding xmit_lock holders have exited is also given by dev_watchdog_down. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5e2707f commit d4828d8

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎net/core/dev.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ int dev_queue_xmit(struct sk_buff *skb)
12951295
/* Disable soft irqs for various locks below. Also
12961296
* stops preemption for RCU.
12971297
*/
1298-
local_bh_disable();
1298+
rcu_read_lock_bh();
12991299

13001300
/* Updates of qdisc are serialized by queue_lock.
13011301
* The struct Qdisc which is pointed to by qdisc is now a
@@ -1369,13 +1369,13 @@ int dev_queue_xmit(struct sk_buff *skb)
13691369
}
13701370

13711371
rc = -ENETDOWN;
1372-
local_bh_enable();
1372+
rcu_read_unlock_bh();
13731373

13741374
out_kfree_skb:
13751375
kfree_skb(skb);
13761376
return rc;
13771377
out:
1378-
local_bh_enable();
1378+
rcu_read_unlock_bh();
13791379
return rc;
13801380
}
13811381

‎net/sched/sch_generic.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,13 @@ static inline int qdisc_restart(struct net_device *dev)
181181

182182
void __qdisc_run(struct net_device *dev)
183183
{
184+
if (unlikely(dev->qdisc == &noop_qdisc))
185+
goto out;
186+
184187
while (qdisc_restart(dev) < 0 && !netif_queue_stopped(dev))
185188
/* NOTHING */;
186189

190+
out:
187191
clear_bit(__LINK_STATE_QDISC_RUNNING, &dev->state);
188192
}
189193

@@ -583,10 +587,12 @@ void dev_deactivate(struct net_device *dev)
583587

584588
dev_watchdog_down(dev);
585589

586-
while (test_bit(__LINK_STATE_SCHED, &dev->state))
587-
yield();
590+
/* Wait for outstanding dev_queue_xmit calls. */
591+
synchronize_rcu();
588592

589-
spin_unlock_wait(&dev->_xmit_lock);
593+
/* Wait for outstanding qdisc_run calls. */
594+
while (test_bit(__LINK_STATE_QDISC_RUNNING, &dev->state))
595+
yield();
590596
}
591597

592598
void dev_init_scheduler(struct net_device *dev)

0 commit comments

Comments
 (0)