Skip to content

Commit 158c260

Browse files
Peter Zijlstrajaywang-amazon
Peter Zijlstra
authored andcommitted
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: 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>
1 parent fa767d2 commit 158c260

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
@@ -952,14 +952,12 @@ void wake_up_all_idle_cpus(void)
952952
{
953953
int cpu;
954954

955-
cpus_read_lock();
956-
for_each_online_cpu(cpu) {
957-
if (cpu == raw_smp_processor_id())
958-
continue;
959-
960-
wake_up_if_idle(cpu);
955+
for_each_possible_cpu(cpu) {
956+
preempt_disable();
957+
if (cpu != smp_processor_id() && cpu_online(cpu))
958+
wake_up_if_idle(cpu);
959+
preempt_enable();
961960
}
962-
cpus_read_unlock();
963961
}
964962
EXPORT_SYMBOL_GPL(wake_up_all_idle_cpus);
965963

0 commit comments

Comments
 (0)