Skip to content

Commit b8b7ed1

Browse files
q2venkuba-moo
authored andcommitted
neighbour: Drop read_lock_bh(&tbl->lock) in pneigh_lookup().
Now, all callers of pneigh_lookup() are under RCU, and the read lock there is no longer needed. Let's drop the lock, inline __pneigh_lookup_1() to pneigh_lookup(), and call it from pneigh_create(). The next patch will remove tbl->lock from pneigh_create(). Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent dd103c9 commit b8b7ed1

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

net/core/neighbour.c

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -720,23 +720,6 @@ static u32 pneigh_hash(const void *pkey, unsigned int key_len)
720720
return hash_val;
721721
}
722722

723-
static struct pneigh_entry *__pneigh_lookup_1(struct pneigh_entry *n,
724-
struct net *net,
725-
const void *pkey,
726-
unsigned int key_len,
727-
struct net_device *dev)
728-
{
729-
while (n) {
730-
if (!memcmp(n->key, pkey, key_len) &&
731-
net_eq(pneigh_net(n), net) &&
732-
(n->dev == dev || !n->dev))
733-
return n;
734-
735-
n = rcu_dereference_protected(n->next, 1);
736-
}
737-
return NULL;
738-
}
739-
740723
struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl,
741724
struct net *net, const void *pkey,
742725
struct net_device *dev)
@@ -747,13 +730,19 @@ struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl,
747730

748731
key_len = tbl->key_len;
749732
hash_val = pneigh_hash(pkey, key_len);
733+
n = rcu_dereference_check(tbl->phash_buckets[hash_val],
734+
lockdep_is_held(&tbl->lock));
750735

751-
read_lock_bh(&tbl->lock);
752-
n = __pneigh_lookup_1(rcu_dereference_protected(tbl->phash_buckets[hash_val], 1),
753-
net, pkey, key_len, dev);
754-
read_unlock_bh(&tbl->lock);
736+
while (n) {
737+
if (!memcmp(n->key, pkey, key_len) &&
738+
net_eq(pneigh_net(n), net) &&
739+
(n->dev == dev || !n->dev))
740+
return n;
755741

756-
return n;
742+
n = rcu_dereference_check(n->next, lockdep_is_held(&tbl->lock));
743+
}
744+
745+
return NULL;
757746
}
758747
EXPORT_IPV6_MOD(pneigh_lookup);
759748

@@ -762,19 +751,18 @@ struct pneigh_entry *pneigh_create(struct neigh_table *tbl,
762751
struct net_device *dev)
763752
{
764753
struct pneigh_entry *n;
765-
unsigned int key_len = tbl->key_len;
766-
u32 hash_val = pneigh_hash(pkey, key_len);
754+
unsigned int key_len;
755+
u32 hash_val;
767756

768757
ASSERT_RTNL();
769758

770759
read_lock_bh(&tbl->lock);
771-
n = __pneigh_lookup_1(rcu_dereference_protected(tbl->phash_buckets[hash_val], 1),
772-
net, pkey, key_len, dev);
760+
n = pneigh_lookup(tbl, net, pkey, dev);
773761
read_unlock_bh(&tbl->lock);
774-
775762
if (n)
776763
goto out;
777764

765+
key_len = tbl->key_len;
778766
n = kzalloc(sizeof(*n) + key_len, GFP_KERNEL);
779767
if (!n)
780768
goto out;
@@ -791,6 +779,7 @@ struct pneigh_entry *pneigh_create(struct neigh_table *tbl,
791779
goto out;
792780
}
793781

782+
hash_val = pneigh_hash(pkey, key_len);
794783
write_lock_bh(&tbl->lock);
795784
n->next = tbl->phash_buckets[hash_val];
796785
rcu_assign_pointer(tbl->phash_buckets[hash_val], n);

0 commit comments

Comments
 (0)