Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932783AbeALC2k (ORCPT + 1 other); Thu, 11 Jan 2018 21:28:40 -0500 Received: from out01.mta.xmission.com ([166.70.13.231]:42450 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932500AbeALC2i (ORCPT ); Thu, 11 Jan 2018 21:28:38 -0500 From: ebiederm@xmission.com (Eric W. Biederman) To: Dan Williams Cc: linux-kernel@vger.kernel.org, Mark Rutland , Tom Lendacky , linux-arch@vger.kernel.org, Greg KH , Peter Zijlstra , Alan Cox , x86@kernel.org, Ingo Molnar , "H. Peter Anvin" , kernel-hardening@lists.openwall.com, tglx@linutronix.de, torvalds@linux-foundation.org, akpm@linux-foundation.org, Elena Reshetova , alan@linux.intel.com References: <151571798296.27429.7166552848688034184.stgit@dwillia2-desk3.amr.corp.intel.com> <151571800589.27429.13615996439124092232.stgit@dwillia2-desk3.amr.corp.intel.com> Date: Thu, 11 Jan 2018 20:27:45 -0600 In-Reply-To: <151571800589.27429.13615996439124092232.stgit@dwillia2-desk3.amr.corp.intel.com> (Dan Williams's message of "Thu, 11 Jan 2018 16:46:45 -0800") Message-ID: <87efmv4xr2.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1eZp56-0006w9-I1;;;mid=<87efmv4xr2.fsf@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=97.121.73.102;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19sLZ1Rm8VDewVqKjjEfM3QTDz5vbvhcIY= X-SA-Exim-Connect-IP: 97.121.73.102 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH v2 04/19] x86: implement ifence() X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Dan Williams writes: > The new barrier, 'ifence', ensures that no instructions past the > boundary are speculatively executed. This needs a much better description. If that description was valid we could add ifence in the syscall entry path and not have any speculative execution to worry about in the kernel. Perhaps: 'ifence', ensures that no speculative execution that reaches the 'ifence' boundary continues past the 'ifence' boundary. > Previously the kernel only needed this fence in 'rdtsc_ordered', but it > can also be used as a mitigation against Spectre variant1 attacks that > speculative access memory past an array bounds check. > > 'ifence', via 'ifence_array_ptr', is an opt-in fallback to the default > mitigation provided by '__array_ptr'. It is also proposed for blocking > speculation in the 'get_user' path to bypass 'access_ok' checks. For > now, just provide the common definition for later patches to build > upon. This part of the description is probably unnecessary. Eric > > Suggested-by: Peter Zijlstra > Suggested-by: Alan Cox > Cc: Tom Lendacky > Cc: Mark Rutland > Cc: Greg KH > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: "H. Peter Anvin" > Cc: x86@kernel.org > Signed-off-by: Elena Reshetova > Signed-off-by: Dan Williams > --- > arch/x86/include/asm/barrier.h | 4 ++++ > arch/x86/include/asm/msr.h | 3 +-- > 2 files changed, 5 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h > index 7fb336210e1b..b04f572d6d97 100644 > --- a/arch/x86/include/asm/barrier.h > +++ b/arch/x86/include/asm/barrier.h > @@ -24,6 +24,10 @@ > #define wmb() asm volatile("sfence" ::: "memory") > #endif > > +/* prevent speculative execution past this barrier */ > +#define ifence() alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC, \ > + "lfence", X86_FEATURE_LFENCE_RDTSC) > + > #ifdef CONFIG_X86_PPRO_FENCE > #define dma_rmb() rmb() > #else > diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h > index 07962f5f6fba..e426d2a33ff3 100644 > --- a/arch/x86/include/asm/msr.h > +++ b/arch/x86/include/asm/msr.h > @@ -214,8 +214,7 @@ static __always_inline unsigned long long rdtsc_ordered(void) > * that some other imaginary CPU is updating continuously with a > * time stamp. > */ > - alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC, > - "lfence", X86_FEATURE_LFENCE_RDTSC); > + ifence(); > return rdtsc(); > } >