Re: [PATCH net-next v4 3/4] nexthop: release cached routes when a nexthop leaves a group

From: netdev-bot+sashiko

Date: Sat Nov 21 2026 - 22:14:33 EST


Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

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).

- [High] nexthop: missing rt_genid_bump_ipv6() in
remove_nexthop_from_groups()
- [Low] The new block comment in remove_nexthop_from_groups()
(net/ipv4/nexthop.c) says "Routes through the groups can still hold…

--

nexthop: release cached routes when a nexthop leaves a group

When a nexthop is removed from a group that stays alive, this patch makes
remove_nexthop_from_groups() release the per-cpu routes and exceptions of
the removed nexthop once synchronize_net() returns, if it is IPv6. It also
flushes the IPv4 route cache once if any affected group carries IPv4
routes.

> diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
> index 42e55b5a755ee..3fccd4f2f916b 100644
> --- a/net/ipv4/nexthop.c
> +++ b/net/ipv4/nexthop.c

[ ... ]

> @@ -2130,6 +2131,20 @@ remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
> /* make sure all see the newly published array before releasing rtnl */
> synchronize_net();
>
> + /* Routes through the groups can still hold dsts cached through @nh,
> + * which are only released when @nh is freed. Release them now that
> + * no reader can pick @nh from the old groups any more.
> + */
> + nhi = rtnl_dereference(nh->nh_info);
> + if (nhi->family == AF_INET6)
> + fib6_nh_release_dsts(&nhi->fib6_nh);
> + list_for_each_entry(nhge, &deferred_free, nh_list) {
> + if (!list_empty(&nhge->nh_parent->fi_list)) {
> + rt_cache_flush(net);
> + break;
> + }
> + }

[Severity: High]
Does this also need an IPv6 genid bump for the groups that carry IPv6
routes?

For a route through a group, ip6_rt_pcpu_alloc() records the current
rt_genid_ipv6() in pcpu_rt->sernum. ip6_dst_check() then takes the
early path for that route:

net/ipv6/route.c:ip6_dst_check() {
...
if (rt->sernum)
return rt6_is_valid(rt) ? dst : NULL;
...
}

rt6_is_valid() only compares rt->sernum against
rt_genid_ipv6(dev_net(rt->dst.dev)). It does not look at
dst->obsolete or rt->from.

fib6_nh_release_dsts() calls dst_dev_put() on each per-cpu route.
That marks the route DST_OBSOLETE_DEAD, points dst->output at
dst_discard_out and moves the device to blackhole_netdev. Nothing on
this path bumps the IPv6 genid, though. The group's routes stay in
the FIB, and __remove_nexthop_fib() only walks nh->f6i_list, not the
parent's.

In a non-initial netns, as in the test from the commit message,
moving the device to blackhole_netdev changes dev_net() to &init_net.
The sernum comparison then fails, more or less by accident.

In init_net, dev_net(blackhole_netdev) is still &init_net and the
genid has not moved. rt6_is_valid() keeps returning true for the dead
dst. Wouldn't a connected socket in init_net then keep that dst in
sk_dst_cache and silently discard everything it sends, instead of
failing over to the remaining members of the group?

The same missing bump would also seem to leave uncached routes
through @nh on rt6_uncached_list valid. Those routes are in neither
rt6i_pcpu nor the exception buckets that fib6_nh_release_dsts()
walks.

nh_rt_cache_flush() handles the replace case by checking f6i_list
under the lock first:

net/ipv4/nexthop.c:nh_rt_cache_flush() {
...
spin_lock_bh(&nh->lock);
have_f6i = !list_empty(&nh->f6i_list);
spin_unlock_bh(&nh->lock);
if (have_f6i)
rt_genid_bump_ipv6(net);
...
}

Should the loop over deferred_free also check
nhge->nh_parent->f6i_list under nh_parent->lock? It could then call
rt_genid_bump_ipv6(net) once, the same way it calls
rt_cache_flush(net) for fi_list.

[Severity: Low]
This isn't a bug, but is the comment accurate for the IPv4 case?

The comment says the dsts cached through @nh are released here. That holds
for IPv6, where fib6_nh_release_dsts() flushes the exceptions and drops the
per-cpu routes.

For IPv4, rt_cache_flush() only bumps the genid:

net/ipv4/route.c:rt_cache_flush() {
rt_genid_bump_ipv4(net);
}

That invalidates the cached rtables, but it does not release them. The
rtables in @nh's fib_nh_common (nhc_pcpu_rth_output and the fnhe
exceptions), and the device references they hold, are still dropped later
from the RCU callback, through nexthop_free_single()->fib_nh_release().

nh_rt_cache_flush() describes these as two separate things. One comment
says the dst entries "need to be regenerated" (the genid bump), and another
says "we have to release all old dsts" (IPv6 only).

Could the new comment draw the same distinction, so it doesn't suggest the
IPv4 dsts are freed at this point?

> +
> /* Now safe to free percpu stats — all RCU readers have finished */
> list_for_each_entry_safe(nhge, tmp, &deferred_free, nh_list) {
> list_del(&nhge->nh_list);

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-bug-net-netns-move-rcu-barrier-v4-0-43e1ca0aac7f%40linux.dev