From patchwork Wed Nov 23 09:57:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Fietkau X-Patchwork-Id: 24842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2699065wrr; Wed, 23 Nov 2022 02:10:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf76q6/tOBIrbTU8JFDRXzwYajCOmkG9u/diclw/3AZVX6cEbJ6SzVK8jYspms2LZFep8xu/ X-Received: by 2002:a17:906:a991:b0:7ba:85a7:2ec3 with SMTP id jr17-20020a170906a99100b007ba85a72ec3mr170478ejb.36.1669198200894; Wed, 23 Nov 2022 02:10:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669198200; cv=none; d=google.com; s=arc-20160816; b=AaPpJgg80wJbhqn0x5Rw/b7a1hvJq09ERy2o+zM2fwxGS5aQMCxygjMIx+t815ds8a VD7Q3uxHb1Hyi/WtUKJdDful875BAp/nnXORST8WEuhxUcedz/gB0Z859K/3CaMdHXsC 71qdbWyafCQ30nNXolsIGEt79ijlh1DLnBZOKqqyUD/C6TbAYONDfqOfC09YaomOqGll 4jy41rOgIwGgh8CbFwQ+UP/LMkWRC9mnnu7/JhehEa4KLkd9WcueDtHFt0dhgzIM1PP2 pJekYZPusQrdYezuZe3Cg40bp0CF60IQfqeOgDBfJ7xexe9raZ/3m7JYqqD8WQhdcOTj goog== 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=TqAxL1ZNrPmWijqt9CG1x9FAOLdXO4JArQexSu8S6G0=; b=G2e/sP47uMbimisVkuCFF0k5+TCfUFSV1V2M+6dtGMXjrdPWLHToKUYHzOXeKVuxFo +pghFi9l59nzx7RuhEyv1i+AgP5BTWftpWKENmTDbGPfmTeXGua/wxA+whgT+wbpdbbj 7uzbfmab+3bA+Hf+Y5b5odLn70jv6u3aZFe6l3OGPy8ejbEd444esKvsYwblW6g/RxGp /no0wCtKfUdvcnzsXjysC2z9mRAkT+6SCxp7wt/Y2xBkFIVZtCiGKwm2TYxHa+HvWUmz fwv1bmqaA1ThAeabC05U1DFnKvJUH7GuF0tSXFxrOas97RK8Iic3L+gY6MIKv2DYNx3g cKiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=k2R54x1q; 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 i38-20020a0564020f2600b004571a669230si13127747eda.469.2022.11.23.02.09.35; Wed, 23 Nov 2022 02:10: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=k2R54x1q; 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 S236890AbiKWKJR (ORCPT + 99 others); Wed, 23 Nov 2022 05:09:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236848AbiKWKIn (ORCPT ); Wed, 23 Nov 2022 05:08:43 -0500 Received: from nbd.name (nbd.name [46.4.11.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D34258016; Wed, 23 Nov 2022 01:58:16 -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=TqAxL1ZNrPmWijqt9CG1x9FAOLdXO4JArQexSu8S6G0=; b=k2R54x1quzswJYr6SR1Uzq2CdC hRMZ/Ky1sWe/E2svBQUKe2pZivsAp3DbmHrcbxCmoSqS1KawTUmo2WYXGEdtHxc6uHZ6yVo2g8IEC VjwuLbM/QvlUZcJ/tWyp1GO8ZuJrN1YXaldjsQC65dQnqZ9jIdzhwRhmE/yGqbozah3k=; Received: from p200300daa7225c0894d890dd9e4669b3.dip0.t-ipconnect.de ([2003:da:a722:5c08:94d8:90dd:9e46:69b3] helo=Maecks.lan) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.94.2) (envelope-from ) id 1oxmVw-003vzk-T3; Wed, 23 Nov 2022 10:57:56 +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 3/5] net: ethernet: mtk_eth_soc: work around issue with sending small fragments Date: Wed, 23 Nov 2022 10:57:52 +0100 Message-Id: <20221123095754.36821-3-nbd@nbd.name> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221123095754.36821-1-nbd@nbd.name> References: <20221123095754.36821-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?1750281172769497532?= X-GMAIL-MSGID: =?utf-8?q?1750281172769497532?= When frames are sent with very small fragments, the DMA engine appears to lock up and transmit attempts time out. Fix this by detecting the presence of small fragments and use skb_gso_segment + skb_linearize to deal with them Signed-off-by: Felix Fietkau --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 36 +++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index 4c9972a94451..e63d2c034ca3 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,17 @@ static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_BUSY; } + if (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 +1510,13 @@ 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; + 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);