Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x86/x86 Add machdep.spectre_v2.method, a string tha...



details:   https://anonhg.NetBSD.org/src/rev/7093b86c22db
branches:  trunk
changeset: 321766:7093b86c22db
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed Apr 04 16:23:27 2018 +0000

description:
Add machdep.spectre_v2.method, a string that tells which method is
active.

diffstat:

 sys/arch/x86/x86/spectre.c     |  18 +++++++++++++++---
 sys/arch/x86/x86/x86_machdep.c |  14 +++++++++++---
 2 files changed, 26 insertions(+), 6 deletions(-)

diffs (102 lines):

diff -r 554c2665a248 -r 7093b86c22db sys/arch/x86/x86/spectre.c
--- a/sys/arch/x86/x86/spectre.c        Wed Apr 04 16:01:05 2018 +0000
+++ b/sys/arch/x86/x86/spectre.c        Wed Apr 04 16:23:27 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: spectre.c,v 1.8 2018/04/04 12:59:49 maxv Exp $ */
+/*     $NetBSD: spectre.c,v 1.9 2018/04/04 16:23:27 maxv Exp $ */
 
 /*
  * Copyright (c) 2018 NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.8 2018/04/04 12:59:49 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.9 2018/04/04 16:23:27 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -57,6 +57,7 @@
 
 bool spec_mitigation_enabled __read_mostly = false;
 static enum spec_mitigation mitigation_method = MITIGATION_NONE;
+char spec_mitigation_name[64] = "(none)";
 
 void speculation_barrier(struct lwp *, struct lwp *);
 
@@ -269,6 +270,7 @@
        struct cpu_info *ci = NULL;
        CPU_INFO_ITERATOR cii;
        uint64_t xc;
+       const char *name;
 
        speculation_detect_method();
 
@@ -305,8 +307,18 @@
                xc_wait(xc);
                printf(" done!\n");
                spec_mitigation_enabled = enabled;
+               mutex_exit(&cpu_lock);
 
-               mutex_exit(&cpu_lock);
+               if (!enabled) {
+                       name = "(none)";
+               } else if (mitigation_method == MITIGATION_AMD_DIS_IND) {
+                       name = "AMD DIS_IND";
+               } else {
+                       name = "Intel IBRS";
+               }
+               strlcpy(spec_mitigation_name, name,
+                   sizeof(spec_mitigation_name));
+
                return 0;
        default:
                panic("impossible");
diff -r 554c2665a248 -r 7093b86c22db sys/arch/x86/x86/x86_machdep.c
--- a/sys/arch/x86/x86/x86_machdep.c    Wed Apr 04 16:01:05 2018 +0000
+++ b/sys/arch/x86/x86/x86_machdep.c    Wed Apr 04 16:23:27 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_machdep.c,v 1.110 2018/03/31 08:43:52 maxv Exp $   */
+/*     $NetBSD: x86_machdep.c,v 1.111 2018/04/04 16:23:27 maxv Exp $   */
 
 /*-
  * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.110 2018/03/31 08:43:52 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.111 2018/04/04 16:23:27 maxv Exp $");
 
 #include "opt_modular.h"
 #include "opt_physmem.h"
@@ -1274,6 +1274,7 @@
 #ifndef XEN
        int sysctl_machdep_spectreV2_mitigated(SYSCTLFN_ARGS);
        extern bool spec_mitigation_enabled;
+       extern char spec_mitigation_name[];
        const struct sysctlnode *spec_rnode;
 
        /* SpectreV1 */
@@ -1297,13 +1298,20 @@
                       CTLTYPE_NODE, "spectre_v2", NULL,
                       NULL, 0, NULL, 0,
                       CTL_MACHDEP, CTL_CREATE);
-       sysctl_createv(clog, 0, &spec_rnode, &spec_rnode,
+       sysctl_createv(clog, 0, &spec_rnode, NULL,
                       CTLFLAG_READWRITE,
                       CTLTYPE_BOOL, "mitigated",
                       SYSCTL_DESCR("Whether Spectre Variant 2 is mitigated"),
                       sysctl_machdep_spectreV2_mitigated, 0,
                       &spec_mitigation_enabled, 0,
                       CTL_CREATE, CTL_EOL);
+       sysctl_createv(clog, 0, &spec_rnode, NULL,
+                      CTLFLAG_PERMANENT,
+                      CTLTYPE_STRING, "method",
+                      SYSCTL_DESCR("Mitigation method in use"),
+                      NULL, 0,
+                      spec_mitigation_name, 0,
+                      CTL_CREATE, CTL_EOL);
 #endif
 
        /* None of these can ever change once the system has booted */



Home | Main Index | Thread Index | Old Index