Skip to contentSkip to conversation

x86/ssb/Intel: If MD is disabled at bootup, then set the SPEC_CTRL MSR

PATCH In review [email protected] 1 participant 1 message Apr 22, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 7/7 x86/ssb/Intel: If MD is disabled at bootup, then set the SPEC_CTRL MSR

Intel CPUs expose methods to:
- detect whether memory disambiguation can be disabled via CPUID.7.0.EDX[31]

- The SPEC_CTRL MSR(0x48), bit 2 set to disable this functionality.

With that in mind if ssb=[auto,on] (or mdd=[auto,on]) is selected we will set at boot-time the SPEC_CTRL MSR to disable memory disambiguation if the platform requires it.

Note that this does not fix the KVM case where the SPEC_CTRL
is exposed to guests who can muck with, see patch titled:
KVM/SVM/VMX/x86/spectre_v2: Support the combination of guest IBRS and ours.

And for the firmware (IBRS to be set), see patch titled:
x86/spectre_v2: Read SPEC_CTRL MSR during boot and re-use reserved bits

---
 arch/x86/include/asm/msr-index.h |  1 +
 arch/x86/kernel/cpu/bugs.c       | 12 ++++++++++++
 arch/x86/kernel/cpu/common.c     |  9 +++++++++
 3 files changed, 22 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
index 53d5b1b..e3cd2f5 100644
@@ -42,6 +42,7 @@
 #define MSR_IA32_SPEC_CTRL		0x00000048 /* Speculation Control */
 #define SPEC_CTRL_IBRS			(1 << 0)   /* Indirect Branch Restricted Speculation */
 #define SPEC_CTRL_STIBP			(1 << 1)   /* Single Thread Indirect Branch Predictors */
+#define SPEC_CTRL_MDD			(1 << 2)   /* Memory Disambiguation Disable */
 
 #define MSR_IA32_PRED_CMD		0x00000049 /* Prediction Command */
 #define PRED_CMD_IBPB			(1 << 0)   /* Indirect Branch Prediction Barrier */
arch/x86/kernel/cpu/bugs.c +12 -0
index bded0c9..4912715 100644
@@ -80,6 +80,14 @@ void __init check_bugs(void)
 	if (!direct_gbpages)
 		set_memory_4k((unsigned long)__va(0), 1);
 #endif
+
+	/*
+	 * If we did anything to update the SPEC_CTRL configuration
+	 * then write it back to the underlying hardware MSR. For
+	 * now, that's just a case of checking if we enabled MDD.
+	 */
+	if (boot_cpu_has(X86_FEATURE_USE_MDD))
+		wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
 }
 
 /* The kernel command line selection */
@@ -439,6 +447,10 @@ static void __init spec_store_bypass_select_mitigation(void)
 
 	if (mode == SPEC_STORE_BYPASS_NONE)
 		setup_clear_cpu_cap(X86_FEATURE_USE_MDD);
+	else if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) {
+		setup_force_cpu_cap(X86_FEATURE_USE_MDD);
+		x86_spec_ctrl_base |= SPEC_CTRL_MDD;
+	}
 }
 
 #undef pr_fmt
arch/x86/kernel/cpu/common.c +9 -0
index 77d7190..1d4a105 100644
@@ -1319,6 +1319,15 @@ static void identify_cpu(struct cpuinfo_x86 *c)
 #ifdef CONFIG_NUMA
 	numa_add_cpu(smp_processor_id());
 #endif
+
+        /*
+         * If we modified the boot time SPEC_CTRL configuration
+         * then write it back to the underlying hardware MSR. For
+         * now, that's just a case of checking if we enabled MDD.
+         */
+        if (boot_cpu_has(X86_FEATURE_USE_MDD))
+                wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
+
 }
 
 /*
Signature · 1 line
1.8.3.1