* [PATCH net-next 1/2] ipv6: base dst ownership on RT6_LOOKUP_F_DST_NOREF only
2026-12-04 11:29 [PATCH net-next 0/2] ipv6: move superseded pcpu dsts to the uncached list Ralf Lici
@ 2026-12-04 11:29 ` Ralf Lici
2026-12-04 11:29 ` [PATCH net-next 2/2] ipv6: keep a superseded pcpu dst working until its holders notice Ralf Lici
1 sibling, 0 replies; 3+ messages in thread
From: Ralf Lici @ 2026-12-04 11:29 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
linux-kernel, David Ahern, Andrea Mayer, Antonio Quartulli
A lookup with RT6_LOOKUP_F_DST_NOREF returns a dst without a reference,
except for the uncached RTF_CACHE clone of the FLOWI_FLAG_KNOWN_NH path,
whose allocation reference goes to the caller. Callers tell the two
apart by the dst's membership in the uncached list:
ip6_route_output_flags, ip6_rt_put_flags and seg6_lookup_any_nexthop.
That membership cannot mark ownership once a dst returned without a
reference can be moved to the uncached list afterwards, as a replaced
per-CPU dst still in use should be. The caller would then assume a
reference it does not have.
Base ownership on the flag only. A RT6_LOOKUP_F_DST_NOREF caller never
owns a reference, and the allocation reference of an uncached clone is
dropped after a grace period instead, so that the dst stays valid for
the caller's RCU section.
The deferred release reuses dst->rcu_head. The dst only queues it when
its last reference is dropped, which cannot happen while the deferred
reference is still held, and by the time the callback drops that
reference the head is no longer queued.
This is needed to put replaced per-CPU dsts on the uncached list, which
the next patch does for nexthop objects and a later change to dst
validation does for all routes.
Suggested-by: Ido Schimmel <idosch@nvidia.com>
Link: https://lore.kernel.org/netdev/20261202161942.GA2800642@shredder/
Signed-off-by: Ralf Lici <ralf@mandelbit.com>
---
include/net/ip6_route.h | 7 ++-----
net/ipv6/route.c | 32 +++++++++++++++++++++++---------
net/ipv6/seg6_local.c | 2 +-
3 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
index 95f936be32c6..d5ef35899b34 100644
--- a/include/net/ip6_route.h
+++ b/include/net/ip6_route.h
@@ -100,13 +100,10 @@ static inline struct dst_entry *ip6_route_output(struct net *net,
return ip6_route_output_flags(net, sk, fl6, 0);
}
-/* Only conditionally release dst if flags indicates
- * !RT6_LOOKUP_F_DST_NOREF or dst is uncached.
- */
+/* Release the dst unless it was looked up with RT6_LOOKUP_F_DST_NOREF */
static inline void ip6_rt_put_flags(struct rt6_info *rt, int flags)
{
- if (!(flags & RT6_LOOKUP_F_DST_NOREF) ||
- rt->dst.rt_uncached_list)
+ if (!(flags & RT6_LOOKUP_F_DST_NOREF))
ip6_rt_put(rt);
}
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index d3c77941d2cf..39bcfa1ce01b 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -147,6 +147,21 @@ void rt6_uncached_list_add(struct rt6_info *rt)
spin_unlock_bh(&ul->lock);
}
+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 reference after a grace period, so that RCU readers that found the
+ * dst without one can still use it and take their own.
+ */
+static void rt6_dst_release_deferred(struct rt6_info *rt)
+{
+ call_rcu(&rt->dst.rcu_head, rt6_dst_release_rcu);
+}
+
void rt6_uncached_list_del(struct rt6_info *rt)
{
struct uncached_list *ul = rt->dst.rt_uncached_list;
@@ -2310,12 +2325,14 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
rt = ip6_rt_cache_alloc(&res, &fl6->daddr, NULL);
if (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
- * if caller sets RT6_LOOKUP_F_DST_NOREF flag.
- */
rt6_uncached_list_add(rt);
+ /* A RT6_LOOKUP_F_DST_NOREF caller does not inherit the
+ * reference ip6_rt_cache_alloc returned. Dropping it
+ * after a grace period keeps the dst alive for the
+ * caller's RCU section.
+ */
+ if (flags & RT6_LOOKUP_F_DST_NOREF)
+ rt6_dst_release_deferred(rt);
rcu_read_unlock();
return rt;
@@ -2715,13 +2732,10 @@ struct dst_entry *ip6_route_output_flags(struct net *net,
int flags)
{
struct dst_entry *dst;
- struct rt6_info *rt6;
rcu_read_lock();
dst = ip6_route_output_flags_noref(net, sk, fl6, flags);
- rt6 = dst_rt6_info(dst);
- /* For an uncached dst, refcnt is already taken. */
- if (!rt6->dst.rt_uncached_list && !dst_hold_safe(dst)) {
+ if (!dst_hold_safe(dst)) {
dst = &net->ipv6.ip6_null_entry->dst;
dst_hold(dst);
}
diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c
index cd93b72a0b22..a774619221a2 100644
--- a/net/ipv6/seg6_local.c
+++ b/net/ipv6/seg6_local.c
@@ -404,7 +404,7 @@ seg6_lookup_any_nexthop(struct sk_buff *skb, struct in6_addr *nhaddr,
}
skb_dst_drop(skb);
- if ((flags & RT6_LOOKUP_F_DST_NOREF) && !dst->rt_uncached_list)
+ if (flags & RT6_LOOKUP_F_DST_NOREF)
skb_dst_set_noref(skb, dst);
else
skb_dst_set(skb, dst);
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH net-next 2/2] ipv6: keep a superseded pcpu dst working until its holders notice
2026-12-04 11:29 [PATCH net-next 0/2] ipv6: move superseded pcpu dsts to the uncached list Ralf Lici
2026-12-04 11:29 ` [PATCH net-next 1/2] ipv6: base dst ownership on RT6_LOOKUP_F_DST_NOREF only Ralf Lici
@ 2026-12-04 11:29 ` Ralf Lici
1 sibling, 0 replies; 3+ messages in thread
From: Ralf Lici @ 2026-12-04 11:29 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
linux-kernel, David Ahern, Andrea Mayer, Antonio Quartulli
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.
Drop the slot's reference after a grace period too. A lookup with
RT6_LOOKUP_F_DST_NOREF may have taken the dst from the slot without a
reference, and when the only other reference is the child reference of
an xfrm bundle, dst_destroy releases it with dst_release_immediate and
frees the dst under that lookup.
A later change to dst validation replaces the per-CPU dsts of all
routes the same way.
Reported-by: Ralf Lici <ralf@mandelbit.com>
Closes: https://lore.kernel.org/netdev/20261124204623.45969-1-ralf@mandelbit.com/
Signed-off-by: David Ahern <dahern@nvidia.com>
Link: https://lore.kernel.org/netdev/20261201174021.7211-3-dsahern@kernel.org/
[ralf: drop the slot's reference after a grace period, drop the comment
and the Fixes tag]
Signed-off-by: Ralf Lici <ralf@mandelbit.com>
---
net/ipv6/route.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 39bcfa1ce01b..df4d670bcfa6 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1499,8 +1499,8 @@ 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);
- dst_release(&prev->dst);
+ rt6_uncached_list_add(prev);
+ rt6_dst_release_deferred(prev);
}
pcpu_rt = NULL;
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread