Skip to content

Commit 1171ed2

Browse files
Valentin Schneiderzeddii
authored andcommitted
notifier: Make atomic_notifiers use raw_spinlock
Booting a recent PREEMPT_RT kernel (v5.10-rc3-rt7-rebase) on my arm64 Juno leads to the idle task blocking on an RT sleeping spinlock down some notifier path: [ 1.809101] BUG: scheduling while atomic: swapper/5/0/0x00000002 [ 1.809116] Modules linked in: [ 1.809123] Preemption disabled at: [ 1.809125] secondary_start_kernel (arch/arm64/kernel/smp.c:227) [ 1.809146] CPU: 5 PID: 0 Comm: swapper/5 Tainted: G W 5.10.0-rc3-rt7 torvalds#168 [ 1.809153] Hardware name: ARM Juno development board (r0) (DT) [ 1.809158] Call trace: [ 1.809160] dump_backtrace (arch/arm64/kernel/stacktrace.c:100 (discriminator 1)) [ 1.809170] show_stack (arch/arm64/kernel/stacktrace.c:198) [ 1.809178] dump_stack (lib/dump_stack.c:122) [ 1.809188] __schedule_bug (kernel/sched/core.c:4886) [ 1.809197] __schedule (./arch/arm64/include/asm/preempt.h:18 kernel/sched/core.c:4913 kernel/sched/core.c:5040) [ 1.809204] preempt_schedule_lock (kernel/sched/core.c:5365 (discriminator 1)) [ 1.809210] rt_spin_lock_slowlock_locked (kernel/locking/rtmutex.c:1072) [ 1.809217] rt_spin_lock_slowlock (kernel/locking/rtmutex.c:1110) [ 1.809224] rt_spin_lock (./include/linux/rcupdate.h:647 kernel/locking/rtmutex.c:1139) [ 1.809231] atomic_notifier_call_chain_robust (kernel/notifier.c:71 kernel/notifier.c:118 kernel/notifier.c:186) [ 1.809240] cpu_pm_enter (kernel/cpu_pm.c:39 kernel/cpu_pm.c:93) [ 1.809249] psci_enter_idle_state (drivers/cpuidle/cpuidle-psci.c:52 drivers/cpuidle/cpuidle-psci.c:129) [ 1.809258] cpuidle_enter_state (drivers/cpuidle/cpuidle.c:238) [ 1.809267] cpuidle_enter (drivers/cpuidle/cpuidle.c:353) [ 1.809275] do_idle (kernel/sched/idle.c:132 kernel/sched/idle.c:213 kernel/sched/idle.c:273) [ 1.809282] cpu_startup_entry (kernel/sched/idle.c:368 (discriminator 1)) [ 1.809288] secondary_start_kernel (arch/arm64/kernel/smp.c:273) Two points worth noting: 1) That this is conceptually the same issue as pointed out in: 313c8c1 ("PM / CPU: replace raw_notifier with atomic_notifier") 2) Only the _robust() variant of atomic_notifier callchains suffer from this AFAICT only the cpu_pm_notifier_chain really needs to be changed, but singling it out would mean introducing a new (truly) non-blocking API. At the same time, callers that are fine with any blocking within the call chain should use blocking notifiers, so patching up all atomic_notifier's doesn't seem *too* crazy to me. Fixes: 70d9329 ("notifier: Fix broken error handling pattern") Signed-off-by: Valentin Schneider <[email protected]> Reviewed-by: Daniel Bristot de Oliveira <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sebastian Andrzej Siewior <[email protected]>
1 parent 1e6ded6 commit 1171ed2

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

include/linux/notifier.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct notifier_block {
5858
};
5959

6060
struct atomic_notifier_head {
61-
spinlock_t lock;
61+
raw_spinlock_t lock;
6262
struct notifier_block __rcu *head;
6363
};
6464

@@ -78,7 +78,7 @@ struct srcu_notifier_head {
7878
};
7979

8080
#define ATOMIC_INIT_NOTIFIER_HEAD(name) do { \
81-
spin_lock_init(&(name)->lock); \
81+
raw_spin_lock_init(&(name)->lock); \
8282
(name)->head = NULL; \
8383
} while (0)
8484
#define BLOCKING_INIT_NOTIFIER_HEAD(name) do { \
@@ -95,7 +95,7 @@ extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
9595
cleanup_srcu_struct(&(name)->srcu);
9696

9797
#define ATOMIC_NOTIFIER_INIT(name) { \
98-
.lock = __SPIN_LOCK_UNLOCKED(name.lock), \
98+
.lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
9999
.head = NULL }
100100
#define BLOCKING_NOTIFIER_INIT(name) { \
101101
.rwsem = __RWSEM_INITIALIZER((name).rwsem), \

kernel/notifier.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
142142
unsigned long flags;
143143
int ret;
144144

145-
spin_lock_irqsave(&nh->lock, flags);
145+
raw_spin_lock_irqsave(&nh->lock, flags);
146146
ret = notifier_chain_register(&nh->head, n);
147-
spin_unlock_irqrestore(&nh->lock, flags);
147+
raw_spin_unlock_irqrestore(&nh->lock, flags);
148148
return ret;
149149
}
150150
EXPORT_SYMBOL_GPL(atomic_notifier_chain_register);
@@ -164,9 +164,9 @@ int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
164164
unsigned long flags;
165165
int ret;
166166

167-
spin_lock_irqsave(&nh->lock, flags);
167+
raw_spin_lock_irqsave(&nh->lock, flags);
168168
ret = notifier_chain_unregister(&nh->head, n);
169-
spin_unlock_irqrestore(&nh->lock, flags);
169+
raw_spin_unlock_irqrestore(&nh->lock, flags);
170170
synchronize_rcu();
171171
return ret;
172172
}
@@ -182,9 +182,9 @@ int atomic_notifier_call_chain_robust(struct atomic_notifier_head *nh,
182182
* Musn't use RCU; because then the notifier list can
183183
* change between the up and down traversal.
184184
*/
185-
spin_lock_irqsave(&nh->lock, flags);
185+
raw_spin_lock_irqsave(&nh->lock, flags);
186186
ret = notifier_call_chain_robust(&nh->head, val_up, val_down, v);
187-
spin_unlock_irqrestore(&nh->lock, flags);
187+
raw_spin_unlock_irqrestore(&nh->lock, flags);
188188

189189
return ret;
190190
}

0 commit comments

Comments
 (0)