Skip to content

Commit e51d739

Browse files
Tom Herbertdavem330
authored andcommitted
net: Fix locking in flush_backlog
Need to take spinlocks when dequeuing from input_pkt_queue in flush_backlog. Also, flush_backlog can now be called directly from netdev_run_todo. Signed-off-by: Tom Herbert <therbert@google.com> Acked-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ec43b1a commit e51d739

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎net/core/dev.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,17 +2766,19 @@ int netif_receive_skb(struct sk_buff *skb)
27662766
EXPORT_SYMBOL(netif_receive_skb);
27672767

27682768
/* Network device is going away, flush any packets still pending */
2769-
static void flush_backlog(void *arg)
2769+
static void flush_backlog(struct net_device *dev, int cpu)
27702770
{
2771-
struct net_device *dev = arg;
2772-
struct softnet_data *queue = &__get_cpu_var(softnet_data);
2771+
struct softnet_data *queue = &per_cpu(softnet_data, cpu);
27732772
struct sk_buff *skb, *tmp;
2773+
unsigned long flags;
27742774

2775+
spin_lock_irqsave(&queue->input_pkt_queue.lock, flags);
27752776
skb_queue_walk_safe(&queue->input_pkt_queue, skb, tmp)
27762777
if (skb->dev == dev) {
27772778
__skb_unlink(skb, &queue->input_pkt_queue);
27782779
kfree_skb(skb);
27792780
}
2781+
spin_unlock_irqrestore(&queue->input_pkt_queue.lock, flags);
27802782
}
27812783

27822784
static int napi_gro_complete(struct sk_buff *skb)
@@ -5545,6 +5547,7 @@ void netdev_run_todo(void)
55455547
while (!list_empty(&list)) {
55465548
struct net_device *dev
55475549
= list_first_entry(&list, struct net_device, todo_list);
5550+
int i;
55485551
list_del(&dev->todo_list);
55495552

55505553
if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) {
@@ -5556,7 +5559,8 @@ void netdev_run_todo(void)
55565559

55575560
dev->reg_state = NETREG_UNREGISTERED;
55585561

5559-
on_each_cpu(flush_backlog, dev, 1);
5562+
for_each_online_cpu(i)
5563+
flush_backlog(dev, i);
55605564

55615565
netdev_wait_allrefs(dev);
55625566

0 commit comments

Comments
 (0)