diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2021-03-19 06:15:37 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2021-03-29 06:04:17 -0700 |
commit | 27f74636752d0c4438cf8346cf2a76b6fcf3be16 (patch) | |
tree | d3710a44e90b6e6ab090a7de68b3437e41280b1f /sysdeps/x86 | |
parent | cb882b21b63606aabd6e55afe23b42434d95f2ef (diff) | |
download | glibc-27f74636752d0c4438cf8346cf2a76b6fcf3be16.zip glibc-27f74636752d0c4438cf8346cf2a76b6fcf3be16.tar.gz glibc-27f74636752d0c4438cf8346cf2a76b6fcf3be16.tar.bz2 |
x86: Properly disable XSAVE related features [BZ #27605]
1. Support GLIBC_TUNABLES=glibc.cpu.hwcaps=-XSAVE.
2. Disable all features which depend on XSAVE:
a. If OSXSAVE is disabled by glibc tunables. Or
b. If both XSAVE and XSAVEC aren't usable.
Diffstat (limited to 'sysdeps/x86')
-rw-r--r-- | sysdeps/x86/cpu-features.c | 55 | ||||
-rw-r--r-- | sysdeps/x86/cpu-tunables.c | 1 |
2 files changed, 56 insertions, 0 deletions
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index d7248cb..e99e67f 100644 --- a/sysdeps/x86/cpu-features.c +++ b/sysdeps/x86/cpu-features.c @@ -654,6 +654,61 @@ no_cpuid: #if HAVE_TUNABLES TUNABLE_GET (hwcaps, tunable_val_t *, TUNABLE_CALLBACK (set_hwcaps)); + + bool disable_xsave_features = false; + + if (!CPU_FEATURE_USABLE_P (cpu_features, OSXSAVE)) + { + /* These features are usable only if OSXSAVE is usable. */ + CPU_FEATURE_UNSET (cpu_features, XSAVE); + CPU_FEATURE_UNSET (cpu_features, XSAVEOPT); + CPU_FEATURE_UNSET (cpu_features, XSAVEC); + CPU_FEATURE_UNSET (cpu_features, XGETBV_ECX_1); + CPU_FEATURE_UNSET (cpu_features, XFD); + + disable_xsave_features = true; + } + + if (disable_xsave_features + || (!CPU_FEATURE_USABLE_P (cpu_features, XSAVE) + && !CPU_FEATURE_USABLE_P (cpu_features, XSAVEC))) + { + /* Clear xsave_state_size if both XSAVE and XSAVEC aren't usable. */ + cpu_features->xsave_state_size = 0; + + CPU_FEATURE_UNSET (cpu_features, AVX); + CPU_FEATURE_UNSET (cpu_features, AVX2); + CPU_FEATURE_UNSET (cpu_features, AVX_VNNI); + CPU_FEATURE_UNSET (cpu_features, FMA); + CPU_FEATURE_UNSET (cpu_features, VAES); + CPU_FEATURE_UNSET (cpu_features, VPCLMULQDQ); + CPU_FEATURE_UNSET (cpu_features, XOP); + CPU_FEATURE_UNSET (cpu_features, F16C); + CPU_FEATURE_UNSET (cpu_features, AVX512F); + CPU_FEATURE_UNSET (cpu_features, AVX512CD); + CPU_FEATURE_UNSET (cpu_features, AVX512ER); + CPU_FEATURE_UNSET (cpu_features, AVX512PF); + CPU_FEATURE_UNSET (cpu_features, AVX512VL); + CPU_FEATURE_UNSET (cpu_features, AVX512DQ); + CPU_FEATURE_UNSET (cpu_features, AVX512BW); + CPU_FEATURE_UNSET (cpu_features, AVX512_4FMAPS); + CPU_FEATURE_UNSET (cpu_features, AVX512_4VNNIW); + CPU_FEATURE_UNSET (cpu_features, AVX512_BITALG); + CPU_FEATURE_UNSET (cpu_features, AVX512_IFMA); + CPU_FEATURE_UNSET (cpu_features, AVX512_VBMI); + CPU_FEATURE_UNSET (cpu_features, AVX512_VBMI2); + CPU_FEATURE_UNSET (cpu_features, AVX512_VNNI); + CPU_FEATURE_UNSET (cpu_features, AVX512_VPOPCNTDQ); + CPU_FEATURE_UNSET (cpu_features, AVX512_VP2INTERSECT); + CPU_FEATURE_UNSET (cpu_features, AVX512_BF16); + CPU_FEATURE_UNSET (cpu_features, AVX512_FP16); + CPU_FEATURE_UNSET (cpu_features, AMX_BF16); + CPU_FEATURE_UNSET (cpu_features, AMX_TILE); + CPU_FEATURE_UNSET (cpu_features, AMX_INT8); + + CPU_FEATURE_UNSET (cpu_features, FMA4); + } + #elif defined SHARED /* Reuse dl_platform, dl_hwcap and dl_hwcap_mask for x86. The glibc.cpu.hwcap_mask tunable is initialized already, so no diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c index 126896f..61b05e5 100644 --- a/sysdeps/x86/cpu-tunables.c +++ b/sysdeps/x86/cpu-tunables.c @@ -168,6 +168,7 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp) CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, MOVBE, 5); CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, SHSTK, 5); CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, SSSE3, 5); + CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, XSAVE, 5); } break; case 6: |