Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp131954iof; Sun, 5 Jun 2022 23:18:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW7gSAfU8vpENI4UkXtApA6g0cZswQe2cshNVEApNisQZQxwIt3ijtrJl+4Vhsknl+WEfV X-Received: by 2002:a17:90b:4f45:b0:1e3:495a:2b51 with SMTP id pj5-20020a17090b4f4500b001e3495a2b51mr24790718pjb.3.1654496312295; Sun, 05 Jun 2022 23:18:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654496312; cv=none; d=google.com; s=arc-20160816; b=xpZn/3CinOlGudnAFtipSOSd2RdRYa8W3CdxiLr8U0ACcYh9FS0d/5s7uUHFsG/suF omEYxkPDs29HEza5OkBHANLrEMaPwFDLE5ZWmh6c3PAMV+wNvZCMx9ndaO629NYNcRj0 vtXqJZ1cOsWjgMNNDsHVDzKenTsGtWfI82bBxj18SC5DN81bqFSx3McwxrekSPgEmzgG zCdX36qbK5Bdgwke4YFkSbdGy0PcDx2g6hVuJL8D5UKvy262++dg7VbfyEGoJP8959ix t0c0xcdDf4AcTJYeh58LgLuHGNUqnXaBBTKkv8vXmvZ06wQIOdFCsxUb85JIEKKf6aXL 71RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=oq/7Nt8hH+8An2BVROqJRuKS0FRepvvGNwqF4LhpwJ4=; b=fQhYV8KL21EiSkIIvHXAhKiB0WD6G5BYRqimtpm34aJn9dYSImdG9vHd/5NN5YaIrw DLeZ//mK7nR9X8JDr+q11ZkbpTZAHvzwG52ytAn/os2vZQ8hw+hRakYTaLJzz370IYV2 MaBALGk+dbHGG0B+9SFdbIZklmBds5WSFyUbvfF666GtxohyhL0rETwwDoD8+JnZtx+R +a6X7r1/P4x+r1OOpi1o3IfY+XAXPqZ8zavICPtKjCINMpuCgHrByowybhNim7Hujpb+ o+7xT7FnDzme5ifwJkW5RYMNVvJL1zdwKBxmttKXybQWWSa5dvqsADOdzD/bS/fUJ1UB Hcyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DzV8Du2H; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id hk6-20020a17090b224600b001dfab05243bsi20747045pjb.181.2022.06.05.23.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 23:18:32 -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=@gmail.com header.s=20210112 header.b=DzV8Du2H; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 30043BF8A0; Sun, 5 Jun 2022 21:57:49 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245544AbiFCPdl (ORCPT + 99 others); Fri, 3 Jun 2022 11:33:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230520AbiFCPdk (ORCPT ); Fri, 3 Jun 2022 11:33:40 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BE2744A14; Fri, 3 Jun 2022 08:33:39 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id fd25so10652128edb.3; Fri, 03 Jun 2022 08:33:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oq/7Nt8hH+8An2BVROqJRuKS0FRepvvGNwqF4LhpwJ4=; b=DzV8Du2HCN9eSAgLq3MmS7PYFIDS1VRh6mUcBFhEV21yX/IAgSreSh/t0mxzUtlImT rfOo2ZsgUXTal15h7gqJ3yfC67EuvjyOCTFfTAcVFPBROXrLgimo9pbQA2jauTKqdiHv 8rYPBk3HZh2QD+PnAMm9CTzNQeC5kO98ipf8eDi4YcO3RoVLWo/3YXOTCHmj0RWgcqGV p2isfYtVh+mgHQ+vs/Y7M792D41OHL9f2VzELxLiQe6NQ8qI8ZrlyU+QZtDPjUQKZowp h7ivIuhuz8cQZi3TiKh9mmfcCwiZR1BLqwfiiwt7n4xMegJPJiL3JMgE2+XaZ9FfJl8o 1xMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oq/7Nt8hH+8An2BVROqJRuKS0FRepvvGNwqF4LhpwJ4=; b=p6bJLr3//zxGLT86rkDCdFcBgy+5YDqDsQEKUtr5hROZQ+vNEKMY5lN0l6ORJhcTj0 OgJEZlbmOpbMOZMYsCmxOCSIdsmdTaWgmAip3eLPIZA0O7AcdVh7Q/VfJPssGxHJDAk3 faxhQZMjlvkknxNNnJ2uDITCmeC037clNCftBprAB7jPjPzwF9+PasvlDeQd0aKOIFMS ryGk+o+xWHycJVCpIuDnxWu2cX2jI4hdtJFmGGRbc6H1jh07k330CQfSZS5cYGITSSsd DxVnxjxfLLos9nq1YjSUvdW/oh1gCFynl1RVZwzbw2kPoRrh7BJCTsf8lO6r/SCjlwlK NaMg== X-Gm-Message-State: AOAM530ENG2Y39qOn+BH+qOWNEzFooLVhCx7uumlFsFir5a12VU9vvKW 8L/RKCbPo1AphIR0aYz1ZcO1C4pqovu0F6ecKjk= X-Received: by 2002:a05:6402:1399:b0:410:9fa2:60d6 with SMTP id b25-20020a056402139900b004109fa260d6mr11253369edv.35.1654270416705; Fri, 03 Jun 2022 08:33:36 -0700 (PDT) MIME-Version: 1.0 References: <2997c5b0-3611-5e00-466c-b2966f09f067@nbd.name> <1654245968-8067-1-git-send-email-chen45464546@163.com> In-Reply-To: From: Alexander Duyck Date: Fri, 3 Jun 2022 08:33:25 -0700 Message-ID: Subject: Re: [PATCH v2] net: ethernet: mtk_eth_soc: fix misuse of mem alloc interface netdev[napi]_alloc_frag To: Chen Lin Cc: Felix Fietkau , Jakub Kicinski , John Crispin , Sean Wang , Mark-MC.Lee@mediatek.com, David Miller , Eric Dumazet , Paolo Abeni , matthias.bgg@gmail.com, Netdev , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, LKML Content-Type: text/plain; charset="UTF-8" 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 On Fri, Jun 3, 2022 at 8:25 AM Alexander Duyck wrote: > > On Fri, Jun 3, 2022 at 2:03 AM Chen Lin wrote: > > > > 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; > > } > > Actually I looked closer at this driver. Is it able to receive frames > larger than 2K? If not there isn't any point in this change. > > Based on commit 4fd59792097a ("net: ethernet: mediatek: support > setting MTU") it looks like it doesn't, so odds are this patch is not > necessary. I spoke too soon. I had overlooked the LRO part. With that being the case you can probably optimize this code to do away with the get_order piece entirely, at least during runtime. My main concern is that doing that in the fast-path will be expensive so you would be much better off doing something like get_order(mtk_max_frag_size(MTK_RX_FLAGS_HWLRO)) which would be converted into a constant at compile time since everything else would be less than 1 page in size. Also you could then replace alloc_pages with __get_free_pages which would take care of the page_address call for you.