From owner-svn-src-all@freebsd.org Mon Oct 24 20:47:48 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 10BDBC1F998; Mon, 24 Oct 2016 20:47:48 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E00319C0; Mon, 24 Oct 2016 20:47:47 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u9OKll6w005755; Mon, 24 Oct 2016 20:47:47 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u9OKlknk005749; Mon, 24 Oct 2016 20:47:46 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201610242047.u9OKlknk005749@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 24 Oct 2016 20:47:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r307880 - in head/sys: amd64/amd64 i386/i386 x86/include x86/x86 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Oct 2016 20:47:48 -0000 Author: kib Date: Mon Oct 24 20:47:46 2016 New Revision: 307880 URL: https://svnweb.freebsd.org/changeset/base/307880 Log: Follow-up to r307866: - Make !KDB config buildable. - Simplify interface to nmi_handle_intr() by evaluating panic_on_nmi in one place, namely nmi_call_kdb(). This allows to remove do_panic argument from the functions, and to remove i386/amd64 duplication of the variable and sysctl definitions. Note that now NMI causes panic(9) instead of trap_fatal() reporting and then panic(9), consistently for NMIs delivered while CPU operated in ring 0 and 3. Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Modified: head/sys/amd64/amd64/trap.c head/sys/i386/i386/trap.c head/sys/x86/include/x86_var.h head/sys/x86/x86/cpu_machdep.c head/sys/x86/x86/mp_x86.c Modified: head/sys/amd64/amd64/trap.c ============================================================================== --- head/sys/amd64/amd64/trap.c Mon Oct 24 20:36:54 2016 (r307879) +++ head/sys/amd64/amd64/trap.c Mon Oct 24 20:47:46 2016 (r307880) @@ -144,9 +144,6 @@ static char *trap_msg[] = { "DTrace pid return trap", /* 32 T_DTRACE_RET */ }; -static int panic_on_nmi = 1; -SYSCTL_INT(_machdep, OID_AUTO, panic_on_nmi, CTLFLAG_RWTUN, - &panic_on_nmi, 0, "Panic on NMI"); static int prot_fault_translation; SYSCTL_INT(_machdep, OID_AUTO, prot_fault_translation, CTLFLAG_RWTUN, &prot_fault_translation, 0, @@ -372,7 +369,7 @@ trap(struct trapframe *frame) #ifdef DEV_ISA case T_NMI: - nmi_handle_intr(type, frame, true); + nmi_handle_intr(type, frame); break; #endif /* DEV_ISA */ @@ -544,10 +541,8 @@ trap(struct trapframe *frame) #ifdef DEV_ISA case T_NMI: - if (nmi_handle_intr(type, frame, false) || - !panic_on_nmi) - goto out; - /* FALLTHROUGH */ + nmi_handle_intr(type, frame); + goto out; #endif /* DEV_ISA */ } Modified: head/sys/i386/i386/trap.c ============================================================================== --- head/sys/i386/i386/trap.c Mon Oct 24 20:36:54 2016 (r307879) +++ head/sys/i386/i386/trap.c Mon Oct 24 20:47:46 2016 (r307880) @@ -158,14 +158,6 @@ static char *trap_msg[] = { int has_f00f_bug = 0; /* Initialized so that it can be patched. */ #endif -#ifdef KDB -static int kdb_on_nmi = 1; -SYSCTL_INT(_machdep, OID_AUTO, kdb_on_nmi, CTLFLAG_RWTUN, - &kdb_on_nmi, 0, "Go to KDB on NMI"); -#endif -static int panic_on_nmi = 1; -SYSCTL_INT(_machdep, OID_AUTO, panic_on_nmi, CTLFLAG_RWTUN, - &panic_on_nmi, 0, "Panic on NMI"); static int prot_fault_translation = 0; SYSCTL_INT(_machdep, OID_AUTO, prot_fault_translation, CTLFLAG_RW, &prot_fault_translation, 0, "Select signal to deliver on protection fault"); @@ -467,7 +459,7 @@ user_trctrap_out: } goto userout; #else /* !POWERFAIL_NMI */ - nmi_handle_intr(type, frame, true); + nmi_handle_intr(type, frame); break; #endif /* POWERFAIL_NMI */ #endif /* DEV_ISA */ @@ -716,10 +708,8 @@ kernel_trctrap: } goto out; #else /* !POWERFAIL_NMI */ - if (nmi_handle_intr(type, frame, false) || - !panic_on_nmi) - goto out; - /* FALLTHROUGH */ + nmi_handle_intr(type, frame); + goto out; #endif /* POWERFAIL_NMI */ #endif /* DEV_ISA */ } Modified: head/sys/x86/include/x86_var.h ============================================================================== --- head/sys/x86/include/x86_var.h Mon Oct 24 20:36:54 2016 (r307879) +++ head/sys/x86/include/x86_var.h Mon Oct 24 20:47:46 2016 (r307880) @@ -108,10 +108,9 @@ bool fix_cpuid(void); void fillw(int /*u_short*/ pat, void *base, size_t cnt); int is_physical_memory(vm_paddr_t addr); int isa_nmi(int cd); -bool nmi_call_kdb(u_int cpu, u_int type, struct trapframe *frame, - bool panic); -bool nmi_call_kdb_smp(u_int type, struct trapframe *frame, bool panic); -int nmi_handle_intr(u_int type, struct trapframe *frame, bool panic); +void nmi_call_kdb(u_int cpu, u_int type, struct trapframe *frame); +void nmi_call_kdb_smp(u_int type, struct trapframe *frame); +void nmi_handle_intr(u_int type, struct trapframe *frame); void pagecopy(void *from, void *to); void printcpuinfo(void); int user_dbreg_trap(void); Modified: head/sys/x86/x86/cpu_machdep.c ============================================================================== --- head/sys/x86/x86/cpu_machdep.c Mon Oct 24 20:36:54 2016 (r307879) +++ head/sys/x86/x86/cpu_machdep.c Mon Oct 24 20:47:46 2016 (r307880) @@ -524,6 +524,10 @@ idle_sysctl(SYSCTL_HANDLER_ARGS) SYSCTL_PROC(_machdep, OID_AUTO, idle, CTLTYPE_STRING | CTLFLAG_RW, 0, 0, idle_sysctl, "A", "currently selected idle function"); +static int panic_on_nmi = 1; +SYSCTL_INT(_machdep, OID_AUTO, panic_on_nmi, CTLFLAG_RWTUN, + &panic_on_nmi, 0, + "Panic on NMI"); int nmi_is_broadcast = 1; SYSCTL_INT(_machdep, OID_AUTO, nmi_is_broadcast, CTLFLAG_RWTUN, &nmi_is_broadcast, 0, @@ -536,8 +540,8 @@ SYSCTL_INT(_machdep, OID_AUTO, kdb_on_nm #endif #ifdef DEV_ISA -bool -nmi_call_kdb(u_int cpu, u_int type, struct trapframe *frame, bool do_panic) +void +nmi_call_kdb(u_int cpu, u_int type, struct trapframe *frame) { /* machine/parity/power fail/"kitchen sink" faults */ @@ -549,26 +553,25 @@ nmi_call_kdb(u_int cpu, u_int type, stru if (kdb_on_nmi) { printf ("NMI/cpu%d ... going to debugger\n", cpu); kdb_trap(type, 0, frame); - return (true); } - } else #endif /* KDB */ - if (do_panic) + } else if (panic_on_nmi) { panic("NMI indicates hardware failure"); - return (false); + } } #endif -int -nmi_handle_intr(u_int type, struct trapframe *frame, bool panic) +void +nmi_handle_intr(u_int type, struct trapframe *frame) { #ifdef DEV_ISA #ifdef SMP - if (nmi_is_broadcast) - return (nmi_call_kdb_smp(type, frame, panic)); - else + if (nmi_is_broadcast) { + nmi_call_kdb_smp(type, frame); + return; + } #endif - return (nmi_call_kdb(0, type, frame, panic)); + nmi_call_kdb(0, type, frame); #endif } Modified: head/sys/x86/x86/mp_x86.c ============================================================================== --- head/sys/x86/x86/mp_x86.c Mon Oct 24 20:36:54 2016 (r307879) +++ head/sys/x86/x86/mp_x86.c Mon Oct 24 20:47:46 2016 (r307880) @@ -1216,18 +1216,17 @@ ipi_nmi_handler(void) #ifdef DEV_ISA int nmi_kdb_lock; -bool -nmi_call_kdb_smp(u_int type, struct trapframe *frame, bool do_panic) +void +nmi_call_kdb_smp(u_int type, struct trapframe *frame) { int cpu; - bool call_post, ret; + bool call_post; cpu = PCPU_GET(cpuid); if (atomic_cmpset_acq_int(&nmi_kdb_lock, 0, 1)) { - ret = nmi_call_kdb(cpu, type, frame, do_panic); + nmi_call_kdb(cpu, type, frame); call_post = false; } else { - ret = true; savectx(&stoppcbs[cpu]); CPU_SET_ATOMIC(cpu, &stopped_cpus); while (!atomic_cmpset_acq_int(&nmi_kdb_lock, 0, 1)) @@ -1237,7 +1236,6 @@ nmi_call_kdb_smp(u_int type, struct trap atomic_store_rel_int(&nmi_kdb_lock, 0); if (call_post) cpustop_handler_post(cpu); - return (ret); } #endif