Skip to content

Commit 3aad6fe

Browse files
ingomolnargregkh
authored andcommitted
x86/speculation: Clean up various Spectre related details
commit 21e433b upstream. Harmonize all the Spectre messages so that a: dmesg | grep -i spectre ... gives us most Spectre related kernel boot messages. Also fix a few other details: - clarify a comment about firmware speculation control - s/KPTI/PTI - remove various line-breaks that made the code uglier Acked-by: David Woodhouse <dwmw@amazon.co.uk> Cc: Andy Lutomirski <luto@kernel.org> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9665296 commit 3aad6fe

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

arch/x86/kernel/cpu/bugs.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
161161
if (cmdline_find_option_bool(boot_command_line, "nospectre_v2"))
162162
return SPECTRE_V2_CMD_NONE;
163163
else {
164-
ret = cmdline_find_option(boot_command_line, "spectre_v2", arg,
165-
sizeof(arg));
164+
ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, sizeof(arg));
166165
if (ret < 0)
167166
return SPECTRE_V2_CMD_AUTO;
168167

@@ -174,8 +173,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
174173
}
175174

176175
if (i >= ARRAY_SIZE(mitigation_options)) {
177-
pr_err("unknown option (%s). Switching to AUTO select\n",
178-
mitigation_options[i].option);
176+
pr_err("unknown option (%s). Switching to AUTO select\n", mitigation_options[i].option);
179177
return SPECTRE_V2_CMD_AUTO;
180178
}
181179
}
@@ -184,8 +182,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
184182
cmd == SPECTRE_V2_CMD_RETPOLINE_AMD ||
185183
cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC) &&
186184
!IS_ENABLED(CONFIG_RETPOLINE)) {
187-
pr_err("%s selected but not compiled in. Switching to AUTO select\n",
188-
mitigation_options[i].option);
185+
pr_err("%s selected but not compiled in. Switching to AUTO select\n", mitigation_options[i].option);
189186
return SPECTRE_V2_CMD_AUTO;
190187
}
191188

@@ -255,14 +252,14 @@ static void __init spectre_v2_select_mitigation(void)
255252
goto retpoline_auto;
256253
break;
257254
}
258-
pr_err("kernel not compiled with retpoline; no mitigation available!");
255+
pr_err("Spectre mitigation: kernel not compiled with retpoline; no mitigation available!");
259256
return;
260257

261258
retpoline_auto:
262259
if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
263260
retpoline_amd:
264261
if (!boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) {
265-
pr_err("LFENCE not serializing. Switching to generic retpoline\n");
262+
pr_err("Spectre mitigation: LFENCE not serializing, switching to generic retpoline\n");
266263
goto retpoline_generic;
267264
}
268265
mode = retp_compiler() ? SPECTRE_V2_RETPOLINE_AMD :
@@ -280,7 +277,7 @@ static void __init spectre_v2_select_mitigation(void)
280277
pr_info("%s\n", spectre_v2_strings[mode]);
281278

282279
/*
283-
* If neither SMEP or KPTI are available, there is a risk of
280+
* If neither SMEP nor PTI are available, there is a risk of
284281
* hitting userspace addresses in the RSB after a context switch
285282
* from a shallow call stack to a deeper one. To prevent this fill
286283
* the entire RSB, even when using IBRS.
@@ -294,21 +291,20 @@ static void __init spectre_v2_select_mitigation(void)
294291
if ((!boot_cpu_has(X86_FEATURE_KAISER) &&
295292
!boot_cpu_has(X86_FEATURE_SMEP)) || is_skylake_era()) {
296293
setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW);
297-
pr_info("Filling RSB on context switch\n");
294+
pr_info("Spectre v2 mitigation: Filling RSB on context switch\n");
298295
}
299296

300297
/* Initialize Indirect Branch Prediction Barrier if supported */
301298
if (boot_cpu_has(X86_FEATURE_IBPB)) {
302299
setup_force_cpu_cap(X86_FEATURE_USE_IBPB);
303-
pr_info("Enabling Indirect Branch Prediction Barrier\n");
300+
pr_info("Spectre v2 mitigation: Enabling Indirect Branch Prediction Barrier\n");
304301
}
305302
}
306303

307304
#undef pr_fmt
308305

309306
#ifdef CONFIG_SYSFS
310-
ssize_t cpu_show_meltdown(struct device *dev,
311-
struct device_attribute *attr, char *buf)
307+
ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf)
312308
{
313309
if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN))
314310
return sprintf(buf, "Not affected\n");
@@ -317,16 +313,14 @@ ssize_t cpu_show_meltdown(struct device *dev,
317313
return sprintf(buf, "Vulnerable\n");
318314
}
319315

320-
ssize_t cpu_show_spectre_v1(struct device *dev,
321-
struct device_attribute *attr, char *buf)
316+
ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf)
322317
{
323318
if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V1))
324319
return sprintf(buf, "Not affected\n");
325320
return sprintf(buf, "Mitigation: __user pointer sanitization\n");
326321
}
327322

328-
ssize_t cpu_show_spectre_v2(struct device *dev,
329-
struct device_attribute *attr, char *buf)
323+
ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf)
330324
{
331325
if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2))
332326
return sprintf(buf, "Not affected\n");

0 commit comments

Comments
 (0)