panic stops every other processor
A panic used to stop only the processor it happened on. The rest carried on with a dead kernel: on the ASUS laptop the report flashed up and was drawn over, and the fans stayed loud until the power button was held. Now the panicking processor sends every other one an NMI, which arrives even with interrupts off, and trap() halts a processor that takes one while panic_stop is set -- first thing, before the canary check, since that stack may be what broke. NMI gets its own per-CPU stack (IST 1): for a few instructions at the top of syscall_entry the live stack is the user's, at ring 0, and a fault pushing the frame there would be a double fault on the same stack and a reset instead of a report. A second processor that panics while one is already reporting halts instead of drawing over it; the owner's own nested panic still gets through. Checked under QEMU with -smp 4: after a sysrq crash CPUs 1-3 sit in hlt with IF clear and CPU 0 is in the report's blink loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
This commit is contained in:
parent
d8e8ae604f
commit
38c89b1a9a
5 changed files with 57 additions and 0 deletions
|
|
@ -559,6 +559,9 @@ report_serial(char *reason, addr_t *pcs, int npcs)
|
|||
|
||||
static void panic_blink(void) __attribute__((noreturn));
|
||||
|
||||
volatile int panic_stop;
|
||||
static volatile int panic_owner = -1;
|
||||
|
||||
__attribute__((noreturn))
|
||||
void
|
||||
panic(char *s)
|
||||
|
|
@ -566,6 +569,21 @@ panic(char *s)
|
|||
addr_t pcs[10];
|
||||
|
||||
cli();
|
||||
|
||||
// One processor reports; any other that panics meanwhile -- the same broken
|
||||
// state tends to reach several at once -- stops where it is. The owner may
|
||||
// panic again while drawing, and that nested report is let through.
|
||||
int me = cpunum();
|
||||
int owner = __sync_val_compare_and_swap(&panic_owner, -1, me);
|
||||
if (owner != -1 && owner != me)
|
||||
for (;;) {
|
||||
cli();
|
||||
hlt();
|
||||
}
|
||||
// And the rest are stopped outright, see trap().
|
||||
panic_stop = 1;
|
||||
lapic_nmi_others();
|
||||
|
||||
// Stop every other path from writing to the console. consputc checks this
|
||||
// and spins, which is what keeps another CPU from painting over the report
|
||||
// while it is being drawn.
|
||||
|
|
|
|||
Loading…
Reference in a new issue