Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2934629pxk; Mon, 21 Sep 2020 00:21:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3iVihZ/rVxurs3hykQ7hQGeJ64MK6y4iltplbx8AetIa2B0zYoMQWD3SVfZIaPzu/rn+Y X-Received: by 2002:a17:906:1484:: with SMTP id x4mr47185570ejc.81.1600672882050; Mon, 21 Sep 2020 00:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600672882; cv=none; d=google.com; s=arc-20160816; b=f822WRoD3Gkpjg61H4+rMDZ0qSZAyCGTH/3f/wFtxUVttKO8/yMFRV7H7bdxTngFTF MpE4VdjbWHTa5X8lWNYxs7+tEgvOFLv5isw62jDbvDOosL9apov7rFJ6/tPGOamRET71 iYbbABvbmMiMPLXdXx30u3kCuPumH/uGhKv8V2xXWn5XdXrql03BsKshXGNkLxEmtjuf mxDmiFe6cintKK5/uougR7/IU6HuVHN2GmQzX97A0R+9pjjQBQajn1UwLQYd5O6oQyYD KQYL7q3KNP3I6MxQVfmMDafZ9dDplExbCIADExlYazWBlbcpFz+Lf85y3Mz6knPPg0y/ KxzA== 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=J74hei80adNTzhYNjM9XWAuJbKr+AfEajEupZTz7dsQ=; b=Qii3IzY8USWAm8b6z5UMjyEqMRaQcJnF34027jGPP1Zgv5R1K09Uc0mRFD/SsyEQfT y3VenESWMJKtnAHodH8Rty3jZHyfmsnfcFfxUWVtTj5ajaWNyGOpEnBrn2K2zY/Mogde f2XCyBCppzrs/qksYNnNCTl2KWiYUz4V7PMdiVcfN9Psff1DPqkgNrEifIeDEV2q1lp4 TJT64RqWgd52wbsqmwddL6l4MeVrg3qqpZDNn2libtDd2TBKxExZX4JgOM1sYs4QPzb9 IkDM52ks/64t99kZSHMlGcmgze+qnsLatnGYEM42I41G7D+5+Pdv21rYPEDBRJO/2l0x +bsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="FM/cABQ7"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g25si7303229edu.330.2020.09.21.00.20.57; Mon, 21 Sep 2020 00:21:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="FM/cABQ7"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726405AbgIUHTd (ORCPT + 99 others); Mon, 21 Sep 2020 03:19:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726211AbgIUHTc (ORCPT ); Mon, 21 Sep 2020 03:19:32 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F74BC061755 for ; Mon, 21 Sep 2020 00:19:32 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id r25so14369644ioj.0 for ; Mon, 21 Sep 2020 00:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=J74hei80adNTzhYNjM9XWAuJbKr+AfEajEupZTz7dsQ=; b=FM/cABQ7w1uG4yzBJwkCQ17ro5QtkQMVwytS964BkBwlodtZr9Vg/RPLfMOyejCt3o hnkip9jXnfMty6j6tFPfUF0CDq/+ZUtaWIx/iSU7Nr63YiN0KX6DcAQs23fh53f5dljP BbmSiM6FgMO1x4osWYkMkz1nyENLJ9PwaiAjSh/tgENreIoPUQ+i77aUgVnYkI4wHrOl n8XArYiUba3QjM7gpyoApqt6VVfBP4cznn8+0WZArsQ52IARyTV5y335IKe5rDoRd+mW /fjvTrOTtFohfAqBr0dfrKpPZ9ma/S5a0DOkco/BrZlDhDQo6PshQf4Vsdcqjr2n45+o kpKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=J74hei80adNTzhYNjM9XWAuJbKr+AfEajEupZTz7dsQ=; b=XzxD4J/nZls1Qmzl3uKVxRCInYyriJDjow+r6w89B1CxAeZ0vajdCufPqelZw3e4o0 0s5gtUkGYpPud7NeWDT92gi3TPj/ThwE/QA7Bv0Eh/10miS6SpFg3JdsIHP5cY95ICfA Gtofzx6BoFpLjSX1yNlg4ytRjEbl6UjjCjXJYZUOKzJQMWYWpQ6Q6iyVI2EjlFO7zSek PTB+H6tiLa4ZJhxDXJhEgHy6GRnuVMlh+IHTvvg5J4ahQ6prfh48J63vIe/cCsAynoIE BfOBYM739ekH7s7N8XXO48QqfVWqxbKVqwgwoBF6eB3JNZ/0EAAbXYgxx/HJHPHaIG7U CeZw== X-Gm-Message-State: AOAM532sCKZfqfCp6S1aho3XemaQhObPndHN7J2Qp+qi7tfFWMQpungQ Uzo8Iku+wv3FINLavcT9wkdM1haBZcXsyMUNneo98g== X-Received: by 2002:a05:6638:1381:: with SMTP id w1mr39780355jad.34.1600672771685; Mon, 21 Sep 2020 00:19:31 -0700 (PDT) MIME-Version: 1.0 References: <1600653893-206277-1-git-send-email-linyunsheng@huawei.com> In-Reply-To: <1600653893-206277-1-git-send-email-linyunsheng@huawei.com> From: Eric Dumazet Date: Mon, 21 Sep 2020 09:19:20 +0200 Message-ID: Subject: Re: [PATCH net-next] net: use in_softirq() to indicate the NAPI context in napi_consume_skb() To: Yunsheng Lin Cc: David Miller , Jakub Kicinski , linmiaohe , martin.varghese@nokia.com, Florian Westphal , Davide Caratti , Steffen Klassert , Paolo Abeni , kyk.segfault@gmail.com, Saeed Mahameed , netdev , LKML , linuxarm@huawei.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 21, 2020 at 4:08 AM Yunsheng Lin wrote: > > When napi_consume_skb() is called in the tx desc cleaning process, > it is usually in the softirq context(BH disabled, or are processing > softirqs), but it may also be in the task context, such as in the > netpoll or loopback selftest process. > > Currently napi_consume_skb() uses non-zero budget to indicate the > NAPI context, the driver writer may provide the wrong budget when > tx desc cleaning function is reused for both NAPI and non-NAPI > context, see [1]. > > So this patch uses in_softirq() to indicate the NAPI context, which > doesn't necessarily mean in NAPI context, but it shouldn't care if > NAPI context or not as long as it runs in softirq context or with BH > disabled, then _kfree_skb_defer() will push the skb to the particular > cpu' napi_alloc_cache atomically. > > [1] https://lkml.org/lkml/2020/9/15/38 > > Signed-off-by: Yunsheng Lin > --- > note that budget parameter is not removed in this patch because it > involves many driver changes, we can remove it in separate patch if > this patch is accepted. > --- > net/core/skbuff.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > index e077447..03d0d28 100644 > --- a/net/core/skbuff.c > +++ b/net/core/skbuff.c > @@ -895,8 +895,10 @@ void __kfree_skb_defer(struct sk_buff *skb) > > void napi_consume_skb(struct sk_buff *skb, int budget) > { > - /* Zero budget indicate non-NAPI context called us, like netpoll */ > - if (unlikely(!budget)) { > + /* called by non-softirq context, which usually means non-NAPI > + * context, like netpoll. > + */ > + if (unlikely(!in_softirq())) { > dev_consume_skb_any(skb); > return; > } > -- I do not think we should add this kind of fuzzy logic, just because _one_ driver author made a mistake. Add a disable_bh() in the driver slow path, and accept the _existing_ semantic, the one that was understood by dozens.