From: Boqun Feng <boqun.feng@gmail.com>
To: Ryo Takakura <ryotkkr98@gmail.com>
Cc: bigeasy@linutronix.de, clrkwllms@kernel.org, llong@redhat.com,
mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org,
tglx@linutronix.de, will@kernel.org,
linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: Re: [PATCH v3] lockdep: Fix wait context check on softirq for PREEMPT_RT
Date: Sun, 9 Feb 2025 21:22:09 -0800 [thread overview]
Message-ID: <Z6mNARx5H65MPd1-@Mac.home> (raw)
In-Reply-To: <20250118054900.18639-1-ryotkkr98@gmail.com>
On Sat, Jan 18, 2025 at 02:49:00PM +0900, Ryo Takakura wrote:
> Since commit 0c1d7a2c2d32 ("lockdep: Remove softirq accounting on
> PREEMPT_RT."), the wait context test for mutex usage within
> "in softirq context" fails as it references @softirq_context.
>
> [ 0.184549] | wait context tests |
> [ 0.184549] --------------------------------------------------------------------------
> [ 0.184549] | rcu | raw | spin |mutex |
> [ 0.184549] --------------------------------------------------------------------------
> [ 0.184550] in hardirq context: ok | ok | ok | ok |
> [ 0.185083] in hardirq context (not threaded): ok | ok | ok | ok |
> [ 0.185606] in softirq context: ok | ok | ok |FAILED|
>
> As a fix, add lockdep map for BH disabled section. This fixes the
> issue by letting us catch cases when local_bh_disable() gets called
> with preemption disabled where local_lock doesn't get acquired.
> In the case of "in softirq context" selftest, local_bh_disable() was
> being called with preemption disable as it's early in the boot.
>
> Signed-off-by: Ryo Takakura <ryotkkr98@gmail.com>
Queued for future tests and reviews, thanks!
Regards,
Boqun
> ---
>
> Hi!
>
> This version uses CONFIG_DEBUG_LOCK_ALLOC instead of CONFIG_LOCKDEP.
> Thanks Waiman for the advise!
>
> v1:
> https://lore.kernel.org/lkml/20241202012017.14910-1-ryotkkr98@gmail.com/
>
> v2:
> https://lore.kernel.org/lkml/20241227040824.83626-1-ryotkkr98@gmail.com/
>
> Boqun, let me know in case if I should add you as <suggested-by> tag.
> (Please forgive me and ignore if not what the tag intends for...
> I thought its appropriate reading the document[0].)
>
> Sincerely,
> Ryo Takakura
>
> [0] https://www.kernel.org/doc/html/v6.12/process/submitting-patches.html#using-reported-by-tested-by-reviewed-by-suggested-by-and-fixes
>
> ---
> include/linux/bottom_half.h | 8 ++++++++
> kernel/softirq.c | 12 ++++++++++++
> 2 files changed, 20 insertions(+)
>
> diff --git a/include/linux/bottom_half.h b/include/linux/bottom_half.h
> index fc53e0ad5..0640a147b 100644
> --- a/include/linux/bottom_half.h
> +++ b/include/linux/bottom_half.h
> @@ -4,6 +4,7 @@
>
> #include <linux/instruction_pointer.h>
> #include <linux/preempt.h>
> +#include <linux/lockdep.h>
>
> #if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_TRACE_IRQFLAGS)
> extern void __local_bh_disable_ip(unsigned long ip, unsigned int cnt);
> @@ -15,8 +16,13 @@ static __always_inline void __local_bh_disable_ip(unsigned long ip, unsigned int
> }
> #endif
>
> +#ifdef CONFIG_DEBUG_LOCK_ALLOC
> +extern struct lockdep_map bh_lock_map;
> +#endif
> +
> static inline void local_bh_disable(void)
> {
> + lock_map_acquire_read(&bh_lock_map);
> __local_bh_disable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
> }
>
> @@ -25,11 +31,13 @@ extern void __local_bh_enable_ip(unsigned long ip, unsigned int cnt);
>
> static inline void local_bh_enable_ip(unsigned long ip)
> {
> + lock_map_release(&bh_lock_map);
> __local_bh_enable_ip(ip, SOFTIRQ_DISABLE_OFFSET);
> }
>
> static inline void local_bh_enable(void)
> {
> + lock_map_release(&bh_lock_map);
> __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
> }
>
> diff --git a/kernel/softirq.c b/kernel/softirq.c
> index 8c4524ce6..f0edb0abc 100644
> --- a/kernel/softirq.c
> +++ b/kernel/softirq.c
> @@ -1012,3 +1012,15 @@ unsigned int __weak arch_dynirq_lower_bound(unsigned int from)
> {
> return from;
> }
> +
> +#ifdef CONFIG_DEBUG_LOCK_ALLOC
> +static struct lock_class_key bh_lock_key;
> +struct lockdep_map bh_lock_map = {
> + .name = "local_bh",
> + .key = &bh_lock_key,
> + .wait_type_outer = LD_WAIT_FREE,
> + .wait_type_inner = LD_WAIT_CONFIG, /* PREEMPT_RT makes BH preemptible. */
> + .lock_type = LD_LOCK_PERCPU,
> +};
> +EXPORT_SYMBOL_GPL(bh_lock_map);
> +#endif
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-02-10 5:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-18 5:49 [PATCH v3] lockdep: Fix wait context check on softirq for PREEMPT_RT Ryo Takakura
2025-02-10 5:22 ` Boqun Feng [this message]
2025-03-03 18:51 ` [tip: locking/core] " tip-bot2 for Ryo Takakura
2025-03-07 11:39 ` Peter Zijlstra
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=Z6mNARx5H65MPd1-@Mac.home \
--to=boqun.feng@gmail.com \
--cc=bigeasy@linutronix.de \
--cc=clrkwllms@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=llong@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=ryotkkr98@gmail.com \
--cc=tglx@linutronix.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.