Commit d1059518 authored by Konrad Rzeszutek Wilk's avatar Konrad Rzeszutek Wilk Committed by Thomas Gleixner

x86/bugs: Concentrate bug reporting into a separate function

Those SysFS functions have a similar preamble, as such make common
code to handle them.
Suggested-by: default avatarBorislav Petkov <bp@suse.de>
Signed-off-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarBorislav Petkov <bp@suse.de>
Reviewed-by: default avatarIngo Molnar <mingo@kernel.org>
parent 4a28bfe3
...@@ -314,30 +314,48 @@ static void __init spectre_v2_select_mitigation(void) ...@@ -314,30 +314,48 @@ static void __init spectre_v2_select_mitigation(void)
#undef pr_fmt #undef pr_fmt
#ifdef CONFIG_SYSFS #ifdef CONFIG_SYSFS
ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf)
ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,
char *buf, unsigned int bug)
{ {
if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN)) if (!boot_cpu_has_bug(bug))
return sprintf(buf, "Not affected\n"); return sprintf(buf, "Not affected\n");
switch (bug) {
case X86_BUG_CPU_MELTDOWN:
if (boot_cpu_has(X86_FEATURE_PTI)) if (boot_cpu_has(X86_FEATURE_PTI))
return sprintf(buf, "Mitigation: PTI\n"); return sprintf(buf, "Mitigation: PTI\n");
break;
case X86_BUG_SPECTRE_V1:
return sprintf(buf, "Mitigation: __user pointer sanitization\n");
case X86_BUG_SPECTRE_V2:
return sprintf(buf, "%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "",
boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",
spectre_v2_module_string());
default:
break;
}
return sprintf(buf, "Vulnerable\n"); return sprintf(buf, "Vulnerable\n");
} }
ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf)
{
return cpu_show_common(dev, attr, buf, X86_BUG_CPU_MELTDOWN);
}
ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf) ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf)
{ {
if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V1)) return cpu_show_common(dev, attr, buf, X86_BUG_SPECTRE_V1);
return sprintf(buf, "Not affected\n");
return sprintf(buf, "Mitigation: __user pointer sanitization\n");
} }
ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf) ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf)
{ {
if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2)) return cpu_show_common(dev, attr, buf, X86_BUG_SPECTRE_V2);
return sprintf(buf, "Not affected\n");
return sprintf(buf, "%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "",
boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",
spectre_v2_module_string());
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment