179894
Based on the following commit, adjusted for glibc-2.28 in RHEL-8:
179894
179894
commit 27f74636752d0c4438cf8346cf2a76b6fcf3be16
179894
Author: H.J. Lu <hjl.tools@gmail.com>
179894
Date:   Fri Mar 19 06:15:37 2021 -0700
179894
179894
    x86: Properly disable XSAVE related features [BZ #27605]
179894
    
179894
    1. Support GLIBC_TUNABLES=glibc.cpu.hwcaps=-XSAVE.
179894
    2. Disable all features which depend on XSAVE:
179894
       a. If OSXSAVE is disabled by glibc tunables.  Or
179894
       b. If both XSAVE and XSAVEC aren't usable.
179894
179894
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
179894
index 805d00a43309fc23..910425053d9e226f 100644
179894
--- a/sysdeps/x86/cpu-features.c
179894
+++ b/sysdeps/x86/cpu-features.c
179894
@@ -654,6 +654,60 @@ no_cpuid:
179894
     = TUNABLE_GET (x86_data_cache_size, long int, NULL);
179894
   cpu_features->shared_cache_size
179894
     = TUNABLE_GET (x86_shared_cache_size, long int, NULL);
179894
+
179894
+  bool disable_xsave_features = false;
179894
+
179894
+  if (!CPU_FEATURE_USABLE_P (cpu_features, OSXSAVE))
179894
+    {
179894
+      /* These features are usable only if OSXSAVE is usable.  */
179894
+      CPU_FEATURE_UNSET (cpu_features, XSAVE);
179894
+      CPU_FEATURE_UNSET (cpu_features, XSAVEOPT);
179894
+      CPU_FEATURE_UNSET (cpu_features, XSAVEC);
179894
+      CPU_FEATURE_UNSET (cpu_features, XGETBV_ECX_1);
179894
+      CPU_FEATURE_UNSET (cpu_features, XFD);
179894
+
179894
+      disable_xsave_features = true;
179894
+    }
179894
+
179894
+  if (disable_xsave_features
179894
+      || (!CPU_FEATURE_USABLE_P (cpu_features, XSAVE)
179894
+	  && !CPU_FEATURE_USABLE_P (cpu_features, XSAVEC)))
179894
+    {
179894
+      /* Clear xsave_state_size if both XSAVE and XSAVEC aren't usable.  */
179894
+      cpu_features->xsave_state_size = 0;
179894
+
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX2);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX_VNNI);
179894
+      CPU_FEATURE_UNSET (cpu_features, FMA);
179894
+      CPU_FEATURE_UNSET (cpu_features, VAES);
179894
+      CPU_FEATURE_UNSET (cpu_features, VPCLMULQDQ);
179894
+      CPU_FEATURE_UNSET (cpu_features, XOP);
179894
+      CPU_FEATURE_UNSET (cpu_features, F16C);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512F);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512CD);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512ER);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512PF);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512VL);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512DQ);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512BW);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512_4FMAPS);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512_4VNNIW);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512_BITALG);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512_IFMA);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VBMI);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VBMI2);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VNNI);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VPOPCNTDQ);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512_VP2INTERSECT);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512_BF16);
179894
+      CPU_FEATURE_UNSET (cpu_features, AVX512_FP16);
179894
+      CPU_FEATURE_UNSET (cpu_features, AMX_BF16);
179894
+      CPU_FEATURE_UNSET (cpu_features, AMX_TILE);
179894
+      CPU_FEATURE_UNSET (cpu_features, AMX_INT8);
179894
+
179894
+      CPU_FEATURE_UNSET (cpu_features, FMA4);
179894
+    }
179894
 #endif
179894
 
179894
   /* Reuse dl_platform, dl_hwcap and dl_hwcap_mask for x86.  */
179894
diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c
179894
index 0728023007a0f423..3173b2b959ca88f9 100644
179894
--- a/sysdeps/x86/cpu-tunables.c
179894
+++ b/sysdeps/x86/cpu-tunables.c
179894
@@ -168,6 +168,7 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp)
179894
 	      CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, MOVBE, 5);
179894
 	      CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, SHSTK, 5);
179894
 	      CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, SSSE3, 5);
179894
+	      CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, XSAVE, 5);
179894
 	    }
179894
 	  break;
179894
 	case 6: