]> xenbits.xensource.com Git - xtf.git/commitdiff
Utility for classifying the current RTM behaviour
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 4 Nov 2019 13:42:39 +0000 (13:42 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 24 Jun 2021 11:17:50 +0000 (12:17 +0100)
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/include/arch/cpuid.h
arch/x86/include/arch/tsx.h
docs/all-tests.dox
tests/rtm-check/Makefile [new file with mode: 0644]
tests/rtm-check/main.c [new file with mode: 0644]

index f91117a3088086eb2c735e6e5c4aa5c8deb41641..4a117a94ed8c5636761959a5c0f607c00fc1824b 100644 (file)
@@ -89,7 +89,9 @@ static inline bool cpu_has(unsigned int feature)
 #define cpu_has_svm             cpu_has(X86_FEATURE_SVM)
 
 #define cpu_has_fsgsbase        cpu_has(X86_FEATURE_FSGSBASE)
+#define cpu_has_hle             cpu_has(X86_FEATURE_HLE)
 #define cpu_has_smep            cpu_has(X86_FEATURE_SMEP)
+#define cpu_has_rtm             cpu_has(X86_FEATURE_RTM)
 #define cpu_has_smap            cpu_has(X86_FEATURE_SMAP)
 
 #define cpu_has_umip            cpu_has(X86_FEATURE_UMIP)
index 503f4a3f39ca901e1ae84c4c572c1171541bfd04..c54ff1b7db3bb62672e76249217d4141f993f10c 100644 (file)
 #define XTF_X86_TSX_H
 
 #include <xtf/compiler.h>
+#include <xtf/extable.h>
 
 #define _XBEGIN_STARTED  (~0u)
+#define _XBEGIN_UD       EXINFO_SYM(UD, 0)
 #define _XABORT_EXPLICIT (1u << 0)
 #define _XABORT_RETRY    (1u << 1)
 #define _XABORT_CONFLICT (1u << 2)
@@ -41,6 +43,20 @@ static inline unsigned int _xbegin(void)
     return ret;
 }
 
+/* Like _xbegin(), but will catch #UD as well. */
+static inline unsigned int _xbegin_safe(void)
+{
+    unsigned int ret = _XBEGIN_STARTED;
+
+    asm volatile ("1: .byte 0xc7, 0xf8, 0, 0, 0, 0; 2:" /* xbegin 2f; 2: */
+                  _ASM_EXTABLE_HANDLER(1b, 2b, %P[rec])
+                  : "+a" (ret)
+                  : [rec] "p" (ex_record_fault_eax)
+                  : "memory");
+
+    return ret;
+}
+
 static inline int _xtest(void)
 {
     int rc;
index 902fc44d298f70035c26adc4dd413417756a7a64..322f078db09e6dd668895f7eec9fb28a75ed9690 100644 (file)
@@ -170,6 +170,8 @@ states.
 
 @subpage test-msr - Print MSR information.
 
+@subpage test-rtm-check - Probe for the RTM behaviour.
+
 
 @section index-in-development In Development
 
diff --git a/tests/rtm-check/Makefile b/tests/rtm-check/Makefile
new file mode 100644 (file)
index 0000000..010cda2
--- /dev/null
@@ -0,0 +1,9 @@
+include $(ROOT)/build/common.mk
+
+NAME      := rtm-check
+CATEGORY  := utility
+TEST-ENVS := pv64 hvm64
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
diff --git a/tests/rtm-check/main.c b/tests/rtm-check/main.c
new file mode 100644 (file)
index 0000000..eadee26
--- /dev/null
@@ -0,0 +1,45 @@
+/**
+ * @file tests/rtm-check/main.c
+ * @ref test-rtm-check
+ *
+ * @page test-rtm-check rtm-check
+ *
+ * Probe the RTM behaviour on the system, independently of CPUID settings.
+ * Classifies as usable, unavailable (@#UD) or always aborting.
+ *
+ * @see tests/rtm-check/main.c
+ */
+#include <xtf.h>
+
+const char test_title[] = "Test RTM behaviour";
+
+void test_main(void)
+{
+    printk("CPUID: HLE %u, RTM %u\n",
+           cpu_has_hle, cpu_has_rtm);
+
+    for ( int i = 0; i < 1000; ++i )
+    {
+        unsigned int xstatus = _xbegin_safe();
+
+        if ( xstatus == _XBEGIN_STARTED )
+        {
+            _xend();
+            return xtf_success("RTM usable\n");
+        }
+        else if ( xstatus == _XBEGIN_UD )
+            return xtf_success("RTM unavailable\n");
+    }
+
+    xtf_success("RTM always aborting\n");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */