diff options
author | Ingo Molnar <mingo@kernel.org> | 2018-02-13 03:03:08 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2018-02-13 03:03:08 -0500 |
commit | 21e433bdb95bdf3aa48226fd3d33af608437f293 (patch) | |
tree | 45347efa6481dd412cd2e5ccfbb47ca793523f00 | |
parent | 3712caeb14dcb33fb4d5114f14c0beef10aca101 (diff) |
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>
-rw-r--r-- | arch/x86/kernel/cpu/bugs.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 61152aa53377..4acf16a76d1e 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c | |||
@@ -162,8 +162,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void) | |||
162 | if (cmdline_find_option_bool(boot_command_line, "nospectre_v2")) | 162 | if (cmdline_find_option_bool(boot_command_line, "nospectre_v2")) |
163 | return SPECTRE_V2_CMD_NONE; | 163 | return SPECTRE_V2_CMD_NONE; |
164 | else { | 164 | else { |
165 | ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, | 165 | ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, sizeof(arg)); |
166 | sizeof(arg)); | ||
167 | if (ret < 0) | 166 | if (ret < 0) |
168 | return SPECTRE_V2_CMD_AUTO; | 167 | return SPECTRE_V2_CMD_AUTO; |
169 | 168 | ||
@@ -175,8 +174,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void) | |||
175 | } | 174 | } |
176 | 175 | ||
177 | if (i >= ARRAY_SIZE(mitigation_options)) { | 176 | if (i >= ARRAY_SIZE(mitigation_options)) { |
178 | pr_err("unknown option (%s). Switching to AUTO select\n", | 177 | pr_err("unknown option (%s). Switching to AUTO select\n", mitigation_options[i].option); |
179 | mitigation_options[i].option); | ||
180 | return SPECTRE_V2_CMD_AUTO; | 178 | return SPECTRE_V2_CMD_AUTO; |
181 | } | 179 | } |
182 | } | 180 | } |
@@ -185,8 +183,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void) | |||
185 | cmd == SPECTRE_V2_CMD_RETPOLINE_AMD || | 183 | cmd == SPECTRE_V2_CMD_RETPOLINE_AMD || |
186 | cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC) && | 184 | cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC) && |
187 | !IS_ENABLED(CONFIG_RETPOLINE)) { | 185 | !IS_ENABLED(CONFIG_RETPOLINE)) { |
188 | pr_err("%s selected but not compiled in. Switching to AUTO select\n", | 186 | pr_err("%s selected but not compiled in. Switching to AUTO select\n", mitigation_options[i].option); |
189 | mitigation_options[i].option); | ||
190 | return SPECTRE_V2_CMD_AUTO; | 187 | return SPECTRE_V2_CMD_AUTO; |
191 | } | 188 | } |
192 | 189 | ||
@@ -256,14 +253,14 @@ static void __init spectre_v2_select_mitigation(void) | |||
256 | goto retpoline_auto; | 253 | goto retpoline_auto; |
257 | break; | 254 | break; |
258 | } | 255 | } |
259 | pr_err("kernel not compiled with retpoline; no mitigation available!"); | 256 | pr_err("Spectre mitigation: kernel not compiled with retpoline; no mitigation available!"); |
260 | return; | 257 | return; |
261 | 258 | ||
262 | retpoline_auto: | 259 | retpoline_auto: |
263 | if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { | 260 | if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { |
264 | retpoline_amd: | 261 | retpoline_amd: |
265 | if (!boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) { | 262 | 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"); |
267 | goto retpoline_generic; | 264 | goto retpoline_generic; |
268 | } | 265 | } |
269 | mode = retp_compiler() ? SPECTRE_V2_RETPOLINE_AMD : | 266 | mode = retp_compiler() ? SPECTRE_V2_RETPOLINE_AMD : |
@@ -281,7 +278,7 @@ retpoline_auto: | |||
281 | pr_info("%s\n", spectre_v2_strings[mode]); | 278 | pr_info("%s\n", spectre_v2_strings[mode]); |
282 | 279 | ||
283 | /* | 280 | /* |
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 |
285 | * hitting userspace addresses in the RSB after a context switch | 282 | * hitting userspace addresses in the RSB after a context switch |
286 | * from a shallow call stack to a deeper one. To prevent this fill | 283 | * from a shallow call stack to a deeper one. To prevent this fill |
287 | * the entire RSB, even when using IBRS. | 284 | * the entire RSB, even when using IBRS. |
@@ -295,21 +292,20 @@ retpoline_auto: | |||
295 | if ((!boot_cpu_has(X86_FEATURE_PTI) && | 292 | if ((!boot_cpu_has(X86_FEATURE_PTI) && |
296 | !boot_cpu_has(X86_FEATURE_SMEP)) || is_skylake_era()) { | 293 | !boot_cpu_has(X86_FEATURE_SMEP)) || is_skylake_era()) { |
297 | setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW); | 294 | 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"); |
299 | } | 296 | } |
300 | 297 | ||
301 | /* Initialize Indirect Branch Prediction Barrier if supported */ | 298 | /* Initialize Indirect Branch Prediction Barrier if supported */ |
302 | if (boot_cpu_has(X86_FEATURE_IBPB)) { | 299 | if (boot_cpu_has(X86_FEATURE_IBPB)) { |
303 | setup_force_cpu_cap(X86_FEATURE_USE_IBPB); | 300 | 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"); |
305 | } | 302 | } |
306 | } | 303 | } |
307 | 304 | ||
308 | #undef pr_fmt | 305 | #undef pr_fmt |
309 | 306 | ||
310 | #ifdef CONFIG_SYSFS | 307 | #ifdef CONFIG_SYSFS |
311 | ssize_t cpu_show_meltdown(struct device *dev, | 308 | ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, char *buf) |
312 | struct device_attribute *attr, char *buf) | ||
313 | { | 309 | { |
314 | if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN)) | 310 | if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN)) |
315 | return sprintf(buf, "Not affected\n"); | 311 | return sprintf(buf, "Not affected\n"); |
@@ -318,16 +314,14 @@ ssize_t cpu_show_meltdown(struct device *dev, | |||
318 | return sprintf(buf, "Vulnerable\n"); | 314 | return sprintf(buf, "Vulnerable\n"); |
319 | } | 315 | } |
320 | 316 | ||
321 | ssize_t cpu_show_spectre_v1(struct device *dev, | 317 | ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, char *buf) |
322 | struct device_attribute *attr, char *buf) | ||
323 | { | 318 | { |
324 | if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V1)) | 319 | if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V1)) |
325 | return sprintf(buf, "Not affected\n"); | 320 | return sprintf(buf, "Not affected\n"); |
326 | return sprintf(buf, "Mitigation: __user pointer sanitization\n"); | 321 | return sprintf(buf, "Mitigation: __user pointer sanitization\n"); |
327 | } | 322 | } |
328 | 323 | ||
329 | ssize_t cpu_show_spectre_v2(struct device *dev, | 324 | ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, char *buf) |
330 | struct device_attribute *attr, char *buf) | ||
331 | { | 325 | { |
332 | if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2)) | 326 | if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2)) |
333 | return sprintf(buf, "Not affected\n"); | 327 | return sprintf(buf, "Not affected\n"); |