From nobody Mon Nov 25 07:28:34 2024 Received: from serv108.segi.ulg.ac.be (serv108.segi.ulg.ac.be [139.165.32.111]) (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 9C4FB188704; Tue, 19 Nov 2024 22:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=139.165.32.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732054919; cv=none; b=Sk0ilprGot6hWoNlJBQg6bz/l9KtVJG5HKUueVg5gW97d7MGgDj87+IETaUZCdbGQMUpTj9lIv5YmkeCvl0Q7GpbS1OSYrwmTKOBw10dkhndOfm9Q/cHiOAF4TOKk+CFnlTnL09wQae0oQVEvBZTlGPxwmcjjJJ1JQ3SnqJcHME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732054919; c=relaxed/simple; bh=cF1iOYXgx7EUZBi/kFYrkWmAEw8t0MrdXPp2O/hCa+U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TkEGOuguRAC+lNKMJl4UaVbk3GYoSz6gAm3e9pjq8TgNo2Vdl0btYoDs26X6o0I2MYr3M8btvvfqCnQeArOsVNwLX88tWUEq6BrTGXAi0Ea+PVP43idXhMS0IRm89jTCypyGdMpEy2tiQ6cwLAvkId+u9dExy/KKELt928i3rbk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uliege.be; spf=pass smtp.mailfrom=uliege.be; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b=WerwblkY; arc=none smtp.client-ip=139.165.32.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uliege.be Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uliege.be Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b="WerwblkY" Received: from ubuntu.home (220.24-245-81.adsl-dyn.isp.belgacom.be [81.245.24.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by serv108.segi.ulg.ac.be (Postfix) with ESMTPSA id 62B9B200CCF3; Tue, 19 Nov 2024 23:21:50 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be 62B9B200CCF3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be; s=ulg20190529; t=1732054910; bh=to687Gkwrc1hnQQoEgmLYx3ysEJ7wdMxa7NT5CZGMhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WerwblkYCjfYkSMiAfJdKYlb3ZEkL1aXboxG3JjQQNo2IVyfSDc2v6B6r2WkXkrWn 9vUxRtdr3InrhOSsBPPhbkotK4G1TU1emw5LFLge97hNA8quu+eI57hVxkasSaAU+e E/ZJrUf3RlfKogS58f7s2QBWgs8Cu45kpUBzZCMOVE9Rx1pYovwbJZCIcpcOO4kvif fARCPu44F50f8/EWxFYVcLa+UKB0ejetM8MCJEO6+fXbel9viBfhgaK93IFzAWJpUT +7fMkn9jReq57K9WHfOINuoutJGP44rFE3fBmOZpyg/Kok29Eard++3MFHl2XFjldi p1KS8LscOkv9A== From: Justin Iurman To: netdev@vger.kernel.org Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, linux-kernel@vger.kernel.org, justin.iurman@uliege.be, Alexander Lobakin , Vadim Fedorenko Subject: [PATCH net-next v5 1/4] include: net: add static inline dst_dev_overhead() to dst.h Date: Tue, 19 Nov 2024 23:21:36 +0100 Message-Id: <20241119222139.14338-2-justin.iurman@uliege.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241119222139.14338-1-justin.iurman@uliege.be> References: <20241119222139.14338-1-justin.iurman@uliege.be> 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 Content-Type: text/plain; charset="utf-8" Add static inline dst_dev_overhead() function to include/net/dst.h. This helper function is used by ioam6_iptunnel, rpl_iptunnel and seg6_iptunnel to get the dev's overhead based on a cache entry (dst_entry). If the cache is empty, the default and generic value skb->mac_len is returned. Otherwise, LL_RESERVED_SPACE() over dst's dev is returned. Signed-off-by: Justin Iurman Cc: Alexander Lobakin Cc: Vadim Fedorenko --- include/net/dst.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/net/dst.h b/include/net/dst.h index 0f303cc60252..08647c99d79c 100644 --- a/include/net/dst.h +++ b/include/net/dst.h @@ -440,6 +440,15 @@ static inline void dst_set_expires(struct dst_entry *d= st, int timeout) dst->expires =3D expires; } =20 +static inline unsigned int dst_dev_overhead(struct dst_entry *dst, + struct sk_buff *skb) +{ + if (likely(dst)) + return LL_RESERVED_SPACE(dst->dev); + + return skb->mac_len; +} + INDIRECT_CALLABLE_DECLARE(int ip6_output(struct net *, struct sock *, struct sk_buff *)); INDIRECT_CALLABLE_DECLARE(int ip_output(struct net *, struct sock *, --=20 2.34.1 From nobody Mon Nov 25 07:28:34 2024 Received: from serv108.segi.ulg.ac.be (serv108.segi.ulg.ac.be [139.165.32.111]) (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 EBD9E1C1F08; Tue, 19 Nov 2024 22:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=139.165.32.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732054922; cv=none; b=mCD2norhexbpJRAkTC3vhqDcdraRKXOaMOMglTFypb43uYF1OwAFa3OjzG5HAx6ebUb/9AoC5tPpb1N5nn05iI4kYdwryVssRnxmcA66wHBeSQ4dyprRQ7H53QfXIcFcvAdiOC4iIGQMS1XjSeIXSa45eM4u4XK46KO8MB/JPp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732054922; c=relaxed/simple; bh=NxyQcAFC+EIcEx4ym0rUYYFqK38LZuoe4X6+NBqzFI8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hbULoAd85HiJK08hwQwLY827sFg5tLQldbUU0U7ofO3XLUXwqSMSqzddT8oY58zJGin/ZQAL2eY+JtFoGHKi27i5XkkIzWkIpTEnTtHL5zGji+Wq2iR42NSMpqxRmQ+tYBJn3XVR8T8YL6i8tXG2xYPVGCHQI4IYHikTJFt29Fc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uliege.be; spf=pass smtp.mailfrom=uliege.be; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b=iveLdEh3; arc=none smtp.client-ip=139.165.32.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uliege.be Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uliege.be Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b="iveLdEh3" Received: from ubuntu.home (220.24-245-81.adsl-dyn.isp.belgacom.be [81.245.24.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by serv108.segi.ulg.ac.be (Postfix) with ESMTPSA id ADDA6200CCF4; Tue, 19 Nov 2024 23:21:50 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be ADDA6200CCF4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be; s=ulg20190529; t=1732054910; bh=mQveZItNLzTIo34Os3uLO1zS26WneyxGStddfBwzByY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iveLdEh3+PKk2LCoVTnzhLXpFd+yMNnz62siU/9rBQmU9EEetcwa8pEnHseSeoy/b oURlWcZ0jjEdqC0qugRbBVXYu9dYRa6kALrBhJ4qiX4LNZAsS2lpCyXLyvjXqP3Lm9 TnA68QCYlZSU0KhsbDLOfJ1Ha4GmQOLjaikIvBtcXu0yexBS0xNkVVmNsoLaomqBQ3 oamadU9jrYgOf11aUWykJDfkbSCgSo/9wJsxLc3O1+iz44GPQ3ok/F5GFLeGUjxMHZ WOPAaj0nCf5ctvJtZfOSkKz6FtaQ+R44QJi3FKc4D6V5wYbgTKfcUDqRt2M9oqXZve b2J0RtZEGo+KQ== From: Justin Iurman To: netdev@vger.kernel.org Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, linux-kernel@vger.kernel.org, justin.iurman@uliege.be Subject: [PATCH net-next v5 2/4] net: ipv6: ioam6_iptunnel: mitigate 2-realloc issue Date: Tue, 19 Nov 2024 23:21:37 +0100 Message-Id: <20241119222139.14338-3-justin.iurman@uliege.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241119222139.14338-1-justin.iurman@uliege.be> References: <20241119222139.14338-1-justin.iurman@uliege.be> 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 Content-Type: text/plain; charset="utf-8" This patch mitigates the two-reallocations issue with ioam6_iptunnel by providing the dst_entry (in the cache) to the first call to skb_cow_head(). As a result, the very first iteration may still trigger two reallocations (i.e., empty cache), while next iterations would only trigger a single reallocation. Performance tests before/after applying this patch, which clearly shows the improvement: - inline mode: - before: https://ibb.co/LhQ8V63 - after: https://ibb.co/x5YT2bS - encap mode: - before: https://ibb.co/3Cjm5m0 - after: https://ibb.co/TwpsxTC - encap mode with tunsrc: - before: https://ibb.co/Gpy9QPg - after: https://ibb.co/PW1bZFT This patch also fixes an incorrect behavior: after the insertion, the second call to skb_cow_head() makes sure that the dev has enough headroom in the skb for layer 2 and stuff. In that case, the "old" dst_entry was used, which is now fixed. After discussing with Paolo, it appears that both patches can be merged into a single one -this one- (for the sake of readability) and target net-next. Signed-off-by: Justin Iurman --- net/ipv6/ioam6_iptunnel.c | 73 ++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/net/ipv6/ioam6_iptunnel.c b/net/ipv6/ioam6_iptunnel.c index 9d8422e350f8..28e5a89dc255 100644 --- a/net/ipv6/ioam6_iptunnel.c +++ b/net/ipv6/ioam6_iptunnel.c @@ -253,14 +253,15 @@ static int ioam6_do_fill(struct net *net, struct sk_b= uff *skb) } =20 static int ioam6_do_inline(struct net *net, struct sk_buff *skb, - struct ioam6_lwt_encap *tuninfo) + struct ioam6_lwt_encap *tuninfo, + struct dst_entry *cache_dst) { struct ipv6hdr *oldhdr, *hdr; int hdrlen, err; =20 hdrlen =3D (tuninfo->eh.hdrlen + 1) << 3; =20 - err =3D skb_cow_head(skb, hdrlen + skb->mac_len); + err =3D skb_cow_head(skb, hdrlen + dst_dev_overhead(cache_dst, skb)); if (unlikely(err)) return err; =20 @@ -291,7 +292,8 @@ static int ioam6_do_encap(struct net *net, struct sk_bu= ff *skb, struct ioam6_lwt_encap *tuninfo, bool has_tunsrc, struct in6_addr *tunsrc, - struct in6_addr *tundst) + struct in6_addr *tundst, + struct dst_entry *cache_dst) { struct dst_entry *dst =3D skb_dst(skb); struct ipv6hdr *hdr, *inner_hdr; @@ -300,7 +302,7 @@ static int ioam6_do_encap(struct net *net, struct sk_bu= ff *skb, hdrlen =3D (tuninfo->eh.hdrlen + 1) << 3; len =3D sizeof(*hdr) + hdrlen; =20 - err =3D skb_cow_head(skb, len + skb->mac_len); + err =3D skb_cow_head(skb, len + dst_dev_overhead(cache_dst, skb)); if (unlikely(err)) return err; =20 @@ -334,7 +336,7 @@ static int ioam6_do_encap(struct net *net, struct sk_bu= ff *skb, =20 static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *= skb) { - struct dst_entry *dst =3D skb_dst(skb); + struct dst_entry *dst =3D skb_dst(skb), *cache_dst; struct in6_addr orig_daddr; struct ioam6_lwt *ilwt; int err =3D -EINVAL; @@ -352,6 +354,10 @@ static int ioam6_output(struct net *net, struct sock *= sk, struct sk_buff *skb) =20 orig_daddr =3D ipv6_hdr(skb)->daddr; =20 + local_bh_disable(); + cache_dst =3D dst_cache_get(&ilwt->cache); + local_bh_enable(); + switch (ilwt->mode) { case IOAM6_IPTUNNEL_MODE_INLINE: do_inline: @@ -359,7 +365,7 @@ static int ioam6_output(struct net *net, struct sock *s= k, struct sk_buff *skb) if (ipv6_hdr(skb)->nexthdr =3D=3D NEXTHDR_HOP) goto out; =20 - err =3D ioam6_do_inline(net, skb, &ilwt->tuninfo); + err =3D ioam6_do_inline(net, skb, &ilwt->tuninfo, cache_dst); if (unlikely(err)) goto drop; =20 @@ -369,7 +375,7 @@ static int ioam6_output(struct net *net, struct sock *s= k, struct sk_buff *skb) /* Encapsulation (ip6ip6) */ err =3D ioam6_do_encap(net, skb, &ilwt->tuninfo, ilwt->has_tunsrc, &ilwt->tunsrc, - &ilwt->tundst); + &ilwt->tundst, cache_dst); if (unlikely(err)) goto drop; =20 @@ -387,41 +393,36 @@ static int ioam6_output(struct net *net, struct sock = *sk, struct sk_buff *skb) goto drop; } =20 - err =3D skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev)); - if (unlikely(err)) - goto drop; + if (unlikely(!cache_dst)) { + struct ipv6hdr *hdr =3D ipv6_hdr(skb); + struct flowi6 fl6; + + memset(&fl6, 0, sizeof(fl6)); + fl6.daddr =3D hdr->daddr; + fl6.saddr =3D hdr->saddr; + fl6.flowlabel =3D ip6_flowinfo(hdr); + fl6.flowi6_mark =3D skb->mark; + fl6.flowi6_proto =3D hdr->nexthdr; + + cache_dst =3D ip6_route_output(net, NULL, &fl6); + if (cache_dst->error) { + err =3D cache_dst->error; + dst_release(cache_dst); + goto drop; + } =20 - if (!ipv6_addr_equal(&orig_daddr, &ipv6_hdr(skb)->daddr)) { local_bh_disable(); - dst =3D dst_cache_get(&ilwt->cache); + dst_cache_set_ip6(&ilwt->cache, cache_dst, &fl6.saddr); local_bh_enable(); =20 - if (unlikely(!dst)) { - struct ipv6hdr *hdr =3D ipv6_hdr(skb); - struct flowi6 fl6; - - memset(&fl6, 0, sizeof(fl6)); - fl6.daddr =3D hdr->daddr; - fl6.saddr =3D hdr->saddr; - fl6.flowlabel =3D ip6_flowinfo(hdr); - fl6.flowi6_mark =3D skb->mark; - fl6.flowi6_proto =3D hdr->nexthdr; - - dst =3D ip6_route_output(net, NULL, &fl6); - if (dst->error) { - err =3D dst->error; - dst_release(dst); - goto drop; - } - - local_bh_disable(); - dst_cache_set_ip6(&ilwt->cache, dst, &fl6.saddr); - local_bh_enable(); - } + err =3D skb_cow_head(skb, LL_RESERVED_SPACE(cache_dst->dev)); + if (unlikely(err)) + goto drop; + } =20 + if (!ipv6_addr_equal(&orig_daddr, &ipv6_hdr(skb)->daddr)) { skb_dst_drop(skb); - skb_dst_set(skb, dst); - + skb_dst_set(skb, cache_dst); return dst_output(net, sk, skb); } out: --=20 2.34.1 From nobody Mon Nov 25 07:28:34 2024 Received: from serv108.segi.ulg.ac.be (serv108.segi.ulg.ac.be [139.165.32.111]) (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 EBDF21C1F30; Tue, 19 Nov 2024 22:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=139.165.32.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732054921; cv=none; b=hIPS077mvVVXiqZ27ifPm1ni/EqAVg26PxdUvm+45xj/C7UkmWo6JKWnWx8ptoEvmiD+Nm24p/Bwzda9w+nq2pnTZCXxXscKnEcM92lsRdB1tbe2lPv9taNvO3twVRuQfzS8QuAcYHV0IJYzaOlYtzMoJmO6RI7MGa7BvEnfuuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732054921; c=relaxed/simple; bh=ZEG9otDQvINqY6OReyg8BWgPrE/7dIYiKGpsAvyKPLo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kD+QM5Hf7pB8ghMpZD1xbaX/zx2HbheXQ5e957la0WqEWtT9lLe+k5HccPoZY4ramyMZ7ElZDOX+edu0lil05Cqtp4QeLlVNzwjae2gS0bYqnnSvTrCmwJypsZgNWDOC1n8ISVE1X5JQU12XjdtAYevBXH/foRpBw0+EEYS9Dj4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uliege.be; spf=pass smtp.mailfrom=uliege.be; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b=XGRqZAjv; arc=none smtp.client-ip=139.165.32.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uliege.be Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uliege.be Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b="XGRqZAjv" Received: from ubuntu.home (220.24-245-81.adsl-dyn.isp.belgacom.be [81.245.24.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by serv108.segi.ulg.ac.be (Postfix) with ESMTPSA id EAE19200CCF5; Tue, 19 Nov 2024 23:21:50 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be EAE19200CCF5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be; s=ulg20190529; t=1732054911; bh=Mtv8ELvUZ9071b3yI3eGE0meU9AdbEXLRQz1hY3sUiA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XGRqZAjvrGMReDZSVfpg+eFTg3VxmR5MRQ6IRgYZRg8M/qItRAz6YNrrqR7TWzbcx DhPCv06ar44z5I40CUXFFmwgMJqP3BwR+zqSxHTtBkwVO2ZtcIgI3hRcruNECQ7kSC yzqvsM5nQ8/sDeOyHAZS3Vdu1vNFjwfHf/HZfnuq6NqHfUSAgRWXRXCNAJpix5O/Ue JxHM1MSplYZB6vn6N9PKFShZGiQ0XmDMp53aiqOQhzSD98lIdeYk96jpAk2+I9o35Q jEkXpmCHGn+QgCeRjp9DyVHVzdsM938ZinzsY40kwRdtKYHam72ibdjk+ZczzG60rs 2Zgo9KmySvGkA== From: Justin Iurman To: netdev@vger.kernel.org Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, linux-kernel@vger.kernel.org, justin.iurman@uliege.be, David Lebrun Subject: [PATCH net-next v5 3/4] net: ipv6: seg6_iptunnel: mitigate 2-realloc issue Date: Tue, 19 Nov 2024 23:21:38 +0100 Message-Id: <20241119222139.14338-4-justin.iurman@uliege.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241119222139.14338-1-justin.iurman@uliege.be> References: <20241119222139.14338-1-justin.iurman@uliege.be> 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 Content-Type: text/plain; charset="utf-8" This patch mitigates the two-reallocations issue with seg6_iptunnel by providing the dst_entry (in the cache) to the first call to skb_cow_head(). As a result, the very first iteration would still trigger two reallocations (i.e., empty cache), while next iterations would only trigger a single reallocation. Performance tests before/after applying this patch, which clearly shows the improvement: - before: https://ibb.co/3Cg4sNH - after: https://ibb.co/8rQ350r Signed-off-by: Justin Iurman Cc: David Lebrun --- net/ipv6/seg6_iptunnel.c | 85 ++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c index 098632adc9b5..4bf937bfc263 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -124,8 +124,8 @@ static __be32 seg6_make_flowlabel(struct net *net, stru= ct sk_buff *skb, return flowlabel; } =20 -/* encapsulate an IPv6 packet within an outer IPv6 header with a given SRH= */ -int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int p= roto) +static int __seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *os= rh, + int proto, struct dst_entry *cache_dst) { struct dst_entry *dst =3D skb_dst(skb); struct net *net =3D dev_net(dst->dev); @@ -137,7 +137,7 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_= sr_hdr *osrh, int proto) hdrlen =3D (osrh->hdrlen + 1) << 3; tot_len =3D hdrlen + sizeof(*hdr); =20 - err =3D skb_cow_head(skb, tot_len + skb->mac_len); + err =3D skb_cow_head(skb, tot_len + dst_dev_overhead(cache_dst, skb)); if (unlikely(err)) return err; =20 @@ -197,11 +197,18 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv= 6_sr_hdr *osrh, int proto) =20 return 0; } + +/* encapsulate an IPv6 packet within an outer IPv6 header with a given SRH= */ +int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int p= roto) +{ + return __seg6_do_srh_encap(skb, osrh, proto, NULL); +} EXPORT_SYMBOL_GPL(seg6_do_srh_encap); =20 /* encapsulate an IPv6 packet within an outer IPv6 header with reduced SRH= */ static int seg6_do_srh_encap_red(struct sk_buff *skb, - struct ipv6_sr_hdr *osrh, int proto) + struct ipv6_sr_hdr *osrh, int proto, + struct dst_entry *cache_dst) { __u8 first_seg =3D osrh->first_segment; struct dst_entry *dst =3D skb_dst(skb); @@ -230,7 +237,7 @@ static int seg6_do_srh_encap_red(struct sk_buff *skb, =20 tot_len =3D red_hdrlen + sizeof(struct ipv6hdr); =20 - err =3D skb_cow_head(skb, tot_len + skb->mac_len); + err =3D skb_cow_head(skb, tot_len + dst_dev_overhead(cache_dst, skb)); if (unlikely(err)) return err; =20 @@ -317,8 +324,8 @@ static int seg6_do_srh_encap_red(struct sk_buff *skb, return 0; } =20 -/* insert an SRH within an IPv6 packet, just after the IPv6 header */ -int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh) +static int __seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *o= srh, + struct dst_entry *cache_dst) { struct ipv6hdr *hdr, *oldhdr; struct ipv6_sr_hdr *isrh; @@ -326,7 +333,7 @@ int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6= _sr_hdr *osrh) =20 hdrlen =3D (osrh->hdrlen + 1) << 3; =20 - err =3D skb_cow_head(skb, hdrlen + skb->mac_len); + err =3D skb_cow_head(skb, hdrlen + dst_dev_overhead(cache_dst, skb)); if (unlikely(err)) return err; =20 @@ -369,9 +376,8 @@ int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6= _sr_hdr *osrh) =20 return 0; } -EXPORT_SYMBOL_GPL(seg6_do_srh_inline); =20 -static int seg6_do_srh(struct sk_buff *skb) +static int seg6_do_srh(struct sk_buff *skb, struct dst_entry *cache_dst) { struct dst_entry *dst =3D skb_dst(skb); struct seg6_iptunnel_encap *tinfo; @@ -384,7 +390,7 @@ static int seg6_do_srh(struct sk_buff *skb) if (skb->protocol !=3D htons(ETH_P_IPV6)) return -EINVAL; =20 - err =3D seg6_do_srh_inline(skb, tinfo->srh); + err =3D __seg6_do_srh_inline(skb, tinfo->srh, cache_dst); if (err) return err; break; @@ -402,9 +408,11 @@ static int seg6_do_srh(struct sk_buff *skb) return -EINVAL; =20 if (tinfo->mode =3D=3D SEG6_IPTUN_MODE_ENCAP) - err =3D seg6_do_srh_encap(skb, tinfo->srh, proto); + err =3D __seg6_do_srh_encap(skb, tinfo->srh, + proto, cache_dst); else - err =3D seg6_do_srh_encap_red(skb, tinfo->srh, proto); + err =3D seg6_do_srh_encap_red(skb, tinfo->srh, + proto, cache_dst); =20 if (err) return err; @@ -425,11 +433,13 @@ static int seg6_do_srh(struct sk_buff *skb) skb_push(skb, skb->mac_len); =20 if (tinfo->mode =3D=3D SEG6_IPTUN_MODE_L2ENCAP) - err =3D seg6_do_srh_encap(skb, tinfo->srh, - IPPROTO_ETHERNET); + err =3D __seg6_do_srh_encap(skb, tinfo->srh, + IPPROTO_ETHERNET, + cache_dst); else err =3D seg6_do_srh_encap_red(skb, tinfo->srh, - IPPROTO_ETHERNET); + IPPROTO_ETHERNET, + cache_dst); =20 if (err) return err; @@ -444,6 +454,13 @@ static int seg6_do_srh(struct sk_buff *skb) return 0; } =20 +/* insert an SRH within an IPv6 packet, just after the IPv6 header */ +int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh) +{ + return __seg6_do_srh_inline(skb, osrh, NULL); +} +EXPORT_SYMBOL_GPL(seg6_do_srh_inline); + static int seg6_input_finish(struct net *net, struct sock *sk, struct sk_buff *skb) { @@ -458,31 +475,33 @@ static int seg6_input_core(struct net *net, struct so= ck *sk, struct seg6_lwt *slwt; int err; =20 - err =3D seg6_do_srh(skb); - if (unlikely(err)) - goto drop; - slwt =3D seg6_lwt_lwtunnel(orig_dst->lwtstate); =20 local_bh_disable(); dst =3D dst_cache_get(&slwt->cache); + local_bh_enable(); + + err =3D seg6_do_srh(skb, dst); + if (unlikely(err)) + goto drop; =20 if (!dst) { ip6_route_input(skb); dst =3D skb_dst(skb); if (!dst->error) { + local_bh_disable(); dst_cache_set_ip6(&slwt->cache, dst, &ipv6_hdr(skb)->saddr); + local_bh_enable(); } + + err =3D skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev)); + if (unlikely(err)) + goto drop; } else { skb_dst_drop(skb); skb_dst_set(skb, dst); } - local_bh_enable(); - - err =3D skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev)); - if (unlikely(err)) - goto drop; =20 if (static_branch_unlikely(&nf_hooks_lwtunnel_enabled)) return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, @@ -528,16 +547,16 @@ static int seg6_output_core(struct net *net, struct s= ock *sk, struct seg6_lwt *slwt; int err; =20 - err =3D seg6_do_srh(skb); - if (unlikely(err)) - goto drop; - slwt =3D seg6_lwt_lwtunnel(orig_dst->lwtstate); =20 local_bh_disable(); dst =3D dst_cache_get(&slwt->cache); local_bh_enable(); =20 + err =3D seg6_do_srh(skb, dst); + if (unlikely(err)) + goto drop; + if (unlikely(!dst)) { struct ipv6hdr *hdr =3D ipv6_hdr(skb); struct flowi6 fl6; @@ -559,15 +578,15 @@ static int seg6_output_core(struct net *net, struct s= ock *sk, local_bh_disable(); dst_cache_set_ip6(&slwt->cache, dst, &fl6.saddr); local_bh_enable(); + + err =3D skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev)); + if (unlikely(err)) + goto drop; } =20 skb_dst_drop(skb); skb_dst_set(skb, dst); =20 - err =3D skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev)); - if (unlikely(err)) - goto drop; - if (static_branch_unlikely(&nf_hooks_lwtunnel_enabled)) return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, sk, skb, NULL, skb_dst(skb)->dev, dst_output); --=20 2.34.1 From nobody Mon Nov 25 07:28:34 2024 Received: from serv108.segi.ulg.ac.be (serv108.segi.ulg.ac.be [139.165.32.111]) (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 EBD2F1B21A0; Tue, 19 Nov 2024 22:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=139.165.32.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732054920; cv=none; b=Hv/or+mFo+v5eCyAbN33jhrRQYYoMEJ3zYMMVCMGrjDflY4uHABHekm3WucD09Rx1z2LMdUbkH94BmHdcUv8eBlOpzkstIptB9+JULgBhiVXR0dcTbBj9y032aUbbIUxE/U0i2vBsH4WKQlV8Bf1LmoB3sdqcbUyo9aFm3v/dQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732054920; c=relaxed/simple; bh=N9lNPAnG9daoRRu44eC7wcwd7qVHi20bhm7d5c83t+A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FnoOW8ZuYedtHW9r7VoxKgdZmV7U1W9FrUMru8bwuJDgWwor0mA/SmJqmKiRQU8y6Q4V0OYM9G1rMvmq5QKxbkhNrReMT4AIBOASPurtsplOdVc3gG0lKuMxhGZfGCEGo2mwS8oredYHd/UR10TTZgIIe2SZcXuliKJLMH+KMT0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uliege.be; spf=pass smtp.mailfrom=uliege.be; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b=BpzyMveM; arc=none smtp.client-ip=139.165.32.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uliege.be Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uliege.be Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=uliege.be header.i=@uliege.be header.b="BpzyMveM" Received: from ubuntu.home (220.24-245-81.adsl-dyn.isp.belgacom.be [81.245.24.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by serv108.segi.ulg.ac.be (Postfix) with ESMTPSA id 388D6200CCF7; Tue, 19 Nov 2024 23:21:51 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be 388D6200CCF7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be; s=ulg20190529; t=1732054911; bh=BRbyYLcn7uQDCnfS43ZRCSxf5KuJgj54skzk37kjRJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BpzyMveM29XchPa3h3hn7ICJNYK4bOe90dHa8CMINJ2TQCO5KN8Dvm5QJRaPf5pdZ ZSciWdYyOxsVdcnx0Ao40edwYohccTC/8BVZ+MqFazVZMJccC3YcJeekBd/mfR4c+C vR275Ieh3o62vlm+UvBv0taF80WAUJ9DtfFy+gt8HCbj6GONsKkA1dGsS0KnEX6PB+ rOfwR1SdHw9DskZqNxBAqVf13B9ELypAURqxk4sJEDHer+JpTTtWtnYyCEqeJQ0Epv 8TDx/gxbKBrPoSmAaHn45cMHzY7wvi93b853XTlKPLvXVFhW6Jtnm1A422O6vXKfP6 1ar+R496eP60w== From: Justin Iurman To: netdev@vger.kernel.org Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, linux-kernel@vger.kernel.org, justin.iurman@uliege.be, Alexander Aring Subject: [PATCH net-next v5 4/4] net: ipv6: rpl_iptunnel: mitigate 2-realloc issue Date: Tue, 19 Nov 2024 23:21:39 +0100 Message-Id: <20241119222139.14338-5-justin.iurman@uliege.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241119222139.14338-1-justin.iurman@uliege.be> References: <20241119222139.14338-1-justin.iurman@uliege.be> 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 Content-Type: text/plain; charset="utf-8" This patch mitigates the two-reallocations issue with rpl_iptunnel by providing the dst_entry (in the cache) to the first call to skb_cow_head(). As a result, the very first iteration would still trigger two reallocations (i.e., empty cache), while next iterations would only trigger a single reallocation. Performance tests before/after applying this patch, which clearly shows there is no impact (it even shows improvement): - before: https://ibb.co/nQJhqwc - after: https://ibb.co/4ZvW6wV Signed-off-by: Justin Iurman Cc: Alexander Aring --- net/ipv6/rpl_iptunnel.c | 46 ++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/net/ipv6/rpl_iptunnel.c b/net/ipv6/rpl_iptunnel.c index db3c19a42e1c..7ba22d2f2bfe 100644 --- a/net/ipv6/rpl_iptunnel.c +++ b/net/ipv6/rpl_iptunnel.c @@ -125,7 +125,8 @@ static void rpl_destroy_state(struct lwtunnel_state *lw= t) } =20 static int rpl_do_srh_inline(struct sk_buff *skb, const struct rpl_lwt *rl= wt, - const struct ipv6_rpl_sr_hdr *srh) + const struct ipv6_rpl_sr_hdr *srh, + struct dst_entry *cache_dst) { struct ipv6_rpl_sr_hdr *isrh, *csrh; const struct ipv6hdr *oldhdr; @@ -153,7 +154,7 @@ static int rpl_do_srh_inline(struct sk_buff *skb, const= struct rpl_lwt *rlwt, =20 hdrlen =3D ((csrh->hdrlen + 1) << 3); =20 - err =3D skb_cow_head(skb, hdrlen + skb->mac_len); + err =3D skb_cow_head(skb, hdrlen + dst_dev_overhead(cache_dst, skb)); if (unlikely(err)) { kfree(buf); return err; @@ -186,7 +187,8 @@ static int rpl_do_srh_inline(struct sk_buff *skb, const= struct rpl_lwt *rlwt, return 0; } =20 -static int rpl_do_srh(struct sk_buff *skb, const struct rpl_lwt *rlwt) +static int rpl_do_srh(struct sk_buff *skb, const struct rpl_lwt *rlwt, + struct dst_entry *cache_dst) { struct dst_entry *dst =3D skb_dst(skb); struct rpl_iptunnel_encap *tinfo; @@ -196,7 +198,7 @@ static int rpl_do_srh(struct sk_buff *skb, const struct= rpl_lwt *rlwt) =20 tinfo =3D rpl_encap_lwtunnel(dst->lwtstate); =20 - return rpl_do_srh_inline(skb, rlwt, tinfo->srh); + return rpl_do_srh_inline(skb, rlwt, tinfo->srh, cache_dst); } =20 static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *sk= b) @@ -208,14 +210,14 @@ static int rpl_output(struct net *net, struct sock *s= k, struct sk_buff *skb) =20 rlwt =3D rpl_lwt_lwtunnel(orig_dst->lwtstate); =20 - err =3D rpl_do_srh(skb, rlwt); - if (unlikely(err)) - goto drop; - local_bh_disable(); dst =3D dst_cache_get(&rlwt->cache); local_bh_enable(); =20 + err =3D rpl_do_srh(skb, rlwt, dst); + if (unlikely(err)) + goto drop; + if (unlikely(!dst)) { struct ipv6hdr *hdr =3D ipv6_hdr(skb); struct flowi6 fl6; @@ -237,15 +239,15 @@ static int rpl_output(struct net *net, struct sock *s= k, struct sk_buff *skb) local_bh_disable(); dst_cache_set_ip6(&rlwt->cache, dst, &fl6.saddr); local_bh_enable(); + + err =3D skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev)); + if (unlikely(err)) + goto drop; } =20 skb_dst_drop(skb); skb_dst_set(skb, dst); =20 - err =3D skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev)); - if (unlikely(err)) - goto drop; - return dst_output(net, sk, skb); =20 drop: @@ -262,29 +264,31 @@ static int rpl_input(struct sk_buff *skb) =20 rlwt =3D rpl_lwt_lwtunnel(orig_dst->lwtstate); =20 - err =3D rpl_do_srh(skb, rlwt); - if (unlikely(err)) - goto drop; - local_bh_disable(); dst =3D dst_cache_get(&rlwt->cache); + local_bh_enable(); + + err =3D rpl_do_srh(skb, rlwt, dst); + if (unlikely(err)) + goto drop; =20 if (!dst) { ip6_route_input(skb); dst =3D skb_dst(skb); if (!dst->error) { + local_bh_disable(); dst_cache_set_ip6(&rlwt->cache, dst, &ipv6_hdr(skb)->saddr); + local_bh_enable(); } + + err =3D skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev)); + if (unlikely(err)) + goto drop; } else { skb_dst_drop(skb); skb_dst_set(skb, dst); } - local_bh_enable(); - - err =3D skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev)); - if (unlikely(err)) - goto drop; =20 return dst_input(skb); =20 --=20 2.34.1