From patchwork Thu Apr 28 10:56:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830415 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92C67C433EF for ; Thu, 28 Apr 2022 10:58:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345025AbiD1LBS (ORCPT ); Thu, 28 Apr 2022 07:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344966AbiD1LBC (ORCPT ); Thu, 28 Apr 2022 07:01:02 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3196A95A3E; Thu, 28 Apr 2022 03:57:45 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id i5so6196906wrc.13; Thu, 28 Apr 2022 03:57:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ul+t6uTHofyRjOEGXVcu4PlOdgwxB5M3MPuVkOzIQ1Y=; b=cZNzSUcmv+bYXCqMXlvHlmCao3TAKfZHR+cXCTOPk2meuPJBce0NtdnKSKUdN4ZWnm 09VNe1iMqfCkrXJJfWUPBIp56YBIezb6yGscB49qDR4JuMXc4hEK/154pW/Hrfkks5ad 6JrtsOHq9v1wuPZ7Z9Um8Ba1UWVyHD5EQ+Pru2lrrQDnKmw7SHpXMAN/gCJdVI1paVoM 4z8XZsAj1W7k3Ow+sF4mR6DOc4wLFPTKMU0oRXTmxCWYY4Id/5qjtYCNwPG4U10UPMJL I9Lg3PaD85uWESe4Tu5HV4L92sFCIulFdOamKyhrf1fWInkMuY+wy+P52vlfatsd+XO+ 6Vrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ul+t6uTHofyRjOEGXVcu4PlOdgwxB5M3MPuVkOzIQ1Y=; b=2VkOY7wRbQqPHn8pQHIgsoPaUHMyaUrUbbGROQ/sjiJV2YMsZFJPLmTgtA1tfgnATQ RwV2lKI6kMI4NwGKjzc5zdzV8vEi5eT4rmtOl40/mla8ltmJ4wxPYB4Bq/xMPPGgFdk2 oRgl6aCohi45kf21671u/WRmQcOJ1VF8t+miyMgOXd/TZzaj6z4VNt7seFHa8XA8b7/j bJrIwkXmk3EbtsUkfVl8NFLxWMkCX2+tRSHKxRW2DHHidw3mtq2cuUzQjXRv1kX9Stee EAzdyc6z9gXOw9lvQu+CwBU1Y6aGCFevfI4/EA+qmA/iRSGWiRwMHnLcG2So4UOFow2p s12A== X-Gm-Message-State: AOAM530MX13ITWFunCgNKtNaD2YJ/WWnx77CzJJshXNDVmmCBIChycrJ QVu+y3UE84SgFpKDjNFnHXA9jHKuXjA= X-Google-Smtp-Source: ABdhPJwck+eoUYcstYlxOr02IVXvb1NXBw5lVqFBRIXksd9+2gk9v8n1XSWqgBOB/56Rxty548l5Vg== X-Received: by 2002:a05:6000:114d:b0:20a:d608:5e54 with SMTP id d13-20020a056000114d00b0020ad6085e54mr19754957wrx.539.1651143463594; Thu, 28 Apr 2022 03:57:43 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:43 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 08/10] ipv6: refactor opts push in __ip6_make_skb() Date: Thu, 28 Apr 2022 11:56:40 +0100 Message-Id: <3d72bc581954b5a9156661cf6957a72c5940a459.1651071506.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Don't preload v6_cork->opt before we actually need it, it likely to be saved on the stack and read again for no good reason. Signed-off-by: Pavel Begunkov --- net/ipv6/ip6_output.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 976554d0fdec..43a541bbcf5f 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1855,7 +1855,6 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, struct ipv6_pinfo *np = inet6_sk(sk); struct net *net = sock_net(sk); struct ipv6hdr *hdr; - struct ipv6_txoptions *opt = v6_cork->opt; struct rt6_info *rt = (struct rt6_info *)cork->base.dst; struct flowi6 *fl6 = &cork->fl.u.ip6; unsigned char proto = fl6->flowi6_proto; @@ -1884,10 +1883,14 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, __skb_pull(skb, skb_network_header_len(skb)); final_dst = &fl6->daddr; - if (opt && opt->opt_flen) - ipv6_push_frag_opts(skb, opt, &proto); - if (opt && opt->opt_nflen) - ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst, &fl6->saddr); + if (v6_cork->opt) { + struct ipv6_txoptions *opt = v6_cork->opt; + + if (opt->opt_flen) + ipv6_push_frag_opts(skb, opt, &proto); + if (opt->opt_nflen) + ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst, &fl6->saddr); + } skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); From patchwork Thu Apr 28 10:56:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830416 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C849C4332F for ; Thu, 28 Apr 2022 10:58:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345028AbiD1LBT (ORCPT ); Thu, 28 Apr 2022 07:01:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344971AbiD1LBG (ORCPT ); Thu, 28 Apr 2022 07:01:06 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D99709681B; Thu, 28 Apr 2022 03:57:46 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id j15so6261158wrb.2; Thu, 28 Apr 2022 03:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e3JOSUJWrUPvCHFoWua5pWRqSGO0w+9yuqoonKqU/u4=; b=eL7q2mgdQJaJ0Esr+ePbHxQKz4HHk0UPt1Ns9c+WfO4/Ng6MXt+4EZlOZAxz8kDAWu Qz+HfYpd5ogfL2w8suSVRYsHaHtG5dJ3IyVG8l1UEN2mEtNruNj9OybcDD4YeB/VbBH0 RtpzcEtw+zdgcGOIi0704alycyY0NOGrF4Fzt9TdE+ZcsCV9HaWH+8fe94fNrOayV0Uk NxRD8DJiqKkRcrVGYuzy37DWfUTzoqRQX1mPGPSDJPzKKb5dUGVbEuW89XciLenoaYgG P/JNkZ6EOPZanVvNsA8aGdQl1TEUJzAah//NqrVSlOPlwERJ4PzZ9ys/PNxZhclrr0oJ 74iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e3JOSUJWrUPvCHFoWua5pWRqSGO0w+9yuqoonKqU/u4=; b=cS0qDSR3SmB19SLQ17B0VMpPrBNXskjv0nkqLvBkFspGjWVMEUbsZpfhvU9brgIHST aE2mLaiRaQpc3m+VPGKi5p7xNsSuZbqWpIcJsVIJTs3rU1RDvWYkGH7NjOwLm5+JTtna HZOg6gTHZ/lTHrdlQa7rz4QM90g66wCnR7YYInc8gsXzSquDnme3IKBR2HipakGmhFvS wuNb6VqQIMzGc9av9qQw+OpeRX/SjiKD20fjoUZcTtJ12nhLPjh78Yt/cXG0GKrKa56H XzGOvBd5n3TIiFhuADvSnp75TPw95AuWwQOTpe7OzhQ6oVpgIBIEF4c/oj0lGgZU4ERU meqA== X-Gm-Message-State: AOAM533PE6Xeh8mW2x3cTmC9hz96hcxcnMUXb8o+W5Y+1OHPyIl6XcaB C1V5ELCUrcorsh1VqZPGWkrtoPpwGbY= X-Google-Smtp-Source: ABdhPJy/s/SxzIbIuA2jyZR46ty8wmnnh6mU39KKWgrZuMlC3i3k475A5WXcTVfo8z6AT7dRweGX4w== X-Received: by 2002:a5d:4e88:0:b0:20a:f4ff:9d20 with SMTP id e8-20020a5d4e88000000b0020af4ff9d20mr3105887wru.51.1651143465324; Thu, 28 Apr 2022 03:57:45 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:45 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 09/10] ipv6: improve opt-less __ip6_make_skb() Date: Thu, 28 Apr 2022 11:56:41 +0100 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org We do a bit of a network header pointer shuffling in __ip6_make_skb() expecting that ipv6_push_*frag_opts() might change the layout. Avoid it with associated overhead when there are no opts. Signed-off-by: Pavel Begunkov --- net/ipv6/ip6_output.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 43a541bbcf5f..416d14299242 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1880,22 +1880,20 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, /* Allow local fragmentation. */ skb->ignore_df = ip6_sk_ignore_df(sk); - __skb_pull(skb, skb_network_header_len(skb)); - final_dst = &fl6->daddr; if (v6_cork->opt) { struct ipv6_txoptions *opt = v6_cork->opt; + __skb_pull(skb, skb_network_header_len(skb)); if (opt->opt_flen) ipv6_push_frag_opts(skb, opt, &proto); if (opt->opt_nflen) ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst, &fl6->saddr); + skb_push(skb, sizeof(struct ipv6hdr)); + skb_reset_network_header(skb); } - skb_push(skb, sizeof(struct ipv6hdr)); - skb_reset_network_header(skb); hdr = ipv6_hdr(skb); - ip6_flow_hdr(hdr, v6_cork->tclass, ip6_make_flowlabel(net, skb, fl6->flowlabel, ip6_autoflowlabel(net, np), fl6)); From patchwork Thu Apr 28 10:56:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12830418 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4C0BC433FE for ; Thu, 28 Apr 2022 10:58:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235049AbiD1LBY (ORCPT ); Thu, 28 Apr 2022 07:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344975AbiD1LBI (ORCPT ); Thu, 28 Apr 2022 07:01:08 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FB899728B; Thu, 28 Apr 2022 03:57:50 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id p7-20020a05600c358700b00393e80c59daso3821699wmq.0; Thu, 28 Apr 2022 03:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YHrgbwGuKsi0qBohJI6HWm6IXg77xQmft6cGgAr+KkM=; b=G08PfzWMMNczVdgm19wLhWwXkL0bjiazN2I6VAZLCQodi6Vb+C0Ia1UxSEIcuugs7Y Cc+n2Rtvk6yDrG/5nOM9cuDxyWaFgzzw5r+IxcVHlE7qcLeIoU2rsDae1x/zckgflrQ7 iAkSz1mC7rz6t7OwL0y/uHH9tSCQVD47Ixt2w/y+Fhio/pisp51ckJ4T8DE5yB7EC6P8 75c6Sw8vIHNXU1h3H7f+W+Md4AavCTscw7yY4vDcEhJlMsQWjyv0rHIUGhogdvt2qc8G hNcUaxATzp4h0NR4DKUY8ZBvl4HOt8LZYRMu9XWlczNx4YLm9CET5MCkMBVw355GOSuG z7TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YHrgbwGuKsi0qBohJI6HWm6IXg77xQmft6cGgAr+KkM=; b=pEKjOzOV9X2KB4ducBiMYfBNxMK/LAqyRUBKCEhrGUvONqpxkgnLMhaEb24mNAuy9U 0gpK7M/ZTKO1jnHFyLLXxeNsOL7K8V+Q59REkYZH4uNhK1Gu1jwTHP6VrVWPpyvbObi7 Ndwkg1vbuOipv6w8ZTM0KhiTbHXx9dCi2dZODoziXM7BxvSVXiVliMFS/prgHd9eTkF9 3SUARfvG/NGqWFqQxCVMjbPNx1bnnYnhKXhjZ5rEC0XDD4T6usInX+ALE0TcYVhTy0wm K2Xl2E8JBqdDh2Wd6qgmLra2dhzsGmxvokE8LlkTeXb5wZIw3C9LzCCtpdo3h9B7MeTe U8hw== X-Gm-Message-State: AOAM533ypdlPwCMrm+vNBag8VnAKz1TBnuKJUydmm7tjFA/YXlprIlpe +2pePQQLRegyl5xMLKYrl+JZ1o3bQ7E= X-Google-Smtp-Source: ABdhPJwNB3CIXpmBVqQuNvVTeogjYXy4OSUnrAq0pSj4BB/n0N/SyvnNTi7eUWnXrYvPvLrMaAl/PA== X-Received: by 2002:a1c:4e0b:0:b0:393:fd8f:e340 with SMTP id g11-20020a1c4e0b000000b00393fd8fe340mr8685091wmh.136.1651143468417; Thu, 28 Apr 2022 03:57:48 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-230-8.dab.02.net. [82.132.230.8]) by smtp.gmail.com with ESMTPSA id z11-20020a7bc14b000000b0039419dfbb39sm7547wmi.33.2022.04.28.03.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:57:48 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next 10/10] ipv6: clean up ip6_setup_cork Date: Thu, 28 Apr 2022 11:56:43 +0100 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Do a bit of refactoring for ip6_setup_cork(). Cache a xfrm_dst_path() result to not call it twice, reshuffle ifs to not repeat some parts twice and so. Signed-off-by: Pavel Begunkov --- net/ipv6/ip6_output.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 416d14299242..a17b26d5f34d 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1358,15 +1358,13 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, struct ipv6_pinfo *np = inet6_sk(sk); unsigned int mtu; struct ipv6_txoptions *nopt, *opt = ipc6->opt; + struct dst_entry *xrfm_dst; /* callers pass dst together with a reference, set it first so * ip6_cork_release() can put it down even in case of an error. */ cork->base.dst = &rt->dst; - /* - * setup for corking - */ if (opt) { if (WARN_ON(v6_cork->opt)) return -EINVAL; @@ -1399,28 +1397,26 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, } v6_cork->hop_limit = ipc6->hlimit; v6_cork->tclass = ipc6->tclass; - if (rt->dst.flags & DST_XFRM_TUNNEL) - mtu = np->pmtudisc >= IPV6_PMTUDISC_PROBE ? - READ_ONCE(rt->dst.dev->mtu) : dst_mtu(&rt->dst); + + xrfm_dst = xfrm_dst_path(&rt->dst); + if (dst_allfrag(xrfm_dst)) + cork->base.flags |= IPCORK_ALLFRAG; + + if (np->pmtudisc < IPV6_PMTUDISC_PROBE) + mtu = dst_mtu(rt->dst.flags & DST_XFRM_TUNNEL ? &rt->dst : xrfm_dst); else - mtu = np->pmtudisc >= IPV6_PMTUDISC_PROBE ? - READ_ONCE(rt->dst.dev->mtu) : dst_mtu(xfrm_dst_path(&rt->dst)); - if (np->frag_size < mtu) { - if (np->frag_size) - mtu = np->frag_size; - } + mtu = READ_ONCE(rt->dst.dev->mtu); + + if (np->frag_size < mtu && np->frag_size) + mtu = np->frag_size; + cork->base.fragsize = mtu; cork->base.gso_size = ipc6->gso_size; cork->base.tx_flags = 0; cork->base.mark = ipc6->sockc.mark; sock_tx_timestamp(sk, ipc6->sockc.tsflags, &cork->base.tx_flags); - - if (dst_allfrag(xfrm_dst_path(&rt->dst))) - cork->base.flags |= IPCORK_ALLFRAG; cork->base.length = 0; - cork->base.transmit_time = ipc6->sockc.transmit_time; - return 0; }