From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, ralf@mandelbit.com, ja@ssi.bg,
David Ahern <dahern@nvidia.com>
Subject: [PATCH net-next v3 07/13] ipv6: make rt_genid_bump_ipv6() a plain counter increment
Date: Tue, 1 Dec 2026 10:40:08 -0700 [thread overview]
Message-ID: <20261201174021.7211-8-dsahern@kernel.org> (raw)
In-Reply-To: <20261201174021.7211-1-dsahern@kernel.org>
From: David Ahern <dahern@nvidia.com>
rt_genid_bump_ipv6() called fib6_flush_trees() through a function
pointer. That walked every node of every table to write a new
fn_sernum, so that cookies derived from fn_sernum would mismatch.
Cached dsts are now validated against net->ipv6.fib6_sernum itself,
so the walk no longer invalidates anything. Do what
rt_genid_bump_ipv4() does and increment the counter, keeping
fib6_new_sernum()'s wrap to 1 so the value is never 0.
This makes nexthop, address and FIB rule changes cheap, and stops
them from touching fn_sernum, which route dumps use to detect that a
tree changed: a dump is no longer restarted by events that do not
change the tree.
With the walk gone, drop the __fib6_flush_trees pointer and its
export, fib6_new_sernum() in favour of the new helper, and the sernum
handling in fib6_cleaner that only the walk used.
Signed-off-by: David Ahern <dahern@nvidia.com>
---
include/net/net_namespace.h | 26 ++++++++++++++-----
net/ipv6/addrconf_core.c | 7 -----
net/ipv6/ip6_fib.c | 51 ++++++-------------------------------
3 files changed, 27 insertions(+), 57 deletions(-)
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 4a4d72080acd..f39baf51bcc5 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -556,18 +556,30 @@ static inline int rt_genid_ipv6(const struct net *net)
{
return atomic_read(&net->ipv6.fib6_sernum);
}
-#endif
-static inline void rt_genid_bump_ipv4(struct net *net)
+/* Invalidate every cached IPv6 dst in @net. Returns the new generation,
+ * which is never 0.
+ */
+static inline int rt_genid_bump_ipv6(struct net *net)
{
- atomic_inc(&net->ipv4.rt_genid);
+ int new, old = atomic_read(&net->ipv6.fib6_sernum);
+
+ do {
+ new = old < INT_MAX ? old + 1 : 1;
+ } while (!atomic_try_cmpxchg(&net->ipv6.fib6_sernum, &old, new));
+
+ return new;
}
+#else
+static inline int rt_genid_bump_ipv6(struct net *net)
+{
+ return 0;
+}
+#endif
-extern void (*__fib6_flush_trees)(struct net *net);
-static inline void rt_genid_bump_ipv6(struct net *net)
+static inline void rt_genid_bump_ipv4(struct net *net)
{
- if (__fib6_flush_trees)
- __fib6_flush_trees(net);
+ atomic_inc(&net->ipv4.rt_genid);
}
#if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN)
diff --git a/net/ipv6/addrconf_core.c b/net/ipv6/addrconf_core.c
index 29095c90aa16..e7ee5f98327d 100644
--- a/net/ipv6/addrconf_core.c
+++ b/net/ipv6/addrconf_core.c
@@ -9,13 +9,6 @@
#include <net/addrconf.h>
#include <net/ip.h>
-/* if ipv6 module registers this function is used by xfrm to force all
- * sockets to relookup their nodes - this is fairly expensive, be
- * careful
- */
-void (*__fib6_flush_trees)(struct net *);
-EXPORT_SYMBOL(__fib6_flush_trees);
-
#define IPV6_ADDR_SCOPE_TYPE(scope) ((scope) << 16)
static inline unsigned int ipv6_addr_scope2type(unsigned int scope)
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 266370e15774..75512fbcb945 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -43,7 +43,6 @@ struct fib6_cleaner {
struct fib6_walker w;
struct net *net;
int (*func)(struct fib6_info *, void *arg);
- int sernum;
void *arg;
bool skip_notify;
};
@@ -123,21 +122,6 @@ static void fib6_walkers_skip_rt(struct net *net, struct fib6_info *rt)
fib6_walkers_replace_leaf(net, rt, next);
}
-static int fib6_new_sernum(struct net *net)
-{
- int new, old = atomic_read(&net->ipv6.fib6_sernum);
-
- do {
- new = old < INT_MAX ? old + 1 : 1;
- } while (!atomic_try_cmpxchg(&net->ipv6.fib6_sernum, &old, new));
-
- return new;
-}
-
-enum {
- FIB6_NO_SERNUM_CHANGE = 0,
-};
-
void fib6_update_sernum(struct net *net, struct fib6_info *f6i)
{
struct fib6_node *fn;
@@ -145,7 +129,7 @@ void fib6_update_sernum(struct net *net, struct fib6_info *f6i)
fn = rcu_dereference_protected(f6i->fib6_node,
lockdep_is_held(&f6i->fib6_table->tb6_lock));
if (fn)
- WRITE_ONCE(fn->fn_sernum, fib6_new_sernum(net));
+ WRITE_ONCE(fn->fn_sernum, rt_genid_bump_ipv6(net));
}
/* Tell route dumps that an exception was added under @f6i without
@@ -1464,7 +1448,7 @@ static void __fib6_update_sernum_upto_root(struct fib6_info *rt,
void fib6_update_sernum_upto_root(struct net *net, struct fib6_info *rt)
{
- __fib6_update_sernum_upto_root(rt, fib6_new_sernum(net));
+ __fib6_update_sernum_upto_root(rt, rt_genid_bump_ipv6(net));
}
/*
@@ -1595,7 +1579,7 @@ int fib6_add(struct fib6_node *root, struct fib6_info *rt,
fib6_info_release(iter);
}
- __fib6_update_sernum_upto_root(rt, fib6_new_sernum(info->nl_net));
+ __fib6_update_sernum_upto_root(rt, rt_genid_bump_ipv6(info->nl_net));
if (rt->fib6_flags & RTF_EXPIRES)
fib6_add_gc_list(rt);
@@ -2282,16 +2266,6 @@ static int fib6_clean_node(struct fib6_walker *w)
.skip_notify = c->skip_notify,
};
- if (c->sernum != FIB6_NO_SERNUM_CHANGE &&
- READ_ONCE(w->node->fn_sernum) != c->sernum)
- WRITE_ONCE(w->node->fn_sernum, c->sernum);
-
- if (!c->func) {
- WARN_ON_ONCE(c->sernum == FIB6_NO_SERNUM_CHANGE);
- w->leaf = NULL;
- return 0;
- }
-
for_each_fib6_walker_rt(w) {
res = c->func(rt, c->arg);
if (res == -1) {
@@ -2331,7 +2305,7 @@ static int fib6_clean_node(struct fib6_walker *w)
static void fib6_clean_tree(struct net *net, struct fib6_node *root,
int (*func)(struct fib6_info *, void *arg),
- int sernum, void *arg, bool skip_notify)
+ void *arg, bool skip_notify)
{
struct fib6_cleaner c;
@@ -2341,7 +2315,6 @@ static void fib6_clean_tree(struct net *net, struct fib6_node *root,
c.w.skip = 0;
c.w.skip_in_node = 0;
c.func = func;
- c.sernum = sernum;
c.arg = arg;
c.net = net;
c.skip_notify = skip_notify;
@@ -2351,7 +2324,7 @@ static void fib6_clean_tree(struct net *net, struct fib6_node *root,
static void __fib6_clean_all(struct net *net,
int (*func)(struct fib6_info *, void *),
- int sernum, void *arg, bool skip_notify)
+ void *arg, bool skip_notify)
{
struct fib6_table *table;
struct hlist_head *head;
@@ -2363,7 +2336,7 @@ static void __fib6_clean_all(struct net *net,
hlist_for_each_entry_rcu(table, head, tb6_hlist) {
spin_lock_bh(&table->tb6_lock);
fib6_clean_tree(net, &table->tb6_root,
- func, sernum, arg, skip_notify);
+ func, arg, skip_notify);
spin_unlock_bh(&table->tb6_lock);
}
}
@@ -2373,21 +2346,14 @@ static void __fib6_clean_all(struct net *net,
void fib6_clean_all(struct net *net, int (*func)(struct fib6_info *, void *),
void *arg)
{
- __fib6_clean_all(net, func, FIB6_NO_SERNUM_CHANGE, arg, false);
+ __fib6_clean_all(net, func, arg, false);
}
void fib6_clean_all_skip_notify(struct net *net,
int (*func)(struct fib6_info *, void *),
void *arg)
{
- __fib6_clean_all(net, func, FIB6_NO_SERNUM_CHANGE, arg, true);
-}
-
-static void fib6_flush_trees(struct net *net)
-{
- int new_sernum = fib6_new_sernum(net);
-
- __fib6_clean_all(net, NULL, new_sernum, NULL, false);
+ __fib6_clean_all(net, func, arg, true);
}
/*
@@ -2624,7 +2590,6 @@ int __init fib6_init(void)
if (ret)
goto out_unregister_subsys;
- __fib6_flush_trees = fib6_flush_trees;
out:
return ret;
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-12-01 17:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 01/13] ipv6: allocate the exception entry before removing the one it replaces David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 02/13] ipv6: keep a superseded pcpu dst working until its holders notice David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 03/13] ipv6: don't insert a PMTU exception whose MTU could not be stored David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 04/13] ipv6: invalidate the failing dst in ip6_link_failure() David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 05/13] ipv6: tell route dumps about exception inserts with a table sequence David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 06/13] ipv6: validate dsts against the netns route generation David Ahern
2026-12-01 17:40 ` David Ahern [this message]
2026-12-01 17:40 ` [PATCH net-next v3 08/13] nexthop: factor out nh_has_f6i() David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 09/13] nexthop: bump the IPv6 route generation on group changes David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 10/13] ipv6: stamp dsts with the generation sampled before the FIB lookup David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 11/13] selftests: net: pmtu: check that a deleted cached exception stays deleted David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 12/13] selftests: net: fib_tests: Add stale pcpu test David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 13/13] selftests: net: ipvs: check a PMTU learned after the DR route was cached David Ahern
2026-12-01 17:43 ` [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation netdev-bot+sinfo
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=20261201174021.7211-8-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=dahern@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=ja@ssi.bg \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ralf@mandelbit.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.