From: Ralf Lici <ralf@mandelbit.com>
To: netdev@vger.kernel.org
Cc: David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>,
linux-kernel@vger.kernel.org, David Ahern <dahern@nvidia.com>,
Andrea Mayer <andrea.mayer@uniroma2.it>,
Antonio Quartulli <antonio@mandelbit.com>
Subject: [PATCH net-next 1/2] ipv6: base dst ownership on RT6_LOOKUP_F_DST_NOREF only
Date: Fri, 4 Dec 2026 12:29:27 +0100 [thread overview]
Message-ID: <4ce33518174bd6b736b3535b3e3ede02c6d23184.1796382820.git.ralf@mandelbit.com> (raw)
In-Reply-To: <cover.1796382820.git.ralf@mandelbit.com>
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
next prev parent reply other threads:[~2026-12-04 11:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-12-05 12:31 ` [PATCH net-next 1/2] ipv6: base dst ownership on RT6_LOOKUP_F_DST_NOREF only netdev-bot+sashiko
2026-12-04 11:29 ` [PATCH net-next 2/2] ipv6: keep a superseded pcpu dst working until its holders notice Ralf Lici
2026-12-05 12:31 ` netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4ce33518174bd6b736b3535b3e3ede02c6d23184.1796382820.git.ralf@mandelbit.com \
--to=ralf@mandelbit.com \
--cc=andrea.mayer@uniroma2.it \
--cc=antonio@mandelbit.com \
--cc=dahern@nvidia.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®