Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2382919rwb; Mon, 7 Nov 2022 12:37:26 -0800 (PST) X-Google-Smtp-Source: AMsMyM4Sm9LVVra8hAWlVf2v4uRpNeKhbYxKWNGw2Vvx1pcm7VASMOdbGl3AIHkA0s3QrRQIFtK4 X-Received: by 2002:a05:6a00:10cf:b0:563:34ce:412f with SMTP id d15-20020a056a0010cf00b0056334ce412fmr53111123pfu.67.1667853446665; Mon, 07 Nov 2022 12:37:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667853446; cv=none; d=google.com; s=arc-20160816; b=mqH8AFpRhDznddMI+xzJ/SGJ2HNyfpnMDIbnYNqSHGw6JEXFIJVJoWpBhjg5LXgm90 M+HKnHy9bjd4mIB3CC3GRJ+yQTwkgV59pVC6GqxZhntgtQPDsxVPNIFNY6OZb9aNkHC3 mDtDlIBazTzDWvzpDSMq9XMkLWrZjJD6OB/hWvwQOZgXzQY/aV8BUTOaTFMhWua/7Rla zH2wGLi/cZMv1ajfbCN2udgydDT9T5Xtn+S2AB5nPAzoPsyncZwrUN963PBxve4RBJ4O +lgIuk9u2EqDeLIfOL+UKFYrzVaFP2MO7Uzp0scNgxRPNvt+zsM7qFAAC8+R4Xmw/nKD 8T4Q== 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=xCr45UuzrLNIeKdnQROVOgewNl0be/E8YvRAW/QU3O4=; b=Iu+8WXUHRawPYmFhRIBSuaq3/m6rJPr7vTFJZQHH3hZH0+7AZsDSd+H9EAQtilvwgT x74yJL1Y04BIbqrwsl6J3gPsvySkAzDH3tn+IUAFcPgR20BrcXqBzU8s7BExgJ+7WbhT e9u4OQezTRdrZBlI0Yscy8MjY3RxfY/RxlC9CY+AbDvbeunmWMX/O3MuiWWX3uPWg3hY bLEi/Rk/JGd6Jsc11P3EXhCCVqqXpbgWPT0jQyaRxAdSKt830oiTDsVQ0WMPWHYr7fU9 BRfOFkKD7jYmB9xrNW7cbVH0bPpKSLATNk2HqfJjWMf/2y1hGDe2hrFGbSvNOwPq1Stc e+/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=A8NmC8uy; 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 lw11-20020a17090b180b00b00205ee3e845bsi13069679pjb.116.2022.11.07.12.37.14; Mon, 07 Nov 2022 12:37:26 -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=A8NmC8uy; 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 S231627AbiKGTZg (ORCPT + 92 others); Mon, 7 Nov 2022 14:25:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232167AbiKGTZc (ORCPT ); Mon, 7 Nov 2022 14:25:32 -0500 Received: from nbd.name (nbd.name [46.4.11.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F57C286EC; Mon, 7 Nov 2022 11:25: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=xCr45UuzrLNIeKdnQROVOgewNl0be/E8YvRAW/QU3O4=; b=A8NmC8uyAFNHwtnVUx1Qg7EzE/ Iia6sjNBFsbKq34UUC19vohNFhU7am+FpMSYWIA2OfmGK66c8ECVwH3nHo4ppZcr3N+ba2bZ/xYyq Kzj6VV21d+Q/KQj0xs2PNzZ3IJisJNXILxTddQSNTUcLc6OV49Ngjqdg0WSQSvWpBiJQ=; Received: from p200300daa72ee1007849d74f78949f6c.dip0.t-ipconnect.de ([2003:da:a72e:e100:7849:d74f:7894:9f6c] helo=Maecks.lan) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.94.2) (envelope-from ) id 1os7HH-000LCc-5a; Mon, 07 Nov 2022 19:55:23 +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: linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/14] net: ethernet: mtk_eth_soc: work around issue with sending small fragments Date: Mon, 7 Nov 2022 19:54:50 +0100 Message-Id: <20221107185452.90711-12-nbd@nbd.name> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221107185452.90711-1-nbd@nbd.name> References: <20221107185452.90711-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 3b8995a483aa..50756c8aa871 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); -- 2.38.1