Skip to contentSkip to conversation

Improve neigh_flush_dev performance

PATCH Superseded Gilad Naaman 3 participants 7 messages Oct 1, 2024 – Oct 4, 2024

Subsystems (3)

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

cover Improve neigh_flush_dev performance

This patchsets improves the performance of neigh_flush_dev.

Currently, the only way to implement it requires traversing all neighbours known to the kernel, across all network-namespaces.

This means that some flows are slowed down as a function of neighbour-scale, even if the specific link they're handling has little to no neighbours.

In order to solve this, this patchset adds a netdev->neighbours list, as well as making the original linked-list doubly-, so that it is possible to unlink neighbours without traversing the hash-bucket to obtain the previous neighbour.

The original use-case we encountered was mass-deletion of links (12K VLANs) while there are 50K ARPs and 50K NDPs in the system; though the slowdowns would also appear when the links are set down.

Gilad Naaman (2):
Convert neighbour-table to use hlist
Create netdev->neighbour association

 .../networking/net_cachelines/net_device.rst  |   1 +
 include/linux/netdevice.h                     |   3 +
 include/net/neighbour.h                       |  18 +-
 include/net/neighbour_tables.h                |  13 ++
 net/core/neighbour.c                          | 221 +++++++++---------
 5 files changed, 138 insertions(+), 118 deletions(-)
 create mode 100644 include/net/neighbour_tables.h
Signature · 1 line
2.46.0
#1 lore raw

PATCH 1/2 Convert neighbour-table to use hlist

Use doubly-linked instead of singly-linked list when linking neighbours, so that it is possible to remove neighbours without traversing the entire table.

---
 include/net/neighbour.h |   8 +--
 net/core/neighbour.c    | 123 ++++++++++++++--------------------------
 2 files changed, 45 insertions(+), 86 deletions(-)
include/net/neighbour.h +4 -4
index a44f262a7384..77a4aa53aecb 100644
@@ -135,7 +135,7 @@ struct neigh_statistics {
 #define NEIGH_CACHE_STAT_INC(tbl, field) this_cpu_inc((tbl)->stats->field)
 
 struct neighbour {
-	struct neighbour __rcu	*next;
+	struct hlist_node __rcu list;
 	struct neigh_table	*tbl;
 	struct neigh_parms	*parms;
 	unsigned long		confirmed;
@@ -190,7 +190,7 @@ struct pneigh_entry {
 #define NEIGH_NUM_HASH_RND	4
 
 struct neigh_hash_table {
-	struct neighbour __rcu	**hash_buckets;
+	struct hlist_head __rcu	*hash_buckets;
 	unsigned int		hash_shift;
 	__u32			hash_rnd[NEIGH_NUM_HASH_RND];
 	struct rcu_head		rcu;
@@ -304,9 +304,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]);
+	for (n = (struct neighbour *)rcu_dereference(nht->hash_buckets[hash_val].first);
 	     n != NULL;
-	     n = rcu_dereference(n->next)) {
+	     n = (struct neighbour *)rcu_dereference(n->list.next)) {
 		if (n->dev == dev && key_eq(n, pkey))
 			return n;
 	}
net/core/neighbour.c +41 -82

284 lines not on this page · raw message

Signature · 1 line
2.46.0
reviewer
#2 lore raw

Re: [PATCH net-next 1/2] Convert neighbour-table to use hlist

Quoted 5 lines · Gilad Naaman

Use doubly-linked instead of singly-linked list when linking neighbours, so that it is possible to remove neighbours without traversing the entire table.

Hi Gilad,

This is not a full review, but rather some feedback to take into account once a proper review arrives.

Quoted 10 lines
---
 include/net/neighbour.h |   8 +--
 net/core/neighbour.c    | 123 ++++++++++++++--------------------------
 2 files changed, 45 insertions(+), 86 deletions(-)
include/net/neighbour.h +0 -0
index a44f262a7384..77a4aa53aecb 100644

include/net/neighbour.h struct neigh_statistics { · line 141

Quoted 8 lines
include/net/neighbour.h +1 -1
@@ -135,7 +135,7 @@ struct neigh_statistics {
 #define NEIGH_CACHE_STAT_INC(tbl, field) this_cpu_inc((tbl)->stats->field)
 
 struct neighbour {
-	struct neighbour __rcu	*next;
+	struct hlist_node __rcu list;
 	struct neigh_table	*tbl;
 	struct neigh_parms	*parms;
 	unsigned long		confirmed;

Sparse is having a bit of a cow with rcu changes introduced by this patch. Please take a look at that.

...

#3 lore raw

Re: [PATCH net-next 1/2] Convert neighbour-table to use hlist

Hey Simon,

Thank you for the notes, I'll make sure that Sparse is happy.

For some reason I can't get it to accept hlist_for_each_entry_rcu, complaining that the cast removes __rcu, (even if I add __rcu to the pos variable definition):

Quoted 6 lines

static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb,
struct netlink_callback *cb, struct neigh_dump_filter *filter)

{
	struct net *net = sock_net(skb->sk);
	struct neighbour __rcu *n;

<snip>

Line 2752:

Quoted 1 line
		hlist_for_each_entry_rcu(n, &nht->hash_buckets[h], list) {

Sparse output:

Quoted 1 line

net/core/neighbour.c:2752:17: sparse: warning: cast removes address space '__rcu' of expression

Do you know if this is solveable without reverting to the previous style of iteration?

Thank you

#4 lore raw

Re: [PATCH net-next 1/2] Convert neighbour-table to use hlist

In reply to Gilad Naaman
kernel test robot noticed the following build warnings:

Hi Gilad,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Gilad-Naaman/Convert-neighbour-table-to-use-hlist/20241001-131234
base:   net-next/main
patch link:    https://lore.kernel.org/r/20241001050959.1799151-2-gnaaman%40drivenets.com
patch subject: [PATCH net-next 1/2] Convert neighbour-table to use hlist
config: x86_64-randconfig-121-20241004 (https://download.01.org/0day-ci/archive/20241004/[email protected]/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241004/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:215:32: sparse: sparse: incorrect type in argument 1 (different modifiers) @@     expected struct hlist_node *n @@     got struct hlist_node [noderef] * @@
   net/core/neighbour.c:215:32: sparse:     expected struct hlist_node *n
   net/core/neighbour.c:215:32: sparse:     got struct hlist_node [noderef] *
   net/core/neighbour.c:370:26: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:382:40: sparse: sparse: incorrect type in argument 1 (different modifiers) @@     expected struct hlist_node *n @@     got struct hlist_node [noderef] * @@
   net/core/neighbour.c:382:40: sparse:     expected struct hlist_node *n
   net/core/neighbour.c:382:40: sparse:     got struct hlist_node [noderef] *
>> net/core/neighbour.c:519:25: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected struct hlist_head [noderef] __rcu *buckets @@     got void *_res @@
   net/core/neighbour.c:519:25: sparse:     expected struct hlist_head [noderef] __rcu *buckets
   net/core/neighbour.c:519:25: sparse:     got void *_res
>> net/core/neighbour.c:524:32: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *ptr @@     got struct hlist_head [noderef] __rcu *[assigned] buckets @@
   net/core/neighbour.c:524:32: sparse:     expected void const *ptr
   net/core/neighbour.c:524:32: sparse:     got struct hlist_head [noderef] __rcu *[assigned] buckets
>> net/core/neighbour.c:546:23: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *objp @@     got struct hlist_head [noderef] __rcu *buckets @@
   net/core/neighbour.c:546:23: sparse:     expected void const *objp
   net/core/neighbour.c:546:23: sparse:     got struct hlist_head [noderef] __rcu *buckets
>> net/core/neighbour.c:548:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const *ptr @@     got struct hlist_head [noderef] __rcu *buckets @@
   net/core/neighbour.c:548:31: sparse:     expected void const *ptr
   net/core/neighbour.c:548:31: sparse:     got struct hlist_head [noderef] __rcu *buckets
>> net/core/neighbour.c:572:25: sparse: sparse: incompatible types in comparison expression (different address spaces):
   net/core/neighbour.c:572:25: sparse:    struct hlist_node [noderef] __rcu *
   net/core/neighbour.c:572:25: sparse:    struct hlist_node *
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
>> net/core/neighbour.c:669:9: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:688:29: sparse: sparse: incorrect type in argument 1 (different modifiers) @@     expected struct hlist_node *n @@     got struct hlist_node [noderef] * @@
>> net/core/neighbour.c:688:56: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected struct hlist_head *h @@     got struct hlist_head [noderef] __rcu * @@
   net/core/neighbour.c:948:23: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:971:48: sparse: sparse: incorrect type in argument 1 (different modifiers) @@     expected struct hlist_node *n @@     got struct hlist_node [noderef] * @@
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:2698:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3065:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3086:23: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3094:48: sparse: sparse: incorrect type in argument 1 (different modifiers) @@     expected struct hlist_node *n @@     got struct hlist_node [noderef] * @@
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3164:17: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3203:14: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3222:30: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3231:41: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:3231:22: sparse: sparse: cast removes address space '__rcu' of expression
   net/core/neighbour.c:429:9: sparse: sparse: context imbalance in '__neigh_ifdown' - wrong count at exit
>> net/core/neighbour.c:572:25: sparse: sparse: dereference of noderef expression
   net/core/neighbour.c: note: in included file:
>> include/net/neighbour.h:307:38: sparse: sparse: cast removes address space '__rcu' of expression
>> include/net/neighbour.h:307:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:307:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:307:38: sparse:    struct hlist_node *
   include/net/neighbour.h:309:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:309:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:309:38: sparse:    struct hlist_node *
>> include/net/neighbour.h:307:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:307:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:307:38: sparse:    struct hlist_node *
   include/net/neighbour.h:309:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:309:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:309:38: sparse:    struct hlist_node *
>> include/net/neighbour.h:307:38: sparse: sparse: incompatible types in comparison expression (different address spaces):

include/net/neighbour.h:307:38: sparse: struct hlist_node [noderef] __rcu *
include/net/neighbour.h:307:38: sparse: struct hlist_node *
include/net/neighbour.h:309:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
include/net/neighbour.h:309:38: sparse: struct hlist_node [noderef] __rcu *
include/net/neighbour.h:309:38: sparse: struct hlist_node *
--
net/core/filter.c:1423:39: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sock_filter const *filter @@ got struct sock_filter [noderef] __user *filter @@
net/core/filter.c:1423:39: sparse: expected struct sock_filter const *filter
net/core/filter.c:1423:39: sparse: got struct sock_filter [noderef] __user *filter
net/core/filter.c:1501:39: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sock_filter const *filter @@ got struct sock_filter [noderef] __user *filter @@
net/core/filter.c:1501:39: sparse: expected struct sock_filter const *filter
net/core/filter.c:1501:39: sparse: got struct sock_filter [noderef] __user *filter
net/core/filter.c:2340:45: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected restricted __be32 [usertype] daddr @@ got unsigned int [usertype] ipv4_nh @@
net/core/filter.c:2340:45: sparse: expected restricted __be32 [usertype] daddr
net/core/filter.c:2340:45: sparse: got unsigned int [usertype] ipv4_nh
net/core/filter.c:11048:31: sparse: sparse: symbol 'cg_skb_verifier_ops' was not declared. Should it be static? net/core/filter.c:11054:27: sparse: sparse: symbol 'cg_skb_prog_ops' was not declared. Should it be static? net/core/filter.c:11098:31: sparse: sparse: symbol 'cg_sock_verifier_ops' was not declared. Should it be static? net/core/filter.c:11104:27: sparse: sparse: symbol 'cg_sock_prog_ops' was not declared. Should it be static? net/core/filter.c:11107:31: sparse: sparse: symbol 'cg_sock_addr_verifier_ops' was not declared. Should it be static? net/core/filter.c:11113:27: sparse: sparse: symbol 'cg_sock_addr_prog_ops' was not declared. Should it be static?
net/core/filter.c:1943:43: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected restricted __wsum [usertype] diff @@ got unsigned long long [usertype] to @@
net/core/filter.c:1943:43: sparse: expected restricted __wsum [usertype] diff
net/core/filter.c:1943:43: sparse: got unsigned long long [usertype] to
net/core/filter.c:1946:36: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected restricted __be16 [usertype] old @@ got unsigned long long [usertype] from @@
net/core/filter.c:1946:36: sparse: expected restricted __be16 [usertype] old
net/core/filter.c:1946:36: sparse: got unsigned long long [usertype] from
net/core/filter.c:1946:42: sparse: sparse: incorrect type in argument 3 (different base types) @@ expected restricted __be16 [usertype] new @@ got unsigned long long [usertype] to @@
net/core/filter.c:1946:42: sparse: expected restricted __be16 [usertype] new
net/core/filter.c:1946:42: sparse: got unsigned long long [usertype] to
net/core/filter.c:1949:36: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected restricted __be32 [usertype] from @@ got unsigned long long [usertype] from @@
net/core/filter.c:1949:36: sparse: expected restricted __be32 [usertype] from
net/core/filter.c:1949:36: sparse: got unsigned long long [usertype] from
net/core/filter.c:1949:42: sparse: sparse: incorrect type in argument 3 (different base types) @@ expected restricted __be32 [usertype] to @@ got unsigned long long [usertype] to @@
net/core/filter.c:1949:42: sparse: expected restricted __be32 [usertype] to
net/core/filter.c:1949:42: sparse: got unsigned long long [usertype] to
net/core/filter.c:1994:59: sparse: sparse: incorrect type in argument 3 (different base types) @@ expected restricted __wsum [usertype] diff @@ got unsigned long long [usertype] to @@
net/core/filter.c:1994:59: sparse: expected restricted __wsum [usertype] diff
net/core/filter.c:1994:59: sparse: got unsigned long long [usertype] to
net/core/filter.c:1997:52: sparse: sparse: incorrect type in argument 3 (different base types) @@ expected restricted __be16 [usertype] from @@ got unsigned long long [usertype] from @@
net/core/filter.c:1997:52: sparse: expected restricted __be16 [usertype] from
net/core/filter.c:1997:52: sparse: got unsigned long long [usertype] from
net/core/filter.c:1997:58: sparse: sparse: incorrect type in argument 4 (different base types) @@ expected restricted __be16 [usertype] to @@ got unsigned long long [usertype] to @@
net/core/filter.c:1997:58: sparse: expected restricted __be16 [usertype] to
net/core/filter.c:1997:58: sparse: got unsigned long long [usertype] to
net/core/filter.c:2000:52: sparse: sparse: incorrect type in argument 3 (different base types) @@ expected restricted __be32 [usertype] from @@ got unsigned long long [usertype] from @@
net/core/filter.c:2000:52: sparse: expected restricted __be32 [usertype] from
net/core/filter.c:2000:52: sparse: got unsigned long long [usertype] from
net/core/filter.c:2000:58: sparse: sparse: incorrect type in argument 4 (different base types) @@ expected restricted __be32 [usertype] to @@ got unsigned long long [usertype] to @@
net/core/filter.c:2000:58: sparse: expected restricted __be32 [usertype] to
net/core/filter.c:2000:58: sparse: got unsigned long long [usertype] to
net/core/filter.c:2050:16: sparse: sparse: incorrect type in return expression (different base types) @@ expected unsigned long long @@ got restricted __wsum [assigned] [usertype] ret @@
net/core/filter.c:2050:16: sparse: expected unsigned long long
net/core/filter.c:2050:16: sparse: got restricted __wsum [assigned] [usertype] ret
net/core/filter.c:2072:35: sparse: sparse: incorrect type in return expression (different base types) @@ expected unsigned long long @@ got restricted __wsum [usertype] csum @@
net/core/filter.c:2072:35: sparse: expected unsigned long long
net/core/filter.c:2072:35: sparse: got restricted __wsum [usertype] csum
net/core/filter.c: note: in included file (through include/net/dst.h, include/net/sock.h, include/linux/sock_diag.h):

>> include/net/neighbour.h:307:38: sparse: sparse: cast removes address space '__rcu' of expression
>> include/net/neighbour.h:307:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:307:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:307:38: sparse:    struct hlist_node *
   include/net/neighbour.h:309:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:309:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:309:38: sparse:    struct hlist_node *
>> include/net/neighbour.h:307:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:307:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:307:38: sparse:    struct hlist_node *
   include/net/neighbour.h:309:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:309:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:309:38: sparse:    struct hlist_node *
>> include/net/neighbour.h:307:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:307:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:307:38: sparse:    struct hlist_node *
   include/net/neighbour.h:309:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:309:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:309:38: sparse:    struct hlist_node *
>> include/net/neighbour.h:307:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:307:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:307:38: sparse:    struct hlist_node *
   include/net/neighbour.h:309:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:309:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:309:38: sparse:    struct hlist_node *
>> include/net/neighbour.h:307:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:307:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:307:38: sparse:    struct hlist_node *
   include/net/neighbour.h:309:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:309:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:309:38: sparse:    struct hlist_node *
>> include/net/neighbour.h:307:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:307:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:307:38: sparse:    struct hlist_node *
   include/net/neighbour.h:309:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:309:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:309:38: sparse:    struct hlist_node *
>> include/net/neighbour.h:307:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:307:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:307:38: sparse:    struct hlist_node *
   include/net/neighbour.h:309:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:309:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:309:38: sparse:    struct hlist_node *
>> include/net/neighbour.h:307:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:307:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:307:38: sparse:    struct hlist_node *
   include/net/neighbour.h:309:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/net/neighbour.h:309:38: sparse:    struct hlist_node [noderef] __rcu *
   include/net/neighbour.h:309:38: sparse:    struct hlist_node *
>> include/net/neighbour.h:307:38: sparse: sparse: incompatible types in comparison expression (different address spaces):

include/net/neighbour.h:307:38: sparse: struct hlist_node [noderef] __rcu *
include/net/neighbour.h:307:38: sparse: struct hlist_node *
include/net/neighbour.h:309:38: sparse: sparse: incompatible types in comparison expression (different address spaces):
include/net/neighbour.h:309:38: sparse: struct hlist_node [noderef] __rcu *
include/net/neighbour.h:309:38: sparse: struct hlist_node *

vim +/__rcu +669 net/core/neighbour.c

507
508 static struct neigh_hash_table *neigh_hash_alloc(unsigned int shift)
509 {
510 size_t size = (1 << shift) * sizeof(struct hlist_head);
511 struct neigh_hash_table *ret;
512 struct hlist_head __rcu *buckets;
513 int i;
514
515 ret = kmalloc(sizeof(*ret), GFP_ATOMIC);
516 if (!ret)
517 return NULL;
518 if (size <= PAGE_SIZE) {

 > 519			buckets = kzalloc(size, GFP_ATOMIC);
   520		} else {
   521			buckets = (struct hlist_head __rcu *)
   522				  __get_free_pages(GFP_ATOMIC | __GFP_ZERO,
   523						   get_order(size));
 > 524			kmemleak_alloc(buckets, size, 1, GFP_ATOMIC);
   525		}
   526		if (!buckets) {
   527			kfree(ret);
   528			return NULL;
   529		}
   530		ret->hash_buckets = buckets;
   531		ret->hash_shift = shift;
   532		for (i = 0; i < NEIGH_NUM_HASH_RND; i++)
   533			neigh_get_hash_rnd(&ret->hash_rnd[i]);
   534		return ret;
   535	}
   536	
   537	static void neigh_hash_free_rcu(struct rcu_head *head)
   538	{
   539		struct neigh_hash_table *nht = container_of(head,
   540							    struct neigh_hash_table,
   541							    rcu);
   542		size_t size = (1 << nht->hash_shift) * sizeof(struct hlist_head);
   543		struct hlist_head __rcu *buckets = nht->hash_buckets;
   544	
   545		if (size <= PAGE_SIZE) {
 > 546			kfree(buckets);
   547		} else {
 > 548			kmemleak_free(buckets);
   549			free_pages((unsigned long)buckets, get_order(size));
   550		}
   551		kfree(nht);
   552	}
   553	
   554	static struct neigh_hash_table *neigh_hash_grow(struct neigh_table *tbl,
   555							unsigned long new_shift)
   556	{
   557		unsigned int i, hash;
   558		struct neigh_hash_table *new_nht, *old_nht;
   559	
   560		NEIGH_CACHE_STAT_INC(tbl, hash_grows);
   561	
   562		old_nht = rcu_dereference_protected(tbl->nht,
   563						    lockdep_is_held(&tbl->lock));
   564		new_nht = neigh_hash_alloc(new_shift);
   565		if (!new_nht)
   566			return old_nht;
   567	
   568		for (i = 0; i < (1 << old_nht->hash_shift); i++) {
   569			struct neighbour *n, *next;
   570	
   571			for (n = (struct neighbour *)
 > 572				rcu_dereference_protected(old_nht->hash_buckets[i].first,
   573							  lockdep_is_held(&tbl->lock));
   574			     n != NULL;
   575			     n = next) {
   576				hash = tbl->hash(n->primary_key, n->dev,
   577						 new_nht->hash_rnd);
   578	
   579				hash >>= (32 - new_nht->hash_shift);
   580				next = (struct neighbour *)hlist_next_rcu(&n->list);
   581				hlist_del_rcu(&n->list);
   582				hlist_add_head_rcu(&n->list, &new_nht->hash_buckets[hash]);
   583			}
   584		}
   585	
   586		rcu_assign_pointer(tbl->nht, new_nht);
   587		call_rcu(&old_nht->rcu, neigh_hash_free_rcu);
   588		return new_nht;
   589	}
   590	
   591	struct neighbour *neigh_lookup(struct neigh_table *tbl, const void *pkey,
   592				       struct net_device *dev)
   593	{
   594		struct neighbour *n;
   595	
   596		NEIGH_CACHE_STAT_INC(tbl, lookups);
   597	
   598		rcu_read_lock();
   599		n = __neigh_lookup_noref(tbl, pkey, dev);
   600		if (n) {
   601			if (!refcount_inc_not_zero(&n->refcnt))
   602				n = NULL;
   603			NEIGH_CACHE_STAT_INC(tbl, hits);
   604		}
   605	
   606		rcu_read_unlock();
   607		return n;
   608	}
   609	EXPORT_SYMBOL(neigh_lookup);
   610	
   611	static struct neighbour *
   612	___neigh_create(struct neigh_table *tbl, const void *pkey,
   613			struct net_device *dev, u32 flags,
   614			bool exempt_from_gc, bool want_ref)
   615	{
   616		u32 hash_val, key_len = tbl->key_len;
   617		struct neighbour *n1, *rc, *n;
   618		struct neigh_hash_table *nht;
   619		int error;
   620	
   621		n = neigh_alloc(tbl, dev, flags, exempt_from_gc);
   622		trace_neigh_create(tbl, dev, pkey, n, exempt_from_gc);
   623		if (!n) {
   624			rc = ERR_PTR(-ENOBUFS);
   625			goto out;
   626		}
   627	
   628		memcpy(n->primary_key, pkey, key_len);
   629		n->dev = dev;
   630		netdev_hold(dev, &n->dev_tracker, GFP_ATOMIC);
   631	
   632		/* Protocol specific setup. */
   633		if (tbl->constructor &&	(error = tbl->constructor(n)) < 0) {
   634			rc = ERR_PTR(error);
   635			goto out_neigh_release;
   636		}
   637	
   638		if (dev->netdev_ops->ndo_neigh_construct) {
   639			error = dev->netdev_ops->ndo_neigh_construct(dev, n);
   640			if (error < 0) {
   641				rc = ERR_PTR(error);
   642				goto out_neigh_release;
   643			}
   644		}
   645	
   646		/* Device specific setup. */
   647		if (n->parms->neigh_setup &&
   648		    (error = n->parms->neigh_setup(n)) < 0) {
   649			rc = ERR_PTR(error);
   650			goto out_neigh_release;
   651		}
   652	
   653		n->confirmed = jiffies - (NEIGH_VAR(n->parms, BASE_REACHABLE_TIME) << 1);
   654	
   655		write_lock_bh(&tbl->lock);
   656		nht = rcu_dereference_protected(tbl->nht,
   657						lockdep_is_held(&tbl->lock));
   658	
   659		if (atomic_read(&tbl->entries) > (1 << nht->hash_shift))
   660			nht = neigh_hash_grow(tbl, nht->hash_shift + 1);
   661	
   662		hash_val = tbl->hash(n->primary_key, dev, nht->hash_rnd) >> (32 - nht->hash_shift);
   663	
   664		if (n->parms->dead) {
   665			rc = ERR_PTR(-EINVAL);
   666			goto out_tbl_unlock;
   667		}
   668	
 > 669		hlist_for_each_entry_rcu(n1,
   670					 &nht->hash_buckets[hash_val],
   671					 list,
   672					 lockdep_is_held(&tbl->lock)) {
   673			if (dev == n1->dev && !memcmp(n1->primary_key, n->primary_key, key_len)) {
   674				if (want_ref)
   675					neigh_hold(n1);
   676				rc = n1;
   677				goto out_tbl_unlock;
   678			}
   679		}
   680	
   681		n->dead = 0;
   682		if (!exempt_from_gc)
   683			list_add_tail(&n->gc_list, &n->tbl->gc_list);
   684		if (n->flags & NTF_MANAGED)
   685			list_add_tail(&n->managed_list, &n->tbl->managed_list);
   686		if (want_ref)
   687			neigh_hold(n);
 > 688		hlist_add_head_rcu(&n->list, &nht->hash_buckets[hash_val]);

689 write_unlock_bh(&tbl->lock);
690 neigh_dbg(2, "neigh %p is created\n", n);
691 rc = n;
692 out:
693 return rc;
694 out_tbl_unlock:
695 write_unlock_bh(&tbl->lock);
696 out_neigh_release:
697 if (!exempt_from_gc)
698 atomic_dec(&tbl->gc_entries);
699 neigh_release(n);
700 goto out;
701 }
702

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

PATCH 2/2 Create netdev->neighbour association

In reply to Gilad Naaman

Create a mapping between a netdev and its neighoburs, allowing for much cheaper flushes.

---
 .../networking/net_cachelines/net_device.rst  |   1 +
 include/linux/netdevice.h                     |   3 +
 include/net/neighbour.h                       |  10 +-
 include/net/neighbour_tables.h                |  13 +++
 net/core/neighbour.c                          | 100 +++++++++++++-----
 5 files changed, 94 insertions(+), 33 deletions(-)
 create mode 100644 include/net/neighbour_tables.h
Documentation/networking/net_cachelines/net_device.rst +1 -0
index 22b07c814f4a..510c407d7268 100644
@@ -183,3 +183,4 @@ struct_devlink_port*                devlink_port
 struct_dpll_pin*                    dpll_pin                                                        
 struct hlist_head                   page_pools
 struct dim_irq_moder*               irq_moder
+struct hlist_head                   neighbours[3]
include/linux/netdevice.h +3 -0
index e87b5e488325..7b24a792280c 100644
@@ -52,6 +52,7 @@
 #include <net/net_trackers.h>
 #include <net/net_debug.h>
 #include <net/dropreason-core.h>
+#include <net/neighbour_tables.h>
 
 struct netpoll_info;
 struct device;
@@ -2399,6 +2400,8 @@ struct net_device {
 	/** @irq_moder: dim parameters used if IS_ENABLED(CONFIG_DIMLIB). */
 	struct dim_irq_moder	*irq_moder;
 
+	struct hlist_head neighbours[NEIGH_NR_TABLES];
+
 	u8			priv[] ____cacheline_aligned
 				       __counted_by(priv_len);
 } ____cacheline_aligned;
include/net/neighbour.h +2 -8
index 77a4aa53aecb..580c2d00e4d5 100644
@@ -29,6 +29,7 @@
 #include <linux/sysctl.h>
 #include <linux/workqueue.h>
 #include <net/rtnetlink.h>
+#include <net/neighbour_tables.h>
 
 /*
  * NUD stands for "neighbor unreachability detection"
@@ -136,6 +137,7 @@ struct neigh_statistics {
 
 struct neighbour {
 	struct hlist_node __rcu list;
+	struct hlist_node __rcu dev_list;
 	struct neigh_table	*tbl;
 	struct neigh_parms	*parms;
 	unsigned long		confirmed;
@@ -236,14 +238,6 @@ struct neigh_table {
 	struct pneigh_entry	**phash_buckets;
 };
 
-enum {
-	NEIGH_ARP_TABLE = 0,
-	NEIGH_ND_TABLE = 1,
-	NEIGH_DN_TABLE = 2,
-	NEIGH_NR_TABLES,
-	NEIGH_LINK_TABLE = NEIGH_NR_TABLES /* Pseudo table for neigh_xmit */
-};
-
 static inline int neigh_parms_family(struct neigh_parms *p)
 {
 	return p->tbl->family;
include/net/neighbour_tables.h new file +13 -0
new file mode 100644
index 000000000000..ad98b49d58db
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _NET_NEIGHBOUR_TABLES_H
+#define _NET_NEIGHBOUR_TABLES_H
+
+enum {
+	NEIGH_ARP_TABLE = 0,
+	NEIGH_ND_TABLE = 1,
+	NEIGH_DN_TABLE = 2,
+	NEIGH_NR_TABLES,
+	NEIGH_LINK_TABLE = NEIGH_NR_TABLES /* Pseudo table for neigh_xmit */
+};
+
+#endif
net/core/neighbour.c +75 -25

148 lines not on this page · raw message

Signature · 1 line
2.46.0
reviewer
#6 lore raw

Re: [PATCH net-next 2/2] Create netdev->neighbour association

Quoted 4 lines · Gilad Naaman

Create a mapping between a netdev and its neighoburs, allowing for much cheaper flushes.

Hi Gilad,

As per my comment on patch 1/2, This is not a full review, but rather some feedback to take into account once a proper review arrives.

...

Quoted 1 line
Documentation/networking/net_cachelines/net_device.rst +0 -0

...

Quoted 1 line
include/linux/netdevice.h +0 -0

...

include/linux/netdevice.h struct net_device { · line 2404

Quoted 6 lines
include/linux/netdevice.h +2 -0
@@ -2399,6 +2400,8 @@ struct net_device {
 	/** @irq_moder: dim parameters used if IS_ENABLED(CONFIG_DIMLIB). */
 	struct dim_irq_moder	*irq_moder;
 
+	struct hlist_head neighbours[NEIGH_NR_TABLES];
+

Please add an entry for neighbours in the Kernel doc for this structure, which is immediately above it.

This is flagged by ./scripts/kernel-doc -none, and W=1 allmodconfig builds.

Quoted 3 lines
include/linux/netdevice.h +0 -0
 	u8			priv[] ____cacheline_aligned
 				       __counted_by(priv_len);
 } ____cacheline_aligned;

...