Skip to content

Commit 21e433b

Browse files
committed
x86/speculation: Clean up various Spectre related details
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>
1 parent 3712cae commit 21e433b

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
@@ -162,8 +162,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
162162
if (cmdline_find_option_bool(boot_command_line, "nospectre_v2"))
163163
return SPECTRE_V2_CMD_NONE;
164164
else {
165-
ret = cmdline_find_option(boot_command_line, "spectre_v2", arg,
166-
sizeof(arg));
165+
ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, sizeof(arg));
167166
if (ret < 0)
168167
return SPECTRE_V2_CMD_AUTO;
169168

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

177176
if (i >= ARRAY_SIZE(mitigation_options)) {
178-
pr_err("unknown option (%s). Switching to AUTO select\n",
179-
mitigation_options[i].option);
177+
pr_err("unknown option (%s). Switching to AUTO select\n", mitigation_options[i].option);
180178
return SPECTRE_V2_CMD_AUTO;
181179
}
182180
}
@@ -185,8 +183,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
185183
cmd == SPECTRE_V2_CMD_RETPOLINE_AMD ||
186184
cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC) &&
187185
!IS_ENABLED(CONFIG_RETPOLINE)) {
188-
pr_err("%s selected but not compiled in. Switching to AUTO select\n",
189-
mitigation_options[i].option);
186+
pr_err("%s selected but not compiled in. Switching to AUTO select\n", mitigation_options[i].option);
190187
return SPECTRE_V2_CMD_AUTO;
191188
}
192189

@@ -256,14 +253,14 @@ static void __init spectre_v2_select_mitigation(void)
256253
goto retpoline_auto;
257254
break;
258255
}
259-
pr_err("kernel not compiled with retpoline; no mitigation available!");
256+
pr_err("Spectre mitigation: kernel not compiled with retpoline; no mitigation available!");
260257
return;
261258

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

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

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

308305
#undef pr_fmt
309306

310307
#ifdef CONFIG_SYSFS
311-
ssize_t cpu_show_meltdown(struct device *dev,
312-
struct device_attribute *attr, char *buf)
308+
ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf)
313309
{
314310
if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN))
315311
return sprintf(buf, "Not affected\n");
@@ -318,16 +314,14 @@ ssize_t cpu_show_meltdown(struct device *dev,
318314
return sprintf(buf, "Vulnerable\n");
319315
}
320316

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

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

0 commit comments

Comments
 (0)