From: Ingo Molnar Enable might_sleep() checks even in early bootup code (when system_state != SYSTEM_RUNNING). There's also a new config option to turn this off: CONFIG_DEBUG_SPINLOCK_SLEEP_EARLY_BOOTUP_WORKAROUND while most other architectures. The patch also documents and works around an EARLY_PRINTK locking dependency. [which we might want to get rid of in the future.] Signed-off-by: Ingo Molnar Signed-off-by: Andrew Morton --- arch/powerpc/Kconfig.debug | 2 ++ kernel/printk.c | 11 ++++++++++- kernel/sched.c | 7 +++++-- lib/Kconfig.debug | 11 +++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff -puN arch/powerpc/Kconfig.debug~turn-on-might_sleep-in-early-bootup-code-too arch/powerpc/Kconfig.debug --- devel/arch/powerpc/Kconfig.debug~turn-on-might_sleep-in-early-bootup-code-too 2006-01-18 22:20:56.000000000 -0800 +++ devel-akpm/arch/powerpc/Kconfig.debug 2006-01-18 22:20:56.000000000 -0800 @@ -2,6 +2,8 @@ menu "Kernel hacking" source "lib/Kconfig.debug" +select CONFIG_DEBUG_SPINLOCK_SLEEP_EARLY_BOOTUP_WORKAROUND + config DEBUG_STACKOVERFLOW bool "Check for stack overflows" depends on DEBUG_KERNEL && PPC64 diff -puN kernel/printk.c~turn-on-might_sleep-in-early-bootup-code-too kernel/printk.c --- devel/kernel/printk.c~turn-on-might_sleep-in-early-bootup-code-too 2006-01-18 22:20:56.000000000 -0800 +++ devel-akpm/kernel/printk.c 2006-01-18 22:20:56.000000000 -0800 @@ -710,7 +710,16 @@ void acquire_console_sem(void) { if (in_interrupt()) BUG(); - down(&console_sem); + /* + * Early-printk wants to acquire the console_sem in + * register_console(). Make a special exception for them by + * going via trylock first, which doesnt trigger the + * might_sleep() atomicity check. + */ +#ifdef CONFIG_EARLY_PRINTK + if (down_trylock(&console_sem)) +#endif + down(&console_sem); console_locked = 1; console_may_schedule = 1; } diff -puN kernel/sched.c~turn-on-might_sleep-in-early-bootup-code-too kernel/sched.c --- devel/kernel/sched.c~turn-on-might_sleep-in-early-bootup-code-too 2006-01-18 22:20:56.000000000 -0800 +++ devel-akpm/kernel/sched.c 2006-01-18 22:20:56.000000000 -0800 @@ -6162,8 +6162,11 @@ void __might_sleep(char *file, int line) #if defined(in_atomic) static unsigned long prev_jiffy; /* ratelimiting */ - if ((in_atomic() || irqs_disabled()) && - system_state == SYSTEM_RUNNING && !oops_in_progress) { +#ifdef CONFIG_DEBUG_SPINLOCK_SLEEP_EARLY_BOOTUP_WORKAROUND + if (system_state != SYSTEM_RUNNING) + return; +#endif + if ((in_atomic() || irqs_disabled()) && !oops_in_progress) { if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) return; prev_jiffy = jiffies; diff -puN lib/Kconfig.debug~turn-on-might_sleep-in-early-bootup-code-too lib/Kconfig.debug --- devel/lib/Kconfig.debug~turn-on-might_sleep-in-early-bootup-code-too 2006-01-18 22:20:56.000000000 -0800 +++ devel-akpm/lib/Kconfig.debug 2006-01-18 22:20:56.000000000 -0800 @@ -119,6 +119,17 @@ config DEBUG_SPINLOCK_SLEEP If you say Y here, various routines which may sleep will become very noisy if they are called with a spinlock held. +config DEBUG_SPINLOCK_SLEEP_EARLY_BOOTUP_WORKAROUND + bool "Work around sleep-inside-spinlock checking in early bootup code" + depends on DEBUG_SPINLOCK_SLEEP + help + If you say Y here, then early bootup code will not check for + "do not call potentially sleeping functions in atomic sections" + rule, that the DEBUG_SPINLOCK_SLEEP option enforces. + + You want to say N here, unless your system does not boot with + "Y" here. + config DEBUG_KOBJECT bool "kobject debugging" depends on DEBUG_KERNEL _