From patchwork Thu Jan 28 09:18:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 12053241 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 X-Spam-Level: X-Spam-Status: No, score=-15.7 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 80798C433E0 for ; Thu, 28 Jan 2021 09:29:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5936864DEF for ; Thu, 28 Jan 2021 09:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231659AbhA1JVN (ORCPT ); Thu, 28 Jan 2021 04:21:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232516AbhA1JT3 (ORCPT ); Thu, 28 Jan 2021 04:19:29 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EC3BC06174A for ; Thu, 28 Jan 2021 01:18:49 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id w18so3593651pfu.9 for ; Thu, 28 Jan 2021 01:18:49 -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=eWfTH8I5aZb+Qsz9WIhVj682ORKxn6wMT2Ob0SnJQMs=; b=WRu/WLLADRMs7rOUUXYsaT0bBvccGuMdgRjSgp0oySkSQqUTvO3R6QcBxVcEzUBVod gawynDuw/AF85FxcuRIEx078kvyQ/M8AugjhAdo71cw/MNvMIBIDwaNLpaM5QzyR6Tm2 Wydb3MDeSG/56yuBjhYp6fmoyeT8ZnJATyQtEjlLyyWk4XATvhSzyNxBJEqxBPlIAX8w 6UfkUMEFGeNyUi135rZnJlUCxC/RwqO9I+AYIiu+iyYRLU+f2tlg2bE8+/NtXD4WyOb2 lvu00jmNbTn1DrfG7HuMB33abk+yFkgV/+E6c2zCTRyF4Ab0tFUkqdfv9Ru/lCrQX92y VpZA== 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=eWfTH8I5aZb+Qsz9WIhVj682ORKxn6wMT2Ob0SnJQMs=; b=JHHmBJyuHpTeGsXfj3zxWotH6+0fk8rAimA5GVJ8CRRKKRNJEzfUsmXIbwG28OpYIM Kw5WKJx2A48EKNkmUjUYXJj6vo38CPJmsc9kzgDsGC1N0Ty9tCKmhTXgnhyV7XlB52yJ CU7hXVWltJLOjEuk3J2klvtDjuH6JPDqeqc52GwtBFewIz3jkzpagOeR+LkM0rmZH5DN ghePqmPaIR3rmBklJIt3K5h6EnKdP3jHLED4Tu0zqS/deABQ8fvpfGgtHuqT+FnpQB1T Fkly9IWx9MgnvhhW9OT/i09ZFqMMqgQ6Sf8XxIyVnE3mHLy8An6uqOB6jNaNemftxFU3 ucJw== X-Gm-Message-State: AOAM531kOyyGNeswS47XgQAIFVq1Skcjeug/vlmIZV/qgL7gMXfX5M7g 3vhUHA409D/mFqxNfRZ7noQbq3vKa03Dxw== X-Google-Smtp-Source: ABdhPJyTAI/fFaRhNbltKHUy3ZiX6MCX2j+aNYU5jyn/FBZQSLsqq9V7Ae/QfSR0yFuWTyZtb0gHzg== X-Received: by 2002:aa7:90cf:0:b029:1a3:a176:f4d0 with SMTP id k15-20020aa790cf0000b02901a3a176f4d0mr14916769pfk.8.1611825528641; Thu, 28 Jan 2021 01:18:48 -0800 (PST) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id o14sm4618646pjf.12.2021.01.28.01.18.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jan 2021 01:18:48 -0800 (PST) From: Xin Long To: network dev Cc: Marcelo Ricardo Leitner , Davide Caratti , davem@davemloft.net, Jakub Kicinski , Willem de Bruijn , Alexander Duyck Subject: [PATCHv3 net-next 1/2] net: support ip generic csum processing in skb_csum_hwoffload_help Date: Thu, 28 Jan 2021 17:18:31 +0800 Message-Id: <02bef0921778d2053ab63140c31704712bb5a864.1611825446.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 X-Patchwork-Delegate: kuba@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. Note that we're using skb->csum_offset to check if it's a TCP/UDP proctol, this might be fragile. However, as Alex said, for now we only have a few L4 protocols that are requesting Tx csum offload, we'd better fix this until a new protocol comes with a same csum offset. v1->v2: - not extend skb->csum_not_inet, but use skb->csum_offset to tell if it's an UDP/TCP csum packet. v2->v3: - add a note in the changelog, as Willem suggested. 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 Thu Jan 28 09:18:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 12053229 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 X-Spam-Level: X-Spam-Status: No, score=-15.7 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 4EA92C433DB for ; Thu, 28 Jan 2021 09:23:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F053264DE2 for ; Thu, 28 Jan 2021 09:23:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232482AbhA1JVq (ORCPT ); Thu, 28 Jan 2021 04:21:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232531AbhA1JTj (ORCPT ); Thu, 28 Jan 2021 04:19:39 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74E35C061756 for ; Thu, 28 Jan 2021 01:18:58 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id u15so3001036plf.1 for ; Thu, 28 Jan 2021 01:18:58 -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=iT9IExS8cf4oqSnjqoHYUVDFQ2+rqVLuCdPf4MA7bB+opp+pw70BoUAEOBiK++SQs6 JIGxfYns/vb38LOkgbOuduiprs4hfo+5qzIjOF74T4R03PtmTK8kmAnDTl5b+eMicArP DzgtQaYjeCgfd652zwKr1e0meWLOHNQbUz3SWR9KKHVD4J53iueqkZIRm2ezSyWrpm5N FjLOvPAn+x0f6oVDyHRK/H8XnKz7ZxAk27EKkIbpVBTL8lm7I1OvKYeRTeRpQDDkyb4t 8gxDILVRu7DjIo2S/56AjL4H6YIkIgWBcwgOVeofI7zDPv4/HtPwEiYfKCG9rhDt7xE/ pYrw== 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=N1YTwqFWPrdK417gH+BMkMtpE93SufImMyf3N/sCA0x1u8bn8sjCtoKOCcKzCceNpP QwLUMRU0GhLbdHgr2IjVY43mv6d9B2Prz5wdaIdGM+EsWAX+JD2swroJ5J5vKrScSGDc 2Tg+n1+RUBR5ZoEQ4oKVFM/EgRY2gjzXZ8u5BmscXH0WIucU3jNXtkX+PilrDYUzfUjV harfOLaySclKC7HfY4LB8zoalUalZwYribpmdVPjmKjsFUStj4Mf8H+YVJ/SM/liSxoQ MtF7HMMEFa/78JKy045PPCfiaN/csEkIDC+hY4k012mGWM5IagkSKyfjhOF5g7zjAWQz 7JEw== X-Gm-Message-State: AOAM530j2TMm44k6gc6ALqGhbqSpVy54MG2XaRgqxkvLlM1gtX6SpycB YAhsL4JnrkbB2o8wPhLG5wh2zVbPPCgMcQ== X-Google-Smtp-Source: ABdhPJxxHvDbtR8fwb6D44Ww8DY8f9MeqO2/7J2YNgTJlMJ+a4trM+CBQPsv2KVqEUfAmETbVWrB6A== X-Received: by 2002:a17:903:248e:b029:de:b329:ffaa with SMTP id p14-20020a170903248eb02900deb329ffaamr15567840plw.71.1611825537639; Thu, 28 Jan 2021 01:18:57 -0800 (PST) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id i10sm4823491pgt.85.2021.01.28.01.18.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jan 2021 01:18:56 -0800 (PST) From: Xin Long To: network dev Cc: Marcelo Ricardo Leitner , Davide Caratti , davem@davemloft.net, Jakub Kicinski , Willem de Bruijn , Alexander Duyck Subject: [PATCHv3 net-next 2/2] ip_gre: add csum offload support for gre header Date: Thu, 28 Jan 2021 17:18:32 +0800 Message-Id: <6a8bceca30a03e63da07dcbf5c37de40b53d7978.1611825446.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <02bef0921778d2053ab63140c31704712bb5a864.1611825446.git.lucien.xin@gmail.com> References: <02bef0921778d2053ab63140c31704712bb5a864.1611825446.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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;