Skip to content

Commit 1115a85

Browse files
konradwilkKAGA-KOKO
authored andcommitted
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: Konrad Rzeszutek Wilk <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Ingo Molnar <[email protected]>
1 parent 7724397 commit 1115a85

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ static void __init ssb_select_mitigation(void);
3535
*/
3636
static u64 __ro_after_init x86_spec_ctrl_base;
3737

38+
/*
39+
* The vendor and possibly platform specific bits which can be modified in
40+
* x86_spec_ctrl_base.
41+
*/
42+
static u64 __ro_after_init x86_spec_ctrl_mask = ~SPEC_CTRL_IBRS;
43+
3844
void __init check_bugs(void)
3945
{
4046
identify_boot_cpu();
@@ -117,7 +123,7 @@ static enum spectre_v2_mitigation spectre_v2_enabled = SPECTRE_V2_NONE;
117123

118124
void x86_spec_ctrl_set(u64 val)
119125
{
120-
if (val & ~(SPEC_CTRL_IBRS | SPEC_CTRL_RDS))
126+
if (val & x86_spec_ctrl_mask)
121127
WARN_ONCE(1, "SPEC_CTRL MSR value 0x%16llx is unknown.\n", val);
122128
else
123129
wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base | val);
@@ -459,6 +465,7 @@ static enum ssb_mitigation_cmd __init __ssb_select_mitigation(void)
459465
switch (boot_cpu_data.x86_vendor) {
460466
case X86_VENDOR_INTEL:
461467
x86_spec_ctrl_base |= SPEC_CTRL_RDS;
468+
x86_spec_ctrl_mask &= ~SPEC_CTRL_RDS;
462469
x86_spec_ctrl_set(SPEC_CTRL_RDS);
463470
break;
464471
case X86_VENDOR_AMD:
@@ -482,7 +489,7 @@ static void ssb_select_mitigation()
482489
void x86_spec_ctrl_setup_ap(void)
483490
{
484491
if (boot_cpu_has(X86_FEATURE_IBRS))
485-
x86_spec_ctrl_set(x86_spec_ctrl_base & (SPEC_CTRL_IBRS | SPEC_CTRL_RDS));
492+
x86_spec_ctrl_set(x86_spec_ctrl_base & ~x86_spec_ctrl_mask);
486493
}
487494

488495
#ifdef CONFIG_SYSFS

0 commit comments

Comments
 (0)