diff options
Diffstat (limited to 'arch/x86/kernel/cpu/amd.c')
| -rw-r--r-- | arch/x86/kernel/cpu/amd.c | 46 | 
1 files changed, 39 insertions, 7 deletions
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 0c0b09796ced..35d5288394cb 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -862,6 +862,28 @@ static void init_amd_bd(struct cpuinfo_x86 *c)  	clear_rdrand_cpuid_bit(c);  } +void init_spectral_chicken(struct cpuinfo_x86 *c) +{ +#ifdef CONFIG_CPU_UNRET_ENTRY +	u64 value; + +	/* +	 * On Zen2 we offer this chicken (bit) on the altar of Speculation. +	 * +	 * This suppresses speculation from the middle of a basic block, i.e. it +	 * suppresses non-branch predictions. +	 * +	 * We use STIBP as a heuristic to filter out Zen2 from the rest of F17H +	 */ +	if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && cpu_has(c, X86_FEATURE_AMD_STIBP)) { +		if (!rdmsrl_safe(MSR_ZEN2_SPECTRAL_CHICKEN, &value)) { +			value |= MSR_ZEN2_SPECTRAL_CHICKEN_BIT; +			wrmsrl_safe(MSR_ZEN2_SPECTRAL_CHICKEN, value); +		} +	} +#endif +} +  static void init_amd_zn(struct cpuinfo_x86 *c)  {  	set_cpu_cap(c, X86_FEATURE_ZEN); @@ -870,12 +892,21 @@ static void init_amd_zn(struct cpuinfo_x86 *c)  	node_reclaim_distance = 32;  #endif -	/* -	 * Fix erratum 1076: CPB feature bit not being set in CPUID. -	 * Always set it, except when running under a hypervisor. -	 */ -	if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && !cpu_has(c, X86_FEATURE_CPB)) -		set_cpu_cap(c, X86_FEATURE_CPB); +	/* Fix up CPUID bits, but only if not virtualised. */ +	if (!cpu_has(c, X86_FEATURE_HYPERVISOR)) { + +		/* Erratum 1076: CPB feature bit not being set in CPUID. */ +		if (!cpu_has(c, X86_FEATURE_CPB)) +			set_cpu_cap(c, X86_FEATURE_CPB); + +		/* +		 * Zen3 (Fam19 model < 0x10) parts are not susceptible to +		 * Branch Type Confusion, but predate the allocation of the +		 * BTC_NO bit. +		 */ +		if (c->x86 == 0x19 && !cpu_has(c, X86_FEATURE_BTC_NO)) +			set_cpu_cap(c, X86_FEATURE_BTC_NO); +	}  }  static void init_amd(struct cpuinfo_x86 *c) @@ -907,7 +938,8 @@ static void init_amd(struct cpuinfo_x86 *c)  	case 0x12: init_amd_ln(c); break;  	case 0x15: init_amd_bd(c); break;  	case 0x16: init_amd_jg(c); break; -	case 0x17: fallthrough; +	case 0x17: init_spectral_chicken(c); +		   fallthrough;  	case 0x19: init_amd_zn(c); break;  	}  | 
