x86: add tests for MSR_IA32_TSX_CTRL
Paolo Bonzini
maintainerPATCH 1/1 x86: add tests for MSR_IA32_TSX_CTRL
--- lib/x86/msr.h | 14 +++++++++++++ lib/x86/processor.h | 2 ++ x86/Makefile.common | 2 +- x86/tsx-ctrl.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ x86/vmexit.c | 12 +++++++++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 x86/tsx-ctrl.c
lib/x86/msr.h +14 -0
@@ -221,6 +221,20 @@#define MSR_IA32_UCODE_WRITE 0x00000079#define MSR_IA32_UCODE_REV 0x0000008b +#define MSR_IA32_ARCH_CAPABILITIES 0x0000010a +#define ARCH_CAP_RDCL_NO (1ULL << 0) +#define ARCH_CAP_IBRS_ALL (1ULL << 1) +#define ARCH_CAP_SKIP_VMENTRY_L1DFLUSH (1ULL << 3) +#define ARCH_CAP_SSB_NO (1ULL << 4) +#define ARCH_CAP_MDS_NO (1ULL << 5) +#define ARCH_CAP_PSCHANGE_MC_NO (1ULL << 6) +#define ARCH_CAP_TSX_CTRL_MSR (1ULL << 7) +#define ARCH_CAP_TAA_NO (1ULL << 8) + +#define MSR_IA32_TSX_CTRL 0x00000122 +#define TSX_CTRL_RTM_DISABLE (1ULL << 0) +#define TSX_CTRL_CPUID_CLEAR (1ULL << 1) +#define MSR_IA32_PERF_STATUS 0x00000198#define MSR_IA32_PERF_CTL 0x00000199
lib/x86/processor.h +2 -0
@@ -137,6 +137,7 @@ static inline u8 cpuid_maxphyaddr(void)#define X86_FEATURE_XMM (CPUID(0x1, 0, EDX, 25))#define X86_FEATURE_XMM2 (CPUID(0x1, 0, EDX, 26))#define X86_FEATURE_TSC_ADJUST (CPUID(0x7, 0, EBX, 1)) +#define X86_FEATURE_HLE (CPUID(0x7, 0, EBX, 4))#define X86_FEATURE_INVPCID_SINGLE (CPUID(0x7, 0, EBX, 7))#define X86_FEATURE_INVPCID (CPUID(0x7, 0, EBX, 10))#define X86_FEATURE_RTM (CPUID(0x7, 0, EBX, 11))
@@ -149,6 +150,7 @@ static inline u8 cpuid_maxphyaddr(void)#define X86_FEATURE_LA57 (CPUID(0x7, 0, ECX, 16))#define X86_FEATURE_RDPID (CPUID(0x7, 0, ECX, 22))#define X86_FEATURE_SPEC_CTRL (CPUID(0x7, 0, EDX, 26)) +#define X86_FEATURE_ARCH_CAPABILITIES (CPUID(0x7, 0, EDX, 29))#define X86_FEATURE_NX (CPUID(0x80000001, 0, EDX, 20))#define X86_FEATURE_RDPRU (CPUID(0x80000008, 0, EBX, 4))
x86/Makefile.common +1 -1
@@ -58,7 +58,7 @@ tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \ $(TEST_DIR)/init.flat $(TEST_DIR)/smap.flat \ $(TEST_DIR)/hyperv_synic.flat $(TEST_DIR)/hyperv_stimer.flat \ $(TEST_DIR)/hyperv_connections.flat \ - $(TEST_DIR)/umip.flat + $(TEST_DIR)/umip.flat $(TEST_DIR)/tsx-ctrl.flat ifdef API tests-api = api/api-sample api/dirty-log api/dirty-log-perf
x86/tsx-ctrl.c new file +60 -0
60 lines not on this page · raw message
x86/vmexit.c +12 -0
@@ -434,6 +434,17 @@ static void tscdeadline(void)while (x ==0 )barrier (); } +static void wr_tsx_ctrl_msr (void ) +{ +wrmsr (MSR_IA32_TSX_CTRL ,0 ); +} + +static int has_tsx_ctrl (void ) +{ +return this_cpu_has (X86_FEATURE_ARCH_CAPABILITIES ) + && (rdmsr (MSR_IA32_ARCH_CAPABILITIES ) &ARCH_CAP_TSX_CTRL_MSR ); +} +static void wr_ibrs_msr (void ) {wrmsr (MSR_IA32_SPEC_CTRL ,1 );
@@ -478,6 +489,7 @@ static struct test tests[] = { { ipi_halt, "ipi_halt", is_smp, .parallel = 0, }, { ple_round_robin, "ple_round_robin", .parallel = 1 }, { wr_kernel_gs_base, "wr_kernel_gs_base", .parallel = 1 }, + { wr_tsx_ctrl_msr, "wr_tsx_ctrl_msr", has_tsx_ctrl, .parallel = 1, }, { wr_ibrs_msr, "wr_ibrs_msr", has_spec_ctrl, .parallel = 1 }, { wr_ibpb_msr, "wr_ibpb_msr", has_ibpb, .parallel = 1 }, { wr_tsc_adjust_msr, "wr_tsc_adjust_msr", .parallel = 1 },
Signature · 1 line
1.8.3.1
Quoted 2 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>
I had to add tsx-ctrl to x86/unittests.cfg:
+[tsx-ctrl]
+file = tsx-ctrl.flat
+extra_params = -cpu host
+groups = tsx-ctrl
+
With qemu 4.1, I get:
timeout -k 1s --foreground 90s /root/kvm-unit-tests/deps/qemu.sh -nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel x86/tsx-ctrl.flat -smp 1 -cpu host # -initrd /tmp/tmp.7wOLppNO4W
enabling apic
SKIP: TSX_CTRL not available
Maybe qemu is masking off ARCH_CAP_TSX_CTRL_MSR? I haven't investigated.
Paolo Bonzini
maintainerQuoted 22 lines · Jim Mattson
Quoted 2 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>I had to add tsx-ctrl to x86/unittests.cfg:
+[tsx-ctrl]
(quoted diff) +4
-0+file = tsx-ctrl.flat +extra_params = -cpu host +groups = tsx-ctrl +With qemu 4.1, I get:
timeout -k 1s --foreground 90s
/root/kvm-unit-tests/deps/qemu.sh-nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel x86/tsx-ctrl.flat -smp 1 -cpu host # -initrd/tmp/tmp.7wOLppNO4W
enabling apic
SKIP:TSX_CTRLnot available
Quoted 1 line
Maybe qemu is masking off
ARCH_CAP_TSX_CTRL_MSR? I haven't investigated.
Yes, you need "-cpu host,migratable=off" if you don't have the corresponding QEMU patches (which I've only sent today, but just allowing unmigratable features in extra_params will be okay for you to test).
Paolo
Quoted 24 lines · Paolo Bonzini
Quoted 22 lines · Jim Mattson
Quoted 2 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>I had to add tsx-ctrl to x86/unittests.cfg:
+[tsx-ctrl]
(quoted diff) +4
-0+file = tsx-ctrl.flat +extra_params = -cpu host +groups = tsx-ctrl +With qemu 4.1, I get:
timeout -k 1s --foreground 90s
/root/kvm-unit-tests/deps/qemu.sh-nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel x86/tsx-ctrl.flat -smp 1 -cpu host # -initrd/tmp/tmp.7wOLppNO4W
enabling apic
SKIP:TSX_CTRLnot available
Quoted 6 lines
Quoted 1 line
Maybe qemu is masking off
ARCH_CAP_TSX_CTRL_MSR? I haven't investigated.Yes, you need "-cpu host,migratable=off" if you don't have the corresponding QEMU patches (which I've only sent today, but just allowing unmigratable features in
extra_paramswill be okay for you to test).
Okay, that works!
enabling apic
PASS: TSX_CTRL should be 0
PASS: Transactions do not abort
PASS: TSX_CTRL hides RTM
PASS: TSX_CTRL hides HLE
PASS: TSX_CTRL=0 unhides RTM
PASS: TSX_CTRL causes transactions to abort
PASS: TSX_CTRL=0 causes transactions to succeed
SUMMARY: 7 tests
...and, for the vmexit test...
enabling apic
paging enabled
cr0 = 80010011
cr3 = 61e000
cr4 = 20
pci-testdev at 0x10 membar febff000 iobar c000wr_tsx_ctrl_msr 2058
Paolo Bonzini
maintainerQuoted 34 lines · Jim Mattson
Quoted 24 lines · Paolo Bonzini
Quoted 22 lines · Jim Mattson
Quoted 2 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>I had to add tsx-ctrl to x86/unittests.cfg:
+[tsx-ctrl]
(quoted diff) +4
-0+file = tsx-ctrl.flat +extra_params = -cpu host +groups = tsx-ctrl +With qemu 4.1, I get:
timeout -k 1s --foreground 90s
/root/kvm-unit-tests/deps/qemu.sh-nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel x86/tsx-ctrl.flat -smp 1 -cpu host # -initrd/tmp/tmp.7wOLppNO4W
enabling apic
SKIP:TSX_CTRLnot availableQuoted 6 lines
Quoted 1 line
Maybe qemu is masking off
ARCH_CAP_TSX_CTRL_MSR? I haven't investigated.Yes, you need "-cpu host,migratable=off" if you don't have the corresponding QEMU patches (which I've only sent today, but just allowing unmigratable features in
extra_paramswill be okay for you to test).Okay, that works!
Quoted 9 lines
enabling apic
PASS:TSX_CTRLshould be 0
PASS: Transactions do not abort
PASS:TSX_CTRLhides RTM
PASS:TSX_CTRLhides HLE
PASS: TSX_CTRL=0 unhides RTM
PASS:TSX_CTRLcauses transactions to abort
PASS: TSX_CTRL=0 causes transactions to succeed
SUMMARY: 7 tests
Great, should I merge the patches in 5.5 with your Tested-by annotation?
Paolo
Quoted 10 lines
...and, for the vmexit test...
enabling apic
paging enabled
cr0 = 80010011
cr3 = 61e000
cr4 = 20
pci-testdev at0x10membarfebff000iobar c000wr_tsx_ctrl_msr2058
Quoted 46 lines · Paolo Bonzini
Quoted 34 lines · Jim Mattson
Quoted 24 lines · Paolo Bonzini
Quoted 22 lines · Jim Mattson
Quoted 2 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>I had to add tsx-ctrl to x86/unittests.cfg:
+[tsx-ctrl]
(quoted diff) +4
-0+file = tsx-ctrl.flat +extra_params = -cpu host +groups = tsx-ctrl +With qemu 4.1, I get:
timeout -k 1s --foreground 90s
/root/kvm-unit-tests/deps/qemu.sh-nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel x86/tsx-ctrl.flat -smp 1 -cpu host # -initrd/tmp/tmp.7wOLppNO4W
enabling apic
SKIP:TSX_CTRLnot availableQuoted 6 lines
Quoted 1 line
Maybe qemu is masking off
ARCH_CAP_TSX_CTRL_MSR? I haven't investigated.Yes, you need "-cpu host,migratable=off" if you don't have the corresponding QEMU patches (which I've only sent today, but just allowing unmigratable features in
extra_paramswill be okay for you to test).Okay, that works!
Quoted 9 lines
enabling apic
PASS:TSX_CTRLshould be 0
PASS: Transactions do not abort
PASS:TSX_CTRLhides RTM
PASS:TSX_CTRLhides HLE
PASS: TSX_CTRL=0 unhides RTM
PASS:TSX_CTRLcauses transactions to abort
PASS: TSX_CTRL=0 causes transactions to succeed
SUMMARY: 7 tests
Quoted 1 line
Great, should I merge the patches in 5.5 with your Tested-by annotation?
Please do.