Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1729977iof; Tue, 7 Jun 2022 10:24:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxzFlmdRjiJX/k0ybYP/wDEKdPMzBpvsh5DmWUnYpb4yLJUP+ISnZMQJQLjlYqW0K1ur8k X-Received: by 2002:a17:903:2287:b0:164:83cf:bb15 with SMTP id b7-20020a170903228700b0016483cfbb15mr29894055plh.49.1654622692134; Tue, 07 Jun 2022 10:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654622692; cv=none; d=google.com; s=arc-20160816; b=EJt9th6gEBjmskWc58I5vpNYF/NyylWITRVH6Dfd0C0bAwcLAjwVkG+u+A5w7HgkU2 6t8bWcdhFH0iuKVWww/+2MNZcwcJMQzh7d9Fc49pr3pULMCTeOgYp7pSkybqJGH+ABaY dlBTLKG78NPBax7c+H0uJ0j0aLQKk0FILd/jSpCDzEEG89UlAaT+kVMPeQdwVvIrHDXI IvMzjrUdGEyX16n+JYq5XyJ3DE8jTwwAVoPz8K6F1ioGBX0xhnKm+pxkkRgjeKJropWf gzfjKYtvVVEwUAwWaUqDodZh7cWiVlGhfqiMobIDe5PJUFKegwltP72AZ14V1vgiJw/8 2mAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=W2pGeBJj/dLqJYD8kB9C4khRrBNd4zxXRj9ATg2uzBY=; b=W0FtRJl7Vy6rjJKoijiO6pJCWEyn7jQ9+XgFF++rMTg2L58Q9u1674HD/ZuV5ji0dh 0y7D9mUajgjUkEGxMYYI0mWN79lCi7Xcma7W+zmVWuKjR2NaOBQb89/paZlswaaNIZzO +8GHAJWDyGNsiqsbH+TLceAHfub7BBfFnWStx4BLraxJgoUkR8pECkBYZcPakoFk2w07 vZAckwDMMhAX3tldD5rrxZ9YWze8QgAIKD/sQqSK2EdgZzH/p1xuFexMylgGeTLOTFJc yTdxgSqoDDt+JWRlPBEFxbFsuqX/6qkysavWRX2rl+qtCPLrhk3rIKzsWKv/5g7IM3Ws +OOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=Goj6AceC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g185-20020a636bc2000000b003fd8db5b36fsi11451978pgc.217.2022.06.07.10.24.36; Tue, 07 Jun 2022 10:24:52 -0700 (PDT) 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=pass header.i=@163.com header.s=s110527 header.b=Goj6AceC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232516AbiFFXlV (ORCPT + 99 others); Mon, 6 Jun 2022 19:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235302AbiFFXlT (ORCPT ); Mon, 6 Jun 2022 19:41:19 -0400 Received: from m12-17.163.com (m12-17.163.com [220.181.12.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7EF47B5257; Mon, 6 Jun 2022 16:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=W2pGeBJj/dLqJYD8kB 9C4khRrBNd4zxXRj9ATg2uzBY=; b=Goj6AceCMxqUO8j9t4MO6BV6oHOeJ2PM1W 34uvRHBYiiilbIxy+8LBhoMZamvh1Q2OHsOcW+yC0qrM9rUauLYapZfT7n6NTbAA zVVR80LNDZ/Jwa5bh6jnFxqLe9Y51bINkg1JJht4SIvF0EVxZkelkRbxCPb8TDNR 4x0tg7hu8= Received: from localhost.localdomain (unknown [171.221.147.121]) by smtp13 (Coremail) with SMTP id EcCowABHYpM1kJ5iHCCHGg--.35368S2; Tue, 07 Jun 2022 07:39:43 +0800 (CST) From: Chen Lin To: kuba@kernel.org Cc: nbd@nbd.name, john@phrozen.org, sean.wang@mediatek.com, Mark-MC.Lee@mediatek.com, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, matthias.bgg@gmail.com, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, alexander.duyck@gmail.com, Chen Lin Subject: [PATCH v4] net: ethernet: mtk_eth_soc: fix misuse of mem alloc interface netdev[napi]_alloc_frag Date: Tue, 7 Jun 2022 07:39:11 +0800 Message-Id: <1654558751-3702-1-git-send-email-chen45464546@163.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <20220606143437.25397f08@kernel.org> References: <20220606143437.25397f08@kernel.org> X-CM-TRANSID: EcCowABHYpM1kJ5iHCCHGg--.35368S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZFyfKF13AF45WF4kJFyxZrb_yoW8ur18pr 4UtFy3AF4UJr47G395Aa1DZa1Yyw4IgrWUKFy3Z34fZ345tFWrtFyktFWUWrySkrWqkF1S yFs8Zr9I9FnIkw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pi2g43UUUUU= X-Originating-IP: [171.221.147.121] X-CM-SenderInfo: hfkh0kqvuwkkiuw6il2tof0z/xtbB2AcYnmBHK2EpqgAAs3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 rx_flag == MTK_RX_FLAGS_HWLRO, rx_data_len = MTK_MAX_LRO_RX_LENGTH(4096 * 3) > PAGE_SIZE. netdev_alloc_frag is for alloction of page fragment only. Reference to other drivers and Documentation/vm/page_frags.rst Branch to use __get_free_pages when ring->frag_size > PAGE_SIZE. Signed-off-by: Chen Lin --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index b3b3c07..3da162e 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -899,6 +899,17 @@ static bool mtk_rx_get_desc(struct mtk_eth *eth, struct mtk_rx_dma_v2 *rxd, return true; } +static inline void *mtk_max_lro_buf_alloc(gfp_t gfp_mask) +{ + void *data; + + data = (void *)__get_free_pages(gfp_mask | + __GFP_COMP | __GFP_NOWARN, + get_order(mtk_max_frag_size(MTK_MAX_LRO_RX_LENGTH))); + + return data; +} + /* the qdma core needs scratch memory to be setup */ static int mtk_init_fq_dma(struct mtk_eth *eth) { @@ -1467,7 +1478,10 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, goto release_desc; /* alloc new buffer */ - new_data = napi_alloc_frag(ring->frag_size); + if (ring->frag_size <= PAGE_SIZE) + new_data = napi_alloc_frag(ring->frag_size); + else + new_data = mtk_max_lro_buf_alloc(GFP_ATOMIC); if (unlikely(!new_data)) { netdev->stats.rx_dropped++; goto release_desc; @@ -1914,7 +1928,10 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag) return -ENOMEM; for (i = 0; i < rx_dma_size; i++) { - ring->data[i] = netdev_alloc_frag(ring->frag_size); + if (ring->frag_size <= PAGE_SIZE) + ring->data[i] = netdev_alloc_frag(ring->frag_size); + else + ring->data[i] = mtk_max_lro_buf_alloc(GFP_KERNEL); if (!ring->data[i]) return -ENOMEM; } -- 1.7.9.5