Skip to contentSkip to conversation

Rudimentary Intel Restricted Transactional Memory Support.

PATCH New [email protected] 1 participant 1 message Feb 7, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Rudimentary Intel Restricted Transactional Memory Support.

From: Xin Tong <[email protected]>

A better looking patch generated by git format-patch.

Implement a rudimentary support for intel RTM. Xbegin always fails to fallback code path. Handle Xbegin, Xend, Xtest, Xabort described in Intel ISA extension manual @
http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325462.pdf

---
 target-i386/cpu.c         |  8 ++--
 target-i386/cpu.h         |  8 ++++
 target-i386/helper.h      |  5 +++
 target-i386/misc_helper.c | 19 +++++++++
 target-i386/translate.c   | 99 +++++++++++++++++++++++++++++++++++------------
 5 files changed, 111 insertions(+), 28 deletions(-)
target-i386/cpu.c +5 -3
index 3a9b32e..9397665 100644
@@ -334,7 +334,8 @@ static const char *cpuid_xsave_feature_name[] = {
 #define TCG_SVM_FEATURES 0
 #define TCG_KVM_FEATURES 0
 #define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \
-          CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX)
+          CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX | \
+          CPUID_7_0_EBX_HLE | CPUID_7_0_EBX_RTM)
           /* missing:
           CPUID_7_0_EBX_FSGSBASE, CPUID_7_0_EBX_HLE, CPUID_7_0_EBX_AVX2,
           CPUID_7_0_EBX_ERMS, CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM,
@@ -1101,7 +1102,8 @@ static X86CPUDefinition builtin_x86_defs[] = {
         .features[FEAT_7_0_EBX] =
             CPUID_7_0_EBX_FSGSBASE | CPUID_7_0_EBX_BMI1 |
             CPUID_7_0_EBX_AVX2 | CPUID_7_0_EBX_SMEP |
-            CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_INVPCID,
+            CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_INVPCID |
+            CPUID_7_0_EBX_HLE | CPUID_7_0_EBX_RTM,
         .features[FEAT_XSAVE] =
             CPUID_XSAVE_XSAVEOPT,
         .xlevel = 0x8000000A,
@@ -1137,7 +1139,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
             CPUID_7_0_EBX_AVX2 | CPUID_7_0_EBX_SMEP |
             CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_INVPCID |
             CPUID_7_0_EBX_RDSEED | CPUID_7_0_EBX_ADX |
-            CPUID_7_0_EBX_SMAP,
+            CPUID_7_0_EBX_SMAP | CPUID_7_0_EBX_HLE | CPUID_7_0_EBX_RTM,
         .features[FEAT_XSAVE] =
             CPUID_XSAVE_XSAVEOPT,
         .xlevel = 0x8000000A,
target-i386/cpu.h +8 -0
index 478450c..2879c3a 100644
@@ -625,6 +625,14 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
 #define EXCP_SYSCALL    0x100 /* only happens in user only emulation
                                  for syscall instruction */
 
+/* intel rtm abort reason bit */
+#define INTEL_RTM_XABORT      0
+#define INTEL_RTM_RETRY       1
+#define INTEL_RTM_CONFLICT    2
+#define INTEL_RTM_OVERFLOW    3
+#define INTEL_RTM_BREAKPOINT  4
+#define INTEL_RTM_ABORT_NEST  5
+
 /* i386-specific interrupt pending bits.  */
 #define CPU_INTERRUPT_POLL      CPU_INTERRUPT_TGT_EXT_1
 #define CPU_INTERRUPT_SMI       CPU_INTERRUPT_TGT_EXT_2
target-i386/helper.h +5 -0
index 8eb0145..52a97fe 100644
@@ -202,6 +202,11 @@ DEF_HELPER_1(enter_mmx, void, env)
 DEF_HELPER_1(emms, void, env)
 DEF_HELPER_3(movq, void, env, ptr, ptr)
 
+/* Intel RTM */
+DEF_HELPER_2(xbegin, void, env, i32)
+DEF_HELPER_1(xend, void, env)
+DEF_HELPER_1(xtest, void, env)
+
 #define SHIFT 0
 #include "ops_sse_header.h"
 #define SHIFT 1
target-i386/misc_helper.c +19 -0
index 4aaf1e4..b5690c9 100644
@@ -600,3 +600,22 @@ void helper_debug(CPUX86State *env)
     cs->exception_index = EXCP_DEBUG;
     cpu_loop_exit(cs);
 }
+
+void helper_xbegin(CPUX86State *env, uint32_t next_eip_addend)
+{
+    /* as a degenerate implementation, always fail xbegin. */
+    env->eip += next_eip_addend;
+    env->regs[R_EAX] = ~(1<<INTEL_RTM_OVERFLOW); /* internal buffer overflow */
+}
+
+void helper_xend(CPUX86State *env)
+{
+    /* only way to get here is to execute a xend without xbegin. GPF. */
+    raise_exception(env, EXCP0D_GPF);
+}
+
+void helper_xtest(CPUX86State *env)
+{
+    /* xbegin always fails to fallback code, set RTM not active. */
+    env->eflags &= ~(1<<6); /* zf */
+}
target-i386/translate.c +74 -25

122 lines not on this page · raw message

--
1.9.1