Article View: linux.kernel.netdev
Article #21323[RFC net-next v2 6/7] ipv6: make rt_genid_bump_ipv6() a plain counter increment
From: David Ahern
Date: Mon, 23 Nov 2026 21:26
Date: Mon, 23 Nov 2026 21:26
238 lines
14938 bytes
14938 bytes
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>
---
Changes since v1:
- None.
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.43.0
Technical Details
Message-ID:
<20261123212623.106153-7-dsahern@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369783-linux-kernel-netdev=dewy.ruReferences:
<20261123212623.106153-1-dsahern@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369783-linux-kernel-netdev=dewy.ru From: dsahern@kernel.org (David Ahern) Newsgroups: linux.kernel.netdev Subject: [RFC net-next v2 6/7] ipv6: make rt_genid_bump_ipv6() a plain counter increment Date: Mon, 23 Nov 2026 14:26:08 -0700 Organization: Usenet Network Message-ID: <20261123212623.106153-7-dsahern@kernel.org> References: <20261123212623.106153-1-dsahern@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3988787"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:AsSoc7xh3lxAm47WlN+iq3QQkoY= sha256:Qt8GPMsgLiUkQ1icPyb6ZKDdhXSy4M6oTQrANnd58h8= sha1:C/kt7RYft6XzJ2p7NFu/PoLa+Pc= sha256:FCVRUZgBoT0wnaB/p4E2CYVOMgjLE8El2c0W2+RDBIM= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 7A2A6125DC7; Tue, 24 Nov 2026 00:27:08 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F5V-cSYAl_it; Tue, 24 Nov 2026 00:27:05 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369783-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 47931125DB9; Tue, 24 Nov 2026 00:26:57 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 5068E2B6F9; Mon, 23 Nov 2026 21:26:39 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795469193; b=Ekmd6V0qF0H+UAL5H2ZmVj9jeVJ2G0/3gQWN+7z/ar60jYLJgIk5Qw3RnYoAlCceK1CJ JDPm4kZoZzPFjuYUJJXuQ55dUitBoK7dJsyx3ba8rm3fzeBJg/eQlyItBKUiYfIe6eG7o uSybD4x+ogyJcEWdb4PLvEvGCVEHsiTswJVKL7wcU+phdqmUj+NZAB9ro/b1hBrxZwTy3 5+qofg4BSK+hV7J5RW8Q823dLFP4W3fqaS2wz57kQmFbSbxxsHHTyW6mj4HOEpMtA6Uzz KqDavfI2NP9cXPZl5yfvvf+NY7ant8FGio6WugOJIvO71XH8IuBFffaBMH9MDrGurmA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795469193; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding; bh=DPe8sGGCdGPvCKGe5lwr97QVEUM6TDbF4ggH12EU7+E=; b=1/e5wjdK4TVWM0GsgzBbhvek6/KL31xC85t2sLPOcIHsNuw/kfSDCiXCsPkvYOMWskjX xqTtF550vSy02mFK81U0CWnJeadOOZD2yR1P457Y9aPh5ygvn0pZy/2fWp0WbjjeODx7L ixty/3VotsvcRpbXQPW6ppnW8QXoRHWeRJGvPUD8vbswY4H3skKYMVGB0mQ/g6CdwirBt FzdOWr1yjKDpj4j2GJZfIq0hv0upAh1Y3rNTHmZk84i9hu6HHMUUlUKBRHrpaKuHT/zB4 nAHkFciQTNFoy4C3bh26GQiqTn16Db9OJUBZXAUTBwjFImAX9K9SJfaHwcEXQ4pUEgA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HsXMtOt0; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC802606A6AD; Mon, 23 Nov 2026 21:26:33 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HsXMtOt0 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795469192; b=qMJ4i3lwr2xVJTF+raL1UQGOulGYT8CCC1a/FqaJ/Jc9jdtZ3BlMWhD3wR/J4KqZcjWT dpVOfYVA6jIDhM2M9X4VCfAw1l6vuxS5wNw9tmGHgArGP87zKlnSRH8eBSCQo+jaZ51fU 590mvuROXxHT7j0Pi0rEb7FHniT0E35SNxxK3H1EhxLGDuYUtrQeSJQyCtrgtbVDtLkMK xVR83bxaO7kPIo6RBXZbjm4SlvLCWJLGw+u8Fb9zPwkGPmIvwIsjGiERr8yNCP4Q07UQu 1GWucMHVB+5rx9RIaNx6A0oPocpGYElxzJsNSI0WMFVjW6fZDMVBNY5lhFEkwlTz/lA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795469192; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=DPe8sGGCdGPvCKGe5lwr97QVEUM6TDbF4ggH12EU7+E=; b=0lNDzRlfwjAZXqPI7rpXu27QkBdXyPBS5V2NOaMgIOKGUr+my3uthVvXlsz5wDCfNFlr qGWNCp0eQQ3bFoEjvgB689ptUOY3LXnRO00DaByH+RKl/RhBGBqa+8UgtpUei24pnU0zO lYXPlfGKYxksAH3YGnb9xuWw0H2ulyn3ba4cEdLVS8CNm0HcMO6JUAGqMRMv6mpEwd4lL vJbFsozrZB+GgO8YY1x5XKENjLX+HmBJvDrHRH+l9Ml6i/p2To7EILyL6uoxc/tZI7QGf bxgT9Zd9ZGNpvBVQo/8behL6Mw5FwmZussY9HyAVkgBkKey/ix4D6vWhhmQE7xu8uaA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HsXMtOt0; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDF44606A32C for <netdev@vger.kernel.org>; Mon, 23 Nov 2026 21:26:32 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C0861F000F0; Mon, 23 Nov 2026 21:26:32 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795469192; bh=DPe8sGGCdGPvCKGe5lwr97QVEUM6TDbF4ggH12EU7+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HsXMtOt0uN/HypjeFPioAb/50LIeMrpKRQ/wNpGiT3pJDm30Fc655vNZo4dzqhyXI syZ2B4Emp8/oYGyjih6u3R2ygobMiNfi/cRheOZb+YCBPZtDXEO2uu6O5YJ7iwN2/D odTWj81Ks4hG5tgJSn3wZJHJm9yEFf0fT8fuNQobPhR9viLowhWp5kalZxXqgZbS+a XEjucRCIo3eo3bsHmCDluicfO5jkLbYHwxXUynI3nyikExn8AS6OiTcISy8vylTDDF PC/VaQs0S104m+jK7P7h8FmqHdJWNVgAs07oRrdh0lkpEqo7eNCJzw/3Dx8HGkD8H8 CUpSMU7aZzkIA== X-Cc: ralf@mandelbit.com, David Ahern <dahern@nvidia.com> X-Mailer: git-send-email 2.43.0 X-In-Reply-To: <20261123212623.106153-1-dsahern@kernel.org> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list