Skip to content

Commit b0e28f1

Browse files
Eric Dumazetdavem330
authored andcommitted
net: netif_rx() must disable preemption
Eric Paris reported netif_rx() is calling smp_processor_id() from preemptible context, in particular when caller is ip_dev_loopback_xmit(). RPS commit added this smp_processor_id() call, this patch makes sure preemption is disabled. rps_get_cpus() wants rcu_read_lock() anyway, we can dot it a bit earlier. Reported-by: Eric Paris <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fea0691 commit b0e28f1

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

net/core/dev.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,7 @@ DEFINE_PER_CPU(struct netif_rx_stats, netdev_rx_stat) = { 0, };
22062206
/*
22072207
* get_rps_cpu is called from netif_receive_skb and returns the target
22082208
* CPU from the RPS map of the receiving queue for a given skb.
2209+
* rcu_read_lock must be held on entry.
22092210
*/
22102211
static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb)
22112212
{
@@ -2217,8 +2218,6 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb)
22172218
u8 ip_proto;
22182219
u32 addr1, addr2, ports, ihl;
22192220

2220-
rcu_read_lock();
2221-
22222221
if (skb_rx_queue_recorded(skb)) {
22232222
u16 index = skb_get_rx_queue(skb);
22242223
if (unlikely(index >= dev->num_rx_queues)) {
@@ -2296,7 +2295,6 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb)
22962295
}
22972296

22982297
done:
2299-
rcu_read_unlock();
23002298
return cpu;
23012299
}
23022300

@@ -2392,7 +2390,7 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu)
23922390

23932391
int netif_rx(struct sk_buff *skb)
23942392
{
2395-
int cpu;
2393+
int ret;
23962394

23972395
/* if netpoll wants it, pretend we never saw it */
23982396
if (netpoll_rx(skb))
@@ -2402,14 +2400,21 @@ int netif_rx(struct sk_buff *skb)
24022400
net_timestamp(skb);
24032401

24042402
#ifdef CONFIG_RPS
2405-
cpu = get_rps_cpu(skb->dev, skb);
2406-
if (cpu < 0)
2407-
cpu = smp_processor_id();
2403+
{
2404+
int cpu;
2405+
2406+
rcu_read_lock();
2407+
cpu = get_rps_cpu(skb->dev, skb);
2408+
if (cpu < 0)
2409+
cpu = smp_processor_id();
2410+
ret = enqueue_to_backlog(skb, cpu);
2411+
rcu_read_unlock();
2412+
}
24082413
#else
2409-
cpu = smp_processor_id();
2414+
ret = enqueue_to_backlog(skb, get_cpu());
2415+
put_cpu();
24102416
#endif
2411-
2412-
return enqueue_to_backlog(skb, cpu);
2417+
return ret;
24132418
}
24142419
EXPORT_SYMBOL(netif_rx);
24152420

0 commit comments

Comments
 (0)