Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758690AbeAIAfF (ORCPT + 1 other); Mon, 8 Jan 2018 19:35:05 -0500 Received: from mail.skyhub.de ([5.9.137.197]:39094 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758675AbeAIAfE (ORCPT ); Mon, 8 Jan 2018 19:35:04 -0500 Date: Tue, 9 Jan 2018 01:34:54 +0100 From: Borislav Petkov To: Tim Chen Cc: Thomas Gleixner , Andy Lutomirski , Linus Torvalds , Greg KH , Dave Hansen , Andrea Arcangeli , Andi Kleen , Arjan Van De Ven , David Woodhouse , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 6/8] x86/microcode: Recheck IBRS features on microcode reload Message-ID: <20180109003453.ht5bxgp2mhubgsxv@pd.tnic> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Fri, Jan 05, 2018 at 06:12:21PM -0800, Tim Chen wrote: > On new microcode write, check whether IBRS > is present by rescanning IBRS feature. > > Signed-off-by: Tim Chen > --- > arch/x86/include/asm/spec_ctrl.h | 1 + > arch/x86/kernel/cpu/microcode/core.c | 4 ++++ > arch/x86/kernel/cpu/spec_ctrl.c | 18 ++++++++++-------- > 3 files changed, 15 insertions(+), 8 deletions(-) > > diff --git a/arch/x86/include/asm/spec_ctrl.h b/arch/x86/include/asm/spec_ctrl.h > index 62c5dc8..be08ae7 100644 > --- a/arch/x86/include/asm/spec_ctrl.h > +++ b/arch/x86/include/asm/spec_ctrl.h > @@ -8,6 +8,7 @@ > #include > > void scan_spec_ctrl_feature(struct cpuinfo_x86 *c); > +void rescan_spec_ctrl_feature(struct cpuinfo_x86 *c); > bool ibrs_inuse(void); > > extern unsigned int dynamic_ibrs; > diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c > index c4fa4a8..848c3e9 100644 > --- a/arch/x86/kernel/cpu/microcode/core.c > +++ b/arch/x86/kernel/cpu/microcode/core.c > @@ -40,6 +40,7 @@ > #include > #include > #include > +#include > > #define DRIVER_VERSION "2.2" > > @@ -444,6 +445,9 @@ static ssize_t microcode_write(struct file *file, const char __user *buf, > if (ret > 0) > perf_check_microcode(); > > + /* check spec_ctrl capabilities */ > + rescan_spec_ctrl_feature(&boot_cpu_data); Needs to be under the if like perf_check_microcode(). > + > mutex_unlock(µcode_mutex); > put_online_cpus(); > > diff --git a/arch/x86/kernel/cpu/spec_ctrl.c b/arch/x86/kernel/cpu/spec_ctrl.c > index 1641bec..28107a2 100644 > --- a/arch/x86/kernel/cpu/spec_ctrl.c > +++ b/arch/x86/kernel/cpu/spec_ctrl.c > @@ -24,13 +24,18 @@ static bool ibrs_admin_disabled; > /* mutex to serialize IBRS control changes */ > DEFINE_MUTEX(spec_ctrl_mutex); > > +static inline void set_ibrs_feature(void) > +{ > + if (!ibrs_admin_disabled) { > + dynamic_ibrs = 1; > + ibrs_enabled = IBRS_ENABLED; > + } > +} > + > void scan_spec_ctrl_feature(struct cpuinfo_x86 *c) > { > if ((!c->cpu_index) && (boot_cpu_has(X86_FEATURE_SPEC_CTRL))) { > - if (!ibrs_admin_disabled) { > - dynamic_ibrs = 1; > - ibrs_enabled = IBRS_ENABLED; > - } > + set_ibrs_feature(); > } > } > EXPORT_SYMBOL_GPL(scan_spec_ctrl_feature); > @@ -43,10 +48,7 @@ void rescan_spec_ctrl_feature(struct cpuinfo_x86 *c) > { > mutex_lock(&spec_ctrl_mutex); > if (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) { > - if (!ibrs_admin_disabled) { > - dynamic_ibrs = 1; > - ibrs_enabled = IBRS_ENABLED; > - } > + set_ibrs_feature(); As already stated, this does not work. You want to check the CPUID leaf after the microcode reload and then set X86_FEATURE_SPEC_CTRL on each CPU. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.