Skip to contentSkip to conversation

i386: halt the CPU on serious errors

PATCH In review Chuck Ebbert 5 participants 5 messages Jun 20, 2006 – Jun 21, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i386: halt the CPU on serious errors

Halt the CPU when serious errors are encountered and we deliberately go into an infinite loop.

Suggested by Andreas Mohr.

arch/i386/kernel/crash.c +2 -2
@@ -113,8 +113,8 @@ static int crash_nmi_callback(struct pt_
 	disable_local_APIC();
 	atomic_dec(&waiting_for_crash_ipi);
 	/* Assume hlt works */
-	halt();
-	for(;;);
+	for (;;)
+		halt();
 
 	return 1;
 }
arch/i386/kernel/doublefault.c +2 -1
@@ -44,7 +44,8 @@ static void doublefault_fn(void)
 		}
 	}
 
-	for (;;) /* nothing */;
+	for (;;)
+		halt();
 }
 
 struct tss_struct doublefault_tss __cacheline_aligned = {
Signature · 2 lines
Chuck
 "You can't read a newspaper if you can't read."  --George W. Bush
#1 lore raw

arch/i386/kernel/crash.c static int crash_nmi_callback(struct pt_ · line 119

Quoted 12 lines · Chuck Ebbert
arch/i386/kernel/crash.c +2 -2
@@ -113,8 +113,8 @@ static int crash_nmi_callback(struct pt_
 	disable_local_APIC();
 	atomic_dec(&waiting_for_crash_ipi);
 	/* Assume hlt works */
-	halt();
-	for(;;);
+	for (;;)
+		halt();
 
 	return 1;

But we should never get past that first halt(), as interrupts are disabled.

arch/i386/kernel/doublefault.c static void doublefault_fn(void) · line 49

Quoted 10 lines
arch/i386/kernel/doublefault.c +2 -1
@@ -44,7 +44,8 @@ static void doublefault_fn(void)
 		}
 	}
 
-	for (;;) /* nothing */;
+	for (;;)
+		halt();
 }

This one would probably be better off as a cpu_relax()

Dave

Signature · 1 line
http://www.codemonkey.org.uk
#2 lore raw
In reply to Chuck Ebbert

Hi,

Quoted 4 lines · Chuck Ebbert

Halt the CPU when serious errors are encountered and we deliberately go into an infinite loop.

Suggested by Andreas Mohr.

Thanks for the very fast patch, but:

arch/i386/kernel/crash.c static int crash_nmi_callback(struct pt_ · line 117

Quoted 5 lines
      /* Assume hlt works */
arch/i386/kernel/crash.c +2 -2
-     halt();
-     for(;;);
+     for (;;)
+             halt();

The comment above seems to hint at this code in arch/i386/kernel/smp.c/ stop_this_cpu() which does proper hlt checks:

        if (cpu_data[smp_processor_id()].hlt_works_ok)
                for(;;) halt();
        for (;;);

So I'm unsure what happens if hlt is not supported properly. Maybe there's an invalid opcode exception in a loop then.

I think a patch should do the following (or more):

- try to group various CPU emergency stop places together
- comment about trying to avoid overheating, mentioning ACPI thermal protection specifications and possibly *missing protection* in non-ACPI systems/modes (APM!)
- if (hlt_works_ok), do hlt loop
- if not, do a cpu_relax() loop (or even: for (;;) 3 times cpu_relax() for lower activity?)

One thing that may be worth pondering about is whether using cpu_relax() might actually keep the CPU slightly below the ACPI shutdown temperature limit and thus do *more* harm with a broken fan. In that case we might want to check for active ACPI mode and if active do a busy loop instead. This however may cause temperature to cycle (will a CPU shutdown reactivate itself after cooling down again?), so a cpu_relax() might still be better.

Andreas Mohr

#3 lore raw
In reply to Chuck Ebbert
Quoted 2 lines · Chuck Ebbert

Halt the CPU when serious errors are encountered and we deliberately go into an infinite loop.

You need to check first if the CPU supports halt.

-Andi

#4 lore raw
In reply to Chuck Ebbert
Quoted 10 lines · Chuck Ebbert

Halt the CPU when serious errors are encountered and we deliberately go into an infinite loop.

Suggested by Andreas Mohr.

arch/i386/kernel/crash.c static int crash_nmi_callback(struct pt_ · line 117

Quoted 7 lines
arch/i386/kernel/crash.c +2 -2
@@ -113,8 +113,8 @@ static int crash_nmi_callback(struct pt_
 	disable_local_APIC();
 	atomic_dec(&waiting_for_crash_ipi);
 	/* Assume hlt works */
-	halt();
-	for(;;);
+	for (;;)
+		halt();

if halt is fall through (as you suggest).. this would want a cpu_relax() as well..