]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/x86-speculation-rework-smt-state-change.patch
4.4-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.4 / x86-speculation-rework-smt-state-change.patch
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:39 +0100
4 Subject: x86/speculation: Rework SMT state change
5
6 From: Thomas Gleixner <tglx@linutronix.de>
7
8 commit a74cfffb03b73d41e08f84c2e5c87dec0ce3db9f upstream.
9
10 arch_smt_update() is only called when the sysfs SMT control knob is
11 changed. This means that when SMT is enabled in the sysfs control knob the
12 system is considered to have SMT active even if all siblings are offline.
13
14 To allow finegrained control of the speculation mitigations, the actual SMT
15 state is more interesting than the fact that siblings could be enabled.
16
17 Rework the code, so arch_smt_update() is invoked from each individual CPU
18 hotplug function, and simplify the update function while at it.
19
20 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
21 Reviewed-by: Ingo Molnar <mingo@kernel.org>
22 Cc: Peter Zijlstra <peterz@infradead.org>
23 Cc: Andy Lutomirski <luto@kernel.org>
24 Cc: Linus Torvalds <torvalds@linux-foundation.org>
25 Cc: Jiri Kosina <jkosina@suse.cz>
26 Cc: Tom Lendacky <thomas.lendacky@amd.com>
27 Cc: Josh Poimboeuf <jpoimboe@redhat.com>
28 Cc: Andrea Arcangeli <aarcange@redhat.com>
29 Cc: David Woodhouse <dwmw@amazon.co.uk>
30 Cc: Tim Chen <tim.c.chen@linux.intel.com>
31 Cc: Andi Kleen <ak@linux.intel.com>
32 Cc: Dave Hansen <dave.hansen@intel.com>
33 Cc: Casey Schaufler <casey.schaufler@intel.com>
34 Cc: Asit Mallick <asit.k.mallick@intel.com>
35 Cc: Arjan van de Ven <arjan@linux.intel.com>
36 Cc: Jon Masters <jcm@redhat.com>
37 Cc: Waiman Long <longman9394@gmail.com>
38 Cc: Greg KH <gregkh@linuxfoundation.org>
39 Cc: Dave Stewart <david.c.stewart@intel.com>
40 Cc: Kees Cook <keescook@chromium.org>
41 Link: https://lkml.kernel.org/r/20181125185004.521974984@linutronix.de
42 [bwh: Backported to 4.4: adjust context]
43 Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
44 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
45 ---
46 arch/x86/kernel/cpu/bugs.c | 11 +++++------
47 include/linux/sched/smt.h | 2 ++
48 kernel/cpu.c | 10 +++++++++-
49 3 files changed, 16 insertions(+), 7 deletions(-)
50
51 --- a/arch/x86/kernel/cpu/bugs.c
52 +++ b/arch/x86/kernel/cpu/bugs.c
53 @@ -13,6 +13,7 @@
54 #include <linux/module.h>
55 #include <linux/nospec.h>
56 #include <linux/prctl.h>
57 +#include <linux/sched/smt.h>
58
59 #include <asm/spec-ctrl.h>
60 #include <asm/cmdline.h>
61 @@ -340,16 +341,14 @@ void arch_smt_update(void)
62 return;
63
64 mutex_lock(&spec_ctrl_mutex);
65 - mask = x86_spec_ctrl_base;
66 - if (IS_ENABLED(CONFIG_SMP))
67 +
68 + mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP;
69 + if (sched_smt_active())
70 mask |= SPEC_CTRL_STIBP;
71 - else
72 - mask &= ~SPEC_CTRL_STIBP;
73
74 if (mask != x86_spec_ctrl_base) {
75 pr_info("Spectre v2 cross-process SMT mitigation: %s STIBP\n",
76 - IS_ENABLED(CONFIG_SMP) ?
77 - "Enabling" : "Disabling");
78 + mask & SPEC_CTRL_STIBP ? "Enabling" : "Disabling");
79 x86_spec_ctrl_base = mask;
80 on_each_cpu(update_stibp_msr, NULL, 1);
81 }
82 --- a/include/linux/sched/smt.h
83 +++ b/include/linux/sched/smt.h
84 @@ -15,4 +15,6 @@ static __always_inline bool sched_smt_ac
85 static inline bool sched_smt_active(void) { return false; }
86 #endif
87
88 +void arch_smt_update(void);
89 +
90 #endif
91 --- a/kernel/cpu.c
92 +++ b/kernel/cpu.c
93 @@ -8,6 +8,7 @@
94 #include <linux/init.h>
95 #include <linux/notifier.h>
96 #include <linux/sched.h>
97 +#include <linux/sched/smt.h>
98 #include <linux/unistd.h>
99 #include <linux/cpu.h>
100 #include <linux/oom.h>
101 @@ -199,6 +200,12 @@ void cpu_hotplug_enable(void)
102 EXPORT_SYMBOL_GPL(cpu_hotplug_enable);
103 #endif /* CONFIG_HOTPLUG_CPU */
104
105 +/*
106 + * Architectures that need SMT-specific errata handling during SMT hotplug
107 + * should override this.
108 + */
109 +void __weak arch_smt_update(void) { }
110 +
111 /* Need to know about CPUs going up/down? */
112 int register_cpu_notifier(struct notifier_block *nb)
113 {
114 @@ -434,6 +441,7 @@ out_release:
115 cpu_hotplug_done();
116 if (!err)
117 cpu_notify_nofail(CPU_POST_DEAD | mod, hcpu);
118 + arch_smt_update();
119 return err;
120 }
121
122 @@ -537,7 +545,7 @@ out_notify:
123 __cpu_notify(CPU_UP_CANCELED | mod, hcpu, nr_calls, NULL);
124 out:
125 cpu_hotplug_done();
126 -
127 + arch_smt_update();
128 return ret;
129 }
130