Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by David Ahern
Tue, 01 Dec 2026 17:40
[PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation
Author: David Ahern
Date: Tue, 01 Dec 2026 17:40
Date: Tue, 01 Dec 2026 17:40
100 lines
12634 bytes
12634 bytes
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)
[PATCH net-next v3 01/13] ipv6: allocate the exception entry before removing the one it replaces
Author: David Ahern
Date: Tue, 01 Dec 2026 17:40
Date: Tue, 01 Dec 2026 17:40
67 lines
9801 bytes
9801 bytes
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)
[PATCH net-next v3 03/13] ipv6: don't insert a PMTU exception whose MTU could not be stored
Author: David Ahern
Date: Tue, 01 Dec 2026 17:40
Date: Tue, 01 Dec 2026 17:40
125 lines
12284 bytes
12284 bytes
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)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads