Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp99467iof; Sun, 5 Jun 2022 22:20:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8KvD26F4k93AMwKiA4y4r9ZZRVuD1ruwh1QrN3Duf1+gUihzjl5YKfRDSIcVRSdO1A5HI X-Received: by 2002:a17:90a:b703:b0:1dd:1e2f:97d7 with SMTP id l3-20020a17090ab70300b001dd1e2f97d7mr59345509pjr.62.1654492840231; Sun, 05 Jun 2022 22:20:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654492840; cv=none; d=google.com; s=arc-20160816; b=A1WwwnBbKhSeMFliUYA0PBeDalVChdDANpIXnB04DHGqVmGFEasbQ+KHH/5nXpJSpp wVYS6dm1fbGnSRZiU+sD+cqEcTn5D0PZv8TjjO2oJxqCsjzq01HTm45zC5gRYet9xgIi GzUqS2zUP9ldxQlktmRW3mnYiYi0NHeWpXX47uQlXCjrnV/cqY8iVtzqMFXK8/d8Mmcs zcBDTUSwakEQa+Hmjc4ViJtHmj3k6yEV2H3oAWdwvtygu4gptlwnbqqM5wLDBkua3JLw bqCM7++t0b82Mm8uML7XnWWC0EkAyb6jeqbUdHndnuSg0f5MnlHO3sRifKQvZDvN74Zl g64Q== 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=W3JiO5UY4+ex2grmCg7a8OXWeSx+fkxzA9451eGZd0s=; b=D8MUqI0QAoJY8JfgkFjiugYq5/m/hDIYBjYyovuhd5bkZqZ4g5N8uCQmg/LzwCuSlB 6aWD6E2/YjeYyHqvNJCugPCSBRVCH5+CW857tvdz1mQx8LJdKeq+bYK0krJBRxxdcs8S lOlJ3lfhWZ/WdYKBCMvFQxfzdi93HZDEw70VwLMZbaBdIBILOVQGryVzvJcZyLj+dUcf lSr3vbLeb5fq+8K6fTuVEbv60GlQKt4L2drhPUAFQCY6Ixli23yXUksRgwjowV8fT/uI p0xeqhjKBNWUnsuDzMHS9FqoxCdWrw8zL29A7rlgVblvjCIxSGioNggF48rM0Trt+0Sf kBRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=YuhlqzOr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o17-20020a170902e29100b0016375294933si17155774plc.4.2022.06.05.22.20.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:20:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=YuhlqzOr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5B4102109E5; Sun, 5 Jun 2022 21:31:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242884AbiFCIrt (ORCPT + 99 others); Fri, 3 Jun 2022 04:47:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236477AbiFCIrr (ORCPT ); Fri, 3 Jun 2022 04:47:47 -0400 Received: from m12-15.163.com (m12-15.163.com [220.181.12.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 41A0422508; Fri, 3 Jun 2022 01:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=W3JiO5UY4+ex2grmCg 7a8OXWeSx+fkxzA9451eGZd0s=; b=YuhlqzOr9G8xK8pkLg/tE3S9E681hv6NV2 VXIjYyQi3jN07ADjbnem/+QrB+WVwOUJuMeBzioFUkPJDbGuZ1p1wa6H1zZ7ZEXY 7+aCwf/70VdFCinfg/t6YUxRFKy3DRtmTzuMA/YCn5663Qw6cGEVPjAnXPNgDefy 8RLlGw5Tk= Received: from localhost.localdomain (unknown [218.88.124.148]) by smtp11 (Coremail) with SMTP id D8CowAB3U9ltypliCzpDFw--.50149S2; Fri, 03 Jun 2022 16:46:41 +0800 (CST) From: Chen Lin To: nbd@nbd.name, kuba@kernel.org Cc: 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 v2] net: ethernet: mtk_eth_soc: fix misuse of mem alloc interface netdev[napi]_alloc_frag Date: Fri, 3 Jun 2022 16:46:08 +0800 Message-Id: <1654245968-8067-1-git-send-email-chen45464546@163.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <2997c5b0-3611-5e00-466c-b2966f09f067@nbd.name> References: <2997c5b0-3611-5e00-466c-b2966f09f067@nbd.name> X-CM-TRANSID: D8CowAB3U9ltypliCzpDFw--.50149S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZFyfKF13AFy7trWxWry5twb_yoW8CFyUpF WUta4fAFW8Ar4DGws5Aa1UZF45Kw18trWDKr13Z34fZwnxtFWFkryktFWUCFySkrWDCF1f trs0vr9I9F98Gw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zR4xRDUUUUU= X-Originating-IP: [218.88.124.148] X-CM-SenderInfo: hfkh0kqvuwkkiuw6il2tof0z/xtbB2BEVnmBHKy0oDwAAsE X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 alloc_pages when ring->frag_size > PAGE_SIZE. Signed-off-by: Chen Lin --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 22 ++++++++++++++++++++-- 1 file changed, 20 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..772d903 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -1467,7 +1467,16 @@ 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 { + struct page *page; + unsigned int order = get_order(ring->frag_size); + + page = alloc_pages(GFP_ATOMIC | __GFP_COMP | + __GFP_NOWARN, order); + new_data = page ? page_address(page) : NULL; + } if (unlikely(!new_data)) { netdev->stats.rx_dropped++; goto release_desc; @@ -1914,7 +1923,16 @@ 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 { + struct page *page; + unsigned int order = get_order(ring->frag_size); + + page = alloc_pages(GFP_KERNEL | __GFP_COMP | + __GFP_NOWARN, order); + ring->data[i] = page ? page_address(page) : NULL; + } if (!ring->data[i]) return -ENOMEM; } -- 1.7.9.5