From: netdev-bot+sashiko@kernel.org
To: qiliang.yuan@linux.dev
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, dsahern@kernel.org,
idosch@nvidia.com, razor@blackwall.org, kuniyu@google.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v4 3/4] nexthop: release cached routes when a nexthop leaves a group
Date: Sun, 22 Nov 2026 03:14:13 +0000 [thread overview]
Message-ID: <179531725321.3135.3845475174656034580@kernel.org> (raw)
In-Reply-To: <20261117-bug-net-netns-move-rcu-barrier-v4-3-43e1ca0aac7f@linux.dev>
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
next prev parent reply other threads:[~2026-11-22 3:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 2:28 [PATCH net-next v4 0/4] net: make moving a device to another netns cheaper Qiliang Yuan
2026-11-18 2:28 ` [PATCH net-next v4 1/4] ipv4: draw rt_genid from a sequence shared by all netns Qiliang Yuan
2026-11-22 3:14 ` netdev-bot+sashiko
2026-11-18 2:28 ` [PATCH net-next v4 2/4] ipv6: take fib6_sernum " Qiliang Yuan
2026-11-20 17:52 ` Ralf Lici
2026-11-20 23:13 ` Qiliang Yuan
2026-11-22 3:14 ` netdev-bot+sashiko
2026-11-18 2:28 ` [PATCH net-next v4 3/4] nexthop: release cached routes when a nexthop leaves a group Qiliang Yuan
2026-11-22 3:14 ` netdev-bot+sashiko [this message]
2026-11-18 2:28 ` [PATCH net-next v4 4/4] net: remove rcu_barrier() from __dev_change_net_namespace() Qiliang Yuan
2026-11-22 3:14 ` netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179531725321.3135.3845475174656034580@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=qiliang.yuan@linux.dev \
--cc=razor@blackwall.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®