Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Enable the SpectreV2 mitigation by default at boot ...



details:   https://anonhg.NetBSD.org/src/rev/1a58dd2be2cf
branches:  trunk
changeset: 360874:1a58dd2be2cf
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed Apr 04 12:59:49 2018 +0000

description:
Enable the SpectreV2 mitigation by default at boot time.

diffstat:

 sys/arch/amd64/amd64/machdep.c |   7 +++++--
 sys/arch/x86/include/cpu.h     |   3 ++-
 sys/arch/x86/x86/cpu.c         |   7 +++++--
 sys/arch/x86/x86/spectre.c     |  22 ++++++++++++++++++++--
 4 files changed, 32 insertions(+), 7 deletions(-)

diffs (116 lines):

diff -r 800bb9bc9d54 -r 1a58dd2be2cf sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Wed Apr 04 10:17:52 2018 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Wed Apr 04 12:59:49 2018 +0000
@@ -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 @@
        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 */
 
diff -r 800bb9bc9d54 -r 1a58dd2be2cf sys/arch/x86/include/cpu.h
--- a/sys/arch/x86/include/cpu.h        Wed Apr 04 10:17:52 2018 +0000
+++ b/sys/arch/x86/include/cpu.h        Wed Apr 04 12:59:49 2018 +0000
@@ -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_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()
diff -r 800bb9bc9d54 -r 1a58dd2be2cf sys/arch/x86/x86/cpu.c
--- a/sys/arch/x86/x86/cpu.c    Wed Apr 04 10:17:52 2018 +0000
+++ b/sys/arch/x86/x86/cpu.c    Wed Apr 04 12:59:49 2018 +0000
@@ -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_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); */
diff -r 800bb9bc9d54 -r 1a58dd2be2cf sys/arch/x86/x86/spectre.c
--- a/sys/arch/x86/x86/spectre.c        Wed Apr 04 10:17:52 2018 +0000
+++ b/sys/arch/x86/x86/spectre.c        Wed Apr 04 12:59:49 2018 +0000
@@ -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 @@
        }
 }
 
+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



Home | Main Index | Thread Index | Old Index