]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-4.4/x86-speculation-prepare-arch_smt_update-for-prctl-mode.patch
4.4-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.4 / x86-speculation-prepare-arch_smt_update-for-prctl-mode.patch
CommitLineData
1f91e7a4
GKH
1From foo@baz Tue 14 May 2019 08:29:35 PM CEST
2From: Thomas Gleixner <tglx@linutronix.de>
3Date: Sun, 25 Nov 2018 19:33:52 +0100
4Subject: x86/speculation: Prepare arch_smt_update() for PRCTL mode
5
6From: Thomas Gleixner <tglx@linutronix.de>
7
8commit 6893a959d7fdebbab5f5aa112c277d5a44435ba1 upstream.
9
10The upcoming fine grained per task STIBP control needs to be updated on CPU
11hotplug as well.
12
13Split out the code which controls the strict mode so the prctl control code
14can be added later. Mark the SMP function call argument __unused while at it.
15
16Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
17Reviewed-by: Ingo Molnar <mingo@kernel.org>
18Cc: Peter Zijlstra <peterz@infradead.org>
19Cc: Andy Lutomirski <luto@kernel.org>
20Cc: Linus Torvalds <torvalds@linux-foundation.org>
21Cc: Jiri Kosina <jkosina@suse.cz>
22Cc: Tom Lendacky <thomas.lendacky@amd.com>
23Cc: Josh Poimboeuf <jpoimboe@redhat.com>
24Cc: Andrea Arcangeli <aarcange@redhat.com>
25Cc: David Woodhouse <dwmw@amazon.co.uk>
26Cc: Tim Chen <tim.c.chen@linux.intel.com>
27Cc: Andi Kleen <ak@linux.intel.com>
28Cc: Dave Hansen <dave.hansen@intel.com>
29Cc: Casey Schaufler <casey.schaufler@intel.com>
30Cc: Asit Mallick <asit.k.mallick@intel.com>
31Cc: Arjan van de Ven <arjan@linux.intel.com>
32Cc: Jon Masters <jcm@redhat.com>
33Cc: Waiman Long <longman9394@gmail.com>
34Cc: Greg KH <gregkh@linuxfoundation.org>
35Cc: Dave Stewart <david.c.stewart@intel.com>
36Cc: Kees Cook <keescook@chromium.org>
37Link: https://lkml.kernel.org/r/20181125185005.759457117@linutronix.de
38Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
39Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
40---
41 arch/x86/kernel/cpu/bugs.c | 46 ++++++++++++++++++++++++---------------------
42 1 file changed, 25 insertions(+), 21 deletions(-)
43
44--- a/arch/x86/kernel/cpu/bugs.c
45+++ b/arch/x86/kernel/cpu/bugs.c
46@@ -525,40 +525,44 @@ specv2_set_mode:
47 arch_smt_update();
48 }
49
50-static bool stibp_needed(void)
51+static void update_stibp_msr(void * __unused)
52 {
53- /* Enhanced IBRS makes using STIBP unnecessary. */
54- if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
55- return false;
56-
57- /* Check for strict user mitigation mode */
58- return spectre_v2_user == SPECTRE_V2_USER_STRICT;
59+ wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
60 }
61
62-static void update_stibp_msr(void *info)
63+/* Update x86_spec_ctrl_base in case SMT state changed. */
64+static void update_stibp_strict(void)
65 {
66- wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
67+ u64 mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP;
68+
69+ if (sched_smt_active())
70+ mask |= SPEC_CTRL_STIBP;
71+
72+ if (mask == x86_spec_ctrl_base)
73+ return;
74+
75+ pr_info("Update user space SMT mitigation: STIBP %s\n",
76+ mask & SPEC_CTRL_STIBP ? "always-on" : "off");
77+ x86_spec_ctrl_base = mask;
78+ on_each_cpu(update_stibp_msr, NULL, 1);
79 }
80
81 void arch_smt_update(void)
82 {
83- u64 mask;
84-
85- if (!stibp_needed())
86+ /* Enhanced IBRS implies STIBP. No update required. */
87+ if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
88 return;
89
90 mutex_lock(&spec_ctrl_mutex);
91
92- mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP;
93- if (sched_smt_active())
94- mask |= SPEC_CTRL_STIBP;
95-
96- if (mask != x86_spec_ctrl_base) {
97- pr_info("Spectre v2 cross-process SMT mitigation: %s STIBP\n",
98- mask & SPEC_CTRL_STIBP ? "Enabling" : "Disabling");
99- x86_spec_ctrl_base = mask;
100- on_each_cpu(update_stibp_msr, NULL, 1);
101+ switch (spectre_v2_user) {
102+ case SPECTRE_V2_USER_NONE:
103+ break;
104+ case SPECTRE_V2_USER_STRICT:
105+ update_stibp_strict();
106+ break;
107 }
108+
109 mutex_unlock(&spec_ctrl_mutex);
110 }
111