]>
Commit | Line | Data |
---|---|---|
1f91e7a4 GKH |
1 | From foo@baz Tue 14 May 2019 08:29:35 PM CEST |
2 | From: Thomas Gleixner <tglx@linutronix.de> | |
3 | Date: Sun, 25 Nov 2018 19:33:52 +0100 | |
4 | Subject: x86/speculation: Prepare arch_smt_update() for PRCTL mode | |
5 | ||
6 | From: Thomas Gleixner <tglx@linutronix.de> | |
7 | ||
8 | commit 6893a959d7fdebbab5f5aa112c277d5a44435ba1 upstream. | |
9 | ||
10 | The upcoming fine grained per task STIBP control needs to be updated on CPU | |
11 | hotplug as well. | |
12 | ||
13 | Split out the code which controls the strict mode so the prctl control code | |
14 | can be added later. Mark the SMP function call argument __unused while at it. | |
15 | ||
16 | Signed-off-by: Thomas Gleixner <tglx@linutronix.de> | |
17 | Reviewed-by: Ingo Molnar <mingo@kernel.org> | |
18 | Cc: Peter Zijlstra <peterz@infradead.org> | |
19 | Cc: Andy Lutomirski <luto@kernel.org> | |
20 | Cc: Linus Torvalds <torvalds@linux-foundation.org> | |
21 | Cc: Jiri Kosina <jkosina@suse.cz> | |
22 | Cc: Tom Lendacky <thomas.lendacky@amd.com> | |
23 | Cc: Josh Poimboeuf <jpoimboe@redhat.com> | |
24 | Cc: Andrea Arcangeli <aarcange@redhat.com> | |
25 | Cc: David Woodhouse <dwmw@amazon.co.uk> | |
26 | Cc: Tim Chen <tim.c.chen@linux.intel.com> | |
27 | Cc: Andi Kleen <ak@linux.intel.com> | |
28 | Cc: Dave Hansen <dave.hansen@intel.com> | |
29 | Cc: Casey Schaufler <casey.schaufler@intel.com> | |
30 | Cc: Asit Mallick <asit.k.mallick@intel.com> | |
31 | Cc: Arjan van de Ven <arjan@linux.intel.com> | |
32 | Cc: Jon Masters <jcm@redhat.com> | |
33 | Cc: Waiman Long <longman9394@gmail.com> | |
34 | Cc: Greg KH <gregkh@linuxfoundation.org> | |
35 | Cc: Dave Stewart <david.c.stewart@intel.com> | |
36 | Cc: Kees Cook <keescook@chromium.org> | |
37 | Link: https://lkml.kernel.org/r/20181125185005.759457117@linutronix.de | |
38 | Signed-off-by: Ben Hutchings <ben@decadent.org.uk> | |
39 | Signed-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 |