Skip to contentSkip to conversation

neighbour: Misc follow-ups on per-netns neigh_table series.

PATCH Applied Kuniyuki Iwashima 3 participants 10 messages Oct 13 – Oct 20

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

v2 cover neighbour: Misc follow-ups on per-netns neigh_table series.

Patch 1 updates the switchdev doc, s/arp_tbl/arp_table(net)/.

Patch 2 updates a selftest for per-netns sysctl knobs, though this is not an actual issue since the test does not hit gc_thresh by default.

Patches 3 ~ 5 are based on a suggestion by Ido Schimmel to make neigh_periodic_work() and neigh_managed_work() CPU-friendly:

https://lore.kernel.org/netdev/20260902143023.GA3966681@shredder/

Given it's rc7, I'll defer RTNL removal to the next cycle.

Changes:
v2:
* Add patch 5 for neigh_periodic_work()
* Patch 4:
* Update commit message (rephrase 1st and add last sentence)
* Add and use NTBL_PARM_MS_MIN

v1: https://lore.kernel.org/netdev/[email protected]/

Kuniyuki Iwashima (5):
Documentation: networking: switchdev: Replace arp_tbl with

    arp_table(net).

selftests: netfilter: Set gc_thresh[123] for gw netns in
nft_nat_zones.sh.
neighbour: Schedule neigh_managed_work only when needed.
neighbour: Floor INTERVAL_PROBE_TIME_MS at 1000.
neighbour: Floor neigh_periodic_work() interval at 1s.

 Documentation/netlink/specs/rt-neigh.yaml     |  2 +-
 Documentation/networking/ip-sysctl.rst        |  2 +-
 Documentation/networking/switchdev.rst        | 11 +++---
 net/core/neighbour.c                          | 31 ++++++++++++-----
 .../selftests/net/netfilter/nft_nat_zones.sh  | 34 +++++--------------
 5 files changed, 38 insertions(+), 42 deletions(-)
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
#1 lore raw

PATCH v2 1/5 Documentation: networking: switchdev: Replace arp_tbl with arp_table(net).

Since commit cda2962b6e2b ("neighbour: Namespacify neigh_tables."), arp_tbl is a template for the per-netns table.

Let's apply s/arp_tbl/arp_table(net)/ to switchdev.rst.

---
 Documentation/networking/switchdev.rst | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
Documentation/networking/switchdev.rst +6 -5
index 2966b7122f05..8e8ab6632ffe 100644
@@ -401,14 +401,15 @@ The FIB entry's nexthop list contains the nexthop tuple (gateway, dev), but for
 the switch device to forward the packet with the correct dst mac address, the
 nexthop gateways must be resolved to the neighbor's mac address.  Neighbor mac
 address discovery comes via the ARP (or ND) process and is available via the
-arp_tbl neighbor table.  To resolve the routes nexthop gateways, the driver
-should trigger the kernel's neighbor resolution process.  See the rocker
+arp_table(net) neighbor table.  To resolve the routes nexthop gateways, the
+driver should trigger the kernel's neighbor resolution process.  See the rocker
 driver's rocker_port_ipv4_resolve() for an example.
 
-The driver can monitor for updates to arp_tbl using the netevent notifier
+The driver can monitor for updates to arp_table(net) using the netevent notifier
 NETEVENT_NEIGH_UPDATE.  The device can be programmed with resolved nexthops
-for the routes as arp_tbl updates.  The driver implements ndo_neigh_destroy
-to know when arp_tbl neighbor entries are purged from the port.
+for the routes as arp_table(net) updates.  The driver implements
+ndo_neigh_destroy to know when arp_table(net) neighbor entries are purged from
+the port.
 
 Device driver expected behavior
 -------------------------------
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
#2 lore raw

PATCH v2 2/5 selftests: netfilter: Set gc_thresh[123] for gw netns in nft_nat_zones.sh.

In reply to Kuniyuki Iwashima

Since commit cda2962b6e2b ("neighbour: Namespacify neigh_tables."), net.ipv[46].neigh.default.gc_thresh[123] are per-netns attributes.

Let's update nft_nat_zones.sh.

Note that the number of neighbour entries does not even reach the default gc_thresh1 (128) with the default maxclients=100, and the raised thresholds are only needed for gw netns when maxclients is manually increased (e.g., 2000 as mentioned in the comment).

---
Cc: Pablo Neira Ayuso <[email protected]>
Cc: Florian Westphal <[email protected]>
Cc: Phil Sutter <[email protected]>

---
 .../selftests/net/netfilter/nft_nat_zones.sh  | 34 +++++--------------
 1 file changed, 8 insertions(+), 26 deletions(-)
tools/testing/selftests/net/netfilter/nft_nat_zones.sh +8 -26
index 9f200f80253a..d935c967dd13 100755
@@ -31,25 +31,6 @@ ret=0
 #   NAT Gateway is supposed to do port reallocation for each of the
 #   connections.
 
-v4gc1=$(sysctl -n net.ipv4.neigh.default.gc_thresh1 2>/dev/null)
-v4gc2=$(sysctl -n net.ipv4.neigh.default.gc_thresh2 2>/dev/null)
-v4gc3=$(sysctl -n net.ipv4.neigh.default.gc_thresh3 2>/dev/null)
-v6gc1=$(sysctl -n net.ipv6.neigh.default.gc_thresh1 2>/dev/null)
-v6gc2=$(sysctl -n net.ipv6.neigh.default.gc_thresh2 2>/dev/null)
-v6gc3=$(sysctl -n net.ipv6.neigh.default.gc_thresh3 2>/dev/null)
-
-cleanup()
-{
-	cleanup_all_ns
-
-	sysctl -q net.ipv4.neigh.default.gc_thresh1="$v4gc1" 2>/dev/null
-	sysctl -q net.ipv4.neigh.default.gc_thresh2="$v4gc2" 2>/dev/null
-	sysctl -q net.ipv4.neigh.default.gc_thresh3="$v4gc3" 2>/dev/null
-	sysctl -q net.ipv6.neigh.default.gc_thresh1="$v6gc1" 2>/dev/null
-	sysctl -q net.ipv6.neigh.default.gc_thresh2="$v6gc2" 2>/dev/null
-	sysctl -q net.ipv6.neigh.default.gc_thresh3="$v6gc3" 2>/dev/null
-}
-
 checktool "nft --version" echo "run test without nft tool"
 checktool "conntrack -V" "run test without conntrack tool"
 
@@ -59,18 +40,19 @@ fi
 
 setup_ns gw srv
 
-trap cleanup EXIT
+trap cleanup_all_ns EXIT
 
 ip link add veth0 netns "$gw" type veth peer name eth0 netns "$srv"
 ip -net "$gw" link set veth0 up
 ip -net "$srv" link set eth0 up
 
-sysctl -q net.ipv6.neigh.default.gc_thresh1=512  2>/dev/null
-sysctl -q net.ipv6.neigh.default.gc_thresh2=1024 2>/dev/null
-sysctl -q net.ipv6.neigh.default.gc_thresh3=4096 2>/dev/null
-sysctl -q net.ipv4.neigh.default.gc_thresh1=512  2>/dev/null
-sysctl -q net.ipv4.neigh.default.gc_thresh2=1024 2>/dev/null
-sysctl -q net.ipv4.neigh.default.gc_thresh3=4096 2>/dev/null
+ip netns exec "$gw" sysctl -q \
+   net.ipv6.neigh.default.gc_thresh1=512 \
+   net.ipv6.neigh.default.gc_thresh2=1024 \
+   net.ipv6.neigh.default.gc_thresh3=4096 \
+   net.ipv4.neigh.default.gc_thresh1=512 \
+   net.ipv4.neigh.default.gc_thresh2=1024 \
+   net.ipv4.neigh.default.gc_thresh3=4096 2>/dev/null
 
 for i in $(seq 1 "$maxclients");do
   setup_ns "cl$i"
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
#3 lore raw

PATCH v2 3/5 neighbour: Schedule neigh_managed_work only when needed.

In reply to Kuniyuki Iwashima

neigh_table is now per-netns.

tbl->managed_work is scheduled when netns is created and runs periodically even though the netns does not have any NTF_MANAGED entries.

Let's delay scheduling the work for the first NTF_MANAGED entry and stop rescheduling if tbl->managed_list is empty.

---
 net/core/neighbour.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
net/core/neighbour.c +17 -5
index 90335895b415..6b0569aa5d64 100644
@@ -184,6 +184,15 @@ static void neigh_update_gc_list(struct neighbour *n)
 	}
 }
 
+static void neigh_add_managed_list(struct neighbour *n)
+{
+	list_add_tail(&n->managed_list, &n->tbl->managed_list);
+
+	if (list_is_singular(&n->tbl->managed_list))
+		queue_delayed_work(system_power_efficient_wq,
+				   &n->tbl->managed_work, 0);
+}
+
 static void neigh_update_managed_list(struct neighbour *n)
 {
 	bool on_managed_list, add_to_managed;
@@ -194,7 +203,7 @@ static void neigh_update_managed_list(struct neighbour *n)
 	if (!add_to_managed && on_managed_list)
 		list_del_init(&n->managed_list);
 	else if (add_to_managed && !on_managed_list)
-		list_add_tail(&n->managed_list, &n->tbl->managed_list);
+		neigh_add_managed_list(n);
 }
 
 static void neigh_update_flags(struct neighbour *neigh, u32 flags, int *notify,
@@ -708,7 +717,7 @@ ___neigh_create(struct neigh_table *tbl, const void *pkey,
 	if (!exempt_from_gc)
 		list_add_tail(&n->gc_list, &n->tbl->gc_list);
 	if (n->flags & NTF_MANAGED)
-		list_add_tail(&n->managed_list, &n->tbl->managed_list);
+		neigh_add_managed_list(n);
 	if (want_ref)
 		neigh_hold(n);
 	hlist_add_head_rcu(&n->hash, &nht->hash_heads[hash_val]);
@@ -1670,10 +1679,14 @@ static void neigh_managed_work(struct work_struct *work)
 	struct neighbour *neigh;
 
 	spin_lock_bh(&tbl->lock);
+
 	list_for_each_entry(neigh, &tbl->managed_list, managed_list)
 		neigh_event_send_probe(neigh, NULL, false);
-	queue_delayed_work(system_power_efficient_wq, &tbl->managed_work,
-			   NEIGH_VAR(&tbl->parms, INTERVAL_PROBE_TIME_MS));
+
+	if (!list_empty(&tbl->managed_list))
+		queue_delayed_work(system_power_efficient_wq, &tbl->managed_work,
+				   NEIGH_VAR(&tbl->parms, INTERVAL_PROBE_TIME_MS));
+
 	spin_unlock_bh(&tbl->lock);
 }
 
@@ -1873,7 +1886,6 @@ static int neigh_table_init(struct net *net, struct neigh_table *tbl)
 
 	INIT_LIST_HEAD(&tbl->managed_list);
 	INIT_DEFERRABLE_WORK(&tbl->managed_work, neigh_managed_work);
-	queue_delayed_work(system_power_efficient_wq, &tbl->managed_work, 0);
 
 	return 0;
 
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
maintainer Reviewed-by on v2 3/5
#4 lore raw

Re: [PATCH v2 net-next 3/5] neighbour: Schedule neigh_managed_work only when needed.

Quoted 6 lines · Kuniyuki Iwashima

neigh_table is now per-netns.

tbl->managed_work is scheduled when netns is created and runs periodically even though the netns does not have any NTF_MANAGED entries.

Quoted 6 lines

Let's delay scheduling the work for the first NTF_MANAGED entry and stop rescheduling if tbl->managed_list is empty.

#5 lore raw

PATCH v2 4/5 neighbour: Floor INTERVAL_PROBE_TIME_MS at 1000.

In reply to Kuniyuki Iwashima

Previously, neigh_managed_work() was not rescheduled within 1s since commit ed6cd6a17896 ("net, neigh: Set lower cap for neigh_managed_work rearming").

Later, commit 211da42eaa45 ("net, neigh: introduce interval_probe_time_ms for periodic probe") added INTERVAL_PROBE_TIME_MS and changed the limit to 1ms.

The limit actually did not work but was fixed with netlink_range_validation by commit 6d79b223ec44 ("neighbour:
Enforce min/max to NDTPA_INTERVAL_PROBE_TIME_MS.").

neigh_table is now per-netns, and a user could hog CPU by setting INTERVAL_PROBE_TIME_MS to a small value.

Let's floor the value at 1 second.

This is a user-visible change, but given we had the 1s floor before and the default is 5s, it is unlikely that anyone but syzbot is setting it below 1s and affected by this change.

---
v2:
* Update commit message (rephrase 1st and add last sentence)
* Add and use NTBL_PARM_MS_MIN

---
 Documentation/netlink/specs/rt-neigh.yaml | 2 +-
 Documentation/networking/ip-sysctl.rst    | 2 +-
 net/core/neighbour.c                      | 5 +++--
 3 files changed, 5 insertions(+), 4 deletions(-)
Documentation/netlink/specs/rt-neigh.yaml +1 -1
index c8e55c98d564..7929e667cc7a 100644
@@ -342,7 +342,7 @@ attribute-sets:
         name: interval-probe-time-ms
         type: u64
         checks:
-          min: 1
+          min: 1000
           max: 86400000
 
 operations:
Documentation/networking/ip-sysctl.rst +1 -1
index 685c84cf543d..b00bd77363d7 100644
@@ -248,7 +248,7 @@ neigh/default/unres_qlen - INTEGER
 
 neigh/default/interval_probe_time_ms - INTEGER
 	The probe interval for neighbor entries with NTF_MANAGED flag,
-	the min value is 1, and the max value is 86400000 (1 day).
+	the min value is 1000 (1s), and the max value is 86400000 (1 day).
 
 	Default: 5000
 
net/core/neighbour.c +3 -2
index 6b0569aa5d64..aa3da886eaab 100644
@@ -2435,10 +2435,11 @@ static const struct nla_policy nl_neightbl_policy[NDTA_MAX+1] = {
 	[NDTA_PARMS]		= { .type = NLA_NESTED },
 };
 
+#define NTBL_PARM_MS_MIN	MSEC_PER_SEC
 #define NTBL_PARM_MS_MAX	(24 * 60 * 60 * MSEC_PER_SEC)
 
 static const struct netlink_range_validation nl_ntbl_parm_ms_range = {
-	.min = 1,
+	.min = NTBL_PARM_MS_MIN,
 	.max = NTBL_PARM_MS_MAX,
 };
 
@@ -3701,7 +3702,7 @@ static int neigh_proc_dointvec_ms_jiffies_positive(const struct ctl_table *ctl,
 	struct ctl_table tmp = *ctl;
 	int ret, min, max;
 
-	min = msecs_to_jiffies(1);
+	min = msecs_to_jiffies(NTBL_PARM_MS_MIN);
 	max = msecs_to_jiffies(NTBL_PARM_MS_MAX);
 
 	tmp.extra1 = &min;
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
maintainer Reviewed-by on v2 4/5
#6 lore raw

Re: [PATCH v2 net-next 4/5] neighbour: Floor INTERVAL_PROBE_TIME_MS at 1000.

Quoted 17 lines · Kuniyuki Iwashima

Previously, neigh_managed_work() was not rescheduled within 1s since commit ed6cd6a17896 ("net, neigh: Set lower cap for neigh_managed_work rearming").

Later, commit 211da42eaa45 ("net, neigh: introduce interval_probe_time_ms for periodic probe") added INTERVAL_PROBE_TIME_MS and changed the limit to 1ms.

The limit actually did not work but was fixed with netlink_range_validation by commit 6d79b223ec44 ("neighbour:
Enforce min/max to NDTPA_INTERVAL_PROBE_TIME_MS.").

neigh_table is now per-netns, and a user could hog CPU by setting INTERVAL_PROBE_TIME_MS to a small value.

Let's floor the value at 1 second.

Quoted 7 lines

This is a user-visible change, but given we had the 1s floor before and the default is 5s, it is unlikely that anyone but syzbot is setting it below 1s and affected by this change.

#7 lore raw

PATCH v2 5/5 neighbour: Floor neigh_periodic_work() interval at 1s.

In reply to Kuniyuki Iwashima

neigh_periodic_work() reschedules tbl->gc_work with a delay of BASE_REACHABLE_TIME >> 1.

neigh_table is now per-netns, and a user could hog CPU by setting BASE_REACHABLE_TIME to a small value.

Unlike INTERVAL_PROBE_TIME_MS, BASE_REACHABLE_TIME is also used to compute reachable_time for NUD_REACHABLE entries.

Let's floor only the GC interval at 1 second.

---
 net/core/neighbour.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/neighbour.c +2 -2
index aa3da886eaab..d6e9c7c59a89 100644
@@ -1042,12 +1042,12 @@ static void neigh_periodic_work(struct work_struct *work)
 						lockdep_is_held(&tbl->lock));
 	}
 out:
-	/* Cycle through all hash buckets every BASE_REACHABLE_TIME/2 ticks.
+	/* Cycle through all hash buckets every max(HZ, BASE_REACHABLE_TIME/2) ticks.
 	 * ARP entry timeouts range from 1/2 BASE_REACHABLE_TIME to 3/2
 	 * BASE_REACHABLE_TIME.
 	 */
 	queue_delayed_work(system_power_efficient_wq, &tbl->gc_work,
-			      NEIGH_VAR(&tbl->parms, BASE_REACHABLE_TIME) >> 1);
+			   max(HZ, NEIGH_VAR(&tbl->parms, BASE_REACHABLE_TIME) >> 1));
 	spin_unlock_bh(&tbl->lock);
 }
 
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
maintainer Reviewed-by on v2 5/5
#8 lore raw

Re: [PATCH v2 net-next 5/5] neighbour: Floor neigh_periodic_work() interval at 1s.

Quoted 6 lines · Kuniyuki Iwashima

neigh_periodic_work() reschedules tbl->gc_work with a delay of BASE_REACHABLE_TIME >> 1.

neigh_table is now per-netns, and a user could hog CPU by setting BASE_REACHABLE_TIME to a small value.

Quoted 8 lines

Unlike INTERVAL_PROBE_TIME_MS, BASE_REACHABLE_TIME is also used to compute reachable_time for NUD_REACHABLE entries.

Let's floor only the GC interval at 1 second.

Thanks!

#9 lore raw
In reply to Kuniyuki Iwashima
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Tue, 13 Oct 2026 20:57:27 +0000 you wrote:

Patch 1 updates the switchdev doc, s/arp_tbl/arp_table(net)/.

Patch 2 updates a selftest for per-netns sysctl knobs, though this is not an actual issue since the test does not hit gc_thresh by default.

Patches 3 ~ 5 are based on a suggestion by Ido Schimmel to make neigh_periodic_work() and neigh_managed_work() CPU-friendly:

[...]

Here is the summary with links:
- [v2,net-next,1/5] Documentation: networking: switchdev: Replace arp_tbl with arp_table(net).

    https://git.kernel.org/netdev/net-next/c/3e2ca51e7e35
  - [v2,net-next,2/5] selftests: netfilter: Set gc_thresh[123] for gw netns in nft_nat_zones.sh.
    https://git.kernel.org/netdev/net-next/c/2335e48461f2
  - [v2,net-next,3/5] neighbour: Schedule neigh_managed_work only when needed.
    https://git.kernel.org/netdev/net-next/c/8854b0e247ae
  - [v2,net-next,4/5] neighbour: Floor INTERVAL_PROBE_TIME_MS at 1000.
    https://git.kernel.org/netdev/net-next/c/7a71343ba1a6
  - [v2,net-next,5/5] neighbour: Floor neigh_periodic_work() interval at 1s.
    https://git.kernel.org/netdev/net-next/c/ccd0742641dc

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html