From nobody Mon Nov 25 09:57:41 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 A40EA18E05D; Mon, 28 Oct 2024 22:36:29 +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=1730154992; cv=none; b=DJe/mcAsYh0fkSRSNL//3IY4iLuSUABxZ7Q71jn2m/BaxjI8pQ02gIDsrGiTey1yiN040Iu95CDOj8FxkmkjarwBbg1Sv04KP33bKdRoBBnb3p1mDh/PbBbcyJYsEMWKGVP63JTkjNEMuTAPCV+/UgKNtSZetTkRXnkTH1kmMYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730154992; c=relaxed/simple; bh=fcb6/ZXqWJIFRDmjDhyI8ULDpI0uIWrmsfpnD3tx5PU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EtgSniMXUCmjZ9guIzr5S3j06ar7mP2CgsyXqboQfx5BtdJqcFda/IgD1gfS7cmjM+EtUZopmuJumKBKEWTnvAFZ6jsJhYkGyV1Gnx0umc3KIAvp0RA9AtyOH/k3VBPAdVqK13A/EpDLEXJX1mxOXeGLNf4N4TfzhARLjfNF/38= 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=gG0RGd56; 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="gG0RGd56" Received: from localhost.localdomain (unknown [10.29.254.136]) (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 8BB20200DF96; Mon, 28 Oct 2024 23:36:26 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 serv108.segi.ulg.ac.be 8BB20200DF96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uliege.be; s=ulg20190529; t=1730154988; bh=tYfpbkPNAjaZpZFMkRWmpEDluZdW9RukyEp0aeELqDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gG0RGd56fYB4i6Mr0y1PANR29LyYM4pZRZpo/J+glpj2805OJcCj3az+topCl5OZg DKVUdI0Y3+MtB1/siLcaPSI0qAChSa0Tgn2vwGO5FDxTeUXUogVTXhy47IqtgPVAv6 isuf73tPvxsq2RRL4PmgAYZf1DSIdwbqzR+MdxEF/qhkemjaqlnr+h207oAUZieTQ2 Uoe34ZILjWuEOGWcozgX8IyJ95L8NJOgpP7bjouwJ/lR+5eUN8T+Noh9DWHKsGQRXH b2pL8A5gi43UV7YB8MUyA8Q51r+RVNyA/Noth3S/hPaFPOtKFvspKfhN9+fUA3F0UB +niZ4lEhokyGA== 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 v3 3/3] net: ipv6: rpl_iptunnel: mitigate 2-realloc issue Date: Mon, 28 Oct 2024 23:36:11 +0100 Message-Id: <20241028223611.26599-4-justin.iurman@uliege.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241028223611.26599-1-justin.iurman@uliege.be> References: <20241028223611.26599-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 | 67 +++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/net/ipv6/rpl_iptunnel.c b/net/ipv6/rpl_iptunnel.c index db3c19a42e1c..c518728460a2 100644 --- a/net/ipv6/rpl_iptunnel.c +++ b/net/ipv6/rpl_iptunnel.c @@ -124,8 +124,17 @@ static void rpl_destroy_state(struct lwtunnel_state *l= wt) dst_cache_destroy(&rpl_lwt_lwtunnel(lwt)->cache); } =20 +static inline int dev_overhead(struct dst_entry *dst, struct sk_buff *skb) +{ + if (likely(dst)) + return LL_RESERVED_SPACE(dst->dev); + + return skb->mac_len; +} + 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 *dst) { struct ipv6_rpl_sr_hdr *isrh, *csrh; const struct ipv6hdr *oldhdr; @@ -153,7 +162,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 + dev_overhead(dst, skb)); if (unlikely(err)) { kfree(buf); return err; @@ -186,36 +195,35 @@ static int rpl_do_srh_inline(struct sk_buff *skb, con= st 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 *dst) { - struct dst_entry *dst =3D skb_dst(skb); struct rpl_iptunnel_encap *tinfo; =20 if (skb->protocol !=3D htons(ETH_P_IPV6)) return -EINVAL; =20 - tinfo =3D rpl_encap_lwtunnel(dst->lwtstate); + tinfo =3D rpl_encap_lwtunnel(skb_dst(skb)->lwtstate); =20 - return rpl_do_srh_inline(skb, rlwt, tinfo->srh); + return rpl_do_srh_inline(skb, rlwt, tinfo->srh, dst); } =20 static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *sk= b) { - struct dst_entry *orig_dst =3D skb_dst(skb); - struct dst_entry *dst =3D NULL; + struct dst_entry *dst; struct rpl_lwt *rlwt; int err; =20 - rlwt =3D rpl_lwt_lwtunnel(orig_dst->lwtstate); - - err =3D rpl_do_srh(skb, rlwt); - if (unlikely(err)) - goto drop; + rlwt =3D rpl_lwt_lwtunnel(skb_dst(skb)->lwtstate); =20 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 +245,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: @@ -255,36 +263,37 @@ static int rpl_output(struct net *net, struct sock *s= k, struct sk_buff *skb) =20 static int rpl_input(struct sk_buff *skb) { - struct dst_entry *orig_dst =3D skb_dst(skb); - struct dst_entry *dst =3D NULL; + struct dst_entry *dst; struct rpl_lwt *rlwt; int err; =20 - rlwt =3D rpl_lwt_lwtunnel(orig_dst->lwtstate); - - err =3D rpl_do_srh(skb, rlwt); - if (unlikely(err)) - goto drop; + rlwt =3D rpl_lwt_lwtunnel(skb_dst(skb)->lwtstate); =20 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