* [PATCH net-next 0/2] ipv6: remove dst_ops gc handler
@ 2026-12-02 1:55 David Ahern
2026-12-02 1:55 ` [PATCH net-next 1/2] " David Ahern
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: David Ahern @ 2026-12-02 1:55 UTC (permalink / raw)
To: netdev; +Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, willemb, horms
IPv6 is the only address family that still uses dst_ops->gc to
limit dst entries. ip6_dst_gc() runs from dst_alloc() whenever
the entry count exceeds gc_thresh. It never fails an allocation
(max_size is already INT_MAX); it only forces a fib6_run_gc()
pass. That pass can free expired exceptions and expired routes
on the FIB6 gc list. It cannot free uncached dsts, which are
held by sockets and skbs.
Remove the handler and rely on the structural limits that
already bound the dst count, the same way IPv4 does.
How the dst count is bounded
----------------------------
Per-cpu routes are DST_NOCOUNT and are limited to one per cpu
per nexthop.
Cached exceptions (PMTU, redirect) live in a per-nexthop hash.
Each bucket is limited to a randomized depth and the oldest
entry is evicted on insert:
IPv6 IPv4
buckets 1024 (shift 10) 2048 (shift 11)
max depth FIB6_MAX_DEPTH (5) FNHE_RECLAIM_DEPTH (5)
+ random(0..4) + random(0..4)
Time-based expiry:
- IPv6: FIB6 gc timer every gc_interval (30s) while the gc
list is non-empty. It also runs on route flush, ndisc
device events and exception insert.
- IPv4: fnhe_expires is checked on lookup and update, and
fnhe_genid invalidates stale entries. There is no timer.
Uncached dsts (icmp6_dst_alloc(), FLOWI_FLAG_KNOWN_NH clones)
are counted but not capped, in both families. They are bounded
only by the users holding references. The old gc could not
reclaim them either.
Behavior changes
----------------
- dst_ops gc_thresh defaults to ~0, as in IPv4. Reading
net.ipv6.route.gc_thresh now returns -1 instead of 1024.
- gc_thresh, gc_min_interval, gc_min_interval_ms, gc_timeout and
gc_elasticity are kept so existing scripts still work. They
have no effect, and a write logs a one-time warning.
gc_interval is unchanged.
- Expired exceptions are no longer reclaimed early under
allocation pressure. They stay until the gc timer runs, up to
gc_interval plus the exception timeout. Memory is capped at
roughly 1024 x 9 entries per nexthop, the same order as IPv4.
Patches
-------
1: remove ip6_dst_gc() and its per-netns state, and mark the
gc sysctls deprecated
2: selftests: add a stress test for dst_entries
David Ahern (2):
ipv6: remove dst_ops gc handler
selftests: Add stress test for dst_entries
include/net/netns/ipv6.h | 2 -
net/ipv6/ip6_fib.c | 1 -
net/ipv6/route.c | 74 ++++++----
tools/testing/selftests/net/fib_tests.sh | 178 ++++++++++++++++++++++-
4 files changed, 219 insertions(+), 36 deletions(-)
--
2.54.0 (Apple Git-157)
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH net-next 1/2] ipv6: remove dst_ops gc handler 2026-12-02 1:55 [PATCH net-next 0/2] ipv6: remove dst_ops gc handler David Ahern @ 2026-12-02 1:55 ` David Ahern 2026-12-02 1:55 ` [PATCH net-next 2/2] selftests: Add stress test for dst_entries David Ahern 2026-12-02 10:04 ` [PATCH net-next 0/2] ipv6: remove dst_ops gc handler Ido Schimmel 2 siblings, 0 replies; 5+ messages in thread From: David Ahern @ 2026-12-02 1:55 UTC (permalink / raw) To: netdev Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, willemb, horms, David Ahern From: David Ahern <dahern@nvidia.com> Remove ip6_dst_gc(), the dst_ops->gc callback that dst_alloc() invoked synchronously whenever the dst entry count exceeded gc_thresh, together with its per-netns state (ip6_rt_gc_expire and ip6_rt_last_gc). Growth of the IPv6 dst cache is instead bounded the same way IPv4 bounds it: cached exceptions live in a hash whose buckets are limited to a randomized depth, with the oldest entry evicted on insert (see rt6_insert_exception() and FIB6_MAX_DEPTH, cf. fnhe_remove_oldest() and FNHE_RECLAIM_DEPTH in net/ipv4/route.c), and per-cpu routes are bounded by the number of nexthops. Expiry is still handled by the FIB6 gc timer (gc_interval) and the fib6_run_gc() calls on device events and route flush. Like IPv4, set the dst_ops gc_thresh default to ~0 since no threshold is enforced any more. Mark the gc_thresh, gc_min_interval, gc_min_interval_ms, gc_timeout and gc_elasticity sysctls as deprecated: they are retained so existing scripts keep working, but a write now logs a one-time warning that the setting has no effect. gc_interval is unchanged and still sets the period of the FIB6 gc timer. Signed-off-by: David Ahern <dahern@nvidia.com> --- include/net/netns/ipv6.h | 2 -- net/ipv6/ip6_fib.c | 1 - net/ipv6/route.c | 74 +++++++++++++++++++++++----------------- 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h index aefce37c04a4..ca4462353328 100644 --- a/include/net/netns/ipv6.h +++ b/include/net/netns/ipv6.h @@ -82,8 +82,6 @@ struct netns_ipv6 { struct list_head fib6_walkers; rwlock_t fib6_walker_lock; spinlock_t fib6_gc_lock; - atomic_t ip6_rt_gc_expire; - unsigned long ip6_rt_last_gc; unsigned char flowlabel_has_excl; #ifdef CONFIG_IPV6_MULTIPLE_TABLES bool fib6_has_custom_rules; diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index e1d49897d6ab..2095f023c137 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -2464,7 +2464,6 @@ void fib6_run_gc(unsigned long expires, struct net *net, bool force) fib6_gc_all(net, &gc_args); now = jiffies; - net->ipv6.ip6_rt_last_gc = now; if (gc_args.more) mod_timer(&net->ipv6.ip6_fib_timer, diff --git a/net/ipv6/route.c b/net/ipv6/route.c index df843178e5ec..14c95d132e1f 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -92,7 +92,6 @@ static void ip6_negative_advice(struct sock *sk, static void ip6_dst_destroy(struct dst_entry *); static void ip6_dst_ifdown(struct dst_entry *, struct net_device *dev); -static void ip6_dst_gc(struct dst_ops *ops); static int ip6_pkt_discard(struct sk_buff *skb); static int ip6_pkt_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb); @@ -271,8 +270,7 @@ static void ip6_confirm_neigh(const struct dst_entry *dst, const void *daddr) static struct dst_ops ip6_dst_ops_template = { .family = AF_INET6, - .gc = ip6_dst_gc, - .gc_thresh = 1024, + .gc_thresh = ~0, .check = ip6_dst_check, .default_advmss = ip6_default_advmss, .mtu = ip6_mtu, @@ -3367,28 +3365,6 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev, return dst; } -static void ip6_dst_gc(struct dst_ops *ops) -{ - struct net *net = container_of(ops, struct net, ipv6.ip6_dst_ops); - int rt_min_interval = READ_ONCE(net->ipv6.sysctl.ip6_rt_gc_min_interval); - int rt_elasticity = READ_ONCE(net->ipv6.sysctl.ip6_rt_gc_elasticity); - int rt_gc_timeout = READ_ONCE(net->ipv6.sysctl.ip6_rt_gc_timeout); - unsigned long rt_last_gc = READ_ONCE(net->ipv6.ip6_rt_last_gc); - unsigned int val; - int entries; - - if (time_after(rt_last_gc + rt_min_interval, jiffies)) - goto out; - - fib6_run_gc(atomic_inc_return(&net->ipv6.ip6_rt_gc_expire), net, true); - entries = dst_entries_get_slow(ops); - if (entries < ops->gc_thresh) - atomic_set(&net->ipv6.ip6_rt_gc_expire, rt_gc_timeout >> 1); -out: - val = atomic_read(&net->ipv6.ip6_rt_gc_expire); - atomic_set(&net->ipv6.ip6_rt_gc_expire, val - (val >> rt_elasticity)); -} - static int ip6_nh_lookup_table(struct net *net, struct fib6_config *cfg, const struct in6_addr *gw_addr, u32 tbid, int flags, struct fib6_result *res) @@ -6615,6 +6591,42 @@ static int ipv6_sysctl_rtcache_flush(const struct ctl_table *ctl, int write, static unsigned int ip6_rt_gc_elasticity_max = 31; +static void ip6_rt_gc_sysctl_warn(const struct ctl_table *ctl, int write) +{ + if (write) + pr_warn_once("%s: net.ipv6.route.%s is deprecated and has no effect\n", + current->comm, ctl->procname); +} + +static int ip6_rt_gc_dointvec(const struct ctl_table *ctl, int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + ip6_rt_gc_sysctl_warn(ctl, write); + return proc_dointvec(ctl, write, buffer, lenp, ppos); +} + +static int ip6_rt_gc_dointvec_jiffies(const struct ctl_table *ctl, int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + ip6_rt_gc_sysctl_warn(ctl, write); + return proc_dointvec_jiffies(ctl, write, buffer, lenp, ppos); +} + +static int ip6_rt_gc_dointvec_ms_jiffies(const struct ctl_table *ctl, int write, + void *buffer, size_t *lenp, + loff_t *ppos) +{ + ip6_rt_gc_sysctl_warn(ctl, write); + return proc_dointvec_ms_jiffies(ctl, write, buffer, lenp, ppos); +} + +static int ip6_rt_gc_dou8vec_minmax(const struct ctl_table *ctl, int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + ip6_rt_gc_sysctl_warn(ctl, write); + return proc_dou8vec_minmax(ctl, write, buffer, lenp, ppos); +} + static const struct ctl_table ipv6_route_table_template[] = { { .procname = "max_size", @@ -6628,7 +6640,7 @@ static const struct ctl_table ipv6_route_table_template[] = { .data = &ip6_dst_ops_template.gc_thresh, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = ip6_rt_gc_dointvec, }, { .procname = "flush", @@ -6642,14 +6654,14 @@ static const struct ctl_table ipv6_route_table_template[] = { .data = &init_net.ipv6.sysctl.ip6_rt_gc_min_interval, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec_jiffies, + .proc_handler = ip6_rt_gc_dointvec_jiffies, }, { .procname = "gc_timeout", .data = &init_net.ipv6.sysctl.ip6_rt_gc_timeout, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec_jiffies, + .proc_handler = ip6_rt_gc_dointvec_jiffies, }, { .procname = "gc_interval", @@ -6663,7 +6675,7 @@ static const struct ctl_table ipv6_route_table_template[] = { .data = &init_net.ipv6.sysctl.ip6_rt_gc_elasticity, .maxlen = sizeof(u8), .mode = 0644, - .proc_handler = proc_dou8vec_minmax, + .proc_handler = ip6_rt_gc_dou8vec_minmax, .extra2 = &ip6_rt_gc_elasticity_max, }, { @@ -6685,7 +6697,7 @@ static const struct ctl_table ipv6_route_table_template[] = { .data = &init_net.ipv6.sysctl.ip6_rt_gc_min_interval, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec_ms_jiffies, + .proc_handler = ip6_rt_gc_dointvec_ms_jiffies, }, { .procname = "skip_notify_on_dev_down", @@ -6796,8 +6808,6 @@ static int __net_init ip6_route_net_init(struct net *net) net->ipv6.sysctl.ip6_rt_min_advmss = IPV6_MIN_MTU - 20 - 40; net->ipv6.sysctl.skip_notify_on_dev_down = 0; - atomic_set(&net->ipv6.ip6_rt_gc_expire, 30*HZ); - ret = 0; out: return ret; -- 2.54.0 (Apple Git-157) ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 2/2] selftests: Add stress test for dst_entries 2026-12-02 1:55 [PATCH net-next 0/2] ipv6: remove dst_ops gc handler David Ahern 2026-12-02 1:55 ` [PATCH net-next 1/2] " David Ahern @ 2026-12-02 1:55 ` David Ahern 2026-12-03 2:02 ` netdev-bot+sashiko 2026-12-02 10:04 ` [PATCH net-next 0/2] ipv6: remove dst_ops gc handler Ido Schimmel 2 siblings, 1 reply; 5+ messages in thread From: David Ahern @ 2026-12-02 1:55 UTC (permalink / raw) To: netdev Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, willemb, horms, David Ahern From: David Ahern <dahern@nvidia.com> Signed-off-by: David Ahern <dahern@nvidia.com> --- tools/testing/selftests/net/fib_tests.sh | 178 ++++++++++++++++++++++- 1 file changed, 177 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh index d7ac3c727f70..d1686dff7a77 100755 --- a/tools/testing/selftests/net/fib_tests.sh +++ b/tools/testing/selftests/net/fib_tests.sh @@ -14,7 +14,8 @@ TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \ ipv4_mpath_list ipv6_mpath_list ipv4_mpath_balance ipv6_mpath_balance \ ipv4_mpath_balance_preferred ipv4_mpath_oif ipv4_mpath_oif_nh \ ipv4_mpath_oif_vrf ipv6_mpath_oif ipv6_mpath_oif_nh ipv6_mpath_oif_vrf \ - fib6_ra_to_static fib6_temp_addr_renewal" + fib6_ra_to_static fib6_temp_addr_renewal \ + ipv4_dst_entries_stress ipv6_dst_entries_stress" VERBOSE=0 PAUSE_ON_FAIL=no @@ -3228,6 +3229,179 @@ ipv6_mpath_oif_vrf_test() cleanup } +# Number of dst entries the netns' dst_ops accounts for. DST_NOCOUNT dsts +# (pcpu routes) are not in it, but exceptions, clones and uncached dsts are. +# The IPv4 counter belongs to the global ipv4_dst_ops, so it also sees other +# netns. +dst_entries() +{ + local family=$1 hex + + if [ "$family" = "6" ]; then + hex=$($NS_EXEC awk '{print $6}' /proc/net/rt6_stats) + else + hex=$($NS_EXEC awk 'NR == 2 {print $1}' /proc/net/stat/rt_cache) + fi + + echo $((16#$hex)) +} + +# wait up to $3 seconds for the dst entry count to drop to $2 or below +wait_dst_entries_le() +{ + local family=$1 + local limit=$2 + local secs=$3 + local i + + for ((i = 0; i < secs * 10; i++)); do + [ $(dst_entries $family) -le $limit ] && return 0 + sleep 0.1 + done + + return 1 +} + +# Create more PMTU exceptions than the exception tables allow and churn the +# routes while every cpu keeps building pcpu dsts. The dst count must stay +# within the table limits, must not grow because of the churn, and must go +# back to where it started once the routes and nexthops are gone. +# +# DST_STRESS_EXC is the number of destinations to send a too big packet to +# per route, DST_STRESS_ITERS the number of churn iterations. +dst_entries_stress() +{ + local family=$1 + local exc=${DST_STRESS_EXC:-1000} + local iters=${DST_STRESS_ITERS:-200} + local ncpus=$(nproc) + local base after_exc after_churn cap slack i cpu dst1 dst2 ip6="" + local gw1 pfx1 pfx2 + + [ $ncpus -gt 4 ] && ncpus=4 + + if [ ! -x "$(command -v taskset)" ]; then + echo "SKIP: taskset not installed" + return $ksft_skip + fi + + setup + + set -e + setup_ns ns2 + $IP link add veth1 type veth peer name veth2 netns $ns2 + $IP link set veth1 up + ip -netns $ns2 link set veth2 up + ip -netns $ns2 link add dummy0 type dummy + ip -netns $ns2 link set dummy0 mtu 1280 up + # the too big messages must not be rate limited + ip netns exec $ns2 sysctl -qw net.ipv4.ip_forward=1 + ip netns exec $ns2 sysctl -qw net.ipv4.icmp_ratelimit=0 + ip netns exec $ns2 sysctl -qw net.ipv4.icmp_msgs_per_sec=100000 + ip netns exec $ns2 sysctl -qw net.ipv4.icmp_msgs_burst=100000 + ip netns exec $ns2 sysctl -qw net.ipv6.conf.all.forwarding=1 + ip netns exec $ns2 sysctl -qw net.ipv6.icmp.ratelimit=0 + + if [ "$family" = "6" ]; then + ip6="-6" + gw1=2001:db8:10::2 + pfx1=2001:db8:12::/64 + pfx2=2001:db8:13::/64 + cap=$((2 * 1024 * 6)) # 2 fib6_nh * buckets * (depth + 1) + slack=16 + $IP -6 address add 2001:db8:10::1/64 dev veth1 nodad + ip -netns $ns2 -6 address add 2001:db8:10::2/64 dev veth2 nodad + ip -netns $ns2 -6 route add $pfx1 dev dummy0 + ip -netns $ns2 -6 route add $pfx2 dev dummy0 + else + gw1=10.10.0.2 + pfx1=10.20.0.0/16 + pfx2=10.30.0.0/16 + cap=$((2 * 2048 * 6)) + slack=64 # the counter is global + $IP address add 10.10.0.1/24 dev veth1 + ip -netns $ns2 address add 10.10.0.2/24 dev veth2 + ip -netns $ns2 route add $pfx1 dev dummy0 + ip -netns $ns2 route add $pfx2 dev dummy0 + fi + + # one route with its own nexthop, one using a nexthop object + $IP $ip6 nexthop add id 100 via $gw1 dev veth1 + $IP $ip6 route add $pfx1 via $gw1 dev veth1 + $IP $ip6 route add $pfx2 nhid 100 + set +e + + base=$(dst_entries $family) + + for ((i = 1; i <= exc; i++)); do + if [ "$family" = "6" ]; then + dst1=2001:db8:12::$(printf %x $i) + dst2=2001:db8:13::$(printf %x $i) + $NS_EXEC $ping6 -c1 -W1 -s1400 $dst1 &> /dev/null + $NS_EXEC $ping6 -c1 -W1 -s1400 $dst2 &> /dev/null + else + dst1=10.20.$((i / 250)).$((i % 250 + 1)) + dst2=10.30.$((i / 250)).$((i % 250 + 1)) + $NS_EXEC ping -c1 -W1 -s1400 -M do $dst1 &> /dev/null + $NS_EXEC ping -c1 -W1 -s1400 -M do $dst2 &> /dev/null + fi + done + + after_exc=$(dst_entries $family) + [ $after_exc -gt $((base + exc / 2)) ] + log_test $? 0 "PMTU exceptions created ($base -> $after_exc dst entries)" + + [ $after_exc -le $((base + cap)) ] + log_test $? 0 "dst entries within the exception table limits ($after_exc <= $((base + cap)))" + + # churn: every cpu builds pcpu dsts, then the routes and the nexthop + # change, which invalidates them + for ((i = 0; i < iters; i++)); do + for ((cpu = 0; cpu < ncpus; cpu++)); do + if [ "$family" = "6" ]; then + taskset -a -c $cpu $IP -6 route get 2001:db8:12::1 &> /dev/null + taskset -a -c $cpu $IP -6 route get 2001:db8:13::1 &> /dev/null + else + taskset -a -c $cpu $IP route get 10.20.0.1 &> /dev/null + taskset -a -c $cpu $IP route get 10.30.0.1 &> /dev/null + fi + done + $IP $ip6 route replace $pfx1 via $gw1 dev veth1 + $IP $ip6 nexthop replace id 100 via $gw1 dev veth1 + $IP $ip6 route replace $pfx2 nhid 100 + done + + # let the deferred releases run + sleep 2 + after_churn=$(dst_entries $family) + [ $after_churn -le $((after_exc + slack)) ] + log_test $? 0 "dst entries do not grow with route churn ($after_exc -> $after_churn)" + + $IP $ip6 route del $pfx1 + $IP $ip6 route del $pfx2 + $IP $ip6 nexthop del id 100 + wait_dst_entries_le $family $((base + slack)) 10 + log_test $? 0 "dst entries released with routes and nexthop (base $base, now $(dst_entries $family))" + + cleanup +} + +ipv4_dst_entries_stress_test() +{ + echo + echo "IPv4 dst entries stress test" + + dst_entries_stress 4 +} + +ipv6_dst_entries_stress_test() +{ + echo + echo "IPv6 dst entries stress test" + + dst_entries_stress 6 +} + ################################################################################ # usage @@ -3322,6 +3496,8 @@ do ipv6_mpath_oif_vrf) ipv6_mpath_oif_vrf_test;; fib6_ra_to_static) fib6_ra_to_static;; fib6_temp_addr_renewal) fib6_temp_addr_renewal;; + ipv4_dst_entries_stress) ipv4_dst_entries_stress_test;; + ipv6_dst_entries_stress) ipv6_dst_entries_stress_test;; help) echo "Test names: $TESTS"; exit 0;; esac -- 2.54.0 (Apple Git-157) ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 2/2] selftests: Add stress test for dst_entries 2026-12-02 1:55 ` [PATCH net-next 2/2] selftests: Add stress test for dst_entries David Ahern @ 2026-12-03 2:02 ` netdev-bot+sashiko 0 siblings, 0 replies; 5+ messages in thread From: netdev-bot+sashiko @ 2026-12-03 2:02 UTC (permalink / raw) To: dsahern Cc: netdev, idosch, davem, edumazet, kuba, pabeni, willemb, horms, dahern Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 2 · Low: 5 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] The IPv4 variant of dst_entries_stress() fails on a correct kernel. - [Medium] dst_entries_stress() says it creates "more PMTU exceptions than the exception tables allow". - [Low] In the dst_entries_stress() churn loop, on IPv4, `$IP route replace $pfx1 via $gw1 dev veth1` and `$IP route replace $pfx2 nhid… - [Low] The "dst entries do not grow with route churn" check in dst_entries_stress() compares after_churn with after_exc + slack, and… - [Low] dst_entries_stress() sets `local ncpus=$(nproc)`. - [Low] The dst_entries() helper comment says "DST_NOCOUNT dsts (pcpu routes) are not in it, but exceptions, clones and uncached dsts are"… - [Low] The commit "selftests: Add stress test for dst_entries" has no body beyond the Signed-off-by. -- selftests: Add stress test for dst_entries This adds ipv4_dst_entries_stress and ipv6_dst_entries_stress to fib_tests.sh. Each test creates PMTU exceptions through a forwarding namespace, churns routes and a nexthop object while pinning route lookups to several CPUs, and checks the dst_ops entry counter at each stage. Both tests are added to the default TESTS list. > diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh > index d7ac3c727f704..d1686dff7a774 100755 > --- a/tools/testing/selftests/net/fib_tests.sh > +++ b/tools/testing/selftests/net/fib_tests.sh > @@ -14,7 +14,8 @@ TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \ > ipv4_mpath_list ipv6_mpath_list ipv4_mpath_balance ipv6_mpath_balance \ > ipv4_mpath_balance_preferred ipv4_mpath_oif ipv4_mpath_oif_nh \ > ipv4_mpath_oif_vrf ipv6_mpath_oif ipv6_mpath_oif_nh ipv6_mpath_oif_vrf \ > - fib6_ra_to_static fib6_temp_addr_renewal" > + fib6_ra_to_static fib6_temp_addr_renewal \ > + ipv4_dst_entries_stress ipv6_dst_entries_stress" [Severity: Low] This isn't a bug, but the commit message has nothing beyond the Signed-off-by. Could it say: - what the test is meant to validate (for example the "ipv6: remove dst_ops gc handler" change) - what each log_test asserts - what DST_STRESS_EXC and DST_STRESS_ITERS control - why there is an IPv4 variant when the series changes no IPv4 code - that taskset is required It would also help to say that both tests join the default TESTS list. That means every default fib_tests.sh run now does thousands of ping and ip invocations. [ ... ] > +# Number of dst entries the netns' dst_ops accounts for. DST_NOCOUNT dsts > +# (pcpu routes) are not in it, but exceptions, clones and uncached dsts are. > +# The IPv4 counter belongs to the global ipv4_dst_ops, so it also sees other > +# netns. [Severity: Low] Is this description accurate for IPv4? It matches IPv6, but on IPv4 rt_dst_alloc() in net/ipv4/route.c never passes DST_NOCOUNT: rt = dst_alloc(&ipv4_dst_ops, dev, DST_OBSOLETE_FORCE_CHK, (noxfrm ? DST_NOXFRM : 0)); So IPv4 pcpu output dsts (nhc_pcpu_rth_output) are counted. An IPv4 exception (fnhe) has no dst unless a later lookup binds one. The IPv4 and IPv6 halves of the test therefore measure different sets of objects. The IPv4 slack=64 is justified only by "the counter is global", not by the counted pcpu dsts that the churn keeps alive. [ ... ] > +# Create more PMTU exceptions than the exception tables allow and churn the > +# routes while every cpu keeps building pcpu dsts. The dst count must stay > +# within the table limits, must not grow because of the churn, and must go > +# back to where it started once the routes and nexthops are gone. [ ... ] > + if [ "$family" = "6" ]; then > + ip6="-6" > + gw1=2001:db8:10::2 > + pfx1=2001:db8:12::/64 > + pfx2=2001:db8:13::/64 > + cap=$((2 * 1024 * 6)) # 2 fib6_nh * buckets * (depth + 1) [ ... ] > + cap=$((2 * 2048 * 6)) [Severity: Medium] Does the default run really create more exceptions than the tables allow? With DST_STRESS_EXC=1000 per route, each nexthop gets about 1000 exceptions. A fib6_nh has 1024 buckets (FIB6_EXCEPTION_BUCKET_SIZE_SHIFT 10) and an IPv4 nexthop has 2048 (FNHE_HASH_SHIFT 11), so that is about one entry per bucket. Eviction only starts once a bucket goes over a randomized depth, in rt6_insert_exception() in net/ipv6/route.c: max_depth = FIB6_MAX_DEPTH + get_random_u32_below(FIB6_MAX_DEPTH); while (bucket->depth > max_depth) rt6_exception_remove_oldest(bucket); update_or_create_fnhe() does the same thing using FNHE_RECLAIM_DEPTH. This means rt6_exception_remove_oldest() is almost never reached. The "within the exception table limits" check (about 2000 against a cap of 12288) cannot fail with the defaults. The cap formula also assumes a fixed 6 entries per bucket. Since max_depth ranges from 5 to 9, an IPv6 bucket can hold up to 9 entries. An IPv4 bucket can hold up to 10, because update_or_create_fnhe() trims before it inserts. If DST_STRESS_EXC is raised enough to fill the IPv6 tables, couldn't after_exc settle above base + 12288 and report a failure on a correct kernel? [ ... ] > + for ((i = 1; i <= exc; i++)); do > + if [ "$family" = "6" ]; then > + dst1=2001:db8:12::$(printf %x $i) > + dst2=2001:db8:13::$(printf %x $i) > + $NS_EXEC $ping6 -c1 -W1 -s1400 $dst1 &> /dev/null > + $NS_EXEC $ping6 -c1 -W1 -s1400 $dst2 &> /dev/null > + else > + dst1=10.20.$((i / 250)).$((i % 250 + 1)) > + dst2=10.30.$((i / 250)).$((i % 250 + 1)) > + $NS_EXEC ping -c1 -W1 -s1400 -M do $dst1 &> /dev/null > + $NS_EXEC ping -c1 -W1 -s1400 -M do $dst2 &> /dev/null > + fi > + done > + > + after_exc=$(dst_entries $family) > + [ $after_exc -gt $((base + exc / 2)) ] > + log_test $? 0 "PMTU exceptions created ($base -> $after_exc dst entries)" [Severity: Medium] Can this check pass on IPv4? Creating an IPv4 exception does not allocate a dst. update_or_create_fnhe() in net/ipv4/route.c only allocates a struct fib_nh_exception. It then marks nhc_rth_input and the nhc_pcpu_rth_output entries DST_OBSOLETE_KILL. An rtable is only bound to an fnhe by a later output lookup for the same daddr, in __mkroute_output(): prth = &fnhe->fnhe_rth_output; Each destination here gets a single ping -c1 -M do. The frag-needed error is handled once, through raw_err() or ping_err() and then ipv4_sk_update_pmtu(). For an unconnected socket, that path ends in __ipv4_sk_update_pmtu(): if (sock_owned_by_user(sk) || !odst) { __ipv4_sk_update_pmtu(skb, sk, mtu); goto out; } __ipv4_sk_update_pmtu() does its route lookup before __ip_rt_update_pmtu() creates the fnhe, and nothing looks up that daddr again. The next lookup on the same nexthop finds the killed pcpu route and allocates a replacement. rt_cache_route() then releases the old one, so the counter stays roughly flat. Since ipv4_dst_entries_stress is in the default TESTS list, won't fib_tests.sh report a failure here on a correct kernel? This assumes ping uses an unconnected socket, which iputils does since it uses sendto(). A connected socket would take the dst_check() path in ipv4_sk_update_pmtu() and look up the route again. [ ... ] > + # churn: every cpu builds pcpu dsts, then the routes and the nexthop > + # change, which invalidates them > + for ((i = 0; i < iters; i++)); do > + for ((cpu = 0; cpu < ncpus; cpu++)); do > + if [ "$family" = "6" ]; then > + taskset -a -c $cpu $IP -6 route get 2001:db8:12::1 &> /dev/null > + taskset -a -c $cpu $IP -6 route get 2001:db8:13::1 &> /dev/null > + else > + taskset -a -c $cpu $IP route get 10.20.0.1 &> /dev/null > + taskset -a -c $cpu $IP route get 10.30.0.1 &> /dev/null > + fi > + done [Severity: Low] ncpus comes from "local ncpus=$(nproc)". That is the number of CPUs in the affinity mask, not a range of CPU ids starting at 0. Suppose the allowed set isn't {0..n-1}, for example under a cpuset that excludes CPU 0, or with offline CPUs in the low range. Then taskset fails to set the affinity and the ip route get never runs. Both stderr and the exit status are thrown away here. Would the per-CPU pcpu dst building then be skipped silently while the test still reports a pass? > + $IP $ip6 route replace $pfx1 via $gw1 dev veth1 > + $IP $ip6 nexthop replace id 100 via $gw1 dev veth1 > + $IP $ip6 route replace $pfx2 nhid 100 > + done [Severity: Low] On IPv4, do the two route replace commands change anything? They resend the existing route exactly. fib_create_info() finds the identical fib_info through fib_find_info() and returns it. fib_table_insert() then matches it and exits early: if (fa_match) { if (fa == fa_match) err = 0; goto out; } No alias is replaced, and no fib_info or fib_nh is released. Only the nexthop replace has an effect. It still invalidates pfx1's cached dsts, because nh_rt_cache_flush() calls rt_cache_flush() when nexthop 100's fi_list is non-empty, and that bumps the genid. What the IPv4 run never covers is the fib_info and fib_nh release path for a replaced route. IPv6 does cover it through fib6_add_rt2node() and fib6_purge_rt(). For IPv4, the comment "then the routes and the nexthop change" is only half true. > + > + # let the deferred releases run > + sleep 2 > + after_churn=$(dst_entries $family) > + [ $after_churn -le $((after_exc + slack)) ] > + log_test $? 0 "dst entries do not grow with route churn ($after_exc -> $after_churn)" [Severity: Low] On IPv6, after_exc includes about 2 * exc exception dsts. In the first churn iteration, ip -6 route replace runs fib6_purge_rt() on the old fib6_info: fib6_drop_pcpu_from(rt); rt6_flush_exceptions(rt); The nexthop replace also frees the old nh_info. fib6_nh_release()->fib6_nh_release_dsts() then calls fib6_nh_flush_exceptions(). Together these drop the counter back to about base. Doesn't that let this check pass even with a churn-induced leak of up to after_exc - base dsts, about 2000 with the defaults? Also, the pcpu dsts the churn builds come from ip6_rt_pcpu_alloc(): pcpu_rt = ip6_dst_alloc(dev_net(dev), dev, flags | DST_NOCOUNT); so /proc/net/rt6_stats never counts them, and a leak of IPv6 pcpu dsts would not show up here. The later base + slack check still catches counted leaks that outlive the route deletion. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202015529.7846-1-dsahern%40kernel.org ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 0/2] ipv6: remove dst_ops gc handler 2026-12-02 1:55 [PATCH net-next 0/2] ipv6: remove dst_ops gc handler David Ahern 2026-12-02 1:55 ` [PATCH net-next 1/2] " David Ahern 2026-12-02 1:55 ` [PATCH net-next 2/2] selftests: Add stress test for dst_entries David Ahern @ 2026-12-02 10:04 ` Ido Schimmel 2 siblings, 0 replies; 5+ messages in thread From: Ido Schimmel @ 2026-12-02 10:04 UTC (permalink / raw) To: David Ahern; +Cc: netdev, davem, edumazet, kuba, pabeni, willemb, horms On Tue, Dec 01, 2026 at 06:55:21PM -0700, David Ahern wrote: > IPv6 is the only address family that still uses dst_ops->gc to > limit dst entries. ip6_dst_gc() runs from dst_alloc() whenever > the entry count exceeds gc_thresh. It never fails an allocation > (max_size is already INT_MAX); it only forces a fib6_run_gc() > pass. That pass can free expired exceptions and expired routes > on the FIB6 gc list. It cannot free uncached dsts, which are > held by sockets and skbs. > > Remove the handler and rely on the structural limits that > already bound the dst count, the same way IPv4 does. You will need to repost this after Willem's patch [1] is in net-next since both submissions conflict. [1] https://lore.kernel.org/netdev/20261201015652.38202-1-willemb@google.com/ ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-03 2:02 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-02 1:55 [PATCH net-next 0/2] ipv6: remove dst_ops gc handler David Ahern 2026-12-02 1:55 ` [PATCH net-next 1/2] " David Ahern 2026-12-02 1:55 ` [PATCH net-next 2/2] selftests: Add stress test for dst_entries David Ahern 2026-12-03 2:02 ` netdev-bot+sashiko 2026-12-02 10:04 ` [PATCH net-next 0/2] ipv6: remove dst_ops gc handler Ido Schimmel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox