From: Yunsheng Lin <linyunsheng@huawei.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <will@kernel.org>,
<viro@zeniv.linux.org.uk>, <kyk.segfault@gmail.com>,
<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>, <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 v3 1/2] lockdep: Introduce in_softirq lockdep assert
Date: Tue, 24 Nov 2020 18:49:28 +0800 [thread overview]
Message-ID: <1606214969-97849-2-git-send-email-linyunsheng@huawei.com> (raw)
In-Reply-To: <1606214969-97849-1-git-send-email-linyunsheng@huawei.com>
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 the lockdep_assert_in_softirq() to assert when the running
context is not in_softirq, in_softirq means softirq is serving or
BH is disabled, which has a ambiguous semantics due to the BH
disabled confusion, so add a comment to emphasize that.
And the softirq context can be interrupted by hard IRQ or NMI
context, lockdep_assert_in_softirq() need to assert about hard
IRQ or NMI context too.
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
---
V3: add comment to emphasize the ambiguous semantics.
---
include/linux/lockdep.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index f559487..8d60f46 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -594,6 +594,13 @@ do { \
this_cpu_read(hardirqs_enabled))); \
} while (0)
+/* Much like in_softirq() - semantics are ambiguous, use carefully. */
+#define lockdep_assert_in_softirq() \
+do { \
+ WARN_ON_ONCE(__lockdep_enabled && \
+ (!in_softirq() || in_irq() || in_nmi())); \
+} while (0)
+
#else
# define might_lock(lock) do { } while (0)
# define might_lock_read(lock) do { } while (0)
@@ -605,6 +612,7 @@ do { \
# define lockdep_assert_preemption_enabled() do { } while (0)
# define lockdep_assert_preemption_disabled() do { } while (0)
+# define lockdep_assert_in_softirq() do { } while (0)
#endif
#ifdef CONFIG_PROVE_RAW_LOCK_NESTING
--
2.8.1
next prev parent reply other threads:[~2020-11-24 10:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-24 10:49 [PATCH net-next v3 0/2] Add an assert in napi_consume_skb() Yunsheng Lin
2020-11-24 10:49 ` Yunsheng Lin [this message]
2020-11-25 23:11 ` [PATCH net-next v3 1/2] lockdep: Introduce in_softirq lockdep assert Jakub Kicinski
2020-11-24 10:49 ` [PATCH net-next v3 2/2] net: Use lockdep_assert_in_softirq() in napi_consume_skb() 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=1606214969-97849-2-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=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peterz@infradead.org \
--cc=pshelar@ovn.org \
--cc=saeed@kernel.org \
--cc=steffen.klassert@secunet.com \
--cc=viro@zeniv.linux.org.uk \
--cc=vladimir.oltean@nxp.com \
--cc=will@kernel.org \
/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).