00db10
commit 2702856bf45c82cf8e69f2064f5aa15c0ceb6359
00db10
Author: Andrew Senkevich <andrew.senkevich@intel.com>
00db10
Date:   Mon Dec 19 13:20:31 2016 +0300
00db10
00db10
    Disable TSX on some Haswell processors.
00db10
    
00db10
    Patch disables Intel TSX on some Haswell processors to avoid TSX
00db10
    on kernels that weren't updated with the latest microcode package
00db10
    (which disables broken feature by default).
00db10
    
00db10
        * sysdeps/x86/cpu-features.c (get_common_indeces): Add
00db10
        stepping identification.
00db10
        (init_cpu_features): Add handle of Haswell.
00db10
00db10
Index: glibc-2.17-c758a686/sysdeps/x86/cpu-features.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/sysdeps/x86/cpu-features.c
00db10
+++ glibc-2.17-c758a686/sysdeps/x86/cpu-features.c
00db10
@@ -21,7 +21,8 @@
00db10
 
00db10
 static inline void
00db10
 get_common_indeces (struct cpu_features *cpu_features,
00db10
-		    unsigned int *family, unsigned int *model)
00db10
+		    unsigned int *family, unsigned int *model,
00db10
+		    unsigned int *stepping)
00db10
 {
00db10
   unsigned int eax;
00db10
   __cpuid (1, eax, cpu_features->cpuid[COMMON_CPUID_INDEX_1].ebx,
00db10
@@ -30,6 +31,7 @@ get_common_indeces (struct cpu_features
00db10
   GLRO(dl_x86_cpu_features).cpuid[COMMON_CPUID_INDEX_1].eax = eax;
00db10
   *family = (eax >> 8) & 0x0f;
00db10
   *model = (eax >> 4) & 0x0f;
00db10
+  *stepping = eax & 0x0f;
00db10
 }
00db10
 
00db10
 static inline void
00db10
@@ -45,9 +47,11 @@ init_cpu_features (struct cpu_features *
00db10
   /* This spells out "GenuineIntel".  */
00db10
   if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69)
00db10
     {
00db10
+      unsigned int stepping;
00db10
+
00db10
       kind = arch_kind_intel;
00db10
 
00db10
-      get_common_indeces (cpu_features, &family, &model);
00db10
+      get_common_indeces (cpu_features, &family, &model, &stepping);
00db10
 
00db10
       /* Intel processors prefer SSE instruction for memory/string
00db10
         routines if they are available.  */
00db10
@@ -128,6 +132,20 @@ init_cpu_features (struct cpu_features *
00db10
 		    | bit_Fast_Unaligned_Load
00db10
 		    | bit_Prefer_PMINUB_for_stringop);
00db10
 	      break;
00db10
+
00db10
+	    case 0x3f:
00db10
+	      /* Xeon E7 v3 with stepping >= 4 has working TSX.  */
00db10
+	      if (stepping >= 4)
00db10
+		break;
00db10
+	    case 0x3c:
00db10
+	    case 0x45:
00db10
+	    case 0x46:
00db10
+	      /* Disable Intel TSX on Haswell processors (except Xeon E7 v3
00db10
+		 with stepping >= 4) to avoid TSX on kernels that weren't
00db10
+		 updated with the latest microcode package (which disables
00db10
+		 broken feature by default).  */
00db10
+	      cpu_features->cpuid[COMMON_CPUID_INDEX_7].ebx &= ~(bit_RTM);
00db10
+	      break;
00db10
 	    }
00db10
 	}
00db10
 
00db10
@@ -148,9 +166,11 @@ init_cpu_features (struct cpu_features *
00db10
   /* This spells out "AuthenticAMD".  */
00db10
   else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65)
00db10
     {
00db10
+      unsigned int stepping;
00db10
+
00db10
       kind = arch_kind_amd;
00db10
 
00db10
-      get_common_indeces (cpu_features, &family, &model);
00db10
+      get_common_indeces (cpu_features, &family, &model, &stepping);
00db10
 
00db10
       ecx = cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx;
00db10