Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760253AbeAISGA (ORCPT + 1 other); Tue, 9 Jan 2018 13:06:00 -0500 Received: from mga03.intel.com ([134.134.136.65]:22737 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755932AbeAISF7 (ORCPT ); Tue, 9 Jan 2018 13:05:59 -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,336,1511856000"; d="scan'208";a="19611286" Subject: Re: [PATCH v2 4/8] x86/spec_ctrl: Add sysctl knobs to enable/disable SPEC_CTRL feature To: Borislav Petkov 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 References: <20180109002943.vdcjeubkflnccmup@pd.tnic> From: Tim Chen Message-ID: <6a9ff9c1-4d62-579b-9764-aa9d37260273@linux.intel.com> Date: Tue, 9 Jan 2018 10:05:57 -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: <20180109002943.vdcjeubkflnccmup@pd.tnic> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 01/08/2018 04:29 PM, Borislav Petkov wrote: > On Fri, Jan 05, 2018 at 06:12:19PM -0800, Tim Chen wrote: >> From: Tim Chen >> From: Andrea Arcangeli > > There's Co-Developed-by for this: > > - Co-Developed-by: states that the patch was also created by another developer > along with the original author. This is useful at times when multiple > people work on a single patch. Note, this person also needs to have a > Signed-off-by: line in the patch as well. > Thanks. Will do. >> .Lskip_\@: >> + lfence >> +.Ldone_\@: >> .endm > > Why not put all macros in spec_ctrl.h ? There were a previous discussion thread in v1 patch with Peter Z and Dave. Peter and Dave prefer that all these entrance macros be consolidated in calling.h > >> diff --git a/arch/x86/include/asm/spec_ctrl.h b/arch/x86/include/asm/spec_ctrl.h >> new file mode 100644 >> index 0000000..4fda38b >> --- /dev/null >> +++ b/arch/x86/include/asm/spec_ctrl.h >> @@ -0,0 +1,15 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> + >> +#ifndef _ASM_X86_SPEC_CTRL_H >> +#define _ASM_X86_SPEC_CTRL_H >> + >> +#include >> +#include >> +#include > > Left over include from a previous version. > > Instead, you need > > #include > > in spec_ctrl.c for get/put_online_cpus(). > >> +void scan_spec_ctrl_feature(struct cpuinfo_x86 *c); >> +bool ibrs_inuse(void); >> + >> +extern unsigned int dynamic_ibrs; >> + >> +#endif /* _ASM_X86_SPEC_CTRL_H */ >> diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile >> index 570e8bb..3ffbd24 100644 >> --- a/arch/x86/kernel/cpu/Makefile >> +++ b/arch/x86/kernel/cpu/Makefile >> @@ -24,6 +24,7 @@ obj-y += match.o >> obj-y += bugs.o >> obj-y += aperfmperf.o >> obj-y += cpuid-deps.o >> +obj-y += spec_ctrl.o >> >> obj-$(CONFIG_PROC_FS) += proc.o >> obj-$(CONFIG_X86_FEATURE_NAMES) += capflags.o powerflags.o >> diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c >> index bc50c40..5756d14 100644 >> --- a/arch/x86/kernel/cpu/scattered.c >> +++ b/arch/x86/kernel/cpu/scattered.c >> @@ -8,6 +8,7 @@ >> #include >> >> #include >> +#include >> >> struct cpuid_bit { >> u16 feature; >> @@ -57,6 +58,7 @@ void init_scattered_cpuid_features(struct cpuinfo_x86 *c) >> if (regs[cb->reg] & (1 << cb->bit)) >> set_cpu_cap(c, cb->feature); >> } >> + scan_spec_ctrl_feature(c); > > Hell no! > > This function is only for setting the feature bits. > >> u32 get_scattered_cpuid_leaf(unsigned int level, unsigned int sub_leaf, >> diff --git a/arch/x86/kernel/cpu/spec_ctrl.c b/arch/x86/kernel/cpu/spec_ctrl.c >> new file mode 100644 >> index 0000000..1641bec >> --- /dev/null >> +++ b/arch/x86/kernel/cpu/spec_ctrl.c >> @@ -0,0 +1,160 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> + >> +#include >> +#include >> +#include >> + >> +#include >> +#include >> + >> +unsigned int dynamic_ibrs __read_mostly; > > WTH is dynamic_ibrs? Dynamic ibrs because we enable the IBRS in MSR 0x48 entering the kernel and disable it when we exit the kernel. > >> +EXPORT_SYMBOL_GPL(dynamic_ibrs); >> + >> +enum { >> + IBRS_DISABLED, >> + /* in host kernel, disabled in guest and userland */ >> + IBRS_ENABLED, >> + /* in host kernel and host userland, disabled in guest */ >> + IBRS_ENABLED_USER, >> + IBRS_MAX = IBRS_ENABLED_USER, >> +}; >> +static unsigned int ibrs_enabled; >> +static bool ibrs_admin_disabled; > > Srsly?! > > That's *three* variables controlling IBRS. This needs simplification. > >> + >> +/* mutex to serialize IBRS control changes */ >> +DEFINE_MUTEX(spec_ctrl_mutex); > > static > >> +void scan_spec_ctrl_feature(struct cpuinfo_x86 *c) >> +{ >> + if ((!c->cpu_index) && (boot_cpu_has(X86_FEATURE_SPEC_CTRL))) { > > What is !c->cpu_index? Checking whether this is the BSP? What for? This is to ensure that we only do the operation once during boot. Thanks. Tim