From patchwork Tue Dec 27 14:08:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Fietkau X-Patchwork-Id: 36904 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1408488wrt; Tue, 27 Dec 2022 06:09:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXuuX4i/vhvItXDY8ct9R1QEOo2wYNOIEN7rY8nTQYuB7JJUperJfoaqwHLuPHN6YsZFoP7O X-Received: by 2002:a05:6a00:d6f:b0:581:4ce0:e5bf with SMTP id n47-20020a056a000d6f00b005814ce0e5bfmr6433577pfv.26.1672150140258; Tue, 27 Dec 2022 06:09:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672150140; cv=none; d=google.com; s=arc-20160816; b=pc0qI7badXSCLSQTvE2GVtjdnEDaM9aWnYueE1OgZGK1U+1sL9AeaPWMfkAV2Q7rOo 0iZYuL0KFb+GZrJzhX8IS9X4ntN0TQ/QYd4DUV2kc+popZwju4zdJObcfJ4PgP/A/NYx jzFBBHIXy6IgG5N3TT15bVeLYp2ZpZQNG4Vmuy4HBqrMk36Hi/C/Tg/ppEbmapaGysoD pGKdJ1DXGgCn79sT2H/qHAO1tAf8D4zB1PFBxdzEekgAU1tUFkb7fD4ADyj3O9N4E+KD p3C8K90ESo0lwEmcONYuOFSk/TsKPifUgxmRgX9yIGPeNm2ule3SYgQDjJGlPNvtwnsj jnZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=uVR2uPfM2wpTa8jMNvsapEg7hJdOqwYrYDayzI7tjh8=; b=tFfVD02A07AhJL3mwD8wMWuKf7mNrCgYqyjUleV9AgQ7k7wOyVp5RNCLKtL5jSbOMG BgV205Z2bLCHqswxbJFqjg67FLZvMcSLPCr7YCi7YiNso9pc5Dc3VY+rPBCiTlxxAw+i sb6Y1eqRcB7Yh9WagGIgDG8o45Bp+ctSN0GUeBH0g0mc0wp7sME1aMp1M2LAULxBacnS XQFENiU/w1Yh37+1Wq9TAMj3qId5LecOhATAz7iIrnW78lxD80/7dWKmpMfficTsvNM2 vRIQj9BVUguogOepBzHaSuVzFl6eTW4muQhCYbb0Ta4z+Iy8REc0ecHqva7AXDVQJNOP jm6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=P8VuvCqw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 73-20020a62144c000000b0058167c50a3asi2035911pfu.142.2022.12.27.06.08.48; Tue, 27 Dec 2022 06:09:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=P8VuvCqw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231289AbiL0OI2 (ORCPT + 99 others); Tue, 27 Dec 2022 09:08:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbiL0OIW (ORCPT ); Tue, 27 Dec 2022 09:08:22 -0500 Received: from nbd.name (nbd.name [46.4.11.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E883662CD; Tue, 27 Dec 2022 06:08:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=uVR2uPfM2wpTa8jMNvsapEg7hJdOqwYrYDayzI7tjh8=; b=P8VuvCqwvpww21pEHzsjSlOyCc nDjtBtNnBCVJwgYUjnHNbRVJXNxPy7Ct3vgJkDPi99SkqAK0/B07Rzyxki/gU5Dfa7DwOO+niz5pL yU0SLnceA4BeHQ3tRQoXdIdYgU7W8JF8hodHTAFiRC8TZVFOVRKOY+bnA3pxgC3RJAjo=; Received: from p200300daa720fc040c81ba64b0a9b1e5.dip0.t-ipconnect.de ([2003:da:a720:fc04:c81:ba64:b0a9:b1e5] helo=Maecks.lan) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.94.2) (envelope-from ) id 1pAAci-00C3RB-BH; Tue, 27 Dec 2022 15:08:08 +0100 From: Felix Fietkau To: netdev@vger.kernel.org, John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger Cc: Vladimir Oltean , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH net v2 1/5] net: ethernet: mtk_eth_soc: account for vlan in rx header length Date: Tue, 27 Dec 2022 15:08:03 +0100 Message-Id: <20221227140807.48413-1-nbd@nbd.name> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753376505119992711?= X-GMAIL-MSGID: =?utf-8?q?1753376505119992711?= The network stack assumes that devices can handle an extra VLAN tag without increasing the MTU Reviewed-by: Vladimir Oltean Signed-off-by: Felix Fietkau --- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h index ee06406e9ff6..628ed72911bd 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h @@ -34,7 +34,7 @@ #define MTK_QDMA_RING_SIZE 2048 #define MTK_DMA_SIZE 512 #define MTK_MAC_COUNT 2 -#define MTK_RX_ETH_HLEN (ETH_HLEN + ETH_FCS_LEN) +#define MTK_RX_ETH_HLEN (VLAN_ETH_HLEN + ETH_FCS_LEN) #define MTK_RX_HLEN (NET_SKB_PAD + MTK_RX_ETH_HLEN + NET_IP_ALIGN) #define MTK_DMA_DUMMY_DESC 0xffffffff #define MTK_DEFAULT_MSG_ENABLE (NETIF_MSG_DRV | \ From patchwork Tue Dec 27 14:08:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Fietkau X-Patchwork-Id: 36908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1409652wrt; Tue, 27 Dec 2022 06:11:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXvFXlH3XGOOX0VnhiZzsKoChc2+/1HPtgKPEZkgEyPj5Kc6fqA183WBFGUJ+FmSuzzD+Ozb X-Received: by 2002:a17:90b:485:b0:223:ffd0:b2a1 with SMTP id bh5-20020a17090b048500b00223ffd0b2a1mr25221537pjb.48.1672150275149; Tue, 27 Dec 2022 06:11:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672150275; cv=none; d=google.com; s=arc-20160816; b=gy6KBbL900R5Ekzt0HMGf5PhHEfkOPKROq2leC+UmMOIGx6yvtF9CGnR1K4P81Hlp/ Kjwd7kgdO9avPvjicxJY8sGGjYcgipkvXnv2DoehoazQxCLlRK+4PNGPwGpvNxwiiIyB OLTHyPapfk6GqBUbMLna8RwbBDLIpyb2ofxQI3jaIW4kl9dPAyilRjj/cFdOuYe8dVz8 5qWLFUURF0lJPwIyW1qAeH+ICmA+a1W1OEp+XK0rp7qiRbDYNYq9CSPHPS0NSS3bhiyq mSkR4XzWWawuHBWLNTMyoC8XEX+1+sH48hIAWyrRayWSUQY83V5SASjlJrt0Ee6Maa+3 sTag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Wu4+/ysy1Pzt6jWFfy9ST450nk1QbkSGcPcWerr8QPI=; b=Nzl23l/ms22PQx32VN+AZpCm7rKTJjHNM1gq9Cw+Z8oUbMT9k0qFhXOxgJv0prLnAU g7AZWXjQELggFImxZe3QiZo6SruK/zS/7OSGHnM7rIulzLhKvq1HtWXDHDd1eHmMbSDC I+n2BNHQiRiSDgh74jqNNSi8+L3nZKA/jkPJYTUBvvFCFtnLhYZvu4a2VNSyJ2T/aNBD Rn5qnYbgEz1q4ysFCj+MEOVoEqwXYsUCkR9ZHcSvZBE7IeCEXA0g+3lmwpa1LHNAkDd6 DjEqmba/0cLLJxweKlaG25IJBrKrSn2V0lONId1c0vTVOoE3pGtH6cJY4yg8zO+lXaVM 1pEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=SHQ43VMN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ob3-20020a17090b390300b00205f1a25a31si14743233pjb.161.2022.12.27.06.11.03; Tue, 27 Dec 2022 06:11:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=SHQ43VMN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231678AbiL0OIh (ORCPT + 99 others); Tue, 27 Dec 2022 09:08:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbiL0OIZ (ORCPT ); Tue, 27 Dec 2022 09:08:25 -0500 Received: from nbd.name (nbd.name [46.4.11.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69E076168; Tue, 27 Dec 2022 06:08:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Wu4+/ysy1Pzt6jWFfy9ST450nk1QbkSGcPcWerr8QPI=; b=SHQ43VMNc5LoDG+o6N4TLX9TOD zkYv9dxNbhCN/i/VFStXwETNNXhNR2tTAtUsF/GrXzvU70r7QBMdSUqlcLxdhKSaXDLWthXgBIIwG sd75zTFVu4Jj5SPzDXFXsVLfyEvXxmfIaqs5Y9yalQrZsCFoHw1muOanIEIQO24PT0uI=; Received: from p200300daa720fc040c81ba64b0a9b1e5.dip0.t-ipconnect.de ([2003:da:a720:fc04:c81:ba64:b0a9:b1e5] helo=Maecks.lan) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.94.2) (envelope-from ) id 1pAAcj-00C3RB-1x; Tue, 27 Dec 2022 15:08:09 +0100 From: Felix Fietkau To: netdev@vger.kernel.org, John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger Cc: linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH net v2 2/5] net: ethernet: mtk_eth_soc: work around issue with sending small fragments Date: Tue, 27 Dec 2022 15:08:04 +0100 Message-Id: <20221227140807.48413-2-nbd@nbd.name> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221227140807.48413-1-nbd@nbd.name> References: <20221227140807.48413-1-nbd@nbd.name> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753376646858288088?= X-GMAIL-MSGID: =?utf-8?q?1753376646858288088?= When lots of frames are sent with a number of very small fragments, an internal FIFO can overflow, causing the DMA engine to lock up lock up and transmit attempts time out. Fix this on MT7986 by increasing the reserved FIFO space. Fix this on older chips by detecting the presence of small fragments and use skb_gso_segment + skb_linearize to deal with them. Signed-off-by: Felix Fietkau --- v2: add proper fix for MT7986, limit workaround to NETSYS v1 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 38 +++++++++++++++++++-- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index e3de9a53b2d9..8245cddccb5a 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -1441,12 +1441,28 @@ static void mtk_wake_queue(struct mtk_eth *eth) } } +static bool mtk_skb_has_small_frag(struct sk_buff *skb) +{ + int min_size = 16; + int i; + + if (skb_headlen(skb) < min_size) + return true; + + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) + if (skb_frag_size(&skb_shinfo(skb)->frags[i]) < min_size) + return true; + + return false; +} + static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev) { struct mtk_mac *mac = netdev_priv(dev); struct mtk_eth *eth = mac->hw; struct mtk_tx_ring *ring = ð->tx_ring; struct net_device_stats *stats = &dev->stats; + struct sk_buff *segs, *next; bool gso = false; int tx_num; @@ -1468,6 +1484,18 @@ static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_BUSY; } + if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) && + skb_is_gso(skb) && mtk_skb_has_small_frag(skb)) { + segs = skb_gso_segment(skb, dev->features & ~NETIF_F_ALL_TSO); + if (IS_ERR(segs)) + goto drop; + + if (segs) { + consume_skb(skb); + skb = segs; + } + } + /* TSO: fill MSS info in tcp checksum field */ if (skb_is_gso(skb)) { if (skb_cow_head(skb, 0)) { @@ -1483,8 +1511,14 @@ static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev) } } - if (mtk_tx_map(skb, dev, tx_num, ring, gso) < 0) - goto drop; + if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) + skb_list_walk_safe(skb, skb, next) { + if ((mtk_skb_has_small_frag(skb) && skb_linearize(skb)) || + mtk_tx_map(skb, dev, tx_num, ring, gso) < 0) { + stats->tx_dropped++; + dev_kfree_skb_any(skb); + } + } if (unlikely(atomic_read(&ring->free_count) <= ring->thresh)) netif_tx_stop_all_queues(dev); diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h index 628ed72911bd..ce8044e8b3f7 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h @@ -246,7 +246,7 @@ #define MTK_CHK_DDONE_EN BIT(28) #define MTK_DMAD_WR_WDONE BIT(26) #define MTK_WCOMP_EN BIT(24) -#define MTK_RESV_BUF (0x40 << 16) +#define MTK_RESV_BUF (0x80 << 16) #define MTK_MUTLI_CNT (0x4 << 12) #define MTK_LEAKY_BUCKET_EN BIT(11) From patchwork Tue Dec 27 14:08:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Fietkau X-Patchwork-Id: 36903 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1408405wrt; Tue, 27 Dec 2022 06:08:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXu8jKWA24Ro9WX81FIWZYxCgvWO4/6pCRNpzM8RHtkdZTfBCYYI9L1Ppm5xuXX6PFjiwhoJ X-Received: by 2002:a05:6a20:3942:b0:a5:7700:2a4a with SMTP id r2-20020a056a20394200b000a577002a4amr38275685pzg.51.1672150129717; Tue, 27 Dec 2022 06:08:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672150129; cv=none; d=google.com; s=arc-20160816; b=wnNYE61V0c7mljDkm1aW8t8kSloVUZZ/DNDSSTyVkLLczbP/wAUf/qfeOa14Q3Twjf +Sbph8t71B/p1cXxGdej2s6SbE+UD73MUq0QMHmYv/yXOTRkKU/bs1YLpjKzT6Yodvb+ H49DGIezP9wV8gKDdxLmbW2QNlrZ/IiRVd5Sa32cLwl8jkxbgjtrWZgSwvvBnDYLwDNw UDDme0GlGJJzgjNa8wpTdFDePVYPx/icC8aiwqiZHtNo5+czvesCqDzSXXSwGYx5k8rC W4i0h2KsNYzxYtdZyUWVFBkehSQdlkzUFhGoDPt8my9aDsdt5VPglXnrKysXc/taYsgX 2OIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/eX4/CTCtjyiWC4V7OvOX6dzNZbFQNR2QZZFW5KPupw=; b=STeENcGNPDjXivi46+0GjQMuIckANaZG2lMvQGXfwGSls3VSruFo+RObqk59JBtzkT amm4kXGm7BHTeXic9/fEQN75g+w3wtKFfIsCc6u6J86Bls0ZgtEkKlsO3SbrnzR21ffi 89WjAvBwwZkdyCDnB08pWKhJnKYavGCAwxg+t1lDS6WtRdJup4PG5VkcGvAs1L3/DdPm gtx53h2F4cvXQwW9SyANsJSwYLzWFQ5kDnEOusNZKIX6NMl0nH1DFW4mKRUrCkUoU2qU S7Fb5p5Efz8waL1/kHEzzaovH45VWzQXA86C4RTEQXjxUJlXei/jWQu51/YijqWlDyIZ Xzzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=BtblUvXN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g6-20020a636b06000000b00478870de520si14751199pgc.293.2022.12.27.06.08.37; Tue, 27 Dec 2022 06:08:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=BtblUvXN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229949AbiL0OIY (ORCPT + 99 others); Tue, 27 Dec 2022 09:08:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbiL0OIW (ORCPT ); Tue, 27 Dec 2022 09:08:22 -0500 Received: from nbd.name (nbd.name [46.4.11.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4957C6168; Tue, 27 Dec 2022 06:08:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=/eX4/CTCtjyiWC4V7OvOX6dzNZbFQNR2QZZFW5KPupw=; b=BtblUvXNpMM+uRjnZub7/HH0ZN JyGVd7GXvimWLXPGJllc61VE4q54FXGlsGT0icVkju52lu0ok2Nz4GQDCOOtfdgHw+gtAfoWeULLB fKzA0KJU2n8q+4sBtKu1O/IOl6xEz1sZ807p6kIyRv22vF82L6j+hYiNWXA+KCd4zCXY=; Received: from p200300daa720fc040c81ba64b0a9b1e5.dip0.t-ipconnect.de ([2003:da:a720:fc04:c81:ba64:b0a9:b1e5] helo=Maecks.lan) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.94.2) (envelope-from ) id 1pAAcj-00C3RB-P2; Tue, 27 Dec 2022 15:08:09 +0100 From: Felix Fietkau To: netdev@vger.kernel.org, John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , Pablo Neira Ayuso Cc: linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH net v2 3/5] net: ethernet: mtk_eth_soc: fix flow_offload related refcount bug Date: Tue, 27 Dec 2022 15:08:05 +0100 Message-Id: <20221227140807.48413-3-nbd@nbd.name> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221227140807.48413-1-nbd@nbd.name> References: <20221227140807.48413-1-nbd@nbd.name> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753376494846626660?= X-GMAIL-MSGID: =?utf-8?q?1753376494846626660?= Since we call flow_block_cb_decref on FLOW_BLOCK_UNBIND, we need to call flow_block_cb_incref unconditionally, even for a newly allocated cb. Fixes a use-after-free bug Fixes: 502e84e2382d ("net: ethernet: mtk_eth_soc: add flow offloading support") Signed-off-by: Felix Fietkau --- .../net/ethernet/mediatek/mtk_ppe_offload.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c index 81afd5ee3fbf..412d215b9571 100644 --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c @@ -554,6 +554,7 @@ mtk_eth_setup_tc_block(struct net_device *dev, struct flow_block_offload *f) struct mtk_eth *eth = mac->hw; static LIST_HEAD(block_cb_list); struct flow_block_cb *block_cb; + bool register_block = false; flow_setup_cb_t *cb; if (!eth->soc->offload_version) @@ -568,16 +569,20 @@ mtk_eth_setup_tc_block(struct net_device *dev, struct flow_block_offload *f) switch (f->command) { case FLOW_BLOCK_BIND: block_cb = flow_block_cb_lookup(f->block, cb, dev); - if (block_cb) { - flow_block_cb_incref(block_cb); - return 0; + if (!block_cb) { + block_cb = flow_block_cb_alloc(cb, dev, dev, NULL); + if (IS_ERR(block_cb)) + return PTR_ERR(block_cb); + + register_block = true; } - block_cb = flow_block_cb_alloc(cb, dev, dev, NULL); - if (IS_ERR(block_cb)) - return PTR_ERR(block_cb); - flow_block_cb_add(block_cb, f); - list_add_tail(&block_cb->driver_list, &block_cb_list); + flow_block_cb_incref(block_cb); + + if (register_block) { + flow_block_cb_add(block_cb, f); + list_add_tail(&block_cb->driver_list, &block_cb_list); + } return 0; case FLOW_BLOCK_UNBIND: block_cb = flow_block_cb_lookup(f->block, cb, dev); From patchwork Tue Dec 27 14:08:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Fietkau X-Patchwork-Id: 36906 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1409293wrt; Tue, 27 Dec 2022 06:10:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXv3Rhgyivi0D+/DA/PByZsCdPaSrcQ4wJivmRD8RvEEteVdKv1CdW8pyZqMRRKTiYl8cTWd X-Received: by 2002:a17:902:d386:b0:192:68e8:c60c with SMTP id e6-20020a170902d38600b0019268e8c60cmr12988674pld.31.1672150232436; Tue, 27 Dec 2022 06:10:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672150232; cv=none; d=google.com; s=arc-20160816; b=zrsQ0zYZ3Af/ScG4n6Mo9bPYl1Rn0096Efp7l9DdwHFdrbejIQ69Gf8b+eO1MKgVfJ UW53DEiD2ACp4pv2Fn1wuAmIgqFbBLsNTaOQhzWh/SqQd0jlHV45E1+jkQLuxdN1oCaS +lrG2VqN47dWko1ARvf8A9Ez94QchRVuvZ1ST+HWSfGGTvfJgtU2NagyBWk1+2V3fUE6 pAi0J6RyMN2NnDhZ28pgRJUrBMJz6p9q3kJTg22CDIK8skV7wHeJjhTPd8lSv2c+EU0Y dLNjzetlKUH01IR0FjPrdGXlU+Q+iOzkkBji71WzVQZ3YluK6AVLQ/vzmKmMPKzIXiB2 A3CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=J/+msWmD/g1lZcf4oy0r+1hkk+U3OA6AiiaExjYdBco=; b=bgHSbGUZR9L9F78sCLRFnFBg1RSGb6rIXyZ6ADYumsnhb9b+hoMIeTod3FzzA7F8As fm0Hp/U3+utmpf+A2pxdjWwJZTyq5RCAb9bonOEwhJrf9PpGu+MkDkst0AkPhmosAJ7O FAnJcWkpCF42L2IIGAaC7ssnh6CpoNSOZG+g4Rj/oBkF4vKP+LwPzwGJl+EXaLCbfH2J N4RlvV01btem3KhMjeIHBWnaw6Hu8xEq/zbJ7aldjMrxB94vgA+xeVPiVJLb+w85RQlg eZRAq/KGzkQ34X7bpj0BRT/IDOA4vXLiaVk1H4DdYmy7OKOMo1C/UgBkhn+cIyaKY5TF uudQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=Blpp9FiT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a21-20020a63e855000000b00470759f312csi14201817pgk.864.2022.12.27.06.10.19; Tue, 27 Dec 2022 06:10:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=Blpp9FiT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231726AbiL0OIr (ORCPT + 99 others); Tue, 27 Dec 2022 09:08:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbiL0OIb (ORCPT ); Tue, 27 Dec 2022 09:08:31 -0500 Received: from nbd.name (nbd.name [46.4.11.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4471F64D2; Tue, 27 Dec 2022 06:08:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=J/+msWmD/g1lZcf4oy0r+1hkk+U3OA6AiiaExjYdBco=; b=Blpp9FiTGYTzanipAn93Zg+sDs iDF1SJ2G63MwJDdveDLBtM9yH76cLEazwltPpQuMYsoQyIcyhBmB/ODi1+6J2PNPRjJL4zLq0XV0P Fhfr8wx5ThXosUNj74s9m+Q+OFPsUnGoVkvUZzDkBlA3/7gKv01kbXxRi7QjcrEwuteI=; Received: from p200300daa720fc040c81ba64b0a9b1e5.dip0.t-ipconnect.de ([2003:da:a720:fc04:c81:ba64:b0a9:b1e5] helo=Maecks.lan) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.94.2) (envelope-from ) id 1pAAck-00C3RB-Hn; Tue, 27 Dec 2022 15:08:10 +0100 From: Felix Fietkau To: netdev@vger.kernel.org, John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , Russell King Cc: Frank Wunderlich , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH net v2 4/5] net: ethernet: mtk_eth_soc: drop generic vlan rx offload, only use DSA untagging Date: Tue, 27 Dec 2022 15:08:06 +0100 Message-Id: <20221227140807.48413-4-nbd@nbd.name> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221227140807.48413-1-nbd@nbd.name> References: <20221227140807.48413-1-nbd@nbd.name> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753376601955762923?= X-GMAIL-MSGID: =?utf-8?q?1753376601955762923?= Through testing I found out that hardware vlan rx offload support seems to have some hardware issues. At least when using multiple MACs and when receiving tagged packets on the secondary MAC, the hardware can sometimes start to emit wrong tags on the first MAC as well. In order to avoid such issues, drop the feature configuration and use the offload feature only for DSA hardware untagging on MT7621/MT7622 devices which only use one MAC. Tested-By: Frank Wunderlich Signed-off-by: Felix Fietkau --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 101 ++++++++------------ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 1 - 2 files changed, 39 insertions(+), 63 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index 8245cddccb5a..214cd80a19a0 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -2042,29 +2042,16 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED) mtk_ppe_check_skb(eth->ppe[0], skb, hash); - if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) { - if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) { - if (trxd.rxd3 & RX_DMA_VTAG_V2) - __vlan_hwaccel_put_tag(skb, - htons(RX_DMA_VPID(trxd.rxd4)), - RX_DMA_VID(trxd.rxd4)); - } else if (trxd.rxd2 & RX_DMA_VTAG) { - __vlan_hwaccel_put_tag(skb, htons(RX_DMA_VPID(trxd.rxd3)), - RX_DMA_VID(trxd.rxd3)); - } - } - /* When using VLAN untagging in combination with DSA, the * hardware treats the MTK special tag as a VLAN and untags it. */ - if (skb_vlan_tag_present(skb) && netdev_uses_dsa(netdev)) { - unsigned int port = ntohs(skb->vlan_proto) & GENMASK(2, 0); + if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) && + (trxd.rxd2 & RX_DMA_VTAG) && netdev_uses_dsa(netdev)) { + unsigned int port = RX_DMA_VPID(trxd.rxd3) & GENMASK(2, 0); if (port < ARRAY_SIZE(eth->dsa_meta) && eth->dsa_meta[port]) skb_dst_set_noref(skb, ð->dsa_meta[port]->dst); - - __vlan_hwaccel_clear_tag(skb); } skb_record_rx_queue(skb, 0); @@ -2889,29 +2876,11 @@ static netdev_features_t mtk_fix_features(struct net_device *dev, static int mtk_set_features(struct net_device *dev, netdev_features_t features) { - struct mtk_mac *mac = netdev_priv(dev); - struct mtk_eth *eth = mac->hw; netdev_features_t diff = dev->features ^ features; - int i; if ((diff & NETIF_F_LRO) && !(features & NETIF_F_LRO)) mtk_hwlro_netdev_disable(dev); - /* Set RX VLAN offloading */ - if (!(diff & NETIF_F_HW_VLAN_CTAG_RX)) - return 0; - - mtk_w32(eth, !!(features & NETIF_F_HW_VLAN_CTAG_RX), - MTK_CDMP_EG_CTRL); - - /* sync features with other MAC */ - for (i = 0; i < MTK_MAC_COUNT; i++) { - if (!eth->netdev[i] || eth->netdev[i] == dev) - continue; - eth->netdev[i]->features &= ~NETIF_F_HW_VLAN_CTAG_RX; - eth->netdev[i]->features |= features & NETIF_F_HW_VLAN_CTAG_RX; - } - return 0; } @@ -3211,30 +3180,6 @@ static int mtk_open(struct net_device *dev) struct mtk_eth *eth = mac->hw; int i, err; - if (mtk_uses_dsa(dev) && !eth->prog) { - for (i = 0; i < ARRAY_SIZE(eth->dsa_meta); i++) { - struct metadata_dst *md_dst = eth->dsa_meta[i]; - - if (md_dst) - continue; - - md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX, - GFP_KERNEL); - if (!md_dst) - return -ENOMEM; - - md_dst->u.port_info.port_id = i; - eth->dsa_meta[i] = md_dst; - } - } else { - /* Hardware special tag parsing needs to be disabled if at least - * one MAC does not use DSA. - */ - u32 val = mtk_r32(eth, MTK_CDMP_IG_CTRL); - val &= ~MTK_CDMP_STAG_EN; - mtk_w32(eth, val, MTK_CDMP_IG_CTRL); - } - err = phylink_of_phy_connect(mac->phylink, mac->of_node, 0); if (err) { netdev_err(dev, "%s: could not attach PHY: %d\n", __func__, @@ -3273,6 +3218,39 @@ static int mtk_open(struct net_device *dev) phylink_start(mac->phylink); netif_tx_start_all_queues(dev); + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) + return 0; + + if (mtk_uses_dsa(dev) && !eth->prog) { + for (i = 0; i < ARRAY_SIZE(eth->dsa_meta); i++) { + struct metadata_dst *md_dst = eth->dsa_meta[i]; + + if (md_dst) + continue; + + md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX, + GFP_KERNEL); + if (!md_dst) + return -ENOMEM; + + md_dst->u.port_info.port_id = i; + eth->dsa_meta[i] = md_dst; + } + } else { + /* Hardware special tag parsing needs to be disabled if at least + * one MAC does not use DSA. + */ + u32 val = mtk_r32(eth, MTK_CDMP_IG_CTRL); + val &= ~MTK_CDMP_STAG_EN; + mtk_w32(eth, val, MTK_CDMP_IG_CTRL); + + val = mtk_r32(eth, MTK_CDMQ_IG_CTRL); + val &= ~MTK_CDMQ_STAG_EN; + mtk_w32(eth, val, MTK_CDMQ_IG_CTRL); + + mtk_w32(eth, 0, MTK_CDMP_EG_CTRL); + } + return 0; } @@ -3599,10 +3577,9 @@ static int mtk_hw_init(struct mtk_eth *eth) if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) { val = mtk_r32(eth, MTK_CDMP_IG_CTRL); mtk_w32(eth, val | MTK_CDMP_STAG_EN, MTK_CDMP_IG_CTRL); - } - /* Enable RX VLan Offloading */ - mtk_w32(eth, 1, MTK_CDMP_EG_CTRL); + mtk_w32(eth, 1, MTK_CDMP_EG_CTRL); + } /* set interrupt delays based on current Net DIM sample */ mtk_dim_rx(ð->rx_dim.work); @@ -4203,7 +4180,7 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np) eth->netdev[id]->hw_features |= NETIF_F_LRO; eth->netdev[id]->vlan_features = eth->soc->hw_features & - ~(NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX); + ~NETIF_F_HW_VLAN_CTAG_TX; eth->netdev[id]->features |= eth->soc->hw_features; eth->netdev[id]->ethtool_ops = &mtk_ethtool_ops; diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h index ce8044e8b3f7..00d9a3badf9a 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h @@ -48,7 +48,6 @@ #define MTK_HW_FEATURES (NETIF_F_IP_CSUM | \ NETIF_F_RXCSUM | \ NETIF_F_HW_VLAN_CTAG_TX | \ - NETIF_F_HW_VLAN_CTAG_RX | \ NETIF_F_SG | NETIF_F_ALL_TSO | \ NETIF_F_IPV6_CSUM |\ NETIF_F_HW_TC) From patchwork Tue Dec 27 14:08:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Fietkau X-Patchwork-Id: 36905 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1408548wrt; Tue, 27 Dec 2022 06:09:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXvSMXIyi9AUEyZhdBpJOTgp0LJvzmdjL3/N5GFYk9eyc99nuP9+EbgTgODXyWZYD+KLmnv9 X-Received: by 2002:a05:6a00:1d14:b0:580:e1e2:c555 with SMTP id a20-20020a056a001d1400b00580e1e2c555mr13290327pfx.22.1672150147292; Tue, 27 Dec 2022 06:09:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672150147; cv=none; d=google.com; s=arc-20160816; b=KlN710CbWPf3Xdt/v5gHdbSjhbscdAPmXHgBSlr6Dfhrt7d4h4g+1kiIUZGOmcfh1Y WylwnMSf26h5GMdMMpEXpBypjOfbKZQmS2SebCGyzEXdBxs658G5bSdn4Les8a/iRrGd Fp3OxPiT89jzS0IYHs7zLtnrkttzGYyK9rVaazVhKXiFZBGBHoJV3S76e8K6xdwTPbAd FLSifbSQh16ug0z1jLoJgtDD0OLAOEyWSDX80Mx8G7Rm7hpBBnpFE+ZlfsEYwbW48HqG z7FNYnatQ8aImS7sIZ/BlE0i/w2u5PJ2OKU4qMoQZkFKIg049Y7raGSKmHO6MtOFHW/+ +Y6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NhkhKuz1T8rY3m+BTG+T8ROPfsy5F+fsbAj5AjslqQI=; b=lT3nVm4bNSGJ/QwFhwqy19Jq5ycv7e2MqyGDBaAZVULcp/utXS2IAg0pxIB26VdHfF ltg70tpmNSmOE5YZUKBDJAjKhccYiNIq0OC6EM7qud2jLMrOlKhAGlNacc0fmtVE/cre 446d32Iqiv9IMMhAZAVFXKLvU6IWSaVOvyZu3Mh+yVFRyoutttQiqzvUDH27+y6eEsV4 55FvCWaDbLgeT+Mmwqclak9QUY3z6mlbrWwnDXwJLzDPk07CTaoRyeH0akZldh+LJmZx LQ7cftmjA1sKo4adSViy5vmcR+3rrDH/DlUx/9Whkl/SqJkcxlmcug/zPZipfQL1EZTZ Mrdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=bHRRVkl6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f4-20020a056a00238400b0057f905fb1easi15609280pfc.335.2022.12.27.06.08.55; Tue, 27 Dec 2022 06:09:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=bHRRVkl6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231594AbiL0OIc (ORCPT + 99 others); Tue, 27 Dec 2022 09:08:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229579AbiL0OIW (ORCPT ); Tue, 27 Dec 2022 09:08:22 -0500 Received: from nbd.name (nbd.name [46.4.11.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 082CD634A; Tue, 27 Dec 2022 06:08:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=NhkhKuz1T8rY3m+BTG+T8ROPfsy5F+fsbAj5AjslqQI=; b=bHRRVkl6OIg31PWjSg1UuCP0XI uFWEUyviKbGEiVg7WZg8K+xAq7B7Vqs0z067i3HUfUzQ8woB7ZoMh7v2xxf/k7LB5iMpGGEkomW+4 1ELdEvlxY2VYilCRYjKkxAB7w4AXf2SyLOTxdhyAwIW6Zfta4NRremPVSZ6a84a87BAc=; Received: from p200300daa720fc040c81ba64b0a9b1e5.dip0.t-ipconnect.de ([2003:da:a720:fc04:c81:ba64:b0a9:b1e5] helo=Maecks.lan) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.94.2) (envelope-from ) id 1pAAcl-00C3RB-A3; Tue, 27 Dec 2022 15:08:11 +0100 From: Felix Fietkau To: netdev@vger.kernel.org, John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger Cc: linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH net v2 5/5] net: ethernet: mtk_eth_soc: ppe: fix L2 offloading with DSA untagging offload enabled Date: Tue, 27 Dec 2022 15:08:07 +0100 Message-Id: <20221227140807.48413-5-nbd@nbd.name> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221227140807.48413-1-nbd@nbd.name> References: <20221227140807.48413-1-nbd@nbd.name> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753376512756321804?= X-GMAIL-MSGID: =?utf-8?q?1753376512756321804?= Check for skb metadata in order to detect the case where the DSA header is not present. Fixes: 2d7605a72906 ("net: ethernet: mtk_eth_soc: enable hardware DSA untagging") Signed-off-by: Felix Fietkau --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 6 +++--- drivers/net/ethernet/mediatek/mtk_ppe.c | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index 214cd80a19a0..b54248bce501 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -2039,9 +2039,6 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, skb_checksum_none_assert(skb); skb->protocol = eth_type_trans(skb, netdev); - if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED) - mtk_ppe_check_skb(eth->ppe[0], skb, hash); - /* When using VLAN untagging in combination with DSA, the * hardware treats the MTK special tag as a VLAN and untags it. */ @@ -2054,6 +2051,9 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, skb_dst_set_noref(skb, ð->dsa_meta[port]->dst); } + if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED) + mtk_ppe_check_skb(eth->ppe[0], skb, hash); + skb_record_rx_queue(skb, 0); napi_gro_receive(napi, skb); diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c index 269208a841c7..e366a83cf516 100644 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "mtk_eth_soc.h" #include "mtk_ppe.h" @@ -700,7 +701,9 @@ void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash) skb->dev->dsa_ptr->tag_ops->proto != DSA_TAG_PROTO_MTK) goto out; - tag += 4; + if (!skb_metadata_dst(skb)) + tag += 4; + if (get_unaligned_be16(tag) != ETH_P_8021Q) break;