Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753545AbeADWvj (ORCPT + 1 other); Thu, 4 Jan 2018 17:51:39 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:49114 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752713AbeADWvi (ORCPT ); Thu, 4 Jan 2018 17:51:38 -0500 Date: Thu, 4 Jan 2018 23:51:27 +0100 From: Peter Zijlstra To: Tim Chen Cc: Thomas Gleixner , Andy Lutomirski , Linus Torvalds , Greg KH , Dave Hansen , Andrea Arcangeli , Andi Kleen , Arjan Van De Ven , linux-kernel@vger.kernel.org, David Woodhouse Subject: Re: [PATCH 5/7] x86: Use IBRS for firmware update path Message-ID: <20180104225127.GF32035@hirez.programming.kicks-ass.net> References: <8d3710432534b27d224283557c4629cd1aa5b0ea.1515086770.git.tim.c.chen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8d3710432534b27d224283557c4629cd1aa5b0ea.1515086770.git.tim.c.chen@linux.intel.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Thu, Jan 04, 2018 at 09:56:46AM -0800, Tim Chen wrote: > diff --git a/arch/x86/include/asm/spec_ctrl.h b/arch/x86/include/asm/spec_ctrl.h > index 28b0314..23b2804 100644 > --- a/arch/x86/include/asm/spec_ctrl.h > +++ b/arch/x86/include/asm/spec_ctrl.h > @@ -113,5 +113,42 @@ static inline void unprotected_speculation_end(void) > rmb(); > } > > + > +#if defined(RETPOLINE) > +/* > + * RETPOLINE does not protect against indirect speculation > + * in firmware code. Enable IBRS to protect firmware execution. > + */ > +static inline void unprotected_firmware_begin(void) > +{ > + if (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) > + __disable_indirect_speculation(); > + else > + /* > + * If we intended to disable indirect speculation > + * but come here due to mis-speculation, we need > + * to stop the mis-speculation with rmb. > + */ > + rmb(); > +} Looks like an exact replica of unprotected_speculation_end() we're going for max linecount or something? > + > +static inline void unprotected_firmware_end(void) > +{ > + if (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) > + __enable_indirect_speculation(); > +} > + > +#else > +static inline void unprotected_firmware_begin(void) > +{ > + return; > +} > + > +static inline void unprotected_firmware_end(void) > +{ > + return; > +} Those return's are superfluous. > +#endif > + > #endif /* __ASSEMBLY__ */ > #endif /* _ASM_X86_SPEC_CTRL_H */ > -- > 2.9.4 >