summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests
diff options
context:
space:
mode:
authorVitaly Kuznetsov <vkuznets@redhat.com>2019-10-08 14:08:08 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2019-10-22 07:31:18 -0400
commitef4059809890f732c69cc1726d3a9a108a832a2f (patch)
tree6ac0a5e1d902568a9a4cc374a5c34d7107ee2e2b /tools/testing/selftests
parent11eada4718a352a6a588de9908200c1e348530f1 (diff)
selftests: kvm: fix sync_regs_test with newer gccs
Commit 204c91eff798a ("KVM: selftests: do not blindly clobber registers in guest asm") was intended to make test more gcc-proof, however, the result is exactly the opposite: on newer gccs (e.g. 8.2.1) the test breaks with ==== Test Assertion Failure ==== x86_64/sync_regs_test.c:168: run->s.regs.regs.rbx == 0xBAD1DEA + 1 pid=14170 tid=14170 - Invalid argument 1 0x00000000004015b3: main at sync_regs_test.c:166 (discriminator 6) 2 0x00007f413fb66412: ?? ??:0 3 0x000000000040191d: _start at ??:? rbx sync regs value incorrect 0x1. Apparently, compile is still free to play games with registers even when they have variables attached. Re-write guest code with 'asm volatile' by embedding ucall there and making sure rbx is preserved. Fixes: 204c91eff798a ("KVM: selftests: do not blindly clobber registers in guest asm") Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/testing/selftests')
-rw-r--r--tools/testing/selftests/kvm/x86_64/sync_regs_test.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/tools/testing/selftests/kvm/x86_64/sync_regs_test.c b/tools/testing/selftests/kvm/x86_64/sync_regs_test.c
index 11c2a70a7b87..5c8224256294 100644
--- a/tools/testing/selftests/kvm/x86_64/sync_regs_test.c
+++ b/tools/testing/selftests/kvm/x86_64/sync_regs_test.c
@@ -22,18 +22,19 @@
22 22
23#define VCPU_ID 5 23#define VCPU_ID 5
24 24
25#define UCALL_PIO_PORT ((uint16_t)0x1000)
26
27/*
28 * ucall is embedded here to protect against compiler reshuffling registers
29 * before calling a function. In this test we only need to get KVM_EXIT_IO
30 * vmexit and preserve RBX, no additional information is needed.
31 */
25void guest_code(void) 32void guest_code(void)
26{ 33{
27 /* 34 asm volatile("1: in %[port], %%al\n"
28 * use a callee-save register, otherwise the compiler 35 "add $0x1, %%rbx\n"
29 * saves it around the call to GUEST_SYNC. 36 "jmp 1b"
30 */ 37 : : [port] "d" (UCALL_PIO_PORT) : "rax", "rbx");
31 register u32 stage asm("rbx");
32 for (;;) {
33 GUEST_SYNC(0);
34 stage++;
35 asm volatile ("" : : "r" (stage));
36 }
37} 38}
38 39
39static void compare_regs(struct kvm_regs *left, struct kvm_regs *right) 40static void compare_regs(struct kvm_regs *left, struct kvm_regs *right)