Skip to content

Commit 26aae8c

Browse files
andyhhpsuryasaimadhu
authored andcommitted
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 <[email protected]> Signed-off-by: Borislav Petkov <[email protected]>
1 parent 7a05bc9 commit 26aae8c

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
#define X86_FEATURE_VIRT_SSBD (13*32+25) /* Virtualized Speculative Store Bypass Disable */
323323
#define X86_FEATURE_AMD_SSB_NO (13*32+26) /* "" Speculative Store Bypass is fixed in hardware. */
324324
#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 */
325326
#define X86_FEATURE_BRS (13*32+31) /* Branch Sampling available */
326327

327328
/* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */

arch/x86/kernel/cpu/amd.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -890,12 +890,21 @@ static void init_amd_zn(struct cpuinfo_x86 *c)
890890
node_reclaim_distance = 32;
891891
#endif
892892

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+
}
899908
}
900909

901910
static void init_amd(struct cpuinfo_x86 *c)

arch/x86/kernel/cpu/common.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,8 +1359,10 @@ static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)
13591359
!arch_cap_mmio_immune(ia32_cap))
13601360
setup_force_cpu_bug(X86_BUG_MMIO_STALE_DATA);
13611361

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+
}
13641366

13651367
if (cpu_matches(cpu_vuln_whitelist, NO_MELTDOWN))
13661368
return;

0 commit comments

Comments
 (0)