From: Jakub Kicinski <kuba@kernel.org>
To: eric.dumazet@gmail.com
Cc: davem@davemloft.net, netdev@vger.kernel.org, kernel-team@fb.com,
Jakub Kicinski <kuba@kernel.org>
Subject: [RFC -next 2/3] net: manage napi add/del idempotence explicitly
Date: Thu, 27 Aug 2020 15:32:49 -0700 [thread overview]
Message-ID: <20200827223250.2045503-3-kuba@kernel.org> (raw)
In-Reply-To: <20200827223250.2045503-1-kuba@kernel.org>
To RCUify napi->dev_list we need to replace list_del_init()
with list_del_rcu(). There is no _init() version for RCU for
obvious reasons. Up until now netif_napi_del() was idempotent
so to make sure it remains such add a bit which is set when
NAPI is listed, and cleared when it removed. Since we don't
expect multiple calls to netif_napi_add() to be correct,
add a warning on that side.
Now that napi_hash_add / napi_hash_del are only called by
napi_add / del we can actually steal its bit. We just need
to make sure hash node is initialized correctly.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
include/linux/netdevice.h | 4 ++--
net/core/dev.c | 13 +++++++++----
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 67400efa6f00..55738cd862b5 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -355,7 +355,7 @@ enum {
NAPI_STATE_MISSED, /* reschedule a napi */
NAPI_STATE_DISABLE, /* Disable pending */
NAPI_STATE_NPSVC, /* Netpoll - don't dequeue from poll_list */
- NAPI_STATE_HASHED, /* In NAPI hash (busy polling possible) */
+ NAPI_STATE_LISTED, /* NAPI added to system lists */
NAPI_STATE_NO_BUSY_POLL,/* Do not add in napi_hash, no busy polling */
NAPI_STATE_IN_BUSY_POLL,/* sk_busy_loop() owns this NAPI */
};
@@ -365,7 +365,7 @@ enum {
NAPIF_STATE_MISSED = BIT(NAPI_STATE_MISSED),
NAPIF_STATE_DISABLE = BIT(NAPI_STATE_DISABLE),
NAPIF_STATE_NPSVC = BIT(NAPI_STATE_NPSVC),
- NAPIF_STATE_HASHED = BIT(NAPI_STATE_HASHED),
+ NAPIF_STATE_LISTED = BIT(NAPI_STATE_LISTED),
NAPIF_STATE_NO_BUSY_POLL = BIT(NAPI_STATE_NO_BUSY_POLL),
NAPIF_STATE_IN_BUSY_POLL = BIT(NAPI_STATE_IN_BUSY_POLL),
};
diff --git a/net/core/dev.c b/net/core/dev.c
index d2c6fa24aa23..623060907132 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6533,8 +6533,7 @@ EXPORT_SYMBOL(napi_busy_loop);
static void napi_hash_add(struct napi_struct *napi)
{
- if (test_bit(NAPI_STATE_NO_BUSY_POLL, &napi->state) ||
- test_and_set_bit(NAPI_STATE_HASHED, &napi->state))
+ if (test_bit(NAPI_STATE_NO_BUSY_POLL, &napi->state))
return;
spin_lock(&napi_hash_lock);
@@ -6559,8 +6558,7 @@ static void napi_hash_del(struct napi_struct *napi)
{
spin_lock(&napi_hash_lock);
- if (test_and_clear_bit(NAPI_STATE_HASHED, &napi->state))
- hlist_del_rcu(&napi->napi_hash_node);
+ hlist_del_init_rcu(&napi->napi_hash_node);
spin_unlock(&napi_hash_lock);
}
@@ -6595,7 +6593,11 @@ static void init_gro_hash(struct napi_struct *napi)
void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
int (*poll)(struct napi_struct *, int), int weight)
{
+ if (WARN_ON(test_and_set_bit(NAPI_STATE_LISTED, &napi->state)))
+ return;
+
INIT_LIST_HEAD(&napi->poll_list);
+ INIT_HLIST_NODE(&napi->napi_hash_node);
hrtimer_init(&napi->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED);
napi->timer.function = napi_watchdog;
init_gro_hash(napi);
@@ -6650,6 +6652,9 @@ static void flush_gro_hash(struct napi_struct *napi)
/* Must be called in process context */
void __netif_napi_del(struct napi_struct *napi)
{
+ if (!test_and_clear_bit(NAPI_STATE_LISTED, &napi->state))
+ return;
+
napi_hash_del(napi);
list_del_init(&napi->dev_list);
napi_free_frags(napi);
--
2.26.2
next prev parent reply other threads:[~2020-08-27 22:33 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
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 ` Jakub Kicinski [this message]
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=20200827223250.2045503-3-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
/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).