From patchwork Wed Jul 14 19:17:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 477281 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=-12.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_BASE64_TEXT, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 087F4C12002 for ; Wed, 14 Jul 2021 19:18:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1270613C8 for ; Wed, 14 Jul 2021 19:18:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240101AbhGNTVN (ORCPT ); Wed, 14 Jul 2021 15:21:13 -0400 Received: from mout.gmx.net ([212.227.15.15]:33871 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230139AbhGNTVL (ORCPT ); Wed, 14 Jul 2021 15:21:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1626290287; bh=1NBRlTgjfqUeCWVZMGYnD8k80BqYbSqvVSZtm5STHYw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=iwjHP7qUtqKnQKBWIxYUHizE+HCQt/zk9Eow4mRTslk5m+/3Kr8ZAjtyJ589s02Tw ZrHnROogL083TTqUcFTDJ94tUZNI5ur8x6Mrvym4b1dmzC0dQ4MdCbWt+3/RtC3iua fnKIOmTV3nhYZ1XKhXqbfW9IJ/chSdxOeKXeG2gs= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([149.172.237.67]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mq2nA-1lPgk9046k-00n8DO; Wed, 14 Jul 2021 21:18:07 +0200 From: Lino Sanfilippo To: woojung.huh@microchip.com Cc: UNGLinuxDriver@microchip.com, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Lino Sanfilippo Subject: [PATCH 1/2] net: dsa: tag_ksz: linearize SKB before adding DSA tag Date: Wed, 14 Jul 2021 21:17:22 +0200 Message-Id: <20210714191723.31294-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210714191723.31294-1-LinoSanfilippo@gmx.de> References: <20210714191723.31294-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:zG9W3k55wS/h0OdIs+SlIeLtet69YyCpxgFOl5IYJvy4b/Nigpi HFDEIoFeEx/5nfNXKJwgyEyt9p/fzo2c06lbL3Mns/iyo3g2C77QW9br1evxgLVAdfwyosn 6LR5E4HhR1kH2u1cqEhZVqf0gcNE/uWQQFbE3wQlTeyZoamC9vKKteEMBX31l5dBBNuRGFW OLexEsVIsFCaxg0LHegXw== X-UI-Out-Filterresults: notjunk:1; V03:K0:Ylk+XbVU5vY=:hTz0CNh5cPeJvElCX4T9Xi KqnxY0hlGQvK6WKNlAj27HEb8+LLnwnY2RJ+4rvR37WMjTTtfJJuyicysYGcyMsUui6F4AoiI 2jUjOMSxO8MUDR9gCaMqf/aUgOqXk+7i+uUlOpdDrWDto/WWw2QQ3lNrdctSYbjtQzzhgBa3c dEdPOmNwiWBn4QMr3W8+RbyJyb0EgnqXSBlrmDNBCpcf1UFVSCcIbnNeaSkZFiwrtIix+78vs jr+PU7hp477mMrmzzbkwqkbRL59u6daS0JxPDFDbCqPan0HTNU5D55BZ1HR4/i5iHizv1dcyI NP6dSGF/12+esVHBmLSdayRqmdwebZwfEXHnrUTi1sfSzq17mYR8yBKs570GPXQT6FbNlDgab ep2fEA/4nf3Gp6C6ophWmOslaHcHmhgoCSrg6rJzkxbg8prjSW526hURcibibwyckPfRG0CXo GWJA/7/b/3/dHtRyDDkPBiPS0K/Fav/Mzrl7fqgx7LLzrJkelEcki2rdof+3Ci3OSEUjtwwRr Jsec/gTGzMHwtnDL5FS275csKJP45nn9pbwPoFWYNXjys93mzSCe/YfdJpvUMtXlw482Z5ky0 QiHIBkuWUpQcMl9/DR7LdLROeQR7fxWpPv2EuAphWIr7fAazv318XVnwZlCSJ2One2jQQgwhN BY4x6yrImXMTvfpJgcF6Wc1g6xORGUfBbxzVbsRtvPCU7wbP7dlu/AKQWneZt+DvkQgUBWLoE 14U104iZ1MH5G/7u9UEUPU6mlEGvu2LjkZxyKJXN0TUBImQG5+MQ8Ee8eOHFhqu0VNA83p2R1 lNvXxXxs+Eh5F7Qzn/lUcfviZNDGaFC7ggtRLC5BuuOfy9wlW2cko4Hs1J0PQz0/o/hdfnyO+ 9lliX1sY7qR2t+OPDQ/kzBakzH4I3WgibQQ+soYHhl3yPGGX7qgkxo1VqqNZrXM/JOcjB27eI Ts83rIincMFfqU3ZuZTxypwJ40EOChHGdzzs9rOkMZZ2x4PmTt2j/ix5Qb2ICztkCFY5A1OwO q/bxTRcZ0fLxIL639Ov6VObXggg4QBXWUHz3eFBNwNnJiAE3guEbUSpzQTVtxOw23YOUuYq1u dToMamxLde9ugNG+gmcK6kfIvN7w2oFunnQ5vy/NPc6reAqLbfEffStRQ== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In ksz9477_xmit() skb_put() is used to add the DSA tag to the passed SKB. However skb_put() must only be called for linear SKBs which may not be the case if the DSA slave device inherited NETIF_F_SG from the master device. So make sure the SKB is always linearized. Signed-off-by: Lino Sanfilippo --- net/dsa/tag_ksz.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c index 53565f48934c..364f509d7cd7 100644 --- a/net/dsa/tag_ksz.c +++ b/net/dsa/tag_ksz.c @@ -53,6 +53,9 @@ static struct sk_buff *ksz8795_xmit(struct sk_buff *skb, struct net_device *dev) u8 *tag; u8 *addr; + if (skb_linearize(skb)) + return NULL; + /* Tag encoding */ tag = skb_put(skb, KSZ_INGRESS_TAG_LEN); addr = skb_mac_header(skb); @@ -114,6 +117,9 @@ static struct sk_buff *ksz9477_xmit(struct sk_buff *skb, u8 *addr; u16 val; + if (skb_linearize(skb)) + return NULL; + /* Tag encoding */ tag = skb_put(skb, KSZ9477_INGRESS_TAG_LEN); addr = skb_mac_header(skb); @@ -164,6 +170,9 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb, u8 *addr; u8 *tag; + if (skb_linearize(skb)) + return NULL; + /* Tag encoding */ tag = skb_put(skb, KSZ_INGRESS_TAG_LEN); addr = skb_mac_header(skb); From patchwork Wed Jul 14 19:17:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 477280 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=-12.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_BASE64_TEXT, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 30449C1B08C for ; Wed, 14 Jul 2021 19:18:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 156BE613C8 for ; Wed, 14 Jul 2021 19:18:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240149AbhGNTVR (ORCPT ); Wed, 14 Jul 2021 15:21:17 -0400 Received: from mout.gmx.net ([212.227.15.18]:48889 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230185AbhGNTVM (ORCPT ); Wed, 14 Jul 2021 15:21:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1626290287; bh=0Vu294fMLWIi7gFkQR70Ggc20BScAncxP5pTxianCVo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=QLHTr+1KaDMeaIooUyH6iPx6kKaUUXbvZ9290LCAN0rZWfYJnObH8KTsPxpEjKkw1 OGUdDUTTSMQp4VVPCE7PWIUb0ks82jg2X8zMzzENm7rVOpix9fZ3ku87j2852FVqVx 5CLlvdV4ypEd/PzBlmzJqCYMSIckFgbzHOzYCwGY= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([149.172.237.67]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MWRRZ-1lejeW1jWF-00XvkV; Wed, 14 Jul 2021 21:18:07 +0200 From: Lino Sanfilippo To: woojung.huh@microchip.com Cc: UNGLinuxDriver@microchip.com, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Lino Sanfilippo Subject: [PATCH 2/2] net: dsa: tag_ksz: dont let the hardware process the layer 4 checksum Date: Wed, 14 Jul 2021 21:17:23 +0200 Message-Id: <20210714191723.31294-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210714191723.31294-1-LinoSanfilippo@gmx.de> References: <20210714191723.31294-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:JCoB5BM+Bai/xCSzcnAL1DpJwVTKmW5Z3yW1PB+KpAG290y0d/2 nsDriOHoXw8vLXrLGyqKwZJX7CpsFKZUIY41S1ydmFF1CIAhg6tHUqFFE340YBg+uftBTgY ilN55HxyelA7ZZAiPyykc0Zq5XQkPD2lRi2ozjqtUaBk3rJb1vAAUqkwTZGkJ4TWZLzU0dH lzwcvFsCy6S9gv5qFnQ7w== X-UI-Out-Filterresults: notjunk:1; V03:K0:Dy0uXD9Ok10=:D3rSzTC6gEaoRX4EfHM7xC RJonplED3trLlh7qeMMCKBIEF9MdfWCe/divPw1ewAwaTbj4ZqazDXG5qJaLX29o27zXeWhvy 8wFFHRsBpWN6jcMJF/FNFsaw7lNWT7kYRnvh1AY2fRGU0UakrmHmzbRwE0xr09VxMyHhcE5Ak mxrl3nsXJ5n5YzX/AIL1BdZaF6Lp+uVoFz//YRv2cDSPIJ42TRVeKJHMq5bm4L3M+HTsPmRZA dQO1FoO8uzGhnTRGUAebZu3Zl1JFFa/mraN+arWdPcj1q//9h8jvCsIIGc1zL4/FZw6C7di1n xM3TayDXRMWDVj0gvq7Cu8n60JsyLbD7kHicZ83merUjaxygf2LFnBRyzoY8uMlDnZ+OKPbra 1vgJTRHHlk/J9C0rz6OABSqbudqQjRI269OtrpcU0xTTLMo3/T15Pqxs6BbtqawJiW+JonsoF i1ZfA3Q6Cndb7QHKu4z1WIRpGwkb+Y7Q3AI8CTmFkQSqOlZcPIV4NJNgyTP7CshpgvGl7GMVk sz0XDJNpsWSZMK/T8DaySGCdl4ajS/sRu0JoIIQnaB87sFHJ894Y3EdspIYMsgGwSah2YHqVV VnFX35OL5mr9LYGv92lm18olFAJlMo/82ZGFZUUk83PrJfEkEW8M/ggsiAxSNJVX3napGCFFA UQYR5/HPhMUysE7dscttak8qlMC7NoGOguqZ+a/29rAe3E+TfPI9s4DuCLHdStSUmls5xhTvf T9krDnnFtRoHkrEpBVC/odCcEiZMz0BzeXOEJdazvhKGx9BjDJCBdufCwUtQdz7XXBcVx2UVy Sf/O94ILGXaM6nIa7u6jHtkKUZlpdARBrs7mSPGcO62+3BbcIfdCUitaP+ntfUVpXWfXrI4mY 1gJr60cSEEM+jjwMMHgGlldhA/RTQYZtTrWDi9YeEUTB5a3B/xiKeWvgnwQNROfy2yuokYg5l zDJ6KFiWjzAhZuK/2bnkwnST7joDI2EpTfsWY8j3RlWxQFPlyFDxT7IDrpp4+dOb1gTFD2vsW hwtx0KtQGItAw2H7IgpwYfKbq35BtG1IGWM1ArOScDGM7MroPgTDrfX9K5f2l2rSAZUbOFDGI h5FGQ7yao+gy34MUm7CtdmfX/S3zQ9biyyr+T/cZgi7GvYeyoXGp+TtLw== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If the checksum calculation is offloaded to the network device (e.g due to NETIF_F_HW_CSUM inherited from the DSA master device), the calculated layer 4 checksum is incorrect. This is since the DSA tag which is placed after the layer 4 data is seen as a part of the data portion and thus errorneously included into the checksum calculation. To avoid this, always calculate the layer 4 checksum in software. Signed-off-by: Lino Sanfilippo --- net/dsa/tag_ksz.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c index 364f509d7cd7..d59f0e7019e2 100644 --- a/net/dsa/tag_ksz.c +++ b/net/dsa/tag_ksz.c @@ -56,6 +56,9 @@ static struct sk_buff *ksz8795_xmit(struct sk_buff *skb, struct net_device *dev) if (skb_linearize(skb)) return NULL; + if (skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_help(skb)) + return NULL; + /* Tag encoding */ tag = skb_put(skb, KSZ_INGRESS_TAG_LEN); addr = skb_mac_header(skb); @@ -120,6 +123,9 @@ static struct sk_buff *ksz9477_xmit(struct sk_buff *skb, if (skb_linearize(skb)) return NULL; + if (skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_help(skb)) + return NULL; + /* Tag encoding */ tag = skb_put(skb, KSZ9477_INGRESS_TAG_LEN); addr = skb_mac_header(skb); @@ -173,6 +179,9 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb, if (skb_linearize(skb)) return NULL; + if (skb->ip_summed == CHECKSUM_PARTIAL && skb_checksum_help(skb)) + return NULL; + /* Tag encoding */ tag = skb_put(skb, KSZ_INGRESS_TAG_LEN); addr = skb_mac_header(skb);