]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: disable netpoll on fresh napis
authorJakub Kicinski <kuba@kernel.org>
Wed, 26 Aug 2020 19:40:06 +0000 (12:40 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 12 Sep 2020 09:45:33 +0000 (11:45 +0200)
[ Upstream commit 96e97bc07e90f175a8980a22827faf702ca4cb30 ]

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 <rsher@fb.com>
Fixes: 2d8bff12699a ("netpoll: Close race condition between poll_one_napi and napi_disable")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/core/dev.c
net/core/netpoll.c

index 09115c68f29dcb62abf7c08c8870892a186652be..59157e9686fb2d2650bec1d4a0b0b2d7756d8e72 100644 (file)
@@ -4849,13 +4849,14 @@ void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
                pr_err_once("netif_napi_add() called with weight %d on device %s\n",
                            weight, dev->name);
        napi->weight = weight;
-       list_add(&napi->dev_list, &dev->napi_list);
        napi->dev = dev;
 #ifdef CONFIG_NETPOLL
        spin_lock_init(&napi->poll_lock);
        napi->poll_owner = -1;
 #endif
        set_bit(NAPI_STATE_SCHED, &napi->state);
+       set_bit(NAPI_STATE_NPSVC, &napi->state);
+       list_add_rcu(&napi->dev_list, &dev->napi_list);
 }
 EXPORT_SYMBOL(netif_napi_add);
 
index 0d7c2cc1ff09d5480959b9bf3590786dab66492d..f2610f8f171ca9a911cca827088f0c868840bf9a 100644 (file)
@@ -178,7 +178,7 @@ static void poll_napi(struct net_device *dev)
 {
        struct napi_struct *napi;
 
-       list_for_each_entry(napi, &dev->napi_list, dev_list) {
+       list_for_each_entry_rcu(napi, &dev->napi_list, dev_list) {
                if (napi->poll_owner != smp_processor_id() &&
                    spin_trylock(&napi->poll_lock)) {
                        poll_one_napi(napi);