From patchwork Sun Jan 24 08:44:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 370508 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5F33C433E0 for ; Sun, 24 Jan 2021 08:46:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E09022C9C for ; Sun, 24 Jan 2021 08:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726590AbhAXIqL (ORCPT ); Sun, 24 Jan 2021 03:46:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726456AbhAXIp7 (ORCPT ); Sun, 24 Jan 2021 03:45:59 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4528FC06174A for ; Sun, 24 Jan 2021 00:45:09 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id v19so6866814pgj.12 for ; Sun, 24 Jan 2021 00:45:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=yF1/rZdC1UjfjxzVhZlCIxkNqUGI4he3FVfdNHhm1u0=; b=DnxOl4DO+Do8EXLOaalACs63drdQmC43tBRVk5Htr3/5OsYF4TzFitNCylHVSHSOqC VDJuI4Ut3++yPBwigUspgAtCQME9d4d8jV4DRx/hHC4Z0FdVjJeTciDFdwdw6lZK8ur+ 6DuThnCb6lHCgvXTzSQ82RpUG1IDbBQ460J5TDjHf7s6dRnav+Jx5JJAJKPp0Zfz8LWK qWPLIuHR8joiRNNwzxOEIxv3F0y1JNxZD/7uwFlWl8qgM/7C2kWuSWVee6NfGYSaZTua HsmHM66PW/L3nZsr2TVvzfx1cewsQNBazjZay76LvZCvbDdAYLviKepRuqCyl/wrnKY4 YHFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=yF1/rZdC1UjfjxzVhZlCIxkNqUGI4he3FVfdNHhm1u0=; b=ep3mAIGMB0TJ0hcFPrd91TD1AkkE+OAMWXC7WCAg9241iexISaJFGdjN7FtLT/Wcmg JaN2+wtj/LPpywDLHNtJFvEmP6xCZmGGRLk2TCaz8NcTE8JKVhyDT4NM6/9ww1yiPq+V P3GiCqkesXnBbYJ++e1MqMD/L9qvPP9Xsj/9MEIXjvRk9y0fAlABhUIfptH6yZz0A0oP ZYobL7IRkcWGwjqEsKEVZQ0HePXzyPFDgI/ounojc2y0aD4P59/QLtmrPHsaOihKUIp+ vnI9xPGJXMd9xTa+G4S+He1GdacB4XGMTTtfs5bWBlK13somF7CJej3jKZj1V19uhiJN MPsA== X-Gm-Message-State: AOAM530ZdEDh2H/ZVGgPK6K3YiXP7Xp+vSVHATsf0mSzPtqj7nue42Bn ElbQx07wGDoLjv3m5s+Prx38ckCG8Ax+aw== X-Google-Smtp-Source: ABdhPJx1tji78g97p0SQRGsXcEGVoeib9DhrpC+XLfbLrUIJGRKU00r50kaFRA8vFaTo4ADDtPMIwg== X-Received: by 2002:a62:7fc1:0:b029:19f:1dab:5029 with SMTP id a184-20020a627fc10000b029019f1dab5029mr12835258pfd.13.1611477908613; Sun, 24 Jan 2021 00:45:08 -0800 (PST) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id i10sm13550354pgt.85.2021.01.24.00.45.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Jan 2021 00:45:08 -0800 (PST) From: Xin Long To: network dev Cc: Marcelo Ricardo Leitner , davem@davemloft.net, Jakub Kicinski , Davide Caratti , Alexander Duyck Subject: [PATCH net-next 1/2] net: support ip generic csum processing in skb_csum_hwoffload_help Date: Sun, 24 Jan 2021 16:44:51 +0800 Message-Id: <100e0b32b0322e70127f415ea5b26afd26ac0fed.1611477858.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org NETIF_F_IP|IPV6_CSUM feature flag indicates UDP and TCP csum offload while NETIF_F_HW_CSUM feature flag indicates ip generic csum offload for HW, which includes not only for TCP/UDP csum, but also for other protocols' csum like GRE's. However, in skb_csum_hwoffload_help() it only checks features against NETIF_F_CSUM_MASK(NETIF_F_HW|IP|IPV6_CSUM). So if it's a non TCP/UDP packet and the features doesn't support NETIF_F_HW_CSUM, but supports NETIF_F_IP|IPV6_CSUM only, it would still return 0 and leave the HW to do csum. This patch is to support ip generic csum processing by checking NETIF_F_HW_CSUM for all protocols, and check (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM) only for TCP and UDP. v1->v2: - not extend skb->csum_not_inet, but use skb->csum_offset to tell if it's an UDP/TCP csum packet. Suggested-by: Alexander Duyck Signed-off-by: Xin Long --- net/core/dev.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index 6df3f1b..aae116d 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3621,7 +3621,18 @@ int skb_csum_hwoffload_help(struct sk_buff *skb, return !!(features & NETIF_F_SCTP_CRC) ? 0 : skb_crc32c_csum_help(skb); - return !!(features & NETIF_F_CSUM_MASK) ? 0 : skb_checksum_help(skb); + if (features & NETIF_F_HW_CSUM) + return 0; + + if (features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)) { + switch (skb->csum_offset) { + case offsetof(struct tcphdr, check): + case offsetof(struct udphdr, check): + return 0; + } + } + + return skb_checksum_help(skb); } EXPORT_SYMBOL(skb_csum_hwoffload_help); From patchwork Sun Jan 24 08:44:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 370123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B11DC433DB for ; Sun, 24 Jan 2021 08:46:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E81D022C9D for ; Sun, 24 Jan 2021 08:46:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726600AbhAXIqb (ORCPT ); Sun, 24 Jan 2021 03:46:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726456AbhAXIqP (ORCPT ); Sun, 24 Jan 2021 03:46:15 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9D97C061756 for ; Sun, 24 Jan 2021 00:45:17 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id h15so3267590pli.8 for ; Sun, 24 Jan 2021 00:45:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=mK0/+9iW2x8uz2VxyxWZQDGjXg3EBuKUOG/sV5MybAs=; b=jxy+h3G9XVNZV0ZZ+6/wXUN9CzeSnxP7iUpA/4SQk4xcsU65xdbEmFIZ01fljeW4ic izdg7hITd4179Z+fnoA2/ifma5cTdqkqTmTTYa3ezipLldHUWDB54iMVUq8wvlcN1zbz oFoge6JaWLu5JCWRNQyhZwJEmR5bd2/HaGh6HErqD49V7OgHCgMvtQPL3mjqtOaQlqmN wTaSCjuoUfjSkfxa7NOatYYbl12Lbma/qnvoU0elqEsV/Y6fhChx56iWQq/dhxPiHPq5 DXSfrAMvOo4xUem/z+CwyowgcsIAjQHxzrEdpOPqWcxe5cq5zRJsA7I6scGhET3UOMWw UeZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=mK0/+9iW2x8uz2VxyxWZQDGjXg3EBuKUOG/sV5MybAs=; b=l/55pbfJlVgAry3SPf2L5W8aZ9bg0/9Fzq0V0ZfRcvZAodmL2Mq2HYjr/SxxkmHF48 8zRENAUONzdcpkzYpNwpxskKoRuCGmeGAZtCfAHzxS47wFxtPkl4SUyel7+EFPjW61be 6DcYqdj2K9rQ6w6n3dLki4yrlKFjwNNeLVhMekzEfJOPrUGWznXaFh3P+KCkM2uW3mKG Zf+OqXze7Zg/8AfM4cMgRLvN83ft4B5kxbqLUfsYBxRPvstQboPrdBAO2OzZ1f7uLuho 3Yn5GnMk07SSb0/KSLqxpW/CD9g6MnecpvmK+LJPDFDB84c76D/tWwksrHkzIrkGkfLn XqUg== X-Gm-Message-State: AOAM530X/nRf0bF9QM+rfsK31AUrfxF7E/C6PYftrROjo1Xn8e87C0PN 0kPppCM77+A3y3K15wNRghGasOiF80/oPA== X-Google-Smtp-Source: ABdhPJwIfo3tQHs23WgdEQ5KOur1pvCtPwN6/mNEDxDPds2D6qVOdufkxLXMWfiP3gFdw7mHn+56rg== X-Received: by 2002:a17:902:8b8a:b029:df:fff2:c133 with SMTP id ay10-20020a1709028b8ab02900dffff2c133mr143164plb.63.1611477917096; Sun, 24 Jan 2021 00:45:17 -0800 (PST) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id u4sm14480713pjv.22.2021.01.24.00.45.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Jan 2021 00:45:16 -0800 (PST) From: Xin Long To: network dev Cc: Marcelo Ricardo Leitner , davem@davemloft.net, Jakub Kicinski , Davide Caratti , Alexander Duyck Subject: [PATCH net-next 2/2] ip_gre: add csum offload support for gre header Date: Sun, 24 Jan 2021 16:44:52 +0800 Message-Id: <045a48adc4ff5d81e2ff9f685a9a8c4cea56b792.1611477858.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <100e0b32b0322e70127f415ea5b26afd26ac0fed.1611477858.git.lucien.xin@gmail.com> References: <100e0b32b0322e70127f415ea5b26afd26ac0fed.1611477858.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch is to add csum offload support for gre header: On the TX path in gre_build_header(), when CHECKSUM_PARTIAL's set for inner proto, it will calculate the csum for outer proto, and inner csum will be offloaded later. Otherwise, CHECKSUM_PARTIAL and csum_start/offset will be set for outer proto, and the outer csum will be offloaded later. On the GSO path in gre_gso_segment(), when CHECKSUM_PARTIAL is not set for inner proto and the hardware supports csum offload, CHECKSUM_PARTIAL and csum_start/offset will be set for outer proto, and outer csum will be offloaded later. Otherwise, it will do csum for outer proto by calling gso_make_checksum(). Note that SCTP has to do the csum by itself for non GSO path in sctp_packet_pack(), as gre_build_header() can't handle the csum with CHECKSUM_PARTIAL set for SCTP CRC csum offload. v1->v2: - remove the SCTP part, as GRE dev doesn't support SCTP CRC CSUM and it will always do checksum for SCTP in sctp_packet_pack() when it's not a GSO packet. Signed-off-by: Xin Long --- include/net/gre.h | 19 +++++++------------ net/ipv4/gre_offload.c | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/net/gre.h b/include/net/gre.h index b60f212..4e20970 100644 --- a/include/net/gre.h +++ b/include/net/gre.h @@ -106,17 +106,6 @@ static inline __be16 gre_tnl_flags_to_gre_flags(__be16 tflags) return flags; } -static inline __sum16 gre_checksum(struct sk_buff *skb) -{ - __wsum csum; - - if (skb->ip_summed == CHECKSUM_PARTIAL) - csum = lco_csum(skb); - else - csum = skb_checksum(skb, 0, skb->len, 0); - return csum_fold(csum); -} - static inline void gre_build_header(struct sk_buff *skb, int hdr_len, __be16 flags, __be16 proto, __be32 key, __be32 seq) @@ -146,7 +135,13 @@ static inline void gre_build_header(struct sk_buff *skb, int hdr_len, !(skb_shinfo(skb)->gso_type & (SKB_GSO_GRE | SKB_GSO_GRE_CSUM))) { *ptr = 0; - *(__sum16 *)ptr = gre_checksum(skb); + if (skb->ip_summed == CHECKSUM_PARTIAL) { + *(__sum16 *)ptr = csum_fold(lco_csum(skb)); + } else { + skb->ip_summed = CHECKSUM_PARTIAL; + skb->csum_start = skb_transport_header(skb) - skb->head; + skb->csum_offset = sizeof(*greh); + } } } } diff --git a/net/ipv4/gre_offload.c b/net/ipv4/gre_offload.c index 10bc49b..1121a9d 100644 --- a/net/ipv4/gre_offload.c +++ b/net/ipv4/gre_offload.c @@ -15,10 +15,10 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb, netdev_features_t features) { int tnl_hlen = skb_inner_mac_header(skb) - skb_transport_header(skb); + bool need_csum, offload_csum, gso_partial, need_ipsec; struct sk_buff *segs = ERR_PTR(-EINVAL); u16 mac_offset = skb->mac_header; __be16 protocol = skb->protocol; - bool need_csum, gso_partial; u16 mac_len = skb->mac_len; int gre_offset, outer_hlen; @@ -47,6 +47,11 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb, if (need_csum) features &= ~NETIF_F_SCTP_CRC; + need_ipsec = skb_dst(skb) && dst_xfrm(skb_dst(skb)); + /* Try to offload checksum if possible */ + offload_csum = !!(need_csum && !need_ipsec && + (skb->dev->features & NETIF_F_HW_CSUM)); + /* segment inner packet. */ segs = skb_mac_gso_segment(skb, features); if (IS_ERR_OR_NULL(segs)) { @@ -100,7 +105,13 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb, } *(pcsum + 1) = 0; - *pcsum = gso_make_checksum(skb, 0); + if (skb->encapsulation || !offload_csum) { + *pcsum = gso_make_checksum(skb, 0); + } else { + skb->ip_summed = CHECKSUM_PARTIAL; + skb->csum_start = skb_transport_header(skb) - skb->head; + skb->csum_offset = sizeof(*greh); + } } while ((skb = skb->next)); out: return segs;