Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp856811rwb; Wed, 9 Nov 2022 09:25:15 -0800 (PST) X-Google-Smtp-Source: AMsMyM5wlwDAq+OpD0S08d6EDe6wzsi5aWEnyGn9+pDfRz5RKDOoTAERZqiQbI7r6/zDiMezub3S X-Received: by 2002:a17:90a:7d0a:b0:213:ee54:a707 with SMTP id g10-20020a17090a7d0a00b00213ee54a707mr52824519pjl.206.1668014715663; Wed, 09 Nov 2022 09:25:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668014715; cv=none; d=google.com; s=arc-20160816; b=unfWHyxIXQax5IudS+HmDr/TSd7RGs+fHgdxVKOjnbB/zXAf+gh+x+1dNNZOBjQxEe /F58Gs2KHNLaoAbpw8oS5p565gucaCUeJEEmK2Hfy02efOoGdKDWM65UE5VFTaeLqaXI 2fSNxhNyeyy5gUlglhD+MQ3WYwVJyOFJyejUHg9IfTnBM3i3Q3OXaCRPJdeLYG2jChCh Rw0c0Y+ROReqZQ1ZK8NN7AD2J+7vDie56Mzyrj5+MjF10UGPhD7Upytg/a4ZvcpPjU+J QYd3QYweAJjrl5iCR7Ky10lDcAaBgvKbg1lDOLFqYL93dbQ2QZnnXU8EM9gyU9zxmHuX dekg== 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=K5PkePP8GWSVO/aA2H0vGreyzQRw46Jl9mG+ltEDiYg=; b=AEFPp0pVl5nY2EZ+uqc7bzREl2s+n7yCKiUXx7ZTpMUB/WkKoAalMt6UfZ+e2pjlfx o2sl176PPxEn+57Xb1kp+7eEUAiqv+FfRHDAw3Ub9S0sFFQE4/lCSQ3oQ7HTdznQKNXv U/NNZHE8pfDmysVx6/2nRVnuPeKeh5dPv0RjvGn/s761jMAkFW5Y0UlcRC2jragM2ldR 2lWslLIULHY49+YQWMD8Ete8qTv3xeA6a5HeRR05s6PjFiEBgwuXjUlnQQBErXExPgkK TMYiDmUoSUYi0O5MOqXm2CjH50cC8Eh47Iv9/1I30n7cl4dMZw68I4/3v8GYT8K+F9Tv Zqvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=HTd09RZI; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y27-20020aa793db000000b0056e3a9809f5si15905537pff.56.2022.11.09.09.25.03; Wed, 09 Nov 2022 09:25: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=HTd09RZI; 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 S231142AbiKIQy2 (ORCPT + 92 others); Wed, 9 Nov 2022 11:54:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230212AbiKIQx7 (ORCPT ); Wed, 9 Nov 2022 11:53:59 -0500 Received: from nbd.name (nbd.name [46.4.11.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06F4D27DEC; Wed, 9 Nov 2022 08:53:01 -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=K5PkePP8GWSVO/aA2H0vGreyzQRw46Jl9mG+ltEDiYg=; b=HTd09RZIWm9L73OSxmR7psrYuu VoT8Dce6T8Twgp9f7m/vnYYvgsRF2R9z4z0tBVa//GfjFlQipgaOpimAqk0Cej6PQRWPjvG7KbAAg JXrUX+9PZSi6aUV+nTP0u5aDkLO1uLtZB0fx/6Fwt+hwy5U4WBVXKCXi6Dqpp8FaBwpA=; Received: from p200300daa72ee100054f3c61b16ef6e7.dip0.t-ipconnect.de ([2003:da:a72e:e100:54f:3c61:b16e:f6e7] helo=localhost.localdomain) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.94.2) (envelope-from ) id 1oso2A-000l4N-VU; Wed, 09 Nov 2022 17:34:39 +0100 From: Felix Fietkau To: netdev@vger.kernel.org, John Crispin , Sean Wang , Mark Lee , "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-next v2 10/12] net: ethernet: mtk_eth_soc: work around issue with sending small fragments Date: Wed, 9 Nov 2022 17:34:24 +0100 Message-Id: <20221109163426.76164-11-nbd@nbd.name> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221109163426.76164-1-nbd@nbd.name> References: <20221109163426.76164-1-nbd@nbd.name> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 f7b1d39bf936..a9a270317ff4 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -1442,12 +1442,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; @@ -1469,6 +1485,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)) { @@ -1484,8 +1511,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); -- 2.38.1