]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/5.0.16/0011-x86-speculation-mds-Add-sysfs-reporting-for-MDS.patch
Linux 5.0.16
[thirdparty/kernel/stable-queue.git] / releases / 5.0.16 / 0011-x86-speculation-mds-Add-sysfs-reporting-for-MDS.patch
CommitLineData
b07c49f8
GKH
1From d73522ef5e741a0c239eaa5451ea8cc24ff5baaa Mon Sep 17 00:00:00 2001
2From: Thomas Gleixner <tglx@linutronix.de>
3Date: Mon, 18 Feb 2019 22:51:43 +0100
4Subject: [PATCH 11/27] x86/speculation/mds: Add sysfs reporting for MDS
5
6commit 8a4b06d391b0a42a373808979b5028f5c84d9c6a upstream
7
8Add the sysfs reporting file for MDS. It exposes the vulnerability and
9mitigation state similar to the existing files for the other speculative
10hardware vulnerabilities.
11
12Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
13Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
14Reviewed-by: Borislav Petkov <bp@suse.de>
15Reviewed-by: Jon Masters <jcm@redhat.com>
16Tested-by: Jon Masters <jcm@redhat.com>
17Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
18---
19 .../ABI/testing/sysfs-devices-system-cpu | 1 +
20 arch/x86/kernel/cpu/bugs.c | 25 +++++++++++++++++++
21 drivers/base/cpu.c | 8 ++++++
22 include/linux/cpu.h | 2 ++
23 4 files changed, 36 insertions(+)
24
25diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
26index 9605dbd4b5b5..2db5c3407fd6 100644
27--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
28+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
29@@ -484,6 +484,7 @@ What: /sys/devices/system/cpu/vulnerabilities
30 /sys/devices/system/cpu/vulnerabilities/spectre_v2
31 /sys/devices/system/cpu/vulnerabilities/spec_store_bypass
32 /sys/devices/system/cpu/vulnerabilities/l1tf
33+ /sys/devices/system/cpu/vulnerabilities/mds
34 Date: January 2018
35 Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>
36 Description: Information about CPU vulnerabilities
37diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
38index 90f102c85a29..60eab526f98d 100644
39--- a/arch/x86/kernel/cpu/bugs.c
40+++ b/arch/x86/kernel/cpu/bugs.c
41@@ -1172,6 +1172,22 @@ static ssize_t l1tf_show_state(char *buf)
42 }
43 #endif
44
45+static ssize_t mds_show_state(char *buf)
46+{
47+ if (!hypervisor_is_type(X86_HYPER_NATIVE)) {
48+ return sprintf(buf, "%s; SMT Host state unknown\n",
49+ mds_strings[mds_mitigation]);
50+ }
51+
52+ if (boot_cpu_has(X86_BUG_MSBDS_ONLY)) {
53+ return sprintf(buf, "%s; SMT %s\n", mds_strings[mds_mitigation],
54+ sched_smt_active() ? "mitigated" : "disabled");
55+ }
56+
57+ return sprintf(buf, "%s; SMT %s\n", mds_strings[mds_mitigation],
58+ sched_smt_active() ? "vulnerable" : "disabled");
59+}
60+
61 static char *stibp_state(void)
62 {
63 if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
64@@ -1238,6 +1254,10 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr
65 if (boot_cpu_has(X86_FEATURE_L1TF_PTEINV))
66 return l1tf_show_state(buf);
67 break;
68+
69+ case X86_BUG_MDS:
70+ return mds_show_state(buf);
71+
72 default:
73 break;
74 }
75@@ -1269,4 +1289,9 @@ ssize_t cpu_show_l1tf(struct device *dev, struct device_attribute *attr, char *b
76 {
77 return cpu_show_common(dev, attr, buf, X86_BUG_L1TF);
78 }
79+
80+ssize_t cpu_show_mds(struct device *dev, struct device_attribute *attr, char *buf)
81+{
82+ return cpu_show_common(dev, attr, buf, X86_BUG_MDS);
83+}
84 #endif
85diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
86index eb9443d5bae1..2fd6ca1021c2 100644
87--- a/drivers/base/cpu.c
88+++ b/drivers/base/cpu.c
89@@ -546,11 +546,18 @@ ssize_t __weak cpu_show_l1tf(struct device *dev,
90 return sprintf(buf, "Not affected\n");
91 }
92
93+ssize_t __weak cpu_show_mds(struct device *dev,
94+ struct device_attribute *attr, char *buf)
95+{
96+ return sprintf(buf, "Not affected\n");
97+}
98+
99 static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL);
100 static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL);
101 static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL);
102 static DEVICE_ATTR(spec_store_bypass, 0444, cpu_show_spec_store_bypass, NULL);
103 static DEVICE_ATTR(l1tf, 0444, cpu_show_l1tf, NULL);
104+static DEVICE_ATTR(mds, 0444, cpu_show_mds, NULL);
105
106 static struct attribute *cpu_root_vulnerabilities_attrs[] = {
107 &dev_attr_meltdown.attr,
108@@ -558,6 +565,7 @@ static struct attribute *cpu_root_vulnerabilities_attrs[] = {
109 &dev_attr_spectre_v2.attr,
110 &dev_attr_spec_store_bypass.attr,
111 &dev_attr_l1tf.attr,
112+ &dev_attr_mds.attr,
113 NULL
114 };
115
116diff --git a/include/linux/cpu.h b/include/linux/cpu.h
117index 5041357d0297..3c87ad888ed3 100644
118--- a/include/linux/cpu.h
119+++ b/include/linux/cpu.h
120@@ -57,6 +57,8 @@ extern ssize_t cpu_show_spec_store_bypass(struct device *dev,
121 struct device_attribute *attr, char *buf);
122 extern ssize_t cpu_show_l1tf(struct device *dev,
123 struct device_attribute *attr, char *buf);
124+extern ssize_t cpu_show_mds(struct device *dev,
125+ struct device_attribute *attr, char *buf);
126
127 extern __printf(4, 5)
128 struct device *cpu_device_create(struct device *parent, void *drvdata,
129--
1302.21.0
131