Skip to content

Commit 7eb8956

Browse files
committed
x86/cpufeatures: Disentangle MSR_SPEC_CTRL enumeration from IBRS
The availability of the SPEC_CTRL MSR is enumerated by a CPUID bit on Intel and implied by IBRS or STIBP support on AMD. That's just confusing and in case an AMD CPU has IBRS not supported because the underlying problem has been fixed but has another bit valid in the SPEC_CTRL MSR, the thing falls apart. Add a synthetic feature bit X86_FEATURE_MSR_SPEC_CTRL to denote the availability on both Intel and AMD. While at it replace the boot_cpu_has() checks with static_cpu_has() where possible. This prevents late microcode loading from exposing SPEC_CTRL, but late loading is already very limited as it does not reevaluate the mitigation options and other bits and pieces. Having static_cpu_has() is the simplest and least fragile solution. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Borislav Petkov <bp@suse.de> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
1 parent e7c587d commit 7eb8956

4 files changed

Lines changed: 20 additions & 9 deletions

File tree

‎arch/x86/include/asm/cpufeatures.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
#define X86_FEATURE_RETPOLINE_AMD ( 7*32+13) /* "" AMD Retpoline mitigation for Spectre variant 2 */
207207
#define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */
208208
#define X86_FEATURE_CDP_L2 ( 7*32+15) /* Code and Data Prioritization L2 */
209+
#define X86_FEATURE_MSR_SPEC_CTRL ( 7*32+16) /* "" MSR SPEC_CTRL is implemented */
209210

210211
#define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */
211212
#define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* "" Fill RSB on context switches */

‎arch/x86/kernel/cpu/bugs.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void __init check_bugs(void)
6464
* have unknown values. AMD64_LS_CFG MSR is cached in the early AMD
6565
* init code as it is not enumerated and depends on the family.
6666
*/
67-
if (boot_cpu_has(X86_FEATURE_IBRS))
67+
if (boot_cpu_has(X86_FEATURE_MSR_SPEC_CTRL))
6868
rdmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
6969

7070
/* Select the proper spectre mitigation before patching alternatives */
@@ -145,7 +145,7 @@ u64 x86_spec_ctrl_get_default(void)
145145
{
146146
u64 msrval = x86_spec_ctrl_base;
147147

148-
if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
148+
if (static_cpu_has(X86_FEATURE_SPEC_CTRL))
149149
msrval |= ssbd_tif_to_spec_ctrl(current_thread_info()->flags);
150150
return msrval;
151151
}
@@ -155,10 +155,12 @@ void x86_spec_ctrl_set_guest(u64 guest_spec_ctrl)
155155
{
156156
u64 host = x86_spec_ctrl_base;
157157

158-
if (!boot_cpu_has(X86_FEATURE_IBRS))
158+
/* Is MSR_SPEC_CTRL implemented ? */
159+
if (!static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL))
159160
return;
160161

161-
if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
162+
/* Intel controls SSB in MSR_SPEC_CTRL */
163+
if (static_cpu_has(X86_FEATURE_SPEC_CTRL))
162164
host |= ssbd_tif_to_spec_ctrl(current_thread_info()->flags);
163165

164166
if (host != guest_spec_ctrl)
@@ -170,10 +172,12 @@ void x86_spec_ctrl_restore_host(u64 guest_spec_ctrl)
170172
{
171173
u64 host = x86_spec_ctrl_base;
172174

173-
if (!boot_cpu_has(X86_FEATURE_IBRS))
175+
/* Is MSR_SPEC_CTRL implemented ? */
176+
if (!static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL))
174177
return;
175178

176-
if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
179+
/* Intel controls SSB in MSR_SPEC_CTRL */
180+
if (static_cpu_has(X86_FEATURE_SPEC_CTRL))
177181
host |= ssbd_tif_to_spec_ctrl(current_thread_info()->flags);
178182

179183
if (host != guest_spec_ctrl)
@@ -631,7 +635,7 @@ int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which)
631635

632636
void x86_spec_ctrl_setup_ap(void)
633637
{
634-
if (boot_cpu_has(X86_FEATURE_IBRS))
638+
if (boot_cpu_has(X86_FEATURE_MSR_SPEC_CTRL))
635639
x86_spec_ctrl_set(x86_spec_ctrl_base & ~x86_spec_ctrl_mask);
636640

637641
if (ssb_mode == SPEC_STORE_BYPASS_DISABLE)

‎arch/x86/kernel/cpu/common.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,19 +761,24 @@ static void init_speculation_control(struct cpuinfo_x86 *c)
761761
if (cpu_has(c, X86_FEATURE_SPEC_CTRL)) {
762762
set_cpu_cap(c, X86_FEATURE_IBRS);
763763
set_cpu_cap(c, X86_FEATURE_IBPB);
764+
set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL);
764765
}
765766

766767
if (cpu_has(c, X86_FEATURE_INTEL_STIBP))
767768
set_cpu_cap(c, X86_FEATURE_STIBP);
768769

769-
if (cpu_has(c, X86_FEATURE_AMD_IBRS))
770+
if (cpu_has(c, X86_FEATURE_AMD_IBRS)) {
770771
set_cpu_cap(c, X86_FEATURE_IBRS);
772+
set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL);
773+
}
771774

772775
if (cpu_has(c, X86_FEATURE_AMD_IBPB))
773776
set_cpu_cap(c, X86_FEATURE_IBPB);
774777

775-
if (cpu_has(c, X86_FEATURE_AMD_STIBP))
778+
if (cpu_has(c, X86_FEATURE_AMD_STIBP)) {
776779
set_cpu_cap(c, X86_FEATURE_STIBP);
780+
set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL);
781+
}
777782
}
778783

779784
void get_cpu_cap(struct cpuinfo_x86 *c)

‎arch/x86/kernel/cpu/intel.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ static void early_init_intel(struct cpuinfo_x86 *c)
188188
setup_clear_cpu_cap(X86_FEATURE_IBPB);
189189
setup_clear_cpu_cap(X86_FEATURE_STIBP);
190190
setup_clear_cpu_cap(X86_FEATURE_SPEC_CTRL);
191+
setup_clear_cpu_cap(X86_FEATURE_MSR_SPEC_CTRL);
191192
setup_clear_cpu_cap(X86_FEATURE_INTEL_STIBP);
192193
setup_clear_cpu_cap(X86_FEATURE_SSBD);
193194
}

0 commit comments

Comments
 (0)