Skip to content

Commit 96e97bc

Browse files
kuba-moodavem330
authored andcommitted
net: disable netpoll on fresh napis
napi_disable() makes sure to set the NAPI_STATE_NPSVC bit to prevent netpoll from accessing rings before init is complete. However, the same is not done for fresh napi instances in netif_napi_add(), even though we expect NAPI instances to be added as disabled. This causes crashes during driver reconfiguration (enabling XDP, changing the channel count) - if there is any printk() after netif_napi_add() but before napi_enable(). To ensure memory ordering is correct we need to use RCU accessors. Reported-by: Rob Sherwood <[email protected]> Fixes: 2d8bff1 ("netpoll: Close race condition between poll_one_napi and napi_disable") Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7f6f32b commit 96e97bc

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

net/core/dev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6612,12 +6612,13 @@ void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
66126612
netdev_err_once(dev, "%s() called with weight %d\n", __func__,
66136613
weight);
66146614
napi->weight = weight;
6615-
list_add(&napi->dev_list, &dev->napi_list);
66166615
napi->dev = dev;
66176616
#ifdef CONFIG_NETPOLL
66186617
napi->poll_owner = -1;
66196618
#endif
66206619
set_bit(NAPI_STATE_SCHED, &napi->state);
6620+
set_bit(NAPI_STATE_NPSVC, &napi->state);
6621+
list_add_rcu(&napi->dev_list, &dev->napi_list);
66216622
napi_hash_add(napi);
66226623
}
66236624
EXPORT_SYMBOL(netif_napi_add);

net/core/netpoll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static void poll_napi(struct net_device *dev)
162162
struct napi_struct *napi;
163163
int cpu = smp_processor_id();
164164

165-
list_for_each_entry(napi, &dev->napi_list, dev_list) {
165+
list_for_each_entry_rcu(napi, &dev->napi_list, dev_list) {
166166
if (cmpxchg(&napi->poll_owner, -1, cpu) == -1) {
167167
poll_one_napi(napi);
168168
smp_store_release(&napi->poll_owner, -1);

0 commit comments

Comments
 (0)