Return-path: Received: from aserp2120.oracle.com ([141.146.126.78]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1f9Llm-0004AB-Bb for speck@linutronix.de; Fri, 20 Apr 2018 04:27:28 +0200 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w3K2RJL6159139 for ; Fri, 20 Apr 2018 02:27:19 GMT Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2hdrxnjktw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 20 Apr 2018 02:27:19 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w3K2RJAp008972 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 20 Apr 2018 02:27:19 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w3K2RI2K026709 for ; Fri, 20 Apr 2018 02:27:19 GMT Message-Id: <20180420022613.340394083@localhost.localdomain> Date: Thu, 19 Apr 2018 22:25:48 -0400 From: konrad.wilk@oracle.com Subject: [MODERATED] [patch 08/11] [PATCH v2 08/10] Linux Patch #8 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 Signed-off-by: Konrad Rzeszutek Wilk --- 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(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index c9084dedfcfa..bf34fa975212 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/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index 96e5d61e035a..856b792e49b5 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -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[]; diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index f02443b331f5..fbd39d90a0fc 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -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 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 16ee38d8977a..9e865ac6fcdb 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -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, }; -- 2.14.3