Skip to content

Commit 54fd120

Browse files
committed
x86/bugs/intel: Set proper CPU features and setup RDS
Intel CPUs expose methods to: - Detect whether RDS capability is available via CPUID.7.0.EDX[31], - The SPEC_CTRL MSR(0x48), bit 2 set to enable RDS. - MSR_IA32_ARCH_CAPABILITIES, Bit(4) no need to enable RRS. With that in mind if spec_store_bypass_disable=[auto,on] is selected set at boot-time the SPEC_CTRL MSR to enable RDS if the platform requires it. Note that this does not fix the KVM case where the SPEC_CTRL is exposed to guests which can muck with it, see patch titled : KVM/SVM/VMX/x86/spectre_v2: Support the combination of guest and host IBRS. And for the firmware (IBRS to be set), see patch titled: x86/spectre_v2: Read SPEC_CTRL MSR during boot and re-use reserved bits [ tglx: Distangled it from the intel implementation and kept the call order ] Signed-off-by: Konrad Rzeszutek Wilk <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Borislav Petkov <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> (cherry picked from commit 7724397) Orabug: 28034177 CVE: CVE-2018-3639 Signed-off-by: Konrad Rzeszutek Wilk <[email protected]> Tested-by: Mihai Carabas <[email protected]> Reviewed-by: Mihai Carabas <[email protected]> Reviewed-by: John Haxby <[email protected]> Conflicts: arch/x86/kernel/cpu/bugs.c [As we have u64 host that messes it up] --- v2: Ripped out the extra newline that came in.
1 parent e45f11c commit 54fd120

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

arch/x86/include/asm/msr-index.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#define SPEC_CTRL_IBRS (1 << 0)
4545
#define SPEC_CTRL_FEATURE_ENABLE_IBRS SPEC_CTRL_IBRS /* Indirect Branch Restricted Speculation */
4646
#define SPEC_CTRL_STIBP (1 << 1) /* Single Thread Indirect Branch Predictors */
47+
#define SPEC_CTRL_RDS (1 << 2) /* Reduced Data Speculation */
4748

4849
#define MSR_IA32_PRED_CMD 0x00000049 /* Prediction Command */
4950
#define PRED_CMD_IBPB (1 << 0) /* Indirect Branch Prediction Barrier */
@@ -70,6 +71,11 @@
7071
#define MSR_IA32_ARCH_CAPABILITIES 0x0000010a
7172
#define ARCH_CAP_RDCL_NO (1 << 0) /* Not susceptible to Meltdown */
7273
#define ARCH_CAP_IBRS_ALL (1 << 1) /* Enhanced IBRS support */
74+
#define ARCH_CAP_RDS_NO (1 << 4) /*
75+
* Not susceptible to Speculative Store Bypass
76+
* attack, so no Reduced Data Speculation control
77+
* required.
78+
*/
7379

7480
#define MSR_IA32_BBL_CR_CTL 0x00000119
7581
#define MSR_IA32_BBL_CR_CTL3 0x0000011e

arch/x86/kernel/cpu/bugs.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void x86_spec_ctrl_set(u64 val)
191191
{
192192
u64 host;
193193

194-
if (val & ~SPEC_CTRL_IBRS)
194+
if (val & ~(SPEC_CTRL_IBRS | SPEC_CTRL_RDS))
195195
WARN_ONCE(1, "SPEC_CTRL MSR value 0x%16llx is unknown.\n", val);
196196
else {
197197
/*
@@ -677,8 +677,28 @@ static enum ssb_mitigation_cmd __init __ssb_select_mitigation(void)
677677
break;
678678
}
679679

680-
if (mode != SPEC_STORE_BYPASS_NONE)
680+
/*
681+
* We have three CPU feature flags that are in play here:
682+
* - X86_BUG_SPEC_STORE_BYPASS - CPU is susceptible.
683+
* - X86_FEATURE_RDS - CPU is able to turn off speculative store bypass
684+
* - X86_FEATURE_SPEC_STORE_BYPASS_DISABLE - engage the mitigation
685+
*/
686+
if (mode != SPEC_STORE_BYPASS_NONE) {
681687
setup_force_cpu_cap(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE);
688+
/*
689+
* Intel uses the SPEC CTRL MSR Bit(2) for this, while AMD uses
690+
* a completely different MSR and bit dependent on family.
691+
*/
692+
switch (boot_cpu_data.x86_vendor) {
693+
case X86_VENDOR_INTEL:
694+
x86_spec_ctrl_base |= SPEC_CTRL_RDS;
695+
x86_spec_ctrl_set(SPEC_CTRL_RDS);
696+
break;
697+
case X86_VENDOR_AMD:
698+
break;
699+
}
700+
}
701+
682702
return mode;
683703
}
684704

@@ -692,6 +712,12 @@ static void ssb_select_mitigation()
692712

693713
#undef pr_fmt
694714

715+
void x86_spec_ctrl_setup_ap(void)
716+
{
717+
if (boot_cpu_has(X86_FEATURE_IBRS))
718+
x86_spec_ctrl_set(x86_spec_ctrl_base & (SPEC_CTRL_IBRS | SPEC_CTRL_RDS));
719+
}
720+
695721
#ifdef CONFIG_SYSFS
696722

697723
ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,

arch/x86/kernel/cpu/common.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,11 @@ static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)
976976
{
977977
u64 ia32_cap = 0;
978978

979-
if (!x86_match_cpu(cpu_no_spec_store_bypass))
979+
if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES))
980+
rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap);
981+
982+
if (!x86_match_cpu(cpu_no_spec_store_bypass) &&
983+
!(ia32_cap & ARCH_CAP_RDS_NO))
980984
setup_force_cpu_bug(X86_BUG_SPEC_STORE_BYPASS);
981985

982986
if (x86_match_cpu(cpu_no_speculation))
@@ -988,9 +992,6 @@ static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)
988992
if (x86_match_cpu(cpu_no_meltdown))
989993
return;
990994

991-
if (cpu_has(c, X86_FEATURE_ARCH_CAPABILITIES))
992-
rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap);
993-
994995
/* Rogue Data Cache Load? No! */
995996
if (ia32_cap & ARCH_CAP_RDCL_NO)
996997
return;
@@ -1404,6 +1405,7 @@ void identify_secondary_cpu(struct cpuinfo_x86 *c)
14041405
#endif
14051406
mtrr_ap_init();
14061407
validate_apic_and_package_id(c);
1408+
x86_spec_ctrl_setup_ap();
14071409
}
14081410

14091411
static __init int setup_noclflush(char *arg)

arch/x86/kernel/cpu/cpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ extern void cpu_detect_cache_sizes(struct cpuinfo_x86 *c);
5151

5252
unsigned int aperfmperf_get_khz(int cpu);
5353

54+
extern void x86_spec_ctrl_setup_ap(void);
55+
5456
#endif /* ARCH_X86_CPU_H */

arch/x86/kernel/cpu/intel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ static void early_init_intel(struct cpuinfo_x86 *c)
189189
setup_clear_cpu_cap(X86_FEATURE_STIBP);
190190
setup_clear_cpu_cap(X86_FEATURE_SPEC_CTRL);
191191
setup_clear_cpu_cap(X86_FEATURE_INTEL_STIBP);
192+
setup_clear_cpu_cap(X86_FEATURE_RDS);
192193
}
193194

194195
/*

0 commit comments

Comments
 (0)