Commit 92715e28 authored by Ravikiran G Thirumalai's avatar Ravikiran G Thirumalai Committed by Andi Kleen

[PATCH] x86: Fix boot hang due to nmi watchdog init code

2.6.19  stopped booting (or booted based on build/config) on our x86_64
systems due to a bug introduced in 2.6.19.  check_nmi_watchdog schedules an
IPI on all cpus to  busy wait on a flag, but fails to set the busywait
flag if NMI functionality is disabled.  This causes the secondary cpus
to spin in an endless loop, causing the kernel bootup to hang.
Depending upon the build, the  busywait flag got overwritten (stack variable)
and caused  the kernel to bootup on certain builds.  Following patch fixes
the bug by setting the busywait flag before returning from check_nmi_watchdog.
I guess using a stack variable is not good here as the calling function could
potentially return while the busy wait loop is still spinning on the flag.

AK: I redid the patch significantly to be cleaner
Signed-off-by: default avatarRavikiran Thirumalai <kiran@scalex86.org>
Signed-off-by: default avatarShai Fultheim <shai@scalex86.org>
Signed-off-by: default avatarAndi Kleen <ak@suse.de>
parent 16d279d2
...@@ -195,6 +195,8 @@ static __cpuinit inline int nmi_known_cpu(void) ...@@ -195,6 +195,8 @@ static __cpuinit inline int nmi_known_cpu(void)
return 0; return 0;
} }
static int endflag __initdata = 0;
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
/* The performance counters used by NMI_LOCAL_APIC don't trigger when /* The performance counters used by NMI_LOCAL_APIC don't trigger when
* the CPU is idle. To make sure the NMI watchdog really ticks on all * the CPU is idle. To make sure the NMI watchdog really ticks on all
...@@ -202,7 +204,6 @@ static __cpuinit inline int nmi_known_cpu(void) ...@@ -202,7 +204,6 @@ static __cpuinit inline int nmi_known_cpu(void)
*/ */
static __init void nmi_cpu_busy(void *data) static __init void nmi_cpu_busy(void *data)
{ {
volatile int *endflag = data;
local_irq_enable_in_hardirq(); local_irq_enable_in_hardirq();
/* Intentionally don't use cpu_relax here. This is /* Intentionally don't use cpu_relax here. This is
to make sure that the performance counter really ticks, to make sure that the performance counter really ticks,
...@@ -210,14 +211,13 @@ static __init void nmi_cpu_busy(void *data) ...@@ -210,14 +211,13 @@ static __init void nmi_cpu_busy(void *data)
pause instruction. On a real HT machine this is fine because pause instruction. On a real HT machine this is fine because
all other CPUs are busy with "useless" delay loops and don't all other CPUs are busy with "useless" delay loops and don't
care if they get somewhat less cycles. */ care if they get somewhat less cycles. */
while (*endflag == 0) while (endflag == 0)
barrier(); mb();
} }
#endif #endif
static int __init check_nmi_watchdog(void) static int __init check_nmi_watchdog(void)
{ {
volatile int endflag = 0;
unsigned int *prev_nmi_count; unsigned int *prev_nmi_count;
int cpu; int cpu;
......
...@@ -193,6 +193,8 @@ void nmi_watchdog_default(void) ...@@ -193,6 +193,8 @@ void nmi_watchdog_default(void)
nmi_watchdog = NMI_IO_APIC; nmi_watchdog = NMI_IO_APIC;
} }
static int endflag __initdata = 0;
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
/* The performance counters used by NMI_LOCAL_APIC don't trigger when /* The performance counters used by NMI_LOCAL_APIC don't trigger when
* the CPU is idle. To make sure the NMI watchdog really ticks on all * the CPU is idle. To make sure the NMI watchdog really ticks on all
...@@ -200,7 +202,6 @@ void nmi_watchdog_default(void) ...@@ -200,7 +202,6 @@ void nmi_watchdog_default(void)
*/ */
static __init void nmi_cpu_busy(void *data) static __init void nmi_cpu_busy(void *data)
{ {
volatile int *endflag = data;
local_irq_enable_in_hardirq(); local_irq_enable_in_hardirq();
/* Intentionally don't use cpu_relax here. This is /* Intentionally don't use cpu_relax here. This is
to make sure that the performance counter really ticks, to make sure that the performance counter really ticks,
...@@ -208,14 +209,13 @@ static __init void nmi_cpu_busy(void *data) ...@@ -208,14 +209,13 @@ static __init void nmi_cpu_busy(void *data)
pause instruction. On a real HT machine this is fine because pause instruction. On a real HT machine this is fine because
all other CPUs are busy with "useless" delay loops and don't all other CPUs are busy with "useless" delay loops and don't
care if they get somewhat less cycles. */ care if they get somewhat less cycles. */
while (*endflag == 0) while (endflag == 0)
barrier(); mb();
} }
#endif #endif
int __init check_nmi_watchdog (void) int __init check_nmi_watchdog (void)
{ {
volatile int endflag = 0;
int *counts; int *counts;
int cpu; int cpu;
...@@ -256,6 +256,7 @@ int __init check_nmi_watchdog (void) ...@@ -256,6 +256,7 @@ int __init check_nmi_watchdog (void)
if (!atomic_read(&nmi_active)) { if (!atomic_read(&nmi_active)) {
kfree(counts); kfree(counts);
atomic_set(&nmi_active, -1); atomic_set(&nmi_active, -1);
endflag = 1;
return -1; return -1;
} }
endflag = 1; endflag = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment