From: Thomas Gleixner Date: Thu, 28 Mar 2019 17:57:22 +0000 (-0400) Subject: x86/speculation/mds: Add sysfs reporting for MDS X-Git-Tag: v4.1.12-124.31.3~188 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=808717b3ff88c248d0e4852dc8c360c16931a352;p=users%2Fjedix%2Flinux-maple.git x86/speculation/mds: Add sysfs reporting for MDS commit 8a4b06d391b0a42a373808979b5028f5c84d9c6a upstream Add the sysfs reporting file for MDS. It exposes the vulnerability and mitigation state similar to the existing files for the other speculative hardware vulnerabilities. Signed-off-by: Thomas Gleixner Reviewed-by: Greg Kroah-Hartman Reviewed-by: Borislav Petkov Reviewed-by: Jon Masters Tested-by: Jon Masters (cherry picked from commit db366061fff1f76407cb5d1b0975fcc381400cc3) Orabug: 29526900 CVE: CVE-2018-12126 CVE: CVE-2018-12130 CVE: CVE-2018-12127 Signed-off-by: Kanth Ghatraju Reviewed-by: Mihai Carabas Reviewed-by: Boris Ostrovsky Conflicts: The changes to arch/x86/kernel/cpu/bugs.c instead need to be made to arch/x86/kernel/cpu/bugs_64.c. X86_HYPER_NATIVE doesn't exist so just leave that change out. sched_smt_active() does not exist, instead use cpu_smp_control. hypervisor_is_type replaced with cpu_has_hypervisor --- diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu index 23348a84462d..fdaf7e4d7dd6 100644 --- a/Documentation/ABI/testing/sysfs-devices-system-cpu +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu @@ -278,6 +278,7 @@ What: /sys/devices/system/cpu/vulnerabilities /sys/devices/system/cpu/vulnerabilities/spectre_v2 /sys/devices/system/cpu/vulnerabilities/spec_store_bypass /sys/devices/system/cpu/vulnerabilities/l1tf + /sys/devices/system/cpu/vulnerabilities/mds Date: January 2018 Contact: Linux kernel mailing list Description: Information about CPU vulnerabilities diff --git a/arch/x86/kernel/cpu/bugs_64.c b/arch/x86/kernel/cpu/bugs_64.c index afc91d319b22..7babe5d1c4b2 100644 --- a/arch/x86/kernel/cpu/bugs_64.c +++ b/arch/x86/kernel/cpu/bugs_64.c @@ -1373,6 +1373,22 @@ static ssize_t l1tf_show_state(char *buf) l1tf_vmx_states[l1tf_vmx_mitigation], cpu_smt_control == CPU_SMT_ENABLED ? "vulnerable" : "disabled"); } + +static ssize_t mds_show_state(char *buf) +{ + if (cpu_has_hypervisor) { + return sprintf(buf, "%s; SMT Host state unknown\n", + mds_strings[mds_mitigation]); + } + + if (boot_cpu_has(X86_BUG_MSBDS_ONLY)) { + return sprintf(buf, "%s; SMT %s\n", mds_strings[mds_mitigation], + (cpu_smt_control == CPU_SMT_ENABLED) ? "mitigated" : "disabled"); + } + + return sprintf(buf, "%s; SMT %s\n", mds_strings[mds_mitigation], + (cpu_smt_control == CPU_SMT_ENABLED) ? "vulnerable" : "disabled"); +} #else static ssize_t l1tf_show_state(char *buf) { @@ -1475,6 +1491,10 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr return l1tf_show_state(buf); break; + case X86_BUG_MDS: + return mds_show_state(buf); + break; + default: break; } @@ -1510,4 +1530,9 @@ ssize_t cpu_show_l1tf(struct device *dev, struct device_attribute *attr, char *b { return cpu_show_common(dev, attr, buf, X86_BUG_L1TF); } + +ssize_t cpu_show_mds(struct device *dev, struct device_attribute *attr, char *buf) +{ + return cpu_show_common(dev, attr, buf, X86_BUG_MDS); +} #endif diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index e495e904c026..adb1315b21ab 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -501,11 +501,18 @@ ssize_t __weak cpu_show_l1tf(struct device *dev, return sprintf(buf, "Not affected\n"); } +ssize_t __weak cpu_show_mds(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "Not affected\n"); +} + static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL); static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL); static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL); static DEVICE_ATTR(spec_store_bypass, 0444, cpu_show_spec_store_bypass, NULL); static DEVICE_ATTR(l1tf, 0444, cpu_show_l1tf, NULL); +static DEVICE_ATTR(mds, 0444, cpu_show_mds, NULL); static struct attribute *cpu_root_vulnerabilities_attrs[] = { &dev_attr_meltdown.attr, @@ -513,6 +520,7 @@ static struct attribute *cpu_root_vulnerabilities_attrs[] = { &dev_attr_spectre_v2.attr, &dev_attr_spec_store_bypass.attr, &dev_attr_l1tf.attr, + &dev_attr_mds.attr, NULL }; diff --git a/include/linux/cpu.h b/include/linux/cpu.h index 20f0013a719e..00ddb1b5d0ba 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -50,6 +50,8 @@ extern ssize_t cpu_show_spec_store_bypass(struct device *dev, struct device_attribute *attr, char *buf); extern ssize_t cpu_show_l1tf(struct device *dev, struct device_attribute *attr, char *buf); +extern ssize_t cpu_show_mds(struct device *dev, + struct device_attribute *attr, char *buf); extern struct device *cpu_device_create(struct device *parent, void *drvdata, const struct attribute_group **groups,