]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
52997341057451078740ac5f8ff3198e4a77a202
[thirdparty/kernel/stable-queue.git] /
1 From foo@baz Tue Jul 12 05:07:35 PM CEST 2022
2 From: Peter Zijlstra <peterz@infradead.org>
3 Date: Tue, 14 Jun 2022 23:15:56 +0200
4 Subject: x86/bugs: Split spectre_v2_select_mitigation() and spectre_v2_user_select_mitigation()
5
6 From: Peter Zijlstra <peterz@infradead.org>
7
8 commit 166115c08a9b0b846b783088808a27d739be6e8d upstream.
9
10 retbleed will depend on spectre_v2, while spectre_v2_user depends on
11 retbleed. Break this cycle.
12
13 Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
14 Signed-off-by: Borislav Petkov <bp@suse.de>
15 Reviewed-by: Josh Poimboeuf <jpoimboe@kernel.org>
16 Signed-off-by: Borislav Petkov <bp@suse.de>
17 Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
18 Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 ---
21 arch/x86/kernel/cpu/bugs.c | 25 +++++++++++++++++--------
22 1 file changed, 17 insertions(+), 8 deletions(-)
23
24 --- a/arch/x86/kernel/cpu/bugs.c
25 +++ b/arch/x86/kernel/cpu/bugs.c
26 @@ -37,8 +37,9 @@
27 #include "cpu.h"
28
29 static void __init spectre_v1_select_mitigation(void);
30 -static void __init retbleed_select_mitigation(void);
31 static void __init spectre_v2_select_mitigation(void);
32 +static void __init retbleed_select_mitigation(void);
33 +static void __init spectre_v2_user_select_mitigation(void);
34 static void __init ssb_select_mitigation(void);
35 static void __init l1tf_select_mitigation(void);
36 static void __init mds_select_mitigation(void);
37 @@ -137,13 +138,19 @@ void __init check_bugs(void)
38
39 /* Select the proper CPU mitigations before patching alternatives: */
40 spectre_v1_select_mitigation();
41 + spectre_v2_select_mitigation();
42 + /*
43 + * retbleed_select_mitigation() relies on the state set by
44 + * spectre_v2_select_mitigation(); specifically it wants to know about
45 + * spectre_v2=ibrs.
46 + */
47 retbleed_select_mitigation();
48 /*
49 - * spectre_v2_select_mitigation() relies on the state set by
50 + * spectre_v2_user_select_mitigation() relies on the state set by
51 * retbleed_select_mitigation(); specifically the STIBP selection is
52 * forced for UNRET.
53 */
54 - spectre_v2_select_mitigation();
55 + spectre_v2_user_select_mitigation();
56 ssb_select_mitigation();
57 l1tf_select_mitigation();
58 md_clear_select_mitigation();
59 @@ -969,13 +976,15 @@ static void __init spec_v2_user_print_co
60 pr_info("spectre_v2_user=%s forced on command line.\n", reason);
61 }
62
63 +static __ro_after_init enum spectre_v2_mitigation_cmd spectre_v2_cmd;
64 +
65 static enum spectre_v2_user_cmd __init
66 -spectre_v2_parse_user_cmdline(enum spectre_v2_mitigation_cmd v2_cmd)
67 +spectre_v2_parse_user_cmdline(void)
68 {
69 char arg[20];
70 int ret, i;
71
72 - switch (v2_cmd) {
73 + switch (spectre_v2_cmd) {
74 case SPECTRE_V2_CMD_NONE:
75 return SPECTRE_V2_USER_CMD_NONE;
76 case SPECTRE_V2_CMD_FORCE:
77 @@ -1010,7 +1019,7 @@ static inline bool spectre_v2_in_ibrs_mo
78 }
79
80 static void __init
81 -spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)
82 +spectre_v2_user_select_mitigation(void)
83 {
84 enum spectre_v2_user_mitigation mode = SPECTRE_V2_USER_NONE;
85 bool smt_possible = IS_ENABLED(CONFIG_SMP);
86 @@ -1023,7 +1032,7 @@ spectre_v2_user_select_mitigation(enum s
87 cpu_smt_control == CPU_SMT_NOT_SUPPORTED)
88 smt_possible = false;
89
90 - cmd = spectre_v2_parse_user_cmdline(v2_cmd);
91 + cmd = spectre_v2_parse_user_cmdline();
92 switch (cmd) {
93 case SPECTRE_V2_USER_CMD_NONE:
94 goto set_mode;
95 @@ -1347,7 +1356,7 @@ static void __init spectre_v2_select_mit
96 }
97
98 /* Set up IBPB and STIBP depending on the general spectre V2 command */
99 - spectre_v2_user_select_mitigation(cmd);
100 + spectre_v2_cmd = cmd;
101 }
102
103 static void update_stibp_msr(void * __unused)