From: Tim Chen <tim.c.chen@linux.intel.com>
To: Jiri Kosina <jikos@kernel.org>, Thomas Gleixner <tglx@linutronix.de>
Cc: Tim Chen <tim.c.chen@linux.intel.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Tom Lendacky <thomas.lendacky@amd.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Andrea Arcangeli <aarcange@redhat.com>,
David Woodhouse <dwmw@amazon.co.uk>,
Andi Kleen <ak@linux.intel.com>,
Dave Hansen <dave.hansen@intel.com>,
Casey Schaufler <casey.schaufler@intel.com>,
Asit Mallick <asit.k.mallick@intel.com>,
Arjan van de Ven <arjan@linux.intel.com>,
Jon Masters <jcm@redhat.com>, Waiman Long <longman9394@gmail.com>,
Greg KH <gregkh@linuxfoundation.org>,
Dave Stewart <david.c.stewart@intel.com>,
linux-kernel@vger.kernel.org, x86@kernel.org,
stable@vger.kernel.org
Subject: [Patch v6 07/16] x86/smt: Convert cpu_smt_control check to cpu_smt_enabled static key
Date: Tue, 20 Nov 2018 15:59:59 -0800 [thread overview]
Message-ID: <d928244ca07ab3cc3a9858dbfc11d5d6e2c5f683.1542757030.git.tim.c.chen@linux.intel.com> (raw)
In-Reply-To: <cover.1542757030.git.tim.c.chen@linux.intel.com>
In-Reply-To: <cover.1542757030.git.tim.c.chen@linux.intel.com>
The checks to cpu_smt_control outside of kernel/cpu.c can be converted
to use cpu_smt_enabled key to run SMT specific code.
Save the export of cpu_smt_control and convert usage of cpu_smt_control
to cpu_smt_enabled outside of kernel/cpu.c.
Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
---
arch/x86/kernel/cpu/bugs.c | 13 +++++++------
arch/x86/kvm/vmx.c | 2 +-
include/linux/cpu.h | 12 +++---------
kernel/cpu.c | 11 +++++++++--
4 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index a63456a..3e5ae2c 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -353,15 +353,16 @@ void arch_smt_update(void)
mutex_lock(&spec_ctrl_mutex);
mask = x86_spec_ctrl_base;
- if (cpu_smt_control == CPU_SMT_ENABLED)
+ if (cpu_use_smt_and_hotplug)
mask |= SPEC_CTRL_STIBP;
else
mask &= ~SPEC_CTRL_STIBP;
if (mask != x86_spec_ctrl_base) {
- pr_info("Spectre v2 cross-process SMT mitigation: %s STIBP\n",
- cpu_smt_control == CPU_SMT_ENABLED ?
- "Enabling" : "Disabling");
+ if (cpu_use_smt_and_hotplug)
+ pr_info("Spectre v2 cross-process SMT mitigation: Enabling STIBP\n");
+ else
+ pr_info("Spectre v2 cross-process SMT mitigation: Disabling STIBP\n");
x86_spec_ctrl_base = mask;
on_each_cpu(update_stibp_msr, NULL, 1);
}
@@ -844,13 +845,13 @@ static ssize_t l1tf_show_state(char *buf)
if (l1tf_vmx_mitigation == VMENTER_L1D_FLUSH_EPT_DISABLED ||
(l1tf_vmx_mitigation == VMENTER_L1D_FLUSH_NEVER &&
- cpu_smt_control == CPU_SMT_ENABLED))
+ cpu_use_smt_and_hotplug))
return sprintf(buf, "%s; VMX: %s\n", L1TF_DEFAULT_MSG,
l1tf_vmx_states[l1tf_vmx_mitigation]);
return sprintf(buf, "%s; VMX: %s, SMT %s\n", L1TF_DEFAULT_MSG,
l1tf_vmx_states[l1tf_vmx_mitigation],
- cpu_smt_control == CPU_SMT_ENABLED ? "vulnerable" : "disabled");
+ cpu_use_smt_and_hotplug ? "vulnerable" : "disabled");
}
#else
static ssize_t l1tf_show_state(char *buf)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 4555077..6c71d4c 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -11607,7 +11607,7 @@ static int vmx_vm_init(struct kvm *kvm)
* Warn upon starting the first VM in a potentially
* insecure environment.
*/
- if (cpu_smt_control == CPU_SMT_ENABLED)
+ if (cpu_use_smt_and_hotplug)
pr_warn_once(L1TF_MSG_SMT);
if (l1tf_vmx_mitigation == VMENTER_L1D_FLUSH_NEVER)
pr_warn_once(L1TF_MSG_L1D);
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index ce8267e..6f43024 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -170,20 +170,14 @@ void cpuhp_report_idle_dead(void);
static inline void cpuhp_report_idle_dead(void) { }
#endif /* #ifdef CONFIG_HOTPLUG_CPU */
-enum cpuhp_smt_control {
- CPU_SMT_ENABLED,
- CPU_SMT_DISABLED,
- CPU_SMT_FORCE_DISABLED,
- CPU_SMT_NOT_SUPPORTED,
-};
-
#if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT)
-extern enum cpuhp_smt_control cpu_smt_control;
+DECLARE_STATIC_KEY_TRUE(cpu_smt_enabled);
+#define cpu_use_smt_and_hotplug (static_branch_likely(&cpu_smt_enabled))
extern void cpu_smt_disable(bool force);
extern void cpu_smt_check_topology_early(void);
extern void cpu_smt_check_topology(void);
#else
-# define cpu_smt_control (CPU_SMT_ENABLED)
+#define cpu_use_smt_and_hotplug false
static inline void cpu_smt_disable(bool force) { }
static inline void cpu_smt_check_topology_early(void) { }
static inline void cpu_smt_check_topology(void) { }
diff --git a/kernel/cpu.c b/kernel/cpu.c
index e216154..f846416 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -368,8 +368,15 @@ static void lockdep_release_cpus_lock(void)
#endif /* CONFIG_HOTPLUG_CPU */
#ifdef CONFIG_HOTPLUG_SMT
-enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
-EXPORT_SYMBOL_GPL(cpu_smt_control);
+
+enum cpuhp_smt_control {
+ CPU_SMT_ENABLED,
+ CPU_SMT_DISABLED,
+ CPU_SMT_FORCE_DISABLED,
+ CPU_SMT_NOT_SUPPORTED,
+};
+
+static enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
DEFINE_STATIC_KEY_TRUE(cpu_smt_enabled);
EXPORT_SYMBOL_GPL(cpu_smt_enabled);
--
2.9.4
next prev parent reply other threads:[~2018-11-21 0:34 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-20 23:59 [Patch v6 00/16] Provide task property based options to enable Spectre v2 userspace-userspace protection Tim Chen
2018-11-20 23:59 ` [Patch v6 01/16] x86/speculation: Reorganize cpu_show_common() Tim Chen
2018-11-20 23:59 ` [Patch v6 02/16] x86/speculation: Add X86_FEATURE_USE_IBRS_ENHANCED Tim Chen
2018-11-20 23:59 ` [Patch v6 03/16] x86/speculation: Disable STIBP when enhanced IBRS is in use Tim Chen
2018-11-20 23:59 ` [Patch v6 04/16] x86/speculation: Rename SSBD update functions Tim Chen
2018-11-20 23:59 ` [Patch v6 05/16] x86/speculation: Reorganize speculation control MSRs update Tim Chen
2018-11-20 23:59 ` [Patch v6 06/16] smt: Create cpu_smt_enabled static key for SMT specific code Tim Chen
2018-11-20 23:59 ` Tim Chen [this message]
2018-11-21 0:00 ` [Patch v6 08/16] x86/speculation: Turn on or off STIBP according to a task's TIF_STIBP Tim Chen
2018-11-21 0:00 ` [Patch v6 09/16] x86/speculation: Add Spectre v2 app to app protection modes Tim Chen
2018-11-21 0:00 ` [Patch v6 10/16] x86/speculation: Create PRCTL interface to restrict indirect branch speculation Tim Chen
2018-11-21 0:00 ` [Patch v6 11/16] x86/speculation: Enable IBPB for tasks with TIF_SPEC_BRANCH_SPECULATION Tim Chen
2018-11-21 0:00 ` [Patch v6 12/16] x86/speculation: Add 'seccomp' Spectre v2 app to app protection mode Tim Chen
2018-11-21 0:44 ` Jiri Kosina
2018-11-21 0:54 ` Tim Chen
2018-11-21 0:00 ` [Patch v6 13/16] security: Update speculation restriction of a process when modifying its dumpability Tim Chen
2018-11-21 0:00 ` [Patch v6 14/16] x86/speculation: Use STIBP to restrict speculation on non-dumpable task Tim Chen
2018-11-21 1:27 ` Linus Torvalds
2018-11-21 6:14 ` Jiri Kosina
2018-11-21 17:41 ` Tim Chen
2018-11-21 19:32 ` Linus Torvalds
2018-11-21 20:07 ` Dave Hansen
2018-11-21 20:26 ` Linus Torvalds
2018-11-21 0:00 ` [Patch v6 15/16] sched/smt: Make sched_smt_present track topology Tim Chen
2018-11-21 0:00 ` [Patch v6 16/16] x86/smt: Allow disabling of SMT when last SMT is offlined Tim Chen
2018-11-21 0:44 ` [Patch v6 00/16] Provide task property based options to enable Spectre v2 userspace-userspace protection Tim Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d928244ca07ab3cc3a9858dbfc11d5d6e2c5f683.1542757030.git.tim.c.chen@linux.intel.com \
--to=tim.c.chen@linux.intel.com \
--cc=aarcange@redhat.com \
--cc=ak@linux.intel.com \
--cc=arjan@linux.intel.com \
--cc=asit.k.mallick@intel.com \
--cc=casey.schaufler@intel.com \
--cc=dave.hansen@intel.com \
--cc=david.c.stewart@intel.com \
--cc=dwmw@amazon.co.uk \
--cc=gregkh@linuxfoundation.org \
--cc=jcm@redhat.com \
--cc=jikos@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman9394@gmail.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).