1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 1994 Linus Torvalds
5 * Cyrix stuff, June 1998 by:
6 * - Rafael R. Reilova (moved everything from head.S),
7 * <rreilova@ececs.uc.edu>
8 * - Channing Corn (tests & fixes),
9 * - Andrew D. Balsa (code cleanup).
11 #include <linux/init.h>
12 #include <linux/utsname.h>
13 #include <linux/cpu.h>
14 #include <linux/module.h>
15 #include <linux/nospec.h>
16 #include <linux/prctl.h>
18 #include <asm/spec-ctrl.h>
19 #include <asm/cmdline.h>
21 #include <asm/processor.h>
22 #include <asm/processor-flags.h>
23 #include <asm/fpu/internal.h>
25 #include <asm/paravirt.h>
26 #include <asm/alternative.h>
27 #include <asm/pgtable.h>
28 #include <asm/set_memory.h>
29 #include <asm/intel-family.h>
31 static void __init
spectre_v2_select_mitigation(void);
32 static void __init
ssb_select_mitigation(void);
35 * Our boot-time value of the SPEC_CTRL MSR. We read it once so that any
36 * writes to SPEC_CTRL contain whatever reserved bits have been set.
38 u64 __ro_after_init x86_spec_ctrl_base
;
41 * The vendor and possibly platform specific bits which can be modified in
44 static u64 __ro_after_init x86_spec_ctrl_mask
= ~SPEC_CTRL_IBRS
;
47 * AMD specific MSR info for Speculative Store Bypass control.
48 * x86_amd_ls_cfg_ssbd_mask is initialized in identify_boot_cpu().
50 u64 __ro_after_init x86_amd_ls_cfg_base
;
51 u64 __ro_after_init x86_amd_ls_cfg_ssbd_mask
;
53 void __init
check_bugs(void)
57 if (!IS_ENABLED(CONFIG_SMP
)) {
59 print_cpu_info(&boot_cpu_data
);
63 * Read the SPEC_CTRL MSR to account for reserved bits which may
64 * have unknown values. AMD64_LS_CFG MSR is cached in the early AMD
65 * init code as it is not enumerated and depends on the family.
67 if (boot_cpu_has(X86_FEATURE_MSR_SPEC_CTRL
))
68 rdmsrl(MSR_IA32_SPEC_CTRL
, x86_spec_ctrl_base
);
70 /* Select the proper spectre mitigation before patching alternatives */
71 spectre_v2_select_mitigation();
74 * Select proper mitigation for any exposure to the Speculative Store
75 * Bypass vulnerability.
77 ssb_select_mitigation();
81 * Check whether we are able to run this kernel safely on SMP.
83 * - i386 is no longer supported.
84 * - In order to run on anything without a TSC, we need to be
85 * compiled for a i486.
87 if (boot_cpu_data
.x86
< 4)
88 panic("Kernel requires i486+ for 'invlpg' and other features");
90 init_utsname()->machine
[1] =
91 '0' + (boot_cpu_data
.x86
> 6 ? 6 : boot_cpu_data
.x86
);
92 alternative_instructions();
94 fpu__init_check_bugs();
95 #else /* CONFIG_X86_64 */
96 alternative_instructions();
99 * Make sure the first 2MB area is not mapped by huge pages
100 * There are typically fixed size MTRRs in there and overlapping
101 * MTRRs into large pages causes slow downs.
103 * Right now we don't do that with gbpages because there seems
104 * very little benefit for that case.
107 set_memory_4k((unsigned long)__va(0), 1);
111 /* The kernel command line selection */
112 enum spectre_v2_mitigation_cmd
{
115 SPECTRE_V2_CMD_FORCE
,
116 SPECTRE_V2_CMD_RETPOLINE
,
117 SPECTRE_V2_CMD_RETPOLINE_GENERIC
,
118 SPECTRE_V2_CMD_RETPOLINE_AMD
,
121 static const char *spectre_v2_strings
[] = {
122 [SPECTRE_V2_NONE
] = "Vulnerable",
123 [SPECTRE_V2_RETPOLINE_MINIMAL
] = "Vulnerable: Minimal generic ASM retpoline",
124 [SPECTRE_V2_RETPOLINE_MINIMAL_AMD
] = "Vulnerable: Minimal AMD ASM retpoline",
125 [SPECTRE_V2_RETPOLINE_GENERIC
] = "Mitigation: Full generic retpoline",
126 [SPECTRE_V2_RETPOLINE_AMD
] = "Mitigation: Full AMD retpoline",
130 #define pr_fmt(fmt) "Spectre V2 : " fmt
132 static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init
=
135 void x86_spec_ctrl_set(u64 val
)
137 if (val
& x86_spec_ctrl_mask
)
138 WARN_ONCE(1, "SPEC_CTRL MSR value 0x%16llx is unknown.\n", val
);
140 wrmsrl(MSR_IA32_SPEC_CTRL
, x86_spec_ctrl_base
| val
);
142 EXPORT_SYMBOL_GPL(x86_spec_ctrl_set
);
144 u64
x86_spec_ctrl_get_default(void)
146 u64 msrval
= x86_spec_ctrl_base
;
148 if (static_cpu_has(X86_FEATURE_SPEC_CTRL
))
149 msrval
|= ssbd_tif_to_spec_ctrl(current_thread_info()->flags
);
152 EXPORT_SYMBOL_GPL(x86_spec_ctrl_get_default
);
155 * x86_spec_ctrl_set_guest - Set speculation control registers for the guest
156 * @guest_spec_ctrl: The guest content of MSR_SPEC_CTRL
157 * @guest_virt_spec_ctrl: The guest controlled bits of MSR_VIRT_SPEC_CTRL
158 * (may get translated to MSR_AMD64_LS_CFG bits)
160 * Avoids writing to the MSR if the content/bits are the same
162 void x86_spec_ctrl_set_guest(u64 guest_spec_ctrl
, u64 guest_virt_spec_ctrl
)
164 u64 host
= x86_spec_ctrl_base
;
166 /* Is MSR_SPEC_CTRL implemented ? */
167 if (!static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL
))
170 /* SSBD controlled in MSR_SPEC_CTRL */
171 if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD
))
172 host
|= ssbd_tif_to_spec_ctrl(current_thread_info()->flags
);
174 if (host
!= guest_spec_ctrl
)
175 wrmsrl(MSR_IA32_SPEC_CTRL
, guest_spec_ctrl
);
177 EXPORT_SYMBOL_GPL(x86_spec_ctrl_set_guest
);
180 * x86_spec_ctrl_restore_host - Restore host speculation control registers
181 * @guest_spec_ctrl: The guest content of MSR_SPEC_CTRL
182 * @guest_virt_spec_ctrl: The guest controlled bits of MSR_VIRT_SPEC_CTRL
183 * (may get translated to MSR_AMD64_LS_CFG bits)
185 * Avoids writing to the MSR if the content/bits are the same
187 void x86_spec_ctrl_restore_host(u64 guest_spec_ctrl
, u64 guest_virt_spec_ctrl
)
189 u64 host
= x86_spec_ctrl_base
;
191 /* Is MSR_SPEC_CTRL implemented ? */
192 if (!static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL
))
195 /* SSBD controlled in MSR_SPEC_CTRL */
196 if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD
))
197 host
|= ssbd_tif_to_spec_ctrl(current_thread_info()->flags
);
199 if (host
!= guest_spec_ctrl
)
200 wrmsrl(MSR_IA32_SPEC_CTRL
, host
);
202 EXPORT_SYMBOL_GPL(x86_spec_ctrl_restore_host
);
204 static void x86_amd_ssb_disable(void)
206 u64 msrval
= x86_amd_ls_cfg_base
| x86_amd_ls_cfg_ssbd_mask
;
208 if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD
))
209 wrmsrl(MSR_AMD64_LS_CFG
, msrval
);
213 static bool spectre_v2_bad_module
;
215 bool retpoline_module_ok(bool has_retpoline
)
217 if (spectre_v2_enabled
== SPECTRE_V2_NONE
|| has_retpoline
)
220 pr_err("System may be vulnerable to spectre v2\n");
221 spectre_v2_bad_module
= true;
225 static inline const char *spectre_v2_module_string(void)
227 return spectre_v2_bad_module
? " - vulnerable module loaded" : "";
230 static inline const char *spectre_v2_module_string(void) { return ""; }
233 static void __init
spec2_print_if_insecure(const char *reason
)
235 if (boot_cpu_has_bug(X86_BUG_SPECTRE_V2
))
236 pr_info("%s selected on command line.\n", reason
);
239 static void __init
spec2_print_if_secure(const char *reason
)
241 if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2
))
242 pr_info("%s selected on command line.\n", reason
);
245 static inline bool retp_compiler(void)
247 return __is_defined(RETPOLINE
);
250 static inline bool match_option(const char *arg
, int arglen
, const char *opt
)
252 int len
= strlen(opt
);
254 return len
== arglen
&& !strncmp(arg
, opt
, len
);
257 static const struct {
259 enum spectre_v2_mitigation_cmd cmd
;
261 } mitigation_options
[] = {
262 { "off", SPECTRE_V2_CMD_NONE
, false },
263 { "on", SPECTRE_V2_CMD_FORCE
, true },
264 { "retpoline", SPECTRE_V2_CMD_RETPOLINE
, false },
265 { "retpoline,amd", SPECTRE_V2_CMD_RETPOLINE_AMD
, false },
266 { "retpoline,generic", SPECTRE_V2_CMD_RETPOLINE_GENERIC
, false },
267 { "auto", SPECTRE_V2_CMD_AUTO
, false },
270 static enum spectre_v2_mitigation_cmd __init
spectre_v2_parse_cmdline(void)
274 enum spectre_v2_mitigation_cmd cmd
= SPECTRE_V2_CMD_AUTO
;
276 if (cmdline_find_option_bool(boot_command_line
, "nospectre_v2"))
277 return SPECTRE_V2_CMD_NONE
;
279 ret
= cmdline_find_option(boot_command_line
, "spectre_v2", arg
, sizeof(arg
));
281 return SPECTRE_V2_CMD_AUTO
;
283 for (i
= 0; i
< ARRAY_SIZE(mitigation_options
); i
++) {
284 if (!match_option(arg
, ret
, mitigation_options
[i
].option
))
286 cmd
= mitigation_options
[i
].cmd
;
290 if (i
>= ARRAY_SIZE(mitigation_options
)) {
291 pr_err("unknown option (%s). Switching to AUTO select\n", arg
);
292 return SPECTRE_V2_CMD_AUTO
;
296 if ((cmd
== SPECTRE_V2_CMD_RETPOLINE
||
297 cmd
== SPECTRE_V2_CMD_RETPOLINE_AMD
||
298 cmd
== SPECTRE_V2_CMD_RETPOLINE_GENERIC
) &&
299 !IS_ENABLED(CONFIG_RETPOLINE
)) {
300 pr_err("%s selected but not compiled in. Switching to AUTO select\n", mitigation_options
[i
].option
);
301 return SPECTRE_V2_CMD_AUTO
;
304 if (cmd
== SPECTRE_V2_CMD_RETPOLINE_AMD
&&
305 boot_cpu_data
.x86_vendor
!= X86_VENDOR_AMD
) {
306 pr_err("retpoline,amd selected but CPU is not AMD. Switching to AUTO select\n");
307 return SPECTRE_V2_CMD_AUTO
;
310 if (mitigation_options
[i
].secure
)
311 spec2_print_if_secure(mitigation_options
[i
].option
);
313 spec2_print_if_insecure(mitigation_options
[i
].option
);
318 /* Check for Skylake-like CPUs (for RSB handling) */
319 static bool __init
is_skylake_era(void)
321 if (boot_cpu_data
.x86_vendor
== X86_VENDOR_INTEL
&&
322 boot_cpu_data
.x86
== 6) {
323 switch (boot_cpu_data
.x86_model
) {
324 case INTEL_FAM6_SKYLAKE_MOBILE
:
325 case INTEL_FAM6_SKYLAKE_DESKTOP
:
326 case INTEL_FAM6_SKYLAKE_X
:
327 case INTEL_FAM6_KABYLAKE_MOBILE
:
328 case INTEL_FAM6_KABYLAKE_DESKTOP
:
335 static void __init
spectre_v2_select_mitigation(void)
337 enum spectre_v2_mitigation_cmd cmd
= spectre_v2_parse_cmdline();
338 enum spectre_v2_mitigation mode
= SPECTRE_V2_NONE
;
341 * If the CPU is not affected and the command line mode is NONE or AUTO
342 * then nothing to do.
344 if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2
) &&
345 (cmd
== SPECTRE_V2_CMD_NONE
|| cmd
== SPECTRE_V2_CMD_AUTO
))
349 case SPECTRE_V2_CMD_NONE
:
352 case SPECTRE_V2_CMD_FORCE
:
353 case SPECTRE_V2_CMD_AUTO
:
354 if (IS_ENABLED(CONFIG_RETPOLINE
))
357 case SPECTRE_V2_CMD_RETPOLINE_AMD
:
358 if (IS_ENABLED(CONFIG_RETPOLINE
))
361 case SPECTRE_V2_CMD_RETPOLINE_GENERIC
:
362 if (IS_ENABLED(CONFIG_RETPOLINE
))
363 goto retpoline_generic
;
365 case SPECTRE_V2_CMD_RETPOLINE
:
366 if (IS_ENABLED(CONFIG_RETPOLINE
))
370 pr_err("Spectre mitigation: kernel not compiled with retpoline; no mitigation available!");
374 if (boot_cpu_data
.x86_vendor
== X86_VENDOR_AMD
) {
376 if (!boot_cpu_has(X86_FEATURE_LFENCE_RDTSC
)) {
377 pr_err("Spectre mitigation: LFENCE not serializing, switching to generic retpoline\n");
378 goto retpoline_generic
;
380 mode
= retp_compiler() ? SPECTRE_V2_RETPOLINE_AMD
:
381 SPECTRE_V2_RETPOLINE_MINIMAL_AMD
;
382 setup_force_cpu_cap(X86_FEATURE_RETPOLINE_AMD
);
383 setup_force_cpu_cap(X86_FEATURE_RETPOLINE
);
386 mode
= retp_compiler() ? SPECTRE_V2_RETPOLINE_GENERIC
:
387 SPECTRE_V2_RETPOLINE_MINIMAL
;
388 setup_force_cpu_cap(X86_FEATURE_RETPOLINE
);
391 spectre_v2_enabled
= mode
;
392 pr_info("%s\n", spectre_v2_strings
[mode
]);
395 * If neither SMEP nor PTI are available, there is a risk of
396 * hitting userspace addresses in the RSB after a context switch
397 * from a shallow call stack to a deeper one. To prevent this fill
398 * the entire RSB, even when using IBRS.
400 * Skylake era CPUs have a separate issue with *underflow* of the
401 * RSB, when they will predict 'ret' targets from the generic BTB.
402 * The proper mitigation for this is IBRS. If IBRS is not supported
403 * or deactivated in favour of retpolines the RSB fill on context
404 * switch is required.
406 if ((!boot_cpu_has(X86_FEATURE_PTI
) &&
407 !boot_cpu_has(X86_FEATURE_SMEP
)) || is_skylake_era()) {
408 setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW
);
409 pr_info("Spectre v2 mitigation: Filling RSB on context switch\n");
412 /* Initialize Indirect Branch Prediction Barrier if supported */
413 if (boot_cpu_has(X86_FEATURE_IBPB
)) {
414 setup_force_cpu_cap(X86_FEATURE_USE_IBPB
);
415 pr_info("Spectre v2 mitigation: Enabling Indirect Branch Prediction Barrier\n");
419 * Retpoline means the kernel is safe because it has no indirect
420 * branches. But firmware isn't, so use IBRS to protect that.
422 if (boot_cpu_has(X86_FEATURE_IBRS
)) {
423 setup_force_cpu_cap(X86_FEATURE_USE_IBRS_FW
);
424 pr_info("Enabling Restricted Speculation for firmware calls\n");
429 #define pr_fmt(fmt) "Speculative Store Bypass: " fmt
431 static enum ssb_mitigation ssb_mode __ro_after_init
= SPEC_STORE_BYPASS_NONE
;
433 /* The kernel command line selection */
434 enum ssb_mitigation_cmd
{
435 SPEC_STORE_BYPASS_CMD_NONE
,
436 SPEC_STORE_BYPASS_CMD_AUTO
,
437 SPEC_STORE_BYPASS_CMD_ON
,
438 SPEC_STORE_BYPASS_CMD_PRCTL
,
439 SPEC_STORE_BYPASS_CMD_SECCOMP
,
442 static const char *ssb_strings
[] = {
443 [SPEC_STORE_BYPASS_NONE
] = "Vulnerable",
444 [SPEC_STORE_BYPASS_DISABLE
] = "Mitigation: Speculative Store Bypass disabled",
445 [SPEC_STORE_BYPASS_PRCTL
] = "Mitigation: Speculative Store Bypass disabled via prctl",
446 [SPEC_STORE_BYPASS_SECCOMP
] = "Mitigation: Speculative Store Bypass disabled via prctl and seccomp",
449 static const struct {
451 enum ssb_mitigation_cmd cmd
;
452 } ssb_mitigation_options
[] = {
453 { "auto", SPEC_STORE_BYPASS_CMD_AUTO
}, /* Platform decides */
454 { "on", SPEC_STORE_BYPASS_CMD_ON
}, /* Disable Speculative Store Bypass */
455 { "off", SPEC_STORE_BYPASS_CMD_NONE
}, /* Don't touch Speculative Store Bypass */
456 { "prctl", SPEC_STORE_BYPASS_CMD_PRCTL
}, /* Disable Speculative Store Bypass via prctl */
457 { "seccomp", SPEC_STORE_BYPASS_CMD_SECCOMP
}, /* Disable Speculative Store Bypass via prctl and seccomp */
460 static enum ssb_mitigation_cmd __init
ssb_parse_cmdline(void)
462 enum ssb_mitigation_cmd cmd
= SPEC_STORE_BYPASS_CMD_AUTO
;
466 if (cmdline_find_option_bool(boot_command_line
, "nospec_store_bypass_disable")) {
467 return SPEC_STORE_BYPASS_CMD_NONE
;
469 ret
= cmdline_find_option(boot_command_line
, "spec_store_bypass_disable",
472 return SPEC_STORE_BYPASS_CMD_AUTO
;
474 for (i
= 0; i
< ARRAY_SIZE(ssb_mitigation_options
); i
++) {
475 if (!match_option(arg
, ret
, ssb_mitigation_options
[i
].option
))
478 cmd
= ssb_mitigation_options
[i
].cmd
;
482 if (i
>= ARRAY_SIZE(ssb_mitigation_options
)) {
483 pr_err("unknown option (%s). Switching to AUTO select\n", arg
);
484 return SPEC_STORE_BYPASS_CMD_AUTO
;
491 static enum ssb_mitigation __init
__ssb_select_mitigation(void)
493 enum ssb_mitigation mode
= SPEC_STORE_BYPASS_NONE
;
494 enum ssb_mitigation_cmd cmd
;
496 if (!boot_cpu_has(X86_FEATURE_SSBD
))
499 cmd
= ssb_parse_cmdline();
500 if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS
) &&
501 (cmd
== SPEC_STORE_BYPASS_CMD_NONE
||
502 cmd
== SPEC_STORE_BYPASS_CMD_AUTO
))
506 case SPEC_STORE_BYPASS_CMD_AUTO
:
507 case SPEC_STORE_BYPASS_CMD_SECCOMP
:
509 * Choose prctl+seccomp as the default mode if seccomp is
512 if (IS_ENABLED(CONFIG_SECCOMP
))
513 mode
= SPEC_STORE_BYPASS_SECCOMP
;
515 mode
= SPEC_STORE_BYPASS_PRCTL
;
517 case SPEC_STORE_BYPASS_CMD_ON
:
518 mode
= SPEC_STORE_BYPASS_DISABLE
;
520 case SPEC_STORE_BYPASS_CMD_PRCTL
:
521 mode
= SPEC_STORE_BYPASS_PRCTL
;
523 case SPEC_STORE_BYPASS_CMD_NONE
:
528 * We have three CPU feature flags that are in play here:
529 * - X86_BUG_SPEC_STORE_BYPASS - CPU is susceptible.
530 * - X86_FEATURE_SSBD - CPU is able to turn off speculative store bypass
531 * - X86_FEATURE_SPEC_STORE_BYPASS_DISABLE - engage the mitigation
533 if (mode
== SPEC_STORE_BYPASS_DISABLE
) {
534 setup_force_cpu_cap(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE
);
536 * Intel uses the SPEC CTRL MSR Bit(2) for this, while AMD uses
537 * a completely different MSR and bit dependent on family.
539 switch (boot_cpu_data
.x86_vendor
) {
540 case X86_VENDOR_INTEL
:
541 x86_spec_ctrl_base
|= SPEC_CTRL_SSBD
;
542 x86_spec_ctrl_mask
&= ~SPEC_CTRL_SSBD
;
543 x86_spec_ctrl_set(SPEC_CTRL_SSBD
);
546 x86_amd_ssb_disable();
554 static void ssb_select_mitigation(void)
556 ssb_mode
= __ssb_select_mitigation();
558 if (boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS
))
559 pr_info("%s\n", ssb_strings
[ssb_mode
]);
563 #define pr_fmt(fmt) "Speculation prctl: " fmt
565 static int ssb_prctl_set(struct task_struct
*task
, unsigned long ctrl
)
569 if (ssb_mode
!= SPEC_STORE_BYPASS_PRCTL
&&
570 ssb_mode
!= SPEC_STORE_BYPASS_SECCOMP
)
575 /* If speculation is force disabled, enable is not allowed */
576 if (task_spec_ssb_force_disable(task
))
578 task_clear_spec_ssb_disable(task
);
579 update
= test_and_clear_tsk_thread_flag(task
, TIF_SSBD
);
581 case PR_SPEC_DISABLE
:
582 task_set_spec_ssb_disable(task
);
583 update
= !test_and_set_tsk_thread_flag(task
, TIF_SSBD
);
585 case PR_SPEC_FORCE_DISABLE
:
586 task_set_spec_ssb_disable(task
);
587 task_set_spec_ssb_force_disable(task
);
588 update
= !test_and_set_tsk_thread_flag(task
, TIF_SSBD
);
595 * If being set on non-current task, delay setting the CPU
596 * mitigation until it is next scheduled.
598 if (task
== current
&& update
)
599 speculative_store_bypass_update();
604 int arch_prctl_spec_ctrl_set(struct task_struct
*task
, unsigned long which
,
608 case PR_SPEC_STORE_BYPASS
:
609 return ssb_prctl_set(task
, ctrl
);
615 #ifdef CONFIG_SECCOMP
616 void arch_seccomp_spec_mitigate(struct task_struct
*task
)
618 if (ssb_mode
== SPEC_STORE_BYPASS_SECCOMP
)
619 ssb_prctl_set(task
, PR_SPEC_FORCE_DISABLE
);
623 static int ssb_prctl_get(struct task_struct
*task
)
626 case SPEC_STORE_BYPASS_DISABLE
:
627 return PR_SPEC_DISABLE
;
628 case SPEC_STORE_BYPASS_SECCOMP
:
629 case SPEC_STORE_BYPASS_PRCTL
:
630 if (task_spec_ssb_force_disable(task
))
631 return PR_SPEC_PRCTL
| PR_SPEC_FORCE_DISABLE
;
632 if (task_spec_ssb_disable(task
))
633 return PR_SPEC_PRCTL
| PR_SPEC_DISABLE
;
634 return PR_SPEC_PRCTL
| PR_SPEC_ENABLE
;
636 if (boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS
))
637 return PR_SPEC_ENABLE
;
638 return PR_SPEC_NOT_AFFECTED
;
642 int arch_prctl_spec_ctrl_get(struct task_struct
*task
, unsigned long which
)
645 case PR_SPEC_STORE_BYPASS
:
646 return ssb_prctl_get(task
);
652 void x86_spec_ctrl_setup_ap(void)
654 if (boot_cpu_has(X86_FEATURE_MSR_SPEC_CTRL
))
655 x86_spec_ctrl_set(x86_spec_ctrl_base
& ~x86_spec_ctrl_mask
);
657 if (ssb_mode
== SPEC_STORE_BYPASS_DISABLE
)
658 x86_amd_ssb_disable();
663 static ssize_t
cpu_show_common(struct device
*dev
, struct device_attribute
*attr
,
664 char *buf
, unsigned int bug
)
666 if (!boot_cpu_has_bug(bug
))
667 return sprintf(buf
, "Not affected\n");
670 case X86_BUG_CPU_MELTDOWN
:
671 if (boot_cpu_has(X86_FEATURE_PTI
))
672 return sprintf(buf
, "Mitigation: PTI\n");
676 case X86_BUG_SPECTRE_V1
:
677 return sprintf(buf
, "Mitigation: __user pointer sanitization\n");
679 case X86_BUG_SPECTRE_V2
:
680 return sprintf(buf
, "%s%s%s%s\n", spectre_v2_strings
[spectre_v2_enabled
],
681 boot_cpu_has(X86_FEATURE_USE_IBPB
) ? ", IBPB" : "",
682 boot_cpu_has(X86_FEATURE_USE_IBRS_FW
) ? ", IBRS_FW" : "",
683 spectre_v2_module_string());
685 case X86_BUG_SPEC_STORE_BYPASS
:
686 return sprintf(buf
, "%s\n", ssb_strings
[ssb_mode
]);
692 return sprintf(buf
, "Vulnerable\n");
695 ssize_t
cpu_show_meltdown(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
697 return cpu_show_common(dev
, attr
, buf
, X86_BUG_CPU_MELTDOWN
);
700 ssize_t
cpu_show_spectre_v1(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
702 return cpu_show_common(dev
, attr
, buf
, X86_BUG_SPECTRE_V1
);
705 ssize_t
cpu_show_spectre_v2(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
707 return cpu_show_common(dev
, attr
, buf
, X86_BUG_SPECTRE_V2
);
710 ssize_t
cpu_show_spec_store_bypass(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
712 return cpu_show_common(dev
, attr
, buf
, X86_BUG_SPEC_STORE_BYPASS
);