Skip to content

Commit 1c3c5ea

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
sched/core: Enable might_sleep() and smp_processor_id() checks early
might_sleep() and smp_processor_id() checks are enabled after the boot process is done. That hides bugs in the SMP bringup and driver initialization code. Enable it right when the scheduler starts working, i.e. when init task and kthreadd have been created and right before the idle task enables preemption. Tested-by: Mark Rutland <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Mark Rutland <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 69a78ff commit 1c3c5ea

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

init/main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,16 @@ static noinline void __ref rest_init(void)
414414
rcu_read_lock();
415415
kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
416416
rcu_read_unlock();
417+
418+
/*
419+
* Enable might_sleep() and smp_processor_id() checks.
420+
* They cannot be enabled earlier because with CONFIG_PRREMPT=y
421+
* kernel_thread() would trigger might_sleep() splats. With
422+
* CONFIG_PREEMPT_VOLUNTARY=y the init task might have scheduled
423+
* already, but it's stuck on the kthreadd_done completion.
424+
*/
425+
system_state = SYSTEM_SCHEDULING;
426+
417427
complete(&kthreadd_done);
418428

419429
/*

kernel/sched/core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6238,8 +6238,10 @@ void ___might_sleep(const char *file, int line, int preempt_offset)
62386238

62396239
if ((preempt_count_equals(preempt_offset) && !irqs_disabled() &&
62406240
!is_idle_task(current)) ||
6241-
system_state != SYSTEM_RUNNING || oops_in_progress)
6241+
system_state == SYSTEM_BOOTING || system_state > SYSTEM_RUNNING ||
6242+
oops_in_progress)
62426243
return;
6244+
62436245
if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
62446246
return;
62456247
prev_jiffy = jiffies;

lib/smp_processor_id.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ notrace static unsigned int check_preemption_disabled(const char *what1,
2828
/*
2929
* It is valid to assume CPU-locality during early bootup:
3030
*/
31-
if (system_state != SYSTEM_RUNNING)
31+
if (system_state < SYSTEM_SCHEDULING)
3232
goto out;
3333

3434
/*

0 commit comments

Comments
 (0)