History

x86/cpu/amd: Add Spectral Chicken

Zen2 uarchs have an undocumented, unnamed, MSR that contains a chicken bit for some speculation behaviour. It needs setting. Note: very belatedly AMD released naming; it's now officially called MSR_AMD64_DE_CFG2 and MSR_AMD64_DE_CFG2_SUPPRESS_NOBR_PRED_BIT but shall remain the SPECTRAL CHICKEN.

Peter Zijlstra committed 4 years ago

Commit d7caac91 parent a09a6e24 files · +33 −1Browse files

Unified · Split

4 files
  1. arch/x86/include/asm/msr-index.h +3 −0
  2. arch/x86/kernel/cpu/amd.c +22 −1
  3. arch/x86/kernel/cpu/cpu.h +2 −0
  4. arch/x86/kernel/cpu/hygon.c +6 −0
arch/x86/include/asm/msr-index.h+3−0
@@ -568,6 +568,9 @@ · 567 unmodified lines
568/* Fam 17h MSRs */568/* Fam 17h MSRs */
569#define MSR_F17H_IRPERF 0xc00000e9569#define MSR_F17H_IRPERF 0xc00000e9
570 570
571#define MSR_ZEN2_SPECTRAL_CHICKEN 0xc00110e3
572#define MSR_ZEN2_SPECTRAL_CHICKEN_BIT BIT_ULL(1)
573
571/* Fam 16h MSRs */574/* Fam 16h MSRs */
572#define MSR_F16H_L2I_PERF_CTL 0xc0010230575#define MSR_F16H_L2I_PERF_CTL 0xc0010230
573#define MSR_F16H_L2I_PERF_CTR 0xc0010231576#define MSR_F16H_L2I_PERF_CTR 0xc0010231
arch/x86/kernel/cpu/amd.c+22−1
@@ -862,6 +862,26 @@ static void init_amd_bd(struct cpuinfo_x86 *c) · 861 unmodified lines
862 clear_rdrand_cpuid_bit(c);862 clear_rdrand_cpuid_bit(c);
863}863}
864 864
865void init_spectral_chicken(struct cpuinfo_x86 *c)
866{
867 u64 value;
868
869 /*
870 * On Zen2 we offer this chicken (bit) on the altar of Speculation.
871 *
872 * This suppresses speculation from the middle of a basic block, i.e. it
873 * suppresses non-branch predictions.
874 *
875 * We use STIBP as a heuristic to filter out Zen2 from the rest of F17H
876 */
877 if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && cpu_has(c, X86_FEATURE_AMD_STIBP)) {
878 if (!rdmsrl_safe(MSR_ZEN2_SPECTRAL_CHICKEN, &value)) {
879 value |= MSR_ZEN2_SPECTRAL_CHICKEN_BIT;
880 wrmsrl_safe(MSR_ZEN2_SPECTRAL_CHICKEN, value);
881 }
882 }
883}
884
865static void init_amd_zn(struct cpuinfo_x86 *c)885static void init_amd_zn(struct cpuinfo_x86 *c)
866{886{
867 set_cpu_cap(c, X86_FEATURE_ZEN);887 set_cpu_cap(c, X86_FEATURE_ZEN);
@@ -907,7 +927,8 @@ static void init_amd(struct cpuinfo_x86 *c) · 39 unmodified lines
907 case 0x12: init_amd_ln(c); break;927 case 0x12: init_amd_ln(c); break;
908 case 0x15: init_amd_bd(c); break;928 case 0x15: init_amd_bd(c); break;
909 case 0x16: init_amd_jg(c); break;929 case 0x16: init_amd_jg(c); break;
910 case 0x17: fallthrough;930 case 0x17: init_spectral_chicken(c);
931 fallthrough;
911 case 0x19: init_amd_zn(c); break;932 case 0x19: init_amd_zn(c); break;
912 }933 }
913 934
arch/x86/kernel/cpu/cpu.h+2−0
@@ -61,6 +61,8 @@ static inline void tsx_init(void) { } · 60 unmodified lines
61static inline void tsx_ap_init(void) { }61static inline void tsx_ap_init(void) { }
62#endif /* CONFIG_CPU_SUP_INTEL */62#endif /* CONFIG_CPU_SUP_INTEL */
63 63
64extern void init_spectral_chicken(struct cpuinfo_x86 *c);
65
64extern void get_cpu_cap(struct cpuinfo_x86 *c);66extern void get_cpu_cap(struct cpuinfo_x86 *c);
65extern void get_cpu_address_sizes(struct cpuinfo_x86 *c);67extern void get_cpu_address_sizes(struct cpuinfo_x86 *c);
66extern void cpu_detect_cache_sizes(struct cpuinfo_x86 *c);68extern void cpu_detect_cache_sizes(struct cpuinfo_x86 *c);
arch/x86/kernel/cpu/hygon.c+6−0
@@ -302,6 +302,12 @@ static void init_hygon(struct cpuinfo_x86 *c) · 301 unmodified lines
302 /* get apicid instead of initial apic id from cpuid */302 /* get apicid instead of initial apic id from cpuid */
303 c->apicid = hard_smp_processor_id();303 c->apicid = hard_smp_processor_id();
304 304
305 /*
306 * XXX someone from Hygon needs to confirm this DTRT
307 *
308 init_spectral_chicken(c);
309 */
310
305 set_cpu_cap(c, X86_FEATURE_ZEN);311 set_cpu_cap(c, X86_FEATURE_ZEN);
306 set_cpu_cap(c, X86_FEATURE_CPB);312 set_cpu_cap(c, X86_FEATURE_CPB);
307 313

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t