linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yunsheng Lin <linyunsheng@huawei.com>
To: <davem@davemloft.net>, <kuba@kernel.org>, <linmiaohe@huawei.com>,
	<martin.varghese@nokia.com>, <pabeni@redhat.com>,
	<pshelar@ovn.org>, <fw@strlen.de>, <gnault@redhat.com>,
	<steffen.klassert@secunet.com>, <kyk.segfault@gmail.com>,
	<viro@zeniv.linux.org.uk>, <vladimir.oltean@nxp.com>,
	<edumazet@google.com>, <saeed@kernel.org>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linuxarm@huawei.com>
Subject: [PATCH net-next] net: add in_softirq() debug checking in napi_consume_skb()
Date: Thu, 29 Oct 2020 19:34:48 +0800	[thread overview]
Message-ID: <1603971288-4786-1-git-send-email-linyunsheng@huawei.com> (raw)

The current semantic for napi_consume_skb() is that caller need
to provide non-zero budget when calling from NAPI context, and
breaking this semantic will cause hard to debug problem, because
_kfree_skb_defer() need to run in atomic context in order to push
the skb to the particular cpu' napi_alloc_cache atomically.

So add a in_softirq() debug checking in napi_consume_skb() to catch
this kind of error.

Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
---
v1: drop RFC in the title
---
 include/linux/netdevice.h | 6 ++++++
 net/Kconfig               | 7 +++++++
 net/core/skbuff.c         | 4 ++++
 3 files changed, 17 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 964b494..8042bf1 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -5158,6 +5158,12 @@ do {								\
 })
 #endif
 
+#if defined(CONFIG_DEBUG_NET)
+#define DEBUG_NET_WARN(condition, ...)	WARN(condition, ##__VA_ARGS__)
+#else
+#define DEBUG_NET_WARN(condition, ...)
+#endif
+
 /*
  *	The list of packet types we will receive (as opposed to discard)
  *	and the routines to invoke.
diff --git a/net/Kconfig b/net/Kconfig
index d656716..82e69b0 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -459,6 +459,13 @@ config ETHTOOL_NETLINK
 	  netlink. It provides better extensibility and some new features,
 	  e.g. notification messages.
 
+config DEBUG_NET
+	bool "Net debugging and diagnostics"
+	depends on DEBUG_KERNEL
+	default n
+	help
+	  Say Y here to add some extra checks and diagnostics to networking.
+
 endif   # if NET
 
 # Used by archs to tell that they support BPF JIT compiler plus which flavour.
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 1ba8f01..1834007 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -897,6 +897,10 @@ void napi_consume_skb(struct sk_buff *skb, int budget)
 		return;
 	}
 
+	DEBUG_NET_WARN(!in_softirq(),
+		       "%s is called with non-zero budget outside softirq context.\n",
+		       __func__);
+
 	if (!skb_unref(skb))
 		return;
 
-- 
2.8.1


             reply	other threads:[~2020-10-29 11:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29 11:34 Yunsheng Lin [this message]
2020-10-31 22:38 ` [PATCH net-next] net: add in_softirq() debug checking in napi_consume_skb() Jakub Kicinski
2020-11-02  3:14   ` Yunsheng Lin
2020-11-02 19:41     ` Jakub Kicinski
2020-11-18  1:57       ` Yunsheng Lin
2020-11-18 15:43         ` Jakub Kicinski
2020-11-18 15:57           ` Peter Zijlstra
2020-11-18 16:26             ` Jakub Kicinski
2020-11-19  9:19               ` Yunsheng Lin
2020-11-19 11:41                 ` Peter Zijlstra
2020-11-19 12:29                   ` Yunsheng Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1603971288-4786-1-git-send-email-linyunsheng@huawei.com \
    --to=linyunsheng@huawei.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=gnault@redhat.com \
    --cc=kuba@kernel.org \
    --cc=kyk.segfault@gmail.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=martin.varghese@nokia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pshelar@ovn.org \
    --cc=saeed@kernel.org \
    --cc=steffen.klassert@secunet.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vladimir.oltean@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).