From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754198AbeAJBXY (ORCPT + 1 other); Tue, 9 Jan 2018 20:23:24 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:53925 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752897AbeAJBVr (ORCPT ); Tue, 9 Jan 2018 20:21:47 -0500 Message-Id: <20180110011350.759392067@linutronix.de> User-Agent: quilt/0.63-1 Date: Wed, 10 Jan 2018 02:06:56 +0100 From: Thomas Gleixner To: LKML Cc: Linus Torvalds , x86@kernel.org, Peter Zijlstra , Borislav Petkov , David Woodhouse , Tim Chen , Andrea Arcangeli , Andi Kleen , Greg KH , Dave Hansen , Andy Lutomirski , Arjan Van De Ven , Linus Torvalds Subject: [patch RFC 4/5] x86/cpufeatures: Detect Speculation control feature References: <20180110010652.404145126@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Disposition: inline; filename=x86-feature--Detect_the_x86_IBRS_feature_to_control_Speculation.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: From: Tim Chen CPUs can expose a MSR to control speculation. The initial function of this MSR is to control Indirect Branch Speculation, which is required to mitigate the Spectre_V2 attack on certain CPU generations. If CPUID(7).RDX[26] is set then MSR_IA32_SPEC_CTRL (0x48) is available and bit 0 of that MSR controls whether Indirect Branch Speculation is restricted or not. The control bit is named IBRS (Indirect Branch Restricted Speculation). The IBSR bit can be unconditionally set to 1 without clearing it before. If IBRS is set, near returns and near indirect jumps/calls will not allow their predicted target address to be controlled by code that executed in a less privileged prediction mode before the IBRS mode was last written with a value of 1 or on another logical processor so long as all Return Stack Buffer (RSB) entries from the previous less privileged prediction mode are overwritten. Thus a near indirect jump/call/return may be affected by code in a less privileged prediction mode that executed AFTER IBRS mode was last written with a value of 1. Code executed by a sibling logical processor cannot control indirect jump/call/return predicted target when IBRS is set IBRS is not required in order to isolate branch predictions for SMM or SGX enclaves. Enabling IBRS can cause a measurable and depending on the workload significant CPU performance penalty. [ tglx: Steam blastered changelog ] Signed-off-by: Tim Chen Signed-off-by: Thomas Gleixner Cc: Andrea Arcangeli Cc: Andi Kleen Cc: Greg KH Cc: Dave Hansen Cc: Andy Lutomirski Cc: Arjan Van De Ven Cc: Linus Torvalds Cc: David Woodhouse --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 4 ++++ arch/x86/kernel/cpu/scattered.c | 1 + 3 files changed, 6 insertions(+) --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -211,6 +211,7 @@ #define X86_FEATURE_AVX512_4FMAPS ( 7*32+17) /* AVX-512 Multiply Accumulation Single precision */ #define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */ +#define X86_FEATURE_SPEC_CTRL ( 7*32+19) /* Speculation Control */ /* Virtualization flags: Linux defined, word 8 */ #define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */ --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -42,6 +42,10 @@ #define MSR_PPIN_CTL 0x0000004e #define MSR_PPIN 0x0000004f +#define MSR_IA32_SPEC_CTRL 0x00000048 +#define SPEC_CTRL_DISABLE_IBRS (0UL << 0) +#define SPEC_CTRL_ENABLE_IBRS (1UL << 0) + #define MSR_IA32_PERFCTR0 0x000000c1 #define MSR_IA32_PERFCTR1 0x000000c2 #define MSR_FSB_FREQ 0x000000cd --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -24,6 +24,7 @@ static const struct cpuid_bit cpuid_bits { X86_FEATURE_INTEL_PT, CPUID_EBX, 25, 0x00000007, 0 }, { X86_FEATURE_AVX512_4VNNIW, CPUID_EDX, 2, 0x00000007, 0 }, { X86_FEATURE_AVX512_4FMAPS, CPUID_EDX, 3, 0x00000007, 0 }, + { X86_FEATURE_SPEC_CTRL, CPUID_EDX, 26, 0x00000007, 0 }, { X86_FEATURE_CAT_L3, CPUID_EBX, 1, 0x00000010, 0 }, { X86_FEATURE_CAT_L2, CPUID_EBX, 2, 0x00000010, 0 }, { X86_FEATURE_CDP_L3, CPUID_ECX, 2, 0x00000010, 1 },