Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2288938imm; Thu, 7 Jun 2018 08:14:43 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJuO2q02lSuUUoXbeblDr9lDr5llGGbxQhKVMLV0c9W922WhTFJfhrSqm7Rl/ipCz8D7uE4 X-Received: by 2002:a17:902:8491:: with SMTP id c17-v6mr2404814plo.97.1528384483886; Thu, 07 Jun 2018 08:14:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528384483; cv=none; d=google.com; s=arc-20160816; b=SFZzB2BfY5uvR3AWngVZQqkjiB+YWJXDGlk56CJLUVGp+H5nY1pPrzcY7muvsWYc14 HzDy1p7cUs8UzbYqPx86C+KEw+cvQh+E5F47yqlqSzhXlU289Ly8ewDOOwAJulRze7bp JeMMsNovHkWeeH8HEe0woObDJ22OPKH53NoEeqJfgwHoqwnjBOAvTmgcSAtKg3VoD9na +FyYdZdtnV6oX2A1XC2Mhyop02znilWTMZLVN+R9thMEEjStWQhpy4jLORfpCounhDe/ 1k1PTEasq/Td0Jjxb8J3pZx8gtmmvc25RhzJElK0LDyUtvQmXoW1hgjo5TBEcLeayD+R rZ+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=wrkle+Dfmijru705TlD9XUa7Z+wxaBao2mNXHkg5S88=; b=UXHhQ/auiwPgS6V8ouhUwE/ie5oP1vb64QkS1UAYEEqY9ApL37dZYchdHXPWtYkyLS ZgSiEY65Hc8yB0rW+JgZU8qpbF7P7AxhT3lVgeHHH8Y1oOUUMHA+lOKtLmH7LILgMjSP u4seZYugSiU4XtSZc9aaqLnKPQtkQJLZ71XZk2uCjMAwGSNkWlzn6GjFDA6urIblG+Sw wJQTk/sHJGha26p5Zpi0+XD9kbPZfGgQFskKBvW6AUYNy2xTirEhWX6yWfXeTSsxRl6I kPz7Zo/BcuC4lgEeR1LBFetGZ7IGeNZJfbb/QvN+H/dR8aCpSYvGIXxCunOXILpCRD1z yFAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u123-v6si25518402pfc.178.2018.06.07.08.14.29; Thu, 07 Jun 2018 08:14:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753781AbeFGPNZ (ORCPT + 99 others); Thu, 7 Jun 2018 11:13:25 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41436 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964886AbeFGPCQ (ORCPT ); Thu, 7 Jun 2018 11:02:16 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvby-0005hL-44; Thu, 07 Jun 2018 15:09:58 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvay-0002jt-UQ; Thu, 07 Jun 2018 15:08:56 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Greg Kroah-Hartman" , pbonzini@redhat.com, tim.c.chen@linux.intel.com, peterz@infradead.org, ashok.raj@intel.com, "David Woodhouse" , bp@alien8.de, ak@linux.intel.com, gregkh@linux-foundation.org, dave.hansen@intel.com, "KarimAllah Ahmed" , torvalds@linux-foundation.org, arjan@linux.intel.com, gnomes@lxorguk.ukuu.org.uk Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 047/410] x86/speculation: Add basic IBPB (Indirect Branch Prediction Barrier) support In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: David Woodhouse commit 20ffa1caecca4db8f79fe665acdeaa5af815a24d upstream. Expose indirect_branch_prediction_barrier() for use in subsequent patches. [ tglx: Add IBPB status to spectre_v2 sysfs file ] Co-developed-by: KarimAllah Ahmed Signed-off-by: KarimAllah Ahmed Signed-off-by: David Woodhouse Cc: gnomes@lxorguk.ukuu.org.uk Cc: ak@linux.intel.com Cc: ashok.raj@intel.com Cc: dave.hansen@intel.com Cc: arjan@linux.intel.com Cc: torvalds@linux-foundation.org Cc: peterz@infradead.org Cc: bp@alien8.de Cc: pbonzini@redhat.com Cc: tim.c.chen@linux.intel.com Cc: gregkh@linux-foundation.org Link: https://lkml.kernel.org/r/1516896855-7642-8-git-send-email-dwmw@amazon.co.uk Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman [bwh: Backported to 3.16: - Renumber the feature bit - Adjust context] Signed-off-by: Ben Hutchings --- arch/x86/include/asm/cpufeature.h | 2 ++ arch/x86/include/asm/nospec-branch.h | 13 +++++++++++++ arch/x86/kernel/cpu/bugs.c | 10 +++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -189,6 +189,8 @@ #define X86_FEATURE_INVPCID_SINGLE (7*32+10) /* Effectively INVPCID && CR4.PCIDE=1 */ #define X86_FEATURE_RSB_CTXSW (7*32+11) /* "" Fill RSB on context switches */ +#define X86_FEATURE_IBPB (7*32+12) /* Indirect Branch Prediction Barrier enabled*/ + #define X86_FEATURE_RETPOLINE (7*32+29) /* "" Generic Retpoline mitigation for Spectre variant 2 */ #define X86_FEATURE_RETPOLINE_AMD (7*32+30) /* "" AMD Retpoline mitigation for Spectre variant 2 */ /* Because the ALTERNATIVE scheme is for members of the X86_FEATURE club... */ --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -194,5 +194,18 @@ static inline void vmexit_fill_RSB(void) #endif } +static inline void indirect_branch_prediction_barrier(void) +{ + asm volatile(ALTERNATIVE("", + "movl %[msr], %%ecx\n\t" + "movl %[val], %%eax\n\t" + "movl $0, %%edx\n\t" + "wrmsr", + X86_FEATURE_IBPB) + : : [msr] "i" (MSR_IA32_PRED_CMD), + [val] "i" (PRED_CMD_IBPB) + : "eax", "ecx", "edx", "memory"); +} + #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_NOSPEC_BRANCH_H_ */ --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -358,6 +358,13 @@ retpoline_auto: setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW); pr_info("Filling RSB on context switch\n"); } + + /* Initialize Indirect Branch Prediction Barrier if supported */ + if (boot_cpu_has(X86_FEATURE_SPEC_CTRL) || + boot_cpu_has(X86_FEATURE_AMD_PRED_CMD)) { + setup_force_cpu_cap(X86_FEATURE_IBPB); + pr_info("Enabling Indirect Branch Prediction Barrier\n"); + } } #undef pr_fmt @@ -387,7 +394,8 @@ ssize_t cpu_show_spectre_v2(struct devic if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2)) return sprintf(buf, "Not affected\n"); - return sprintf(buf, "%s%s\n", spectre_v2_strings[spectre_v2_enabled], + return sprintf(buf, "%s%s%s\n", spectre_v2_strings[spectre_v2_enabled], + boot_cpu_has(X86_FEATURE_IBPB) ? ", IPBP" : "", spectre_v2_module_string()); } #endif