190885
From 81174145d5f7b76744c8f635165e88735a944fca Mon Sep 17 00:00:00 2001
190885
From: "H.J. Lu" <hjl.tools@gmail.com>
190885
Date: Wed, 2 Mar 2022 14:45:02 -0800
190885
Subject: [PATCH] x86: Check RTM_ALWAYS_ABORT for RTM [BZ #28033]
190885
190885
From
190885
190885
https://www.intel.com/content/www/us/en/support/articles/000059422/processors.html
190885
190885
* Intel TSX will be disabled by default.
190885
* The processor will force abort all Restricted Transactional Memory (RTM)
190885
  transactions by default.
190885
* A new CPUID bit CPUID.07H.0H.EDX[11](RTM_ALWAYS_ABORT) will be enumerated,
190885
  which is set to indicate to updated software that the loaded microcode is
190885
  forcing RTM abort.
190885
* On processors that enumerate support for RTM, the CPUID enumeration bits
190885
  for Intel TSX (CPUID.07H.0H.EBX[11] and CPUID.07H.0H.EBX[4]) continue to
190885
  be set by default after microcode update.
190885
* Workloads that were benefited from Intel TSX might experience a change
190885
  in performance.
190885
* System software may use a new bit in Model-Specific Register (MSR) 0x10F
190885
  TSX_FORCE_ABORT[TSX_CPUID_CLEAR] functionality to clear the Hardware Lock
190885
  Elision (HLE) and RTM bits to indicate to software that Intel TSX is
190885
  disabled.
190885
190885
1. Add RTM_ALWAYS_ABORT to CPUID features.
190885
2. Set RTM usable only if RTM_ALWAYS_ABORT isn't set.  This skips the
190885
string/tst-memchr-rtm etc. testcases on the affected processors, which
190885
always fail after a microcde update.
190885
3. Check RTM feature, instead of usability, against /proc/cpuinfo.
190885
190885
This fixes BZ #28033.
190885
190885
(cherry picked from commit ea8e465a6b8d0f26c72bcbe453a854de3abf68ec)
190885
---
190885
 manual/platform.texi                    | 3 +++
190885
 sysdeps/x86/cpu-features.c              | 5 ++++-
190885
 sysdeps/x86/sys/platform/x86.h          | 6 +++---
190885
 sysdeps/x86/tst-cpu-features-supports.c | 2 +-
190885
 sysdeps/x86/tst-get-cpu-features.c      | 2 ++
190885
 5 files changed, 13 insertions(+), 5 deletions(-)
190885
190885
diff --git a/manual/platform.texi b/manual/platform.texi
190885
index 8fec2933..b7e8aef7 100644
190885
--- a/manual/platform.texi
190885
+++ b/manual/platform.texi
190885
@@ -510,6 +510,9 @@ capability.
190885
 @item
190885
 @code{RTM} -- RTM instruction extensions.
190885
 
190885
+@item
190885
+@code{RTM_ALWAYS_ABORT} -- Transactions always abort, making RTM unusable.
190885
+
190885
 @item
190885
 @code{SDBG} -- IA32_DEBUG_INTERFACE MSR for silicon debug.
190885
 
190885
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
190885
index 3610ee5c..4889f062 100644
190885
--- a/sysdeps/x86/cpu-features.c
190885
+++ b/sysdeps/x86/cpu-features.c
190885
@@ -74,7 +74,6 @@ update_usable (struct cpu_features *cpu_features)
190885
   CPU_FEATURE_SET_USABLE (cpu_features, HLE);
190885
   CPU_FEATURE_SET_USABLE (cpu_features, BMI2);
190885
   CPU_FEATURE_SET_USABLE (cpu_features, ERMS);
190885
-  CPU_FEATURE_SET_USABLE (cpu_features, RTM);
190885
   CPU_FEATURE_SET_USABLE (cpu_features, RDSEED);
190885
   CPU_FEATURE_SET_USABLE (cpu_features, ADX);
190885
   CPU_FEATURE_SET_USABLE (cpu_features, CLFLUSHOPT);
190885
@@ -90,6 +89,7 @@ update_usable (struct cpu_features *cpu_features)
190885
   CPU_FEATURE_SET_USABLE (cpu_features, MOVDIRI);
190885
   CPU_FEATURE_SET_USABLE (cpu_features, MOVDIR64B);
190885
   CPU_FEATURE_SET_USABLE (cpu_features, FSRM);
190885
+  CPU_FEATURE_SET_USABLE (cpu_features, RTM_ALWAYS_ABORT);
190885
   CPU_FEATURE_SET_USABLE (cpu_features, SERIALIZE);
190885
   CPU_FEATURE_SET_USABLE (cpu_features, TSXLDTRK);
190885
   CPU_FEATURE_SET_USABLE (cpu_features, LAHF64_SAHF64);
190885
@@ -779,6 +779,9 @@ no_cpuid:
190885
     GLRO(dl_platform) = "i586";
190885
 #endif
190885
 
190885
+  if (!CPU_FEATURES_CPU_P (cpu_features, RTM_ALWAYS_ABORT))
190885
+    CPU_FEATURE_SET_USABLE (cpu_features, RTM);
190885
+
190885
 #if CET_ENABLED
190885
 # if HAVE_TUNABLES
190885
   TUNABLE_GET (x86_ibt, tunable_val_t *,
190885
diff --git a/sysdeps/x86/sys/platform/x86.h b/sysdeps/x86/sys/platform/x86.h
190885
index e5cc7c68..7a434926 100644
190885
--- a/sysdeps/x86/sys/platform/x86.h
190885
+++ b/sysdeps/x86/sys/platform/x86.h
190885
@@ -247,7 +247,7 @@ extern const struct cpu_features *__x86_get_cpu_features (unsigned int)
190885
 #define bit_cpu_AVX512_VP2INTERSECT (1u << 8)
190885
 #define bit_cpu_INDEX_7_EDX_9	(1u << 9)
190885
 #define bit_cpu_MD_CLEAR	(1u << 10)
190885
-#define bit_cpu_INDEX_7_EDX_11	(1u << 11)
190885
+#define bit_cpu_RTM_ALWAYS_ABORT (1u << 11)
190885
 #define bit_cpu_INDEX_7_EDX_12	(1u << 12)
190885
 #define bit_cpu_INDEX_7_EDX_13	(1u << 13)
190885
 #define bit_cpu_SERIALIZE	(1u << 14)
190885
@@ -471,7 +471,7 @@ extern const struct cpu_features *__x86_get_cpu_features (unsigned int)
190885
 #define index_cpu_AVX512_VP2INTERSECT COMMON_CPUID_INDEX_7
190885
 #define index_cpu_INDEX_7_EDX_9	COMMON_CPUID_INDEX_7
190885
 #define index_cpu_MD_CLEAR	COMMON_CPUID_INDEX_7
190885
-#define index_cpu_INDEX_7_EDX_11 COMMON_CPUID_INDEX_7
190885
+#define index_cpu_RTM_ALWAYS_ABORT COMMON_CPUID_INDEX_7
190885
 #define index_cpu_INDEX_7_EDX_12 COMMON_CPUID_INDEX_7
190885
 #define index_cpu_INDEX_7_EDX_13 COMMON_CPUID_INDEX_7
190885
 #define index_cpu_SERIALIZE	COMMON_CPUID_INDEX_7
190885
@@ -695,7 +695,7 @@ extern const struct cpu_features *__x86_get_cpu_features (unsigned int)
190885
 #define reg_AVX512_VP2INTERSECT	edx
190885
 #define reg_INDEX_7_EDX_9	edx
190885
 #define reg_MD_CLEAR		edx
190885
-#define reg_INDEX_7_EDX_11	edx
190885
+#define reg_RTM_ALWAYS_ABORT	edx
190885
 #define reg_INDEX_7_EDX_12	edx
190885
 #define reg_INDEX_7_EDX_13	edx
190885
 #define reg_SERIALIZE		edx
190885
diff --git a/sysdeps/x86/tst-cpu-features-supports.c b/sysdeps/x86/tst-cpu-features-supports.c
190885
index 287cf01f..8100a319 100644
190885
--- a/sysdeps/x86/tst-cpu-features-supports.c
190885
+++ b/sysdeps/x86/tst-cpu-features-supports.c
190885
@@ -152,7 +152,7 @@ do_test (int argc, char **argv)
190885
   fails += CHECK_SUPPORTS (rdpid, RDPID);
190885
   fails += CHECK_SUPPORTS (rdrnd, RDRAND);
190885
   fails += CHECK_SUPPORTS (rdseed, RDSEED);
190885
-  fails += CHECK_SUPPORTS (rtm, RTM);
190885
+  fails += CHECK_CPU_SUPPORTS (rtm, RTM);
190885
   fails += CHECK_SUPPORTS (serialize, SERIALIZE);
190885
   fails += CHECK_SUPPORTS (sha, SHA);
190885
   fails += CHECK_CPU_SUPPORTS (shstk, SHSTK);
190885
diff --git a/sysdeps/x86/tst-get-cpu-features.c b/sysdeps/x86/tst-get-cpu-features.c
190885
index 2763deb6..0717e5d8 100644
190885
--- a/sysdeps/x86/tst-get-cpu-features.c
190885
+++ b/sysdeps/x86/tst-get-cpu-features.c
190885
@@ -183,6 +183,7 @@ do_test (void)
190885
   CHECK_CPU_FEATURE (UINTR);
190885
   CHECK_CPU_FEATURE (AVX512_VP2INTERSECT);
190885
   CHECK_CPU_FEATURE (MD_CLEAR);
190885
+  CHECK_CPU_FEATURE (RTM_ALWAYS_ABORT);
190885
   CHECK_CPU_FEATURE (SERIALIZE);
190885
   CHECK_CPU_FEATURE (HYBRID);
190885
   CHECK_CPU_FEATURE (TSXLDTRK);
190885
@@ -344,6 +345,7 @@ do_test (void)
190885
   CHECK_CPU_FEATURE_USABLE (FSRM);
190885
   CHECK_CPU_FEATURE_USABLE (AVX512_VP2INTERSECT);
190885
   CHECK_CPU_FEATURE_USABLE (MD_CLEAR);
190885
+  CHECK_CPU_FEATURE_USABLE (RTM_ALWAYS_ABORT);
190885
   CHECK_CPU_FEATURE_USABLE (SERIALIZE);
190885
   CHECK_CPU_FEATURE_USABLE (HYBRID);
190885
   CHECK_CPU_FEATURE_USABLE (TSXLDTRK);
190885
-- 
190885
GitLab
190885