From: Gilad Naaman <gnaaman@drivenets.com>
To: netdev <netdev@vger.kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Gilad Naaman <gnaaman@drivenets.com>,
Kuniyuki Iwashima <kuniyu@amazon.com>,
Ido Schimmel <idosch@nvidia.com>, Petr Machata <petrm@nvidia.com>
Subject: [PATCH net-next v5 4/6] Convert neighbour iteration to use hlist+macro
Date: Thu, 17 Oct 2024 07:04:39 +0000 [thread overview]
Message-ID: <20241017070445.4013745-5-gnaaman@drivenets.com> (raw)
In-Reply-To: <20241017070445.4013745-1-gnaaman@drivenets.com>
Remove all usage of the bare neighbour::next pointer,
replacing them with neighbour::hash and its for_each macro.
Signed-off-by: Gilad Naaman <gnaaman@drivenets.com>
---
include/net/neighbour.h | 7 +++----
net/core/neighbour.c | 34 +++++++++++++---------------------
2 files changed, 16 insertions(+), 25 deletions(-)
diff --git a/include/net/neighbour.h b/include/net/neighbour.h
index 14f08a2e4f74..96528a6cd74b 100644
--- a/include/net/neighbour.h
+++ b/include/net/neighbour.h
@@ -278,6 +278,8 @@ static inline void *neighbour_priv(const struct neighbour *n)
extern const struct nla_policy nda_policy[];
#define neigh_for_each(pos, head) hlist_for_each_entry(pos, head, hash)
+#define neigh_for_each_safe(pos, tmp, head) \
+ hlist_for_each_entry_safe(pos, tmp, head, hash)
#define neigh_first_entry(bucket) \
hlist_entry_safe((bucket)->first, struct neighbour, hash)
@@ -309,12 +311,9 @@ static inline struct neighbour *___neigh_lookup_noref(
u32 hash_val;
hash_val = hash(pkey, dev, nht->hash_rnd) >> (32 - nht->hash_shift);
- for (n = rcu_dereference(nht->hash_buckets[hash_val]);
- n != NULL;
- n = rcu_dereference(n->next)) {
+ neigh_for_each(n, &nht->hash_heads[hash_val])
if (n->dev == dev && key_eq(n, pkey))
return n;
- }
return NULL;
}
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index e4e31d2ca2ea..a1dd419655a1 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -391,8 +391,7 @@ static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev,
struct neighbour *n;
struct neighbour __rcu **np = &nht->hash_buckets[i];
- while ((n = rcu_dereference_protected(*np,
- lockdep_is_held(&tbl->lock))) != NULL) {
+ neigh_for_each(n, &nht->hash_heads[i]) {
if (dev && n->dev != dev) {
np = &n->next;
continue;
@@ -621,11 +620,9 @@ static struct neigh_hash_table *neigh_hash_grow(struct neigh_table *tbl,
for (i = 0; i < (1 << old_nht->hash_shift); i++) {
struct neighbour *n, *next;
+ struct hlist_node *tmp;
- for (n = rcu_dereference_protected(old_nht->hash_buckets[i],
- lockdep_is_held(&tbl->lock));
- n != NULL;
- n = next) {
+ neigh_for_each_safe(n, tmp, &old_nht->hash_heads[i]) {
hash = tbl->hash(n->primary_key, n->dev,
new_nht->hash_rnd);
@@ -726,11 +723,7 @@ ___neigh_create(struct neigh_table *tbl, const void *pkey,
goto out_tbl_unlock;
}
- for (n1 = rcu_dereference_protected(nht->hash_buckets[hash_val],
- lockdep_is_held(&tbl->lock));
- n1 != NULL;
- n1 = rcu_dereference_protected(n1->next,
- lockdep_is_held(&tbl->lock))) {
+ neigh_for_each(n1, &nht->hash_heads[hash_val]) {
if (dev == n1->dev && !memcmp(n1->primary_key, n->primary_key, key_len)) {
if (want_ref)
neigh_hold(n1);
@@ -982,10 +975,11 @@ static void neigh_connect(struct neighbour *neigh)
static void neigh_periodic_work(struct work_struct *work)
{
struct neigh_table *tbl = container_of(work, struct neigh_table, gc_work.work);
- struct neighbour *n;
+ struct neigh_hash_table *nht;
struct neighbour __rcu **np;
+ struct hlist_node *tmp;
+ struct neighbour *n;
unsigned int i;
- struct neigh_hash_table *nht;
NEIGH_CACHE_STAT_INC(tbl, periodic_gc_runs);
@@ -1012,8 +1006,7 @@ static void neigh_periodic_work(struct work_struct *work)
for (i = 0 ; i < (1 << nht->hash_shift); i++) {
np = &nht->hash_buckets[i];
- while ((n = rcu_dereference_protected(*np,
- lockdep_is_held(&tbl->lock))) != NULL) {
+ neigh_for_each_safe(n, tmp, &nht->hash_heads[i]) {
unsigned int state;
write_lock(&n->lock);
@@ -2763,9 +2756,8 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
for (h = s_h; h < (1 << nht->hash_shift); h++) {
if (h > s_h)
s_idx = 0;
- for (n = rcu_dereference(nht->hash_buckets[h]), idx = 0;
- n != NULL;
- n = rcu_dereference(n->next)) {
+ idx = 0;
+ neigh_for_each(n, &nht->hash_heads[h]) {
if (idx < s_idx || !net_eq(dev_net(n->dev), net))
goto next;
if (neigh_ifindex_filtered(n->dev, filter->dev_idx) ||
@@ -3124,18 +3116,18 @@ static int neigh_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,
void __neigh_for_each_release(struct neigh_table *tbl,
int (*cb)(struct neighbour *))
{
- int chain;
struct neigh_hash_table *nht;
+ int chain;
nht = rcu_dereference_protected(tbl->nht,
lockdep_is_held(&tbl->lock));
for (chain = 0; chain < (1 << nht->hash_shift); chain++) {
struct neighbour *n;
+ struct hlist_node *tmp;
struct neighbour __rcu **np;
np = &nht->hash_buckets[chain];
- while ((n = rcu_dereference_protected(*np,
- lockdep_is_held(&tbl->lock))) != NULL) {
+ neigh_for_each_safe(n, tmp, &nht->hash_heads[chain]) {
int release;
write_lock(&n->lock);
--
2.46.0
next prev parent reply other threads:[~2024-10-17 7:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-17 7:04 [PATCH net-next v5 0/6] Improve neigh_flush_dev performance Gilad Naaman
2024-10-17 7:04 ` [PATCH net-next v5 1/6] Add hlist_node to struct neighbour Gilad Naaman
2024-10-17 7:04 ` [PATCH net-next v5 2/6] Define neigh_for_each Gilad Naaman
2024-10-17 16:26 ` Petr Machata
2024-10-20 7:16 ` Gilad Naaman
2024-10-21 9:07 ` Petr Machata
2024-10-17 7:04 ` [PATCH net-next v5 3/6] Convert neigh_* seq_file functions to use hlist Gilad Naaman
2024-10-17 7:04 ` Gilad Naaman [this message]
2024-10-18 11:42 ` [PATCH net-next v5 4/6] Convert neighbour iteration to use hlist+macro Simon Horman
2024-10-17 7:04 ` [PATCH net-next v5 5/6] Remove bare neighbour::next pointer Gilad Naaman
2024-10-18 4:56 ` kernel test robot
2024-10-17 7:04 ` [PATCH net-next v5 6/6] Create netdev->neighbour association Gilad Naaman
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=20241017070445.4013745-5-gnaaman@drivenets.com \
--to=gnaaman@drivenets.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=kuniyu@amazon.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.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).