]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/x86-speculation-split-out-tif-update.patch
4.4-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.4 / x86-speculation-split-out-tif-update.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:51 +0100
4 Subject: x86/speculation: Split out TIF update
5
6 From: Thomas Gleixner <tglx@linutronix.de>
7
8 commit e6da8bb6f9abb2628381904b24163c770e630bac upstream.
9
10 The update of the TIF_SSBD flag and the conditional speculation control MSR
11 update is done in the ssb_prctl_set() function directly. The upcoming prctl
12 support for controlling indirect branch speculation via STIBP needs the
13 same mechanism.
14
15 Split the code out and make it reusable. Reword the comment about updates
16 for other tasks.
17
18 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
19 Reviewed-by: Ingo Molnar <mingo@kernel.org>
20 Cc: Peter Zijlstra <peterz@infradead.org>
21 Cc: Andy Lutomirski <luto@kernel.org>
22 Cc: Linus Torvalds <torvalds@linux-foundation.org>
23 Cc: Jiri Kosina <jkosina@suse.cz>
24 Cc: Tom Lendacky <thomas.lendacky@amd.com>
25 Cc: Josh Poimboeuf <jpoimboe@redhat.com>
26 Cc: Andrea Arcangeli <aarcange@redhat.com>
27 Cc: David Woodhouse <dwmw@amazon.co.uk>
28 Cc: Tim Chen <tim.c.chen@linux.intel.com>
29 Cc: Andi Kleen <ak@linux.intel.com>
30 Cc: Dave Hansen <dave.hansen@intel.com>
31 Cc: Casey Schaufler <casey.schaufler@intel.com>
32 Cc: Asit Mallick <asit.k.mallick@intel.com>
33 Cc: Arjan van de Ven <arjan@linux.intel.com>
34 Cc: Jon Masters <jcm@redhat.com>
35 Cc: Waiman Long <longman9394@gmail.com>
36 Cc: Greg KH <gregkh@linuxfoundation.org>
37 Cc: Dave Stewart <david.c.stewart@intel.com>
38 Cc: Kees Cook <keescook@chromium.org>
39 Link: https://lkml.kernel.org/r/20181125185005.652305076@linutronix.de
40 Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
41 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
42 ---
43 arch/x86/kernel/cpu/bugs.c | 35 +++++++++++++++++++++++------------
44 1 file changed, 23 insertions(+), 12 deletions(-)
45
46 --- a/arch/x86/kernel/cpu/bugs.c
47 +++ b/arch/x86/kernel/cpu/bugs.c
48 @@ -697,10 +697,29 @@ static void ssb_select_mitigation(void)
49 #undef pr_fmt
50 #define pr_fmt(fmt) "Speculation prctl: " fmt
51
52 -static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl)
53 +static void task_update_spec_tif(struct task_struct *tsk, int tifbit, bool on)
54 {
55 bool update;
56
57 + if (on)
58 + update = !test_and_set_tsk_thread_flag(tsk, tifbit);
59 + else
60 + update = test_and_clear_tsk_thread_flag(tsk, tifbit);
61 +
62 + /*
63 + * Immediately update the speculation control MSRs for the current
64 + * task, but for a non-current task delay setting the CPU
65 + * mitigation until it is scheduled next.
66 + *
67 + * This can only happen for SECCOMP mitigation. For PRCTL it's
68 + * always the current task.
69 + */
70 + if (tsk == current && update)
71 + speculation_ctrl_update_current();
72 +}
73 +
74 +static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl)
75 +{
76 if (ssb_mode != SPEC_STORE_BYPASS_PRCTL &&
77 ssb_mode != SPEC_STORE_BYPASS_SECCOMP)
78 return -ENXIO;
79 @@ -711,28 +730,20 @@ static int ssb_prctl_set(struct task_str
80 if (task_spec_ssb_force_disable(task))
81 return -EPERM;
82 task_clear_spec_ssb_disable(task);
83 - update = test_and_clear_tsk_thread_flag(task, TIF_SSBD);
84 + task_update_spec_tif(task, TIF_SSBD, false);
85 break;
86 case PR_SPEC_DISABLE:
87 task_set_spec_ssb_disable(task);
88 - update = !test_and_set_tsk_thread_flag(task, TIF_SSBD);
89 + task_update_spec_tif(task, TIF_SSBD, true);
90 break;
91 case PR_SPEC_FORCE_DISABLE:
92 task_set_spec_ssb_disable(task);
93 task_set_spec_ssb_force_disable(task);
94 - update = !test_and_set_tsk_thread_flag(task, TIF_SSBD);
95 + task_update_spec_tif(task, TIF_SSBD, true);
96 break;
97 default:
98 return -ERANGE;
99 }
100 -
101 - /*
102 - * If being set on non-current task, delay setting the CPU
103 - * mitigation until it is next scheduled.
104 - */
105 - if (task == current && update)
106 - speculation_ctrl_update_current();
107 -
108 return 0;
109 }
110