]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/5.0.16/0021-x86-speculation-Support-mitigations-cmdline-option.patch
Linux 5.1.2
[thirdparty/kernel/stable-queue.git] / releases / 5.0.16 / 0021-x86-speculation-Support-mitigations-cmdline-option.patch
1 From 1aaa69ec96c73918d45177d9d35680f648d0faed Mon Sep 17 00:00:00 2001
2 From: Josh Poimboeuf <jpoimboe@redhat.com>
3 Date: Fri, 12 Apr 2019 15:39:29 -0500
4 Subject: [PATCH 21/27] x86/speculation: Support 'mitigations=' cmdline option
5
6 commit d68be4c4d31295ff6ae34a8ddfaa4c1a8ff42812 upstream
7
8 Configure x86 runtime CPU speculation bug mitigations in accordance with
9 the 'mitigations=' cmdline option. This affects Meltdown, Spectre v2,
10 Speculative Store Bypass, and L1TF.
11
12 The default behavior is unchanged.
13
14 Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
15 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
16 Tested-by: Jiri Kosina <jkosina@suse.cz> (on x86)
17 Reviewed-by: Jiri Kosina <jkosina@suse.cz>
18 Cc: Borislav Petkov <bp@alien8.de>
19 Cc: "H . Peter Anvin" <hpa@zytor.com>
20 Cc: Andy Lutomirski <luto@kernel.org>
21 Cc: Peter Zijlstra <peterz@infradead.org>
22 Cc: Jiri Kosina <jikos@kernel.org>
23 Cc: Waiman Long <longman@redhat.com>
24 Cc: Andrea Arcangeli <aarcange@redhat.com>
25 Cc: Jon Masters <jcm@redhat.com>
26 Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
27 Cc: Paul Mackerras <paulus@samba.org>
28 Cc: Michael Ellerman <mpe@ellerman.id.au>
29 Cc: linuxppc-dev@lists.ozlabs.org
30 Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
31 Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
32 Cc: linux-s390@vger.kernel.org
33 Cc: Catalin Marinas <catalin.marinas@arm.com>
34 Cc: Will Deacon <will.deacon@arm.com>
35 Cc: linux-arm-kernel@lists.infradead.org
36 Cc: linux-arch@vger.kernel.org
37 Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
38 Cc: Tyler Hicks <tyhicks@canonical.com>
39 Cc: Linus Torvalds <torvalds@linux-foundation.org>
40 Cc: Randy Dunlap <rdunlap@infradead.org>
41 Cc: Steven Price <steven.price@arm.com>
42 Cc: Phil Auld <pauld@redhat.com>
43 Link: https://lkml.kernel.org/r/6616d0ae169308516cfdf5216bedd169f8a8291b.1555085500.git.jpoimboe@redhat.com
44 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
45 ---
46 Documentation/admin-guide/kernel-parameters.txt | 16 +++++++++++-----
47 arch/x86/kernel/cpu/bugs.c | 11 +++++++++--
48 arch/x86/mm/pti.c | 4 +++-
49 3 files changed, 23 insertions(+), 8 deletions(-)
50
51 diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
52 index df6d9a7c1724..59a1181e52b8 100644
53 --- a/Documentation/admin-guide/kernel-parameters.txt
54 +++ b/Documentation/admin-guide/kernel-parameters.txt
55 @@ -2540,15 +2540,20 @@
56 http://repo.or.cz/w/linux-2.6/mini2440.git
57
58 mitigations=
59 - Control optional mitigations for CPU vulnerabilities.
60 - This is a set of curated, arch-independent options, each
61 - of which is an aggregation of existing arch-specific
62 - options.
63 + [X86] Control optional mitigations for CPU
64 + vulnerabilities. This is a set of curated,
65 + arch-independent options, each of which is an
66 + aggregation of existing arch-specific options.
67
68 off
69 Disable all optional CPU mitigations. This
70 improves system performance, but it may also
71 expose users to several CPU vulnerabilities.
72 + Equivalent to: nopti [X86]
73 + nospectre_v2 [X86]
74 + spectre_v2_user=off [X86]
75 + spec_store_bypass_disable=off [X86]
76 + l1tf=off [X86]
77
78 auto (default)
79 Mitigate all CPU vulnerabilities, but leave SMT
80 @@ -2556,12 +2561,13 @@
81 users who don't want to be surprised by SMT
82 getting disabled across kernel upgrades, or who
83 have other ways of avoiding SMT-based attacks.
84 - This is the default behavior.
85 + Equivalent to: (default behavior)
86
87 auto,nosmt
88 Mitigate all CPU vulnerabilities, disabling SMT
89 if needed. This is for users who always want to
90 be fully mitigated, even if it means losing SMT.
91 + Equivalent to: l1tf=flush,nosmt [X86]
92
93 mminit_loglevel=
94 [KNL] When CONFIG_DEBUG_MEMORY_INIT is set, this
95 diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
96 index 04c140ac36af..7c79672234e4 100644
97 --- a/arch/x86/kernel/cpu/bugs.c
98 +++ b/arch/x86/kernel/cpu/bugs.c
99 @@ -506,7 +506,8 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
100 char arg[20];
101 int ret, i;
102
103 - if (cmdline_find_option_bool(boot_command_line, "nospectre_v2"))
104 + if (cmdline_find_option_bool(boot_command_line, "nospectre_v2") ||
105 + cpu_mitigations_off())
106 return SPECTRE_V2_CMD_NONE;
107
108 ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, sizeof(arg));
109 @@ -771,7 +772,8 @@ static enum ssb_mitigation_cmd __init ssb_parse_cmdline(void)
110 char arg[20];
111 int ret, i;
112
113 - if (cmdline_find_option_bool(boot_command_line, "nospec_store_bypass_disable")) {
114 + if (cmdline_find_option_bool(boot_command_line, "nospec_store_bypass_disable") ||
115 + cpu_mitigations_off()) {
116 return SPEC_STORE_BYPASS_CMD_NONE;
117 } else {
118 ret = cmdline_find_option(boot_command_line, "spec_store_bypass_disable",
119 @@ -1095,6 +1097,11 @@ static void __init l1tf_select_mitigation(void)
120 if (!boot_cpu_has_bug(X86_BUG_L1TF))
121 return;
122
123 + if (cpu_mitigations_off())
124 + l1tf_mitigation = L1TF_MITIGATION_OFF;
125 + else if (cpu_mitigations_auto_nosmt())
126 + l1tf_mitigation = L1TF_MITIGATION_FLUSH_NOSMT;
127 +
128 override_cache_bits(&boot_cpu_data);
129
130 switch (l1tf_mitigation) {
131 diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
132 index 4fee5c3003ed..5890f09bfc19 100644
133 --- a/arch/x86/mm/pti.c
134 +++ b/arch/x86/mm/pti.c
135 @@ -35,6 +35,7 @@
136 #include <linux/spinlock.h>
137 #include <linux/mm.h>
138 #include <linux/uaccess.h>
139 +#include <linux/cpu.h>
140
141 #include <asm/cpufeature.h>
142 #include <asm/hypervisor.h>
143 @@ -115,7 +116,8 @@ void __init pti_check_boottime_disable(void)
144 }
145 }
146
147 - if (cmdline_find_option_bool(boot_command_line, "nopti")) {
148 + if (cmdline_find_option_bool(boot_command_line, "nopti") ||
149 + cpu_mitigations_off()) {
150 pti_mode = PTI_FORCE_OFF;
151 pti_print_if_insecure("disabled on command line.");
152 return;
153 --
154 2.21.0
155