Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2959993pxk; Mon, 21 Sep 2020 01:19:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFUYtTDaOteIedf2kXpaYFWECtClrRgXiuhRHVHf+XjOKn7g29p3x7WlKF03pUmW0rVflG X-Received: by 2002:a17:906:364b:: with SMTP id r11mr47656964ejb.48.1600676362557; Mon, 21 Sep 2020 01:19:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600676362; cv=none; d=google.com; s=arc-20160816; b=Rv1juRhg5XVCaNf7dPfkRz3SrCA2i6pAz5K2UJprP7znLBMBc5j7tMqXsFwK6dXJ2h McnmJFkxIOIMEzYpDejRluDWmLBgHSnpTUWI1sqn1kArSCyXHXHUAoch7AR+HqqP9OZZ gCTXDpf9vtOfZQim7ocdJ7ZCAk7ThKIHafbL3HrxIljcQ7Hvh4Oh5hCfvNfYomSNR8HM xGJBEpad9aulfrMQ0q9YLDnHTuvy/gU2xH1VQ80s/4j+JPq2yPicIzO9ocpIw6xlmulD XEvwp2ebn98jGlHwzGsxmdA//ykAULxp22G3cf+EL6boJjbFlu0ct/XycgSBLG9Q0Ymy R2gA== 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=/wriII4q3u887tBtFEfsKFmvW4EmMFQouEZqnm0Btsk=; b=UioLZgLMn4LQsiwpHTbula6i38sUDQ+caMcHwDu5EFjxfDxSUPpipMSOWWDTC2Mcs+ IG6T1b797u+AClB3I5Qd1WC51k3dcVxmr8NzbF6MlGVuJoH0ArP/nFbGttQBTcpwTcCr fjqblHUNb31fiqy5WqhpyalLQQChZgTwfLRUmb0xG2hx6Lu9BtKQG1gRlXef2bTjPT9X KYNMSUw3lokV7LnAKsEoKQwXEDrWXoA3yHDP+UBZKup4JLPt90efYmmzA8+pqhR9elcS mtji+CUIWxghXBkNkFBb9RkgVWGw0cV9LKW/94xJjzM6ryXOCA0/vD6tMD2XcAzi8TCO TB8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VLkZtbBt; 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 yj16si9290087ejb.592.2020.09.21.01.18.59; Mon, 21 Sep 2020 01:19: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=VLkZtbBt; 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 S1726466AbgIUIRx (ORCPT + 99 others); Mon, 21 Sep 2020 04:17:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726475AbgIUIRx (ORCPT ); Mon, 21 Sep 2020 04:17:53 -0400 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 416CAC0613CF for ; Mon, 21 Sep 2020 01:17:53 -0700 (PDT) Received: by mail-io1-xd43.google.com with SMTP id d190so14481577iof.3 for ; Mon, 21 Sep 2020 01:17:53 -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=/wriII4q3u887tBtFEfsKFmvW4EmMFQouEZqnm0Btsk=; b=VLkZtbBtckpA5qGvxWJzj3bBlSod37e1B3ZyxGiwL66gvgqNp1C8GBj42t97n/VTx1 xnvLZmEpTzkrHD+8c9SyBmCWOl7mh+Qm0i94XB9Vtkh81MG2Q1V4UqjYUFERV25RFQzD AGl5MFH+/0rdreZqyKRi9XS22SxwKP0VWaP9kjMS00Yf2dhOMI5j9g3D8NvoXHtxjYnd gX7tmJWbf0cmHlhRX+zcC2nL1BMnWYII9b4nNwdZaHDNybFkQOBJvtUjkSRVrkjegu3j cQNsNfeDnWMI5cMNcPN9+aMu4Hbbhu9RlpLsrtJjuXFcRWYp4Ktw0gIq+KcBMVoqatbA C6nw== 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=/wriII4q3u887tBtFEfsKFmvW4EmMFQouEZqnm0Btsk=; b=pk+ue/XAha/bzuydSyRz0nEGFgTA776V7sIr5MQxI1MVFFcypzsH/xSlECBsCl43lW thzA5MRxUdiZA1farkoQYdyEWkA1TvJWqNMfd0P5yXQHqcfiJCKCJbgy+wEQtpLsGcxE pXvWFiEzKur5J+cgFw/T6OJWPJQT+Clw3r5EyEBbMyjdFY6nd2yL5cJlHDIwKMoTyWzr syDDpjnunotgQAO9Z1kundnedozezVFpFehDABLFvOnKTacUPaE/S939slk9txoaqtjY wruikXnuknYMDwHN5BVkvPklnUlxKy/Y+C7uJaw/acePesyy6L66xhadckNPaGzVX3Gw AeXw== X-Gm-Message-State: AOAM531FCF+NPQVGaiZJLN1rTiKkwDiYip5oltO26dtElvqdOQuTTTVT 6kE+Aq/Nx7CcmuwYimHkLEYO9UnKH/eqYQdBAp1TqQ== X-Received: by 2002:a6b:3bd3:: with SMTP id i202mr35806508ioa.145.1600676272222; Mon, 21 Sep 2020 01:17:52 -0700 (PDT) MIME-Version: 1.0 References: <1600653893-206277-1-git-send-email-linyunsheng@huawei.com> <2102eba1-eeea-bf95-2df5-7fcfa3141694@huawei.com> In-Reply-To: <2102eba1-eeea-bf95-2df5-7fcfa3141694@huawei.com> From: Eric Dumazet Date: Mon, 21 Sep 2020 10:17:40 +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 10:10 AM Yunsheng Lin wrote: > > On 2020/9/21 15:19, Eric Dumazet wrote: > > 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. > > As my understanding, this patch did not change _existing_ semantic, > it still only call _kfree_skb_defer() in softirq context. This patch > just remove the requirement that a softirq context hint need to be > provided to decide whether calling _kfree_skb_defer(). I do not want to remove the requirement. > > Yes, we can add DEBUG_NET() clauses to catch this kind of error as > you suggested. > > But why we need such a debug clauses, when we can decide if delaying > skb freeing is possible in napi_consume_skb(), why not just use > in_softirq() to make this API more easy to use? Just as __dev_kfree_skb_any() > API use "in_irq() || irqs_disabled()" checking to handle the irq context > and non-irq context. I just do not like your patch. Copying another piece of fuzzy logic, inherited from legacy code is not an excuse. Add a local_bh_disable() in the driver slow path to meet _existing_ requirement, so that we can keep the hot path fast.