Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp268152pxt; Fri, 6 Aug 2021 01:17:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxh1aNiOs1pqrTtPihzn1+wmFU2CVboJ/pNF4eQE2hXNCN5sUvBoWuZYv0V4u71kdQSXvPD X-Received: by 2002:a17:906:1d41:: with SMTP id o1mr5627671ejh.232.1628237869931; Fri, 06 Aug 2021 01:17:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628237869; cv=none; d=google.com; s=arc-20160816; b=QFnzJfdtUb02C/I9Dx5Dqr9J1nS/vTmTMoMNPioXD7rjvijaPpMqabsAwqdNpqYUF9 +V3Ww+WwhZLRYZaFRhi5eg/LxrPSBAIvDnKOZyVpnHD+I4tasMGX9pIPzIiT6sojqfy+ WDxP8lT8IXFXbE71PKsNb/CA1QPI3n8nTBhjW3lB8jAWKJ5pEb0nA4zHh/weFbgXzOJU zoGmgsLFu0l1npkajC6b9+fGBXk2tGjZMavzVBQvX/Dl0LAFcqLjcetUwE0N+iZuxPyi 4sdzSm5IiLJQCeZogXh8Xg1q67uKWfuLD5t89LsVLji2XF81JMxULzxLPCUPwVXTKR1p hPrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:subject:from:dkim-signature; bh=1UovdOxZifIF7TcwgsWVfVFcW1UxG7phFACNfC2QUDI=; b=XLMuOgomS8/Cic7EJkL484Z92rGVdoe6Jlovl1SyzvvF4ITZND0xKK11fWAhVLo7tD zB7+8oJW0SWZRuMxxqAt7Nz88eSPhyVatgAD9dl7Gvfou007IrDezVa6ap7phUHEwzmw EwQDXEn057us2OzcO2IlUZMd/UP8VSyjNfni8yVR2GN4v8UyiQ61vMHq+BDKXRfHKy1q 8M6iYNNVJH6ck521xt56l9eFqIDbwoTu7vCyglVinFUx78xglvd8/3gIPml8bcQZJ8Sv Fq+WF7Ll7L87tc6v0n2zX+pcPf3wg+N+hBIyUYOPRDzOC5LKBCupqL0fXJoKLZeyy9+T RsRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=b3OgBPaU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mc27si8523819ejb.728.2021.08.06.01.17.24; Fri, 06 Aug 2021 01:17:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=b3OgBPaU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243151AbhHFHue (ORCPT + 99 others); Fri, 6 Aug 2021 03:50:34 -0400 Received: from relay.sw.ru ([185.231.240.75]:36334 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242824AbhHFHu3 (ORCPT ); Fri, 6 Aug 2021 03:50:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Date:Message-ID:Subject :From; bh=1UovdOxZifIF7TcwgsWVfVFcW1UxG7phFACNfC2QUDI=; b=b3OgBPaU+WDLQzxuP5b k83/4SP8f/cQyYqNT5mJWGGTVJ0fqfcxMFR+ryBoiHn3dIEPsz0Z4n/GbltE7RSzuQ8Y+zXOJ/S+S qt1ze6lQnlncQq7ayLpm3IHbIZ48hZTPuKOmkaVTqQ2DtWEZOCUukm0w89Dt1Y0GYXCbnztOAFA=; Received: from [10.93.0.56] by relay.sw.ru with esmtp (Exim 4.94.2) (envelope-from ) id 1mBucN-006afe-6e; Fri, 06 Aug 2021 10:50:11 +0300 From: Vasily Averin Subject: [PATCH NET v4 3/7] ipv6: use skb_expand_head in ip6_xmit To: "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , Eric Dumazet Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@openvz.org, Julian Wiedmann References: Message-ID: <77f3e358-c75e-b0bf-ca87-6f8297f5593c@virtuozzo.com> Date: Fri, 6 Aug 2021 10:50:10 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Unlike skb_realloc_headroom, new helper skb_expand_head does not allocate a new skb if possible. Additionally this patch replaces commonly used dereferencing with variables. Signed-off-by: Vasily Averin --- net/ipv6/ip6_output.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 7d2ec25..f91d13a 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -249,6 +249,8 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, const struct ipv6_pinfo *np = inet6_sk(sk); struct in6_addr *first_hop = &fl6->daddr; struct dst_entry *dst = skb_dst(skb); + struct net_device *dev = dst->dev; + struct inet6_dev *idev = ip6_dst_idev(dst); unsigned int head_room; struct ipv6hdr *hdr; u8 proto = fl6->flowi6_proto; @@ -256,22 +258,16 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, int hlimit = -1; u32 mtu; - head_room = sizeof(struct ipv6hdr) + LL_RESERVED_SPACE(dst->dev); + head_room = sizeof(struct ipv6hdr) + LL_RESERVED_SPACE(dev); if (opt) head_room += opt->opt_nflen + opt->opt_flen; - if (unlikely(skb_headroom(skb) < head_room)) { - struct sk_buff *skb2 = skb_realloc_headroom(skb, head_room); - if (!skb2) { - IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), - IPSTATS_MIB_OUTDISCARDS); - kfree_skb(skb); + if (unlikely(head_room > skb_headroom(skb))) { + skb = skb_expand_head(skb, head_room); + if (!skb) { + IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS); return -ENOBUFS; } - if (skb->sk) - skb_set_owner_w(skb2, skb->sk); - consume_skb(skb); - skb = skb2; } if (opt) { @@ -313,8 +309,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, mtu = dst_mtu(dst); if ((skb->len <= mtu) || skb->ignore_df || skb_is_gso(skb)) { - IP6_UPD_PO_STATS(net, ip6_dst_idev(skb_dst(skb)), - IPSTATS_MIB_OUT, skb->len); + IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUT, skb->len); /* if egress device is enslaved to an L3 master device pass the * skb to its handler for processing @@ -327,17 +322,17 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, * we promote our socket to non const */ return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, - net, (struct sock *)sk, skb, NULL, dst->dev, + net, (struct sock *)sk, skb, NULL, dev, dst_output); } - skb->dev = dst->dev; + skb->dev = dev; /* ipv6_local_error() does not require socket lock, * we promote our socket to non const */ ipv6_local_error((struct sock *)sk, EMSGSIZE, fl6, mtu); - IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS); + IP6_INC_STATS(net, idev, IPSTATS_MIB_FRAGFAILS); kfree_skb(skb); return -EMSGSIZE; } -- 1.8.3.1