Return-path: Received: from edison.jonmasters.org ([173.255.233.168]) by Galois.linutronix.de with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1fACx2-00050u-C8 for speck@linutronix.de; Sun, 22 Apr 2018 13:14:37 +0200 Received: from jcm by edison.jonmasters.org with local (Exim 4.71) (envelope-from ) id 1fABiO-0003gG-IX for speck@linutronix.de; Sun, 22 Apr 2018 09:55:24 +0000 Message-Id: <20180422094128.208778623@washington.bos.jonmasters.org> Date: Sun, 22 Apr 2018 05:35:30 -0400 From: jcm@redhat.com Subject: [MODERATED] [patch 7/7] [PATCH v2.1-jcm 7/7] x86/ssb/Intel: If MD is disabled at bootup, then set the SPEC_CTRL MSR MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: 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(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 53d5b1b..e3cd2f5 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -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 */ diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index bded0c9..4912715 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -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 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 77d7190..1d4a105 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -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); + } /* -- 1.8.3.1