Skip to content

Commit 968e9bc

Browse files
committed
x86: move ZMM exclusion list into CPU feature flag
Lift zmm_exclusion_list in aesni-intel_glue.c into the x86 CPU setup code, and add a new x86 CPU feature flag X86_FEATURE_PREFER_YMM that is set when the CPU is on this list. This allows other code in arch/x86/, such as the CRC library code, to apply the same exclusion list when deciding whether to execute 256-bit or 512-bit optimized functions. Note that full AVX512 support including ZMM registers is still exposed to userspace and is still supported for in-kernel use. This flag just indicates whether in-kernel code should prefer to use YMM registers. Acked-by: Ard Biesheuvel <[email protected]> Acked-by: Ingo Molnar <[email protected]> Acked-by: Keith Busch <[email protected]> Reviewed-by: "Martin K. Petersen" <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent 0645b24 commit 968e9bc

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

arch/x86/crypto/aesni-intel_glue.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,26 +1536,6 @@ DEFINE_GCM_ALGS(vaes_avx10_512, FLAG_AVX10_512,
15361536
AES_GCM_KEY_AVX10_SIZE, 800);
15371537
#endif /* CONFIG_AS_VAES && CONFIG_AS_VPCLMULQDQ */
15381538

1539-
/*
1540-
* This is a list of CPU models that are known to suffer from downclocking when
1541-
* zmm registers (512-bit vectors) are used. On these CPUs, the AES mode
1542-
* implementations with zmm registers won't be used by default. Implementations
1543-
* with ymm registers (256-bit vectors) will be used by default instead.
1544-
*/
1545-
static const struct x86_cpu_id zmm_exclusion_list[] = {
1546-
X86_MATCH_VFM(INTEL_SKYLAKE_X, 0),
1547-
X86_MATCH_VFM(INTEL_ICELAKE_X, 0),
1548-
X86_MATCH_VFM(INTEL_ICELAKE_D, 0),
1549-
X86_MATCH_VFM(INTEL_ICELAKE, 0),
1550-
X86_MATCH_VFM(INTEL_ICELAKE_L, 0),
1551-
X86_MATCH_VFM(INTEL_ICELAKE_NNPI, 0),
1552-
X86_MATCH_VFM(INTEL_TIGERLAKE_L, 0),
1553-
X86_MATCH_VFM(INTEL_TIGERLAKE, 0),
1554-
/* Allow Rocket Lake and later, and Sapphire Rapids and later. */
1555-
/* Also allow AMD CPUs (starting with Zen 4, the first with AVX-512). */
1556-
{},
1557-
};
1558-
15591539
static int __init register_avx_algs(void)
15601540
{
15611541
int err;
@@ -1600,7 +1580,7 @@ static int __init register_avx_algs(void)
16001580
if (err)
16011581
return err;
16021582

1603-
if (x86_match_cpu(zmm_exclusion_list)) {
1583+
if (boot_cpu_has(X86_FEATURE_PREFER_YMM)) {
16041584
int i;
16051585

16061586
aes_xts_alg_vaes_avx10_512.base.cra_priority = 1;

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@
483483
#define X86_FEATURE_AMD_FAST_CPPC (21*32 + 5) /* Fast CPPC */
484484
#define X86_FEATURE_AMD_HETEROGENEOUS_CORES (21*32 + 6) /* Heterogeneous Core Topology */
485485
#define X86_FEATURE_AMD_WORKLOAD_CLASS (21*32 + 7) /* Workload Classification */
486+
#define X86_FEATURE_PREFER_YMM (21*32 + 8) /* Avoid ZMM registers due to downclocking */
486487

487488
/*
488489
* BUG word(s)

arch/x86/kernel/cpu/intel.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,25 @@ static void init_intel_misc_features(struct cpuinfo_x86 *c)
521521
wrmsrl(MSR_MISC_FEATURES_ENABLES, msr);
522522
}
523523

524+
/*
525+
* This is a list of Intel CPUs that are known to suffer from downclocking when
526+
* ZMM registers (512-bit vectors) are used. On these CPUs, when the kernel
527+
* executes SIMD-optimized code such as cryptography functions or CRCs, it
528+
* should prefer 256-bit (YMM) code to 512-bit (ZMM) code.
529+
*/
530+
static const struct x86_cpu_id zmm_exclusion_list[] = {
531+
X86_MATCH_VFM(INTEL_SKYLAKE_X, 0),
532+
X86_MATCH_VFM(INTEL_ICELAKE_X, 0),
533+
X86_MATCH_VFM(INTEL_ICELAKE_D, 0),
534+
X86_MATCH_VFM(INTEL_ICELAKE, 0),
535+
X86_MATCH_VFM(INTEL_ICELAKE_L, 0),
536+
X86_MATCH_VFM(INTEL_ICELAKE_NNPI, 0),
537+
X86_MATCH_VFM(INTEL_TIGERLAKE_L, 0),
538+
X86_MATCH_VFM(INTEL_TIGERLAKE, 0),
539+
/* Allow Rocket Lake and later, and Sapphire Rapids and later. */
540+
{},
541+
};
542+
524543
static void init_intel(struct cpuinfo_x86 *c)
525544
{
526545
early_init_intel(c);
@@ -601,6 +620,9 @@ static void init_intel(struct cpuinfo_x86 *c)
601620
}
602621
#endif
603622

623+
if (x86_match_cpu(zmm_exclusion_list))
624+
set_cpu_cap(c, X86_FEATURE_PREFER_YMM);
625+
604626
/* Work around errata */
605627
srat_detect_node(c);
606628

0 commit comments

Comments
 (0)