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