From patchwork Wed Jul 21 21:56:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12392549 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=-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,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 B977FC6377B for ; Wed, 21 Jul 2021 23:56:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 95F9060E0C for ; Wed, 21 Jul 2021 23:56:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbhGUXPc (ORCPT ); Wed, 21 Jul 2021 19:15:32 -0400 Received: from mout.gmx.net ([212.227.17.22]:48009 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbhGUXP1 (ORCPT ); Wed, 21 Jul 2021 19:15:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1626911757; bh=8zeB9SdYIGad3GftpPhXNeuDOVvPqv+DJPqmbH0vpUQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=QiGRi6Jh6eLwK2syCOZSMxr/vMGhbW0PcxujKeJiLdENYtFHJWxW1GlKwaX+k7zs8 daDUVIDIWJKUpqc7Zm9QLtlJ9ywdhhFAZD75vV19gOOpQIzF0PE2K7Y6lrCPSBNoIO /3r9IdZy3IrsfJgFpRWN5x8TP6ThBHTge97YHClQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([149.172.237.67]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MfpSb-1lQdo20hKL-00gIod; Wed, 21 Jul 2021 23:56:51 +0200 From: Lino Sanfilippo To: woojung.huh@microchip.com, olteanv@gmail.com Cc: UNGLinuxDriver@microchip.com, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Lino Sanfilippo Subject: [PATCH v2 1/2] net: dsa: ensure linearized SKBs in case of tail taggers Date: Wed, 21 Jul 2021 23:56:41 +0200 Message-Id: <20210721215642.19866-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210721215642.19866-1-LinoSanfilippo@gmx.de> References: <20210721215642.19866-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:mUIOwjeXZDD68etj9mBr6MrnFG4lg1jEYtOkP3DA14joz2fY37k 1zgYb4+R0rj65ECSE3yX1R7l8ydwDDZsFEE/om+kwVbBW1iwDH/iK7qaqCe8/127jpdqp/9 2i7XiJSX5N3neJyaM6wUWAVTgxASajUarjFiwRpGG2VEAdmAGq3W3lUu+QvPe0T9KMjC2xS rUlm6+0F/PZnud5mT8zjw== X-UI-Out-Filterresults: notjunk:1;V03:K0:vDn73y4plaM=:+5o4aSgaIj/zyUSbyjJhFb MEG6LF2GXoh00HXel2z0Mb8jtmhNbNE4FIqfFN1Fa3w7IZ0eGpSSY2g0lE//srUa196jzceGo T8JuJ8J7UPTccSGLwJ8uUM37FyVK206USKCKe4aLjlf7qVXNJay8BVh6hCqwXbUtUlMtk5Jr7 lLN26DchTNxw78Db0MSmLpdG9DCg9EE/Vh67BuNixdLZIjhvxXWWkBvKYqklRKSTdEzf2vC2P zJ4JraMAC79EjKXR9/joziu4c0DFXOBR/mM7SxnRCCGg/jFShZBQZ8SaXFgRhGYWm23cspVmE dIRixll1VjJUlJ1GMjE01ml4UIIK1bRAzly8xJOqV+rpZ7jio0qk0WAnlsWPtpYIaIK5ckByr IK9H7OO8s0u//7aODOZUzlfXC+28hdpMo6nxWVYP4r2ybT64QctPxB/BD0s3VQN3w4LR1v2w3 TYHrq+2Co1+MtQf92944i0nhZIh9bnenuCbpIZF4+IZIbukLj2vqCeSuuFsLBQfw+VxyU8Dia BJtsWz17UWDHF3DLwnCzBo+SmGuoeOF8EfZv8/19kKlpyzZQQH547shWq727HJdCGPt30+U1v YjOQ9V91hf/79OeF42upEsJu1749oBmofJDqY2BIMAAl7JA16aNpTWnZGF+kVBNXtQN7V7WyV 28YIEKlhgA0EncssHwMOoZDmer7v4sbdncYJNFCDvHl/U5pYrfbpNj4+paw4s6UMK/JzotQGf vjEY1IUevtpSRDyXj8lCz1Obs8x/lVqzLxnpBUwfHNi3kP1yUkVzSMhdzMLEkFydvPYeBU1Ng b6HS6GR/HZYj9D2BPLxAD1UJtvOS6v9kjhG9HZn5Lz5N29bMzg+bDIQRmY6TgAu0AAt07LE5g HvBcvMNX9Ljau5acsi2U+/ZOJDH7ZCQVz4EBh6QSyymMYwpd7Nj2h5cpICuYFUxRrdcw5jFnl up6p6xM3GCY9eRtPkNp3WYFXPiBON/kRDQCeRBWNddImU6tkzHcwKeliOG0fdxYkSVMCBSvfY SG7QYz4NAn/0COIYPdre2wkYrJ+fPH0z5/83GJ1XUt+J0I5rDSV3AMRAJeYvVvRomhov+8EUg qCDcqaifgfC9xqUnvODdSr90nmVjPrQ9dw8CMlPPkP190qBTDr1nShoEg== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The function skb_put() that is used by tail taggers to make room for the DSA tag must only be called for linearized SKBS. However in case that the slave device inherited features like NETIF_F_HW_SG or NETIF_F_FRAGLIST the SKB passed to the slaves transmit function may not be linearized. Avoid those SKBs by clearing the NETIF_F_HW_SG and NETIF_F_FRAGLIST flags for tail taggers. Furthermore since the tagging protocol can be changed at runtime move the code for setting up the slaves features into dsa_slave_setup_tagger(). Suggested-by: Vladimir Oltean Signed-off-by: Lino Sanfilippo Reviewed-by: Florian Fainelli --- net/dsa/slave.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 22ce11cd770e..ae2a648ed9be 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -1808,6 +1808,7 @@ void dsa_slave_setup_tagger(struct net_device *slave) struct dsa_slave_priv *p = netdev_priv(slave); const struct dsa_port *cpu_dp = dp->cpu_dp; struct net_device *master = cpu_dp->master; + const struct dsa_switch *ds = dp->ds; slave->needed_headroom = cpu_dp->tag_ops->needed_headroom; slave->needed_tailroom = cpu_dp->tag_ops->needed_tailroom; @@ -1819,6 +1820,14 @@ void dsa_slave_setup_tagger(struct net_device *slave) slave->needed_tailroom += master->needed_tailroom; p->xmit = cpu_dp->tag_ops->xmit; + + slave->features = master->vlan_features | NETIF_F_HW_TC; + if (ds->ops->port_vlan_add && ds->ops->port_vlan_del) + slave->features |= NETIF_F_HW_VLAN_CTAG_FILTER; + slave->hw_features |= NETIF_F_HW_TC; + slave->features |= NETIF_F_LLTX; + if (slave->needed_tailroom) + slave->features &= ~(NETIF_F_SG | NETIF_F_FRAGLIST); } static struct lock_class_key dsa_slave_netdev_xmit_lock_key; @@ -1881,11 +1890,6 @@ int dsa_slave_create(struct dsa_port *port) if (slave_dev == NULL) return -ENOMEM; - slave_dev->features = master->vlan_features | NETIF_F_HW_TC; - if (ds->ops->port_vlan_add && ds->ops->port_vlan_del) - slave_dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; - slave_dev->hw_features |= NETIF_F_HW_TC; - slave_dev->features |= NETIF_F_LLTX; slave_dev->ethtool_ops = &dsa_slave_ethtool_ops; if (!is_zero_ether_addr(port->mac)) ether_addr_copy(slave_dev->dev_addr, port->mac); From patchwork Wed Jul 21 21:56:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12392551 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=-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,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 D6DEFC6377B for ; Wed, 21 Jul 2021 23:56:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0A5161177 for ; Wed, 21 Jul 2021 23:56:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229928AbhGUXPq (ORCPT ); Wed, 21 Jul 2021 19:15:46 -0400 Received: from mout.gmx.net ([212.227.17.20]:38103 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229974AbhGUXPh (ORCPT ); Wed, 21 Jul 2021 19:15:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1626911767; bh=MTzoNI+4/t77AVtRX7F3dHidZZBtCwdh6utBGbbuUCM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=h1ixPFzUldtN6+MF1sX2ojNNcTYmbrtAtZu9qs3VOOvnt09Ry2+x0B5b9zWk97w2p /QVMTNgzHKUe3ytPAePdyF7kzV3zN3p0KmKZIUqvNXx1VtZkzqisbw7WMH3W2ODmvP w24kuQBEOESKReg/UcQrmVBH4XPffruJUfxHVI54= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([149.172.237.67]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M6ll8-1m1M8T2p1a-008KqK; Wed, 21 Jul 2021 23:56:51 +0200 From: Lino Sanfilippo To: woojung.huh@microchip.com, olteanv@gmail.com Cc: UNGLinuxDriver@microchip.com, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Lino Sanfilippo Subject: [PATCH v2 2/2] net: dsa: tag_ksz: dont let the hardware process the layer 4 checksum Date: Wed, 21 Jul 2021 23:56:42 +0200 Message-Id: <20210721215642.19866-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210721215642.19866-1-LinoSanfilippo@gmx.de> References: <20210721215642.19866-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:VrYRZ8zYIkA/EmJQWzaTUwoWNymemMyGpBXSXegQD3tN4gQv8hr SKV/Rfr0ylf4Afz6WxOvFNJ47HRx9YkCa8eomMPWnuPnE5rXCHl+wgYia4nV/RQI3kHRbpz JnYxqysjd8rwUEKc9obqdFK4cE/cxP91xjQpGMQz4lTk/87hb2SlbVbS5hRJHKvLZRBZ7AS 6Oz0bYceci9NqZ0ricBrg== X-UI-Out-Filterresults: notjunk:1;V03:K0:wttdpPwfjc8=:9y0l/U1MEUh58h4FCgqWsc uF2bw17XQlk+iIv91j6pCdIOf0hGu9AnwCR9t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uUdq5bkizW8PXsYoS1c5+CSMWVoRW7O6I9oSg3A== 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 considered as being part of the daa and thus errorneously included into the checksum calculation. To avoid this, always calculate the layer 4 checksum in software. Signed-off-by: Lino Sanfilippo Reviewed-by: Florian Fainelli --- 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..a201ccf2435d 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->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); @@ -114,6 +117,9 @@ static struct sk_buff *ksz9477_xmit(struct sk_buff *skb, u8 *addr; u16 val; + 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); @@ -164,6 +170,9 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb, u8 *addr; u8 *tag; + 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);