Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation
@ 2026-12-01 17:40 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
                   ` (15 more replies)
  0 siblings, 16 replies; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja

IPv6 dsts are validated through a cookie that a holder (socket, dst_cache,
xfrm bundle, IPVS, ...) captures from the fn_sernum of the route's node at
the time it stores the dst. A route change that lands between the route
lookup and that capture is folded into the cookie, and the stale dst then
looks valid. Only nexthop object pcpu routes carried a generation of
their own, and a pcpu dst that failed its check could be re-stamped and
made valid again for every holder (Fixes: 8f34e53b60b3). The reported
result is a dst that keeps bypassing a route change, or a learned PMTU,
for as long as it is held.

This series stamps every dst with the netns route generation when it is
built and validates it with a plain comparison in ip6_dst_check(), the way
IPv4 does with rt_genid. A dst is never re-stamped: holders keep seeing a
stale dst as stale, and a new one is built for the next lookup. Learned
PMTUs and redirects survive a generation change, because a stale exception
is replaced by a current copy, not dropped.

 1-3: exception insert fixes needed before the exception table is
      touched more often: allocate the new entry before the old one is
      removed, keep a superseded pcpu dst working until its holders
      notice it is stale (it is put on the uncached list, so device
      unregister still detaches it), and do not insert an exception
      whose MTU could not be stored.
 4:   ip6_link_failure() invalidates the failing dst only, with a stale
      mark in its sernum, instead of the whole node.
 5:   route dumps notice exception inserts on the root through a table
      sequence, tb6_excp_seq, rather than through fn_sernum.
 6:   the core change: stamp and validate dsts against the netns
      generation, and refresh stale exceptions. An exception insert
      invalidates only the pcpu dsts of its own nexthop, tracked with a
      per-nexthop cpumask, and ip6_dst_check() also fails an uncached
      RTF_CACHE dst (the FLOWI_FLAG_KNOWN_NH clone, which IPVS keeps in
      dest->dst_cache) once an exception exists for its destination on
      any nexthop group member it can have come from.
 7:   rt_genid_bump_ipv6() becomes a plain counter increment instead of
      a walk over every node of every table.
 8-9: nexthop object changes that did not bump the generation now do.
 10:  stamp a dst with the generation sampled before the FIB lookup, not
      the one current when it is allocated, so a change that lands
      during the lookup cannot be folded in.
 11-13: selftests: a deleted exception stays deleted after a FIB
      change (pmtu.sh), a stale pcpu dst after a nexthop change
      (fib_tests.sh), and a PMTU learned after IPVS cached its DR route
      (ipvs.sh).

Known costs and limits:
 - Every FIB change bumps the generation of the netns, so every exception
   becomes stale and is replaced by a copy the next time traffic uses it.
   That is an allocation per exception revisited, and the replacement takes
   rt6_exception_lock, which is global. The entry and the writable
   metrics are allocated before taking it.

 - An exception insert still scans the nexthop's whole dirty cpumask,
   nr_cpu_ids bits, though it only touches the dsts of CPUs that built one.

Changes since v2
- deferred release in patch 6 (Ralf)

Changes since non RFC v1
 - rebased to top of tree
 - added Ralf's reported-by to a few patches
 - Patch 6: the stale-clone check for uncached RTF_CACHE dsts, the
   allocations done before taking rt6_exception_lock, and corrected wording
   about the cpumask scan.
 - New selftest for IPVS DR mode.


David Ahern (13):
  ipv6: allocate the exception entry before removing the one it replaces
  ipv6: keep a superseded pcpu dst working until its holders notice
  ipv6: don't insert a PMTU exception whose MTU could not be stored
  ipv6: invalidate the failing dst in ip6_link_failure()
  ipv6: tell route dumps about exception inserts with a table sequence
  ipv6: validate dsts against the netns route generation
  ipv6: make rt_genid_bump_ipv6() a plain counter increment
  nexthop: factor out nh_has_f6i()
  nexthop: bump the IPv6 route generation on group changes
  ipv6: stamp dsts with the generation sampled before the FIB lookup
  selftests: net: pmtu: check that a deleted cached exception stays
    deleted
  selftests: net: fib_tests: Add stale pcpu test
  selftests: net: ipvs: check a PMTU learned after the DR route was
    cached

 include/net/ip6_fib.h                         |  70 +-
 include/net/net_namespace.h                   |  36 +-
 net/ipv4/nexthop.c                            |  42 +-
 net/ipv6/addrconf_core.c                      |   7 -
 net/ipv6/fib6_rules.c                         |  33 +-
 net/ipv6/ip6_fib.c                            |  76 +-
 net/ipv6/route.c                              | 747 ++++++++++++++++--
 tools/testing/selftests/net/fib_tests.sh      |  53 +-
 tools/testing/selftests/net/netfilter/config  |   2 +
 tools/testing/selftests/net/netfilter/ipvs.sh |  81 ++
 tools/testing/selftests/net/pmtu.sh           |  90 +++
 11 files changed, 1060 insertions(+), 177 deletions(-)

-- 
2.54.0 (Apple Git-157)

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 01/13] ipv6: allocate the exception entry before removing the one it replaces
  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 ` David Ahern
  2026-12-02 16:02   ` Ido Schimmel
  2026-12-01 17:40 ` [PATCH net-next v3 02/13] ipv6: keep a superseded pcpu dst working until its holders notice David Ahern
                   ` (14 subsequent siblings)
  15 siblings, 1 reply; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

From: David Ahern <dahern@nvidia.com>

rt6_insert_exception() unlinks the existing exception for a
destination before it allocates, with GFP_ATOMIC, the table entry for
its replacement. If that allocation fails, what was learned (a
reduced PMTU or a redirect gateway) is already gone and the caller gets
-ENOMEM, so traffic falls back to the route's own MTU and gateway.

Allocate the entry first. If that fails nothing has been touched and
the exception stays as it was.

Fixes: 35732d01fe31 ("ipv6: introduce a hash table to store dst cache")
Signed-off-by: David Ahern <dahern@nvidia.com>
---
 net/ipv6/route.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index df843178e5ec..c41c5ca23fe1 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1721,8 +1721,8 @@ static int rt6_insert_exception(struct rt6_info *nrt,
 	struct net *net = dev_net(nrt->dst.dev);
 	struct rt6_exception_bucket *bucket;
 	struct fib6_info *f6i = res->f6i;
+	struct rt6_exception *rt6_ex, *new_ex;
 	struct in6_addr *src_key = NULL;
-	struct rt6_exception *rt6_ex;
 	struct fib6_nh *nh = res->nh;
 	int max_depth;
 	int err = 0;
@@ -1765,19 +1765,24 @@ static int rt6_insert_exception(struct rt6_info *nrt,
 		goto out;
 	}
 
+	/* Allocate the new entry before the one it replaces is touched, so
+	 * that running out of memory leaves what was learned in place.
+	 */
+	new_ex = kzalloc_obj(*new_ex, GFP_ATOMIC);
+	if (!new_ex) {
+		err = -ENOMEM;
+		goto out;
+	}
+
+	new_ex->rt6i = nrt;
+	new_ex->stamp = jiffies;
+
 	rt6_ex = __rt6_find_exception_spinlock(&bucket, &nrt->rt6i_dst.addr,
 					       src_key);
 	if (rt6_ex)
 		rt6_remove_exception(bucket, rt6_ex);
 
-	rt6_ex = kzalloc_obj(*rt6_ex, GFP_ATOMIC);
-	if (!rt6_ex) {
-		err = -ENOMEM;
-		goto out;
-	}
-	rt6_ex->rt6i = nrt;
-	rt6_ex->stamp = jiffies;
-	hlist_add_head_rcu(&rt6_ex->hlist, &bucket->chain);
+	hlist_add_head_rcu(&new_ex->hlist, &bucket->chain);
 	bucket->depth++;
 	rt6_exception_net(nrt)->ipv6.rt6_stats->fib_rt_cache++;
 
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 02/13] ipv6: keep a superseded pcpu dst working until its holders notice
  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 ` David Ahern
  2026-12-02 16:19   ` Ido Schimmel
  2026-12-05 19:20   ` netdev-bot+sashiko
  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
                   ` (13 subsequent siblings)
  15 siblings, 2 replies; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

From: David Ahern <dahern@nvidia.com>

When rt6_get_pcpu_route() finds that a pcpu dst of a route using a
nexthop object has been invalidated, it takes the dst out of its slot
and calls dst_dev_put() on it. That points the dst at the blackhole
device and makes its output a discard, although the dst may still be
held: by a socket, a tunnel dst_cache, an xfrm bundle, or an skb that
has not reached dst_output() yet (a queued or NFQUEUE reinjected
packet, async crypto). Those packets are dropped, where the holder
would have noticed that the dst is stale at its next check and looked
the route up again.

The dst does have to be detached from its device when the device is
unregistered: it is no longer reachable from the FIB, and a holder
such as an idle socket can keep it indefinitely, which would hold the
device. Put it on the uncached list instead. It keeps working until its
holders let go, and rt6_uncached_list_flush_dev() detaches it on
unregister like any other uncached dst.

Fixes: 8f34e53b60b3 ("ipv6: Use global sernum for dst validation with nexthop objects")
Reported-by: Ralf Lici <ralf@mandelbit.com>
Signed-off-by: David Ahern <dahern@nvidia.com>
---
 net/ipv6/route.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index c41c5ca23fe1..31ebcf665216 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1483,7 +1483,13 @@ static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res)
 		/* Paired with READ_ONCE() in __fib6_drop_pcpu_from() */
 		prev = xchg(p, NULL);
 		if (prev) {
-			dst_dev_put(&prev->dst);
+			/* Holders may still be using it until they notice it
+			 * is stale, so keep it working rather than dst_dev_put()
+			 * it, which would turn the packets of anyone who has
+			 * not rechecked yet into drops. Device unregister
+			 * detaches it like any other uncached dst.
+			 */
+			rt6_uncached_list_add(prev);
 			dst_release(&prev->dst);
 		}
 
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 03/13] ipv6: don't insert a PMTU exception whose MTU could not be stored
  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 ` David Ahern
  2026-12-05 19:20   ` netdev-bot+sashiko
  2026-12-01 17:40 ` [PATCH net-next v3 04/13] ipv6: invalidate the failing dst in ip6_link_failure() David Ahern
                   ` (12 subsequent siblings)
  15 siblings, 1 reply; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

From: David Ahern <dahern@nvidia.com>

rt6_do_update_pmtu() sets the MTU of a dst with dst_metric_set(). A dst
shares the read-only metrics of its route until it needs its own, and
dst_metric_set() allocates writable ones with GFP_ATOMIC on first use,
doing nothing if that fails, without telling the caller.

For a PMTU update on a new exception the caller then goes on to insert
an exception that has no learned MTU, which lowers nothing, replaces
any exception for that destination that was there, and invalidates the
cached dsts of the nexthop. For an update on an existing exception the
reduction is lost while the stamp that keeps the exception alive is
refreshed.

Allocate the writable metrics in rt6_do_update_pmtu() and return an
error if that fails. Do not insert the new exception then, and release
it. For an exception that is already in use there is nothing to fall
back on, but nothing is claimed either: the next packet too big that
exceeds its MTU makes the update again.

The handlers that update a dst in place do not take a lock either, and
each one decides to lower the MTU from a value it read before. Storing
it unconditionally lets a handler that decided on 1400 overwrite a
1280 that another one stored in between. Lower the MTU with a compare
and exchange, so that it only ever goes down and a smaller value
stored meanwhile is kept.

Fixes: 45e4fd26683c ("ipv6: Only create RTF_CACHE routes after encountering pmtu exception")
Signed-off-by: David Ahern <dahern@nvidia.com>
---
 net/ipv6/route.c | 52 +++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 31ebcf665216..06afb9d5dc2b 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1546,6 +1546,34 @@ static struct net *rt6_exception_net(const struct rt6_info *rt)
 	return container_of(rt->dst.ops, struct net, ipv6.ip6_dst_ops);
 }
 
+/* Lower the MTU in the metrics of @rt to @mtu.
+ *
+ * A dst shares the read-only metrics of its route until it needs its own.
+ * Allocating them can fail, and dst_metric_set() does not say: the PMTU would
+ * be lost.
+ *
+ * Only ever lower it, and with a compare and exchange: PMTU handlers update a
+ * dst in place without a lock, and each decides to lower the MTU from a value
+ * it read earlier, so storing unconditionally could overwrite a smaller value
+ * that another handler stored in between.
+ */
+static int rt6_lower_mtu(struct rt6_info *rt, u32 mtu)
+{
+	u32 *metrics = dst_metrics_write_ptr(&rt->dst);
+	u32 old;
+
+	if (!metrics)
+		return -ENOMEM;
+
+	old = READ_ONCE(metrics[RTAX_MTU - 1]);
+	do {
+		if (old && old <= mtu)
+			break;
+	} while (!try_cmpxchg(&metrics[RTAX_MTU - 1], &old, mtu));
+
+	return 0;
+}
+
 /* Remove rt6_ex from hash table and free the memory
  * Caller must hold rt6_exception_lock
  */
@@ -2913,13 +2941,23 @@ static void rt6_update_expires(struct rt6_info *rt0, int timeout)
 	rt0->rt6i_flags |= RTF_EXPIRES;
 }
 
-static void rt6_do_update_pmtu(struct rt6_info *rt, u32 mtu)
+static int rt6_do_update_pmtu(struct rt6_info *rt, u32 mtu)
 {
 	struct net *net = dev_net(rt->dst.dev);
+	int err;
+
+	/* If the MTU cannot be stored the PMTU would be lost and, for a new
+	 * exception, an exception would be inserted that does not lower
+	 * anything.
+	 */
+	err = rt6_lower_mtu(rt, mtu);
+	if (err)
+		return err;
 
-	dst_metric_set(&rt->dst, RTAX_MTU, mtu);
 	rt->rt6i_flags |= RTF_MODIFIED;
 	rt6_update_expires(rt, READ_ONCE(net->ipv6.sysctl.ip6_rt_mtu_expires));
+
+	return 0;
 }
 
 static bool rt6_cache_allowed_for_pmtu(const struct rt6_info *rt)
@@ -2960,7 +2998,11 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,
 		return;
 
 	if (!rt6_cache_allowed_for_pmtu(rt6)) {
-		rt6_do_update_pmtu(rt6, mtu);
+		/* If the update cannot be made, the next packet too big that
+		 * exceeds this dst's MTU triggers it again
+		 */
+		if (rt6_do_update_pmtu(rt6, mtu))
+			return;
 		/* update rt6_ex->stamp for cache */
 		if (rt6->rt6i_flags & RTF_CACHE)
 			rt6_update_exception_stamp_rt(rt6);
@@ -2998,8 +3040,8 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,
 
 		nrt6 = ip6_rt_cache_alloc(&res, daddr, saddr);
 		if (nrt6) {
-			rt6_do_update_pmtu(nrt6, mtu);
-			if (rt6_insert_exception(nrt6, &res))
+			if (rt6_do_update_pmtu(nrt6, mtu) ||
+			    rt6_insert_exception(nrt6, &res))
 				dst_release_immediate(&nrt6->dst);
 		}
 out_unlock:
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 04/13] ipv6: invalidate the failing dst in ip6_link_failure()
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (2 preceding siblings ...)
  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 ` David Ahern
  2026-12-05 19:20   ` netdev-bot+sashiko
  2026-12-01 17:40 ` [PATCH net-next v3 05/13] ipv6: tell route dumps about exception inserts with a table sequence David Ahern
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

From: David Ahern <dahern@nvidia.com>

When a default route's neighbour fails, ip6_link_failure() writes -1 to
the fn_sernum of the route's node so that users of dsts under that node
look the route up again and let router selection pick another default
router. That invalidates every dst under the node, which for a failing
router that can trigger this for every packet sent through it is far
more than needed.

Invalidate the failing dst only, which for a pcpu dst is one CPU's
copy. Do it by setting the top bit of its sernum: the netns route
generation, which a dst with a non-zero sernum is compared against, is
always positive, so the dst fails the check and its users do the lookup
again, and a pcpu dst that fails it is dropped from its slot and
rebuilt. The rest of sernum is left as it was, and setting the bit is
idempotent, so concurrent invalidators need no lock.

sernum of a published dst can now change under its readers, so read it
with READ_ONCE(), and in rt6_get_cookie() test and return a single
sample. A reader that sees the value before the mark and one that sees
it after both get a non-zero sernum: setting the bit never makes it
zero.

Signed-off-by: David Ahern <dahern@nvidia.com>
---
 include/net/ip6_fib.h | 27 +++++++++++++++++++++++++--
 net/ipv6/route.c      | 18 +++++++++---------
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index 232289b439c3..bfc1895e8591 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -300,9 +300,14 @@ static inline u32 rt6_get_cookie(const struct rt6_info *rt)
 {
 	struct fib6_info *from;
 	u32 cookie = 0;
+	int sernum;
 
-	if (rt->sernum)
-		return rt->sernum;
+	/* Can be stale-marked concurrently (rt6_dst_invalidate()): test and
+	 * return one sample.
+	 */
+	sernum = READ_ONCE(rt->sernum);
+	if (sernum)
+		return sernum;
 
 	rcu_read_lock();
 
@@ -315,6 +320,24 @@ static inline u32 rt6_get_cookie(const struct rt6_info *rt)
 	return cookie;
 }
 
+/* An invalidated dst keeps the generation it was built under in the low
+ * bits, so state derived from it (exceptions) can be stamped with the FIB
+ * state it actually came from. The top bit makes it fail rt6_is_valid():
+ * the netns generation is always positive.
+ */
+#define RT6_SERNUM_STALE	INT_MIN
+
+static inline void rt6_dst_invalidate(struct rt6_info *rt)
+{
+	int sernum = READ_ONCE(rt->sernum);
+
+	/* Do not dirty the cache line of a dst that other CPUs read on the
+	 * fast path when it is already stale.
+	 */
+	if (!(sernum & RT6_SERNUM_STALE))
+		WRITE_ONCE(rt->sernum, sernum | RT6_SERNUM_STALE);
+}
+
 static inline void ip6_rt_put(struct rt6_info *rt)
 {
 	/* dst_release() accepts a NULL parameter.
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 06afb9d5dc2b..5af0f26332ff 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1466,7 +1466,7 @@ static struct rt6_info *ip6_rt_pcpu_alloc(const struct fib6_result *res)
 
 static bool rt6_is_valid(const struct rt6_info *rt6)
 {
-	return rt6->sernum == rt_genid_ipv6(dev_net(rt6->dst.dev));
+	return READ_ONCE(rt6->sernum) == rt_genid_ipv6(dev_net(rt6->dst.dev));
 }
 
 /* It should be called with rcu_read_lock() acquired */
@@ -1476,7 +1476,7 @@ static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res)
 
 	pcpu_rt = this_cpu_read(*res->nh->rt6i_pcpu);
 
-	if (pcpu_rt && pcpu_rt->sernum && !rt6_is_valid(pcpu_rt)) {
+	if (pcpu_rt && READ_ONCE(pcpu_rt->sernum) && !rt6_is_valid(pcpu_rt)) {
 		struct rt6_info *prev, **p;
 
 		p = this_cpu_ptr(res->nh->rt6i_pcpu);
@@ -2855,7 +2855,7 @@ INDIRECT_CALLABLE_SCOPE struct dst_entry *ip6_dst_check(struct dst_entry *dst,
 
 	rt = dst_rt6_info(dst);
 
-	if (rt->sernum)
+	if (READ_ONCE(rt->sernum))
 		return rt6_is_valid(rt) ? dst : NULL;
 
 	rcu_read_lock();
@@ -2912,14 +2912,14 @@ static void ip6_link_failure(struct sk_buff *skb)
 			rt6_remove_exception_rt(rt);
 		} else {
 			struct fib6_info *from;
-			struct fib6_node *fn;
 
+			/* Force sockets using this dst to look the route up
+			 * again; a stale-marked sernum never matches the
+			 * netns generation.
+			 */
 			from = rcu_dereference(rt->from);
-			if (from) {
-				fn = rcu_dereference(from->fib6_node);
-				if (fn && (rt->rt6i_flags & RTF_DEFAULT))
-					WRITE_ONCE(fn->fn_sernum, -1);
-			}
+			if (from && (rt->rt6i_flags & RTF_DEFAULT))
+				rt6_dst_invalidate(rt);
 		}
 		rcu_read_unlock();
 	}
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 05/13] ipv6: tell route dumps about exception inserts with a table sequence
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (3 preceding siblings ...)
  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 ` David Ahern
  2026-12-05 19:20   ` netdev-bot+sashiko
  2026-12-01 17:40 ` [PATCH net-next v3 06/13] ipv6: validate dsts against the netns route generation David Ahern
                   ` (10 subsequent siblings)
  15 siblings, 1 reply; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

From: David Ahern <dahern@nvidia.com>

A route dump that is suspended and later resumed restarts from the
root if the root node's fn_sernum changed, and the exception dump
relies on that happening when an exception is inserted on the root:
rt6_insert_exception() calls fib6_update_sernum(), which among other
things gives the node a new fn_sernum.

That ties dump consistency to what a change to fn_sernum otherwise
means. A fresh fn_sernum can only come from the netns counter, 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 under
tb6_lock when an exception is inserted on the root node, and have
fib6_dump_table() restart when either it or the root's fn_sernum has
changed. The set of inserts a dump notices is the same as before.

Also correct the comment in rt6_nh_dump_exceptions(): only changes to
the root's exceptions are noticed, not those under other nodes, where
a dump suspended in the middle of a route's exceptions can skip or
repeat some of them.

Signed-off-by: David Ahern <dahern@nvidia.com>
---
 include/net/ip6_fib.h |  3 +++
 net/ipv6/ip6_fib.c    | 25 ++++++++++++++++++++++++-
 net/ipv6/route.c      | 15 ++++++++++-----
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index bfc1895e8591..af2a17945011 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -386,6 +386,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;
 };
@@ -419,6 +420,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)
 };
@@ -640,6 +642,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 e1d49897d6ab..4da83c22bbde 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. A dump notices
+ * a changed tree through the root node, so only an exception on the root
+ * needs to be visible. Use a table sequence for that, rather than a fresh
+ * fn_sernum, so that it does not depend on what else a change to fn_sernum
+ * does: fresh values can only come from the netns counter, and a made-up
+ * one could later be issued by the counter to the same node.
+ * 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 5af0f26332ff..836bd7aa05cd 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1832,6 +1832,7 @@ static int rt6_insert_exception(struct rt6_info *nrt,
 	if (!err) {
 		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);
@@ -6125,11 +6126,15 @@ static int rt6_nh_dump_exceptions(struct fib6_nh *nh, void *arg)
 				continue;
 			}
 
-			/* Expiration of entries doesn't bump sernum, insertion
-			 * does. Removal is triggered by insertion, so we can
-			 * rely on the fact that if entries change between two
-			 * partial dumps, this node is scanned again completely,
-			 * see rt6_insert_exception() and fib6_dump_table().
+			/* Expiration of entries doesn't bump anything. An
+			 * insertion on the root node changes the root's
+			 * fn_sernum or tb6_excp_seq, and removal is triggered
+			 * by insertion, so if entries of the root change
+			 * between two partial dumps, the table is scanned
+			 * again, see rt6_insert_exception() and
+			 * fib6_dump_table(). A change under any other node is
+			 * not noticed: a dump suspended in the middle of that
+			 * route's exceptions can skip or repeat some of them.
 			 *
 			 * Count expired entries we go through as handled
 			 * entries that we'll skip next time, in case of partial
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 06/13] ipv6: validate dsts against the netns route generation
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (4 preceding siblings ...)
  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 ` David Ahern
  2026-12-05 19:20   ` netdev-bot+sashiko
  2026-12-01 17:40 ` [PATCH net-next v3 07/13] ipv6: make rt_genid_bump_ipv6() a plain counter increment David Ahern
                   ` (9 subsequent siblings)
  15 siblings, 1 reply; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

From: David Ahern <dahern@nvidia.com>

An rt6_info never carried the fib6 serial number it was created
under. rt6_get_cookie() read fn->fn_sernum through rt->from at the time a
socket, dst_cache or xfrm bundle stored its cookie, so a change that
landed between route lookup and cookie capture was folded into the
cookie and a stale dst looked valid. Only nexthop-object pcpu routes
were stamped at creation, with the same counter.

net->ipv6.fib6_sernum is already the counter that rt_genid_ipv6()
reads and that every FIB change bumps. Stamp every dst with it in
ip6_dst_alloc() and validate with a plain comparison in
ip6_dst_check(); the remaining checks are that the fib6_info is still
in the tree and not expired. rt6_get_cookie() now returns rt->sernum
and fib6_get_cookie_safe() goes away. fn_sernum stays for route dump
consistency.

This covers every holder. Every IPv6 route dst is allocated with
DST_OBSOLETE_FORCE_CHK and stamped at allocation, and holders that
cache a dst (sockets, early demux, dst_cache users, xfrm bundles, SCTP,
IPVS, nf_flowtable) revalidate it through ip6_dst_check(), whose first
test is the generation. The comparison uses the dst's own stamp, not
the cookie the holder captured, so a cookie captured late cannot make
a stale dst look current.

Validity lives in the dst, so a long-lived dst is never re-stamped by
a later lookup: pcpu and exception dsts are shared by every socket and
dst_cache that holds them, and re-stamping would make a stale dst valid
again for all of them. IPv4 does the same: a stale cached route fails
rt_cache_valid() and a new one is allocated, while holders of the old
one keep seeing it as stale. Likewise here:

 - a pcpu dst that fails the check is dropped from the pcpu slot and
   rebuilt by rt6_make_pcpu_route().
 - an exception dst that fails the check is not handed to users as
   their dst. The lookup paths that do that then replace it with a
   current copy that keeps the learned MTU, expiry, redirect gateway
   and flags, so that a FIB change in the netns does not discard every
   learned PMTU and redirect. The copy is stamped like any other dst
   built from the lookup. Callers that only read an exception, not
   hand it out as a dst, still find it whatever its generation: the MTU
   of a FIB lookup in ip6_mtu_from_fib6(), which bpf_fib_lookup() uses
   and which never goes through a dst lookup that would refresh it,
   deleting an exception, and matching a redirect gateway. Hiding it
   from them would make a learned PMTU or redirect disappear from those
   until some packet to that destination refreshed it.
   With source-prefix routes an exception can be keyed by the flow's
   own source address or by the route's source prefix. The exact one is
   found first, and a stale exact one is refreshed in preference to a
   current one under the prefix key, as the exact one would be returned
   if nothing were stale.

   The stale exception is found without rt6_exception_lock, so the
   replacement only goes ahead if it is still the exception for that
   destination once the lock is held, and the state is copied under the
   lock. If another CPU has installed a newer exception, or the
   exception was removed on purpose (aged out, link failure, route
   delete), the copy is dropped and the lookup uses whatever is there
   now: a replacement from an older snapshot must not overwrite the
   newer exception or bring back a deleted one. If the replacement
   cannot be made for lack of memory the stale exception stays, and the
   lookup misses; the next one tries again.

   The replacement is swapped in with hlist_replace_rcu(), not unlinked
   and re-added: nothing invalidates pcpu dsts for a refresh, so a
   lockless lookup that ran in a gap between the two would miss the
   exception and build a pcpu dst that ignores it. The swap also keeps
   the entry's place in its chain, which route dumps count, and the
   bucket depth. A new dst shares the read-only metrics of its route and
   writable ones are allocated on first use, with dst_metric_set()
   silently doing nothing if that fails. The copy gets writable
   metrics up front, so that failing to is treated like any other
   allocation failure instead of replacing the exception with a copy
   that lost its PMTU, and a later merge into it does not have to
   allocate. A stale exception whose MTU is no longer below the route's is
   dropped rather than failing every refresh, unless it is a redirect:
   its PMTU may have been lowered in place and then caught up with by a
   device MTU change, and the gateway is still worth keeping, so only
   the PMTU is forgotten and the copy carries the route's own MTU, as a
   new redirect exception does. The old exception is put
   on the uncached list, not dst_dev_put(): its holders keep a working
   dst until they notice it is stale, and device unregister detaches it.

   If the replacement cannot be made for lack of memory, the lookup
   returns some other dst: a pcpu dst or a clone stamped with the
   current generation, which would bypass the stale exception until the
   next PMTU update, since nothing invalidates pcpu dsts for a refresh.
   The lookup marks the dst it returns stale in that case, so its users
   look the route up, and try the replacement, again.

   An in-place PMTU update of a held exception does not take
   rt6_exception_lock, so it can land on the old dst while a
   replacement is being made, or after it. The identity check cannot
   see that. __ip6_rt_update_pmtu() already follows such an update with
   an update of the exception's stamp, which stays lockless, as before,
   while the updated dst is still the exception in the table, the
   common case. When it is not, that step now takes the lock and merges
   the update into the exception currently in the table (smaller PMTU
   wins, earlier expiry wins, as for an in-place update), so the lock
   orders it against any replacement in progress. A replacement that
   swaps in its copy while the update sees the old dst in the table is
   caught by a barrier pairing: the updater does smp_mb() between the
   update and its lookup, the replacement does smp_mb() after the swap
   and merges into the copy whatever changed on the old dst since it was
   copied. Either the updater finds the copy or the replacement sees the
   update, so the lower PMTU is not lost. Neither path orders the merge
   against a handler updating the current exception in place. Both only
   ever lower the MTU, the merge and rt6_do_update_pmtu(), with the same
   compare and exchange (rt6_lower_mtu()), and the merge lowers the
   expiry the same way: a smaller value stored by one is kept whichever
   order they run in.
   The device MTU change path, which runs under the lock and can also
   raise an exception's PMTU, is not covered by that.

Creating a PMTU or redirect exception must not invalidate every dst
in the namespace, which bumping the netns generation would do: 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. rt6_insert_exception() marks the sernum of the
fib6_nh's pcpu dsts stale, with rt6_dst_invalidate() as
ip6_link_failure() does, instead of calling fib6_update_sernum(), so
their users look the route up once and find the exception. The top
bit, not zero, means the low bits still say which generation the dst
was built under, so that state derived from it can be stamped with that
instead of the generation current at allocation.

That only reaches pcpu slots that are already populated, and the
lookup checks the exception table before it builds a pcpu dst. A
lookup that missed the exception can install its pcpu dst after the
writer scanned the slots, and that dst, stamped with the still-current
generation, would ignore the exception until the next PMTU update. Close
this the way the fib6_destroying handshake in fib6_purge_rt() does: the
writer issues smp_mb() between publishing the exception and reading the
slots, and ip6_pol_route() looks the exception up again for its own
flow after the fully ordered cmpxchg() that installs the pcpu dst.
Whichever side runs second sees the other. The re-check runs only when
a pcpu dst has to be built.

The pcpu invalidation does not reach the RTF_CACHE clone that
ip6_pol_route() makes for FLOWI_FLAG_KNOWN_NH: it is not in rt6i_pcpu and
holders such as the IPVS dest->dst_cache keep it. ip6_dst_check() therefore
also fails an uncached RTF_CACHE dst when its nexthop has an exception for
the dst's destination, so that its holders look the route up and find the
learned PMTU.

Visiting every possible CPU on each exception insert would make a
burst of packet-too-big messages cost the possible CPU count each, on
large systems. Each fib6_nh therefore keeps a cpumask of the CPUs that
installed a pcpu dst since the last invalidation: rt6_make_pcpu_route()
sets its CPU's bit after the install, and the invalidation visits,
tests and clears only those. The per-CPU dst accesses and
invalidations of an insert follow the dsts created rather than the
number of possible CPUs, and a burst of exceptions invalidates each
dst once. Finding the set bits still scans the whole mask, nr_cpu_ids
bits, on every insert that does not replace an exception, which is a
few words even on large systems. The mask is allocated and freed
with the pcpu array, and the handshake above covers it: the installer
orders its mark before the re-check, the writer orders the publish
before reading the mask.

An exception insert no longer changes any fn_sernum, so route dumps
depend on tb6_excp_seq alone for exceptions on the root node, as the
dump patch before this one arranged.

The smp_wmb() in __fib6_update_sernum_upto_root() paired with the
smp_rmb() in fib6_get_cookie_safe(), so that a lockless reader that saw
a new fn_sernum also saw the route inserted before it. That reader is
gone. The remaining fn_sernum readers, the route dumps, take tb6_lock
after reading it and the writers hold it, so drop the barrier.

The reference a pcpu slot or the exception table holds on a dst that
is taken out of it is dropped after a grace period, from a call_rcu()
callback. Lookups with RT6_LOOKUP_F_DST_NOREF rely on RCU to keep the
dst alive, and dropping the reference right away breaks that when the
only other reference is an xfrm bundle's child, since dst_destroy()
releases the child with dst_release_immediate(). This is done for a
stale pcpu dst, for an exception replaced by a refreshed copy, and in
fib6_nh_release_dsts().

Reported-by: Ralf Lici <ralf@mandelbit.com>
Signed-off-by: David Ahern <dahern@nvidia.com>
---
 include/net/ip6_fib.h |  51 +---
 net/ipv6/ip6_fib.c    |  14 +-
 net/ipv6/route.c      | 627 ++++++++++++++++++++++++++++++++++++++----
 3 files changed, 584 insertions(+), 108 deletions(-)

diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index af2a17945011..ef5138ae7075 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -9,6 +9,7 @@
 #ifndef _IP6_FIB_H
 #define _IP6_FIB_H
 
+#include <linux/cpumask.h>
 #include <linux/ipv6_route.h>
 #include <linux/rtnetlink.h>
 #include <linux/spinlock.h>
@@ -152,6 +153,11 @@ struct fib6_nh {
 #endif
 
 	struct rt6_info * __percpu *rt6i_pcpu;
+	/* CPUs that installed a dst in rt6i_pcpu since the last time an
+	 * exception insert invalidated them, so that it does not have to
+	 * look at every possible CPU.
+	 */
+	cpumask_var_t		rt6i_pcpu_dirty;
 	struct rt6_exception_bucket __rcu *rt6i_exception_bucket;
 };
 
@@ -273,51 +279,12 @@ static inline bool fib6_check_expired(const struct fib6_info *f6i)
 	return false;
 }
 
-/* Function to safely get fn->fn_sernum for passed in rt
- * and store result in passed in cookie.
- * Return true if we can get cookie safely
- * Return false if not
- */
-static inline bool fib6_get_cookie_safe(const struct fib6_info *f6i,
-					u32 *cookie)
-{
-	struct fib6_node *fn;
-	bool status = false;
-
-	fn = rcu_dereference(f6i->fib6_node);
-
-	if (fn) {
-		*cookie = READ_ONCE(fn->fn_sernum);
-		/* pairs with smp_wmb() in __fib6_update_sernum_upto_root() */
-		smp_rmb();
-		status = true;
-	}
-
-	return status;
-}
-
 static inline u32 rt6_get_cookie(const struct rt6_info *rt)
 {
-	struct fib6_info *from;
-	u32 cookie = 0;
-	int sernum;
-
-	/* Can be stale-marked concurrently (rt6_dst_invalidate()): test and
-	 * return one sample.
+	/* sernum is the netns route generation the dst was created under;
+	 * ip6_dst_check() compares it to the current one.
 	 */
-	sernum = READ_ONCE(rt->sernum);
-	if (sernum)
-		return sernum;
-
-	rcu_read_lock();
-
-	from = rcu_dereference(rt->from);
-	if (from)
-		fib6_get_cookie_safe(from, &cookie);
-
-	rcu_read_unlock();
-
-	return cookie;
+	return READ_ONCE(rt->sernum);
 }
 
 /* An invalidated dst keeps the generation it was built under in the low
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 4da83c22bbde..266370e15774 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -148,12 +148,12 @@ 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. A dump notices
- * a changed tree through the root node, so only an exception on the root
- * needs to be visible. Use a table sequence for that, rather than a fresh
- * fn_sernum, so that it does not depend on what else a change to fn_sernum
- * does: fresh values can only come from the netns counter, and a made-up
- * one could later be issued by the counter to the same node.
+/* 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)
@@ -1455,8 +1455,6 @@ static void __fib6_update_sernum_upto_root(struct fib6_info *rt,
 	struct fib6_node *fn = rcu_dereference_protected(rt->fib6_node,
 				lockdep_is_held(&rt->fib6_table->tb6_lock));
 
-	/* paired with smp_rmb() in fib6_get_cookie_safe() */
-	smp_wmb();
 	while (fn) {
 		WRITE_ONCE(fn->fn_sernum, sernum);
 		fn = rcu_dereference_protected(fn->parent,
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 836bd7aa05cd..959157896f98 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -115,6 +115,10 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb,
 static struct rt6_info *rt6_find_cached_rt(const struct fib6_result *res,
 					   const struct in6_addr *daddr,
 					   const struct in6_addr *saddr);
+static struct rt6_info *
+rt6_find_cached_rt_refresh(const struct fib6_result *res,
+			   const struct in6_addr *daddr,
+			   const struct in6_addr *saddr, bool *retry);
 
 #ifdef CONFIG_IPV6_ROUTE_INFO
 static struct fib6_info *rt6_add_route_info(struct net *net,
@@ -367,6 +371,7 @@ struct rt6_info *ip6_dst_alloc(struct net *net, struct net_device *dev,
 
 	if (rt) {
 		rt6_info_init(rt);
+		rt->sernum = rt_genid_ipv6(net);
 		atomic_inc(&net->ipv6.rt6_stats->fib_rt_alloc);
 	}
 
@@ -1291,6 +1296,7 @@ INDIRECT_CALLABLE_SCOPE struct rt6_info *ip6_pol_route_lookup(struct net *net,
 	struct fib6_result res = {};
 	struct fib6_node *fn;
 	struct rt6_info *rt;
+	bool retry = false;
 
 	rcu_read_lock();
 	fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
@@ -1318,13 +1324,17 @@ INDIRECT_CALLABLE_SCOPE struct rt6_info *ip6_pol_route_lookup(struct net *net,
 			 fl6->flowi6_oif != 0, skb, flags);
 
 	/* Search through exception table */
-	rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr);
+	rt = rt6_find_cached_rt_refresh(&res, &fl6->daddr, &fl6->saddr,
+					&retry);
 	if (rt) {
 		if (ip6_hold_safe(net, &rt))
 			dst_use_noref(&rt->dst, jiffies);
 	} else {
 do_create:
 		rt = ip6_create_rt_rcu(&res);
+		/* see rt6_find_cached_rt_refresh() */
+		if (retry && rt != net->ipv6.ip6_null_entry)
+			rt6_dst_invalidate(rt);
 	}
 
 out:
@@ -1458,9 +1468,6 @@ static struct rt6_info *ip6_rt_pcpu_alloc(const struct fib6_result *res)
 	ip6_rt_copy_init(pcpu_rt, res);
 	pcpu_rt->rt6i_flags |= RTF_PCPU;
 
-	if (f6i->nh)
-		pcpu_rt->sernum = rt_genid_ipv6(dev_net(dev));
-
 	return pcpu_rt;
 }
 
@@ -1469,6 +1476,29 @@ static bool rt6_is_valid(const struct rt6_info *rt6)
 	return READ_ONCE(rt6->sernum) == rt_genid_ipv6(dev_net(rt6->dst.dev));
 }
 
+static void rt6_dst_release_rcu(struct rcu_head *head)
+{
+	struct dst_entry *dst = container_of(head, struct dst_entry, rcu_head);
+
+	dst_release(dst);
+}
+
+/* Drop a table's (pcpu slot, exception table) reference to a dst that was
+ * just unpublished. Lookups with RT6_LOOKUP_F_DST_NOREF only rely on RCU to
+ * keep the dst alive, so the reference has to outlive the readers that may
+ * have found it. Dropping it right away breaks that when the only other
+ * reference is an xfrm bundle's child: dst_destroy() releases the child with
+ * dst_release_immediate(), freeing it under such a reader.
+ *
+ * dst->rcu_head is free to use here: it is only needed once the refcount
+ * drops to zero, which cannot happen before this reference is gone, and
+ * dst_release() may reuse it from inside this callback.
+ */
+static void rt6_dst_release_deferred(struct rt6_info *rt)
+{
+	call_rcu(&rt->dst.rcu_head, rt6_dst_release_rcu);
+}
+
 /* It should be called with rcu_read_lock() acquired */
 static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res)
 {
@@ -1476,7 +1506,11 @@ static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res)
 
 	pcpu_rt = this_cpu_read(*res->nh->rt6i_pcpu);
 
-	if (pcpu_rt && READ_ONCE(pcpu_rt->sernum) && !rt6_is_valid(pcpu_rt)) {
+	/* A dst stamped with an older genid stays stale for everyone still
+	 * holding it, as in IPv4. Never re-stamp it; drop it and build a
+	 * new one.
+	 */
+	if (pcpu_rt && !rt6_is_valid(pcpu_rt)) {
 		struct rt6_info *prev, **p;
 
 		p = this_cpu_ptr(res->nh->rt6i_pcpu);
@@ -1490,7 +1524,7 @@ static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res)
 			 * detaches it like any other uncached dst.
 			 */
 			rt6_uncached_list_add(prev);
-			dst_release(&prev->dst);
+			rt6_dst_release_deferred(prev);
 		}
 
 		pcpu_rt = NULL;
@@ -1523,6 +1557,13 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net,
 		return prev;
 	}
 
+	/* Tell fib6_nh_invalidate_pcpu() there is a dst to invalidate on this
+	 * CPU. The cmpxchg() above orders the install before the mark.
+	 */
+	cpumask_set_cpu(smp_processor_id(), res->nh->rt6i_pcpu_dirty);
+	/* Order the mark before the exception re-check in ip6_pol_route() */
+	smp_mb__after_atomic();
+
 	if (res->f6i->fib6_destroying) {
 		struct fib6_info *from;
 
@@ -1749,18 +1790,163 @@ struct rt6_exception_bucket *fib6_nh_get_excptn_bucket(const struct fib6_nh *nh,
 	return bucket;
 }
 
-static int rt6_insert_exception(struct rt6_info *nrt,
-				const struct fib6_result *res)
+/* 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(struct fib6_nh *nh)
+{
+	int cpu;
+
+	if (!nh->rt6i_pcpu)
+		return;
+
+	/* The exception was published before this call. Pairs with the
+	 * cmpxchg() and the cpumask update in rt6_make_pcpu_route(): either
+	 * we see the CPU of a pcpu dst installed by a lookup that missed the
+	 * exception, or that lookup's re-check in ip6_pol_route() sees the
+	 * exception.
+	 *
+	 * Only CPUs that installed a dst since the last invalidation are
+	 * visited, so the dst accesses and invalidations follow the dsts
+	 * created, not the number of possible CPUs. Finding the set bits
+	 * still scans the whole mask, nr_cpu_ids bits, on every call. A burst
+	 * of exceptions invalidates each dst once.
+	 */
+	smp_mb();
+
+	rcu_read_lock();
+	for_each_cpu(cpu, nh->rt6i_pcpu_dirty) {
+		struct rt6_info *pcpu_rt;
+
+		if (!cpumask_test_and_clear_cpu(cpu, nh->rt6i_pcpu_dirty))
+			continue;
+
+		pcpu_rt = READ_ONCE(*per_cpu_ptr(nh->rt6i_pcpu, cpu));
+		if (pcpu_rt)
+			rt6_dst_invalidate(pcpu_rt);
+	}
+	rcu_read_unlock();
+}
+
+/* Carry a PMTU or expiry learned in place on @rt over to @cur. Caller holds
+ * rt6_exception_lock.
+ *
+ * That lock does not keep @cur from being updated in place at the same time:
+ * a PMTU handler that holds @cur as its dst writes the metric and the expiry
+ * without it. Both only ever lower them, with a compare and exchange (see
+ * rt6_lower_mtu()), so that neither overwrites what the other stored with a
+ * value that is not lower, in whichever order they run.
+ */
+static void rt6_exception_merge(struct rt6_info *cur, const struct rt6_info *rt)
+{
+	u32 mtu = dst_metric_raw(&rt->dst, RTAX_MTU);
+
+	/* @cur has writable metrics if it was made by a refresh or by a PMTU
+	 * update. A redirect exception that was neither may not, and then
+	 * there is nothing to do if allocating them fails: the update still
+	 * applies to the dst that got it, and the next packet too big that
+	 * exceeds the larger MTU of @cur updates it.
+	 */
+	if (mtu)
+		rt6_lower_mtu(cur, mtu);
+
+	/* As dst_set_expires() does, never extend an expiry */
+	if (rt->rt6i_flags & RTF_EXPIRES) {
+		unsigned long expires = READ_ONCE(rt->dst.expires);
+		unsigned long old = READ_ONCE(cur->dst.expires);
+
+		do {
+			if (old && !time_before(expires, old))
+				break;
+		} while (!try_cmpxchg(&cur->dst.expires, &old, expires));
+
+		cur->rt6i_flags |= RTF_EXPIRES;
+	}
+	cur->rt6i_flags |= rt->rt6i_flags & RTF_MODIFIED;
+}
+
+/* Copy what an exception has learned from @old into its replacement @nrt.
+ * Caller holds rt6_exception_lock, so @old is not replaced or removed under
+ * us.
+ */
+static int rt6_exception_copy_state(struct rt6_info *nrt,
+				    const struct rt6_info *old)
+{
+	u32 *metrics;
+
+	/* Take the flags as they are, not just what was learned on top of the
+	 * route's: a redirect exception, for one, does not carry the route's
+	 * flags at all (see rt6_do_redirect()). The copy then looks exactly
+	 * like the exception that lookups through this nexthop returned
+	 * before it went stale.
+	 */
+	nrt->rt6i_flags = old->rt6i_flags;
+	nrt->rt6i_gateway = old->rt6i_gateway;
+
+	/* A new dst shares the metrics of its route, which are read-only;
+	 * writable ones are allocated when first needed, and the caller of
+	 * dst_metric_set() is not told if that fails. Allocate them here, even
+	 * if what is learned is just the route's own value, so that failing
+	 * to is seen before the exception is replaced, rather than as a PMTU
+	 * that is silently lost, and so that a later in-place update or merge
+	 * into this exception does not have to allocate. The caller did so
+	 * before it took the lock, so this finds them in place.
+	 */
+	metrics = dst_metrics_write_ptr(&nrt->dst);
+	if (!metrics)
+		return -ENOMEM;
+	metrics[RTAX_MTU - 1] = dst_metric_raw(&old->dst, RTAX_MTU);
+
+	if (old->rt6i_flags & RTF_EXPIRES)
+		WRITE_ONCE(nrt->dst.expires, READ_ONCE(old->dst.expires));
+
+	return 0;
+}
+
+/* @old: @nrt replaces this stale exception, which it is a copy of. Nothing
+ * new applies to dsts cached on the nexthop, so they are not invalidated.
+ *
+ * @old was found without the lock. If it is no longer the exception for this
+ * destination, a newer one was installed or it was removed on purpose (aged
+ * out, link failure, route delete); either way the copy is out of date, so
+ * return -EEXIST instead of overwriting or resurrecting it. The state is
+ * copied here, under the lock, so the copy is current at the moment of
+ * replacement.
+ */
+static int __rt6_insert_exception(struct rt6_info *nrt,
+				  const struct fib6_result *res,
+				  struct rt6_info *old)
 {
 	struct net *net = dev_net(nrt->dst.dev);
 	struct rt6_exception_bucket *bucket;
 	struct fib6_info *f6i = res->f6i;
+	struct rt6_exception_bucket *old_bucket = NULL;
 	struct rt6_exception *rt6_ex, *new_ex;
 	struct in6_addr *src_key = NULL;
 	struct fib6_nh *nh = res->nh;
+	unsigned long old_expires = 0;
+	u32 old_mtu = 0;
 	int max_depth;
 	int err = 0;
 
+	/* Allocate what the lock would otherwise be held across: this lock is
+	 * shared by every nexthop of every netns, and a refresh runs for each
+	 * stale exception after a FIB change. Nothing is published until the
+	 * swap below, and what is not used is freed after the unlock.
+	 */
+	new_ex = kzalloc_obj(*new_ex, GFP_ATOMIC);
+	if (!new_ex)
+		return -ENOMEM;
+
+	/* A copy of an exception carries writable metrics, see
+	 * rt6_exception_copy_state(). nrt is not visible to anyone yet.
+	 */
+	if (old && !dst_metrics_write_ptr(&nrt->dst)) {
+		kfree(new_ex);
+		return -ENOMEM;
+	}
+
 	spin_lock_bh(&rt6_exception_lock);
 
 	if (f6i->fib6_destroying) {
@@ -1771,6 +1957,11 @@ static int rt6_insert_exception(struct rt6_info *nrt,
 	bucket = rcu_dereference_protected(nh->rt6i_exception_bucket,
 					  lockdep_is_held(&rt6_exception_lock));
 	if (!bucket) {
+		/* Nothing to replace */
+		if (old) {
+			err = -EEXIST;
+			goto out;
+		}
 		bucket = kzalloc_objs(*bucket, FIB6_EXCEPTION_BUCKET_SIZE,
 				      GFP_ATOMIC);
 		if (!bucket) {
@@ -1790,27 +1981,88 @@ static int rt6_insert_exception(struct rt6_info *nrt,
 	if (f6i->fib6_src.plen)
 		src_key = &nrt->rt6i_src.addr;
 #endif
+	if (old) {
+		old_bucket = bucket;
+		rt6_ex = __rt6_find_exception_spinlock(&old_bucket,
+						       &nrt->rt6i_dst.addr,
+						       src_key);
+		if (!rt6_ex || rt6_ex->rt6i != old) {
+			err = -EEXIST;
+			goto out;
+		}
+		/* Before the copy: an in-place update of old that lands in
+		 * between is then both in the copy and seen as a change after
+		 * the swap, which merges it again, harmlessly.
+		 */
+		old_mtu = dst_metric_raw(&old->dst, RTAX_MTU);
+		old_expires = READ_ONCE(old->dst.expires);
+		err = rt6_exception_copy_state(nrt, old);
+		if (err)
+			goto out;
+	}
+
 	/* rt6_mtu_change() might lower mtu on f6i.
 	 * Only insert this exception route if its mtu
 	 * is less than f6i's mtu value.
 	 */
 	if (dst_metric_raw(&nrt->dst, RTAX_MTU) >= fib6_mtu(res)) {
-		err = -EINVAL;
-		goto out;
-	}
-
-	/* Allocate the new entry before the one it replaces is touched, so
-	 * that running out of memory leaves what was learned in place.
-	 */
-	new_ex = kzalloc_obj(*new_ex, GFP_ATOMIC);
-	if (!new_ex) {
-		err = -ENOMEM;
-		goto out;
+		if (old && (old->rt6i_flags & RTF_DYNAMIC)) {
+			/* A redirect whose PMTU was lowered in place and has
+			 * since stopped lowering anything, e.g. after a device
+			 * MTU change: the gateway is still worth keeping. Forget
+			 * only the PMTU and carry the route's own MTU, as a new
+			 * redirect exception would. The metrics are writable
+			 * already (rt6_exception_copy_state()), so this cannot
+			 * fail.
+			 */
+			dst_metric_set(&nrt->dst, RTAX_MTU, res->f6i->fib6_pmtu);
+		} else {
+			/* A stale exception that no longer lowers anything
+			 * would fail every refresh from here on: drop it.
+			 */
+			if (old)
+				rt6_remove_exception(old_bucket, rt6_ex);
+			err = -EINVAL;
+			goto out;
+		}
 	}
 
 	new_ex->rt6i = nrt;
 	new_ex->stamp = jiffies;
 
+	if (old) {
+		/* rt6_ex, found above, is old's entry. Swap in place: lockless
+		 * lookups see either the old or the new exception and never
+		 * a gap in which they would miss it and build a pcpu dst that
+		 * ignores it, nothing invalidates pcpu dsts for a refresh, and
+		 * the position in the chain, which route dumps count, and the
+		 * depth do not change.
+		 *
+		 * Holders of old find out that it is stale when they next
+		 * check it, so keep it working rather than dst_dev_put() it.
+		 * Device unregister detaches it like any other uncached dst.
+		 */
+		hlist_replace_rcu(&rt6_ex->hlist, &new_ex->hlist);
+
+		/* An in-place PMTU update of old does not take the lock, and
+		 * one that saw old still in the table does not merge (see
+		 * fib6_nh_update_exception()). Pairs with smp_mb() there:
+		 * either it sees nrt and merges into it under the lock, or
+		 * this sees its update and merges it here. Only a change
+		 * since the copy is merged, so the PMTU a redirect copy
+		 * dropped above is not brought back.
+		 */
+		smp_mb();
+		if (dst_metric_raw(&old->dst, RTAX_MTU) != old_mtu ||
+		    READ_ONCE(old->dst.expires) != old_expires)
+			rt6_exception_merge(nrt, old);
+
+		rt6_uncached_list_add(old);
+		rt6_dst_release_deferred(old);
+		kfree_rcu(rt6_ex, rcu);
+		goto out;
+	}
+
 	rt6_ex = __rt6_find_exception_spinlock(&bucket, &nrt->rt6i_dst.addr,
 					       src_key);
 	if (rt6_ex)
@@ -1828,10 +2080,14 @@ 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) {
+	/* new_ex is in the table on success only */
+	if (err)
+		kfree(new_ex);
+
+	if (!err && !old) {
+		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);
@@ -1841,6 +2097,12 @@ static int rt6_insert_exception(struct rt6_info *nrt,
 	return err;
 }
 
+static int rt6_insert_exception(struct rt6_info *nrt,
+				const struct fib6_result *res)
+{
+	return __rt6_insert_exception(nrt, res, NULL);
+}
+
 static void fib6_nh_flush_exceptions(struct fib6_nh *nh, struct fib6_info *from)
 {
 	struct rt6_exception_bucket *bucket;
@@ -1890,9 +2152,10 @@ void rt6_flush_exceptions(struct fib6_info *f6i)
 /* Find cached rt in the hash table inside passed in rt
  * Caller has to hold rcu_read_lock()
  */
-static struct rt6_info *rt6_find_cached_rt(const struct fib6_result *res,
-					   const struct in6_addr *daddr,
-					   const struct in6_addr *saddr)
+static struct rt6_info *__rt6_find_cached_rt(const struct fib6_result *res,
+					     const struct in6_addr *daddr,
+					     const struct in6_addr *saddr,
+					     struct rt6_info **stale)
 {
 	const struct in6_addr *src_key = NULL;
 	struct rt6_exception_bucket *bucket;
@@ -1918,12 +2181,31 @@ static struct rt6_info *rt6_find_cached_rt(const struct fib6_result *res,
 	bucket = fib6_nh_get_excptn_bucket(res->nh, NULL);
 	rt6_ex = __rt6_find_exception_rcu(&bucket, daddr, src_key);
 
-	if (rt6_ex && !rt6_check_expired(rt6_ex->rt6i))
+	if (rt6_ex && !rt6_check_expired(rt6_ex->rt6i)) {
 		ret = rt6_ex->rt6i;
+		/* Callers that hand the exception to users as their dst pass
+		 * @stale: a stale one must not be re-stamped, other holders
+		 * must keep seeing it as stale, so it is a miss for them and is
+		 * returned in @stale to be replaced. Callers that only read it
+		 * (MTU of a FIB lookup, route delete, redirect gateway match)
+		 * get it whatever its generation: what it has learned is still
+		 * right.
+		 */
+		if (stale && !rt6_is_valid(ret)) {
+			*stale = ret;
+			ret = NULL;
+		}
+	}
 
 #ifdef CONFIG_IPV6_SUBTREES
-	/* Use fib6_src as src_key and redo lookup */
-	if (!ret && src_key && src_key != &res->f6i->fib6_src.addr) {
+	/* Use fib6_src as src_key and redo lookup. Not if a stale exception
+	 * was found for the flow's own source address: without the refresh
+	 * the exact match is what the lookup returns, and a current one under
+	 * the prefix key must not take its place, which would also keep the
+	 * stale one from ever being refreshed.
+	 */
+	if (!ret && !(stale && *stale) && src_key &&
+	    src_key != &res->f6i->fib6_src.addr) {
 		src_key = &res->f6i->fib6_src.addr;
 		goto find_ex;
 	}
@@ -1932,6 +2214,86 @@ static struct rt6_info *rt6_find_cached_rt(const struct fib6_result *res,
 	return ret;
 }
 
+static struct rt6_info *rt6_find_cached_rt(const struct fib6_result *res,
+					   const struct in6_addr *daddr,
+					   const struct in6_addr *saddr)
+{
+	return __rt6_find_cached_rt(res, daddr, saddr, NULL);
+}
+
+/* Replace a stale exception with a current copy of it.
+ *
+ * Validity is a property of the dst and the dsts held by sockets and
+ * dst_caches must stay stale, so @old cannot be re-stamped. Its content (the
+ * learned PMTU or redirect gateway) is still right though: it lives on the
+ * nexthop this lookup just selected, and nexthop or route removal flushes it.
+ * Dropping it instead would make every FIB change in the netns discard all
+ * learned PMTUs and redirects.
+ *
+ * The copy is stamped like any dst built from this result. Caller holds
+ * rcu_read_lock().
+ */
+static struct rt6_info *rt6_refresh_exception(const struct fib6_result *res,
+					      struct rt6_info *old,
+					      bool *nomem)
+{
+	const struct in6_addr *saddr = NULL;
+	struct rt6_info *nrt;
+	int err;
+
+#ifdef CONFIG_IPV6_SUBTREES
+	if (old->rt6i_src.plen)
+		saddr = &old->rt6i_src.addr;
+#endif
+	nrt = ip6_rt_cache_alloc(res, &old->rt6i_dst.addr, saddr);
+	if (!nrt) {
+		*nomem = true;
+		return NULL;
+	}
+
+	err = __rt6_insert_exception(nrt, res, old);
+	if (!err)
+		return nrt;
+
+	dst_release_immediate(&nrt->dst);
+
+	/* @old was replaced or removed since we found it: use what is there
+	 * now, which is a miss if it was removed.
+	 */
+	if (err == -EEXIST)
+		return __rt6_find_cached_rt(res, &old->rt6i_dst.addr, saddr,
+					    NULL);
+
+	if (err == -ENOMEM)
+		*nomem = true;
+	return NULL;
+}
+
+/* rt6_find_cached_rt() for the lookup paths that hand the result to users:
+ * a stale exception is replaced by a current copy instead of being lost.
+ *
+ * If the replacement could not be made for lack of memory, the exception is
+ * still there, stale, and the caller will return some other dst, which
+ * would be valid and bypass it until the next PMTU update. *@retry is set
+ * so the caller can mark that dst stale, which makes its users look the
+ * route up, and try the replacement, again.
+ *
+ * Caller holds rcu_read_lock().
+ */
+static struct rt6_info *
+rt6_find_cached_rt_refresh(const struct fib6_result *res,
+			   const struct in6_addr *daddr,
+			   const struct in6_addr *saddr, bool *retry)
+{
+	struct rt6_info *stale = NULL, *rt;
+
+	rt = __rt6_find_cached_rt(res, daddr, saddr, &stale);
+	if (!rt && stale)
+		rt = rt6_refresh_exception(res, stale, retry);
+
+	return rt;
+}
+
 /* Remove the passed in cached rt from the hash table that contains it */
 static int fib6_nh_remove_exception(const struct fib6_nh *nh, int plen,
 				    const struct rt6_info *rt)
@@ -2014,8 +2376,24 @@ static int rt6_remove_exception_rt(struct rt6_info *rt)
 					from->fib6_src.plen, rt);
 }
 
-/* Find rt6_ex which contains the passed in rt cache and
- * refresh its stamp
+/* @rt, a dst some user holds, was just updated in place (PMTU, expiry). Refresh
+ * the stamp of the exception for its destination and make sure that exception
+ * carries the update.
+ *
+ * The exception in the table is not necessarily @rt: a stale one is replaced
+ * by a copy (see rt6_refresh_exception()) while the old dst stays with its
+ * holders, and the in-place update does not take rt6_exception_lock.
+ *
+ * While @rt is still the exception in the table, which is almost always,
+ * only the stamp is refreshed, without the lock. The smp_mb() pairs with the
+ * one in __rt6_insert_exception() after a refresh swaps in its copy: either
+ * the lookup here finds the copy, or the refresh sees this update of @rt and
+ * merges it into the copy. Once @rt has been replaced, the lock orders this
+ * after any later replacement in progress, and the update is merged into
+ * whatever exception is current. Either way a PMTU or expiry learned from
+ * @rt is not lost to the copy.
+ *
+ * Caller holds rcu_read_lock().
  */
 static void fib6_nh_update_exception(const struct fib6_nh *nh, int plen,
 				     const struct rt6_info *rt)
@@ -2024,7 +2402,6 @@ static void fib6_nh_update_exception(const struct fib6_nh *nh, int plen,
 	struct rt6_exception_bucket *bucket;
 	struct rt6_exception *rt6_ex;
 
-	bucket = fib6_nh_get_excptn_bucket(nh, NULL);
 #ifdef CONFIG_IPV6_SUBTREES
 	/* rt6i_src.plen != 0 indicates 'from' is in subtree
 	 * and exception table is indexed by a hash of
@@ -2035,9 +2412,31 @@ static void fib6_nh_update_exception(const struct fib6_nh *nh, int plen,
 	if (plen)
 		src_key = &rt->rt6i_src.addr;
 #endif
+
+	/* Order the update of @rt before the lookup, see above */
+	smp_mb();
+
+	bucket = fib6_nh_get_excptn_bucket(nh, NULL);
 	rt6_ex = __rt6_find_exception_rcu(&bucket, &rt->rt6i_dst.addr, src_key);
-	if (rt6_ex)
+	if (!rt6_ex)
+		return;
+	if (rt6_ex->rt6i == rt) {
+		rt6_ex->stamp = jiffies;
+		return;
+	}
+
+	spin_lock_bh(&rt6_exception_lock);
+
+	bucket = fib6_nh_get_excptn_bucket(nh, &rt6_exception_lock);
+	rt6_ex = __rt6_find_exception_spinlock(&bucket, &rt->rt6i_dst.addr,
+					       src_key);
+	if (rt6_ex) {
 		rt6_ex->stamp = jiffies;
+		if (rt6_ex->rt6i != rt)
+			rt6_exception_merge(rt6_ex->rt6i, rt);
+	}
+
+	spin_unlock_bh(&rt6_exception_lock);
 }
 
 struct fib6_nh_match_arg {
@@ -2315,6 +2714,7 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
 	struct fib6_result res = {};
 	struct rt6_info *rt = NULL;
 	bool have_oif_match;
+	bool retry = false;
 	int strict = 0;
 
 	WARN_ON_ONCE((flags & RT6_LOOKUP_F_DST_NOREF) &&
@@ -2336,7 +2736,8 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
 	fib6_select_path(net, &res, fl6, oif, have_oif_match, skb, strict);
 
 	/*Search through exception table */
-	rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr);
+	rt = rt6_find_cached_rt_refresh(&res, &fl6->daddr, &fl6->saddr,
+					&retry);
 	if (rt) {
 		goto out;
 	} else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) &&
@@ -2349,6 +2750,10 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
 		rt = ip6_rt_cache_alloc(&res, &fl6->daddr, NULL);
 
 		if (rt) {
+			/* see rt6_find_cached_rt_refresh() */
+			if (retry)
+				rt6_dst_invalidate(rt);
+
 			/* 1 refcnt is taken during ip6_rt_cache_alloc().
 			 * As rt6_uncached_list_add() does not consume refcnt,
 			 * this refcnt is always returned to the caller even
@@ -2364,9 +2769,34 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
 		local_bh_disable();
 		rt = rt6_get_pcpu_route(&res);
 
-		if (!rt)
+		if (!rt) {
 			rt = rt6_make_pcpu_route(net, &res);
 
+			/* The exception lookup above may have raced with
+			 * rt6_insert_exception(), whose pcpu invalidation
+			 * skips CPUs that have not marked an installed dst.
+			 * rt6_make_pcpu_route() orders the install and the mark
+			 * before this lookup, so a miss here means the writer's
+			 * invalidation sees our dst and marks it stale.
+			 */
+			if (rt) {
+				struct rt6_info *excp;
+
+				excp = rt6_find_cached_rt_refresh(&res,
+								  &fl6->daddr,
+								  &fl6->saddr,
+								  &retry);
+				if (excp) {
+					rt = excp;
+					retry = false;
+				}
+			}
+		}
+
+		/* see rt6_find_cached_rt_refresh() */
+		if (retry && rt)
+			rt6_dst_invalidate(rt);
+
 		local_bh_enable();
 	}
 out:
@@ -2807,27 +3237,18 @@ struct dst_entry *ip6_blackhole_route(struct net *net, struct dst_entry *dst_ori
  *	Destination cache support functions
  */
 
-static bool fib6_check(struct fib6_info *f6i, u32 cookie)
+static bool fib6_check(struct fib6_info *f6i)
 {
-	u32 rt_cookie = 0;
-
-	if (!fib6_get_cookie_safe(f6i, &rt_cookie) || rt_cookie != cookie)
-		return false;
-
-	if (fib6_check_expired(f6i))
+	if (!rcu_access_pointer(f6i->fib6_node))
 		return false;
 
-	return true;
+	return !fib6_check_expired(f6i);
 }
 
 static struct dst_entry *rt6_check(struct rt6_info *rt,
-				   struct fib6_info *from,
-				   u32 cookie)
+				   struct fib6_info *from)
 {
-	u32 rt_cookie = 0;
-
-	if (!from || !fib6_get_cookie_safe(from, &rt_cookie) ||
-	    rt_cookie != cookie)
+	if (!from || !rcu_access_pointer(from->fib6_node))
 		return NULL;
 
 	if (rt6_check_expired(rt))
@@ -2837,16 +3258,89 @@ static struct dst_entry *rt6_check(struct rt6_info *rt,
 }
 
 static struct dst_entry *rt6_dst_from_check(struct rt6_info *rt,
-					    struct fib6_info *from,
-					    u32 cookie)
+					    struct fib6_info *from)
 {
 	if (!__rt6_check_expired(rt) &&
 	    READ_ONCE(rt->dst.obsolete) == DST_OBSOLETE_FORCE_CHK &&
-	    fib6_check(from, cookie))
+	    fib6_check(from))
 		return &rt->dst;
 	return NULL;
 }
 
+struct rt6_clone_nh_arg {
+	const struct rt6_info *rt;
+	struct fib6_info *from;
+	const struct in6_addr *saddr;
+};
+
+/* Has this nexthop an exception for the destination of the clone in
+ * @_arg? Nonzero if so, which ends a walk of a group.
+ */
+static int rt6_clone_nh_excp(struct fib6_nh *nh, void *_arg)
+{
+	struct rt6_clone_nh_arg *arg = _arg;
+	const struct rt6_info *rt = arg->rt;
+	struct fib6_result res = {
+		.f6i = arg->from,
+		.nh = nh,
+	};
+	struct rt6_info *ex;
+
+	if (nh->fib_nh_dev != dst_dev_rcu(&rt->dst))
+		return 0;
+
+	/* A clone without a gateway was made from a member without one. A
+	 * member of the group that has one, on the same device, is not where
+	 * its exceptions are. A dst with a gateway may have got it from a
+	 * redirect, which is not the member's, so any member will do for it.
+	 */
+	if (!(rt->rt6i_flags & RTF_GATEWAY) && nh->fib_nh_gw_family)
+		return 0;
+
+	if (!rcu_access_pointer(nh->rt6i_exception_bucket))
+		return 0;
+
+	ex = __rt6_find_cached_rt(&res, &rt->rt6i_dst.addr, arg->saddr, NULL);
+
+	return ex && ex != rt;
+}
+
+/* An RTF_CACHE dst on the uncached list is not an exception of the table: it
+ * is a clone that ip6_pol_route() made for FLOWI_FLAG_KNOWN_NH, or an
+ * exception that was replaced or removed. A PMTU or redirect learned for its
+ * destination after it was made is an exception on the nexthop, which
+ * invalidates the pcpu dsts but not this one, and ip6_dst_check() would
+ * otherwise keep passing it. Report whether such an exception exists, so the
+ * holder does the lookup again and gets it.
+ *
+ * The dst does not say which member of a nexthop group it was made from, so
+ * look at every member that it can have come from: the ones on its device
+ * and, if it has no gateway, without one. Several can match, and an exception
+ * on one that was not the source only makes the holder look the route up
+ * again, which is harmless. Missing the source's would not be.
+ *
+ * Caller holds rcu_read_lock().
+ */
+static bool rt6_uncached_clone_superseded(const struct rt6_info *rt,
+					  struct fib6_info *from)
+{
+	struct rt6_clone_nh_arg arg = {
+		.rt = rt,
+		.from = from,
+	};
+
+#ifdef CONFIG_IPV6_SUBTREES
+	if (rt->rt6i_src.plen)
+		arg.saddr = &rt->rt6i_src.addr;
+#endif
+
+	if (from->nh)
+		return nexthop_for_each_fib6_nh(from->nh, rt6_clone_nh_excp,
+						&arg);
+
+	return rt6_clone_nh_excp(from->fib6_nh, &arg);
+}
+
 INDIRECT_CALLABLE_SCOPE struct dst_entry *ip6_dst_check(struct dst_entry *dst,
 							u32 cookie)
 {
@@ -2856,8 +3350,11 @@ INDIRECT_CALLABLE_SCOPE struct dst_entry *ip6_dst_check(struct dst_entry *dst,
 
 	rt = dst_rt6_info(dst);
 
-	if (READ_ONCE(rt->sernum))
-		return rt6_is_valid(rt) ? dst : NULL;
+	/* Any FIB change bumps the netns generation, which invalidates
+	 * every dst created under an older one.
+	 */
+	if (!rt6_is_valid(rt))
+		return NULL;
 
 	rcu_read_lock();
 
@@ -2869,10 +3366,16 @@ INDIRECT_CALLABLE_SCOPE struct dst_entry *ip6_dst_check(struct dst_entry *dst,
 	from = rcu_dereference(rt->from);
 
 	if (from && (rt->rt6i_flags & RTF_PCPU ||
-	    unlikely(rt->dst.rt_uncached_list)))
-		dst_ret = rt6_dst_from_check(rt, from, cookie);
-	else
-		dst_ret = rt6_check(rt, from, cookie);
+	    unlikely(rt->dst.rt_uncached_list))) {
+		if (unlikely(rt->dst.rt_uncached_list &&
+			     (rt->rt6i_flags & RTF_CACHE) &&
+			     rt6_uncached_clone_superseded(rt, from)))
+			dst_ret = NULL;
+		else
+			dst_ret = rt6_dst_from_check(rt, from);
+	} else {
+		dst_ret = rt6_check(rt, from);
+	}
 
 	rcu_read_unlock();
 
@@ -3754,6 +4257,13 @@ int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
 		goto out;
 	}
 
+	if (!zalloc_cpumask_var(&fib6_nh->rt6i_pcpu_dirty, gfp_flags)) {
+		free_percpu(fib6_nh->rt6i_pcpu);
+		fib6_nh->rt6i_pcpu = NULL;
+		err = -ENOMEM;
+		goto out;
+	}
+
 	fib6_nh->fib_nh_dev = dev;
 	fib6_nh->fib_nh_oif = dev->ifindex;
 	err = 0;
@@ -3788,6 +4298,7 @@ void fib6_nh_release(struct fib6_nh *fib6_nh)
 	rcu_read_unlock();
 
 	free_percpu(fib6_nh->rt6i_pcpu);
+	free_cpumask_var(fib6_nh->rt6i_pcpu_dirty);
 
 	fib_nh_common_release(&fib6_nh->nh_common);
 }
@@ -3808,7 +4319,7 @@ void fib6_nh_release_dsts(struct fib6_nh *fib6_nh)
 		pcpu_rt = xchg(ppcpu_rt, NULL);
 		if (pcpu_rt) {
 			dst_dev_put(&pcpu_rt->dst);
-			dst_release(&pcpu_rt->dst);
+			rt6_dst_release_deferred(pcpu_rt);
 		}
 	}
 }
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 07/13] ipv6: make rt_genid_bump_ipv6() a plain counter increment
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (5 preceding siblings ...)
  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
  2026-12-05 19:20   ` netdev-bot+sashiko
  2026-12-01 17:40 ` [PATCH net-next v3 08/13] nexthop: factor out nh_has_f6i() David Ahern
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

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)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 08/13] nexthop: factor out nh_has_f6i()
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (6 preceding siblings ...)
  2026-12-01 17:40 ` [PATCH net-next v3 07/13] ipv6: make rt_genid_bump_ipv6() a plain counter increment David Ahern
@ 2026-12-01 17:40 ` David Ahern
  2026-12-01 17:40 ` [PATCH net-next v3 09/13] nexthop: bump the IPv6 route generation on group changes David Ahern
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

From: David Ahern <dahern@nvidia.com>

nh_rt_cache_flush() open codes a locked check of whether any IPv6
routes use a nexthop. Move it into a helper, placed ahead of
remove_nexthop_from_groups(), so the next patch can use it there as
well.

No functional change.

Signed-off-by: David Ahern <dahern@nvidia.com>
---
 net/ipv4/nexthop.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 42e55b5a755e..53431fe7d328 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -2109,6 +2109,17 @@ remove_nh_grp_entry(struct net *net, struct nh_grp_entry *nhge,
 	return false;
 }
 
+static bool nh_has_f6i(struct nexthop *nh)
+{
+	bool have_f6i;
+
+	spin_lock_bh(&nh->lock);
+	have_f6i = !list_empty(&nh->f6i_list);
+	spin_unlock_bh(&nh->lock);
+
+	return have_f6i;
+}
+
 static bool __must_check
 remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
 			   struct nl_info *nlinfo)
@@ -2248,16 +2259,12 @@ static void nh_rt_cache_flush(struct net *net, struct nexthop *nh,
 			      struct nexthop *replaced_nh)
 {
 	struct nh_group *nhg;
-	bool have_f6i;
 	int i;
 
 	if (!list_empty(&nh->fi_list))
 		rt_cache_flush(net);
 
-	spin_lock_bh(&nh->lock);
-	have_f6i = !list_empty(&nh->f6i_list);
-	spin_unlock_bh(&nh->lock);
-	if (have_f6i)
+	if (nh_has_f6i(nh))
 		rt_genid_bump_ipv6(net);
 
 	/* if an IPv6 group was replaced, we have to release all old
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 09/13] nexthop: bump the IPv6 route generation on group changes
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (7 preceding siblings ...)
  2026-12-01 17:40 ` [PATCH net-next v3 08/13] nexthop: factor out nh_has_f6i() David Ahern
@ 2026-12-01 17:40 ` David Ahern
  2026-12-05 19:20   ` netdev-bot+sashiko
  2026-12-01 17:40 ` [PATCH net-next v3 10/13] ipv6: stamp dsts with the generation sampled before the FIB lookup David Ahern
                   ` (6 subsequent siblings)
  15 siblings, 1 reply; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

From: David Ahern <dahern@nvidia.com>

IPv6 dsts are invalidated by bumping the netns route generation, but
two nexthop object changes did not do so:

 - Replacing a nexthop that is a member of a group only bumped if the
   member itself had IPv6 routes, not when routes used a group
   containing it.
 - Removing a member from a group republishes the group array without
   any bump, so dsts built from the old group stayed valid.

Bump in both cases when IPv6 routes use the nexthop, directly or
through a group.

Signed-off-by: David Ahern <dahern@nvidia.com>
---
 net/ipv4/nexthop.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 53431fe7d328..7cf496589f4f 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -2120,6 +2120,21 @@ static bool nh_has_f6i(struct nexthop *nh)
 	return have_f6i;
 }
 
+/* true if IPv6 routes use @nh directly or through a group containing it */
+static bool nh_used_by_f6i(struct nexthop *nh)
+{
+	struct nh_grp_entry *nhge;
+
+	if (nh_has_f6i(nh))
+		return true;
+
+	list_for_each_entry(nhge, &nh->grp_list, nh_list)
+		if (nh_has_f6i(nhge->nh_parent))
+			return true;
+
+	return false;
+}
+
 static bool __must_check
 remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
 			   struct nl_info *nlinfo)
@@ -2127,6 +2142,7 @@ remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
 	struct nh_grp_entry *nhge, *tmp;
 	LIST_HEAD(deferred_free);
 	bool need_flush = false;
+	bool have_f6i = false;
 
 	/* If there is nothing to do, let's avoid the costly call to
 	 * synchronize_net()
@@ -2134,13 +2150,19 @@ remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
 	if (list_empty(&nh->grp_list))
 		return false;
 
-	list_for_each_entry_safe(nhge, tmp, &nh->grp_list, nh_list)
+	list_for_each_entry_safe(nhge, tmp, &nh->grp_list, nh_list) {
+		have_f6i |= nh_has_f6i(nhge->nh_parent);
 		need_flush |= remove_nh_grp_entry(net, nhge, nlinfo,
 						  &deferred_free);
+	}
 
 	/* make sure all see the newly published array before releasing rtnl */
 	synchronize_net();
 
+	/* a group lost a member: dsts built from the old group are stale */
+	if (have_f6i)
+		rt_genid_bump_ipv6(net);
+
 	/* 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);
@@ -2264,7 +2286,8 @@ static void nh_rt_cache_flush(struct net *net, struct nexthop *nh,
 	if (!list_empty(&nh->fi_list))
 		rt_cache_flush(net);
 
-	if (nh_has_f6i(nh))
+	/* dsts are validated against the netns route generation */
+	if (nh_used_by_f6i(nh))
 		rt_genid_bump_ipv6(net);
 
 	/* if an IPv6 group was replaced, we have to release all old
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 10/13] ipv6: stamp dsts with the generation sampled before the FIB lookup
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (8 preceding siblings ...)
  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 ` David Ahern
  2026-12-05 19:21   ` netdev-bot+sashiko
  2026-12-01 17:40 ` [PATCH net-next v3 11/13] selftests: net: pmtu: check that a deleted cached exception stays deleted David Ahern
                   ` (5 subsequent siblings)
  15 siblings, 1 reply; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

From: David Ahern <dahern@nvidia.com>

A dst is stamped with the netns route generation in ip6_dst_alloc(),
which runs after the FIB has been read. A route change that lands
between the lookup and the allocation is folded into the stamp: the
dst was built from the old tree but carries the new generation, so
ip6_dst_check() accepts it and it can keep bypassing the new route
indefinitely.

Sample the generation before the FIB is walked, carry it in
struct fib6_result and stamp every dst built from that result with it.
Writers bump the generation after the route change is visible, so a
lookup that read the old tree cannot have sampled the new generation;
the resulting dst fails ip6_dst_check() as soon as the change is
published. Use an acquire read for the sample so the FIB reads are not
reordered before it.

The sample is taken in fib6_table_lookup(), ip6_pol_route_lookup() and
__ip6_route_redirect(). Exceptions created from an existing dst in
__ip6_rt_update_pmtu() and rt6_do_redirect() inherit that dst's stamp
instead of the current generation, taken with rt6_dst_sernum() so that
a dst already marked stale still passes on the generation it was built
under. The copy that replaces a stale exception in
rt6_refresh_exception() is stamped from the lookup result too; every
caller samples, and a debug warning catches one that does not. Dsts
allocated without a lookup result keep the stamp taken in
ip6_dst_alloc().

A lookup can also return a cached dst that a later lookup built:
between the sample and reading the pcpu slot, a lookup on the same CPU
(softirq, preemption, migration) can run after a FIB change and
install a pcpu dst stamped with the newer generation for the route
this lookup selected, and an exception can be refreshed by another CPU
in the same way. Such a dst passes the validity checks, but the
decision it is returned for predates the change. ip6_pol_route() makes
a dst whose stamp differs from its sample fail ip6_dst_check(), so its
users look the route up again. This also covers callers that use
ip6_pol_route() directly, such as seg6, which caches the result in a
dst_cache.

The sample is taken for one table. A lookup that reads several, the
local table and then the main one, or those the rules select, decides
from all of them: a route that is added to a table that was already
read, and missed, while a later one is read is not part of the
decision, but the dst of the later table is stamped after the change
and would look current. fib6_rule_lookup() therefore samples before
the first table, and if the dst it returns carries a newer stamp, a
change landed in between and the dst is made to fail ip6_dst_check()
so that its users look the route up again. That only happens when the
generation moved during the lookup.

Reported-by: Ralf Lici <ralf@mandelbit.com>
Signed-off-by: David Ahern <dahern@nvidia.com>
---
 include/net/ip6_fib.h       | 11 +++++++++++
 include/net/net_namespace.h | 10 ++++++++++
 net/ipv6/fib6_rules.c       | 33 ++++++++++++++++++++++++++++++---
 net/ipv6/route.c            | 30 +++++++++++++++++++++++++++++-
 4 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index ef5138ae7075..1c70176751d5 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -231,6 +231,11 @@ struct fib6_result {
 	u32			fib6_flags;
 	u8			fib6_type;
 	struct rt6_info		*rt6;
+	/* Route generation sampled before the FIB was read. Dsts built
+	 * from this result are stamped with it, not with the generation
+	 * at allocation time. 0 means not sampled.
+	 */
+	int			sernum;
 };
 
 #define for_each_fib6_node_rt_rcu(fn)					\
@@ -305,6 +310,12 @@ static inline void rt6_dst_invalidate(struct rt6_info *rt)
 		WRITE_ONCE(rt->sernum, sernum | RT6_SERNUM_STALE);
 }
 
+/* The generation @rt was built under, whether or not it is still valid */
+static inline int rt6_dst_sernum(const struct rt6_info *rt)
+{
+	return READ_ONCE(rt->sernum) & ~RT6_SERNUM_STALE;
+}
+
 static inline void ip6_rt_put(struct rt6_info *rt)
 {
 	/* dst_release() accepts a NULL parameter.
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index f39baf51bcc5..31ffac7baf73 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -557,6 +557,16 @@ static inline int rt_genid_ipv6(const struct net *net)
 	return atomic_read(&net->ipv6.fib6_sernum);
 }
 
+/* Sample the generation before walking the FIB. Writers bump it after the
+ * route change is visible, so a lookup that sees the old tree cannot sample
+ * the new generation: whatever dst it builds carries a generation that
+ * fails ip6_dst_check() once the change lands.
+ */
+static inline int rt_genid_ipv6_sample(const struct net *net)
+{
+	return atomic_read_acquire(&net->ipv6.fib6_sernum);
+}
+
 /* Invalidate every cached IPv6 dst in @net. Returns the new generation,
  * which is never 0.
  */
diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c
index 7efb0515b5c8..8b64b5d44e18 100644
--- a/net/ipv6/fib6_rules.c
+++ b/net/ipv6/fib6_rules.c
@@ -96,10 +96,37 @@ int fib6_lookup(struct net *net, int oif, struct flowi6 *fl6,
 EXPORT_SYMBOL_GPL(fib6_lookup);
 #endif
 
+/* A dst that a table lookup returns is stamped with the generation sampled
+ * before that table was read, so a change that lands after the read cannot
+ * be folded into the stamp. A lookup that reads several tables, the local
+ * one and then the main one, or those the rules select, makes its decision
+ * from all of them. A route that is added to a table that was already read,
+ * and missed, while a later one is being read is not part of that decision,
+ * but the dst of the later table is stamped after the change and would look
+ * current. Sample before the first table, and if the dst carries a newer
+ * stamp a change landed in between: make it fail ip6_dst_check(), so that
+ * its users look the route up again.
+ */
+static struct dst_entry *fib6_rule_lookup_done(struct dst_entry *dst,
+					       int sernum)
+{
+	struct rt6_info *rt = dst_rt6_info(dst);
+
+	/* The static null, prohibit and blackhole entries are not made from a
+	 * route and not stamped
+	 */
+	if (rcu_access_pointer(rt->from) && rt6_dst_sernum(rt) != sernum)
+		rt6_dst_invalidate(rt);
+
+	return dst;
+}
+
 struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
 				   const struct sk_buff *skb,
 				   int flags, pol_lookup_t lookup)
 {
+	int sernum = rt_genid_ipv6_sample(net);
+
 	if (net->ipv6.fib6_has_custom_rules) {
 		struct fib6_result res = {};
 		struct fib_lookup_arg arg = {
@@ -116,19 +143,19 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
 				 flowi6_to_flowi(fl6), flags, &arg);
 
 		if (res.rt6)
-			return &res.rt6->dst;
+			return fib6_rule_lookup_done(&res.rt6->dst, sernum);
 	} else {
 		struct rt6_info *rt;
 
 		rt = pol_lookup_func(lookup,
 			     net, net->ipv6.fib6_local_tbl, fl6, skb, flags);
 		if (rt != net->ipv6.ip6_null_entry && rt->dst.error != -EAGAIN)
-			return &rt->dst;
+			return fib6_rule_lookup_done(&rt->dst, sernum);
 		ip6_rt_put_flags(rt, flags);
 		rt = pol_lookup_func(lookup,
 			     net, net->ipv6.fib6_main_tbl, fl6, skb, flags);
 		if (rt->dst.error != -EAGAIN)
-			return &rt->dst;
+			return fib6_rule_lookup_done(&rt->dst, sernum);
 		ip6_rt_put_flags(rt, flags);
 	}
 
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 959157896f98..8df141363e12 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1214,6 +1214,12 @@ static void ip6_rt_copy_init(struct rt6_info *rt, const struct fib6_result *res)
 	rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL;
 	ip6_rt_init_dst(rt, res);
 
+	/* Pair the dst with the generation the FIB was read under, so a
+	 * change between the lookup and this allocation is not folded in.
+	 */
+	if (res->sernum)
+		rt->sernum = res->sernum;
+
 	rt->rt6i_dst = f6i->fib6_dst;
 	rt->rt6i_flags = res->fib6_flags;
 	if (nh->fib_nh_gw_family) {
@@ -1299,6 +1305,7 @@ INDIRECT_CALLABLE_SCOPE struct rt6_info *ip6_pol_route_lookup(struct net *net,
 	bool retry = false;
 
 	rcu_read_lock();
+	res.sernum = rt_genid_ipv6_sample(net);
 	fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
 restart:
 	res.f6i = rcu_dereference(fn->leaf);
@@ -2230,7 +2237,10 @@ static struct rt6_info *rt6_find_cached_rt(const struct fib6_result *res,
  * Dropping it instead would make every FIB change in the netns discard all
  * learned PMTUs and redirects.
  *
- * The copy is stamped like any dst built from this result. Caller holds
+ * The copy is stamped with the generation sampled before the FIB was read,
+ * like any dst built from this result, so @res must carry that sample:
+ * without it the copy would be stamped when it is allocated and could look
+ * current although the FIB changed after the lookup. Caller holds
  * rcu_read_lock().
  */
 static struct rt6_info *rt6_refresh_exception(const struct fib6_result *res,
@@ -2241,6 +2251,8 @@ static struct rt6_info *rt6_refresh_exception(const struct fib6_result *res,
 	struct rt6_info *nrt;
 	int err;
 
+	DEBUG_NET_WARN_ON_ONCE(!res->sernum);
+
 #ifdef CONFIG_IPV6_SUBTREES
 	if (old->rt6i_src.plen)
 		saddr = &old->rt6i_src.addr;
@@ -2685,6 +2697,7 @@ int fib6_table_lookup(struct net *net, struct fib6_table *table, int oif,
 {
 	struct fib6_node *fn, *saved_fn;
 
+	res->sernum = rt_genid_ipv6_sample(net);
 	fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
 	saved_fn = fn;
 
@@ -2800,6 +2813,17 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
 		local_bh_enable();
 	}
 out:
+	/* A cached dst, pcpu or exception, can have been built or refreshed
+	 * by a lookup that ran after a FIB change landed behind our sample:
+	 * it is stamped with the newer generation and passes
+	 * rt6_get_pcpu_route() and the exception lookup, but our decision
+	 * predates that change. Make it fail ip6_dst_check() so that its
+	 * users look the route up again, as fib6_rule_lookup_done() does
+	 * across tables; this also covers callers that bypass that wrapper.
+	 */
+	if (rt && rt6_dst_sernum(rt) != res.sernum)
+		rt6_dst_invalidate(rt);
+
 	if (!rt)
 		rt = net->ipv6.ip6_null_entry;
 	if (!(flags & RT6_LOOKUP_F_DST_NOREF))
@@ -3521,6 +3545,8 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,
 
 		res.fib6_flags = res.f6i->fib6_flags;
 		res.fib6_type = res.f6i->fib6_type;
+		/* derived from @rt6: it is only as current as that dst */
+		res.sernum = rt6_dst_sernum(rt6);
 
 		if (res.f6i->nh) {
 			struct fib6_nh_match_arg arg = {
@@ -3700,6 +3726,7 @@ INDIRECT_CALLABLE_SCOPE struct rt6_info *__ip6_route_redirect(struct net *net,
 	 */
 
 	rcu_read_lock();
+	res.sernum = rt_genid_ipv6_sample(net);
 	fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
 restart:
 	for_each_fib6_node_rt_rcu(fn) {
@@ -4925,6 +4952,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu
 
 	res.fib6_flags = res.f6i->fib6_flags;
 	res.fib6_type = res.f6i->fib6_type;
+	res.sernum = rt6_dst_sernum(rt);
 	nrt = ip6_rt_cache_alloc(&res, &msg->dest, NULL);
 	if (!nrt)
 		goto out;
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 11/13] selftests: net: pmtu: check that a deleted cached exception stays deleted
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (9 preceding siblings ...)
  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 ` David Ahern
  2026-12-01 17:40 ` [PATCH net-next v3 12/13] selftests: net: fib_tests: Add stale pcpu test David Ahern
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

From: David Ahern <dahern@nvidia.com>

Add a test that learns a PMTU from a packet too big message, changes
the FIB with a route that has nothing to do with the destination, and
deletes the cached exception without looking the destination up in
between. After a FIB change the exception's dst is stale, and a lookup
that handed it out would replace it with a current copy: deleting it
must work on a stale exception too, and nothing may then bring it back.

Check that neither a route lookup nor a packet that fits, which looks
the route up as well, creates the exception again, and that a packet
that exceeds the PMTU does, through a new packet too big message. The
cache is dumped to see the exception, as that does not look the
destination up and so does not refresh it.

The test is run again with nexthop objects like the other exception
tests, which takes the deletion through the nexthop path.

Signed-off-by: David Ahern <dahern@nvidia.com>
---
 tools/testing/selftests/net/pmtu.sh | 90 +++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/tools/testing/selftests/net/pmtu.sh b/tools/testing/selftests/net/pmtu.sh
index c7cd271714ef..5e44ff3a6515 100755
--- a/tools/testing/selftests/net/pmtu.sh
+++ b/tools/testing/selftests/net/pmtu.sh
@@ -198,6 +198,14 @@
 # - pmtu_ipv6_route_change
 #	Same as above but with IPv6
 #
+# - pmtu_ipv6_cached_del
+#	Use the same topology as in pmtu_ipv6. Learn a PMTU from a packet too big
+#	message, change the FIB with an unrelated route add and, without looking
+#	the destination up in between, delete the cached exception. Check that
+#	neither a route lookup nor a packet that does not exceed the PMTU
+#	brings the exception back, and that a packet that does exceed it
+#	creates a new one
+#
 # - pmtu_ipv4_mp_exceptions
 #	Use the same topology as in pmtu_ipv4, but add routeable addresses
 #	on host A and B on lo reachable via both routers. Host A and B
@@ -272,6 +280,7 @@ tests="
 	list_flush_ipv6_exception	ipv6: list and flush cached exceptions	1
 	pmtu_ipv4_route_change		ipv4: PMTU exception w/route replace	1
 	pmtu_ipv6_route_change		ipv6: PMTU exception w/route replace	1
+	pmtu_ipv6_cached_del		ipv6: delete a cached PMTU exception after a FIB change	1
 	pmtu_ipv4_mp_exceptions		ipv4: PMTU multipath nh exceptions	1"
 
 # Addressing and routing for tests with routers: four network segments, with
@@ -2377,6 +2386,87 @@ test_pmtu_ipv6_route_change() {
 	test_pmtu_ipvX_route_change 6
 }
 
+# Is there a cached exception for ${2} in the namespace ${1}? Dumping the cache
+# does not look the destination up, so it does not touch the exception
+cached_exception_exists() {
+	ns_cmd="${1}"
+	dst="${2}"
+
+	${ns_cmd} ip -oneline -6 route list cache | grep -qw -- "${dst}"
+}
+
+test_pmtu_ipv6_cached_del() {
+	setup namespaces routing || return $ksft_skip
+	trace "${ns_a}"  veth_A-R1    "${ns_r1}" veth_R1-A \
+	      "${ns_r1}" veth_R1-B    "${ns_b}"  veth_B-R1 \
+	      "${ns_a}"  veth_A-R2    "${ns_r2}" veth_R2-A \
+	      "${ns_r2}" veth_R2-B    "${ns_b}"  veth_B-R2
+
+	dst="${prefix6}:${b_r1}::1"
+
+	# Set up initial MTU values
+	mtu "${ns_a}"  veth_A-R1 2000
+	mtu "${ns_r1}" veth_R1-A 2000
+	mtu "${ns_r1}" veth_R1-B 1400
+	mtu "${ns_b}"  veth_B-R1 1400
+
+	mtu "${ns_a}"  veth_A-R2 2000
+	mtu "${ns_r2}" veth_R2-A 2000
+	mtu "${ns_r2}" veth_R2-B 1500
+	mtu "${ns_b}"  veth_B-R2 1500
+
+	# Learn a PMTU from a packet too big message
+	run_cmd ${ns_a} ${ping6} -q -M want -i 0.1 -w 1 -s 1800 ${dst}
+
+	pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
+	check_pmtu_value "1400" "${pmtu}" "exceeding MTU" || return 1
+
+	# Change the FIB with a route that has nothing to do with ${dst}. Any
+	# FIB change makes the cached dsts of the namespace stale. Do not look
+	# ${dst} up from here to the deletion: that would refresh the
+	# exception
+	run_cmd ${ns_a} ip -6 route add unreachable "${prefix6}:ff::/64"
+
+	if ! cached_exception_exists "${ns_a}" ${dst}; then
+		err "  PMTU exception disappeared after an unrelated route add"
+		return 1
+	fi
+
+	# Delete the cached exception
+	run_cmd ${ns_a} ip -6 route flush cached ${dst}
+
+	if cached_exception_exists "${ns_a}" ${dst}; then
+		err "  PMTU exception still there after deleting it"
+		return 1
+	fi
+
+	# A lookup must not bring it back
+	run_cmd ${ns_a} ip -6 route get ${dst}
+
+	if cached_exception_exists "${ns_a}" ${dst}; then
+		err "  PMTU exception came back after a route lookup"
+		return 1
+	fi
+
+	# Neither must a packet that fits, which looks the route up as well
+	run_cmd ${ns_a} ${ping6} -q -c 1 -w 1 -s 1000 ${dst}
+
+	pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
+	check_pmtu_value "" "${pmtu}" "deleting the exception and a lookup" || return 1
+
+	if cached_exception_exists "${ns_a}" ${dst}; then
+		err "  PMTU exception came back after a packet that fits"
+		return 1
+	fi
+
+	# A packet that exceeds the PMTU does, through a new packet too big
+	# message. This is what learning it again looks like
+	run_cmd ${ns_a} ${ping6} -q -M want -i 0.1 -w 1 -s 1800 ${dst}
+
+	pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
+	check_pmtu_value "1400" "${pmtu}" "exceeding MTU after the deletion" || return 1
+}
+
 test_pmtu_ipv4_mp_exceptions() {
 	setup namespaces routing multipath || return $ksft_skip
 
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 12/13] selftests: net: fib_tests: Add stale pcpu test
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (10 preceding siblings ...)
  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 ` David Ahern
  2026-12-05 19:21   ` netdev-bot+sashiko
  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
                   ` (3 subsequent siblings)
  15 siblings, 1 reply; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

From: David Ahern <dahern@nvidia.com>

Avoid regression with stale pcpu route entries and add a selftest
that covers the regression fixed by
    8f34e53b60b3 ("ipv6: Use global sernum for dst validation with nexthop objects")

Signed-off-by: David Ahern <dahern@nvidia.com>
---
 tools/testing/selftests/net/fib_tests.sh | 53 +++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index d7ac3c727f70..dc2ac5d7f29b 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -14,7 +14,7 @@ TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \
        ipv4_mpath_list ipv6_mpath_list ipv4_mpath_balance ipv6_mpath_balance \
        ipv4_mpath_balance_preferred ipv4_mpath_oif ipv4_mpath_oif_nh \
        ipv4_mpath_oif_vrf ipv6_mpath_oif ipv6_mpath_oif_nh ipv6_mpath_oif_vrf \
-       fib6_ra_to_static fib6_temp_addr_renewal"
+       fib6_ra_to_static fib6_temp_addr_renewal ipv6_nh_pcpu_stale"
 
 VERBOSE=0
 PAUSE_ON_FAIL=no
@@ -3228,6 +3228,56 @@ ipv6_mpath_oif_vrf_test()
 	cleanup
 }
 
+ipv6_nh_pcpu_stale_test()
+{
+	local cpu
+
+	echo
+	echo "IPv6 nexthop object stale pcpu dst test"
+
+	if [ ! -x "$(command -v taskset)" ]; then
+		echo "SKIP: taskset not installed"
+		return $ksft_skip
+	fi
+
+	if [ $(nproc) -lt 2 ]; then
+		echo "SKIP: pcpu test requires multiple cpus"
+		return $ksft_skip
+	fi
+
+	setup
+
+	set -e
+	setup_ns ns2
+	$IP link add veth1 type veth peer name veth2 netns $ns2
+	$IP link set veth1 up
+	$IP -6 address add 2001:db8:10::1/64 dev veth1 nodad
+	ip -netns $ns2 link set lo up
+	ip -netns $ns2 address add 2001:db8:11::1/128 dev lo
+	ip netns exec $ns2 sysctl -qw net.ipv6.conf.all.forwarding=1
+	ip -netns $ns2 link set veth2 up
+	ip -netns $ns2 -6 address add 2001:db8:10::2/64 dev veth2 nodad
+
+	$IP -6 nexthop add id 100 via 2001:db8:10::2 dev veth1
+	$IP -6 route add 2001:db8:11::1/128 nhid 100
+	set +e
+
+	# create a pcpu dst entry on cpu 0
+	taskset -a -c 0 $IP -6 route get 2001:db8:11::1 &> /dev/null
+
+	# re-add the route entry
+	$IP -6 route del 2001:db8:11::1
+	$IP -6 route add 2001:db8:11::1/128 nhid 100
+
+	# cached dst on cpu 0 must have been invalidated
+	for cpu in 0 1; do
+		taskset -a -c $cpu $IP -6 route get 2001:db8:11::1 &> /dev/null
+		log_test $? 0 "Route get on cpu $cpu after route re-add"
+	done
+
+	cleanup
+}
+
 ################################################################################
 # usage
 
@@ -3322,6 +3372,7 @@ do
 	ipv6_mpath_oif_vrf)		ipv6_mpath_oif_vrf_test;;
 	fib6_ra_to_static)		fib6_ra_to_static;;
 	fib6_temp_addr_renewal)		fib6_temp_addr_renewal;;
+	ipv6_nh_pcpu_stale)		ipv6_nh_pcpu_stale_test;;
 
 	help) echo "Test names: $TESTS"; exit 0;;
 	esac
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH net-next v3 13/13] selftests: net: ipvs: check a PMTU learned after the DR route was cached
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (11 preceding siblings ...)
  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 ` David Ahern
  2026-12-05 19:21   ` netdev-bot+sashiko
  2026-12-01 17:43 ` [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation netdev-bot+sinfo
                   ` (2 subsequent siblings)
  15 siblings, 1 reply; 31+ messages in thread
From: David Ahern @ 2026-12-01 17:40 UTC (permalink / raw)
  To: netdev
  Cc: dsahern, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern, Claude Sonnet 5.5

From: David Ahern <dahern@nvidia.com>

In IPv6 DR mode the director keeps its route to the real server in
dest->dst_cache and revalidates it with ip6_dst_check(). The route is a
FLOWI_FLAG_KNOWN_NH clone that is not cached on the nexthop, so a PMTU
learned for the real server afterwards is not applied to it unless
ip6_dst_check() notices the new exception.

Cache the route with a small datagram, give the director a PMTU for the
real server with a forged packet too big message, then send a datagram
that exceeds it. The director must answer with a packet too big message,
which the client learns as a PMTU for the service.

Add the IPv6 and UDP ipvs options the test needs to the config.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: David Ahern <dahern@nvidia.com>
---
 tools/testing/selftests/net/netfilter/config  |  2 +
 tools/testing/selftests/net/netfilter/ipvs.sh | 81 +++++++++++++++++++
 2 files changed, 83 insertions(+)

diff --git a/tools/testing/selftests/net/netfilter/config b/tools/testing/selftests/net/netfilter/config
index 629b2b29ed1a..d237f8651111 100644
--- a/tools/testing/selftests/net/netfilter/config
+++ b/tools/testing/selftests/net/netfilter/config
@@ -36,7 +36,9 @@ CONFIG_IPV6=y
 CONFIG_IPV6_MULTIPLE_TABLES=y
 CONFIG_IPV6_TUNNEL=m
 CONFIG_IP_VS=m
+CONFIG_IP_VS_IPV6=y
 CONFIG_IP_VS_PROTO_TCP=y
+CONFIG_IP_VS_PROTO_UDP=y
 CONFIG_IP_VS_RR=m
 CONFIG_MACVLAN=m
 CONFIG_NAMESPACES=y
diff --git a/tools/testing/selftests/net/netfilter/ipvs.sh b/tools/testing/selftests/net/netfilter/ipvs.sh
index 9c9d5b38ab71..556ce071035e 100755
--- a/tools/testing/selftests/net/netfilter/ipvs.sh
+++ b/tools/testing/selftests/net/netfilter/ipvs.sh
@@ -40,6 +40,12 @@ readonly dip_v4=172.16.0.1
 readonly rip_v4=172.16.0.2
 readonly sip_v4=10.0.0.3
 
+readonly vip_v6=fd00:3::1
+readonly cip_v6=fd00:1::2
+readonly gip_v6=fd00:1::1
+readonly dip_v6=fd00:2::1
+readonly rip_v6=fd00:2::2
+
 readonly infile="$(mktemp)"
 readonly outfile="$(mktemp)"
 readonly datalen=32
@@ -54,6 +60,7 @@ fi
 
 checktool "ipvsadm -v" "run test without ipvsadm"
 checktool "socat -h" "run test without socat"
+checktool "python3 -c pass" "run test without python3"
 
 setup() {
 	setup_ns ns0 ns1 ns2
@@ -169,6 +176,74 @@ test_tun() {
 	test_service
 }
 
+# Send one UDP datagram of ${2} bytes from the client to the IPv6 service and
+# keep the socket open for a moment, so that a packet too big message for it
+# is accepted.
+udp_send_v6() {
+	ip netns exec "${ns0}" python3 -c '
+import socket, sys, time
+s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
+s.bind((sys.argv[1], 0))
+s.sendto(b"x" * int(sys.argv[3]), (sys.argv[2], int(sys.argv[4])))
+time.sleep(0.5)
+' "${cip_v6}" "${vip_v6}" "${1}" "${port}"
+}
+
+# Send a packet too big message with MTU ${1} for ${dip_v6} -> ${rip_v6} from
+# the real server to the director. The director sees what a router on the path
+# to the real server would tell it, and learns a PMTU exception for ${rip_v6}.
+send_ptb_v6() {
+	ip netns exec "${ns2}" python3 -c '
+import socket, struct, sys
+src, dst, mtu = sys.argv[1], sys.argv[2], int(sys.argv[3])
+inner = struct.pack("!IHBB", 6 << 28, 8, 58, 64)
+inner += socket.inet_pton(socket.AF_INET6, src)
+inner += socket.inet_pton(socket.AF_INET6, dst)
+inner += struct.pack("!BBHHH", 128, 0, 0, 0, 0)
+msg = struct.pack("!BBHI", 2, 0, 0, mtu) + inner
+s = socket.socket(socket.AF_INET6, socket.SOCK_RAW, socket.IPPROTO_ICMPV6)
+s.sendto(msg, (src, 0))
+' "${dip_v6}" "${rip_v6}" "${1}"
+}
+
+# The director keeps the route to a real server for as long as it passes
+# ip6_dst_check(). In DR mode that is a FLOWI_FLAG_KNOWN_NH clone, which is not
+# cached on the nexthop. A PMTU learned for the real server after the route was
+# cached must still reach it: packets that exceed the PMTU must get a packet
+# too big message back to the client.
+test_dr_v6_pmtu() {
+	ip netns exec "${ns0}" ip addr add "${cip_v6}/64" dev br0 nodad
+	ip netns exec "${ns0}" ip route add "${vip_v6}/128" via "${gip_v6}" dev br0
+
+	ip netns exec "${ns1}" ip addr add "${gip_v6}/64" dev veth10 nodad
+	ip netns exec "${ns1}" ip addr add "${dip_v6}/64" dev veth12 nodad
+	ip netns exec "${ns1}" ip addr add "${vip_v6}/128" dev lo nodad
+	ip netns exec "${ns1}" ipvsadm -A -u "[${vip_v6}]:${port}" -s rr
+	ip netns exec "${ns1}" ipvsadm -a -u "[${vip_v6}]:${port}" \
+		-r "[${rip_v6}]:${port}" -g
+
+	ip netns exec "${ns2}" ip addr add "${rip_v6}/64" dev veth21 nodad
+	ip netns exec "${ns2}" ip addr add "${vip_v6}/128" dev lo nodad
+
+	# Let the director cache its route to the real server
+	udp_send_v6 100
+
+	send_ptb_v6 1280
+	sleep 0.2
+	if ! ip netns exec "${ns1}" ip -6 route get "${rip_v6}" | grep -q "mtu 1280"; then
+		echo "FAIL: director did not learn the PMTU of the real server"
+		return 1
+	fi
+
+	# A datagram that exceeds the PMTU must be answered with a packet too
+	# big message, which gives the client a PMTU for the service
+	udp_send_v6 1400
+	if ! ip netns exec "${ns0}" ip -6 route get "${vip_v6}" | grep -q "mtu 1280"; then
+		echo "FAIL: director kept using a route that bypasses the learned PMTU"
+		return 1
+	fi
+}
+
 run_tests() {
 	local errors=
 
@@ -190,6 +265,12 @@ run_tests() {
 	test_tun
 	errors=$(( $errors + $? ))
 
+	echo "Testing IPv6 DR mode PMTU..."
+	cleanup
+	setup
+	test_dr_v6_pmtu
+	errors=$(( $errors + $? ))
+
 	return $errors
 }
 
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (12 preceding siblings ...)
  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 ` netdev-bot+sinfo
  2026-12-02  9:45 ` Ralf Lici
  2026-12-03 15:34 ` Ido Schimmel
  15 siblings, 0 replies; 31+ messages in thread
From: netdev-bot+sinfo @ 2026-12-01 17:43 UTC (permalink / raw)
  To: David Ahern
  Cc: netdev, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (13 preceding siblings ...)
  2026-12-01 17:43 ` [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation netdev-bot+sinfo
@ 2026-12-02  9:45 ` Ralf Lici
  2026-12-03 15:34 ` Ido Schimmel
  15 siblings, 0 replies; 31+ messages in thread
From: Ralf Lici @ 2026-12-02  9:45 UTC (permalink / raw)
  To: David Ahern; +Cc: netdev, idosch, davem, edumazet, kuba, pabeni, horms, ja

Retested v3 with the same reproducers, including the deferred release in
6/13. All of them passs, as do fib_tests ipv6_nh_pcpu_stale and
pmtu_ipv6_cached_del, with no warnings in dmesg.

Tested-by: Ralf Lici <ralf@mandelbit.com>

-- 
Ralf Lici
Mandelbit Srl

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 01/13] ipv6: allocate the exception entry before removing the one it replaces
  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-02 16:02   ` Ido Schimmel
  0 siblings, 0 replies; 31+ messages in thread
From: Ido Schimmel @ 2026-12-02 16:02 UTC (permalink / raw)
  To: David Ahern
  Cc: netdev, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

On Tue, Dec 01, 2026 at 10:40:02AM -0700, David Ahern wrote:
> From: David Ahern <dahern@nvidia.com>
> 
> rt6_insert_exception() unlinks the existing exception for a
> destination before it allocates, with GFP_ATOMIC, the table entry for
> its replacement. If that allocation fails, what was learned (a
> reduced PMTU or a redirect gateway) is already gone and the caller gets
> -ENOMEM, so traffic falls back to the route's own MTU and gateway.
> 
> Allocate the entry first. If that fails nothing has been touched and
> the exception stays as it was.
> 
> Fixes: 35732d01fe31 ("ipv6: introduce a hash table to store dst cache")

Fixes tags on net-next patches are for problems that only exist in
net-next. The blamed commit is 9 years old, the likelihood of the
allocation failing is not high and the next PTB / redirect will recreate
the exception. I would just remove the tag.

> Signed-off-by: David Ahern <dahern@nvidia.com>
> ---
>  net/ipv6/route.c | 23 ++++++++++++++---------
>  1 file changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index df843178e5ec..c41c5ca23fe1 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -1721,8 +1721,8 @@ static int rt6_insert_exception(struct rt6_info *nrt,
>  	struct net *net = dev_net(nrt->dst.dev);
>  	struct rt6_exception_bucket *bucket;
>  	struct fib6_info *f6i = res->f6i;
> +	struct rt6_exception *rt6_ex, *new_ex;

Maintain reverse xmas tree:

https://docs.kernel.org/next/process/maintainer-netdev.html#local-variable-ordering-reverse-xmas-tree-rcs

>  	struct in6_addr *src_key = NULL;
> -	struct rt6_exception *rt6_ex;
>  	struct fib6_nh *nh = res->nh;
>  	int max_depth;
>  	int err = 0;
> @@ -1765,19 +1765,24 @@ static int rt6_insert_exception(struct rt6_info *nrt,
>  		goto out;
>  	}
>  
> +	/* Allocate the new entry before the one it replaces is touched, so
> +	 * that running out of memory leaves what was learned in place.
> +	 */

Comment is redundant. Motivation is in the commit message and this is
not complex enough to justify a comment.

> +	new_ex = kzalloc_obj(*new_ex, GFP_ATOMIC);
> +	if (!new_ex) {
> +		err = -ENOMEM;
> +		goto out;
> +	}
> +
> +	new_ex->rt6i = nrt;
> +	new_ex->stamp = jiffies;
> +
>  	rt6_ex = __rt6_find_exception_spinlock(&bucket, &nrt->rt6i_dst.addr,
>  					       src_key);
>  	if (rt6_ex)
>  		rt6_remove_exception(bucket, rt6_ex);
>  
> -	rt6_ex = kzalloc_obj(*rt6_ex, GFP_ATOMIC);
> -	if (!rt6_ex) {
> -		err = -ENOMEM;
> -		goto out;
> -	}
> -	rt6_ex->rt6i = nrt;
> -	rt6_ex->stamp = jiffies;
> -	hlist_add_head_rcu(&rt6_ex->hlist, &bucket->chain);
> +	hlist_add_head_rcu(&new_ex->hlist, &bucket->chain);
>  	bucket->depth++;
>  	rt6_exception_net(nrt)->ipv6.rt6_stats->fib_rt_cache++;
>  
> -- 
> 2.54.0 (Apple Git-157)
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 02/13] ipv6: keep a superseded pcpu dst working until its holders notice
  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-02 16:19   ` Ido Schimmel
  2026-12-05 19:20   ` netdev-bot+sashiko
  1 sibling, 0 replies; 31+ messages in thread
From: Ido Schimmel @ 2026-12-02 16:19 UTC (permalink / raw)
  To: David Ahern
  Cc: netdev, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	David Ahern

On Tue, Dec 01, 2026 at 10:40:03AM -0700, David Ahern wrote:
> From: David Ahern <dahern@nvidia.com>
> 
> When rt6_get_pcpu_route() finds that a pcpu dst of a route using a
> nexthop object has been invalidated, it takes the dst out of its slot
> and calls dst_dev_put() on it. That points the dst at the blackhole
> device and makes its output a discard, although the dst may still be
> held: by a socket, a tunnel dst_cache, an xfrm bundle, or an skb that
> has not reached dst_output() yet (a queued or NFQUEUE reinjected
> packet, async crypto). Those packets are dropped, where the holder
> would have noticed that the dst is stale at its next check and looked
> the route up again.
> 
> The dst does have to be detached from its device when the device is
> unregistered: it is no longer reachable from the FIB, and a holder
> such as an idle socket can keep it indefinitely, which would hold the
> device. Put it on the uncached list instead. It keeps working until its
> holders let go, and rt6_uncached_list_flush_dev() detaches it on
> unregister like any other uncached dst.
> 
> Fixes: 8f34e53b60b3 ("ipv6: Use global sernum for dst validation with nexthop objects")

Looks like another day 1 bug. I suggest dropping the tag.

> Reported-by: Ralf Lici <ralf@mandelbit.com>
> Signed-off-by: David Ahern <dahern@nvidia.com>
> ---
>  net/ipv6/route.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index c41c5ca23fe1..31ebcf665216 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -1483,7 +1483,13 @@ static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res)
>  		/* Paired with READ_ONCE() in __fib6_drop_pcpu_from() */
>  		prev = xchg(p, NULL);
>  		if (prev) {
> -			dst_dev_put(&prev->dst);
> +			/* Holders may still be using it until they notice it
> +			 * is stale, so keep it working rather than dst_dev_put()
> +			 * it, which would turn the packets of anyone who has
> +			 * not rechecked yet into drops. Device unregister
> +			 * detaches it like any other uncached dst.
> +			 */

Redundant, IMO.

> +			rt6_uncached_list_add(prev);

I don't think it's safe. ip6_route_output_flags() treats uncached dst
entries as entries that are already reference counted and doesn't take a
reference on them:

if (!rt6->dst.rt_uncached_list && !dst_hold_safe(dst)) {

If a lookup in process context is interleaved with a lookup in softirq,
the former can treat the entry as reference counted when it's not
(diagram from Claude):

  CPU 0                                     CPU 1
  -----                                     -----
  ip6_route_output_flags()
    rcu_read_lock()
    ip6_pol_route(NOREF)
      local_bh_disable()
      P = rt6_get_pcpu_route()
                                           P becomes stale because of
                                           route insertion
      local_bh_enable()
        softirq: a packet routed via
        the same nexthop
          ip6_pol_route()
            rt6_get_pcpu_route()
              /* P stale */
              xchg(slot, NULL)
              rt6_uncached_list_add(P)
              /* P->dst.rt_uncached_list
               * is now set */
              dst_release(&P->dst)
              /* the slot's reference
               * is gone */
      return P
    if (!P->dst.rt_uncached_list &&
        /* false */
        !dst_hold_safe(&P->dst))
        /* skipped: no hold */
    rcu_read_unlock()
    return P
    /* caller thinks it owns a
     * reference; nobody holds one */

It's problematic that callers check if a reference was taken based on
dst.rt_uncached_list, which can now change after the entry is already
visible.

IMO, callers should only determine it based on the NOREF flag and
ip6_pol_route() should honor it by queueing an RCU callback to release
the reference from uncached dst entries when this flag is specified.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation
  2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
                   ` (14 preceding siblings ...)
  2026-12-02  9:45 ` Ralf Lici
@ 2026-12-03 15:34 ` Ido Schimmel
  2026-12-03 16:55   ` Ralf Lici
  15 siblings, 1 reply; 31+ messages in thread
From: Ido Schimmel @ 2026-12-03 15:34 UTC (permalink / raw)
  To: David Ahern, ralf; +Cc: netdev, davem, edumazet, kuba, pabeni, horms, ralf, ja

On Tue, Dec 01, 2026 at 10:40:01AM -0700, David Ahern wrote:
> Known costs and limits:
>  - Every FIB change bumps the generation of the netns, so every exception
>    becomes stale and is replaced by a copy the next time traffic uses it.
>    That is an allocation per exception revisited, and the replacement takes
>    rt6_exception_lock, which is global. The entry and the writable
>    metrics are allocated before taking it.
> 
>  - An exception insert still scans the nexthop's whole dirty cpumask,
>    nr_cpu_ids bits, though it only touches the dsts of CPUs that built one.

Another cost is related to the structural difference between IPv4 and
IPv6. The cost of rebuilding cached dst entries in IPv4 is lower
compared to IPv6.

Legacy / inline IPv4 nexthops are consolidated by the kernel when
possible, which limits the number of nexthops and therefore the number
of dst entries that need to be rebuilt each time. In IPv6 each route has
its own nexthop, which means that each bump of the per-netns counter
invalidates many more dst entries (up to the number of active routes
times the number of CPUs). Today, per-CPU dst entries of such routes are
not rebuilt following FIB changes, so this is also a new cost for the
forwarding path.

So, I think Ralf's v5 [1] is a better approach and also easier to
review: Keep the per-node validation for inline nexthops and per-netns
validation for nexthop objects.

A few comments on his series:

1. "ipv6: stamp the default route node with a fresh serial on link
failure" is not strictly related to the other patches and should be
submitted separately and without a Fixes: tag given this is not a
regression.

2. Invalidating live per-CPU dst entries by calling dst_dev_put()
introduces the same problem that was fixed in IPv4 by commit
5018c59607a5 ("ipv4: fix race condition between route lookup and
invalidation") and commit ae89f2724db1 ("ipv4: route: don't blackhole
in-use routes when retiring fnhe routes").

Better to move these dst entries to the uncached list, which requires
handling [2] first.

3. In patch 3, stamping a dst entry with 0 due to a mismatch in the
per-netns counter is too coarse. Any FIB change in the netns (e.g., a
route inserted into a different table) causes the lookup to replace a
valid per-CPU dst entry whose route did not change.

We can sample the per-netns counter before the lookup and use it to
stamp new dst entries. A dst entry is then valid as long as its serial
number is equal or newer than the node's serial number, and the per-CPU
dst entry is only replaced when it is no longer valid. This also avoids
the second read of the counter.

[1] https://lore.kernel.org/netdev/cover.1795537128.git.ralf@mandelbit.com/
[2] https://lore.kernel.org/netdev/20261202161942.GA2800642@shredder/

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation
  2026-12-03 15:34 ` Ido Schimmel
@ 2026-12-03 16:55   ` Ralf Lici
  2026-12-03 17:16     ` Ido Schimmel
  0 siblings, 1 reply; 31+ messages in thread
From: Ralf Lici @ 2026-12-03 16:55 UTC (permalink / raw)
  To: Ido Schimmel
  Cc: David Ahern, netdev, davem, edumazet, kuba, pabeni, horms, ja

On Thu, 03 Dec 2026 17:34:47 +0200, Ido Schimmel <idosch@nvidia.com> wrote:
> So, I think Ralf's v5 [1] is a better approach and also easier to
> review: Keep the per-node validation for inline nexthops and per-netns
> validation for nexthop objects.
>

Thanks Ido for the review, and thanks David. I'll respin my series with
your comments addressed.

> A few comments on his series:
>
> 1. "ipv6: stamp the default route node with a fresh serial on link
> failure" is not strictly related to the other patches and should be
> submitted separately and without a Fixes: tag given this is not a
> regression.

Will do, ahead of the series, since the ordered comparison below relies
on node serials never going backwards. I'll also drop 2/4, which was
merged in net in the meantime.

>
> 2. Invalidating live per-CPU dst entries by calling dst_dev_put()
> introduces the same problem that was fixed in IPv4 by commit
> 5018c59607a5 ("ipv4: fix race condition between route lookup and
> invalidation") and commit ae89f2724db1 ("ipv4: route: don't blackhole
> in-use routes when retiring fnhe routes").
>
> Better to move these dst entries to the uncached list, which requires
> handling [2] first.
>

Agreed. I tried putting replaced pcpu dsts on the uncached list before
posting v5 and dropped it because of the ownership problem you describe
in [2]. I'll start the series with the change you suggest there, basing
the ownership on RT6_LOOKUP_F_DST_NOREF.

> 3. In patch 3, stamping a dst entry with 0 due to a mismatch in the
> per-netns counter is too coarse. Any FIB change in the netns (e.g., a
> route inserted into a different table) causes the lookup to replace a
> valid per-CPU dst entry whose route did not change.
>
> We can sample the per-netns counter before the lookup and use it to
> stamp new dst entries. A dst entry is then valid as long as its serial
> number is equal or newer than the node's serial number, and the per-CPU
> dst entry is only replaced when it is no longer valid. This also avoids
> the second read of the counter.
>

Agreed. I considered stamping with the generation sampled before the
lookup in the RFC [3], but validated by equality to avoid a wrap-aware
comparison. The ordered comparison is simpler.

[3] https://lore.kernel.org/netdev/20260901122501.482920-1-ralf@mandelbit.com/

Thanks!

-- 
Ralf Lici
Mandelbit Srl

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation
  2026-12-03 16:55   ` Ralf Lici
@ 2026-12-03 17:16     ` Ido Schimmel
  0 siblings, 0 replies; 31+ messages in thread
From: Ido Schimmel @ 2026-12-03 17:16 UTC (permalink / raw)
  To: Ralf Lici; +Cc: David Ahern, netdev, davem, edumazet, kuba, pabeni, horms, ja

On Thu, Dec 03, 2026 at 05:55:28PM +0100, Ralf Lici wrote:
> On Thu, 03 Dec 2026 17:34:47 +0200, Ido Schimmel <idosch@nvidia.com> wrote:
> > So, I think Ralf's v5 [1] is a better approach and also easier to
> > review: Keep the per-node validation for inline nexthops and per-netns
> > validation for nexthop objects.
> >
> 
> Thanks Ido for the review, and thanks David. I'll respin my series with
> your comments addressed.
> 
> > A few comments on his series:
> >
> > 1. "ipv6: stamp the default route node with a fresh serial on link
> > failure" is not strictly related to the other patches and should be
> > submitted separately and without a Fixes: tag given this is not a
> > regression.
> 
> Will do, ahead of the series, since the ordered comparison below relies
> on node serials never going backwards. I'll also drop 2/4, which was
> merged in net in the meantime.

Note that we need 1/4 in net-next before you send the main series, since
the ordered comparison depends on it. The same applies to
fib6_flush_trees(), which allocates one serial before walking the tables
and can overwrite a newer serial. Allocating the serial per table after
taking tb6_lock should fix it.

> 
> >
> > 2. Invalidating live per-CPU dst entries by calling dst_dev_put()
> > introduces the same problem that was fixed in IPv4 by commit
> > 5018c59607a5 ("ipv4: fix race condition between route lookup and
> > invalidation") and commit ae89f2724db1 ("ipv4: route: don't blackhole
> > in-use routes when retiring fnhe routes").
> >
> > Better to move these dst entries to the uncached list, which requires
> > handling [2] first.
> >
> 
> Agreed. I tried putting replaced pcpu dsts on the uncached list before
> posting v5 and dropped it because of the ownership problem you describe
> in [2]. I'll start the series with the change you suggest there, basing
> the ownership on RT6_LOOKUP_F_DST_NOREF.

This can also be sent separately before the main series: first base the
ownership on RT6_LOOKUP_F_DST_NOREF, then David's 2/13.

> 
> > 3. In patch 3, stamping a dst entry with 0 due to a mismatch in the
> > per-netns counter is too coarse. Any FIB change in the netns (e.g., a
> > route inserted into a different table) causes the lookup to replace a
> > valid per-CPU dst entry whose route did not change.
> >
> > We can sample the per-netns counter before the lookup and use it to
> > stamp new dst entries. A dst entry is then valid as long as its serial
> > number is equal or newer than the node's serial number, and the per-CPU
> > dst entry is only replaced when it is no longer valid. This also avoids
> > the second read of the counter.
> >
> 
> Agreed. I considered stamping with the generation sampled before the
> lookup in the RFC [3], but validated by equality to avoid a wrap-aware
> comparison. The ordered comparison is simpler.

Note that we shouldn't cache a dst entry if the node's serial number is
newer than the sample. In this case, return an uncached dst stamped with
the sample and leave the per-CPU dst alone.

> 
> [3] https://lore.kernel.org/netdev/20260901122501.482920-1-ralf@mandelbit.com/
> 
> Thanks!
> 
> -- 
> Ralf Lici
> Mandelbit Srl

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 02/13] ipv6: keep a superseded pcpu dst working until its holders notice
  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-02 16:19   ` Ido Schimmel
@ 2026-12-05 19:20   ` netdev-bot+sashiko
  1 sibling, 0 replies; 31+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 19:20 UTC (permalink / raw)
  To: dsahern
  Cc: netdev, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	dahern, noreply

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

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

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

- [Critical] net/ipv6/route.c rt6_get_pcpu_route() now calls
  rt6_uncached_list_add(prev) on a stale RTF_PCPU dst, which sets…
- [Medium] The patch fixes only one of the paths that dst_dev_put() a
  pcpu dst that may still be held.

--

ipv6: keep a superseded pcpu dst working until its holders notice

Before this patch, rt6_get_pcpu_route() called dst_dev_put() on a stale
pcpu dst of a route using a nexthop object. The patch puts the dst on the
uncached list instead. Current holders can keep using it until they notice
it is stale, and rt6_uncached_list_flush_dev() still detaches it from the
device on unregister.

> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index c41c5ca23fe12..31ebcf6652166 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -1483,7 +1483,13 @@ static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res)
>  		/* Paired with READ_ONCE() in __fib6_drop_pcpu_from() */
>  		prev = xchg(p, NULL);
>  		if (prev) {
> -			dst_dev_put(&prev->dst);
> +			/* Holders may still be using it until they notice it
> +			 * is stale, so keep it working rather than dst_dev_put()
> +			 * it, which would turn the packets of anyone who has
> +			 * not rechecked yet into drops. Device unregister
> +			 * detaches it like any other uncached dst.
> +			 */
> +			rt6_uncached_list_add(prev);

[Severity: Critical]
Can this unbalance the refcount on the pcpu dst?

In IPv6, a non-NULL rt_uncached_list tells the caller that it already owns
a reference, even for RT6_LOOKUP_F_DST_NOREF lookups.
rt6_uncached_list_add() documents this:

	/* Set once and never cleared: non-NULL marks an uncached route. */
	rt->dst.rt_uncached_list = ul;

NOREF lookups hand out pcpu dsts without taking a reference. Before this
patch, pcpu dsts never had the marker set. Now the marker can flip on a
pcpu dst that a NOREF caller already holds.

This sequence on one CPU looks possible:

process context
ip6_route_output_flags()
  rcu_read_lock()
  ip6_route_output_flags_noref()
    ip6_pol_route(..., RT6_LOOKUP_F_DST_NOREF)
      local_bh_disable()
      rt6_get_pcpu_route()      <- returns P, no ref, marker NULL
      local_bh_enable()         <- pending softirqs can run here

softirq on the same CPU, after fib6_sernum was bumped elsewhere
ip6_route_input()
  ...
  rt6_get_pcpu_route()          <- finds P stale
    prev = xchg(p, NULL)
    rt6_uncached_list_add(P)    <- marker now set
    dst_release(&P->dst)        <- drops the slot's reference

Then, back in ip6_route_output_flags():

	/* For an uncached dst, refcnt is already taken. */
	if (!rt6->dst.rt_uncached_list && !dst_hold_safe(dst)) {

The marker is now set, so dst_hold_safe() is skipped. P goes back to the
caller as if it owned a reference. When the socket or dst_cache later
releases P, there is one more put than get.

Wouldn't that free P while the socket, or some other holder, still points
to it?

The window runs from local_bh_enable() in ip6_pol_route() to the marker
test. Softirqs on irq exit or preemption under PREEMPT_RCU can land
anywhere in it.

The same marker flip looks like it affects ip6_rt_put_flags():

	if (!(flags & RT6_LOOKUP_F_DST_NOREF) ||
	    rt->dst.rt_uncached_list)
		ip6_rt_put(rt);

That would put a reference the NOREF lookup never took. Callers include
both versions of fib6_rule_lookup() (fib6_rules.c and ip6_fib.c),
fib6_rule_action_alt(), fib6_rule_suppress() and
seg6_lookup_any_nexthop().

seg6_lookup_any_nexthop() also uses the marker to choose skb_dst_set()
over skb_dst_set_noref():

	if ((flags & RT6_LOOKUP_F_DST_NOREF) && !dst->rt_uncached_list)
		skb_dst_set_noref(skb, dst);
	else
		skb_dst_set(skb, dst);

So the later skb_dst_drop() would release a reference that was never
taken.

Before this patch, the same race ended with dst_hold_safe() either
succeeding or falling back to ip6_null_entry.

This also seems to still be present at the end of the series.
rt6_dst_release_deferred() defers the slot's put through call_rcu, which
keeps P alive for one grace period but does not fix the imbalance. Also,
"ipv6: validate dsts against the netns route generation" applies the same
rt6_uncached_list_add(old) pattern to replaced exceptions, and NOREF
lookups return those without a reference too.

>  			dst_release(&prev->dst);
>  		}
>  

[Severity: Medium]
Should fib6_nh_release_dsts() get the same treatment? It still does the
sequence this patch removes here:

net/ipv6/route.c:fib6_nh_release_dsts() {
    ...
		pcpu_rt = xchg(ppcpu_rt, NULL);
		if (pcpu_rt) {
			dst_dev_put(&pcpu_rt->dst);
			dst_release(&pcpu_rt->dst);
		}
    ...
}

When a nexthop group is replaced, nh_rt_cache_flush() calls it for every
IPv6 member right after rt_genid_bump_ipv6(). The routes and member
nexthops stay live:

replace_nexthop_grp()
  nh_rt_cache_flush()
    fib6_nh_release_dsts()
      dst_dev_put()

The commit message describes the holders involved: sockets, tunnel
dst_caches, xfrm bundles and in-flight skbs. After this dst_dev_put(),
their packets would still go to blackhole_netdev/dst_discard_out instead
of the holder re-looking up the route.

The commit message's reasoning about device unregister would seem to
apply here as well. At the end of the series, fib6_nh_release_dsts()
still calls dst_dev_put(); only its dst_release() was converted to
rt6_dst_release_deferred().

Is there a reason this path is left alone?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201174021.7211-1-dsahern%40kernel.org

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 03/13] ipv6: don't insert a PMTU exception whose MTU could not be stored
  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-05 19:20   ` netdev-bot+sashiko
  0 siblings, 0 replies; 31+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 19:20 UTC (permalink / raw)
  To: dsahern
  Cc: netdev, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	dahern, noreply

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

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

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

- [Medium] The compare-and-exchange protocol in rt6_lower_mtu() only
  protects against other PMTU handlers.

--

ipv6: don't insert a PMTU exception whose MTU could not be stored

This patch makes rt6_do_update_pmtu() allocate writable metrics up front
and return an error if that fails. When it fails, a new exception is not
inserted and an existing one does not get its stamp refreshed. It also
adds rt6_lower_mtu(), which lowers RTAX_MTU with try_cmpxchg() so that a
smaller value stored at the same time by another PMTU handler is kept.

> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 31ebcf6652166..06afb9d5dc2b1 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -1546,6 +1546,34 @@ static struct net *rt6_exception_net(const struct rt6_info *rt)
>  	return container_of(rt->dst.ops, struct net, ipv6.ip6_dst_ops);
>  }
>  
> +/* Lower the MTU in the metrics of @rt to @mtu.
> + *
> + * A dst shares the read-only metrics of its route until it needs its own.
> + * Allocating them can fail, and dst_metric_set() does not say: the PMTU would
> + * be lost.
> + *
> + * Only ever lower it, and with a compare and exchange: PMTU handlers update a
> + * dst in place without a lock, and each decides to lower the MTU from a value
> + * it read earlier, so storing unconditionally could overwrite a smaller value
> + * that another handler stored in between.
> + */
> +static int rt6_lower_mtu(struct rt6_info *rt, u32 mtu)
> +{
> +	u32 *metrics = dst_metrics_write_ptr(&rt->dst);
> +	u32 old;
> +
> +	if (!metrics)
> +		return -ENOMEM;
> +
> +	old = READ_ONCE(metrics[RTAX_MTU - 1]);
> +	do {
> +		if (old && old <= mtu)
> +			break;
> +	} while (!try_cmpxchg(&metrics[RTAX_MTU - 1], &old, mtu));

[Severity: Medium]
Does this fully deliver the "only ever goes down and a smaller value
stored meanwhile is kept" guarantee from the commit message? Another
writer of the same RTAX_MTU word on exception dsts was left unchanged.

On NETDEV_CHANGEMTU, fib6_nh_mtu_change() takes only rt6_exception_lock
and calls rt6_exceptions_update_pmtu(). That function first reads the
current MTU, then does a plain store:

net/ipv6/route.c:rt6_mtu_change_route_allowed() {
	u32 dmtu = dst6_mtu(&rt->dst);
    ...
}

net/ipv6/route.c:rt6_exceptions_update_pmtu() {
    ...
			if (dst_metric_raw(&entry->dst, RTAX_MTU) &&
			    rt6_mtu_change_route_allowed(idev, entry, mtu))
				dst_metric_set(&entry->dst, RTAX_MTU, mtu);
    ...
}

dst_metric_set() ends up doing an unconditional "p[metric-1] = val;".

The in-place path __ip6_rt_update_pmtu()->rt6_do_update_pmtu()->
rt6_lower_mtu() never takes rt6_exception_lock. So the two writers do not
share a lock.

Here is one example. An exception has PMTU 1500 and the device MTU is
lowered to 1450:

CPU1 (NETDEV_CHANGEMTU)
rt6_exceptions_update_pmtu()
  rt6_mtu_change_route_allowed()
    dmtu = 1500, decides to store 1450

CPU0 (ICMPv6 Packet Too Big, 1280, same RTF_CACHE dst)
__ip6_rt_update_pmtu()
  rt6_do_update_pmtu()
    rt6_lower_mtu()
      try_cmpxchg() 1500 -> 1280
  rt6_update_exception_stamp_rt()

CPU1
  dst_metric_set(&entry->dst, RTAX_MTU, 1450)

The 1280 just learned is replaced by 1450. Packets then exceed the path
MTU until another Packet Too Big arrives. The same can happen when the
device MTU is raised and dmtu == idev->cnf.mtu6.

That looks like the overwrite the commit message describes, where "a
handler that decided on 1400 overwrite a 1280 that another one stored in
between". It also means a plain store races with READ_ONCE() and
try_cmpxchg() on the same u32, which KCSAN may report.

This still holds at the end of the series. The later commit "ipv6:
validate dsts against the netns route generation" says the device MTU
change path "is not covered by that". Its rt6_exception_merge() comment
repeats the "neither overwrites what the other stored" guarantee, which
this path does not honour.

Could rt6_exceptions_update_pmtu() store conditionally instead? For
example, it could try_cmpxchg() from the raw value it read, so the store
only lands if nothing changed. Another option is to have both writers
take the same lock.

> +
> +	return 0;
> +}
> +

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201174021.7211-1-dsahern%40kernel.org

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 04/13] ipv6: invalidate the failing dst in ip6_link_failure()
  2026-12-01 17:40 ` [PATCH net-next v3 04/13] ipv6: invalidate the failing dst in ip6_link_failure() David Ahern
@ 2026-12-05 19:20   ` netdev-bot+sashiko
  0 siblings, 0 replies; 31+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 19:20 UTC (permalink / raw)
  To: dsahern
  Cc: netdev, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	dahern, noreply

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

Critical: 0 · High: 0 · Medium: 1 · 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).

- [Medium] ip6_link_failure() in net/ipv6/route.c now invalidates only
  the dst attached to the failing skb, through rt6_dst_invalidate(rt).
- [Low] Verified, then discarded under the series rule (baseline
  decision: false).

--

ipv6: invalidate the failing dst in ip6_link_failure()

This patch changes ip6_link_failure() so it no longer writes -1 to the
fn_sernum of the default route's fib6_node. It marks only the failing dst
as stale, by setting the top bit of its sernum. Readers of rt->sernum now
use READ_ONCE(), because the value can change on a published dst.

> diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
> index 232289b439c3c..bfc1895e85915 100644
> --- a/include/net/ip6_fib.h
> +++ b/include/net/ip6_fib.h

[ ... ]

> @@ -315,6 +320,24 @@ static inline u32 rt6_get_cookie(const struct rt6_info *rt)
>  	return cookie;
>  }
>  
> +/* An invalidated dst keeps the generation it was built under in the low
> + * bits, so state derived from it (exceptions) can be stamped with the FIB
> + * state it actually came from. The top bit makes it fail rt6_is_valid():
> + * the netns generation is always positive.
> + */
> +#define RT6_SERNUM_STALE	INT_MIN

[Severity: Low]
This isn't a bug, but does this comment match the code at this point in
the series?

At this commit, ip6_rt_pcpu_alloc() is the only place that writes a
non-zero sernum:

	if (f6i->nh)
		pcpu_rt->sernum = rt_genid_ipv6(dev_net(dev));

Legacy dsts (no nexthop object) still have sernum == 0 when
ip6_link_failure() marks them. So there is no generation in the low bits
to keep. Nothing in this commit reads the low bits or stamps exceptions
from them either.

Marking a legacy pcpu dst also makes its sernum non-zero for the first
time, so the dst now takes the drop path in rt6_get_pcpu_route():

	if (pcpu_rt && READ_ONCE(pcpu_rt->sernum) && !rt6_is_valid(pcpu_rt)) {

Later patches in the series fix this: "ipv6: validate dsts against the
netns route generation" and "ipv6: stamp dsts with the generation
sampled before the FIB lookup". They make ip6_dst_alloc() stamp every
dst, add rt6_dst_sernum() and stamp exceptions from it, so the comment
is accurate at the end of the series.

Could the comment and commit message be reworded here, or this patch be
moved after those, so that each commit describes what it actually does?

[ ... ]

> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 06afb9d5dc2b1..5af0f26332ffa 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c

[ ... ]

> @@ -2912,14 +2912,14 @@ static void ip6_link_failure(struct sk_buff *skb)
>  			rt6_remove_exception_rt(rt);
>  		} else {
>  			struct fib6_info *from;
> -			struct fib6_node *fn;
>  
> +			/* Force sockets using this dst to look the route up
> +			 * again; a stale-marked sernum never matches the
> +			 * netns generation.
> +			 */
>  			from = rcu_dereference(rt->from);
> -			if (from) {
> -				fn = rcu_dereference(from->fib6_node);
> -				if (fn && (rt->rt6i_flags & RTF_DEFAULT))
> -					WRITE_ONCE(fn->fn_sernum, -1);
> -			}
> +			if (from && (rt->rt6i_flags & RTF_DEFAULT))
> +				rt6_dst_invalidate(rt);

[Severity: Medium]
Does this leave the pcpu copies of the same failing default route on
other CPUs valid?

Before this patch, writing -1 to fn_sernum made every dst under the ::/0
node fail the cookie check:

ip6_dst_check()
  rt6_dst_from_check()
    fib6_check(from, cookie)

Sockets on any CPU then looked the route up again. rt6_check_neigh()
returned RT6_NUD_FAIL_PROBE for the NUD_FAILED gateway, and router
selection moved those sockets to another default router.

Now only the skb's dst is marked. Take a connected socket on CPU1 that
holds CPU1's pcpu copy of the same RA-learned (legacy fib6_nh) default
route. Its sernum is still 0 and fn_sernum is no longer touched. So in
ip6_dst_check() this branch is skipped:

	if (READ_ONCE(rt->sernum))
		return rt6_is_valid(rt) ? dst : NULL;

The fn_sernum/cookie check still passes, and the socket keeps sending to
the dead router.

Each of those packets goes through __neigh_event_send(). That moves the
neighbour from NUD_FAILED back to NUD_INCOMPLETE, queues the skb for a
full probe cycle and then drops it. Only after that does the path
error_report -> ip6_link_failure() mark CPU1's copy. Flows whose skbs
were dropped because the neighbour queue was over its length limit never
reach ip6_link_failure() at all.

Is this intended? The commit message says invalidating the node is "far
more than needed" and that the new scope is "one CPU's copy". It doesn't
mention that flows through the same failing router on other CPUs now
fail over later, each after its own probe timeout and packet loss.

This is unchanged at the end of the series. The exception-insert code
added later in the series walks nh->rt6i_pcpu_dirty / rt6i_pcpu and calls
rt6_dst_invalidate() on each copy.

Could ip6_link_failure() do the same for the failing fib6_nh? That would
leave other routers' dsts alone but invalidate every copy of this
router's dst.

>  		}
>  		rcu_read_unlock();
>  	}

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201174021.7211-1-dsahern%40kernel.org

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 05/13] ipv6: tell route dumps about exception inserts with a table sequence
  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-05 19:20   ` netdev-bot+sashiko
  0 siblings, 0 replies; 31+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 19:20 UTC (permalink / raw)
  To: dsahern
  Cc: netdev, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	dahern, noreply

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

Critical: 0 · High: 0 · Medium: 1 · 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).

- [Medium] The patch says it corrects the comment in
  rt6_nh_dump_exceptions() (net/ipv6/route.c), but the rewritten comment…
- [Low] The new comment on fib6_update_excp_seq() (net/ipv6/ip6_fib.c)
  says "A dump notices a changed tree through the root node, so only an…

--

ipv6: tell route dumps about exception inserts with a table sequence

This adds a per-table tb6_excp_seq. rt6_insert_exception() bumps it under
tb6_lock when the exception is inserted on the root node, and
fib6_dump_table() restarts a resumed dump when either the root's
fn_sernum or tb6_excp_seq has changed. The patch also rewrites the
comment in rt6_nh_dump_exceptions() about which exception changes a
dump notices.

> diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
> index e1d49897d6ab0..4da83c22bbde8 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. A dump notices
> + * a changed tree through the root node, so only an exception on the root
> + * needs to be visible. Use a table sequence for that, rather than a fresh
> + * fn_sernum, so that it does not depend on what else a change to fn_sernum
> + * does: fresh values can only come from the netns counter, and a made-up
> + * one could later be issued by the counter to the same node.
> + * 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);
> +}

[Severity: Low]
This isn't a bug, but does this comment contradict the one this patch
adds to rt6_nh_dump_exceptions()?

This comment says only an exception on the root "needs to be visible".
The rt6_nh_dump_exceptions() comment says a change under any other node
"is not noticed: a dump suspended in the middle of that route's
exceptions can skip or repeat some of them."

tb6_excp_seq is table-wide, so fib6_dump_table() would also notice a bump
for a non-root exception. Limiting the bump to fn == &table->tb6_root
looks like a way to keep the old behaviour. It does not seem to be
enough for dump consistency.

Could the wording say this, so a later reader doesn't assume root-only
signalling is complete? The wording also looks unchanged at the end of
the series.

[ ... ]

> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 5af0f26332ffa..836bd7aa05cd7 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c

[ ... ]

> @@ -6125,11 +6126,15 @@ static int rt6_nh_dump_exceptions(struct fib6_nh *nh, void *arg)
>  				continue;
>  			}
>  
> -			/* Expiration of entries doesn't bump sernum, insertion
> -			 * does. Removal is triggered by insertion, so we can
> -			 * rely on the fact that if entries change between two
> -			 * partial dumps, this node is scanned again completely,
> -			 * see rt6_insert_exception() and fib6_dump_table().
> +			/* Expiration of entries doesn't bump anything. An
> +			 * insertion on the root node changes the root's
> +			 * fn_sernum or tb6_excp_seq, and removal is triggered
> +			 * by insertion, so if entries of the root change
> +			 * between two partial dumps, the table is scanned
> +			 * again, see rt6_insert_exception() and
> +			 * fib6_dump_table(). A change under any other node is
> +			 * not noticed: a dump suspended in the middle of that
> +			 * route's exceptions can skip or repeat some of them.
>  			 *
>  			 * Count expired entries we go through as handled
>  			 * entries that we'll skip next time, in case of partial

[Severity: Medium]
The commit message says this corrects the comment. Is the part saying
"removal is triggered by insertion" still accurate?

Only two rt6_remove_exception() calls run under rt6_insert_exception().
One is the eviction in rt6_exception_remove_oldest(), the other replaces
a matching entry. rt6_insert_exception() is also the only caller of
fib6_update_excp_seq().

The other removals change neither the root's fn_sernum nor
tb6_excp_seq:

  fib6_nh_remove_exception(), reached via rt6_remove_exception_rt() on
  RTM_DELROUTE of a cached route, on negative advice and on link failure
  fib6_nh_exceptions_clean_tohost()
  fib6_nh_flush_exceptions()
  rt6_age_examine_exception(), called from GC

net/ipv6/route.c:rt6_age_examine_exception() {
    ...
		if (time_after_eq(now, READ_ONCE(rt->dst.lastuse) +
				       gc_args->timeout)) {
			pr_debug("aging clone %p\n", rt);
			rt6_remove_exception(bucket, rt6_ex);
			return;
		}
	} else if (time_after(jiffies, READ_ONCE(rt->dst.expires))) {
		pr_debug("purging expired route %p\n", rt);
		rt6_remove_exception(bucket, rt6_ex);
		return;
	}
    ...
}

GC removes more than expired entries. It also removes aged
non-RTF_EXPIRES clones and gateway exceptions whose gateway is not a
router.

Say a dump is suspended part-way through the root route's exceptions
with skip_in_node = k. One of the entries already sent is then removed
by one of these paths. On resume, fib6_dump_table() sees the same values:

	if (cb->args[5] != sernum || w->excp_seq != excp_seq) {

So there is no restart, and rt6_nh_dump_exceptions() applies the stale
skip count to the shorter chain:

			if (w->skip) {
				w->skip--;
				continue;
			}

Wouldn't that drop a valid exception that was never sent, without
setting NLM_F_DUMP_INTR?

The skipping itself is older than this patch. The rewritten comment,
though, repeats the inaccurate premise.

The comment is also inaccurate for insertions. With nexthop objects, an
exception can be inserted through a non-root route that shares the
nexthop's fib6_nh. That changes the root route's dumped exceptions, and
neither fn_sernum nor tb6_excp_seq is bumped.

This comment also appears unchanged at the end of the series.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201174021.7211-1-dsahern%40kernel.org

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 06/13] ipv6: validate dsts against the netns route generation
  2026-12-01 17:40 ` [PATCH net-next v3 06/13] ipv6: validate dsts against the netns route generation David Ahern
@ 2026-12-05 19:20   ` netdev-bot+sashiko
  0 siblings, 0 replies; 31+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 19:20 UTC (permalink / raw)
  To: dsahern
  Cc: netdev, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	dahern, noreply

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

Critical: 0 · High: 4 · Medium: 4 · Low: 5

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] Use-after-free (RCU NOREF lifetime): the fix is incomplete.
- [High] ipv6: unguarded dst->dev access in ip6_dst_check() and
  rt6_is_valid()
- [High] ipv6: refcount underflow via rt6_uncached_list_add() on
  published dsts
- [High] ipv6: orphaned pcpu dst after route deletion in
  rt6_get_pcpu_route()
- [Medium] With nexthop objects, a refresh changes which route owns an
  exception without putting the new owner on the GC list.
- [Medium] With CONFIG_IPV6_SUBTREES, rt6_uncached_clone_superseded()
  cannot find PMTU exceptions for FLOWI_FLAG_KNOWN_NH clones of source-…
- [Medium] The rule that a lowered PMTU is not lost to a refresh depends
  on the in-place updater reaching fib6_nh_update_exception(), whose…
- [Medium] ipv6: lost RTF_EXPIRES on refresh race in
  __rt6_insert_exception()
- [Low] Process: the commit fixes a reported, user-visible bug (Reported-
  by: Ralf Lici; a stale dst passes revalidation because the cookie was…
- [Low] The comment in __rt6_find_cached_rt() says callers that hand the
  exception to users as their dst must pass @stale, so a stale exception…
- [Low] After hlist_replace_rcu() in __rt6_insert_exception(), the
  comment says 'Only a change since the copy is merged, so the PMTU a…
- [Low] The commit says the merge 'lowers the expiry the same way' as the
  lockless handler, so that 'a smaller value stored by one is kept…
- [Low] Race in the pcpu-dirty handshake on PREEMPT_RT.

--

ipv6: validate dsts against the netns route generation

This commit stamps every IPv6 dst with the netns route generation when it
is allocated, and ip6_dst_check() validates it with a plain comparison
instead of the fn_sernum based cookie. On lookup, a stale exception is
replaced by a current copy, and an exception insert now invalidates only
the nexthop's pcpu dsts, which are tracked with a new per-nexthop cpumask.
When a pcpu slot or the exception table gives up a dst, its reference is
dropped after an RCU grace period.

> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 836bd7aa05cd7..959157896f980 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c

[ ... ]

> @@ -1523,6 +1557,13 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net,
>  		return prev;
>  	}
>  
> +	/* Tell fib6_nh_invalidate_pcpu() there is a dst to invalidate on this
> +	 * CPU. The cmpxchg() above orders the install before the mark.
> +	 */
> +	cpumask_set_cpu(smp_processor_id(), res->nh->rt6i_pcpu_dirty);
> +	/* Order the mark before the exception re-check in ip6_pol_route() */
> +	smp_mb__after_atomic();
> +

[Severity: Low]
On PREEMPT_RT, can another task on this CPU use the new pcpu dst between
the cmpxchg() and cpumask_set_cpu()? The WARN_ON_ONCE() above already says
preemption is possible here.

Task A installs D and is preempted before it sets its bit. Task C on the
same CPU misses the exception, which is not published yet, and gets D from
rt6_get_pcpu_route() without the re-check.

The writer then publishes the exception, does smp_mb() and scans
rt6i_pcpu_dirty. It finds the bit clear and leaves D valid for C's holder.

Also, when the cmpxchg() fails, rt6_make_pcpu_route() returns prev without
setting the mark or issuing the barrier.

[ ... ]

> @@ -1749,18 +1790,163 @@ struct rt6_exception_bucket *fib6_nh_get_excptn_bucket(const struct fib6_nh *nh,

[ ... ]

> +static void rt6_exception_merge(struct rt6_info *cur, const struct rt6_info *rt)
> +{
> +	u32 mtu = dst_metric_raw(&rt->dst, RTAX_MTU);

[ ... ]

> +	/* As dst_set_expires() does, never extend an expiry */
> +	if (rt->rt6i_flags & RTF_EXPIRES) {
> +		unsigned long expires = READ_ONCE(rt->dst.expires);
> +		unsigned long old = READ_ONCE(cur->dst.expires);
> +
> +		do {
> +			if (old && !time_before(expires, old))
> +				break;
> +		} while (!try_cmpxchg(&cur->dst.expires, &old, expires));
> +
> +		cur->rt6i_flags |= RTF_EXPIRES;
> +	}
> +	cur->rt6i_flags |= rt->rt6i_flags & RTF_MODIFIED;
> +}

[Severity: Low]
The commit message says the merge lowers the expiry the same way the
in-place handler does, so a smaller value is kept whichever order they run
in. Is that accurate for the expiry?

This code uses try_cmpxchg(). The lockless path, rt6_do_update_pmtu() ->
rt6_update_expires() -> dst_set_expires(), checks and then does a plain
store:

	old = READ_ONCE(dst->expires);

	if (!old || time_before(expires, old))
		WRITE_ONCE(dst->expires, expires);

A handler that read the value before this cmpxchg can overwrite the
earlier expiry with a later one. When RTF_EXPIRES is not yet set,
rt6_update_expires() can also store from->expires unconditionally.

rt6i_flags is also changed with a plain |= in two places: here under
rt6_exception_lock, and without the lock in rt6_do_update_pmtu() and
rt6_update_expires(). Should those accesses be annotated or made atomic?

[ ... ]

> @@ -1790,27 +1981,88 @@ static int rt6_insert_exception(struct rt6_info *nrt,

[ ... ]

>  	if (dst_metric_raw(&nrt->dst, RTAX_MTU) >= fib6_mtu(res)) {
> -		err = -EINVAL;
> -		goto out;
> -	}

[ ... ]

> +		if (old && (old->rt6i_flags & RTF_DYNAMIC)) {

[ ... ]

> +			dst_metric_set(&nrt->dst, RTAX_MTU, res->f6i->fib6_pmtu);
> +		} else {
> +			/* A stale exception that no longer lowers anything
> +			 * would fail every refresh from here on: drop it.
> +			 */
> +			if (old)
> +				rt6_remove_exception(old_bucket, rt6_ex);
> +			err = -EINVAL;
> +			goto out;
> +		}
>  	}

[Severity: High]
Should rt6_remove_exception() also defer its release? It still does:

	hlist_del_rcu(&rt6_ex->hlist);
	dst_release(&rt6_ex->rt6i->dst);

The commit message says that when a pcpu slot or the exception table gives
up a dst, its reference is now dropped after a grace period. The reason
given is that RT6_LOOKUP_F_DST_NOREF readers rely on RCU alone, and
dst_destroy() releases an xfrm bundle's child with dst_release_immediate().

This new call on the refresh path drops a stale exception that lockless
readers have just found. Every other path that unpublishes an exception
goes through the same function: aging, rt6_exception_remove_oldest(),
flushes, and replacement on a normal insert.

Could this sequence free the exception while a reader is still using it?

  a NOREF reader in ip6_pol_route() finds exception E under RCU
  E is the child of xfrm bundle B, whose last reference is gone and
    whose dst_destroy_rcu() is already queued
  rt6_remove_exception() unlinks E and calls dst_release() on it
  B's grace period ends: dst_destroy(B) -> dst_release_immediate(E)
  the reader is still using E

Would using rt6_dst_release_deferred() in rt6_remove_exception() close this?

[ ... ]

> +		hlist_replace_rcu(&rt6_ex->hlist, &new_ex->hlist);
> +
> +		/* An in-place PMTU update of old does not take the lock, and
> +		 * one that saw old still in the table does not merge (see
> +		 * fib6_nh_update_exception()). Pairs with smp_mb() there:
> +		 * either it sees nrt and merges into it under the lock, or
> +		 * this sees its update and merges it here. Only a change
> +		 * since the copy is merged, so the PMTU a redirect copy
> +		 * dropped above is not brought back.
> +		 */
> +		smp_mb();
> +		if (dst_metric_raw(&old->dst, RTAX_MTU) != old_mtu ||
> +		    READ_ONCE(old->dst.expires) != old_expires)
> +			rt6_exception_merge(nrt, old);

[Severity: Low]
Does this match the comment that only a change since the copy is merged?
If only old's expiry changed, rt6_exception_merge(nrt, old) still runs and
merges old's whole MTU:

	u32 mtu = dst_metric_raw(&rt->dst, RTAX_MTU);
	...
	if (mtu)
		rt6_lower_mtu(cur, mtu);

In the RTF_DYNAMIC branch above, nrt's MTU was just set to
res->f6i->fib6_pmtu, which is usually 0. rt6_lower_mtu() treats 0 as no
value, so old's MTU gets stored in the copy.

rt6_do_update_pmtu() calls rt6_lower_mtu() and then rt6_update_expires().
Suppose a lockless update's MTU store lands before the snapshot and its
expiry store lands after it. Wouldn't that bring back the PMTU the
redirect branch meant to drop?

> @@ -1828,10 +2080,14 @@ 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) {
> +	/* new_ex is in the table on success only */
> +	if (err)
> +		kfree(new_ex);
> +
> +	if (!err && !old) {
> +		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);

[Severity: Medium]
With nexthop objects, can a refresh move an exception to a route that is
not on the GC list?

rt6_refresh_exception() builds nrt with ip6_rt_cache_alloc(res, ...), so
nrt->from is res->f6i, the route this lookup selected. That can differ
from old->from when two routes share a nexthop object. For example, A is
a /32 that created the exception, and B is a more specific /48 added
later, which bumps the generation and makes the exception stale.

Because old is set, the refresh skips fib6_add_gc_list(f6i) here.

If A is then deleted, fib6_nh_flush_exceptions(nh, A) removes only the
entries whose from is A, so B's copy stays. A also leaves tb6_gc_hlist.

Exceptions are aged only through routes on tb6_gc_hlist:

  fib6_gc_table() -> fib6_age() -> fib6_age_exceptions()

Would the shared bucket stop being aged after that? A redirect exception
would then never be removed by the lastuse timeout, or by the check in
rt6_age_examine_exception() that the gateway is still a router.

[ ... ]

> @@ -1932,6 +2214,86 @@ static struct rt6_info *rt6_find_cached_rt(const struct fib6_result *res,

[ ... ]

> +	err = __rt6_insert_exception(nrt, res, old);
> +	if (!err)
> +		return nrt;
> +
> +	dst_release_immediate(&nrt->dst);
> +
> +	/* @old was replaced or removed since we found it: use what is there
> +	 * now, which is a miss if it was removed.
> +	 */
> +	if (err == -EEXIST)
> +		return __rt6_find_cached_rt(res, &old->rt6i_dst.addr, saddr,
> +					    NULL);

[Severity: Low]
The comment in __rt6_find_cached_rt() says that callers which hand the
exception to users as their dst pass @stale. Does this fallback follow
that rule?

It passes NULL, and the result goes back through
rt6_find_cached_rt_refresh() to ip6_pol_route() and ip6_pol_route_lookup(),
which both hand it out.

The exception now in the table may itself be stale, for example a
concurrent refresh's copy that was stamped before another generation
bump. It would then be returned as is, with no refresh attempt and
without *retry being set.

[ ... ]

> @@ -2035,9 +2412,31 @@ static void fib6_nh_update_exception(const struct fib6_nh *nh, int plen,
>  	if (plen)
>  		src_key = &rt->rt6i_src.addr;
>  #endif
> +
> +	/* Order the update of @rt before the lookup, see above */
> +	smp_mb();
> +

[Severity: Medium]
Does every in-place PMTU update reach this barrier? For nexthop-object
routes, rt6_update_exception_stamp_rt() calls fib6_nh_update_exception()
only when fib6_nh_find_match() matches:

	struct fib6_nh_match_arg arg = {
		.dev = rt->dst.dev,
		.gw = &rt->rt6i_gateway,
	};

	nexthop_for_each_fib6_nh(from->nh, fib6_nh_find_match, &arg);

	if (!arg.match)
		goto unlock;

.gw is never NULL, so fib6_nh_find_match() rejects gateway-less nexthops
through (arg->gw && !nh->fib_nh_gw_family). A redirect exception whose
gateway differs from the nexthop's gateway does not match either.

In those cases the updater lowers old's MTU without the smp_mb(), the
lookup or the merge. If that store lands after the post-swap re-read in
__rt6_insert_exception(), the lower PMTU never reaches the copy.

The commit message says "Either the updater finds the copy or the
replacement sees the update, so the lower PMTU is not lost." How does
that hold for these routes?

[ ... ]

> @@ -2837,16 +3258,89 @@ static struct dst_entry *rt6_check(struct rt6_info *rt,

[ ... ]

> +static bool rt6_uncached_clone_superseded(const struct rt6_info *rt,
> +					  struct fib6_info *from)
> +{
> +	struct rt6_clone_nh_arg arg = {
> +		.rt = rt,
> +		.from = from,
> +	};
> +
> +#ifdef CONFIG_IPV6_SUBTREES
> +	if (rt->rt6i_src.plen)
> +		arg.saddr = &rt->rt6i_src.addr;
> +#endif

[Severity: Medium]
With CONFIG_IPV6_SUBTREES, can this find the PMTU exception for a
FLOWI_FLAG_KNOWN_NH clone of a source-specific route?

ip6_pol_route() makes the clone only for gateway-less nexthops, with
ip6_rt_cache_alloc(&res, &fl6->daddr, NULL), so its rt6i_src stays the
route's source prefix.

PMTU exceptions on the same gateway-less nexthop get the flow's source
address in ip6_rt_cache_alloc(), and are keyed by it:

	if (rt->rt6i_src.plen && saddr) {
		rt->rt6i_src.addr = *saddr;
		rt->rt6i_src.plen = 128;
	}

Here arg.saddr is the prefix. __rt6_find_cached_rt() falls back to
&f6i->fib6_src.addr, which is the same value, so both lookups miss and
ip6_dst_check() keeps passing the clone.

Before this patch, every exception insert called fib6_update_sernum(),
which invalidated such clones through the cookie. Is this a regression
for IPVS dest->dst_cache holders in that configuration?

The commit message says ip6_dst_check() fails an uncached RTF_CACHE dst
"when its nexthop has an exception for the dst's destination". That would
not hold here.

[ ... ]

> @@ -3808,7 +4319,7 @@ void fib6_nh_release_dsts(struct fib6_nh *fib6_nh)
>  		pcpu_rt = xchg(ppcpu_rt, NULL);
>  		if (pcpu_rt) {
>  			dst_dev_put(&pcpu_rt->dst);
> -			dst_release(&pcpu_rt->dst);
> +			rt6_dst_release_deferred(pcpu_rt);
>  		}
>  	}
>  }

[Severity: Low]
This looks like a separate fix for an existing use-after-free. Before this
patch, fib6_nh_release_dsts() called dst_dev_put() and then dropped the
reference immediately, which is open to the same NOREF reader and xfrm
child problem. Could it go into its own patch with a Fixes: tag, so that
stable can take it without this ~600-line redesign?

Also, the commit has "Reported-by: Ralf Lici <ralf@mandelbit.com>" but no
Fixes: or Closes: tag, while the earlier fix patches in the series have
them. Should one be added here?

[ ... ]

> @@ -2856,8 +3350,11 @@ INDIRECT_CALLABLE_SCOPE struct dst_entry *ip6_dst_check(struct dst_entry *dst,
>  
>  	rt = dst_rt6_info(dst);
>  
> -	if (READ_ONCE(rt->sernum))
> -		return rt6_is_valid(rt) ? dst : NULL;
> +	/* Any FIB change bumps the netns generation, which invalidates
> +	 * every dst created under an older one.
> +	 */
> +	if (!rt6_is_valid(rt))
> +		return NULL;
>  
>  	rcu_read_lock();
>  

[Severity: High]
Can this read rt->dst.dev after the device is gone? ip6_dst_check()
now calls rt6_is_valid() for every IPv6 dst, and it does so before
the rcu_read_lock() below. rt6_is_valid() does
dev_net(rt6->dst.dev) and then reads the netns generation, without
dst_dev_rcu() or dst_dev_net_rcu().

Some callers run in preemptible process context without RCU held:
sk_dst_check() in ip6_sk_dst_lookup_flow(), and __sk_dst_check() in
inet6_csk_xmit() and inet6_sk_rebuild_header().

With this patch, retired pcpu dsts and replaced exceptions stay on
the uncached list while sockets still hold them. On unregister,
rt6_uncached_list_flush_dev() or dst_dev_put() points dst->dev at
blackhole_netdev and drops the reference on the old device. A task
preempted after loading rt->dst.dev could then dereference a freed
net_device. The same applies to dev->nd_net when the device moves
to another netns.

The old code had the same unprotected read, but only for
nexthop-object pcpu dsts. Now it covers every dst.

Should the generation check move under the rcu_read_lock() and use
dst_dev_net_rcu()? Or should rt6_is_valid() take the lock itself?

[ ... ]

> @@ -1790,27 +1981,88 @@ static int rt6_insert_exception(struct rt6_info *nrt,
>  	if (f6i->fib6_src.plen)
>  		src_key = &nrt->rt6i_src.addr;
>  #endif
> +	if (old) {
> +		old_bucket = bucket;
> +		rt6_ex = __rt6_find_exception_spinlock(&old_bucket,
> +						       &nrt->rt6i_dst.addr,
> +						       src_key);
> +		if (!rt6_ex || rt6_ex->rt6i != old) {
> +			err = -EEXIST;
> +			goto out;
> +		}
> +		/* Before the copy: an in-place update of old that lands in
> +		 * between is then both in the copy and seen as a change after
> +		 * the swap, which merges it again, harmlessly.
> +		 */
> +		old_mtu = dst_metric_raw(&old->dst, RTAX_MTU);
> +		old_expires = READ_ONCE(old->dst.expires);

[Severity: Medium]
Can a refresh racing with rt6_do_update_pmtu() publish a copy that
has the lower PMTU but no expiry?

Take an exception that does not have RTF_EXPIRES yet, such as a
redirect. rt6_update_expires() writes dst.expires through
dst_set_expires() first, and only afterwards sets RTF_EXPIRES in
rt6i_flags.

Consider this ordering:

  - The MTU and the expiry are already stored on old when old_mtu
    and old_expires are sampled here.
  - RTF_EXPIRES is not yet set when rt6_exception_copy_state()
    reads old->rt6i_flags.

nrt then gets the lower MTU and RTF_MODIFIED, but no RTF_EXPIRES and
an expires of 0.

If the updater's lockless lookup in fib6_nh_update_exception() still
sees old in the table, it only refreshes the stamp. After the swap
and smp_mb(), the re-check compares only the MTU and expires against
the samples. Those have not changed, so rt6_exception_merge() is
skipped.

The published copy then keeps the learned PMTU and never expires it
after ip6_rt_mtu_expires, for as long as the exception stays in use.

Should old->rt6i_flags & RTF_EXPIRES be sampled together with
old_mtu and old_expires, and also be compared after the swap?

> +		err = rt6_exception_copy_state(nrt, old);
> +		if (err)
> +			goto out;
> +	}
> +
>  	/* rt6_mtu_change() might lower mtu on f6i.
>  	 * Only insert this exception route if its mtu
>  	 * is less than f6i's mtu value.
>  	 */
>  	if (dst_metric_raw(&nrt->dst, RTAX_MTU) >= fib6_mtu(res)) {
> -		err = -EINVAL;
> -		goto out;
> -	}
> -
> -	/* Allocate the new entry before the one it replaces is touched, so
> -	 * that running out of memory leaves what was learned in place.
> -	 */
> -	new_ex = kzalloc_obj(*new_ex, GFP_ATOMIC);
> -	if (!new_ex) {
> -		err = -ENOMEM;
> -		goto out;
> +		if (old && (old->rt6i_flags & RTF_DYNAMIC)) {
> +			/* A redirect whose PMTU was lowered in place and has
> +			 * since stopped lowering anything, e.g. after a device
> +			 * MTU change: the gateway is still worth keeping. Forget
> +			 * only the PMTU and carry the route's own MTU, as a new
> +			 * redirect exception would. The metrics are writable
> +			 * already (rt6_exception_copy_state()), so this cannot
> +			 * fail.
> +			 */
> +			dst_metric_set(&nrt->dst, RTAX_MTU, res->f6i->fib6_pmtu);
> +		} else {
> +			/* A stale exception that no longer lowers anything
> +			 * would fail every refresh from here on: drop it.
> +			 */
> +			if (old)
> +				rt6_remove_exception(old_bucket, rt6_ex);
> +			err = -EINVAL;
> +			goto out;
> +		}
>  	}
>  
>  	new_ex->rt6i = nrt;
>  	new_ex->stamp = jiffies;
>  
> +	if (old) {
> +		/* rt6_ex, found above, is old's entry. Swap in place: lockless
> +		 * lookups see either the old or the new exception and never
> +		 * a gap in which they would miss it and build a pcpu dst that
> +		 * ignores it, nothing invalidates pcpu dsts for a refresh, and
> +		 * the position in the chain, which route dumps count, and the
> +		 * depth do not change.
> +		 *
> +		 * Holders of old find out that it is stale when they next
> +		 * check it, so keep it working rather than dst_dev_put() it.
> +		 * Device unregister detaches it like any other uncached dst.
> +		 */
> +		hlist_replace_rcu(&rt6_ex->hlist, &new_ex->hlist);
> +
> +		/* An in-place PMTU update of old does not take the lock, and
> +		 * one that saw old still in the table does not merge (see
> +		 * fib6_nh_update_exception()). Pairs with smp_mb() there:
> +		 * either it sees nrt and merges into it under the lock, or
> +		 * this sees its update and merges it here. Only a change
> +		 * since the copy is merged, so the PMTU a redirect copy
> +		 * dropped above is not brought back.
> +		 */
> +		smp_mb();
> +		if (dst_metric_raw(&old->dst, RTAX_MTU) != old_mtu ||
> +		    READ_ONCE(old->dst.expires) != old_expires)
> +			rt6_exception_merge(nrt, old);
> +
> +		rt6_uncached_list_add(old);
> +		rt6_dst_release_deferred(old);
> +		kfree_rcu(rt6_ex, rcu);
> +		goto out;
> +	}
> +
>  	rt6_ex = __rt6_find_exception_spinlock(&bucket, &nrt->rt6i_dst.addr,
>  					       src_key);
>  	if (rt6_ex)

[Severity: High]
Can this make a NOREF caller think it holds a reference it never
took?

Before this series, the only dst ip6_pol_route() returned with
rt_uncached_list set was the FLOWI_FLAG_KNOWN_NH clone. That clone
always comes with a reference, even under RT6_LOOKUP_F_DST_NOREF.
Callers rely on this and use rt_uncached_list to tell whether they
own one:

  ip6_route_output_flags() skips dst_hold_safe() when it is set
  ip6_rt_put_flags(), used by fib6_rule_lookup() and the fib6 rule
    actions, calls ip6_rt_put() when it is set
  seg6_lookup_any_nexthop() uses skb_dst_set() instead of
    skb_dst_set_noref() when it is set

old was in the exception table until the swap above. Lockless
lookups on other CPUs may have just returned it without taking a
reference:

  CPU0: NOREF lookup in ip6_pol_route() returns exception E
  CPU1: refresh swaps in the copy, rt6_uncached_list_add(E),
        rt6_dst_release_deferred(E)
  CPU0: ip6_route_output_flags() sees rt_uncached_list set, skips
        dst_hold_safe() and returns E as if it held a reference

The caller then releases E, and the deferred release drops the
table's reference. The refcount underflows and E is freed while it
is still in use. ip6_rt_put_flags() and seg6_lookup_any_nexthop()
have the same problem.

The stale pcpu dst that rt6_get_pcpu_route() retires is put on the
uncached list in the same way.

Should the lookup report ownership directly, rather than callers
inferring it from rt_uncached_list afterwards? Or should a dst that
was published in a pcpu slot or the exception table be tracked for
device unregister in some other way?

[ ... ]

> @@ -1476,7 +1506,11 @@ static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res)
>  
>  	pcpu_rt = this_cpu_read(*res->nh->rt6i_pcpu);
>  
> -	if (pcpu_rt && READ_ONCE(pcpu_rt->sernum) && !rt6_is_valid(pcpu_rt)) {
> +	/* A dst stamped with an older genid stays stale for everyone still
> +	 * holding it, as in IPv4. Never re-stamp it; drop it and build a
> +	 * new one.
> +	 */
> +	if (pcpu_rt && !rt6_is_valid(pcpu_rt)) {
>  		struct rt6_info *prev, **p;
>  
>  		p = this_cpu_ptr(res->nh->rt6i_pcpu);

[Severity: High]
With nexthop objects, can rt6_get_pcpu_route() keep returning a
pcpu dst whose from has been cleared?

When a route that uses a shared nexthop object is deleted,
__fib6_drop_pcpu_from() clears pcpu_rt->from with xchg() on the
nexthop's pcpu dsts that came from it. It leaves them in rt6i_pcpu
and does not touch their sernum. rt6_make_pcpu_route() does the same
when it races with fib6_destroying. As far as I can see,
fib6_del_route() does not bump net->ipv6.fib6_sernum either.

So rt6_is_valid() still passes. Lookups of the other route sharing
the nexthop keep getting that dst from the slot.

Before this patch, ip6_dst_check() returned early for such dsts on
the generation alone. Now it falls through to rt6_check(rt, NULL),
which fails on every call. Sockets and dst_cache users then look the
route up again for every packet and get the same dst back. In
addition, __ip6_rt_update_pmtu() and rt6_do_redirect() bail out on a
NULL from, and RTM_GETROUTE for the destination fails with
-ENETUNREACH.

Should rt6_get_pcpu_route() also treat a NULL from as stale? Or
should __fib6_drop_pcpu_from() mark the dsts it orphans with
rt6_dst_invalidate()?

Relatedly, the commit message says every FIB change bumps the netns
generation. Does that hold for deletes? Two cases look like it does
not:

  - Removing an ECMP sibling rebalances the remaining siblings in
    rt6_multipath_rebalance().
  - Removing an RTN_THROW route changes which table a lookup ends
    in.

In both cases the dsts of the surviving routes keep a valid stamp
and a non-NULL fib6_node.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201174021.7211-1-dsahern%40kernel.org

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 07/13] ipv6: make rt_genid_bump_ipv6() a plain counter increment
  2026-12-01 17:40 ` [PATCH net-next v3 07/13] ipv6: make rt_genid_bump_ipv6() a plain counter increment David Ahern
@ 2026-12-05 19:20   ` netdev-bot+sashiko
  0 siblings, 0 replies; 31+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 19:20 UTC (permalink / raw)
  To: dsahern
  Cc: netdev, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	dahern, noreply

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In include/net/net_namespace.h, this patch changes
  rt_genid_bump_ipv6() from void to int.

--

ipv6: make rt_genid_bump_ipv6() a plain counter increment

This patch replaces the fib6_flush_trees() walk behind
rt_genid_bump_ipv6() with an increment of net->ipv6.fib6_sernum. The
increment wraps to 1 so the value is never 0. It also drops the
__fib6_flush_trees pointer and its export, fib6_new_sernum(), and the
sernum handling in fib6_cleaner.

> diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
> index 4a4d72080acdc..f39baf51bcc5d 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

[Severity: Low]
This isn't a bug, but the new comment on rt_genid_bump_ipv6() says the
return value is never 0. The !CONFIG_IPV6 stub added just below returns
exactly 0.

No current caller is affected. The callers that use the return value
are fib6_update_sernum(), fib6_update_sernum_upto_root() and fib6_add()
in net/ipv6/ip6_fib.c, which only builds with IPv6. Every other caller
ignores the result: rt_genid_bump_all(), xfrm_policy.c, nexthop.c,
addrconf.c and fib6_rules.c.

The later patch in the series, "ipv6: stamp dsts with the generation
sampled before the FIB lookup", adds rt_genid_ipv6_sample() but leaves
this comment and the stub unchanged.

Would it be clearer for the comment to say the non-zero guarantee holds
only with CONFIG_IPV6? Another option is to have the stub return a
non-zero value, so a future caller outside IPv6 can't rely on 0 meaning
something.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201174021.7211-1-dsahern%40kernel.org

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 09/13] nexthop: bump the IPv6 route generation on group changes
  2026-12-01 17:40 ` [PATCH net-next v3 09/13] nexthop: bump the IPv6 route generation on group changes David Ahern
@ 2026-12-05 19:20   ` netdev-bot+sashiko
  0 siblings, 0 replies; 31+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 19:20 UTC (permalink / raw)
  To: dsahern
  Cc: netdev, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	dahern, noreply

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

Critical: 0 · High: 0 · Medium: 1 · 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).

- [Medium] remove_nexthop_from_groups() in net/ipv4/nexthop.c decides
  whether to bump the IPv6 generation too early.
- [Low] The commit fixes two user-visible bugs: stale IPv6 dsts after
  replacing a member used only through a group, and after removing a…

--

nexthop: bump the IPv6 route generation on group changes

This commit bumps the netns IPv6 route generation in two more cases: when
a group member is replaced and IPv6 routes use it only through a group,
and when a member is removed from a group. The aim is that dsts built
from the old group no longer pass validation.

> diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
> index 53431fe7d3281..7cf496589f4f4 100644
> --- a/net/ipv4/nexthop.c
> +++ b/net/ipv4/nexthop.c

[ ... ]

> @@ -2134,13 +2150,19 @@ remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
>  	if (list_empty(&nh->grp_list))
>  		return false;
>  
> -	list_for_each_entry_safe(nhge, tmp, &nh->grp_list, nh_list)
> +	list_for_each_entry_safe(nhge, tmp, &nh->grp_list, nh_list) {
> +		have_f6i |= nh_has_f6i(nhge->nh_parent);
>  		need_flush |= remove_nh_grp_entry(net, nhge, nlinfo,
>  						  &deferred_free);
> +	}
>  
>  	/* make sure all see the newly published array before releasing rtnl */
>  	synchronize_net();
>  
> +	/* a group lost a member: dsts built from the old group are stale */
> +	if (have_f6i)
> +		rt_genid_bump_ipv6(net);
> +

[Severity: Medium]
Can the bump be skipped if an IPv6 route is added to the group while the
member is being removed?

have_f6i is read from the parent's f6i_list before remove_nh_grp_entry()
publishes the new array with rcu_assign_pointer(nhp->nh_grp, newg). It is
then used after synchronize_net().

IPv6 route insertion does not hold RTNL. RTM_NEWROUTE is registered with
RTNL_FLAG_DOIT_UNLOCKED, and ip6_route_info_create_nh() looks up the
nexthop under rcu_read_lock(). fib6_add_rt2node_nh() then links the route
into the group's f6i_list while holding only the group's nh->lock:

net/ipv6/ip6_fib.c:fib6_add_rt2node_nh() {
    ...
	list_add(&rt->nh_list, &rt->nh->f6i_list);
    ...
}

So with member X being deleted from group G, this sequence looks possible:

CPU0 (holds RTNL, deleting X)
remove_nexthop_from_groups()
    nh_has_f6i(G) returns false, have_f6i stays false

CPU1 (RTM_NEWROUTE with nhid=G)
fib6_add_rt2node_nh()
    route R is linked into G->f6i_list

CPU2
ip6_pol_route()
    finds R, selects a path from the old G->nh_grp, and builds a dst
    stamped with the current generation

CPU0
remove_nh_grp_entry()
    rcu_assign_pointer(nhp->nh_grp, newg);
synchronize_net()
    have_f6i is false, so rt_genid_bump_ipv6() is not called

The later "ipv6: stamp dsts with the generation sampled before the FIB
lookup" change does not help here. No bump follows the publish, so the
sampled generation is still current. rt6_is_valid() keeps passing until
some unrelated FIB change. This looks like the "dsts built from the old
group stayed valid" case that the commit message says it closes.

Two kinds of dst would stay valid:

- pcpu dsts through surviving members, built under the old
  hash-threshold or resilient mapping
- uncached FLOWI_FLAG_KNOWN_NH clones through the deleted member, which
  fib6_nh_release_dsts() does not reach

Pcpu dsts held in the deleted member's own rt6i_pcpu are released with
dst_dev_put() when X is freed, so they are not affected.

Could the decision be made after synchronize_net(), using the surviving
parents (the nh_parent of the entries on deferred_free)? Another option
is to bump every time a group loses a member, since rt_genid_bump_ipv6()
is now a plain counter update.

[ ... ]

> @@ -2264,7 +2286,8 @@ static void nh_rt_cache_flush(struct net *net, struct nexthop *nh,
>  	if (!list_empty(&nh->fi_list))
>  		rt_cache_flush(net);
>  
> -	if (nh_has_f6i(nh))
> +	/* dsts are validated against the netns route generation */
> +	if (nh_used_by_f6i(nh))
>  		rt_genid_bump_ipv6(net);

[Severity: Low]
This isn't a bug, but should this commit carry a Fixes: tag?

Both gaps predate this series. The check in nh_rt_cache_flush() that
looks only at the member's own f6i_list goes back to the original
nh_rt_cache_flush() in commit 7bf4796dd09984 ("nexthops: add support for
replace"). Blame also points at 4787a6d2629b4e. The baseline
remove_nexthop_from_groups() never bumps the IPv6 generation after
republishing a group.

Other fixes in this series have Fixes: tags. Examples are "ipv6: keep a
superseded pcpu dst working until its holders notice" and "ipv6: allocate
the exception entry before removing the one it replaces". Without a tag
here, stable maintainers cannot tell which kernels need this change.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201174021.7211-1-dsahern%40kernel.org

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 10/13] ipv6: stamp dsts with the generation sampled before the FIB lookup
  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-05 19:21   ` netdev-bot+sashiko
  0 siblings, 0 replies; 31+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 19:21 UTC (permalink / raw)
  To: dsahern
  Cc: netdev, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	dahern, noreply

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

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

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] The fix relies on a premise that some writers break.
- [Medium] The patch only partly closes the cached-dst race it describes
  (a cached dst built or refreshed by a later lookup after a FIB change,…
- [Low] The commit fixes a user-visible bug (a dst built from the old FIB
  passes ip6_dst_check() "indefinitely") and has a Reported-by: Ralf…
- [Low] The comment in rt6_get_cookie() (include/net/ip6_fib.h) still
  says "sernum is the netns route generation the dst was created under".

--

ipv6: stamp dsts with the generation sampled before the FIB lookup

This patch samples the netns IPv6 route generation before the FIB walk,
carries it in struct fib6_result, and stamps dsts built from that result
with the sample instead of the generation at allocation time. Cached pcpu
and exception dsts whose stamp differs from the sample are marked stale.
Dsts returned by fib6_rule_lookup() whose stamp moved during a multi-table
lookup are marked stale too, so that ip6_dst_check() fails for them.

> Reported-by: Ralf Lici <ralf@mandelbit.com>
> Signed-off-by: David Ahern <dahern@nvidia.com>

[Severity: Low]
Should this carry a Fixes: tag, and a Closes: link for the report?

For nexthop-object pcpu routes, folding a post-lookup generation into the
stamp seems to predate this series. At the baseline,
rt6_make_pcpu_route() runs this after the FIB has been read:

    pcpu_rt->sernum = rt_genid_ipv6(dev_net(dev));

That came in with commit 8f34e53b60b3 ("ipv6: Use global sernum for dst
validation with nexthop objects"). The fn_sernum cookie captured after
the lookup had the same window.

Other patches in this series name 8f34e53b60b3 in a Fixes: tag, for
example "ipv6: keep a superseded pcpu dst working until its holders
notice". Without a tag here, stable tooling may pick those up without
this one. checkpatch also warns when Reported-by: is not followed by
Closes:.

> diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
> index f39baf51bcc5d..31ffac7baf73e 100644
> --- a/include/net/net_namespace.h
> +++ b/include/net/net_namespace.h
> @@ -557,6 +557,16 @@ static inline int rt_genid_ipv6(const struct net *net)
>  	return atomic_read(&net->ipv6.fib6_sernum);
>  }
>  
> +/* Sample the generation before walking the FIB. Writers bump it after the
> + * route change is visible, so a lookup that sees the old tree cannot sample
> + * the new generation: whatever dst it builds carries a generation that
> + * fails ip6_dst_check() once the change lands.
> + */
> +static inline int rt_genid_ipv6_sample(const struct net *net)
> +{
> +	return atomic_read_acquire(&net->ipv6.fib6_sernum);
> +}

[Severity: High]
Do all writers bump the generation after the change is visible?

In net/ipv6/route.c, fib6_ifup() and fib6_ifdown() bump first. Only then
do they call rt6_multipath_rebalance(), which rewrites the
fib_nh_upper_bound values that multipath path selection reads:

net/ipv6/route.c:fib6_ifup() {
    ...
	rt->fib6_nh->fib_nh_flags &= ~arg->nh_flags;
	fib6_update_sernum_upto_root(net, rt);
	rt6_multipath_rebalance(rt);
    ...
}

net/ipv6/route.c:fib6_ifdown() {
    ...
	case NETDEV_CHANGE:
		...
		rt->fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN;
		fib6_update_sernum(net, rt);
		rt6_multipath_rebalance(rt);
		break;
    ...
}

The NETDEV_DOWN multipath case in fib6_ifdown() follows the same order
after rt6_multipath_nh_flags_set(). It then returns -2, so the siblings
are skipped and nothing bumps again after the rebalance.

fib6_select_path() reads the upper bounds with atomic_read() under RCU
only. rt6_score_route() does not reject RTNH_F_DEAD or RTNH_F_LINKDOWN
nexthops.

A lookup that runs between the bump and the rebalance could look like
this:

CPU1 (carrier loss)
addrconf_notify()
  rt6_sync_down_dev(dev, NETDEV_CHANGE)
    fib6_ifdown()
      fib_nh_flags |= RTNH_F_LINKDOWN
      fib6_update_sernum()           /* N -> N+1 */

CPU2
ip6_pol_route()
  fib6_table_lookup()
    rt_genid_ipv6_sample()           /* samples N+1 */
  fib6_select_path()                 /* reads old upper bounds */
  rt6_make_pcpu_route()              /* dst stamped N+1 */

CPU1
      rt6_multipath_rebalance()

With ignore_routes_with_linkdown set, could CPU2 pick the nexthop that
just went linkdown and still get a dst stamped N+1?

The new check at the out: label in ip6_pol_route() would not catch this,
and neither would fib6_rule_lookup_done(), because the stamp equals the
sample. For carrier changes, no later bump follows. Sockets and
dst_caches that captured the dst in that window would keep using the
linkdown nexthop until some unrelated FIB change in the netns.

Could the bump move after rt6_multipath_rebalance() at these sites? If
not, should the commit message and this comment stop claiming the
ordering holds for all writers?

[ ... ]

> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 959157896f980..8df141363e128 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -1214,6 +1214,12 @@ static void ip6_rt_copy_init(struct rt6_info *rt, const struct fib6_result *res)
>  	rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL;
>  	ip6_rt_init_dst(rt, res);
>  
> +	/* Pair the dst with the generation the FIB was read under, so a
> +	 * change between the lookup and this allocation is not folded in.
> +	 */
> +	if (res->sernum)
> +		rt->sernum = res->sernum;
> +

[Severity: Low]
This isn't a bug, but the comment in rt6_get_cookie() in
include/net/ip6_fib.h still describes the old meaning:

static inline u32 rt6_get_cookie(const struct rt6_info *rt)
{
	/* sernum is the netns route generation the dst was created under;
	 * ip6_dst_check() compares it to the current one.
	 */
	return READ_ONCE(rt->sernum);
}

With this override, sernum is the generation sampled before the FIB
walk. For exceptions built in __ip6_rt_update_pmtu() and
rt6_do_redirect(), it is the parent dst's generation, which can be older
than the one current at creation.

The RT6_SERNUM_STALE comment in the same header already says "the
generation it was built under". Should the rt6_get_cookie() comment be
updated to match?

> @@ -1299,6 +1305,7 @@ INDIRECT_CALLABLE_SCOPE struct rt6_info *ip6_pol_route_lookup(struct net *net,
>  	bool retry = false;
>  
>  	rcu_read_lock();
> +	res.sernum = rt_genid_ipv6_sample(net);
>  	fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
>  restart:
>  	res.f6i = rcu_dereference(fn->leaf);

[Severity: Medium]
Is the cached-dst race covered here when CONFIG_IPV6_MULTIPLE_TABLES is
not set?

ip6_pol_route() gets its own stamp-versus-sample check at its out:
label. ip6_pol_route_lookup() returns a cached exception without one:

	rt = rt6_find_cached_rt_refresh(&res, &fl6->daddr, &fl6->saddr,
					&retry);
	if (rt) {
		if (ip6_hold_safe(net, &rt))
			dst_use_noref(&rt->dst, jiffies);

This path depends on fib6_rule_lookup_done() in net/ipv6/fib6_rules.c.
That file is only built with CONFIG_IPV6_MULTIPLE_TABLES:

    ipv6-$(CONFIG_IPV6_MULTIPLE_TABLES) += fib6_rules.o

Without that option, fib6_rule_lookup() is the unchanged version in
net/ipv6/ip6_fib.c. It calls pol_lookup_func() on the main table and
returns &rt->dst with no sample and no check.

In that configuration, another CPU can refresh an exception after a FIB
change. __rt6_find_cached_rt() accepts it through rt6_is_valid(), and it
is returned with the newer stamp even though this lookup's decision
predates the change.

__ip6_route_redirect() appears to have the same gap. An exception found
through ip6_redirect_nh_match() is returned unchecked via
ip6_hold_safe(net, &ret). rt6_do_redirect() then copies its stamp into
the new redirect exception with res.sernum = rt6_dst_sernum(rt).

Would the check from ip6_pol_route() close this if it were added to
ip6_pol_route_lookup() and __ip6_route_redirect(), or to the ip6_fib.c
version of fib6_rule_lookup()?

	if (rt && rt6_dst_sernum(rt) != res.sernum)
		rt6_dst_invalidate(rt);

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201174021.7211-1-dsahern%40kernel.org

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 12/13] selftests: net: fib_tests: Add stale pcpu test
  2026-12-01 17:40 ` [PATCH net-next v3 12/13] selftests: net: fib_tests: Add stale pcpu test David Ahern
@ 2026-12-05 19:21   ` netdev-bot+sashiko
  0 siblings, 0 replies; 31+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 19:21 UTC (permalink / raw)
  To: dsahern
  Cc: netdev, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	dahern, noreply

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

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

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

- [Medium] In tools/testing/selftests/net/fib_tests.sh,
  ipv6_nh_pcpu_stale_test() skips only when `$(nproc)` is below 2 (line…

--

selftests: net: fib_tests: Add stale pcpu test

This adds an ipv6_nh_pcpu_stale test to fib_tests.sh. The test creates a
pcpu dst on CPU 0 for a route that uses a nexthop object, re-adds the
route, and then checks route lookups on CPUs 0 and 1. It covers the
regression fixed by commit 8f34e53b60b3 ("ipv6: Use global sernum for dst
validation with nexthop objects").

> diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
> index d7ac3c727f704..dc2ac5d7f29b7 100755
> --- a/tools/testing/selftests/net/fib_tests.sh
> +++ b/tools/testing/selftests/net/fib_tests.sh

[ ... ]

> @@ -3228,6 +3228,56 @@ ipv6_mpath_oif_vrf_test()
>  	cleanup
>  }
>  
> +ipv6_nh_pcpu_stale_test()
> +{

[ ... ]

> +	if [ $(nproc) -lt 2 ]; then
> +		echo "SKIP: pcpu test requires multiple cpus"
> +		return $ksft_skip
> +	fi
> +
> +	setup

[ ... ]

> +	# create a pcpu dst entry on cpu 0
> +	taskset -a -c 0 $IP -6 route get 2001:db8:11::1 &> /dev/null
> +
> +	# re-add the route entry
> +	$IP -6 route del 2001:db8:11::1
> +	$IP -6 route add 2001:db8:11::1/128 nhid 100
> +
> +	# cached dst on cpu 0 must have been invalidated
> +	for cpu in 0 1; do
> +		taskset -a -c $cpu $IP -6 route get 2001:db8:11::1 &> /dev/null
> +		log_test $? 0 "Route get on cpu $cpu after route re-add"
> +	done

[Severity: Medium]
Can ipv6_nh_pcpu_stale_test() report a FAIL when the kernel is working
correctly?

The skip check only looks at nproc. nproc counts the CPUs in the caller's
affinity mask, and GNU nproc also honours OMP_NUM_THREADS and
OMP_THREAD_LIMIT. A count of 2 or more does not mean that CPU 0 and CPU 1
exist, are online, or are allowed.

Some examples: a cpuset-limited container or CI runner with cpus 2-5, a
system where CPU 1 has been hot-unplugged, or a run started under
taskset -c 2,3.

In those cases sched_setaffinity() ends up with an empty mask and returns
EINVAL, so taskset exits non-zero without running ip. Because stderr goes
to /dev/null, log_test only sees the non-zero exit code. It then logs
"Route get on cpu N after route re-add" as a failure.

The test can also miss the regression it is meant to catch, because the
result of the priming lookup is never checked:

	taskset -a -c 0 $IP -6 route get 2001:db8:11::1 &> /dev/null

If pinning to CPU 0 fails, no pcpu dst is created on CPU 0. That means the
stale dst condition is never set up. The later CPU 0 check then fails in
taskset too, which hides the real cause.

Could the test pick two CPUs from the allowed set instead, for example by
parsing taskset -pc $$ or cpuset.cpus.effective? Another option is to skip
when CPUs 0 and 1 are not both usable. Checking the result of the priming
lookup would also help.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201174021.7211-1-dsahern%40kernel.org

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH net-next v3 13/13] selftests: net: ipvs: check a PMTU learned after the DR route was cached
  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-05 19:21   ` netdev-bot+sashiko
  0 siblings, 0 replies; 31+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 19:21 UTC (permalink / raw)
  To: dsahern
  Cc: netdev, idosch, davem, edumazet, kuba, pabeni, horms, ralf, ja,
	dahern, noreply

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

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

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

- [Medium] test_dr_v6_pmtu() in
  tools/testing/selftests/net/netfilter/ipvs.sh can pass on a kernel…
- [Low] The new top-level `checktool "python3 -c pass" "run test without
  python3"` in tools/testing/selftests/net/netfilter/ipvs.sh runs before…
- [Low] The commit message carries the trailer 'Co-Authored-By: Claude
  Sonnet 5.5 <noreply@anthropic.com>'.
- [Low] The header comment of udp_send_v6() in
  tools/testing/selftests/net/netfilter/ipvs.sh says it sends 'one UDP…
- [Low] test_dr_v6_pmtu() in
  tools/testing/selftests/net/netfilter/ipvs.sh never checks the exit…

--

selftests: net: ipvs: check a PMTU learned after the DR route was cached

This adds an IPv6 DR mode test to ipvs.sh. The test caches the director's
route to the real server, forges a packet too big message so the director
learns a PMTU for the real server, and then checks that an oversized
datagram gets a packet too big message back to the client. It also adds
CONFIG_IP_VS_IPV6 and CONFIG_IP_VS_PROTO_UDP to the netfilter selftest
config.

> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

[Severity: Low]
This isn't a bug, but Co-Authored-By is not in $signature_tags in
scripts/checkpatch.pl. Running checkpatch on this patch will warn
"Non-standard signature: Co-Authored-By:".

Documentation/process/coding-assistants.rst in this tree does not define an
AI attribution trailer. It also forbids an AI Signed-off-by, so
Co-developed-by can't be used either.

Could the attribution follow a convention the maintainers accept, or move
below the --- line?

> diff --git a/tools/testing/selftests/net/netfilter/ipvs.sh b/tools/testing/selftests/net/netfilter/ipvs.sh
> index 9c9d5b38ab712..556ce071035ec 100755
> --- a/tools/testing/selftests/net/netfilter/ipvs.sh
> +++ b/tools/testing/selftests/net/netfilter/ipvs.sh

[ ... ]

> @@ -54,6 +60,7 @@ fi
>  
>  checktool "ipvsadm -v" "run test without ipvsadm"
>  checktool "socat -h" "run test without socat"
> +checktool "python3 -c pass" "run test without python3"

[Severity: Low]
On a system without python3, does this skip the existing IPv4 DR, NAT and
tunnel tests as well? checktool() in netfilter/lib.sh exits the whole
script:

checktool (){
	if ! $1 > /dev/null 2>&1; then
		echo "SKIP: Could not $2"
		exit $ksft_skip
	fi
}

The IPv4 tests only need socat, and before this patch they ran without
python3. Only test_dr_v6_pmtu() uses python3, through udp_send_v6() and
send_ptb_v6().

Could the python3 check move into test_dr_v6_pmtu() so that only that test
is skipped?

[ ... ]

> @@ -169,6 +176,74 @@ test_tun() {
>  	test_service
>  }
>  
> +# Send one UDP datagram of ${2} bytes from the client to the IPv6 service and
> +# keep the socket open for a moment, so that a packet too big message for it
> +# is accepted.
> +udp_send_v6() {
> +	ip netns exec "${ns0}" python3 -c '
> +import socket, sys, time
> +s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
> +s.bind((sys.argv[1], 0))
> +s.sendto(b"x" * int(sys.argv[3]), (sys.argv[2], int(sys.argv[4])))
> +time.sleep(0.5)
> +' "${cip_v6}" "${vip_v6}" "${1}" "${port}"
> +}

[Severity: Low]
This isn't a bug, but the comment says the datagram is ${2} bytes. The size
actually comes from ${1}, which is passed as sys.argv[3]. Should the comment
say ${1}?

[ ... ]

> +test_dr_v6_pmtu() {

[ ... ]

> +	ip netns exec "${ns1}" ip addr add "${vip_v6}/128" dev lo nodad
> +	ip netns exec "${ns1}" ipvsadm -A -u "[${vip_v6}]:${port}" -s rr
> +	ip netns exec "${ns1}" ipvsadm -a -u "[${vip_v6}]:${port}" \
> +		-r "[${rip_v6}]:${port}" -g

[Severity: Low]
What happens here if ip_vs was built without CONFIG_IP_VS_IPV6? Neither
ipvsadm call has its exit status checked, so the test carries on with no
service.

The datagrams to vip_v6 would then be delivered locally in ns1. Nothing
listens on the port there, and they are never forwarded to the real server.

The first check still passes. ns1 learns the PMTU from the forged packet
too big through icmpv6_err()->ip6_update_pmtu(), without IPVS being
involved.

The second check then reports "FAIL: director kept using a route that
bypasses the learned PMTU", which points at route caching instead of the
missing IPVS feature. The config fragment in this patch covers CI builds,
but other configs would hit this.

Should a failed ipvsadm call make the test skip, or fail with a message
that names the real cause?

> +
> +	ip netns exec "${ns2}" ip addr add "${rip_v6}/64" dev veth21 nodad
> +	ip netns exec "${ns2}" ip addr add "${vip_v6}/128" dev lo nodad
> +
> +	# Let the director cache its route to the real server
> +	udp_send_v6 100
> +
> +	send_ptb_v6 1280
> +	sleep 0.2
> +	if ! ip netns exec "${ns1}" ip -6 route get "${rip_v6}" | grep -q "mtu 1280"; then
> +		echo "FAIL: director did not learn the PMTU of the real server"
> +		return 1
> +	fi
> +
> +	# A datagram that exceeds the PMTU must be answered with a packet too
> +	# big message, which gives the client a PMTU for the service
> +	udp_send_v6 1400
> +	if ! ip netns exec "${ns0}" ip -6 route get "${vip_v6}" | grep -q "mtu 1280"; then
> +		echo "FAIL: director kept using a route that bypasses the learned PMTU"
> +		return 1
> +	fi
> +}

[Severity: Medium]
Can this test pass on a kernel that lacks the ip6_dst_check() behaviour it
is meant to cover?

setup() brings up veth10 and veth12 in ns1 and then waits only one second:

	ip netns exec "${ns1}" ip link set veth10 up
	...
	ip netns exec "${ns1}" ip link set veth12 up
	...
	sleep 1

setup_ns() does not disable accept_dad, so the link-local addresses on
veth10 and veth12 are still tentative at that point.

addrconf_dad_kick() waits a random delay of up to rtr_solicit_delay (1s)
before the first NS. DAD succeeds RETRANS_TIME (1s) after that, so each
interface finishes DAD somewhere between 1s and 2s after link up.

When DAD completes, addrconf_dad_completed() calls rt_genid_bump_ipv6().
__ipv6_ifa_notify() then inserts the host route with ip6_ins_rt(), and
fib6_add() bumps the generation again.

ip6_dst_check() checks the generation before it gets to the exception
check:

net/ipv6/route.c:ip6_dst_check() {
	...
	if (!rt6_is_valid(rt))
		return NULL;
	...
			     rt6_uncached_clone_superseded(rt, from)))
	...
}

Suppose an ns1 link-local address finishes DAD after "udp_send_v6 100" and
before "udp_send_v6 1400". The cached dst then fails the check for an
unrelated reason.

__ip_vs_get_out_rt_v6() looks the route up again through
ip6_route_output() and picks up the 1280 MTU exception. The client gets a
packet too big message whether or not rt6_uncached_clone_superseded()
works.

The window between the two sends runs from roughly 1.1-1.6s to roughly
2.0-2.6s after link up. That covers most of the DAD completion range for
both ns1 interfaces, so a false pass seems likely on most runs.

Would setting accept_dad=0 in ns1 before the links come up make this
deterministic? Another option is to wait until
"ip -n $ns1 -6 addr show tentative" is empty before the first
udp_send_v6.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201174021.7211-1-dsahern%40kernel.org

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2026-12-05 19:21 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-02 16:02   ` Ido Schimmel
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-02 16:19   ` Ido Schimmel
2026-12-05 19:20   ` netdev-bot+sashiko
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-05 19:20   ` netdev-bot+sashiko
2026-12-01 17:40 ` [PATCH net-next v3 04/13] ipv6: invalidate the failing dst in ip6_link_failure() David Ahern
2026-12-05 19:20   ` netdev-bot+sashiko
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-05 19:20   ` netdev-bot+sashiko
2026-12-01 17:40 ` [PATCH net-next v3 06/13] ipv6: validate dsts against the netns route generation David Ahern
2026-12-05 19:20   ` netdev-bot+sashiko
2026-12-01 17:40 ` [PATCH net-next v3 07/13] ipv6: make rt_genid_bump_ipv6() a plain counter increment David Ahern
2026-12-05 19:20   ` netdev-bot+sashiko
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-05 19:20   ` netdev-bot+sashiko
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-05 19:21   ` netdev-bot+sashiko
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-05 19:21   ` netdev-bot+sashiko
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-05 19:21   ` netdev-bot+sashiko
2026-12-01 17:43 ` [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation netdev-bot+sinfo
2026-12-02  9:45 ` Ralf Lici
2026-12-03 15:34 ` Ido Schimmel
2026-12-03 16:55   ` Ralf Lici
2026-12-03 17:16     ` Ido Schimmel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox