提交 f521dbf3 编写于 作者: J Jakub Kicinski 提交者: Yang Yingliang

net: disable netpoll on fresh napis

stable inclusion
from linux-4.19.145
commit 9f313bcb3b3d021f9b2f04f6d8464f8e9e309452

--------------------------------

[ Upstream commit 96e97bc0 ]

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: NRob Sherwood <rsher@fb.com>
Fixes: 2d8bff12 ("netpoll: Close race condition between poll_one_napi and napi_disable")
Signed-off-by: NJakub Kicinski <kuba@kernel.org>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NAichun Li <liaichun@huawei.com>
Reviewed-by: Nwangxiaopeng <wangxiaopeng7@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 5d7befcc
...@@ -6196,12 +6196,13 @@ void netif_napi_add(struct net_device *dev, struct napi_struct *napi, ...@@ -6196,12 +6196,13 @@ 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", pr_err_once("netif_napi_add() called with weight %d on device %s\n",
weight, dev->name); weight, dev->name);
napi->weight = weight; napi->weight = weight;
list_add(&napi->dev_list, &dev->napi_list);
napi->dev = dev; napi->dev = dev;
#ifdef CONFIG_NETPOLL #ifdef CONFIG_NETPOLL
napi->poll_owner = -1; napi->poll_owner = -1;
#endif #endif
set_bit(NAPI_STATE_SCHED, &napi->state); set_bit(NAPI_STATE_SCHED, &napi->state);
set_bit(NAPI_STATE_NPSVC, &napi->state);
list_add_rcu(&napi->dev_list, &dev->napi_list);
napi_hash_add(napi); napi_hash_add(napi);
} }
EXPORT_SYMBOL(netif_napi_add); EXPORT_SYMBOL(netif_napi_add);
......
...@@ -161,7 +161,7 @@ static void poll_napi(struct net_device *dev) ...@@ -161,7 +161,7 @@ static void poll_napi(struct net_device *dev)
struct napi_struct *napi; struct napi_struct *napi;
int cpu = smp_processor_id(); int cpu = smp_processor_id();
list_for_each_entry(napi, &dev->napi_list, dev_list) { list_for_each_entry_rcu(napi, &dev->napi_list, dev_list) {
if (cmpxchg(&napi->poll_owner, -1, cpu) == -1) { if (cmpxchg(&napi->poll_owner, -1, cpu) == -1) {
poll_one_napi(napi); poll_one_napi(napi);
smp_store_release(&napi->poll_owner, -1); smp_store_release(&napi->poll_owner, -1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册