Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/cpu/amd: Enumerate BTC_NO

BTC_NO indicates that hardware is not susceptible to Branch Type Confusion.

Zen3 CPUs don't suffer BTC.

Hypervisors are expected to synthesise BTC_NO when it is appropriate
given the migration pool, to prevent kernels using heuristics.

[ bp: Massage. ]

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Borislav Petkov <bp@suse.de>

authored by

Andrew Cooper and committed by
Borislav Petkov
26aae8cc 7a05bc95

+20 -8
+1
arch/x86/include/asm/cpufeatures.h
··· 322 322 #define X86_FEATURE_VIRT_SSBD (13*32+25) /* Virtualized Speculative Store Bypass Disable */ 323 323 #define X86_FEATURE_AMD_SSB_NO (13*32+26) /* "" Speculative Store Bypass is fixed in hardware. */ 324 324 #define X86_FEATURE_CPPC (13*32+27) /* Collaborative Processor Performance Control */ 325 + #define X86_FEATURE_BTC_NO (13*32+29) /* "" Not vulnerable to Branch Type Confusion */ 325 326 #define X86_FEATURE_BRS (13*32+31) /* Branch Sampling available */ 326 327 327 328 /* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */
+15 -6
arch/x86/kernel/cpu/amd.c
··· 890 890 node_reclaim_distance = 32; 891 891 #endif 892 892 893 - /* 894 - * Fix erratum 1076: CPB feature bit not being set in CPUID. 895 - * Always set it, except when running under a hypervisor. 896 - */ 897 - if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && !cpu_has(c, X86_FEATURE_CPB)) 898 - set_cpu_cap(c, X86_FEATURE_CPB); 893 + /* Fix up CPUID bits, but only if not virtualised. */ 894 + if (!cpu_has(c, X86_FEATURE_HYPERVISOR)) { 895 + 896 + /* Erratum 1076: CPB feature bit not being set in CPUID. */ 897 + if (!cpu_has(c, X86_FEATURE_CPB)) 898 + set_cpu_cap(c, X86_FEATURE_CPB); 899 + 900 + /* 901 + * Zen3 (Fam19 model < 0x10) parts are not susceptible to 902 + * Branch Type Confusion, but predate the allocation of the 903 + * BTC_NO bit. 904 + */ 905 + if (c->x86 == 0x19 && !cpu_has(c, X86_FEATURE_BTC_NO)) 906 + set_cpu_cap(c, X86_FEATURE_BTC_NO); 907 + } 899 908 } 900 909 901 910 static void init_amd(struct cpuinfo_x86 *c)
+4 -2
arch/x86/kernel/cpu/common.c
··· 1359 1359 !arch_cap_mmio_immune(ia32_cap)) 1360 1360 setup_force_cpu_bug(X86_BUG_MMIO_STALE_DATA); 1361 1361 1362 - if ((cpu_matches(cpu_vuln_blacklist, RETBLEED) || (ia32_cap & ARCH_CAP_RSBA))) 1363 - setup_force_cpu_bug(X86_BUG_RETBLEED); 1362 + if (!cpu_has(c, X86_FEATURE_BTC_NO)) { 1363 + if (cpu_matches(cpu_vuln_blacklist, RETBLEED) || (ia32_cap & ARCH_CAP_RSBA)) 1364 + setup_force_cpu_bug(X86_BUG_RETBLEED); 1365 + } 1364 1366 1365 1367 if (cpu_matches(cpu_vuln_whitelist, NO_MELTDOWN)) 1366 1368 return;