summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kvm/state_test.c
diff options
context:
space:
mode:
authorPeter Xu <peterx@redhat.com>2018-08-22 10:19:57 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2018-08-22 17:48:37 +0300
commit4e18bccc2e5544f0be28fc1c4e6be47a469d6c60 (patch)
treed334c9b09f5e94cb97c85ac487d4da9bf75cf86f /tools/testing/selftests/kvm/state_test.c
parent07a262cc7c586e3f385a61b8870b0913bf31309a (diff)
downloadlinux-4e18bccc2e5544f0be28fc1c4e6be47a469d6c60.tar.xz
kvm: selftest: unify the guest port macros
Most of the tests are using the same way to do guest to host sync but the code is mostly duplicated. Generalize the guest port macros into the common header file and use it in different tests. Meanwhile provide "struct guest_args" and a helper "guest_args_read()" to hide the register details when playing with these port operations on RDI and RSI. Signed-off-by: Peter Xu <peterx@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/testing/selftests/kvm/state_test.c')
-rw-r--r--tools/testing/selftests/kvm/state_test.c30
1 files changed, 4 insertions, 26 deletions
diff --git a/tools/testing/selftests/kvm/state_test.c b/tools/testing/selftests/kvm/state_test.c
index ecabf25b7077..438d7b828581 100644
--- a/tools/testing/selftests/kvm/state_test.c
+++ b/tools/testing/selftests/kvm/state_test.c
@@ -21,28 +21,6 @@
#include "vmx.h"
#define VCPU_ID 5
-#define PORT_SYNC 0x1000
-#define PORT_ABORT 0x1001
-#define PORT_DONE 0x1002
-
-static inline void __exit_to_l0(uint16_t port, uint64_t arg0, uint64_t arg1)
-{
- __asm__ __volatile__("in %[port], %%al"
- :
- : [port]"d"(port), "D"(arg0), "S"(arg1)
- : "rax");
-}
-
-#define exit_to_l0(_port, _arg0, _arg1) \
- __exit_to_l0(_port, (uint64_t) (_arg0), (uint64_t) (_arg1))
-
-#define GUEST_ASSERT(_condition) do { \
- if (!(_condition)) \
- exit_to_l0(PORT_ABORT, "Failed guest assert: " #_condition, __LINE__);\
-} while (0)
-
-#define GUEST_SYNC(stage) \
- exit_to_l0(PORT_SYNC, "hello", stage);
static bool have_nested_state;
@@ -137,7 +115,7 @@ void guest_code(struct vmx_pages *vmx_pages)
if (vmx_pages)
l1_guest_code(vmx_pages);
- exit_to_l0(PORT_DONE, 0, 0);
+ GUEST_DONE();
}
int main(int argc, char *argv[])
@@ -178,13 +156,13 @@ int main(int argc, char *argv[])
memset(&regs1, 0, sizeof(regs1));
vcpu_regs_get(vm, VCPU_ID, &regs1);
switch (run->io.port) {
- case PORT_ABORT:
+ case GUEST_PORT_ABORT:
TEST_ASSERT(false, "%s at %s:%d", (const char *) regs1.rdi,
__FILE__, regs1.rsi);
/* NOT REACHED */
- case PORT_SYNC:
+ case GUEST_PORT_SYNC:
break;
- case PORT_DONE:
+ case GUEST_PORT_DONE:
goto done;
default:
TEST_ASSERT(false, "Unknown port 0x%x.", run->io.port);