From patchwork Mon Nov 7 18:54:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Fietkau X-Patchwork-Id: 16657 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2247846wru; Mon, 7 Nov 2022 11:30:02 -0800 (PST) X-Google-Smtp-Source: AMsMyM7hh4/Y0EA1omo2zMEeCVgEVjyy/PhIcKg+BbRIXJCNGVyW68DX7KTZCZrOuVGGbKfXIize X-Received: by 2002:a17:907:2cd7:b0:7ad:ef1e:3b72 with SMTP id hg23-20020a1709072cd700b007adef1e3b72mr34100649ejc.449.1667849402584; Mon, 07 Nov 2022 11:30:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667849402; cv=none; d=google.com; s=arc-20160816; b=O5ttrvtpVBXJo8DLcxtac0MRpOWxmM9QsmnEjEN5YLLCgtTujqJ7ce5UBpahX9YzGZ qiBkxHUqIsl4R3zGdyr3GU02fgFFATKKd7oBlNFgbmG4mBVmR9uPoGIHoksj6fuKvi95 RmIJ7Gz2qxDZhf+GaOb5uAc5PNUJ10Q6f+MzBr3xnY2f9TkaCD1IpaNfV7TMEr6Be+OZ OeWmI4P0ELBOD3Iuhy/UhFVCqohKKqHPa++WdOKoUc93vECBlcTSJhwoPVen/Dt7GkDU szDxJMdY+gKD88Tva100YbMff+MvrEeNAKc4oWBNE8vfmnaLOMkRde6Bi7Nv0r0f8IfF EzBA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a056402280300b0046329e2724dsi12734594ede.86.2022.11.07.11.29.39; Mon, 07 Nov 2022 11:30:02 -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 + 99 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 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?1748866855085889106?= X-GMAIL-MSGID: =?utf-8?q?1748866855085889106?= 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);