From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: ralf@mandelbit.com, David Ahern <dahern@nvidia.com>,
David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
"Claude Sonnet 5 . 5" <noreply@anthropic.com>
Subject: [RFC net-next 5/6] ipv6: scope exception invalidation to the affected nexthop
Date: Sun, 22 Nov 2026 15:27:03 -0700 [thread overview]
Message-ID: <20261122222717.126333-7-dsahern@kernel.org> (raw)
In-Reply-To: <20261122222717.126333-1-dsahern@kernel.org>
From: David Ahern <dahern@nvidia.com>
rt6_insert_exception() bumped the netns route generation, which with
generation-based dst validation invalidates every dst in the
namespace each time a PMTU or redirect exception is created. A burst
of packet-too-big messages would make all sockets and dst_caches look
their routes up again.
IPv4 limits this to the nexthop: update_or_create_fnhe() marks only
that nexthop's cached dsts stale. Do the same here by clearing the
sernum of the fib6_nh's pcpu dsts, so their users look the route up
once and find the exception.
Route dumps notice a changed tree through the root node's fn_sernum,
and the exception dump relies on that changing when an exception is
inserted on the root. A fresh fn_sernum can only come from the netns
counter, which must not be bumped here, and a locally made-up value
could later be issued by the counter to the same node and go
unnoticed. Add a per-table tb6_excp_seq, bumped for exceptions on the
root node, and have fib6_dump_table() restart when either it or the
root's fn_sernum has changed.
Signed-off-by: David Ahern <dahern@nvidia.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
---
include/net/ip6_fib.h | 3 +++
net/ipv6/ip6_fib.c | 25 ++++++++++++++++++++++++-
net/ipv6/route.c | 27 +++++++++++++++++++++++++--
3 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index ecce7ab007a5..92fed30a7418 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -329,6 +329,7 @@ struct fib6_walker {
unsigned int skip;
unsigned int count;
unsigned int skip_in_node;
+ unsigned int excp_seq; /* tb6_excp_seq seen by a partial dump */
int (*func)(struct fib6_walker *);
void *args;
};
@@ -362,6 +363,7 @@ struct fib6_table {
struct inet_peer_base tb6_peers;
unsigned int flags;
unsigned int fib_seq; /* writes protected by rtnl_mutex */
+ unsigned int tb6_excp_seq; /* writes under tb6_lock */
struct hlist_head tb6_gc_hlist; /* GC candidates */
#define RT6_TABLE_HAS_DFLT_ROUTER BIT(0)
};
@@ -583,6 +585,7 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack);
void fib6_update_sernum(struct net *net, struct fib6_info *rt);
+void fib6_update_excp_seq(struct fib6_info *rt);
#if IS_ENABLED(CONFIG_IPV6)
void fib6_update_sernum_upto_root(struct net *net, struct fib6_info *rt);
#else
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index d465ac6ffbc6..266370e15774 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -148,6 +148,25 @@ void fib6_update_sernum(struct net *net, struct fib6_info *f6i)
WRITE_ONCE(fn->fn_sernum, fib6_new_sernum(net));
}
+/* Tell route dumps that an exception was added under @f6i without
+ * invalidating cached dsts: those follow the netns generation, which this
+ * leaves alone. A dump notices a changed tree through the root node, so
+ * only an exception on the root needs to be visible. Fresh fn_sernum values
+ * can only come from the netns counter, so use a table sequence rather than
+ * a made-up fn_sernum that the counter could later issue again.
+ * Caller holds tb6_lock.
+ */
+void fib6_update_excp_seq(struct fib6_info *f6i)
+{
+ struct fib6_table *table = f6i->fib6_table;
+ struct fib6_node *fn;
+
+ fn = rcu_dereference_protected(f6i->fib6_node,
+ lockdep_is_held(&table->tb6_lock));
+ if (fn == &table->tb6_root)
+ WRITE_ONCE(table->tb6_excp_seq, table->tb6_excp_seq + 1);
+}
+
/*
* Auxiliary address test functions for the radix tree.
*
@@ -637,12 +656,16 @@ static int fib6_dump_table(struct fib6_table *table, struct sk_buff *skb,
if (res > 0) {
cb->args[4] = 1;
cb->args[5] = READ_ONCE(w->root->fn_sernum);
+ w->excp_seq = READ_ONCE(table->tb6_excp_seq);
}
} else {
int sernum = READ_ONCE(w->root->fn_sernum);
- if (cb->args[5] != sernum) {
+ unsigned int excp_seq = READ_ONCE(table->tb6_excp_seq);
+
+ if (cb->args[5] != sernum || w->excp_seq != excp_seq) {
/* Begin at the root if the tree changed */
cb->args[5] = sernum;
+ w->excp_seq = excp_seq;
w->state = FWS_INIT;
w->node = w->root;
w->skip = w->count;
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index d355652a0520..ee7a62dc16c4 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1732,6 +1732,28 @@ struct rt6_exception_bucket *fib6_nh_get_excptn_bucket(const struct fib6_nh *nh,
return bucket;
}
+/* A new exception may apply to dsts already cached on @nh. Make them fail
+ * ip6_dst_check() once so their users look the route up again and find it;
+ * dsts of other routes are left alone.
+ */
+static void fib6_nh_invalidate_pcpu(const struct fib6_nh *nh)
+{
+ int cpu;
+
+ if (!nh->rt6i_pcpu)
+ return;
+
+ rcu_read_lock();
+ for_each_possible_cpu(cpu) {
+ struct rt6_info *pcpu_rt;
+
+ pcpu_rt = READ_ONCE(*per_cpu_ptr(nh->rt6i_pcpu, cpu));
+ if (pcpu_rt)
+ WRITE_ONCE(pcpu_rt->sernum, 0);
+ }
+ rcu_read_unlock();
+}
+
static int rt6_insert_exception(struct rt6_info *nrt,
const struct fib6_result *res)
{
@@ -1806,10 +1828,11 @@ static int rt6_insert_exception(struct rt6_info *nrt,
out:
spin_unlock_bh(&rt6_exception_lock);
- /* Update fn->fn_sernum to invalidate all cached dst */
if (!err) {
+ fib6_nh_invalidate_pcpu(nh);
+
spin_lock_bh(&f6i->fib6_table->tb6_lock);
- fib6_update_sernum(net, f6i);
+ fib6_update_excp_seq(f6i);
fib6_add_gc_list(f6i);
spin_unlock_bh(&f6i->fib6_table->tb6_lock);
fib6_force_start_gc(net);
--
2.43.0
next prev parent reply other threads:[~2026-11-22 22:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 22:26 David Ahern
2026-11-22 22:26 ` [RFC net-next 0/6] ipv6: validate dsts against the netns route generation David Ahern
2026-11-22 22:30 ` David Ahern
2026-11-22 22:26 ` [RFC net-next 1/6] " David Ahern
2026-11-22 22:27 ` [RFC net-next 2/6] ipv6: invalidate the failing dst in ip6_link_failure() David Ahern
2026-11-22 22:27 ` [RFC net-next 3/6] nexthop: factor out nh_has_f6i() David Ahern
2026-11-22 22:27 ` [RFC net-next 4/6] nexthop: bump the IPv6 route generation on group changes David Ahern
2026-11-22 22:27 ` David Ahern [this message]
2026-11-22 22:27 ` [RFC net-next 6/6] ipv6: make rt_genid_bump_ipv6() a plain counter increment David Ahern
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=20261122222717.126333-7-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=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=noreply@anthropic.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox