From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.61 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383792; b=okCfqbTaRjfbSydAzuFKwtbVbut9VVIc0eOR4niQQjde+sxfekOWKBhH7QUEl4SxZfca OSyYGA//165jNIzoRWNMIL0VSIC/j2KEPsdPaRfE+zx9jsltg1aHGerhlYvD3pPPea2Kc YQx56PhqwTVNqa2hDNzaRPjCMnykCorAnimFDFBR8rHxxQwcsa+0e3KLwPYmru+VsQg4o n/HuE0I9N4ozz3iVF2pA1KJeRN95vCxRpG8L/EwTBtQ2vRMZOY+2ECGYdV+aVmXXOYOUV j6cmsx3s7Rg9jKXamgpf6NXsIVj1qkXN7jCUKLiYw0K/PiA4NsbRW3Y+0xTF2w9bdaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383792; h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Rspamd-Queue-Id; bh=iEG+ZT2QMfcHpJ5mB52J/vEQHS8mCkzPQpxNYJaDIro=; b=yB1tZxarDCznPOSK3i7VmqsqJ/ddk8i2EsFiT13hKK8h1uRu6k57iWg3KrHCiTLHun77 UTftVe/8smZl9e3ML7qDqSHp3r2FjKbRlQTd2rAN+VrKKXPt/aPgbUa7L0ebBymwpte0T bqGuf1HOn9AHbks+UZu2MtnXTgRdNgHha0sSeAemDGuPFpivgDWx85EEqHv1gA5eKnLs1 Rj4kdYtoA+I6CZGXK7bX7hCS4yE20XGRoztjbcT9qHj8dqnBPzhL9+66Ov0K+nm6aS/Lm XNszBCHd+emyiq1bkfZbpkySujJE6Ml4HsAGxBJ9vqeQvcYfWvehsSUYaClvF9FW2xw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=mandelbit.com; spf=pass smtp.mailfrom=mandelbit.com; dkim=pass header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=qiKT894v; arc=none smtp.remote-ip=195.10.208.61 Received: from mout-b-201.mailbox.org (mout-b-201.mailbox.org [195.10.208.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94638606A335; Fri, 4 Dec 2026 11:29:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 94638606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mandelbit.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mandelbit.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=qiKT894v Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-201.mailbox.org (Postfix) with ESMTPS id 4jgq5x4dRhzLmhK; Fri, 04 Dec 2026 12:29:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1796383781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iEG+ZT2QMfcHpJ5mB52J/vEQHS8mCkzPQpxNYJaDIro=; b=qiKT894vFA65mSdZcXsJkdz31SxtmiJ3YDbQ4iKBaBeI1uUL6lMgNcyT1sIyglJHd90YVx WkaBLmoAwb9ooCkPNiGXlY5qnH0dtMTfovP1LbgwJMy36/XuK8m+Fy4RvM/watAp5ycmxS FddUgXOI2G7kXxjvFm4/dcSiCi8qBwh2cXH/RHsyWTMLYFER+rS94VtIVvoV4XZBRTYjyv PUpcKx8DWtdY3carEPM4z8SEGW7CZNjVcghVWSDkfCZph8d+E2A1T0WiAa66bnnlNhkVFZ iM0gU08w8gp4uyC1MQdX4kcXuNv8St5GNm/SNQjQt92oVom97no3hHM6Xe2alg== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::1 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: netdev@vger.kernel.org Cc: David Ahern , Ido Schimmel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , linux-kernel@vger.kernel.org, David Ahern , Andrea Mayer , Antonio Quartulli 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 Message-ID: <4ce33518174bd6b736b3535b3e3ede02c6d23184.1796382820.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4jgq5x4dRhzLmhK 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 Link: https://lore.kernel.org/netdev/20261202161942.GA2800642@shredder/ Signed-off-by: Ralf Lici --- 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