From b72d6ac274b7269c62e53d26c39fa31ef1a2d499 Mon Sep 17 00:00:00 2001 From: avg Date: Thu, 7 Jun 2018 14:46:52 +0000 Subject: [PATCH] x86: reorganize code that deals with unexpected NMI-s Expected NMI-s are those than are either generated by the software (such as a CPU sending NMI to other CPU) or generated by the hardware after the software configured it to do so (such as NMI-s on PMC events). Some unexpected NMI-s can be caused by hardware failures and it is possible to inquire the hardware about them (somewhat like MCA but much more primitive) using an EISA mechanism. In some cases the origin of the NMI can remain truly unknown. This commit should not change any functionality. It just reorganizes the code, so that it is easier to extend with new checks for the origin of the NMI. Also, it frees the code that has nothing to do with ISA from DEV_ISA. MFC after: 3 weeks --- sys/x86/x86/cpu_machdep.c | 24 ++++++++++++------------ sys/x86/x86/mp_x86.c | 3 --- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/sys/x86/x86/cpu_machdep.c b/sys/x86/x86/cpu_machdep.c index 0a516445b772..ec70d822e890 100644 --- a/sys/x86/x86/cpu_machdep.c +++ b/sys/x86/x86/cpu_machdep.c @@ -735,33 +735,34 @@ SYSCTL_INT(_machdep, OID_AUTO, kdb_on_nmi, CTLFLAG_RWTUN, "Go to KDB on NMI with unknown source"); #endif -#ifdef DEV_ISA void nmi_call_kdb(u_int cpu, u_int type, struct trapframe *frame) { + bool claimed = false; +#ifdef DEV_ISA /* machine/parity/power fail/"kitchen sink" faults */ - if (isa_nmi(frame->tf_err) == 0) { + if (isa_nmi(frame->tf_err)) { + claimed = true; + if (panic_on_nmi) + panic("NMI indicates hardware failure"); + } +#endif /* DEV_ISA */ #ifdef KDB + if (!claimed && kdb_on_nmi) { /* * NMI can be hooked up to a pushbutton for debugging. */ - if (kdb_on_nmi) { - printf("NMI/cpu%d ... going to debugger\n", cpu); - kdb_trap(type, 0, frame); - } -#endif /* KDB */ - } else if (panic_on_nmi) { - panic("NMI indicates hardware failure"); + printf("NMI/cpu%d ... going to debugger\n", cpu); + kdb_trap(type, 0, frame); } +#endif /* KDB */ } -#endif void nmi_handle_intr(u_int type, struct trapframe *frame) { -#ifdef DEV_ISA #ifdef SMP if (nmi_is_broadcast) { nmi_call_kdb_smp(type, frame); @@ -769,7 +770,6 @@ nmi_handle_intr(u_int type, struct trapframe *frame) } #endif nmi_call_kdb(PCPU_GET(cpuid), type, frame); -#endif } int hw_ibrs_active; diff --git a/sys/x86/x86/mp_x86.c b/sys/x86/x86/mp_x86.c index 23f448e7b9e1..55544a00f7f4 100644 --- a/sys/x86/x86/mp_x86.c +++ b/sys/x86/x86/mp_x86.c @@ -31,7 +31,6 @@ __FBSDID("$FreeBSD$"); #include "opt_apic.h" #endif #include "opt_cpu.h" -#include "opt_isa.h" #include "opt_kstack_pages.h" #include "opt_pmap.h" #include "opt_sched.h" @@ -1339,7 +1338,6 @@ ipi_nmi_handler(void) return (0); } -#ifdef DEV_ISA int nmi_kdb_lock; void @@ -1363,7 +1361,6 @@ nmi_call_kdb_smp(u_int type, struct trapframe *frame) if (call_post) cpustop_handler_post(cpu); } -#endif /* * Handle an IPI_STOP by saving our current context and spinning until we