Skip to contentSkip to conversation

Linux Patch #5

PATCH Superseded [email protected] 3 participants 3 messages Apr 20, 2018

Subsystems (4)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 5/10 Linux Patch #5

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/
---
 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
index d554c11e01ff..f0ea33c95dc1 100644
@@ -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_SSB			X86_BUG(17) /* CPU is affected by speculative store bypass attack */
 
 #endif /* _ASM_X86_CPUFEATURES_H */
arch/x86/kernel/cpu/bugs.c +5 -0
index 3c28473784ad..2838802346fc 100644
@@ -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_ssb(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	return cpu_show_common(dev, attr, buf, X86_BUG_CPU_SSB);
+}
 #endif
arch/x86/kernel/cpu/common.c +17 -3
index 9ddbfbefa5cf..f7d80658cced 100644
@@ -918,27 +918,41 @@ static const __initconst struct x86_cpu_id cpu_no_meltdown[] = {
 	{}
 };
 
+static const __initconst struct x86_cpu_id cpu_no_ssb[] = {
+	{ 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_ssb;
 
 	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_ssb;
 
 	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_ssb;
 
 	setup_force_cpu_bug(X86_BUG_CPU_MELTDOWN);
+
+check_ssb:
+	if (x86_match_cpu(cpu_no_ssb))
+		return;
+
+	setup_force_cpu_bug(X86_BUG_CPU_SSB);
 };
 
 /*
drivers/base/cpu.c +8 -0
index d21a2d913107..eee2d539bb68 100644
@@ -532,14 +532,22 @@ ssize_t __weak cpu_show_spectre_v2(struct device *dev,
 	return sprintf(buf, "Not affected\n");
 }
 
+ssize_t __weak cpu_show_ssb(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(ssb, 0444, cpu_show_ssb, NULL);
 
 static struct attribute *cpu_root_vulnerabilities_attrs[] = {
 	&dev_attr_meltdown.attr,
 	&dev_attr_spectre_v1.attr,
 	&dev_attr_spectre_v2.attr,
+	&dev_attr_ssb.attr,
 	NULL
 };
 
include/linux/cpu.h +2 -0
index 7b01bc11c692..e3089a1658dd 100644
@@ -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_ssb(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
2.14.3
#1 lore raw
Quoted 2 lines · speck for konrad.wilk_at_oracle.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.

I twice referred to "Haswell" when I meant Nehalem and was even thinking the latter (and had discussed as much with Intel). Apologies. I know Konrad is fixing this up in the next post to just say "contemporary".

Intel originally added Memory Disambiguation in "Smart Memory Access", which was a new set of features first publicly announced in 2006.

Jon.

Signature · 1 line
Computer Architect | Sent from my Fedora powered laptop
#2 lore raw
In reply to [email protected]
Quoted 13 lines · speck for konrad.wilk_at_oracle.com

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/
---

...

arch/x86/kernel/cpu/common.c static const __initconst struct x86_cpu_id cpu_no_meltdown[] = { · line 934

Quoted 7 lines

static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c) {

arch/x86/kernel/cpu/common.c +1 -1
 	u64 ia32_cap = 0;
 
 	if (x86_match_cpu(cpu_no_speculation))
-		return;
+		goto check_ssb;

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);
};
Signature · 5 lines
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
--