aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw@amazon.co.uk>2018-01-27 11:24:32 -0500
committerThomas Gleixner <tglx@linutronix.de>2018-01-27 13:10:44 -0500
commit2961298efe1ea1b6fc0d7ee8b76018fa6c0bcef2 (patch)
tree2f235e3928f6c0a4486d8a42b61d1deb91e042ca
parente383095c7fe8d218e00ec0f83e4b95ed4e627b02 (diff)
x86/cpufeatures: Clean up Spectre v2 related CPUID flags
We want to expose the hardware features simply in /proc/cpuinfo as "ibrs", "ibpb" and "stibp". Since AMD has separate CPUID bits for those, use them as the user-visible bits. When the Intel SPEC_CTRL bit is set which indicates both IBRS and IBPB capability, set those (AMD) bits accordingly. Likewise if the Intel STIBP bit is set, set the AMD STIBP that's used for the generic hardware capability. Hide the rest from /proc/cpuinfo by putting "" in the comments. Including RETPOLINE and RETPOLINE_AMD which shouldn't be visible there. There are patches to make the sysfs vulnerabilities information non-readable by non-root, and the same should apply to all information about which mitigations are actually in use. Those *shouldn't* appear in /proc/cpuinfo. The feature bit for whether IBPB is actually used, which is needed for ALTERNATIVEs, is renamed to X86_FEATURE_USE_IBPB. Originally-by: Borislav Petkov <bp@suse.de> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: ak@linux.intel.com Cc: dave.hansen@intel.com Cc: karahmed@amazon.de Cc: arjan@linux.intel.com Cc: torvalds@linux-foundation.org Cc: peterz@infradead.org Cc: bp@alien8.de Cc: pbonzini@redhat.com Cc: tim.c.chen@linux.intel.com Cc: gregkh@linux-foundation.org Link: https://lkml.kernel.org/r/1517070274-12128-2-git-send-email-dwmw@amazon.co.uk
-rw-r--r--arch/x86/include/asm/cpufeatures.h18
-rw-r--r--arch/x86/include/asm/nospec-branch.h2
-rw-r--r--arch/x86/kernel/cpu/bugs.c7
-rw-r--r--arch/x86/kernel/cpu/intel.c31
4 files changed, 34 insertions, 24 deletions
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 07934b2f8df2..73b5fff159a4 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -203,14 +203,14 @@
203#define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9) /* AMD ProcFeedbackInterface */ 203#define X86_FEATURE_PROC_FEEDBACK ( 7*32+ 9) /* AMD ProcFeedbackInterface */
204#define X86_FEATURE_SME ( 7*32+10) /* AMD Secure Memory Encryption */ 204#define X86_FEATURE_SME ( 7*32+10) /* AMD Secure Memory Encryption */
205#define X86_FEATURE_PTI ( 7*32+11) /* Kernel Page Table Isolation enabled */ 205#define X86_FEATURE_PTI ( 7*32+11) /* Kernel Page Table Isolation enabled */
206#define X86_FEATURE_RETPOLINE ( 7*32+12) /* Generic Retpoline mitigation for Spectre variant 2 */ 206#define X86_FEATURE_RETPOLINE ( 7*32+12) /* "" Generic Retpoline mitigation for Spectre variant 2 */
207#define X86_FEATURE_RETPOLINE_AMD ( 7*32+13) /* AMD Retpoline mitigation for Spectre variant 2 */ 207#define X86_FEATURE_RETPOLINE_AMD ( 7*32+13) /* "" AMD Retpoline mitigation for Spectre variant 2 */
208#define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */ 208#define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */
209 209
210#define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */ 210#define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */
211#define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* Fill RSB on context switches */ 211#define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* "" Fill RSB on context switches */
212 212
213#define X86_FEATURE_IBPB ( 7*32+21) /* Indirect Branch Prediction Barrier enabled*/ 213#define X86_FEATURE_USE_IBPB ( 7*32+21) /* "" Indirect Branch Prediction Barrier enabled */
214 214
215/* Virtualization flags: Linux defined, word 8 */ 215/* Virtualization flags: Linux defined, word 8 */
216#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */ 216#define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */
@@ -271,9 +271,9 @@
271#define X86_FEATURE_CLZERO (13*32+ 0) /* CLZERO instruction */ 271#define X86_FEATURE_CLZERO (13*32+ 0) /* CLZERO instruction */
272#define X86_FEATURE_IRPERF (13*32+ 1) /* Instructions Retired Count */ 272#define X86_FEATURE_IRPERF (13*32+ 1) /* Instructions Retired Count */
273#define X86_FEATURE_XSAVEERPTR (13*32+ 2) /* Always save/restore FP error pointers */ 273#define X86_FEATURE_XSAVEERPTR (13*32+ 2) /* Always save/restore FP error pointers */
274#define X86_FEATURE_AMD_PRED_CMD (13*32+12) /* Prediction Command MSR (AMD) */ 274#define X86_FEATURE_IBPB (13*32+12) /* Indirect Branch Prediction Barrier */
275#define X86_FEATURE_AMD_SPEC_CTRL (13*32+14) /* Speculation Control MSR only (AMD) */ 275#define X86_FEATURE_IBRS (13*32+14) /* Indirect Branch Restricted Speculation */
276#define X86_FEATURE_AMD_STIBP (13*32+15) /* Single Thread Indirect Branch Predictors (AMD) */ 276#define X86_FEATURE_STIBP (13*32+15) /* Single Thread Indirect Branch Predictors */
277 277
278/* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */ 278/* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */
279#define X86_FEATURE_DTHERM (14*32+ 0) /* Digital Thermal Sensor */ 279#define X86_FEATURE_DTHERM (14*32+ 0) /* Digital Thermal Sensor */
@@ -325,8 +325,8 @@
325/* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 18 */ 325/* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 18 */
326#define X86_FEATURE_AVX512_4VNNIW (18*32+ 2) /* AVX-512 Neural Network Instructions */ 326#define X86_FEATURE_AVX512_4VNNIW (18*32+ 2) /* AVX-512 Neural Network Instructions */
327#define X86_FEATURE_AVX512_4FMAPS (18*32+ 3) /* AVX-512 Multiply Accumulation Single precision */ 327#define X86_FEATURE_AVX512_4FMAPS (18*32+ 3) /* AVX-512 Multiply Accumulation Single precision */
328#define X86_FEATURE_SPEC_CTRL (18*32+26) /* Speculation Control (IBRS + IBPB) */ 328#define X86_FEATURE_SPEC_CTRL (18*32+26) /* "" Speculation Control (IBRS + IBPB) */
329#define X86_FEATURE_STIBP (18*32+27) /* Single Thread Indirect Branch Predictors */ 329#define X86_FEATURE_INTEL_STIBP (18*32+27) /* "" Single Thread Indirect Branch Predictors */
330#define X86_FEATURE_ARCH_CAPABILITIES (18*32+29) /* IA32_ARCH_CAPABILITIES MSR (Intel) */ 330#define X86_FEATURE_ARCH_CAPABILITIES (18*32+29) /* IA32_ARCH_CAPABILITIES MSR (Intel) */
331 331
332/* 332/*
diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index 865192a2cc31..19ecb5446b30 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -225,7 +225,7 @@ static inline void indirect_branch_prediction_barrier(void)
225 "movl %[val], %%eax\n\t" 225 "movl %[val], %%eax\n\t"
226 "movl $0, %%edx\n\t" 226 "movl $0, %%edx\n\t"
227 "wrmsr", 227 "wrmsr",
228 X86_FEATURE_IBPB) 228 X86_FEATURE_USE_IBPB)
229 : : [msr] "i" (MSR_IA32_PRED_CMD), 229 : : [msr] "i" (MSR_IA32_PRED_CMD),
230 [val] "i" (PRED_CMD_IBPB) 230 [val] "i" (PRED_CMD_IBPB)
231 : "eax", "ecx", "edx", "memory"); 231 : "eax", "ecx", "edx", "memory");
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index b0b7157df89e..32d8e6cdc09e 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -273,9 +273,8 @@ retpoline_auto:
273 } 273 }
274 274
275 /* Initialize Indirect Branch Prediction Barrier if supported */ 275 /* Initialize Indirect Branch Prediction Barrier if supported */
276 if (boot_cpu_has(X86_FEATURE_SPEC_CTRL) || 276 if (boot_cpu_has(X86_FEATURE_IBPB)) {
277 boot_cpu_has(X86_FEATURE_AMD_PRED_CMD)) { 277 setup_force_cpu_cap(X86_FEATURE_USE_IBPB);
278 setup_force_cpu_cap(X86_FEATURE_IBPB);
279 pr_info("Enabling Indirect Branch Prediction Barrier\n"); 278 pr_info("Enabling Indirect Branch Prediction Barrier\n");
280 } 279 }
281} 280}
@@ -308,7 +307,7 @@ ssize_t cpu_show_spectre_v2(struct device *dev,
308 return sprintf(buf, "Not affected\n"); 307 return sprintf(buf, "Not affected\n");
309 308
310 return sprintf(buf, "%s%s%s\n", spectre_v2_strings[spectre_v2_enabled], 309 return sprintf(buf, "%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
311 boot_cpu_has(X86_FEATURE_IBPB) ? ", IBPB" : "", 310 boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "",
312 spectre_v2_module_string()); 311 spectre_v2_module_string());
313} 312}
314#endif 313#endif
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index 5faa487d0477..0c8b916abced 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -175,17 +175,28 @@ static void early_init_intel(struct cpuinfo_x86 *c)
175 if (c->x86 >= 6 && !cpu_has(c, X86_FEATURE_IA64)) 175 if (c->x86 >= 6 && !cpu_has(c, X86_FEATURE_IA64))
176 c->microcode = intel_get_microcode_revision(); 176 c->microcode = intel_get_microcode_revision();
177 177
178 if ((cpu_has(c, X86_FEATURE_SPEC_CTRL) || 178 /*
179 cpu_has(c, X86_FEATURE_STIBP) || 179 * The Intel SPEC_CTRL CPUID bit implies IBRS and IBPB support,
180 cpu_has(c, X86_FEATURE_AMD_SPEC_CTRL) || 180 * and they also have a different bit for STIBP support. Also,
181 cpu_has(c, X86_FEATURE_AMD_PRED_CMD) || 181 * a hypervisor might have set the individual AMD bits even on
182 cpu_has(c, X86_FEATURE_AMD_STIBP)) && bad_spectre_microcode(c)) { 182 * Intel CPUs, for finer-grained selection of what's available.
183 pr_warn("Intel Spectre v2 broken microcode detected; disabling SPEC_CTRL\n"); 183 */
184 clear_cpu_cap(c, X86_FEATURE_SPEC_CTRL); 184 if (cpu_has(c, X86_FEATURE_SPEC_CTRL)) {
185 set_cpu_cap(c, X86_FEATURE_IBRS);
186 set_cpu_cap(c, X86_FEATURE_IBPB);
187 }
188 if (cpu_has(c, X86_FEATURE_INTEL_STIBP))
189 set_cpu_cap(c, X86_FEATURE_STIBP);
190
191 /* Now if any of them are set, check the blacklist and clear the lot */
192 if ((cpu_has(c, X86_FEATURE_IBRS) || cpu_has(c, X86_FEATURE_IBPB) ||
193 cpu_has(c, X86_FEATURE_STIBP)) && bad_spectre_microcode(c)) {
194 pr_warn("Intel Spectre v2 broken microcode detected; disabling Speculation Control\n");
195 clear_cpu_cap(c, X86_FEATURE_IBRS);
196 clear_cpu_cap(c, X86_FEATURE_IBPB);
185 clear_cpu_cap(c, X86_FEATURE_STIBP); 197 clear_cpu_cap(c, X86_FEATURE_STIBP);
186 clear_cpu_cap(c, X86_FEATURE_AMD_SPEC_CTRL); 198 clear_cpu_cap(c, X86_FEATURE_SPEC_CTRL);
187 clear_cpu_cap(c, X86_FEATURE_AMD_PRED_CMD); 199 clear_cpu_cap(c, X86_FEATURE_INTEL_STIBP);
188 clear_cpu_cap(c, X86_FEATURE_AMD_STIBP);
189 } 200 }
190 201
191 /* 202 /*