Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp9435460ioo; Sun, 5 Jun 2022 14:25:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytsGn1vG+QJ61As9w4UcWdrfcx15hIt7QlIpQRZajyRrtkbAOixEU9Oc5NlfaEBFN/ahof X-Received: by 2002:a05:6a00:26cf:b0:4f6:fc52:7b6a with SMTP id p15-20020a056a0026cf00b004f6fc527b6amr87522087pfw.39.1654464349541; Sun, 05 Jun 2022 14:25:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654464349; cv=none; d=google.com; s=arc-20160816; b=eZTjIutxtCSJ4Eae3fVddxI9d86NN9x7KhfKddeSHR5wt6JgqRSWbZY/S23TAmbX7N vm3gHAQRSJPxmEv/ui11FLSQIFLn8thp67eaJs5+ldtseSKEeVhdkoaTKGGCBibUAmde B18PDt3KI7rni/3lKtRxLB5TBYv8nK/1GT9wd5yYnGml8ekbKvI4Q8k/97PiivtedJIk zn3jrAi8cj7rbZuPKtkguC9J6ti6C9uXYbqfCde5cxmqek+hZ+PFGMrFHaNRgr+3TgDk VS+BjfIUtwN/vRC2JQXpXjCfB9ZD0HT/MV6gZ/FzsTvGa9fY2kTDh2GNSIypWVEK+TIZ kuQQ== 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=5fDvBQ9pqnOyeFIGsW6/UXw+F1U5aWM1AabDKQN3DYA=; b=QgQGzkIw3kx7BsnE6LDuhlnZENdjf9Rth7zqVjarDHBTVIAlbLACqhNO3aO4XkXkKa 6YzkBEfYYtOQq4zaTwtnpSgvmhOg50qnlgiuxOMaxPpXp5E6ky2fwsKB0xMYToRFuNad /bsCAoQA8JGNTmcOAKqPL7oGLI3bUO/nwMWbxuMr8bnAexSi7LQ1QtE4hrqlXpo9mwg7 VQNHAmFzN7QfIjrAs1xI7ZWlPmtWF5/cYnuV0j8arwn1uzAsUQW+IEyUra+kno/j4ZkA ZLVVPnSnnuWFC9WZaOYqMYg1O9FZST8Ja1bs3fQOMSAfA9al9ALRwMSsrZfYINCH5oY+ J4NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=sbHxZFWt; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 20-20020a630114000000b003fd4101223bsi9346650pgb.798.2022.06.05.14.25.34; Sun, 05 Jun 2022 14:25:49 -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=@google.com header.s=20210112 header.b=sbHxZFWt; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348888AbiFCTMG (ORCPT + 99 others); Fri, 3 Jun 2022 15:12:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348878AbiFCTL7 (ORCPT ); Fri, 3 Jun 2022 15:11:59 -0400 Received: from mail-yw1-x1129.google.com (mail-yw1-x1129.google.com [IPv6:2607:f8b0:4864:20::1129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC000286FE for ; Fri, 3 Jun 2022 12:11:55 -0700 (PDT) Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-2ff90e0937aso91968727b3.4 for ; Fri, 03 Jun 2022 12:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5fDvBQ9pqnOyeFIGsW6/UXw+F1U5aWM1AabDKQN3DYA=; b=sbHxZFWtLPJzqSmFanseJeEPL/ALu0sQSxEJQocSQIsAYQUBcFJXhscWQcNSmfW230 9rGYlKRGdc8+NCOtXd2QYQ2XQvkPWGrUdp03vXdekmYY9e2qdJp1uNuzLW9Jd7qinut+ Ucgv06zsk3X2VyQCWX4Jb6t/PfpbW+yc+9vdGhOzMheX7HMUapqW3A1s2XfR5HIv0Agq elgZuBluPxPTAsSlHtoZErhKO59lkdTlBMQiKjoovrnNUk+VrG2hHbUT/6BCtCQF7T0s l4pxZlAX/b52GuTokRfKfbVxdKCQqSp0ZEXlF2RRTj0w4dQuw3jptgt+I1RJdICqXtZI HuAQ== 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=5fDvBQ9pqnOyeFIGsW6/UXw+F1U5aWM1AabDKQN3DYA=; b=w1duk/HjdTHkIjHBL9Ug74FU+I+qNtdeyp/FR4JaDsmPuvzW+ETuKlAJM2pcaZtQlC z0y7vOQEmA/iw5wQtLo+pyAXeW1YF+/9iOSJfuKhsCBEOFcIDv1UWnH0xHSkVeXvUjkW KtgBJgrJ1uJM7OBKe5EhF2sy38+YFlCXn8zA9pY327T0bcFR2r3nHrukFWsH8GDgzWlO 5tIjmKDl4j0SvXHlAz2fu1x3rkbWbRCK6ruaPZFT4nem1JwO0wBXOiUsXxVRY7Gp0c9r aac9W0DNs+/LM6wwm8o7GPywdMU+JwzuW72YcuYxnNuPp6PzG6xvmitiKW3Mj3bhZ1M0 vlvw== X-Gm-Message-State: AOAM532hIxM5UD8fVs2RNw5YdVNR9HDjTNIIU8bydVFhKLTeavS46yoM M3GcFsWIfEeidUwSX+QYLOA4uSMOQPV1tn4UbOGXGQ== X-Received: by 2002:a81:b401:0:b0:300:2e86:e7e5 with SMTP id h1-20020a81b401000000b003002e86e7e5mr12645707ywi.467.1654283514691; Fri, 03 Jun 2022 12:11:54 -0700 (PDT) MIME-Version: 1.0 References: <2997c5b0-3611-5e00-466c-b2966f09f067@nbd.name> <1654245968-8067-1-git-send-email-chen45464546@163.com> <20220603115956.6ad82a53@kernel.org> In-Reply-To: <20220603115956.6ad82a53@kernel.org> From: Eric Dumazet Date: Fri, 3 Jun 2022 12:11:43 -0700 Message-ID: Subject: Re: [PATCH v2] net: ethernet: mtk_eth_soc: fix misuse of mem alloc interface netdev[napi]_alloc_frag To: Jakub Kicinski Cc: Chen Lin , Felix Fietkau , john@phrozen.org, sean.wang@mediatek.com, Mark-MC.Lee@mediatek.com, David Miller , Paolo Abeni , Matthias Brugger , netdev , Linux ARM , linux-mediatek@lists.infradead.org, LKML , Alexander Duyck Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 11:59 AM Jakub Kicinski wrote: > > On Fri, 3 Jun 2022 10:25:16 -0700 Eric Dumazet wrote: > > > 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); > > > > Note aside, calling netdev_alloc_frag() in a loop like that is adding > > GFP_ATOMIC pressure. > > > > mtk_rx_alloc() being in process context, using GFP_KERNEL allocations > > would be less aggressive and > > have more chances to succeed. > > > > We probably should offer a generic helper. This could be used from > > driver/net/tun.c and others. > > Do cases where netdev_alloc_frag() is not run from a process context > from to your mind? My feeling is that the prevailing pattern is what > this driver does, which is netdev_alloc_frag() at startup / open and > napi_alloc_frag() from the datapath. So maybe we can even spare the > detail in the API and have napi_alloc_frag() assume GFP_KERNEL by > default? Yes, we only have to review callers and change the documentation and implementation. The confusion/overhead/generalization came with : commit 7ba7aeabbaba484347cc98fbe9045769ca0d118d Author: Sebastian Andrzej Siewior Date: Fri Jun 7 21:20:34 2019 +0200 net: Don't disable interrupts in napi_alloc_frag() netdev_alloc_frag() can be used from any context and is used by NAPI and non-NAPI drivers. Non-NAPI drivers use it in interrupt context and NAPI drivers use it during initial allocation (->ndo_open() or ->ndo_change_mtu()). Some NAPI drivers share the same function for the initial allocation and the allocation in their NAPI callback. The interrupts are disabled in order to ensure locked access from every context to `netdev_alloc_cache'. Let netdev_alloc_frag() check if interrupts are disabled. If they are, use `netdev_alloc_cache' otherwise disable BH and invoke __napi_alloc_frag() for the allocation. The IRQ check is cheaper compared to disabling & enabling interrupts and memory allocation with disabled interrupts does not work on -RT. Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: David S. Miller