book3s guards its machine check path against re-entrancy with paca->in_mce and MAX_MCE_DEPTH (see machine_check_early_common in exceptions-64s.S). The booke/e500 path has no such limit.
The handler runs with MSR[ME]=0, but a machine check can still be delivered into it. On an e5500 board a machine check taken while one was already being handled re-entered __machine_check_exception(); instrumenting the entry showed repeated entries, the first with MSR[ME]=1 and every following one with MSR=0x2 (MSR[RI], MSR[ME]=0). Whether the checkstop happens is platform and firmware dependent, and nothing in the booke path is prepared for the check being delivered again. Each re-entry burns stack and loses the report already in flight. Add the same limit for the platforms that go through the generic handler: count machine checks per CPU and, once re-entered, print the reason and go down via nmi_panic() instead of recursing. The counter is only compiled in for !BOOK3S_64: book3s already has the limit in its early real-mode handler and its late handler runs as a normal async interrupt. Signed-off-by: Jinjie Ruan <[email protected]> --- arch/powerpc/kernel/traps.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c index 3a8f5416e3f6..7d46df57c128 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -811,13 +811,43 @@ void die_mce(const char *str, struct pt_regs *regs, long err) * enabled). The only time when this is not true is if the early handler * is unrecoverable, then it does call this directly to try to get a * message out. + * + * Book3s guards against re-entering this path with paca->in_mce and + * MAX_MCE_DEPTH. Booke and the e500 family have no such limit, so a nested + * machine check keeps re-entering here and burning stack until it overflows. */ +#ifndef CONFIG_PPC_BOOK3S_64 +static DEFINE_PER_CPU(int, mce_in_progress); + +static void check_nested_machine_check(struct pt_regs *regs) +{ + if (__this_cpu_inc_return(mce_in_progress) == 1) + return; + +#ifdef CONFIG_PPC_E500 + pr_emerg("Nested machine check (MCSR=%lx), giving up\n", + mfspr(SPRN_MCSR)); +#endif + nmi_panic(regs, "Nested machine check"); +} + +static void machine_check_done(void) +{ + __this_cpu_dec(mce_in_progress); +} +#else +static void check_nested_machine_check(struct pt_regs *regs) { } +static void machine_check_done(void) { } +#endif + static void __machine_check_exception(struct pt_regs *regs) { int recover = 0; inc_irq_stat_and_enable(IRQ_COUNT_MCE); + check_nested_machine_check(regs); + add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE); /* See if any machine dependent calls. In theory, we would want @@ -846,6 +876,8 @@ static void __machine_check_exception(struct pt_regs *regs) /* Must die if the interrupt is not recoverable */ if (regs_is_unrecoverable(regs)) die_mce("Unrecoverable Machine check", regs, SIGBUS); + + machine_check_done(); } #ifdef CONFIG_PPC_BOOK3S_64 -- 2.34.1
