lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1600653893-206277-1-git-send-email-linyunsheng@huawei.com>
Date:   Mon, 21 Sep 2020 10:04:53 +0800
From:   Yunsheng Lin <linyunsheng@...wei.com>
To:     <davem@...emloft.net>, <kuba@...nel.org>, <linmiaohe@...wei.com>,
        <martin.varghese@...ia.com>, <fw@...len.de>, <edumazet@...gle.com>,
        <dcaratti@...hat.com>, <steffen.klassert@...unet.com>,
        <pabeni@...hat.com>, <kyk.segfault@...il.com>, <saeed@...nel.org>
CC:     <netdev@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <linuxarm@...wei.com>
Subject: [PATCH net-next] net: use in_softirq() to indicate the NAPI context in napi_consume_skb()

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 <linyunsheng@...wei.com>
---
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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ