Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Oct 2016 20:47:46 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
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
Message-ID:  <201610242047.u9OKlknk005749@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201610242047.u9OKlknk005749>