Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2818930pxk; Sun, 20 Sep 2020 19:10:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaqGEMa19Dz96FT0YCeDcUjXo5EgpWYFbv9Cm58PTLWJvQb1J8xYgXWeU5suDvP9G1LsMa X-Received: by 2002:a17:907:3301:: with SMTP id ym1mr50098702ejb.367.1600654202114; Sun, 20 Sep 2020 19:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600654202; cv=none; d=google.com; s=arc-20160816; b=AVJJQMPU/gWO/zxvGrWVTpMkotu7XXcRZwDiKCGubNoL5fJUgjIPl6uggJxh0P1Jb+ PiRfwmRZv5wrz64KbRwrjglf2Fl/+U7i4cjq3xuM12BEbUsCk6JsIK9dN5x1zbomXQpw yM+uRceE9RgAts8uMgPduFMroJj+RfD7KJqHpK4kAjiPAUCwtH7dv3TfncgCjHUp8hcU 0eUp5xVXeGmgSD1MQXDmrUFREoeKf5oaK8b+HcXlvVNKFzTLqoNvNS7T5P6JtksBNx3c u3wDFfeLYKVQuj9SHDOUL7SU+RovqLB7jIrHzzfZrvqUJZf40C9GrUqSm7IU4euFqnrc i20w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=/mjoSMcpcWpnMXaBCNNlTUyuTUvHuMCzDgb+vBmG5ps=; b=O7YMrBgrFllTgOAORHRSQeYdmIggyskERFbQjt3h/dXm0YyWz1m4XdwEzpiu61+Rj/ FNPknqneprA4FT8bEyhi8T5YsbEVGK6mxQ4X3rQYp+EOVs3wqPa3wcD1HE9DmDEB39w5 Ew/+UuFh7AYTwKL6/sUDN7SAEVKUDR0tOYW3w1CKXTvWlthsPvyWLptPCxyPJubv9c2h Yp99egQ9TDvts720xgDEW+6IDXl9G+aYHu9OmHuIklra7Ha+L/LOTMFDuy3AnabJ4VDN OriX2ZYKO70OZchNmeSl4PQ6Af+4M8A6w0yQlMNEFpK5DkcpOm7x8TqmtciVAW/n10xe RW/A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nd6si7461146ejb.189.2020.09.20.19.09.38; Sun, 20 Sep 2020 19:10:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726416AbgIUCIh (ORCPT + 99 others); Sun, 20 Sep 2020 22:08:37 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:13733 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726184AbgIUCIh (ORCPT ); Sun, 20 Sep 2020 22:08:37 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 7D4B3A2B58E6D22EB7B0; Mon, 21 Sep 2020 10:08:35 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Mon, 21 Sep 2020 10:08:25 +0800 From: Yunsheng Lin To: , , , , , , , , , , CC: , , Subject: [PATCH net-next] net: use in_softirq() to indicate the NAPI context in napi_consume_skb() Date: Mon, 21 Sep 2020 10:04:53 +0800 Message-ID: <1600653893-206277-1-git-send-email-linyunsheng@huawei.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.8.1