x86/sbb: Expose the /sys/../sbb and BUG_SBB
Subsystems (4)
PATCH 5/7 x86/sbb: Expose the /sys/../sbb and BUG_SBB
It does not do much except show the words 'Vulnerable' for recent x86 cores. Intel cores prior to Haswell are known not to be vulnerable.
It assumes that older Cyrix, Centaur, etc. cores are immune.
---
v1.3: Remove AMD
s/md/mdd/ v1.4: s/mdd/sbb/ v2.1: s/sbb/spec_store_bypass/ --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/bugs.c | 5 +++++ arch/x86/kernel/cpu/common.c | 20 +++++++++++++++++--- drivers/base/cpu.c | 8 ++++++++ include/linux/cpu.h | 2 ++ 5 files changed, 33 insertions(+), 3 deletions(-)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -362,5 +362,6 @@#define X86_BUG_CPU_MELTDOWN X86_BUG(14)/* CPU is affected by meltdown attack and needs kernel page table isolation */ #define X86_BUG_SPECTRE_V1 X86_BUG(15)/* CPU is affected by Spectre variant 1 attack with conditional branches */ #define X86_BUG_SPECTRE_V2 X86_BUG(16)/* CPU is affected by Spectre variant 2 attack with indirect branches */ +#define X86_BUG_CPU_SPEC_STORE_BYPASS X86_BUG(17)/* CPU is affected by speculative store bypass attack */ #endif /* _ASM_X86_CPUFEATURES_H */
arch/x86/kernel/cpu/bugs.c +5 -0
@@ -391,4 +391,9 @@ ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, c {return cpu_show_common (dev, attr, buf,X86_BUG_SPECTRE_V2 ); } + +ssize_t cpu_show_spec_store_bypass (struct device *dev,struct device_attribute *attr,char *buf) +{ +return cpu_show_common (dev, attr, buf,X86_BUG_CPU_SPEC_STORE_BYPASS ); +}#endif
arch/x86/kernel/cpu/common.c +17 -3
@@ -923,27 +923,41 @@ static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c) {} }; +static const __initconst struct x86_cpu_id cpu_no_spec_store_bypass[] = { + {X86_VENDOR_CENTAUR ,5 }, + {X86_VENDOR_INTEL ,5 }, + {X86_VENDOR_NSC ,5 }, + {X86_VENDOR_ANY ,4 }, + {} +}; +static void __init cpu_set_bug_bits (struct cpuinfo_x86 *c) {u64 ia32_cap =0 ;if (x86_match_cpu (cpu_no_speculation)) -return ; + goto check_spec_store_bypass;setup_force_cpu_bug (X86_BUG_SPECTRE_V1 );setup_force_cpu_bug (X86_BUG_SPECTRE_V2 );if (x86_match_cpu (cpu_no_meltdown)) -return ; + goto check_spec_store_bypass;if (cpu_has (c,X86_FEATURE_ARCH_CAPABILITIES ))rdmsrl (MSR_IA32_ARCH_CAPABILITIES , ia32_cap);/* Rogue Data Cache Load? No! */ if (ia32_cap &ARCH_CAP_RDCL_NO ) -return ; + goto check_spec_store_bypass;setup_force_cpu_bug (X86_BUG_CPU_MELTDOWN ); + +check_spec_store_bypass: +if (x86_match_cpu (cpu_no_spec_store_bypass)) +return ; + +setup_force_cpu_bug (X86_BUG_CPU_SPEC_STORE_BYPASS ); };/*
drivers/base/cpu.c +8 -0
@@ -534,14 +534,22 @@ ssize_t __weak cpu_show_spectre_v2(struct device *dev,return sprintf (buf,"Not affected\n" ); } +ssize_t __weak cpu_show_spec_store_bypass (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 struct attribute *cpu_root_vulnerabilities_attrs[] = { &dev_attr_meltdown.attr, &dev_attr_spectre_v1.attr, &dev_attr_spectre_v2.attr, + &dev_attr_spec_store_bypass.attr,NULL };
include/linux/cpu.h +2 -0
@@ -53,6 +53,8 @@ extern ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf);extern ssize_t cpu_show_spectre_v2 (struct device *dev,struct device_attribute *attr,char *buf); +extern ssize_t cpu_show_spec_store_bypass (struct device *dev, +struct device_attribute *attr,char *buf); extern __printf(4, 5) struct device *cpu_device_create(struct device *parent, void *drvdata,
Signature · 1 line
1.8.3.1
Quoted 2 lines · speck for jcm_at_redhat.com
It does not do much except show the words 'Vulnerable' for recent x86 cores. Intel cores prior to Haswell are known not to be vulnerable.
Sorry, that still needs to say Nehalem in the commit message. Intel can confirm if cores prior to those with "Smart Memory Access" are also vulnerable but everything I have says that they are not.
Jon.
Signature · 1 line
Computer Architect | Sent from my Fedora powered laptop
I will fix up the commit message (match up the name, feature name, etc), and:
Quoted 21 lines
static void
__initcpu_set_bug_bits(struct cpuinfo_x86 *c){arch/x86/kernel/cpu/common.c +2
-3u64 ia32_cap =0 ;if (x86_match_cpu (cpu_no_speculation)) -return ; + goto check_spec_store_bypass;setup_force_cpu_bug (X86_BUG_SPECTRE_V1 );setup_force_cpu_bug (X86_BUG_SPECTRE_V2 );if (x86_match_cpu (cpu_no_meltdown)) -return ; + goto check_spec_store_bypass;if (cpu_has (c,X86_FEATURE_ARCH_CAPABILITIES ))rdmsrl (MSR_IA32_ARCH_CAPABILITIES , ia32_cap);/* Rogue Data Cache Load? No! */ if (ia32_cap &ARCH_CAP_RDCL_NO ) -return ;
arch/x86/kernel/cpu/common.c static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c) · line 961
Quoted 10 lines
arch/x86/kernel/cpu/common.c +7
-0+ goto check_spec_store_bypass;setup_force_cpu_bug (X86_BUG_CPU_MELTDOWN ); + +check_spec_store_bypass: +if (x86_match_cpu (cpu_no_spec_store_bypass)) +return ; + +setup_force_cpu_bug (X86_BUG_CPU_SPEC_STORE_BYPASS ); };
I am going to fix this up per Boris's recommendation (invert the logic):
Instead of jumping to that label three times, you can flip the logic and keep the flow still understandable :) (pasting the whole function here):
static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)
{
u64 ia32_cap = 0;
if (!x86_match_cpu(cpu_no_ssb))
setup_force_cpu_bug(X86_BUG_CPU_SSB);
if (x86_match_cpu(cpu_no_speculation))
return;
setup_force_cpu_bug(X86_BUG_SPECTRE_V1);
setup_force_cpu_bug(X86_BUG_SPECTRE_V2);
if (x86_match_cpu(cpu_no_meltdown))
return;
if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES))
rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap);
/* Rogue Data Cache Load? No! */
if (ia32_cap & ARCH_CAP_RDCL_NO)
return;
setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);arch/x86/kernel/cpu/common.c static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c) · line 930
Quoted 5 lines · speck for jcm_at_redhat.com
arch/x86/kernel/cpu/common.c +5
-0+static const __initconst struct x86_cpu_id cpu_no_spec_store_bypass[] = { + {X86_VENDOR_CENTAUR ,5 }, + {X86_VENDOR_INTEL ,5 }, + {X86_VENDOR_NSC ,5 }, + {X86_VENDOR_ANY ,4 },
The following list of CPUs should also not be susceptible to SSB:
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_PINEVIEW },
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_LINCROFT },
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_PENWELL },
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_CLOVERVIEW },
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_CEDARVIEW },
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1 },
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT2 },
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_AIRMONT },
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNL },
{ X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNM },Tim