#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)
#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)
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;
@subpage test-msr - Print MSR information.
+@subpage test-rtm-check - Probe for the RTM behaviour.
+
@section index-in-development In Development
--- /dev/null
+include $(ROOT)/build/common.mk
+
+NAME := rtm-check
+CATEGORY := utility
+TEST-ENVS := pv64 hvm64
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
--- /dev/null
+/**
+ * @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:
+ */