Skip to content

Commit fd62b43

Browse files
Ryo Takakurafbq
Ryo Takakura
authored andcommitted
lockdep: Fix wait context check on softirq for PREEMPT_RT
Since commit 0c1d7a2 ("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 <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 546dff8 commit fd62b43

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

include/linux/bottom_half.h

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <linux/instruction_pointer.h>
66
#include <linux/preempt.h>
7+
#include <linux/lockdep.h>
78

89
#if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_TRACE_IRQFLAGS)
910
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
1516
}
1617
#endif
1718

19+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
20+
extern struct lockdep_map bh_lock_map;
21+
#endif
22+
1823
static inline void local_bh_disable(void)
1924
{
25+
lock_map_acquire_read(&bh_lock_map);
2026
__local_bh_disable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
2127
}
2228

@@ -25,11 +31,13 @@ extern void __local_bh_enable_ip(unsigned long ip, unsigned int cnt);
2531

2632
static inline void local_bh_enable_ip(unsigned long ip)
2733
{
34+
lock_map_release(&bh_lock_map);
2835
__local_bh_enable_ip(ip, SOFTIRQ_DISABLE_OFFSET);
2936
}
3037

3138
static inline void local_bh_enable(void)
3239
{
40+
lock_map_release(&bh_lock_map);
3341
__local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
3442
}
3543

kernel/softirq.c

+12
Original file line numberDiff line numberDiff line change
@@ -1073,3 +1073,15 @@ unsigned int __weak arch_dynirq_lower_bound(unsigned int from)
10731073
{
10741074
return from;
10751075
}
1076+
1077+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
1078+
static struct lock_class_key bh_lock_key;
1079+
struct lockdep_map bh_lock_map = {
1080+
.name = "local_bh",
1081+
.key = &bh_lock_key,
1082+
.wait_type_outer = LD_WAIT_FREE,
1083+
.wait_type_inner = LD_WAIT_CONFIG, /* PREEMPT_RT makes BH preemptible. */
1084+
.lock_type = LD_LOCK_PERCPU,
1085+
};
1086+
EXPORT_SYMBOL_GPL(bh_lock_map);
1087+
#endif

0 commit comments

Comments
 (0)