Module Name: src
Committed By: maxv
Date: Wed Apr 4 12:59:49 UTC 2018
Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/x86/include: cpu.h
src/sys/arch/x86/x86: cpu.c spectre.c
Log Message:
Enable the SpectreV2 mitigation by default at boot time.
To generate a diff of this commit:
cvs rdiff -u -r1.302 -r1.303 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.90 -r1.91 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.153 -r1.154 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x86/x86/spectre.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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.302 src/sys/arch/amd64/amd64/machdep.c:1.303
--- src/sys/arch/amd64/amd64/machdep.c:1.302 Sat Mar 17 17:12:39 2018
+++ src/sys/arch/amd64/amd64/machdep.c Wed Apr 4 12:59:49 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.302 2018/03/17 17:12:39 maxv Exp $ */
+/* $NetBSD: machdep.c,v 1.303 2018/04/04 12:59:49 maxv Exp $ */
/*
* Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.302 2018/03/17 17:12:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.303 2018/04/04 12:59:49 maxv Exp $");
/* #define XENDEBUG_LOW */
@@ -1603,6 +1603,9 @@ init_x86_64(paddr_t first_avail)
svs_init();
#endif
cpu_init_msrs(&cpu_info_primary, true);
+#ifndef XEN
+ cpu_speculation_init(&cpu_info_primary);
+#endif
use_pae = 1; /* PAE always enabled in long mode */
Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.90 src/sys/arch/x86/include/cpu.h:1.91
--- src/sys/arch/x86/include/cpu.h:1.90 Fri Mar 30 19:51:53 2018
+++ src/sys/arch/x86/include/cpu.h Wed Apr 4 12:59:49 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.90 2018/03/30 19:51:53 maxv Exp $ */
+/* $NetBSD: cpu.h,v 1.91 2018/04/04 12:59:49 maxv Exp $ */
/*
* Copyright (c) 1990 The Regents of the University of California.
@@ -348,6 +348,7 @@ void cpu_kick(struct cpu_info *);
void cpu_pcpuarea_init(struct cpu_info *);
void cpu_svs_init(struct cpu_info *);
+void cpu_speculation_init(struct cpu_info *);
#define curcpu() x86_curcpu()
#define curlwp x86_curlwp()
Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.153 src/sys/arch/x86/x86/cpu.c:1.154
--- src/sys/arch/x86/x86/cpu.c:1.153 Wed Mar 28 14:56:59 2018
+++ src/sys/arch/x86/x86/cpu.c Wed Apr 4 12:59:49 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.153 2018/03/28 14:56:59 maxv Exp $ */
+/* $NetBSD: cpu.c,v 1.154 2018/04/04 12:59:49 maxv Exp $ */
/*
* Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.153 2018/03/28 14:56:59 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.154 2018/04/04 12:59:49 maxv Exp $");
#include "opt_ddb.h"
#include "opt_mpbios.h" /* for MPDEBUG */
@@ -848,6 +848,9 @@ cpu_hatch(void *v)
cpu_init_msrs(ci, true);
cpu_probe(ci);
+#ifdef __x86_64__
+ cpu_speculation_init(ci);
+#endif
ci->ci_data.cpu_cc_freq = cpu_info_primary.ci_data.cpu_cc_freq;
/* cpu_get_tsc_freq(ci); */
Index: src/sys/arch/x86/x86/spectre.c
diff -u src/sys/arch/x86/x86/spectre.c:1.7 src/sys/arch/x86/x86/spectre.c:1.8
--- src/sys/arch/x86/x86/spectre.c:1.7 Sat Mar 31 08:30:01 2018
+++ src/sys/arch/x86/x86/spectre.c Wed Apr 4 12:59:49 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: spectre.c,v 1.7 2018/03/31 08:30:01 maxv Exp $ */
+/* $NetBSD: spectre.c,v 1.8 2018/04/04 12:59:49 maxv Exp $ */
/*
* Copyright (c) 2018 NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.7 2018/03/31 08:30:01 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.8 2018/04/04 12:59:49 maxv Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -313,6 +313,24 @@ mitigation_change(bool enabled)
}
}
+void
+cpu_speculation_init(struct cpu_info *ci)
+{
+ /*
+ * cpu0 is the one that detects the method and sets the global
+ * variable.
+ */
+ if (ci == &cpu_info_primary) {
+ speculation_detect_method();
+ spec_mitigation_enabled =
+ (mitigation_method != MITIGATION_NONE);
+ }
+
+ if (mitigation_method != MITIGATION_NONE) {
+ mitigation_apply_cpu(ci, true);
+ }
+}
+
int sysctl_machdep_spectreV2_mitigated(SYSCTLFN_ARGS);
int