From: Xuan Zhuo <xuanzhuo@linux.alibaba.com> To: Jakub Kicinski <kuba@kernel.org> Cc: =?utf-8?q?netdev=40vger=2Ekernel=2Eorg=2C?=@vger.kernel.org, =?utf-8?q?_linyunsheng=40huawei=2Ecom=2C?=@vger.kernel.org, =?utf-8?q?_David_S=2E_Miller_=3Cdavem=40davemloft=2Enet=3E=2C?=@vger.kernel.org, =?utf-8?q?_Eric_Dumazet_=3Cedumazet=40google=2Ecom=3E=2C?=@vger.kernel.org, =?utf-8?q?_Daniel_Borkmann_=3Cdaniel=40iogearbox=2Enet=3E=2C?=@vger.kernel.org, =?utf-8?q?_Antoine_Tenart_=3Catenart=40kernel=2Eorg=3E=2C?=@vger.kernel.org, =?utf-8?q?_Alexander_Lobakin_=3Calobakin=40pm=2Eme=3E=2C?=@vger.kernel.org, =?utf-8?q?_Wei_Wang_=3Cweiwan=40google=2Ecom=3E=2C?=@vger.kernel.org, =?utf-8?q?_Taehee_Yoo_=3Cap420073=40gmail=2Ecom=3E=2C?=@vger.kernel.org, =?utf-8?b?IEJqw7ZybiBUw7ZwZWwgPGJqb3JuQGtlcm5lbC5vcmc+LA==?=@vger.kernel.org, =?utf-8?q?_Arnd_Bergmann_=3Carnd=40arndb=2Ede=3E=2C?=@vger.kernel.org, =?utf-8?q?_Kumar_Kartikeya_Dwivedi_=3Cmemxor=40gmail=2Ecom=3E=2C?=@vger.kernel.org, =?utf-8?q?_Neil_Horman_=3Cnhorman=40redhat=2Ecom=3E=2C?=@vger.kernel.org, =?utf-8?q?_Dust_Li_=3Cdust=2Eli=40linux=2Ealibaba=2Ecom=3E?=@vger.kernel.org Subject: Re: [PATCH net v2] napi: fix race inside napi_enable Date: Wed, 22 Sep 2021 14:47:47 +0800 [thread overview] Message-ID: <1632293267.9421082-1-xuanzhuo@linux.alibaba.com> (raw) In-Reply-To: <20210920122024.283fe8b2@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> On Mon, 20 Sep 2021 12:20:24 -0700, Jakub Kicinski <kuba@kernel.org> wrote: > On Sat, 18 Sep 2021 16:52:32 +0800 Xuan Zhuo wrote: > > The process will cause napi.state to contain NAPI_STATE_SCHED and > > not in the poll_list, which will cause napi_disable() to get stuck. > > > > The prefix "NAPI_STATE_" is removed in the figure below, and > > NAPI_STATE_HASHED is ignored in napi.state. > > > > CPU0 | CPU1 | napi.state > > =============================================================================== > > napi_disable() | | SCHED | NPSVC > > napi_enable() | | > > { | | > > smp_mb__before_atomic(); | | > > clear_bit(SCHED, &n->state); | | NPSVC > > | napi_schedule_prep() | SCHED | NPSVC > > | napi_poll() | > > | napi_complete_done() | > > | { | > > | if (n->state & (NPSVC | | (1) > > | _BUSY_POLL))) | > > | return false; | > > | ................ | > > | } | SCHED | NPSVC > > | | > > clear_bit(NPSVC, &n->state); | | SCHED > > } | | > > | | > > napi_schedule_prep() | | SCHED | MISSED (2) > > > > (1) Here return direct. Because of NAPI_STATE_NPSVC exists. > > (2) NAPI_STATE_SCHED exists. So not add napi.poll_list to sd->poll_list > > > > Since NAPI_STATE_SCHED already exists and napi is not in the > > sd->poll_list queue, NAPI_STATE_SCHED cannot be cleared and will always > > exist. > > > > 1. This will cause this queue to no longer receive packets. > > 2. If you encounter napi_disable under the protection of rtnl_lock, it > > will cause the entire rtnl_lock to be locked, affecting the overall > > system. > > > > This patch uses cmpxchg to implement napi_enable(), which ensures that > > there will be no race due to the separation of clear two bits. > > > > Fixes: 2d8bff12699abc ("netpoll: Close race condition between poll_one_napi and napi_disable") > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> > > Reviewed-by: Dust Li <dust.li@linux.alibaba.com> > > Why don't you just invert the order of clearing the bits: I think it should be an atomic operation. The original two-step clear itself is problematic. So from this perspective, it is not just a solution to this problem. Thanks. > > diff --git a/net/core/dev.c b/net/core/dev.c > index a796754f75cc..706eca8112c1 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -6953,8 +6953,8 @@ void napi_enable(struct napi_struct *n) > { > BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state)); > smp_mb__before_atomic(); > - clear_bit(NAPI_STATE_SCHED, &n->state); > clear_bit(NAPI_STATE_NPSVC, &n->state); > + clear_bit(NAPI_STATE_SCHED, &n->state); > if (n->dev->threaded && n->thread) > set_bit(NAPI_STATE_THREADED, &n->state); > } > > That's simpler and symmetric with the disable path.
next prev parent reply other threads:[~2021-09-22 6:48 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-18 8:52 Xuan Zhuo 2021-09-20 8:50 ` patchwork-bot+netdevbpf 2021-09-20 19:20 ` Jakub Kicinski 2021-09-22 6:47 ` Xuan Zhuo [this message] 2021-09-23 13:14 ` Jakub Kicinski [not found] ` <1632404456.506512-1-xuanzhuo@linux.alibaba.com> 2021-09-23 14:54 ` Jakub Kicinski 2021-10-18 21:58 ` Sukadev Bhattiprolu 2021-10-18 22:55 ` Jakub Kicinski 2021-10-18 23:36 ` Dany Madden 2021-10-18 23:47 ` Jakub Kicinski 2021-10-19 0:01 ` Sukadev Bhattiprolu 2021-10-22 3:16 ` Sukadev Bhattiprolu 2021-10-25 17:36 ` Jakub Kicinski
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=1632293267.9421082-1-xuanzhuo@linux.alibaba.com \ --to=xuanzhuo@linux.alibaba.com \ --cc==?utf-8?b?IEJqw7ZybiBUw7ZwZWwgPGJqb3JuQGtlcm5lbC5vcmc+LA==?=@vger.kernel.org \ --cc==?utf-8?q?_Alexander_Lobakin_=3Calobakin=40pm=2Eme=3E=2C?=@vger.kernel.org \ --cc==?utf-8?q?_Antoine_Tenart_=3Catenart=40kernel=2Eorg=3E=2C?=@vger.kernel.org \ --cc==?utf-8?q?_Arnd_Bergmann_=3Carnd=40arndb=2Ede=3E=2C?=@vger.kernel.org \ --cc==?utf-8?q?_Daniel_Borkmann_=3Cdaniel=40iogearbox=2Enet=3E=2C?=@vger.kernel.org \ --cc==?utf-8?q?_David_S=2E_Miller_=3Cdavem=40davemloft=2Enet=3E=2C?=@vger.kernel.org \ --cc==?utf-8?q?_Dust_Li_=3Cdust=2Eli=40linux=2Ealibaba=2Ecom=3E?=@vger.kernel.org \ --cc==?utf-8?q?_Eric_Dumazet_=3Cedumazet=40google=2Ecom=3E=2C?=@vger.kernel.org \ --cc==?utf-8?q?_Kumar_Kartikeya_Dwivedi_=3Cmemxor=40gmail=2Ecom=3E=2C?=@vger.kernel.org \ --cc==?utf-8?q?_Neil_Horman_=3Cnhorman=40redhat=2Ecom=3E=2C?=@vger.kernel.org \ --cc==?utf-8?q?_Taehee_Yoo_=3Cap420073=40gmail=2Ecom=3E=2C?=@vger.kernel.org \ --cc==?utf-8?q?_Wei_Wang_=3Cweiwan=40google=2Ecom=3E=2C?=@vger.kernel.org \ --cc==?utf-8?q?_linyunsheng=40huawei=2Ecom=2C?=@vger.kernel.org \ --cc==?utf-8?q?netdev=40vger=2Ekernel=2Eorg=2C?=@vger.kernel.org \ --cc=kuba@kernel.org \ --subject='Re: [PATCH net v2] napi: fix race inside napi_enable' \ /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
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.