History

Merge branch 'core/speculation' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip into for-next/mitigations

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.

Will Deacon committed 7 years ago

Commit cbafee52 parents 79a3aaa 0336e048 files · +89 −8Browse files

Unified · Split

8 files
  1. Documentation/admin-guide/kernel-parameters.txt +32 −0
  2. arch/powerpc/kernel/security.c +3 −3
  3. arch/powerpc/kernel/setup_64.c +1 −1
  4. arch/s390/kernel/nospec-branch.c +2 −1
  5. arch/x86/kernel/cpu/bugs.c +9 −2
  6. arch/x86/mm/pti.c +3 −1
  7. include/linux/cpu.h +24 −0
  8. kernel/cpu.c +15 −0
Documentation/admin-guide/kernel-parameters.txt+32−0
@@ -2544,6 +2544,38 @@ · 2543 unmodified lines
25442544 in the "bleeding edge" mini2440 support kernel at
25452545 http://repo.or.cz/w/linux-2.6/mini2440.git
25462546
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+
25472579 mminit_loglevel=
25482580 [KNL] When CONFIG_DEBUG_MEMORY_INIT is set, this
25492581 parameter allows control of the logging verbosity for
arch/powerpc/kernel/security.c+3−3
@@ -57,7 +57,7 @@ void setup_barrier_nospec(void) · 56 unmodified lines
5757 enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) &&
5858 security_ftr_enabled(SEC_FTR_BNDS_CHK_SPEC_BAR);
5959
60− if (!no_nospec)
60+ if (!no_nospec && !cpu_mitigations_off())
6161 enable_barrier_nospec(enable);
6262 }
6363
@@ -116,7 +116,7 @@ static int __init handle_nospectre_v2(char *p) · 52 unmodified lines
116116 early_param("nospectre_v2", handle_nospectre_v2);
117117 void setup_spectre_v2(void)
118118 {
119− if (no_spectrev2)
119+ if (no_spectrev2 || cpu_mitigations_off())
120120 do_btb_flush_fixups();
121121 else
122122 btb_flush_enabled = true;
@@ -300,7 +300,7 @@ void setup_stf_barrier(void) · 177 unmodified lines
300300
301301 stf_enabled_flush_types = type;
302302
303− if (!no_stf_barrier)
303+ if (!no_stf_barrier && !cpu_mitigations_off())
304304 stf_barrier_enable(enable);
305305 }
306306
arch/powerpc/kernel/setup_64.c+1−1
@@ -932,7 +932,7 @@ void setup_rfi_flush(enum l1d_flush_type types, bool enable) · 931 unmodified lines
932932
933933 enabled_flush_types = types;
934934
935− if (!no_rfi_flush)
935+ if (!no_rfi_flush && !cpu_mitigations_off())
936936 rfi_flush_enable(enable);
937937 }
938938
arch/s390/kernel/nospec-branch.c+2−1
@@ -1,6 +1,7 @@
11 // SPDX-License-Identifier: GPL-2.0
22 #include <linux/module.h>
33 #include <linux/device.h>
4+#include <linux/cpu.h>
45 #include <asm/nospec-branch.h>
56
67 static int __init nobp_setup_early(char *str)
@@ -58,7 +59,7 @@ early_param("nospectre_v2", nospectre_v2_setup_early); · 51 unmodified lines
5859
5960 void __init nospec_auto_detect(void)
6061 {
61− if (test_facility(156)) {
62+ if (test_facility(156) || cpu_mitigations_off()) {
6263 /*
6364 * The machine supports etokens.
6465 * Disable expolines and disable nobp.
arch/x86/kernel/cpu/bugs.c+9−2
@@ -440,7 +440,8 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void) · 439 unmodified lines
440440 char arg[20];
441441 int ret, i;
442442
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())
444445 return SPECTRE_V2_CMD_NONE;
445446
446447 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
672673 char arg[20];
673674 int ret, i;
674675
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()) {
676678 return SPEC_STORE_BYPASS_CMD_NONE;
677679 } else {
678680 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
10081010 if (!boot_cpu_has_bug(X86_BUG_L1TF))
10091011 return;
10101012
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+
10111018 override_cache_bits(&boot_cpu_data);
10121019
10131020 switch (l1tf_mitigation) {
arch/x86/mm/pti.c+3−1
@@ -35,6 +35,7 @@ · 34 unmodified lines
3535 #include <linux/spinlock.h>
3636 #include <linux/mm.h>
3737 #include <linux/uaccess.h>
38+#include <linux/cpu.h>
3839
3940 #include <asm/cpufeature.h>
4041 #include <asm/hypervisor.h>
@@ -115,7 +116,8 @@ void __init pti_check_boottime_disable(void) · 74 unmodified lines
115116 }
116117 }
117118
118− if (cmdline_find_option_bool(boot_command_line, "nopti")) {
119+ if (cmdline_find_option_bool(boot_command_line, "nopti") ||
120+ cpu_mitigations_off()) {
119121 pti_mode = PTI_FORCE_OFF;
120122 pti_print_if_insecure("disabled on command line.");
121123 return;
include/linux/cpu.h+24−0
@@ -187,4 +187,28 @@ static inline void cpu_smt_disable(bool force) { } · 186 unmodified lines
187187 static inline void cpu_smt_check_topology(void) { }
188188 #endif
189189
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+
190214 #endif /* _LINUX_CPU_H_ */
kernel/cpu.c+15−0
@@ -2304,3 +2304,18 @@ void __init boot_cpu_hotplug_init(void) · 2303 unmodified lines
23042304 #endif
23052305 this_cpu_write(cpuhp_state.state, CPUHP_ONLINE);
23062306 }
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);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t