@@ -119,13 +119,13 @@ static inline const char *spectre_v2_module_string(void) { return ""; }
119
119
static void __init spec2_print_if_insecure (const char * reason )
120
120
{
121
121
if (boot_cpu_has_bug (X86_BUG_SPECTRE_V2 ))
122
- pr_info ("%s\n" , reason );
122
+ pr_info ("%s selected on command line. \n" , reason );
123
123
}
124
124
125
125
static void __init spec2_print_if_secure (const char * reason )
126
126
{
127
127
if (!boot_cpu_has_bug (X86_BUG_SPECTRE_V2 ))
128
- pr_info ("%s\n" , reason );
128
+ pr_info ("%s selected on command line. \n" , reason );
129
129
}
130
130
131
131
static inline bool retp_compiler (void )
@@ -140,42 +140,68 @@ static inline bool match_option(const char *arg, int arglen, const char *opt)
140
140
return len == arglen && !strncmp (arg , opt , len );
141
141
}
142
142
143
+ static const struct {
144
+ const char * option ;
145
+ enum spectre_v2_mitigation_cmd cmd ;
146
+ bool secure ;
147
+ } mitigation_options [] = {
148
+ { "off" , SPECTRE_V2_CMD_NONE , false },
149
+ { "on" , SPECTRE_V2_CMD_FORCE , true },
150
+ { "retpoline" , SPECTRE_V2_CMD_RETPOLINE , false },
151
+ { "retpoline,amd" , SPECTRE_V2_CMD_RETPOLINE_AMD , false },
152
+ { "retpoline,generic" , SPECTRE_V2_CMD_RETPOLINE_GENERIC , false },
153
+ { "auto" , SPECTRE_V2_CMD_AUTO , false },
154
+ };
155
+
143
156
static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline (void )
144
157
{
145
158
char arg [20 ];
146
- int ret ;
147
-
148
- ret = cmdline_find_option (boot_command_line , "spectre_v2" , arg ,
149
- sizeof (arg ));
150
- if (ret > 0 ) {
151
- if (match_option (arg , ret , "off" )) {
152
- goto disable ;
153
- } else if (match_option (arg , ret , "on" )) {
154
- spec2_print_if_secure ("force enabled on command line." );
155
- return SPECTRE_V2_CMD_FORCE ;
156
- } else if (match_option (arg , ret , "retpoline" )) {
157
- spec2_print_if_insecure ("retpoline selected on command line." );
158
- return SPECTRE_V2_CMD_RETPOLINE ;
159
- } else if (match_option (arg , ret , "retpoline,amd" )) {
160
- if (boot_cpu_data .x86_vendor != X86_VENDOR_AMD ) {
161
- pr_err ("retpoline,amd selected but CPU is not AMD. Switching to AUTO select\n" );
162
- return SPECTRE_V2_CMD_AUTO ;
163
- }
164
- spec2_print_if_insecure ("AMD retpoline selected on command line." );
165
- return SPECTRE_V2_CMD_RETPOLINE_AMD ;
166
- } else if (match_option (arg , ret , "retpoline,generic" )) {
167
- spec2_print_if_insecure ("generic retpoline selected on command line." );
168
- return SPECTRE_V2_CMD_RETPOLINE_GENERIC ;
169
- } else if (match_option (arg , ret , "auto" )) {
159
+ int ret , i ;
160
+ enum spectre_v2_mitigation_cmd cmd = SPECTRE_V2_CMD_AUTO ;
161
+
162
+ if (cmdline_find_option_bool (boot_command_line , "nospectre_v2" ))
163
+ return SPECTRE_V2_CMD_NONE ;
164
+ else {
165
+ ret = cmdline_find_option (boot_command_line , "spectre_v2" , arg ,
166
+ sizeof (arg ));
167
+ if (ret < 0 )
168
+ return SPECTRE_V2_CMD_AUTO ;
169
+
170
+ for (i = 0 ; i < ARRAY_SIZE (mitigation_options ); i ++ ) {
171
+ if (!match_option (arg , ret , mitigation_options [i ].option ))
172
+ continue ;
173
+ cmd = mitigation_options [i ].cmd ;
174
+ break ;
175
+ }
176
+
177
+ if (i >= ARRAY_SIZE (mitigation_options )) {
178
+ pr_err ("unknown option (%s). Switching to AUTO select\n" ,
179
+ mitigation_options [i ].option );
170
180
return SPECTRE_V2_CMD_AUTO ;
171
181
}
172
182
}
173
183
174
- if (!cmdline_find_option_bool (boot_command_line , "nospectre_v2" ))
184
+ if ((cmd == SPECTRE_V2_CMD_RETPOLINE ||
185
+ cmd == SPECTRE_V2_CMD_RETPOLINE_AMD ||
186
+ cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC ) &&
187
+ !IS_ENABLED (CONFIG_RETPOLINE )) {
188
+ pr_err ("%s selected but not compiled in. Switching to AUTO select\n" ,
189
+ mitigation_options [i ].option );
175
190
return SPECTRE_V2_CMD_AUTO ;
176
- disable :
177
- spec2_print_if_insecure ("disabled on command line." );
178
- return SPECTRE_V2_CMD_NONE ;
191
+ }
192
+
193
+ if (cmd == SPECTRE_V2_CMD_RETPOLINE_AMD &&
194
+ boot_cpu_data .x86_vendor != X86_VENDOR_AMD ) {
195
+ pr_err ("retpoline,amd selected but CPU is not AMD. Switching to AUTO select\n" );
196
+ return SPECTRE_V2_CMD_AUTO ;
197
+ }
198
+
199
+ if (mitigation_options [i ].secure )
200
+ spec2_print_if_secure (mitigation_options [i ].option );
201
+ else
202
+ spec2_print_if_insecure (mitigation_options [i ].option );
203
+
204
+ return cmd ;
179
205
}
180
206
181
207
/* Check for Skylake-like CPUs (for RSB handling) */
0 commit comments