Skip to content

Commit 96611c2

Browse files
author
Peter Zijlstra
committed
sched: Improve wake_up_all_idle_cpus() take #2
As reported by syzbot and experienced by Pavel, using cpus_read_lock() in wake_up_all_idle_cpus() generates lock inversion (against mmap_sem and possibly others). Instead, shrink the preempt disable region by iterating all CPUs and checking the online status for each individual CPU while having preemption disabled. Fixes: 8850cb6 ("sched: Simplify wake_up_*idle*()") Reported-by: [email protected] Reported-by: Pavel Machek <[email protected]> Reported-by: Qian Cai <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Tested-by: Qian Cai <[email protected]>
1 parent 09089db commit 96611c2

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

kernel/smp.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,14 +1170,12 @@ void wake_up_all_idle_cpus(void)
11701170
{
11711171
int cpu;
11721172

1173-
cpus_read_lock();
1174-
for_each_online_cpu(cpu) {
1175-
if (cpu == raw_smp_processor_id())
1176-
continue;
1177-
1178-
wake_up_if_idle(cpu);
1173+
for_each_possible_cpu(cpu) {
1174+
preempt_disable();
1175+
if (cpu != smp_processor_id() && cpu_online(cpu))
1176+
wake_up_if_idle(cpu);
1177+
preempt_enable();
11791178
}
1180-
cpus_read_unlock();
11811179
}
11821180
EXPORT_SYMBOL_GPL(wake_up_all_idle_cpus);
11831181

0 commit comments

Comments
 (0)