Linux Patch #8
Subsystems (2)
PATCH v2 8/10 Linux Patch #8
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
---
v1.2: Expand on the commit description
s/md_v4/mdd/
s/spec_ctrl_msr_on/spec_ctrl_priv/
s/spec_ctrl_msr_off/spec_ctrp_unpriv/
v1.3:
- Add comment about privilege level changes.
v1.4: Simplify and incorporate various suggestions from Jon Masters
- Export a single x86_spec_ctrl_base value with initial bits
--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/include/asm/nospec-branch.h | 2 ++ arch/x86/kernel/cpu/bugs.c | 7 +++++++ arch/x86/kernel/cpu/intel.c | 8 ++++++++ 4 files changed, 18 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
@@ -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/include/asm/nospec-branch.h +2 -0
@@ -230,6 +230,8 @@ enum ssb_mitigation { SSB_DISABLE, }; +extern bool ssb_mitigation_needed (void ); +extern char __indirect_thunk_start[];extern char __indirect_thunk_end[];
arch/x86/kernel/cpu/bugs.c +7 -0
@@ -441,6 +441,13 @@ static void __init ssb_select_mitigation(void)if (mode ==SSB_NONE )setup_clear_cpu_cap (X86_FEATURE_MDD ); +else if (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) + x86_spec_ctrl_base |=SPEC_CTRL_MDD ; +} + +bool ssb_mitigation_needed (void ) +{ +return (ssb_mode ==SSB_DISABLE ); }#undef pr_fmt
arch/x86/kernel/cpu/intel.c +8 -0
@@ -17,6 +17,7 @@#include <asm/cpu.h> #include <asm/intel-family.h> #include <asm/microcode_intel.h> +#include <asm/nospec-branch.h> #include <asm/hwcap2.h> #include <asm/elf.h>
@@ -685,6 +686,12 @@ static void init_intel(struct cpuinfo_x86 *c)init_intel_misc_features (c); } +static void intel_fix_cpu (struct cpuinfo_x86 *c) +{ +if (ssb_mitigation_needed ()) +wrmsrl (MSR_IA32_SPEC_CTRL ,set_spec_ctrl (SPEC_CTRL_MDD )); +} +#ifdef CONFIG_X86_32 static unsigned int intel_size_cache (struct cpuinfo_x86 *c,unsigned int size) {
@@ -938,6 +945,7 @@ static const struct cpu_dev intel_cpu_dev = { .c_early_init = early_init_intel, .c_init = init_intel, .c_bsp_resume = intel_bsp_resume, + .c_bug_fix = intel_fix_cpu, .c_x86_vendor = X86_VENDOR_INTEL, };
Signature · 1 line
2.14.3