Module Name: src
Committed By: maxv
Date: Wed Apr 4 16:23:27 UTC 2018
Modified Files:
src/sys/arch/x86/x86: spectre.c x86_machdep.c
Log Message:
Add machdep.spectre_v2.method, a string that tells which method is
active.
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/x86/spectre.c
cvs rdiff -u -r1.110 -r1.111 src/sys/arch/x86/x86/x86_machdep.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/x86/spectre.c
diff -u src/sys/arch/x86/x86/spectre.c:1.8 src/sys/arch/x86/x86/spectre.c:1.9
--- src/sys/arch/x86/x86/spectre.c:1.8 Wed Apr 4 12:59:49 2018
+++ src/sys/arch/x86/x86/spectre.c Wed Apr 4 16:23:27 2018
@@ -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 @@ enum spec_mitigation {
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 @@ mitigation_change(bool enabled)
struct cpu_info *ci = NULL;
CPU_INFO_ITERATOR cii;
uint64_t xc;
+ const char *name;
speculation_detect_method();
@@ -305,8 +307,18 @@ mitigation_change(bool enabled)
xc_wait(xc);
printf(" done!\n");
spec_mitigation_enabled = enabled;
-
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");
Index: src/sys/arch/x86/x86/x86_machdep.c
diff -u src/sys/arch/x86/x86/x86_machdep.c:1.110 src/sys/arch/x86/x86/x86_machdep.c:1.111
--- src/sys/arch/x86/x86/x86_machdep.c:1.110 Sat Mar 31 08:43:52 2018
+++ src/sys/arch/x86/x86/x86_machdep.c Wed Apr 4 16:23:27 2018
@@ -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 @@ SYSCTL_SETUP(sysctl_machdep_setup, "sysc
#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 @@ SYSCTL_SETUP(sysctl_machdep_setup, "sysc
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 */