
From: Ingo Molnar <mingo@elte.hu>

The early bootup stage is pretty fragile because the idle thread is not yet
functioning as such and so we need preemption disabled.  Whether the bootup
fails or not seems to depend on timing details so e.g.  the presence of
SCHED_SMT makes it go away.

Disabling preemption explicitly has another advantage: the atomicity check
in schedule() will catch early-bootup schedule() calls from now on.

The patch also fixes another preempt-bkl buglet: interrupt-driven
forced-preemption didnt go through preempt_schedule() so it resulted in
auto-dropping of the BKL.  Now we go through preempt_schedule() which
properly deals with the BKL.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/arch/i386/kernel/entry.S |    3 +--
 25-akpm/init/main.c              |    7 +++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff -puN arch/i386/kernel/entry.S~idle-thread-preemption-fix arch/i386/kernel/entry.S
--- 25/arch/i386/kernel/entry.S~idle-thread-preemption-fix	2004-11-07 22:37:29.150102192 -0800
+++ 25-akpm/arch/i386/kernel/entry.S	2004-11-07 22:37:29.155101432 -0800
@@ -197,9 +197,8 @@ need_resched:
 	jz restore_all
 	testl $IF_MASK,EFLAGS(%esp)     # interrupts off (exception path) ?
 	jz restore_all
-	movl $PREEMPT_ACTIVE,TI_preempt_count(%ebp)
 	sti
-	call schedule
+	call preempt_schedule
 	cli
 	movl $0,TI_preempt_count(%ebp)
 	jmp need_resched
diff -puN init/main.c~idle-thread-preemption-fix init/main.c
--- 25/init/main.c~idle-thread-preemption-fix	2004-11-07 22:37:29.152101888 -0800
+++ 25-akpm/init/main.c	2004-11-07 22:37:29.156101280 -0800
@@ -445,6 +445,12 @@ static void noinline rest_init(void)
 {
 	kernel_thread(init, NULL, CLONE_FS | CLONE_SIGHAND);
 	numa_default_policy();
+	/*
+	 * Re-enable preemption but disable interrupts to make sure
+	 * we dont get preempted until we schedule() in cpu_idle().
+	 */
+	local_irq_disable();
+	preempt_enable_no_resched();
 	unlock_kernel();
  	cpu_idle();
 } 
@@ -511,6 +517,7 @@ asmlinkage void __init start_kernel(void
 	 * time - but meanwhile we still have a functioning scheduler.
 	 */
 	sched_init();
+	preempt_disable();
 	build_all_zonelists();
 	page_alloc_init();
 	trap_init();
_
