Commit 1115a859 authored by Konrad Rzeszutek Wilk's avatar Konrad Rzeszutek Wilk Committed by Thomas Gleixner

x86/bugs: Whitelist allowed SPEC_CTRL MSR values

Intel and AMD SPEC_CTRL (0x48) MSR semantics may differ in the
future (or in fact use different MSRs for the same functionality).

As such a run-time mechanism is required to whitelist the appropriate MSR
values.

[ tglx: Made the variable __ro_after_init ]
Signed-off-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarIngo Molnar <mingo@kernel.org>
parent 77243971
...@@ -35,6 +35,12 @@ static void __init ssb_select_mitigation(void); ...@@ -35,6 +35,12 @@ static void __init ssb_select_mitigation(void);
*/ */
static u64 __ro_after_init x86_spec_ctrl_base; static u64 __ro_after_init x86_spec_ctrl_base;
/*
* The vendor and possibly platform specific bits which can be modified in
* x86_spec_ctrl_base.
*/
static u64 __ro_after_init x86_spec_ctrl_mask = ~SPEC_CTRL_IBRS;
void __init check_bugs(void) void __init check_bugs(void)
{ {
identify_boot_cpu(); identify_boot_cpu();
...@@ -117,7 +123,7 @@ static enum spectre_v2_mitigation spectre_v2_enabled = SPECTRE_V2_NONE; ...@@ -117,7 +123,7 @@ static enum spectre_v2_mitigation spectre_v2_enabled = SPECTRE_V2_NONE;
void x86_spec_ctrl_set(u64 val) void x86_spec_ctrl_set(u64 val)
{ {
if (val & ~(SPEC_CTRL_IBRS | SPEC_CTRL_RDS)) if (val & x86_spec_ctrl_mask)
WARN_ONCE(1, "SPEC_CTRL MSR value 0x%16llx is unknown.\n", val); WARN_ONCE(1, "SPEC_CTRL MSR value 0x%16llx is unknown.\n", val);
else else
wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base | val); wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base | val);
...@@ -459,6 +465,7 @@ static enum ssb_mitigation_cmd __init __ssb_select_mitigation(void) ...@@ -459,6 +465,7 @@ static enum ssb_mitigation_cmd __init __ssb_select_mitigation(void)
switch (boot_cpu_data.x86_vendor) { switch (boot_cpu_data.x86_vendor) {
case X86_VENDOR_INTEL: case X86_VENDOR_INTEL:
x86_spec_ctrl_base |= SPEC_CTRL_RDS; x86_spec_ctrl_base |= SPEC_CTRL_RDS;
x86_spec_ctrl_mask &= ~SPEC_CTRL_RDS;
x86_spec_ctrl_set(SPEC_CTRL_RDS); x86_spec_ctrl_set(SPEC_CTRL_RDS);
break; break;
case X86_VENDOR_AMD: case X86_VENDOR_AMD:
...@@ -482,7 +489,7 @@ static void ssb_select_mitigation() ...@@ -482,7 +489,7 @@ static void ssb_select_mitigation()
void x86_spec_ctrl_setup_ap(void) void x86_spec_ctrl_setup_ap(void)
{ {
if (boot_cpu_has(X86_FEATURE_IBRS)) if (boot_cpu_has(X86_FEATURE_IBRS))
x86_spec_ctrl_set(x86_spec_ctrl_base & (SPEC_CTRL_IBRS | SPEC_CTRL_RDS)); x86_spec_ctrl_set(x86_spec_ctrl_base & ~x86_spec_ctrl_mask);
} }
#ifdef CONFIG_SYSFS #ifdef CONFIG_SYSFS
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment