From: Eric Dumazet <eric.dumazet@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>, davem@davemloft.net
Cc: eric.dumazet@gmail.com, michael.chan@broadcom.com,
netdev@vger.kernel.org, kernel-team@fb.com,
Rob Sherwood <rsher@fb.com>
Subject: Re: [PATCH net 1/2] net: disable netpoll on fresh napis
Date: Thu, 27 Aug 2020 00:25:31 -0700 [thread overview]
Message-ID: <25872247-9776-2638-cf83-a51861ce5cd4@gmail.com> (raw)
In-Reply-To: <20200826194007.1962762-2-kuba@kernel.org>
On 8/26/20 12:40 PM, Jakub Kicinski wrote:
> 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>
> ---
> net/core/dev.c | 3 ++-
> net/core/netpoll.c | 2 +-
> 2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/core/dev.c b/net/core/dev.c
> index d42c9ea0c3c0..95ac7568f693 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -6612,12 +6612,13 @@ void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
> netdev_err_once(dev, "%s() called with weight %d\n", __func__,
> weight);
> napi->weight = weight;
> - list_add(&napi->dev_list, &dev->napi_list);
> napi->dev = dev;
> #ifdef CONFIG_NETPOLL
> 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);
> napi_hash_add(napi);
> }
> EXPORT_SYMBOL(netif_napi_add);
> diff --git a/net/core/netpoll.c b/net/core/netpoll.c
> index 093e90e52bc2..2338753e936b 100644
> --- a/net/core/netpoll.c
> +++ b/net/core/netpoll.c
> @@ -162,7 +162,7 @@ static void poll_napi(struct net_device *dev)
> struct napi_struct *napi;
> 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) {
> poll_one_napi(napi);
> smp_store_release(&napi->poll_owner, -1);
>
You added rcu in this patch (without anything in the changelog).
netpoll_poll_dev() uses rcu_dereference_bh(), suggesting you might need list_for_each_entry_rcu_bh()
next prev parent reply other threads:[~2020-08-27 7:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-26 19:40 [PATCH net 0/2] net: fix netpoll crash with bnxt Jakub Kicinski
2020-08-26 19:40 ` [PATCH net 1/2] net: disable netpoll on fresh napis Jakub Kicinski
2020-08-27 7:25 ` Eric Dumazet [this message]
2020-08-27 15:10 ` Jakub Kicinski
2020-08-27 15:43 ` Eric Dumazet
2020-08-27 17:47 ` Jakub Kicinski
2020-08-27 22:32 ` [RFC -next 0/3] " Jakub Kicinski
2020-08-27 22:32 ` [RFC -next 1/3] net: remove napi_hash_del() from driver-facing API Jakub Kicinski
2020-08-27 22:32 ` [RFC -next 2/3] net: manage napi add/del idempotence explicitly Jakub Kicinski
2020-08-27 22:32 ` [RFC -next 3/3] net: make sure napi_list is safe for RCU traversal Jakub Kicinski
2020-08-26 19:40 ` [PATCH net 2/2] bnxt: don't enable NAPI until rings are ready Jakub Kicinski
2020-08-26 20:23 ` Michael Chan
2020-08-26 23:17 ` [PATCH net 0/2] net: fix netpoll crash with bnxt David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=25872247-9776-2638-cf83-a51861ce5cd4@gmail.com \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=kernel-team@fb.com \
--cc=kuba@kernel.org \
--cc=michael.chan@broadcom.com \
--cc=netdev@vger.kernel.org \
--cc=rsher@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).