From nobody Wed Apr 1 14:08:45 2026 Received: from smtp.uniroma2.it (smtp.uniroma2.it [160.80.4.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD66D382291; Tue, 31 Mar 2026 11:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=160.80.4.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774955343; cv=none; b=M6u/cZJcReC5xL4t+Q8VfkEn4lGjMUiOmtTxS4x/mCkYHz5RQYiNsqFbaK+QgsNt00y9nw7O6JPB/a+f1FoDlMD8aMAawf3k2pHo8AehHRMM4q1ZIQX4+v5cDjkSaGMj0FqCrRpKqTPqWCQPSCgqN0IgEnyOmXM6k681F+se0iU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774955343; c=relaxed/simple; bh=BXG8Bu6i2xDjEdXY6/EET2czNFEIOq399DPvup3QsTY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rWlFxqCYg8VqhoGvoxtp7BGf/z2xwGcD16yJh6YMd6tTiHhTs2UiOiv7oZ6C52aKz9AlXym40JrjAuxDQO/wWio3IhXlL6hQgwIV17kmTJ2at4ksRv1V31RLSIuAi1WUkkAMYtSLoi6rkcXzz7ooSneIdvSzW2TvywtYnf2iuQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniroma2.it; spf=pass smtp.mailfrom=uniroma2.it; arc=none smtp.client-ip=160.80.4.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniroma2.it Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniroma2.it Received: from localhost.localdomain ([160.80.103.126]) by smtp-2015.uniroma2.it (8.14.4/8.14.4/Debian-8) with ESMTP id 62VB8VKI008582; Tue, 31 Mar 2026 13:08:38 +0200 From: Andrea Mayer To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, dsahern@kernel.org, david.lebrun@uclouvain.be, stefano.salsano@uniroma2.it, paolo.lungaroni@uniroma2.it, nicolas.dichtel@6wind.com, linux-kernel@vger.kernel.org, Andrea Mayer , stable@vger.kernel.org Subject: [PATCH net 1/2] seg6: separate dst_cache for input and output paths in seg6 lwtunnel Date: Tue, 31 Mar 2026 13:07:54 +0200 Message-Id: <20260331110755.25042-2-andrea.mayer@uniroma2.it> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260331110755.25042-1-andrea.mayer@uniroma2.it> References: <20260331110755.25042-1-andrea.mayer@uniroma2.it> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: clamav-milter 0.100.0 at smtp-2015 X-Virus-Status: Clean Content-Type: text/plain; charset="utf-8" The seg6 lwtunnel uses a single dst_cache per encap route, shared between seg6_input_core() and seg6_output_core(). These two paths can perform the post-encap SID lookup in different routing contexts (e.g., ip rules matching on the ingress interface, or VRF table separation). Whichever path runs first populates the cache, and the other reuses it blindly, bypassing its own lookup. Fix this by splitting the cache into cache_input and cache_output, so each path maintains its own cached dst independently. Fixes: 6c8702c60b88 ("ipv6: sr: add support for SRH encapsulation and injec= tion with lwtunnels") Cc: stable@vger.kernel.org Signed-off-by: Andrea Mayer Reviewed-by: Nicolas Dichtel --- net/ipv6/seg6_iptunnel.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c index 3e1b9991131a..d6a0f7df9080 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -48,7 +48,8 @@ static size_t seg6_lwt_headroom(struct seg6_iptunnel_enca= p *tuninfo) } =20 struct seg6_lwt { - struct dst_cache cache; + struct dst_cache cache_input; + struct dst_cache cache_output; struct seg6_iptunnel_encap tuninfo[]; }; =20 @@ -488,7 +489,7 @@ static int seg6_input_core(struct net *net, struct sock= *sk, slwt =3D seg6_lwt_lwtunnel(lwtst); =20 local_bh_disable(); - dst =3D dst_cache_get(&slwt->cache); + dst =3D dst_cache_get(&slwt->cache_input); local_bh_enable(); =20 err =3D seg6_do_srh(skb, dst); @@ -504,7 +505,7 @@ static int seg6_input_core(struct net *net, struct sock= *sk, /* cache only if we don't create a dst reference loop */ if (!dst->error && lwtst !=3D dst->lwtstate) { local_bh_disable(); - dst_cache_set_ip6(&slwt->cache, dst, + dst_cache_set_ip6(&slwt->cache_input, dst, &ipv6_hdr(skb)->saddr); local_bh_enable(); } @@ -564,7 +565,7 @@ static int seg6_output_core(struct net *net, struct soc= k *sk, slwt =3D seg6_lwt_lwtunnel(orig_dst->lwtstate); =20 local_bh_disable(); - dst =3D dst_cache_get(&slwt->cache); + dst =3D dst_cache_get(&slwt->cache_output); local_bh_enable(); =20 err =3D seg6_do_srh(skb, dst); @@ -591,7 +592,7 @@ static int seg6_output_core(struct net *net, struct soc= k *sk, /* cache only if we don't create a dst reference loop */ if (orig_dst->lwtstate !=3D dst->lwtstate) { local_bh_disable(); - dst_cache_set_ip6(&slwt->cache, dst, &fl6.saddr); + dst_cache_set_ip6(&slwt->cache_output, dst, &fl6.saddr); local_bh_enable(); } =20 @@ -701,11 +702,13 @@ static int seg6_build_state(struct net *net, struct n= lattr *nla, =20 slwt =3D seg6_lwt_lwtunnel(newts); =20 - err =3D dst_cache_init(&slwt->cache, GFP_ATOMIC); - if (err) { - kfree(newts); - return err; - } + err =3D dst_cache_init(&slwt->cache_input, GFP_ATOMIC); + if (err) + goto err_free_newts; + + err =3D dst_cache_init(&slwt->cache_output, GFP_ATOMIC); + if (err) + goto err_destroy_input; =20 memcpy(&slwt->tuninfo, tuninfo, tuninfo_len); =20 @@ -720,11 +723,20 @@ static int seg6_build_state(struct net *net, struct n= lattr *nla, *ts =3D newts; =20 return 0; + +err_destroy_input: + dst_cache_destroy(&slwt->cache_input); +err_free_newts: + kfree(newts); + return err; } =20 static void seg6_destroy_state(struct lwtunnel_state *lwt) { - dst_cache_destroy(&seg6_lwt_lwtunnel(lwt)->cache); + struct seg6_lwt *slwt =3D seg6_lwt_lwtunnel(lwt); + + dst_cache_destroy(&slwt->cache_input); + dst_cache_destroy(&slwt->cache_output); } =20 static int seg6_fill_encap_info(struct sk_buff *skb, --=20 2.20.1