From patchwork Thu Jan 21 08:45:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 369280 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 3C461C433E0 for ; Thu, 21 Jan 2021 19:39:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBC9D23A53 for ; Thu, 21 Jan 2021 19:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725823AbhAUStX (ORCPT ); Thu, 21 Jan 2021 13:49:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728027AbhAUIqz (ORCPT ); Thu, 21 Jan 2021 03:46:55 -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 02BFCC0613C1 for ; Thu, 21 Jan 2021 00:45:58 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id i7so922747pgc.8 for ; Thu, 21 Jan 2021 00:45:57 -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=d2blpBkYNzJ/F4Vj0Wdef50NzhPRGTYyrfkCeYf6UwI=; b=Hj/hKfqv0DePbXsG9/RqSIcRZ1txPdZWz+6wB34f+4VenA/BJk5OEdUVJd/u/YVcWr KoQgkUHXimF+Dc0NtIFeUsWwXiaYI3aEgXmce083VJVk9e6s0kyL395jdnpA6FJD5NBG h72FDuu2WCpMwbE5Ig0qu8gApoY5Shx+EvAubxEcF3gtZsv67dQdtwgMZDjRQDt2t88C 25nsV6wjyqlROGrTqWCgpoa1xU8uz6r0x1i/CojLl/MGUjYfm72mU7obbvnFPfznPQXv 0cNbnSG8omOxa9ssAYRnKzsXQEpNgK7wuxEztimg/xZEdkkusW1SwuFq30UL8yOa3cJv AZGQ== 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=d2blpBkYNzJ/F4Vj0Wdef50NzhPRGTYyrfkCeYf6UwI=; b=n3U3exwpuWY/rg4MZ83uNj8JoAseN+S7I64CmSJMsOLafgdV6m2kp+Tgnyyqbp5tyP 4K2nrQCFOxUQB/xxxkpj9HbGJ3/YuQa3MpbnUD3Mk04EsO5uNrSGFQvBOYqu4iVzo1vN 7k+X5MssXft5N999xgpAEuIo709rcLLLqPod7M3QlmBmVF0hYE2aoHrRCWv5ob5FjNla EofQcAmbkw0zbP8RU1ilAwqCGutz8x1VEki3yZdNHZW3jf1Pm16K99kDfMUnAXm1H8Xt v9/tigjXiB0FFel9suuBQeT6AG7iK+j46Jfv8oadfmNA/72OaRebAaeBM+qJks9YueBf HgJg== X-Gm-Message-State: AOAM531YcU3bjywL931nFDsWcA+wBQeE9XPMQSsmRF8pK6w7mfOosk7Y TsyHX+rnr8d1R9BB/65w1mKdmSvwwiQ= X-Google-Smtp-Source: ABdhPJwd2qsz8gheFRiV9/jCqIrtRYu0h54UglaexWZS0qq/dxB//wLAKUYUXowGhX9OCqc4Qxn+cA== X-Received: by 2002:a63:914b:: with SMTP id l72mr1140698pge.411.1611218757157; Thu, 21 Jan 2021 00:45:57 -0800 (PST) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id mw15sm4867858pjb.34.2021.01.21.00.45.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jan 2021 00:45:56 -0800 (PST) From: Xin Long To: network dev Cc: Marcelo Ricardo Leitner , Davide Caratti , davem@davemloft.net, Jakub Kicinski , Alexander Duyck Subject: [PATCH net-next 1/3] net: rename csum_not_inet to csum_type Date: Thu, 21 Jan 2021 16:45:36 +0800 Message-Id: <0fa4f7f04222e0c4e7bd27cbd86ffe22148f6476.1611218673.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 This patch is to rename csum_not_inet to csum_type, as later more csum type would be introduced in the next patch. Signed-off-by: Xin Long --- include/linux/skbuff.h | 19 +++++++++++-------- net/core/dev.c | 2 +- net/sched/act_csum.c | 2 +- net/sctp/offload.c | 2 +- net/sctp/output.c | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 186dad2..67b0a01 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -169,7 +169,7 @@ * skb_csum_hwoffload_help() can be called to resolve CHECKSUM_PARTIAL based * on network device checksumming capabilities: if a packet does not match * them, skb_checksum_help or skb_crc32c_help (depending on the value of - * csum_not_inet, see item D.) is called to resolve the checksum. + * csum_type, see item D.) is called to resolve the checksum. * * CHECKSUM_NONE: * @@ -190,12 +190,12 @@ * NETIF_F_SCTP_CRC - This feature indicates that a device is capable of * offloading the SCTP CRC in a packet. To perform this offload the stack * will set csum_start and csum_offset accordingly, set ip_summed to - * CHECKSUM_PARTIAL and set csum_not_inet to 1, to provide an indication in - * the skbuff that the CHECKSUM_PARTIAL refers to CRC32c. + * CHECKSUM_PARTIAL and set csum_type to CSUM_T_SCTP_CRC, to provide an + * indication in the skbuff that the CHECKSUM_PARTIAL refers to CRC32c. * A driver that supports both IP checksum offload and SCTP CRC32c offload * must verify which offload is configured for a packet by testing the - * value of skb->csum_not_inet; skb_crc32c_csum_help is provided to resolve - * CHECKSUM_PARTIAL on skbs where csum_not_inet is set to 1. + * value of skb->csum_type; skb_crc32c_csum_help is provided to resolve + * CHECKSUM_PARTIAL on skbs where csum_type is set to CSUM_T_SCTP_CRC. * * NETIF_F_FCOE_CRC - This feature indicates that a device is capable of * offloading the FCOE CRC in a packet. To perform this offload the stack @@ -222,6 +222,9 @@ #define CHECKSUM_COMPLETE 2 #define CHECKSUM_PARTIAL 3 +#define CSUM_T_INET 0 +#define CSUM_T_SCTP_CRC 1 + /* Maximum value in skb->csum_level */ #define SKB_MAX_CSUM_LEVEL 3 @@ -677,7 +680,7 @@ typedef unsigned char *sk_buff_data_t; * @encapsulation: indicates the inner headers in the skbuff are valid * @encap_hdr_csum: software checksum is needed * @csum_valid: checksum is already valid - * @csum_not_inet: use CRC32c to resolve CHECKSUM_PARTIAL + * @csum_type: do the checksum offload according to this type * @csum_complete_sw: checksum was completed by software * @csum_level: indicates the number of consecutive checksums found in * the packet minus one that have been verified as @@ -836,7 +839,7 @@ struct sk_buff { __u8 vlan_present:1; __u8 csum_complete_sw:1; __u8 csum_level:2; - __u8 csum_not_inet:1; + __u8 csum_type:1; __u8 dst_pending_confirm:1; #ifdef CONFIG_IPV6_NDISC_NODETYPE __u8 ndisc_nodetype:2; @@ -4623,7 +4626,7 @@ static inline void skb_reset_redirect(struct sk_buff *skb) static inline bool skb_csum_is_sctp(struct sk_buff *skb) { - return skb->csum_not_inet; + return skb->csum_type == CSUM_T_SCTP_CRC; } static inline void skb_set_kcov_handle(struct sk_buff *skb, diff --git a/net/core/dev.c b/net/core/dev.c index d9ce02e..3241de2 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3279,7 +3279,7 @@ int skb_crc32c_csum_help(struct sk_buff *skb) crc32c_csum_stub)); *(__le32 *)(skb->data + offset) = crc32c_csum; skb->ip_summed = CHECKSUM_NONE; - skb->csum_not_inet = 0; + skb->csum_type = 0; out: return ret; } diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c index 4fa4fcb..9fabb6e 100644 --- a/net/sched/act_csum.c +++ b/net/sched/act_csum.c @@ -376,7 +376,7 @@ static int tcf_csum_sctp(struct sk_buff *skb, unsigned int ihl, sctph->checksum = sctp_compute_cksum(skb, skb_network_offset(skb) + ihl); skb->ip_summed = CHECKSUM_NONE; - skb->csum_not_inet = 0; + skb->csum_type = 0; return 1; } diff --git a/net/sctp/offload.c b/net/sctp/offload.c index eb874e3..372f373 100644 --- a/net/sctp/offload.c +++ b/net/sctp/offload.c @@ -26,7 +26,7 @@ static __le32 sctp_gso_make_checksum(struct sk_buff *skb) { skb->ip_summed = CHECKSUM_NONE; - skb->csum_not_inet = 0; + skb->csum_type = 0; /* csum and csum_start in GSO CB may be needed to do the UDP * checksum when it's a UDP tunneling packet. */ diff --git a/net/sctp/output.c b/net/sctp/output.c index 6614c9f..a8cf0191 100644 --- a/net/sctp/output.c +++ b/net/sctp/output.c @@ -523,7 +523,7 @@ static int sctp_packet_pack(struct sctp_packet *packet, } else { chksum: head->ip_summed = CHECKSUM_PARTIAL; - head->csum_not_inet = 1; + head->csum_type = CSUM_T_SCTP_CRC; head->csum_start = skb_transport_header(head) - head->head; head->csum_offset = offsetof(struct sctphdr, checksum); } From patchwork Thu Jan 21 08:45:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 368469 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 2BABBC433E0 for ; Thu, 21 Jan 2021 19:41:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBBD023A60 for ; Thu, 21 Jan 2021 19:41:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726404AbhAUSsR (ORCPT ); Thu, 21 Jan 2021 13:48:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728034AbhAUIqz (ORCPT ); Thu, 21 Jan 2021 03:46:55 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3344FC0613CF for ; Thu, 21 Jan 2021 00:46:06 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id y205so1101139pfc.5 for ; Thu, 21 Jan 2021 00:46:06 -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=T/kOn/K024TpuPWtmw1eFn6iyRtsLplc24wC47bYr/w=; b=kI+ndFObMxOoERGMPJ3llUwoEPCzuaeNkHYO4Nk5hAeyWjApGcgQmjF2Ana+bwC9Pg 0EC+ciQYrwQG+eNsgACJGO5qiXNn4beDRuxrhV07KmXZb1A19tArDNX681WsH5afT4Fo +3fEPgtnNKi5QEV6uYp4vRIM3NPljtL6M38r1qrOjlVbWlFVeg9uQ3M44Gm1U3ZxiOSU AMiODdhM0LtejcJGnH1S+tPFXVkSTSdn5vD8LAAxrNcGrG2rttpjUnI8pBpwCVbMPiiR V1MoJOBm6fA4UMDhnf4FcCYeyBXlNcxJeurPiIiFhYwO+8MZSp0CRDSGePWCY+Y4smHZ Xwow== 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=T/kOn/K024TpuPWtmw1eFn6iyRtsLplc24wC47bYr/w=; b=AIHEurD/SF0VtVhoZmVBDTLm1udfTknuPmdfsghBGvzzsnoRsnKchRUsidMdsa6TwI n1HkOpwYW718772F6DsQpw9+d70iepXEvf+EZp2UplN8ngEx50YTPBQ22FVjViHB+6Eb X9+x3Qv719Y4S9YY7xr2jtKvz4MehrT2XOuhvagPB7kSBMLu1q3Qh1oHbtRB5rVMlcDM YDm0YZ+QbjHlytmT7PlruE/wEVyntLiMgvZZ5UimPxQR4KowlPNHzNnnpzZ/6FAuyJuJ FyF3Fn/QhEnBPH2J5t3RGmh1mac/MHXr1gzgkovSpMEqGLqlAhKl4CcYA2bI5u1W/a7B HytQ== X-Gm-Message-State: AOAM531mqfrTgKAkjpMj1F0pAfZQTc36zNF0D4GZeMZUC3JT6wtVwn9j wgwkbZc1dYAIhxf0gEyryTzySFBL/ZE= X-Google-Smtp-Source: ABdhPJy0TVrMnDc1VOmgKPvDd3JC7YJ1Qiq5EDi9VbaViqaOeBOx/wxon9k507PW6Eiq3GQymIZ66w== X-Received: by 2002:a62:ed09:0:b029:1bb:3ffc:b7f9 with SMTP id u9-20020a62ed090000b02901bb3ffcb7f9mr5504068pfh.52.1611218765471; Thu, 21 Jan 2021 00:46:05 -0800 (PST) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id h11sm4767375pjg.46.2021.01.21.00.46.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jan 2021 00:46:04 -0800 (PST) From: Xin Long To: network dev Cc: Marcelo Ricardo Leitner , Davide Caratti , davem@davemloft.net, Jakub Kicinski , Alexander Duyck Subject: [PATCH net-next 2/3] net: add CSUM_T_IP_GENERIC csum_type Date: Thu, 21 Jan 2021 16:45:37 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <0fa4f7f04222e0c4e7bd27cbd86ffe22148f6476.1611218673.git.lucien.xin@gmail.com> References: <0fa4f7f04222e0c4e7bd27cbd86ffe22148f6476.1611218673.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch is to extend csum_type field to 2 bits, and introduce CSUM_T_IP_GENERIC csum type, and add the support for this in skb_csum_hwoffload_help(), just like CSUM_T_SCTP_CRC. Note here it moves dst_pending_confirm field below ndisc_nodetype to avoid a memory hole. Signed-off-by: Xin Long --- include/linux/skbuff.h | 5 +++-- net/core/dev.c | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 67b0a01..d5011fb 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -224,6 +224,7 @@ #define CSUM_T_INET 0 #define CSUM_T_SCTP_CRC 1 +#define CSUM_T_IP_GENERIC 2 /* Maximum value in skb->csum_level */ #define SKB_MAX_CSUM_LEVEL 3 @@ -839,11 +840,11 @@ struct sk_buff { __u8 vlan_present:1; __u8 csum_complete_sw:1; __u8 csum_level:2; - __u8 csum_type:1; - __u8 dst_pending_confirm:1; + __u8 csum_type:2; #ifdef CONFIG_IPV6_NDISC_NODETYPE __u8 ndisc_nodetype:2; #endif + __u8 dst_pending_confirm:1; __u8 ipvs_property:1; __u8 inner_protocol_type:1; diff --git a/net/core/dev.c b/net/core/dev.c index 3241de2..6d48af2 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3617,11 +3617,20 @@ static struct sk_buff *validate_xmit_vlan(struct sk_buff *skb, int skb_csum_hwoffload_help(struct sk_buff *skb, const netdev_features_t features) { - if (unlikely(skb_csum_is_sctp(skb))) - return !!(features & NETIF_F_SCTP_CRC) ? 0 : - skb_crc32c_csum_help(skb); + if (likely(!skb->csum_type)) + return !!(features & NETIF_F_CSUM_MASK) ? 0 : + skb_checksum_help(skb); - return !!(features & NETIF_F_CSUM_MASK) ? 0 : skb_checksum_help(skb); + if (skb_csum_is_sctp(skb)) { + return !!(features & NETIF_F_SCTP_CRC) ? 0 : + skb_crc32c_csum_help(skb); + } else if (skb->csum_type == CSUM_T_IP_GENERIC) { + return !!(features & NETIF_F_HW_CSUM) ? 0 : + skb_checksum_help(skb); + } else { + pr_warn("Wrong csum type: %d\n", skb->csum_type); + return 1; + } } EXPORT_SYMBOL(skb_csum_hwoffload_help); From patchwork Thu Jan 21 08:45:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 368475 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 C0E71C433DB for ; Thu, 21 Jan 2021 18:50:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F3D023A1C for ; Thu, 21 Jan 2021 18:50:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726666AbhAUSuZ (ORCPT ); Thu, 21 Jan 2021 13:50:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728060AbhAUIrK (ORCPT ); Thu, 21 Jan 2021 03:47:10 -0500 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E715C061575 for ; Thu, 21 Jan 2021 00:46:14 -0800 (PST) Received: by mail-pg1-x535.google.com with SMTP id z21so935914pgj.4 for ; Thu, 21 Jan 2021 00:46:14 -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=bfYcNjs9yLyzTbVMgIgcdJUR93FtgJul/qWPg+jtbPg=; b=W6g/Teqo2Dag7nCWOwvqFBQmUIpLr/igIqzICtiVMjYoTmSYD7+frx3wJlDwfsz2kP FzaDSAVmYyXbqfvBH1Q935JK/esCdVTO/wCjZwIRRmasXMHwpsZ77oOncWCHJ7pGtM7u V9vW6Sge8fwHJQyJkOljuuvDiYj1xhEt708MEIxNzuwCuRYCF5HRuS1cWnMocwsvvyW7 XtgP21b9+HefbGM+ZwIS5i2J224YahXyoahjsZhVllEk4Ld2zrMR+fL30UDRVU1tcavA KDXd4OVviC5aO21xSu/iV1dQPeJrDC1giVBsxQL4XwW0lEBNTwYLiWrlv+eH0sFRo5+Z y1Yw== 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=bfYcNjs9yLyzTbVMgIgcdJUR93FtgJul/qWPg+jtbPg=; b=pWccSE9o7WxKaoB8vOFmTP4Krvkd34zSNdmg036R9z8U14k/nYeMDFqY4V+2Zyph8D wBlXPOYkPPXgI1K9ReJzU9b48Vv5Esp8c3yslDEiqfiZh05K0BKIIX/wdCbemvbiTtFa zB+V7QDx0f6CFxK1jIC8dFvmGmhV1cStanhXM7EhGYC2NqmH1flNGAmdgZMtypcUP74E YiIJl3TXZcueXR++kfTA7GdTz65CHMSGr9fUw+dytpnF6g5Gs2Vl5rLRH3g1sXvJIaa3 qA/WxWxYwSy7jSd21xO1cU8ISe/lo1iKn9PSIFp4ScOON4IIDsdnzEmERwFsIOn0rfHN kqbg== X-Gm-Message-State: AOAM531+Bgmlh543i1QDnaABE8Tm8V76immxlv4a+3U17p0D4pP2ftwr EcNEclz+xRewMUPCZL7o0FCAftWXepM= X-Google-Smtp-Source: ABdhPJxVMP03LD0qNluuRf9LVpUeCMScTB9hBPbJsRkhc1K0DXmb8AIs8VyXDwnW+GtRxyQBDKZpQQ== X-Received: by 2002:a62:6585:0:b029:1b9:d8d9:1af2 with SMTP id z127-20020a6265850000b02901b9d8d91af2mr10632809pfb.17.1611218773876; Thu, 21 Jan 2021 00:46:13 -0800 (PST) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id e63sm4808202pfe.216.2021.01.21.00.46.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jan 2021 00:46:13 -0800 (PST) From: Xin Long To: network dev Cc: Marcelo Ricardo Leitner , Davide Caratti , davem@davemloft.net, Jakub Kicinski , Alexander Duyck Subject: [PATCH net-next 3/3] ip_gre: add csum offload support for gre header Date: Thu, 21 Jan 2021 16:45:38 +0800 Message-Id: <2f662d55a698ef6d7af2b549f39b72d5b3a4f815.1611218673.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <0fa4f7f04222e0c4e7bd27cbd86ffe22148f6476.1611218673.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. Signed-off-by: Xin Long --- include/net/gre.h | 20 ++++++++------------ net/ipv4/gre_offload.c | 16 ++++++++++++++-- net/sctp/output.c | 1 + 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/include/net/gre.h b/include/net/gre.h index b60f212..250b2fb 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,14 @@ 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->csum_type = CSUM_T_IP_GENERIC; + 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..12d6996 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,14 @@ 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->csum_type = CSUM_T_IP_GENERIC; + 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; diff --git a/net/sctp/output.c b/net/sctp/output.c index a8cf0191..52e12df 100644 --- a/net/sctp/output.c +++ b/net/sctp/output.c @@ -515,6 +515,7 @@ static int sctp_packet_pack(struct sctp_packet *packet, return 1; if (!(tp->dst->dev->features & NETIF_F_SCTP_CRC) || + tp->dst->dev->type == ARPHRD_IPGRE || dst_xfrm(tp->dst) || packet->ipfragok || tp->encap_port) { struct sctphdr *sh = (struct sctphdr *)skb_transport_header(head);