]> xenbits.xensource.com Git - people/liuw/xen.git/commitdiff
x86/tsx: Implement controls for RTM force-abort mode
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 12 Sep 2018 13:36:00 +0000 (14:36 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 12 Mar 2019 17:05:21 +0000 (17:05 +0000)
The CPUID bit and MSR are deliberately not exposed to guests, because they
won't exist on newer processors.  As vPMU isn't security supported, the
misbehaviour of PCR3 isn't expected to impact production deployments.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
docs/misc/xen-command-line.pandoc
tools/misc/xen-cpuid.c
xen/arch/x86/cpu/intel.c
xen/arch/x86/cpu/vpmu.c
xen/arch/x86/msr.c
xen/include/asm-x86/cpufeature.h
xen/include/asm-x86/msr-index.h
xen/include/asm-x86/vpmu.h
xen/include/public/arch-x86/cpufeatureset.h

index ab853bda121a2c1447a8f1f338bbb79eed2a8348..a9fe44989462a69811e543bdb0d8fe4f08a8b293 100644 (file)
@@ -2114,7 +2114,7 @@ Use Virtual Processor ID support if available.  This prevents the need for TLB
 flushes on VM entry and exit, increasing performance.
 
 ### vpmu (x86)
-    = List of [ <bool>, bts, ipc, arch ]
+    = List of [ <bool>, bts, ipc, arch, rtm-abort=<bool> ]
 
     Applicability: x86.  Default: false
 
@@ -2147,6 +2147,21 @@ provide access to a wealth of low level processor information.
 
 *   The `arch` option allows access to the pre-defined architectural events.
 
+*   The `rtm-abort` boolean controls a trade-off between working Restricted
+    Transactional Memory, and working performance counters.
+
+    All processors released to date (Q1 2019) supporting Transactional Memory
+    Extensions suffer an erratum which has been addressed in microcode.
+
+    Processors based on the Skylake microarchitecture with up-to-date
+    microcode internally use performance counter 3 to work around the erratum.
+    A consequence is that the counter gets reprogrammed whenever an `XBEGIN`
+    instruction is executed.
+
+    An alternative mode exists where PCR3 behaves as before, at the cost of
+    `XBEGIN` unconditionally aborting.  Enabling `rtm-abort` mode will
+    activate this alternative mode.
+
 *Warning:*
 As the virtualisation is not 100% safe, don't use the vpmu flag on
 production systems (see http://xenbits.xen.org/xsa/advisory-163.html)!
index 6e7ca8b9a457ac84b7022d8cc34a15a091833122..d87a72e3e65e9e7401d2c4953256dc88a8cd54d8 100644 (file)
@@ -146,6 +146,8 @@ static const char *str_7d0[32] =
 {
     [ 2] = "avx512_4vnniw", [ 3] = "avx512_4fmaps",
 
+    /* 12 */                [13] = "tsx-force-abort",
+
     [26] = "ibrsb",         [27] = "stibp",
     [28] = "l1d_flush",     [29] = "arch_caps",
     /* 30 */                [31] = "ssbd",
index 65fa3d611fbdc80f763c950856e0cc0be0057bc7..29c6b875128adacc2b6b4b56f4b4d547afeed13c 100644 (file)
@@ -286,6 +286,9 @@ static void Intel_errata_workarounds(struct cpuinfo_x86 *c)
        if (c->x86 == 6 && cpu_has_clflush &&
            (c->x86_model == 29 || c->x86_model == 46 || c->x86_model == 47))
                __set_bit(X86_FEATURE_CLFLUSH_MONITOR, c->x86_capability);
+
+       if (cpu_has_tsx_force_abort && opt_rtm_abort)
+               wrmsrl(MSR_TSX_FORCE_ABORT, TSX_FORCE_ABORT_RTM);
 }
 
 
index 8324d62f11debe03e6d520281bfd93fa62505f75..8f6daf13fd12bc986d71ec273e2c946167faecd5 100644 (file)
@@ -45,6 +45,7 @@ CHECK_pmu_params;
 static unsigned int __read_mostly opt_vpmu_enabled;
 unsigned int __read_mostly vpmu_mode = XENPMU_MODE_OFF;
 unsigned int __read_mostly vpmu_features = 0;
+bool __read_mostly opt_rtm_abort;
 
 static DEFINE_SPINLOCK(vpmu_lock);
 static unsigned vpmu_count;
@@ -73,6 +74,8 @@ static int __init parse_vpmu_params(const char *s)
             vpmu_features |= XENPMU_FEATURE_IPC_ONLY;
         else if ( !cmdline_strcmp(s, "arch") )
             vpmu_features |= XENPMU_FEATURE_ARCH_ONLY;
+        else if ( (val = parse_boolean("rtm-abort", s, ss)) >= 0 )
+            opt_rtm_abort = val;
         else
             rc = -EINVAL;
 
index 9bb38b6d663664fbca24fb2709d65db7e2d399dd..4df4a59f4d130491f5d354a1a74c1f575cb254b3 100644 (file)
@@ -131,6 +131,8 @@ int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val)
     case MSR_PRED_CMD:
     case MSR_FLUSH_CMD:
         /* Write-only */
+    case MSR_TSX_FORCE_ABORT:
+        /* Not offered to guests. */
         goto gp_fault;
 
     case MSR_SPEC_CTRL:
@@ -230,6 +232,8 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
     case MSR_INTEL_PLATFORM_INFO:
     case MSR_ARCH_CAPABILITIES:
         /* Read-only */
+    case MSR_TSX_FORCE_ABORT:
+        /* Not offered to guests. */
         goto gp_fault;
 
     case MSR_AMD_PATCHLOADER:
index 1fb9af4b1934be4a2344b6a9e8721f876be6fd4e..745801f3c0afb515caded97966e26fa453f87420 100644 (file)
 /* CPUID level 0x80000007.edx */
 #define cpu_has_itsc            boot_cpu_has(X86_FEATURE_ITSC)
 
+/* CPUID level 0x00000007:0.edx */
+#define cpu_has_tsx_force_abort boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT)
+
 /* Synthesized. */
 #define cpu_has_arch_perfmon    boot_cpu_has(X86_FEATURE_ARCH_PERFMON)
 #define cpu_has_cpuid_faulting  boot_cpu_has(X86_FEATURE_CPUID_FAULTING)
index 24d783a72d6b5de7e984adb804db440634ef9364..c6e1d8768fa04f2728325fa3374d89e4fae20d37 100644 (file)
@@ -51,6 +51,9 @@
 #define MSR_FLUSH_CMD                  0x0000010b
 #define FLUSH_CMD_L1D                  (_AC(1, ULL) << 0)
 
+#define MSR_TSX_FORCE_ABORT             0x0000010f
+#define TSX_FORCE_ABORT_RTM             (_AC(1, ULL) <<  0)
+
 /* Intel MSRs. Some also available on other CPUs */
 #define MSR_IA32_PERFCTR0              0x000000c1
 #define MSR_IA32_A_PERFCTR0            0x000004c1
index 5e778ab7bab14edbae37c7c822e5ca6643e73cb5..1287b9fb6ec7bf3991cf19b9672070912bef04a6 100644 (file)
@@ -125,6 +125,7 @@ static inline int vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content)
 
 extern unsigned int vpmu_mode;
 extern unsigned int vpmu_features;
+extern bool opt_rtm_abort;
 
 /* Context switch */
 static inline void vpmu_switch_from(struct vcpu *prev)
index fbc68fa29f3b0d729ae4f624d8faf285f40c8231..2bcc5487accf396808eb1eb74e0f83a990dcc094 100644 (file)
@@ -242,6 +242,7 @@ XEN_CPUFEATURE(IBPB,          8*32+12) /*A  IBPB support only (no IBRS, used by
 /* Intel-defined CPU features, CPUID level 0x00000007:0.edx, word 9 */
 XEN_CPUFEATURE(AVX512_4VNNIW, 9*32+ 2) /*A  AVX512 Neural Network Instructions */
 XEN_CPUFEATURE(AVX512_4FMAPS, 9*32+ 3) /*A  AVX512 Multiply Accumulation Single Precision */
+XEN_CPUFEATURE(TSX_FORCE_ABORT, 9*32+13) /* MSR_TSX_FORCE_ABORT.RTM_ABORT */
 XEN_CPUFEATURE(IBRSB,         9*32+26) /*A  IBRS and IBPB support (used by Intel) */
 XEN_CPUFEATURE(STIBP,         9*32+27) /*A  STIBP */
 XEN_CPUFEATURE(L1D_FLUSH,     9*32+28) /*S  MSR_FLUSH_CMD and L1D flush. */