Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753089AbeADUrm (ORCPT + 1 other); Thu, 4 Jan 2018 15:47:42 -0500 Received: from mga02.intel.com ([134.134.136.20]:65176 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752544AbeADUrl (ORCPT ); Thu, 4 Jan 2018 15:47:41 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,315,1511856000"; d="scan'208";a="18273817" Subject: Re: [PATCH 1/7] x86/feature: Detect the x86 feature to control Speculation To: Greg KH Cc: Thomas Gleixner , Andy Lutomirski , Linus Torvalds , Dave Hansen , Andrea Arcangeli , Andi Kleen , Arjan Van De Ven , linux-kernel@vger.kernel.org References: <427aa76dea14532dea7e49f0bce4e7cf1dea7c6f.1515086770.git.tim.c.chen@linux.intel.com> <20180104195810.GA30228@kroah.com> From: Tim Chen Message-ID: <3ad75055-5075-8650-5744-a08aa5c0a1a2@linux.intel.com> Date: Thu, 4 Jan 2018 12:47:39 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: <20180104195810.GA30228@kroah.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 01/04/2018 11:58 AM, Greg KH wrote: > On Thu, Jan 04, 2018 at 09:56:42AM -0800, Tim Chen wrote: >> cpuid ax=0x7, return rdx bit 26 to indicate presence of this feature >> IA32_SPEC_CTRL (0x48) and IA32_PRED_CMD (0x49) >> IA32_SPEC_CTRL, bit0 – Indirect Branch Restricted Speculation (IBRS) >> IA32_PRED_CMD, bit0 – Indirect Branch Prediction Barrier (IBPB) >> >> 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 RSB entries from the previous less privileged prediction mode >> are overwritten. >> >> Setting of IBPB ensures that earlier code's behavior does not control later >> indirect branch predictions. It is used when context switching to new >> untrusted address space. Unlike IBRS, it is a command MSR and does not retain >> its state. >> >> * 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 >> >> * There is no need to clear IBRS before writing it with a value of >> 1. Unconditionally writing it with a value of 1 after the prediction >> mode change is sufficient >> >> * Note: IBRS is not required in order to isolate branch predictions for >> SMM or SGX enclaves >> >> * Code executed by a sibling logical processor cannot control indirect >> jump/call/return predicted target when IBRS is set >> >> * SMEP will prevent supervisor mode using RSB entries filled by user code; >> this can reduce the need for software to overwrite RSB entries >> >> * IBRS is not guaranteed to differentiate two applications that use >> the same CR3 due to recycling. Software can use an IBPB command when >> recycling a page table base address. >> >> * VMM software can similarly use an IBPB when recycling a controlling >> VMCS pointer address >> >> CPU performance could be reduced when running with IBRS set. >> >> Signed-off-by: Tim Chen >> --- >> arch/x86/include/asm/cpufeatures.h | 1 + >> arch/x86/include/asm/msr-index.h | 7 +++++++ >> arch/x86/kernel/cpu/scattered.c | 1 + >> 3 files changed, 9 insertions(+) >> >> diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h >> index 86c68cb..431f393 100644 >> --- a/arch/x86/include/asm/cpufeatures.h >> +++ b/arch/x86/include/asm/cpufeatures.h >> @@ -209,6 +209,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) /* Control Speculation Control */ >> >> /* Virtualization flags: Linux defined, word 8 */ >> #define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */ > > You should have gotten a build warning with just this patch, please also > update tools/arch/x86/include/asm/cpufeatures.h to fix that. Sorry about that. Trying to get this patchset posted quickly so I could have missed a few things. > > And why not use a free slot, (7*32+13) or (7*32+12) is free, right? > > Or were you just trying to make backports "easier"? :) > > There are future features related to speculation control. So putting it here so they can stay together. Tim