Skip to content

Commit 7ab92a2

Browse files
Peter Zijlstrapaniakin-aws
Peter Zijlstra
authored andcommitted
sched: Improve wake_up_all_idle_cpus() take #2
commit 96611c2 upstream. 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: syzbot+d5b23b18d2f4feae8a67@syzkaller.appspotmail.com Reported-by: Pavel Machek <pavel@ucw.cz> Reported-by: Qian Cai <quic_qiancai@quicinc.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Qian Cai <quic_qiancai@quicinc.com> (cherry picked from commit 96611c2)
1 parent eed0e2f commit 7ab92a2

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)