Pull in core support for the "mitigations=" cmdline option from Thomas Gleixner via -tip, which we can build on top of when we expose our mitigation state via sysfs.
Unified · Split
| @@ -2544,6 +2544,38 @@ · 2543 unmodified lines | |||
| 2544 | in the "bleeding edge" mini2440 support kernel at | 2544 | in the "bleeding edge" mini2440 support kernel at |
| 2545 | http://repo.or.cz/w/linux-2.6/mini2440.git | 2545 | http://repo.or.cz/w/linux-2.6/mini2440.git |
| 2546 | 2546 | ||
| 2547 | mitigations= | ||
| 2548 | [X86,PPC,S390] Control optional mitigations for CPU | ||
| 2549 | vulnerabilities. This is a set of curated, | ||
| 2550 | arch-independent options, each of which is an | ||
| 2551 | aggregation of existing arch-specific options. | ||
| 2552 | |||
| 2553 | off | ||
| 2554 | Disable all optional CPU mitigations. This | ||
| 2555 | improves system performance, but it may also | ||
| 2556 | expose users to several CPU vulnerabilities. | ||
| 2557 | Equivalent to: nopti [X86,PPC] | ||
| 2558 | nospectre_v1 [PPC] | ||
| 2559 | nobp=0 [S390] | ||
| 2560 | nospectre_v2 [X86,PPC,S390] | ||
| 2561 | spectre_v2_user=off [X86] | ||
| 2562 | spec_store_bypass_disable=off [X86,PPC] | ||
| 2563 | l1tf=off [X86] | ||
| 2564 | |||
| 2565 | auto (default) | ||
| 2566 | Mitigate all CPU vulnerabilities, but leave SMT | ||
| 2567 | enabled, even if it's vulnerable. This is for | ||
| 2568 | users who don't want to be surprised by SMT | ||
| 2569 | getting disabled across kernel upgrades, or who | ||
| 2570 | have other ways of avoiding SMT-based attacks. | ||
| 2571 | Equivalent to: (default behavior) | ||
| 2572 | |||
| 2573 | auto,nosmt | ||
| 2574 | Mitigate all CPU vulnerabilities, disabling SMT | ||
| 2575 | if needed. This is for users who always want to | ||
| 2576 | be fully mitigated, even if it means losing SMT. | ||
| 2577 | Equivalent to: l1tf=flush,nosmt [X86] | ||
| 2578 | |||
| 2547 | mminit_loglevel= | 2579 | mminit_loglevel= |
| 2548 | [KNL] When CONFIG_DEBUG_MEMORY_INIT is set, this | 2580 | [KNL] When CONFIG_DEBUG_MEMORY_INIT is set, this |
| 2549 | parameter allows control of the logging verbosity for | 2581 | parameter allows control of the logging verbosity for |
| @@ -57,7 +57,7 @@ void setup_barrier_nospec(void) · 56 unmodified lines | |||
| 57 | enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) && | 57 | enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) && |
| 58 | security_ftr_enabled(SEC_FTR_BNDS_CHK_SPEC_BAR); | 58 | security_ftr_enabled(SEC_FTR_BNDS_CHK_SPEC_BAR); |
| 59 | 59 | ||
| 60 | if (!no_nospec) | 60 | if (!no_nospec && !cpu_mitigations_off()) |
| 61 | enable_barrier_nospec(enable); | 61 | enable_barrier_nospec(enable); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| @@ -116,7 +116,7 @@ static int __init handle_nospectre_v2(char *p) · 52 unmodified lines | |||
| 116 | early_param("nospectre_v2", handle_nospectre_v2); | 116 | early_param("nospectre_v2", handle_nospectre_v2); |
| 117 | void setup_spectre_v2(void) | 117 | void setup_spectre_v2(void) |
| 118 | { | 118 | { |
| 119 | if (no_spectrev2) | 119 | if (no_spectrev2 || cpu_mitigations_off()) |
| 120 | do_btb_flush_fixups(); | 120 | do_btb_flush_fixups(); |
| 121 | else | 121 | else |
| 122 | btb_flush_enabled = true; | 122 | btb_flush_enabled = true; |
| @@ -300,7 +300,7 @@ void setup_stf_barrier(void) · 177 unmodified lines | |||
| 300 | 300 | ||
| 301 | stf_enabled_flush_types = type; | 301 | stf_enabled_flush_types = type; |
| 302 | 302 | ||
| 303 | if (!no_stf_barrier) | 303 | if (!no_stf_barrier && !cpu_mitigations_off()) |
| 304 | stf_barrier_enable(enable); | 304 | stf_barrier_enable(enable); |
| 305 | } | 305 | } |
| 306 | 306 | ||
| @@ -932,7 +932,7 @@ void setup_rfi_flush(enum l1d_flush_type types, bool enable) · 931 unmodified lines | |||
| 932 | 932 | ||
| 933 | enabled_flush_types = types; | 933 | enabled_flush_types = types; |
| 934 | 934 | ||
| 935 | if (!no_rfi_flush) | 935 | if (!no_rfi_flush && !cpu_mitigations_off()) |
| 936 | rfi_flush_enable(enable); | 936 | rfi_flush_enable(enable); |
| 937 | } | 937 | } |
| 938 | 938 | ||
| @@ -1,6 +1,7 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | #include <linux/module.h> | 2 | #include <linux/module.h> |
| 3 | #include <linux/device.h> | 3 | #include <linux/device.h> |
| 4 | #include <linux/cpu.h> | ||
| 4 | #include <asm/nospec-branch.h> | 5 | #include <asm/nospec-branch.h> |
| 5 | 6 | ||
| 6 | static int __init nobp_setup_early(char *str) | 7 | static int __init nobp_setup_early(char *str) |
| @@ -58,7 +59,7 @@ early_param("nospectre_v2", nospectre_v2_setup_early); · 51 unmodified lines | |||
| 58 | 59 | ||
| 59 | void __init nospec_auto_detect(void) | 60 | void __init nospec_auto_detect(void) |
| 60 | { | 61 | { |
| 61 | if (test_facility(156)) { | 62 | if (test_facility(156) || cpu_mitigations_off()) { |
| 62 | /* | 63 | /* |
| 63 | * The machine supports etokens. | 64 | * The machine supports etokens. |
| 64 | * Disable expolines and disable nobp. | 65 | * Disable expolines and disable nobp. |
| @@ -440,7 +440,8 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void) · 439 unmodified lines | |||
| 440 | char arg[20]; | 440 | char arg[20]; |
| 441 | int ret, i; | 441 | int ret, i; |
| 442 | 442 | ||
| 443 | if (cmdline_find_option_bool(boot_command_line, "nospectre_v2")) | 443 | if (cmdline_find_option_bool(boot_command_line, "nospectre_v2") || |
| 444 | cpu_mitigations_off()) | ||
| 444 | return SPECTRE_V2_CMD_NONE; | 445 | return SPECTRE_V2_CMD_NONE; |
| 445 | 446 | ||
| 446 | ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, sizeof(arg)); | 447 | ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, sizeof(arg)); |
| @@ -672,7 +673,8 @@ static enum ssb_mitigation_cmd __init ssb_parse_cmdline(void) · 225 unmodified lines | |||
| 672 | char arg[20]; | 673 | char arg[20]; |
| 673 | int ret, i; | 674 | int ret, i; |
| 674 | 675 | ||
| 675 | if (cmdline_find_option_bool(boot_command_line, "nospec_store_bypass_disable")) { | 676 | if (cmdline_find_option_bool(boot_command_line, "nospec_store_bypass_disable") || |
| 677 | cpu_mitigations_off()) { | ||
| 676 | return SPEC_STORE_BYPASS_CMD_NONE; | 678 | return SPEC_STORE_BYPASS_CMD_NONE; |
| 677 | } else { | 679 | } else { |
| 678 | ret = cmdline_find_option(boot_command_line, "spec_store_bypass_disable", | 680 | ret = cmdline_find_option(boot_command_line, "spec_store_bypass_disable", |
| @@ -1008,6 +1010,11 @@ static void __init l1tf_select_mitigation(void) · 329 unmodified lines | |||
| 1008 | if (!boot_cpu_has_bug(X86_BUG_L1TF)) | 1010 | if (!boot_cpu_has_bug(X86_BUG_L1TF)) |
| 1009 | return; | 1011 | return; |
| 1010 | 1012 | ||
| 1013 | if (cpu_mitigations_off()) | ||
| 1014 | l1tf_mitigation = L1TF_MITIGATION_OFF; | ||
| 1015 | else if (cpu_mitigations_auto_nosmt()) | ||
| 1016 | l1tf_mitigation = L1TF_MITIGATION_FLUSH_NOSMT; | ||
| 1017 | |||
| 1011 | override_cache_bits(&boot_cpu_data); | 1018 | override_cache_bits(&boot_cpu_data); |
| 1012 | 1019 | ||
| 1013 | switch (l1tf_mitigation) { | 1020 | switch (l1tf_mitigation) { |
| @@ -35,6 +35,7 @@ · 34 unmodified lines | |||
| 35 | #include <linux/spinlock.h> | 35 | #include <linux/spinlock.h> |
| 36 | #include <linux/mm.h> | 36 | #include <linux/mm.h> |
| 37 | #include <linux/uaccess.h> | 37 | #include <linux/uaccess.h> |
| 38 | #include <linux/cpu.h> | ||
| 38 | 39 | ||
| 39 | #include <asm/cpufeature.h> | 40 | #include <asm/cpufeature.h> |
| 40 | #include <asm/hypervisor.h> | 41 | #include <asm/hypervisor.h> |
| @@ -115,7 +116,8 @@ void __init pti_check_boottime_disable(void) · 74 unmodified lines | |||
| 115 | } | 116 | } |
| 116 | } | 117 | } |
| 117 | 118 | ||
| 118 | if (cmdline_find_option_bool(boot_command_line, "nopti")) { | 119 | if (cmdline_find_option_bool(boot_command_line, "nopti") || |
| 120 | cpu_mitigations_off()) { | ||
| 119 | pti_mode = PTI_FORCE_OFF; | 121 | pti_mode = PTI_FORCE_OFF; |
| 120 | pti_print_if_insecure("disabled on command line."); | 122 | pti_print_if_insecure("disabled on command line."); |
| 121 | return; | 123 | return; |
| @@ -187,4 +187,28 @@ static inline void cpu_smt_disable(bool force) { } · 186 unmodified lines | |||
| 187 | static inline void cpu_smt_check_topology(void) { } | 187 | static inline void cpu_smt_check_topology(void) { } |
| 188 | #endif | 188 | #endif |
| 189 | 189 | ||
| 190 | /* | ||
| 191 | * These are used for a global "mitigations=" cmdline option for toggling | ||
| 192 | * optional CPU mitigations. | ||
| 193 | */ | ||
| 194 | enum cpu_mitigations { | ||
| 195 | CPU_MITIGATIONS_OFF, | ||
| 196 | CPU_MITIGATIONS_AUTO, | ||
| 197 | CPU_MITIGATIONS_AUTO_NOSMT, | ||
| 198 | }; | ||
| 199 | |||
| 200 | extern enum cpu_mitigations cpu_mitigations; | ||
| 201 | |||
| 202 | /* mitigations=off */ | ||
| 203 | static inline bool cpu_mitigations_off(void) | ||
| 204 | { | ||
| 205 | return cpu_mitigations == CPU_MITIGATIONS_OFF; | ||
| 206 | } | ||
| 207 | |||
| 208 | /* mitigations=auto,nosmt */ | ||
| 209 | static inline bool cpu_mitigations_auto_nosmt(void) | ||
| 210 | { | ||
| 211 | return cpu_mitigations == CPU_MITIGATIONS_AUTO_NOSMT; | ||
| 212 | } | ||
| 213 | |||
| 190 | #endif /* _LINUX_CPU_H_ */ | 214 | #endif /* _LINUX_CPU_H_ */ |
| @@ -2304,3 +2304,18 @@ void __init boot_cpu_hotplug_init(void) · 2303 unmodified lines | |||
| 2304 | #endif | 2304 | #endif |
| 2305 | this_cpu_write(cpuhp_state.state, CPUHP_ONLINE); | 2305 | this_cpu_write(cpuhp_state.state, CPUHP_ONLINE); |
| 2306 | } | 2306 | } |
| 2307 | |||
| 2308 | enum cpu_mitigations cpu_mitigations __ro_after_init = CPU_MITIGATIONS_AUTO; | ||
| 2309 | |||
| 2310 | static int __init mitigations_parse_cmdline(char *arg) | ||
| 2311 | { | ||
| 2312 | if (!strcmp(arg, "off")) | ||
| 2313 | cpu_mitigations = CPU_MITIGATIONS_OFF; | ||
| 2314 | else if (!strcmp(arg, "auto")) | ||
| 2315 | cpu_mitigations = CPU_MITIGATIONS_AUTO; | ||
| 2316 | else if (!strcmp(arg, "auto,nosmt")) | ||
| 2317 | cpu_mitigations = CPU_MITIGATIONS_AUTO_NOSMT; | ||
| 2318 | |||
| 2319 | return 0; | ||
| 2320 | } | ||
| 2321 | early_param("mitigations", mitigations_parse_cmdline); | ||