Module Name:    src
Committed By:   maya
Date:           Wed Jul  4 07:55:57 UTC 2018

Modified Files:
        src/sys/arch/x86/include: specialreg.h
        src/sys/arch/x86/x86: identcpu.c

Log Message:
Disable MWAIT/MONITOR on Apollo Lake CPUs to workaround APL30 errata.

We use MWAIT/MONITOR to hatch secondary CPUs. The errata means that
the wakeup may not happen, so SMP boot fails.
Use wrmsr to disable it in hardware too, for extra paranoia.

PR port-amd64/53420,
also reported on netbsd-users by joern clausen and ssartor.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/arch/x86/include/specialreg.h
cvs rdiff -u -r1.78 -r1.79 src/sys/arch/x86/x86/identcpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/include/specialreg.h
diff -u src/sys/arch/x86/include/specialreg.h:1.126 src/sys/arch/x86/include/specialreg.h:1.127
--- src/sys/arch/x86/include/specialreg.h:1.126	Thu May 31 03:29:01 2018
+++ src/sys/arch/x86/include/specialreg.h	Wed Jul  4 07:55:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: specialreg.h,v 1.126 2018/05/31 03:29:01 msaitoh Exp $	*/
+/*	$NetBSD: specialreg.h,v 1.127 2018/07/04 07:55:57 maya Exp $	*/
 
 /*-
  * Copyright (c) 1991 The Regents of the University of California.
@@ -683,6 +683,7 @@
 #define MSR_THERM_STATUS	0x19c
 #define MSR_THERM2_CTL		0x19d	/* Pentium M */
 #define MSR_MISC_ENABLE		0x1a0
+#define 	IA32_MISC_MWAIT_EN	0x40000
 #define MSR_TEMPERATURE_TARGET	0x1a2
 #define MSR_DEBUGCTLMSR		0x1d9
 #define MSR_LASTBRANCHFROMIP	0x1db

Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.78 src/sys/arch/x86/x86/identcpu.c:1.79
--- src/sys/arch/x86/x86/identcpu.c:1.78	Sun Jul  1 07:59:30 2018
+++ src/sys/arch/x86/x86/identcpu.c	Wed Jul  4 07:55:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: identcpu.c,v 1.78 2018/07/01 07:59:30 maxv Exp $	*/
+/*	$NetBSD: identcpu.c,v 1.79 2018/07/04 07:55:57 maya Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.78 2018/07/01 07:59:30 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.79 2018/07/04 07:55:57 maya Exp $");
 
 #include "opt_xen.h"
 
@@ -190,6 +190,24 @@ cpu_probe_intel_cache(struct cpu_info *c
 }
 
 static void
+cpu_probe_intel_errata(struct cpu_info *ci)
+{
+	u_int family, model, stepping;
+
+	family = CPUID_TO_FAMILY(ci->ci_signature);
+	model = CPUID_TO_MODEL(ci->ci_signature);
+	stepping = CPUID_TO_STEPPING(ci->ci_signature);
+
+	if (family == 0x6 && model == 0x5C && stepping == 0x9) { /* Apollo Lake */
+		wrmsr(MSR_MISC_ENABLE,
+		    rdmsr(MSR_MISC_ENABLE) & ~IA32_MISC_MWAIT_EN);
+
+		cpu_feature[1] &= ~CPUID2_MONITOR;
+		ci->ci_feat_val[1] &= ~CPUID2_MONITOR;
+	}
+}
+
+static void
 cpu_probe_intel(struct cpu_info *ci)
 {
 
@@ -197,6 +215,7 @@ cpu_probe_intel(struct cpu_info *ci)
 		return;
 
 	cpu_probe_intel_cache(ci);
+	cpu_probe_intel_errata(ci);
 }
 
 static void

Reply via email to