Commit c96f57b0 authored by Vipin Sharma's avatar Vipin Sharma Committed by Paolo Bonzini

KVM: selftests: Make vCPU exit reason test assertion common

Make TEST_ASSERT_KVM_EXIT_REASON() macro and replace all exit reason
test assert statements with it.

No functional changes intended.
Signed-off-by: default avatarVipin Sharma <vipinsh@google.com>
Reviewed-by: default avatarDavid Matlack <dmatlack@google.com>
Message-Id: <20230204014547.583711-2-vipinsh@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent e6239a4e
...@@ -180,9 +180,7 @@ static void host_test_system_suspend(void) ...@@ -180,9 +180,7 @@ static void host_test_system_suspend(void)
enter_guest(source); enter_guest(source);
TEST_ASSERT(run->exit_reason == KVM_EXIT_SYSTEM_EVENT, TEST_ASSERT_KVM_EXIT_REASON(source, KVM_EXIT_SYSTEM_EVENT);
"Unhandled exit reason: %u (%s)",
run->exit_reason, exit_reason_str(run->exit_reason));
TEST_ASSERT(run->system_event.type == KVM_SYSTEM_EVENT_SUSPEND, TEST_ASSERT(run->system_event.type == KVM_SYSTEM_EVENT_SUSPEND,
"Unhandled system event: %u (expected: %u)", "Unhandled system event: %u (expected: %u)",
run->system_event.type, KVM_SYSTEM_EVENT_SUSPEND); run->system_event.type, KVM_SYSTEM_EVENT_SUSPEND);
......
...@@ -63,6 +63,14 @@ void test_assert(bool exp, const char *exp_str, ...@@ -63,6 +63,14 @@ void test_assert(bool exp, const char *exp_str,
#a, #b, #a, (unsigned long) __a, #b, (unsigned long) __b); \ #a, #b, #a, (unsigned long) __a, #b, (unsigned long) __b); \
} while (0) } while (0)
#define TEST_ASSERT_KVM_EXIT_REASON(vcpu, expected) do { \
__u32 exit_reason = (vcpu)->run->exit_reason; \
\
TEST_ASSERT(exit_reason == (expected), \
"Unexpected exit reason: %u (%s)", \
exit_reason, exit_reason_str(exit_reason)); \
} while (0)
#define TEST_FAIL(fmt, ...) do { \ #define TEST_FAIL(fmt, ...) do { \
TEST_ASSERT(false, fmt, ##__VA_ARGS__); \ TEST_ASSERT(false, fmt, ##__VA_ARGS__); \
__builtin_unreachable(); \ __builtin_unreachable(); \
......
...@@ -35,8 +35,7 @@ static uint64_t diag318_handler(void) ...@@ -35,8 +35,7 @@ static uint64_t diag318_handler(void)
vcpu_run(vcpu); vcpu_run(vcpu);
run = vcpu->run; run = vcpu->run;
TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC);
"DIAGNOSE 0x0318 instruction was not intercepted");
TEST_ASSERT(run->s390_sieic.icptcode == ICPT_INSTRUCTION, TEST_ASSERT(run->s390_sieic.icptcode == ICPT_INSTRUCTION,
"Unexpected intercept code: 0x%x", run->s390_sieic.icptcode); "Unexpected intercept code: 0x%x", run->s390_sieic.icptcode);
TEST_ASSERT((run->s390_sieic.ipa & 0xff00) == IPA0_DIAG, TEST_ASSERT((run->s390_sieic.ipa & 0xff00) == IPA0_DIAG,
......
...@@ -126,10 +126,7 @@ void test_req_and_verify_all_valid_regs(struct kvm_vcpu *vcpu) ...@@ -126,10 +126,7 @@ void test_req_and_verify_all_valid_regs(struct kvm_vcpu *vcpu)
run->kvm_valid_regs = TEST_SYNC_FIELDS; run->kvm_valid_regs = TEST_SYNC_FIELDS;
rv = _vcpu_run(vcpu); rv = _vcpu_run(vcpu);
TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv); TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv);
TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC);
"Unexpected exit reason: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
TEST_ASSERT(run->s390_sieic.icptcode == 4 && TEST_ASSERT(run->s390_sieic.icptcode == 4 &&
(run->s390_sieic.ipa >> 8) == 0x83 && (run->s390_sieic.ipa >> 8) == 0x83 &&
(run->s390_sieic.ipb >> 16) == 0x501, (run->s390_sieic.ipb >> 16) == 0x501,
...@@ -165,10 +162,7 @@ void test_set_and_verify_various_reg_values(struct kvm_vcpu *vcpu) ...@@ -165,10 +162,7 @@ void test_set_and_verify_various_reg_values(struct kvm_vcpu *vcpu)
rv = _vcpu_run(vcpu); rv = _vcpu_run(vcpu);
TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv); TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv);
TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC);
"Unexpected exit reason: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
TEST_ASSERT(run->s.regs.gprs[11] == 0xBAD1DEA + 1, TEST_ASSERT(run->s.regs.gprs[11] == 0xBAD1DEA + 1,
"r11 sync regs value incorrect 0x%llx.", "r11 sync regs value incorrect 0x%llx.",
run->s.regs.gprs[11]); run->s.regs.gprs[11]);
...@@ -200,10 +194,7 @@ void test_clear_kvm_dirty_regs_bits(struct kvm_vcpu *vcpu) ...@@ -200,10 +194,7 @@ void test_clear_kvm_dirty_regs_bits(struct kvm_vcpu *vcpu)
run->s.regs.diag318 = 0x4B1D; run->s.regs.diag318 = 0x4B1D;
rv = _vcpu_run(vcpu); rv = _vcpu_run(vcpu);
TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv); TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv);
TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC);
"Unexpected exit reason: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
TEST_ASSERT(run->s.regs.gprs[11] != 0xDEADBEEF, TEST_ASSERT(run->s.regs.gprs[11] != 0xDEADBEEF,
"r11 sync regs value incorrect 0x%llx.", "r11 sync regs value incorrect 0x%llx.",
run->s.regs.gprs[11]); run->s.regs.gprs[11]);
......
...@@ -308,7 +308,6 @@ static void test_delete_memory_region(void) ...@@ -308,7 +308,6 @@ static void test_delete_memory_region(void)
static void test_zero_memory_regions(void) static void test_zero_memory_regions(void)
{ {
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_run *run;
struct kvm_vm *vm; struct kvm_vm *vm;
pr_info("Testing KVM_RUN with zero added memory regions\n"); pr_info("Testing KVM_RUN with zero added memory regions\n");
...@@ -318,10 +317,7 @@ static void test_zero_memory_regions(void) ...@@ -318,10 +317,7 @@ static void test_zero_memory_regions(void)
vm_ioctl(vm, KVM_SET_NR_MMU_PAGES, (void *)64ul); vm_ioctl(vm, KVM_SET_NR_MMU_PAGES, (void *)64ul);
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_INTERNAL_ERROR);
run = vcpu->run;
TEST_ASSERT(run->exit_reason == KVM_EXIT_INTERNAL_ERROR,
"Unexpected exit_reason = %u\n", run->exit_reason);
kvm_vm_free(vm); kvm_vm_free(vm);
} }
......
...@@ -241,7 +241,6 @@ int main(int argc, char *argv[]) ...@@ -241,7 +241,6 @@ int main(int argc, char *argv[])
struct kvm_regs regs1, regs2; struct kvm_regs regs1, regs2;
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_run *run;
struct kvm_x86_state *state; struct kvm_x86_state *state;
int xsave_restore_size; int xsave_restore_size;
vm_vaddr_t amx_cfg, tiledata, xsavedata; vm_vaddr_t amx_cfg, tiledata, xsavedata;
...@@ -268,7 +267,6 @@ int main(int argc, char *argv[]) ...@@ -268,7 +267,6 @@ int main(int argc, char *argv[])
"KVM should enumerate max XSAVE size when XSAVE is supported"); "KVM should enumerate max XSAVE size when XSAVE is supported");
xsave_restore_size = kvm_cpu_property(X86_PROPERTY_XSTATE_MAX_SIZE); xsave_restore_size = kvm_cpu_property(X86_PROPERTY_XSTATE_MAX_SIZE);
run = vcpu->run;
vcpu_regs_get(vcpu, &regs1); vcpu_regs_get(vcpu, &regs1);
/* Register #NM handler */ /* Register #NM handler */
...@@ -291,10 +289,7 @@ int main(int argc, char *argv[]) ...@@ -291,10 +289,7 @@ int main(int argc, char *argv[])
for (stage = 1; ; stage++) { for (stage = 1; ; stage++) {
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Stage %d: unexpected exit reason: %u (%s),\n",
stage, run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
...@@ -350,7 +345,6 @@ int main(int argc, char *argv[]) ...@@ -350,7 +345,6 @@ int main(int argc, char *argv[])
/* Restore state in a new VM. */ /* Restore state in a new VM. */
vcpu = vm_recreate_with_one_vcpu(vm); vcpu = vm_recreate_with_one_vcpu(vm);
vcpu_load_state(vcpu, state); vcpu_load_state(vcpu, state);
run = vcpu->run;
kvm_x86_state_cleanup(state); kvm_x86_state_cleanup(state);
memset(&regs2, 0, sizeof(regs2)); memset(&regs2, 0, sizeof(regs2));
......
...@@ -50,7 +50,6 @@ static void guest_code(void) ...@@ -50,7 +50,6 @@ static void guest_code(void)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_run *run;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_sregs sregs; struct kvm_sregs sregs;
struct ucall uc; struct ucall uc;
...@@ -58,15 +57,10 @@ int main(int argc, char *argv[]) ...@@ -58,15 +57,10 @@ int main(int argc, char *argv[])
TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XSAVE)); TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XSAVE));
vm = vm_create_with_one_vcpu(&vcpu, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
run = vcpu->run;
while (1) { while (1) {
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
"Unexpected exit reason: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_SYNC: case UCALL_SYNC:
......
...@@ -204,7 +204,7 @@ int main(void) ...@@ -204,7 +204,7 @@ int main(void)
vcpu_guest_debug_set(vcpu, &debug); vcpu_guest_debug_set(vcpu, &debug);
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, "KVM_EXIT_IO"); TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
cmd = get_ucall(vcpu, &uc); cmd = get_ucall(vcpu, &uc);
TEST_ASSERT(cmd == UCALL_DONE, "UCALL_DONE"); TEST_ASSERT(cmd == UCALL_DONE, "UCALL_DONE");
......
...@@ -24,10 +24,7 @@ static inline void handle_flds_emulation_failure_exit(struct kvm_vcpu *vcpu) ...@@ -24,10 +24,7 @@ static inline void handle_flds_emulation_failure_exit(struct kvm_vcpu *vcpu)
uint8_t *insn_bytes; uint8_t *insn_bytes;
uint64_t flags; uint64_t flags;
TEST_ASSERT(run->exit_reason == KVM_EXIT_INTERNAL_ERROR, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_INTERNAL_ERROR);
"Unexpected exit reason: %u (%s)",
run->exit_reason,
exit_reason_str(run->exit_reason));
TEST_ASSERT(run->emulation_failure.suberror == KVM_INTERNAL_ERROR_EMULATION, TEST_ASSERT(run->emulation_failure.suberror == KVM_INTERNAL_ERROR_EMULATION,
"Unexpected suberror: %u", "Unexpected suberror: %u",
......
...@@ -207,13 +207,11 @@ int main(void) ...@@ -207,13 +207,11 @@ int main(void)
{ {
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_run *run;
struct ucall uc; struct ucall uc;
vm_vaddr_t tsc_page_gva; vm_vaddr_t tsc_page_gva;
int stage; int stage;
vm = vm_create_with_one_vcpu(&vcpu, guest_main); vm = vm_create_with_one_vcpu(&vcpu, guest_main);
run = vcpu->run;
vcpu_set_hv_cpuid(vcpu); vcpu_set_hv_cpuid(vcpu);
...@@ -227,10 +225,7 @@ int main(void) ...@@ -227,10 +225,7 @@ int main(void)
for (stage = 1;; stage++) { for (stage = 1;; stage++) {
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Stage %d: unexpected exit reason: %u (%s),\n",
stage, run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
...@@ -237,7 +237,6 @@ int main(int argc, char *argv[]) ...@@ -237,7 +237,6 @@ int main(int argc, char *argv[])
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_run *run;
struct ucall uc; struct ucall uc;
int stage; int stage;
...@@ -266,13 +265,8 @@ int main(int argc, char *argv[]) ...@@ -266,13 +265,8 @@ int main(int argc, char *argv[])
pr_info("Running L1 which uses EVMCS to run L2\n"); pr_info("Running L1 which uses EVMCS to run L2\n");
for (stage = 1;; stage++) { for (stage = 1;; stage++) {
run = vcpu->run;
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Stage %d: unexpected exit reason: %u (%s),\n",
stage, run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
...@@ -122,7 +122,6 @@ static void guest_test_msrs_access(void) ...@@ -122,7 +122,6 @@ static void guest_test_msrs_access(void)
{ {
struct kvm_cpuid2 *prev_cpuid = NULL; struct kvm_cpuid2 *prev_cpuid = NULL;
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_run *run;
struct kvm_vm *vm; struct kvm_vm *vm;
struct ucall uc; struct ucall uc;
int stage = 0; int stage = 0;
...@@ -151,8 +150,6 @@ static void guest_test_msrs_access(void) ...@@ -151,8 +150,6 @@ static void guest_test_msrs_access(void)
vm_init_descriptor_tables(vm); vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu); vcpu_init_descriptor_tables(vcpu);
run = vcpu->run;
/* TODO: Make this entire test easier to maintain. */ /* TODO: Make this entire test easier to maintain. */
if (stage >= 21) if (stage >= 21)
vcpu_enable_cap(vcpu, KVM_CAP_HYPERV_SYNIC2, 0); vcpu_enable_cap(vcpu, KVM_CAP_HYPERV_SYNIC2, 0);
...@@ -494,9 +491,7 @@ static void guest_test_msrs_access(void) ...@@ -494,9 +491,7 @@ static void guest_test_msrs_access(void)
msr->idx, msr->write ? "write" : "read"); msr->idx, msr->write ? "write" : "read");
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"unexpected exit reason: %u (%s)",
run->exit_reason, exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
...@@ -518,7 +513,6 @@ static void guest_test_hcalls_access(void) ...@@ -518,7 +513,6 @@ static void guest_test_hcalls_access(void)
{ {
struct kvm_cpuid2 *prev_cpuid = NULL; struct kvm_cpuid2 *prev_cpuid = NULL;
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_run *run;
struct kvm_vm *vm; struct kvm_vm *vm;
struct ucall uc; struct ucall uc;
int stage = 0; int stage = 0;
...@@ -550,8 +544,6 @@ static void guest_test_hcalls_access(void) ...@@ -550,8 +544,6 @@ static void guest_test_hcalls_access(void)
vcpu_init_cpuid(vcpu, prev_cpuid); vcpu_init_cpuid(vcpu, prev_cpuid);
} }
run = vcpu->run;
switch (stage) { switch (stage) {
case 0: case 0:
vcpu_set_cpuid_feature(vcpu, HV_MSR_HYPERCALL_AVAILABLE); vcpu_set_cpuid_feature(vcpu, HV_MSR_HYPERCALL_AVAILABLE);
...@@ -669,9 +661,7 @@ static void guest_test_hcalls_access(void) ...@@ -669,9 +661,7 @@ static void guest_test_hcalls_access(void)
pr_debug("Stage %d: testing hcall: 0x%lx\n", stage, hcall->control); pr_debug("Stage %d: testing hcall: 0x%lx\n", stage, hcall->control);
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"unexpected exit reason: %u (%s)",
run->exit_reason, exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
...@@ -243,7 +243,6 @@ int main(int argc, char *argv[]) ...@@ -243,7 +243,6 @@ int main(int argc, char *argv[])
{ {
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_vcpu *vcpu[3]; struct kvm_vcpu *vcpu[3];
unsigned int exit_reason;
vm_vaddr_t hcall_page; vm_vaddr_t hcall_page;
pthread_t threads[2]; pthread_t threads[2];
int stage = 1, r; int stage = 1, r;
...@@ -283,10 +282,7 @@ int main(int argc, char *argv[]) ...@@ -283,10 +282,7 @@ int main(int argc, char *argv[])
while (true) { while (true) {
vcpu_run(vcpu[0]); vcpu_run(vcpu[0]);
exit_reason = vcpu[0]->run->exit_reason; TEST_ASSERT_KVM_EXIT_REASON(vcpu[0], KVM_EXIT_IO);
TEST_ASSERT(exit_reason == KVM_EXIT_IO,
"unexpected exit reason: %u (%s)",
exit_reason, exit_reason_str(exit_reason));
switch (get_ucall(vcpu[0], &uc)) { switch (get_ucall(vcpu[0], &uc)) {
case UCALL_SYNC: case UCALL_SYNC:
......
...@@ -156,7 +156,6 @@ int main(int argc, char *argv[]) ...@@ -156,7 +156,6 @@ int main(int argc, char *argv[])
vm_vaddr_t hcall_page; vm_vaddr_t hcall_page;
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_run *run;
struct ucall uc; struct ucall uc;
int stage; int stage;
...@@ -165,7 +164,6 @@ int main(int argc, char *argv[]) ...@@ -165,7 +164,6 @@ int main(int argc, char *argv[])
/* Create VM */ /* Create VM */
vm = vm_create_with_one_vcpu(&vcpu, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
vcpu_set_hv_cpuid(vcpu); vcpu_set_hv_cpuid(vcpu);
run = vcpu->run;
vcpu_alloc_svm(vm, &nested_gva); vcpu_alloc_svm(vm, &nested_gva);
vcpu_alloc_hyperv_test_pages(vm, &hv_pages_gva); vcpu_alloc_hyperv_test_pages(vm, &hv_pages_gva);
...@@ -177,10 +175,7 @@ int main(int argc, char *argv[]) ...@@ -177,10 +175,7 @@ int main(int argc, char *argv[])
for (stage = 1;; stage++) { for (stage = 1;; stage++) {
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Stage %d: unexpected exit reason: %u (%s),\n",
stage, run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
...@@ -542,18 +542,13 @@ static void *vcpu_thread(void *arg) ...@@ -542,18 +542,13 @@ static void *vcpu_thread(void *arg)
struct ucall uc; struct ucall uc;
int old; int old;
int r; int r;
unsigned int exit_reason;
r = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old); r = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old);
TEST_ASSERT(!r, "pthread_setcanceltype failed on vcpu_id=%u with errno=%d", TEST_ASSERT(!r, "pthread_setcanceltype failed on vcpu_id=%u with errno=%d",
vcpu->id, r); vcpu->id, r);
vcpu_run(vcpu); vcpu_run(vcpu);
exit_reason = vcpu->run->exit_reason; TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
TEST_ASSERT(exit_reason == KVM_EXIT_IO,
"vCPU %u exited with unexpected exit reason %u-%s, expected KVM_EXIT_IO",
vcpu->id, exit_reason, exit_reason_str(exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
...@@ -587,7 +582,6 @@ int main(int argc, char *argv[]) ...@@ -587,7 +582,6 @@ int main(int argc, char *argv[])
{ {
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_vcpu *vcpu[3]; struct kvm_vcpu *vcpu[3];
unsigned int exit_reason;
pthread_t threads[2]; pthread_t threads[2];
vm_vaddr_t test_data_page, gva; vm_vaddr_t test_data_page, gva;
vm_paddr_t gpa; vm_paddr_t gpa;
...@@ -657,11 +651,7 @@ int main(int argc, char *argv[]) ...@@ -657,11 +651,7 @@ int main(int argc, char *argv[])
while (true) { while (true) {
vcpu_run(vcpu[0]); vcpu_run(vcpu[0]);
exit_reason = vcpu[0]->run->exit_reason; TEST_ASSERT_KVM_EXIT_REASON(vcpu[0], KVM_EXIT_IO);
TEST_ASSERT(exit_reason == KVM_EXIT_IO,
"unexpected exit reason: %u (%s)",
exit_reason, exit_reason_str(exit_reason));
switch (get_ucall(vcpu[0], &uc)) { switch (get_ucall(vcpu[0], &uc)) {
case UCALL_SYNC: case UCALL_SYNC:
......
...@@ -105,7 +105,6 @@ static void setup_clock(struct kvm_vm *vm, struct test_case *test_case) ...@@ -105,7 +105,6 @@ static void setup_clock(struct kvm_vm *vm, struct test_case *test_case)
static void enter_guest(struct kvm_vcpu *vcpu) static void enter_guest(struct kvm_vcpu *vcpu)
{ {
struct kvm_clock_data start, end; struct kvm_clock_data start, end;
struct kvm_run *run = vcpu->run;
struct kvm_vm *vm = vcpu->vm; struct kvm_vm *vm = vcpu->vm;
struct ucall uc; struct ucall uc;
int i; int i;
...@@ -118,9 +117,7 @@ static void enter_guest(struct kvm_vcpu *vcpu) ...@@ -118,9 +117,7 @@ static void enter_guest(struct kvm_vcpu *vcpu)
vcpu_run(vcpu); vcpu_run(vcpu);
vm_ioctl(vm, KVM_GET_CLOCK, &end); vm_ioctl(vm, KVM_GET_CLOCK, &end);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"unexpected exit reason: %u (%s)",
run->exit_reason, exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_SYNC: case UCALL_SYNC:
......
...@@ -111,14 +111,11 @@ static void pr_hcall(struct ucall *uc) ...@@ -111,14 +111,11 @@ static void pr_hcall(struct ucall *uc)
static void enter_guest(struct kvm_vcpu *vcpu) static void enter_guest(struct kvm_vcpu *vcpu)
{ {
struct kvm_run *run = vcpu->run;
struct ucall uc; struct ucall uc;
while (true) { while (true) {
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"unexpected exit reason: %u (%s)",
run->exit_reason, exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_PR_MSR: case UCALL_PR_MSR:
......
...@@ -64,7 +64,6 @@ int main(int argc, char *argv[]) ...@@ -64,7 +64,6 @@ int main(int argc, char *argv[])
{ {
uint64_t disabled_quirks; uint64_t disabled_quirks;
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_run *run;
struct kvm_vm *vm; struct kvm_vm *vm;
struct ucall uc; struct ucall uc;
int testcase; int testcase;
...@@ -74,18 +73,12 @@ int main(int argc, char *argv[]) ...@@ -74,18 +73,12 @@ int main(int argc, char *argv[])
vm = vm_create_with_one_vcpu(&vcpu, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
vcpu_clear_cpuid_feature(vcpu, X86_FEATURE_MWAIT); vcpu_clear_cpuid_feature(vcpu, X86_FEATURE_MWAIT);
run = vcpu->run;
vm_init_descriptor_tables(vm); vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu); vcpu_init_descriptor_tables(vcpu);
while (1) { while (1) {
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
"Unexpected exit reason: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_SYNC: case UCALL_SYNC:
......
...@@ -166,12 +166,9 @@ static void __attribute__((__flatten__)) l1_guest_code(void *test_data) ...@@ -166,12 +166,9 @@ static void __attribute__((__flatten__)) l1_guest_code(void *test_data)
static void assert_ucall_vector(struct kvm_vcpu *vcpu, int vector) static void assert_ucall_vector(struct kvm_vcpu *vcpu, int vector)
{ {
struct kvm_run *run = vcpu->run;
struct ucall uc; struct ucall uc;
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Unexpected exit reason: %u (%s),\n",
run->exit_reason, exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_SYNC: case UCALL_SYNC:
......
...@@ -36,15 +36,12 @@ static void guest_code(void) ...@@ -36,15 +36,12 @@ static void guest_code(void)
static void test_msr_platform_info_enabled(struct kvm_vcpu *vcpu) static void test_msr_platform_info_enabled(struct kvm_vcpu *vcpu)
{ {
struct kvm_run *run = vcpu->run;
struct ucall uc; struct ucall uc;
vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, true); vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, true);
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Exit_reason other than KVM_EXIT_IO: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
get_ucall(vcpu, &uc); get_ucall(vcpu, &uc);
TEST_ASSERT(uc.cmd == UCALL_SYNC, TEST_ASSERT(uc.cmd == UCALL_SYNC,
"Received ucall other than UCALL_SYNC: %lu\n", uc.cmd); "Received ucall other than UCALL_SYNC: %lu\n", uc.cmd);
...@@ -56,14 +53,9 @@ static void test_msr_platform_info_enabled(struct kvm_vcpu *vcpu) ...@@ -56,14 +53,9 @@ static void test_msr_platform_info_enabled(struct kvm_vcpu *vcpu)
static void test_msr_platform_info_disabled(struct kvm_vcpu *vcpu) static void test_msr_platform_info_disabled(struct kvm_vcpu *vcpu)
{ {
struct kvm_run *run = vcpu->run;
vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, false); vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, false);
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_SHUTDOWN, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN);
"Exit_reason other than KVM_EXIT_SHUTDOWN: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
......
...@@ -151,14 +151,10 @@ static void amd_guest_code(void) ...@@ -151,14 +151,10 @@ static void amd_guest_code(void)
*/ */
static uint64_t run_vcpu_to_sync(struct kvm_vcpu *vcpu) static uint64_t run_vcpu_to_sync(struct kvm_vcpu *vcpu)
{ {
struct kvm_run *run = vcpu->run;
struct ucall uc; struct ucall uc;
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Exit_reason other than KVM_EXIT_IO: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
get_ucall(vcpu, &uc); get_ucall(vcpu, &uc);
TEST_ASSERT(uc.cmd == UCALL_SYNC, TEST_ASSERT(uc.cmd == UCALL_SYNC,
"Received ucall other than UCALL_SYNC: %lu", uc.cmd); "Received ucall other than UCALL_SYNC: %lu", uc.cmd);
......
...@@ -133,7 +133,6 @@ int main(int argc, char *argv[]) ...@@ -133,7 +133,6 @@ int main(int argc, char *argv[])
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_regs regs; struct kvm_regs regs;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_run *run;
struct kvm_x86_state *state; struct kvm_x86_state *state;
int stage, stage_reported; int stage, stage_reported;
...@@ -142,8 +141,6 @@ int main(int argc, char *argv[]) ...@@ -142,8 +141,6 @@ int main(int argc, char *argv[])
/* Create VM */ /* Create VM */
vm = vm_create_with_one_vcpu(&vcpu, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
run = vcpu->run;
vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, SMRAM_GPA, vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, SMRAM_GPA,
SMRAM_MEMSLOT, SMRAM_PAGES, 0); SMRAM_MEMSLOT, SMRAM_PAGES, 0);
TEST_ASSERT(vm_phy_pages_alloc(vm, SMRAM_PAGES, SMRAM_GPA, SMRAM_MEMSLOT) TEST_ASSERT(vm_phy_pages_alloc(vm, SMRAM_PAGES, SMRAM_GPA, SMRAM_MEMSLOT)
...@@ -169,10 +166,7 @@ int main(int argc, char *argv[]) ...@@ -169,10 +166,7 @@ int main(int argc, char *argv[])
for (stage = 1;; stage++) { for (stage = 1;; stage++) {
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Stage %d: unexpected exit reason: %u (%s),\n",
stage, run->exit_reason,
exit_reason_str(run->exit_reason));
memset(&regs, 0, sizeof(regs)); memset(&regs, 0, sizeof(regs));
vcpu_regs_get(vcpu, &regs); vcpu_regs_get(vcpu, &regs);
...@@ -208,7 +202,6 @@ int main(int argc, char *argv[]) ...@@ -208,7 +202,6 @@ int main(int argc, char *argv[])
vcpu = vm_recreate_with_one_vcpu(vm); vcpu = vm_recreate_with_one_vcpu(vm);
vcpu_load_state(vcpu, state); vcpu_load_state(vcpu, state);
run = vcpu->run;
kvm_x86_state_cleanup(state); kvm_x86_state_cleanup(state);
} }
......
...@@ -158,14 +158,12 @@ int main(int argc, char *argv[]) ...@@ -158,14 +158,12 @@ int main(int argc, char *argv[])
struct kvm_regs regs1, regs2; struct kvm_regs regs1, regs2;
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_run *run;
struct kvm_x86_state *state; struct kvm_x86_state *state;
struct ucall uc; struct ucall uc;
int stage; int stage;
/* Create VM */ /* Create VM */
vm = vm_create_with_one_vcpu(&vcpu, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
run = vcpu->run;
vcpu_regs_get(vcpu, &regs1); vcpu_regs_get(vcpu, &regs1);
...@@ -183,10 +181,7 @@ int main(int argc, char *argv[]) ...@@ -183,10 +181,7 @@ int main(int argc, char *argv[])
for (stage = 1;; stage++) { for (stage = 1;; stage++) {
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Stage %d: unexpected exit reason: %u (%s),\n",
stage, run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
...@@ -214,7 +209,6 @@ int main(int argc, char *argv[]) ...@@ -214,7 +209,6 @@ int main(int argc, char *argv[])
/* Restore state in a new VM. */ /* Restore state in a new VM. */
vcpu = vm_recreate_with_one_vcpu(vm); vcpu = vm_recreate_with_one_vcpu(vm);
vcpu_load_state(vcpu, state); vcpu_load_state(vcpu, state);
run = vcpu->run;
kvm_x86_state_cleanup(state); kvm_x86_state_cleanup(state);
memset(&regs2, 0, sizeof(regs2)); memset(&regs2, 0, sizeof(regs2));
......
...@@ -85,7 +85,6 @@ static void l1_guest_code(struct svm_test_data *svm) ...@@ -85,7 +85,6 @@ static void l1_guest_code(struct svm_test_data *svm)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_run *run;
vm_vaddr_t svm_gva; vm_vaddr_t svm_gva;
struct kvm_vm *vm; struct kvm_vm *vm;
struct ucall uc; struct ucall uc;
...@@ -103,13 +102,8 @@ int main(int argc, char *argv[]) ...@@ -103,13 +102,8 @@ int main(int argc, char *argv[])
vcpu_alloc_svm(vm, &svm_gva); vcpu_alloc_svm(vm, &svm_gva);
vcpu_args_set(vcpu, 1, svm_gva); vcpu_args_set(vcpu, 1, svm_gva);
run = vcpu->run;
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
...@@ -42,7 +42,6 @@ static void l1_guest_code(struct svm_test_data *svm, struct idt_entry *idt) ...@@ -42,7 +42,6 @@ static void l1_guest_code(struct svm_test_data *svm, struct idt_entry *idt)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_run *run;
vm_vaddr_t svm_gva; vm_vaddr_t svm_gva;
struct kvm_vm *vm; struct kvm_vm *vm;
...@@ -55,13 +54,9 @@ int main(int argc, char *argv[]) ...@@ -55,13 +54,9 @@ int main(int argc, char *argv[])
vcpu_alloc_svm(vm, &svm_gva); vcpu_alloc_svm(vm, &svm_gva);
vcpu_args_set(vcpu, 2, svm_gva, vm->idt); vcpu_args_set(vcpu, 2, svm_gva, vm->idt);
run = vcpu->run;
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_SHUTDOWN, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN);
"Got exit_reason other than KVM_EXIT_SHUTDOWN: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
kvm_vm_free(vm); kvm_vm_free(vm);
} }
...@@ -176,16 +176,12 @@ static void run_test(bool is_nmi) ...@@ -176,16 +176,12 @@ static void run_test(bool is_nmi)
memset(&debug, 0, sizeof(debug)); memset(&debug, 0, sizeof(debug));
vcpu_guest_debug_set(vcpu, &debug); vcpu_guest_debug_set(vcpu, &debug);
struct kvm_run *run = vcpu->run;
struct ucall uc; struct ucall uc;
alarm(2); alarm(2);
vcpu_run(vcpu); vcpu_run(vcpu);
alarm(0); alarm(0);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
...@@ -47,14 +47,10 @@ int main(int argc, char *argv[]) ...@@ -47,14 +47,10 @@ int main(int argc, char *argv[])
vcpu_args_set(vcpu, 1, svm_gva); vcpu_args_set(vcpu, 1, svm_gva);
for (;;) { for (;;) {
volatile struct kvm_run *run = vcpu->run;
struct ucall uc; struct ucall uc;
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
...@@ -132,10 +132,7 @@ int main(int argc, char *argv[]) ...@@ -132,10 +132,7 @@ int main(int argc, char *argv[])
/* TODO: BUILD TIME CHECK: TEST_ASSERT(KVM_SYNC_X86_NUM_FIELDS != 3); */ /* TODO: BUILD TIME CHECK: TEST_ASSERT(KVM_SYNC_X86_NUM_FIELDS != 3); */
run->kvm_valid_regs = TEST_SYNC_FIELDS; run->kvm_valid_regs = TEST_SYNC_FIELDS;
rv = _vcpu_run(vcpu); rv = _vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Unexpected exit reason: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
vcpu_regs_get(vcpu, &regs); vcpu_regs_get(vcpu, &regs);
compare_regs(&regs, &run->s.regs.regs); compare_regs(&regs, &run->s.regs.regs);
...@@ -154,10 +151,7 @@ int main(int argc, char *argv[]) ...@@ -154,10 +151,7 @@ int main(int argc, char *argv[])
run->kvm_valid_regs = TEST_SYNC_FIELDS; run->kvm_valid_regs = TEST_SYNC_FIELDS;
run->kvm_dirty_regs = KVM_SYNC_X86_REGS | KVM_SYNC_X86_SREGS; run->kvm_dirty_regs = KVM_SYNC_X86_REGS | KVM_SYNC_X86_SREGS;
rv = _vcpu_run(vcpu); rv = _vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Unexpected exit reason: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
TEST_ASSERT(run->s.regs.regs.rbx == 0xBAD1DEA + 1, TEST_ASSERT(run->s.regs.regs.rbx == 0xBAD1DEA + 1,
"rbx sync regs value incorrect 0x%llx.", "rbx sync regs value incorrect 0x%llx.",
run->s.regs.regs.rbx); run->s.regs.regs.rbx);
...@@ -181,10 +175,7 @@ int main(int argc, char *argv[]) ...@@ -181,10 +175,7 @@ int main(int argc, char *argv[])
run->kvm_dirty_regs = 0; run->kvm_dirty_regs = 0;
run->s.regs.regs.rbx = 0xDEADBEEF; run->s.regs.regs.rbx = 0xDEADBEEF;
rv = _vcpu_run(vcpu); rv = _vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Unexpected exit reason: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
TEST_ASSERT(run->s.regs.regs.rbx != 0xDEADBEEF, TEST_ASSERT(run->s.regs.regs.rbx != 0xDEADBEEF,
"rbx sync regs value incorrect 0x%llx.", "rbx sync regs value incorrect 0x%llx.",
run->s.regs.regs.rbx); run->s.regs.regs.rbx);
...@@ -199,10 +190,7 @@ int main(int argc, char *argv[]) ...@@ -199,10 +190,7 @@ int main(int argc, char *argv[])
regs.rbx = 0xBAC0; regs.rbx = 0xBAC0;
vcpu_regs_set(vcpu, &regs); vcpu_regs_set(vcpu, &regs);
rv = _vcpu_run(vcpu); rv = _vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Unexpected exit reason: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
TEST_ASSERT(run->s.regs.regs.rbx == 0xAAAA, TEST_ASSERT(run->s.regs.regs.rbx == 0xAAAA,
"rbx sync regs value incorrect 0x%llx.", "rbx sync regs value incorrect 0x%llx.",
run->s.regs.regs.rbx); run->s.regs.regs.rbx);
...@@ -219,10 +207,7 @@ int main(int argc, char *argv[]) ...@@ -219,10 +207,7 @@ int main(int argc, char *argv[])
run->kvm_dirty_regs = TEST_SYNC_FIELDS; run->kvm_dirty_regs = TEST_SYNC_FIELDS;
run->s.regs.regs.rbx = 0xBBBB; run->s.regs.regs.rbx = 0xBBBB;
rv = _vcpu_run(vcpu); rv = _vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Unexpected exit reason: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
TEST_ASSERT(run->s.regs.regs.rbx == 0xBBBB, TEST_ASSERT(run->s.regs.regs.rbx == 0xBBBB,
"rbx sync regs value incorrect 0x%llx.", "rbx sync regs value incorrect 0x%llx.",
run->s.regs.regs.rbx); run->s.regs.regs.rbx);
......
...@@ -89,9 +89,7 @@ int main(void) ...@@ -89,9 +89,7 @@ int main(void)
run = vcpu->run; run = vcpu->run;
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Expected KVM_EXIT_IO, got: %u (%s)\n",
run->exit_reason, exit_reason_str(run->exit_reason));
TEST_ASSERT(run->io.port == ARBITRARY_IO_PORT, TEST_ASSERT(run->io.port == ARBITRARY_IO_PORT,
"Expected IN from port %d from L2, got port %d", "Expected IN from port %d from L2, got port %d",
ARBITRARY_IO_PORT, run->io.port); ARBITRARY_IO_PORT, run->io.port);
...@@ -111,10 +109,7 @@ int main(void) ...@@ -111,10 +109,7 @@ int main(void)
if (has_svm) { if (has_svm) {
TEST_ASSERT(run->exit_reason == KVM_EXIT_SHUTDOWN, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN);
"Got exit_reason other than KVM_EXIT_SHUTDOWN: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
} else { } else {
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_DONE: case UCALL_DONE:
......
...@@ -64,14 +64,10 @@ static void *run_vcpu(void *_cpu_nr) ...@@ -64,14 +64,10 @@ static void *run_vcpu(void *_cpu_nr)
pthread_spin_unlock(&create_lock); pthread_spin_unlock(&create_lock);
for (;;) { for (;;) {
volatile struct kvm_run *run = vcpu->run;
struct ucall uc; struct ucall uc;
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_DONE: case UCALL_DONE:
......
...@@ -137,15 +137,11 @@ static void guest_gp_handler(struct ex_regs *regs) ...@@ -137,15 +137,11 @@ static void guest_gp_handler(struct ex_regs *regs)
static void run_vcpu_expect_gp(struct kvm_vcpu *vcpu) static void run_vcpu_expect_gp(struct kvm_vcpu *vcpu)
{ {
unsigned int exit_reason;
struct ucall uc; struct ucall uc;
vcpu_run(vcpu); vcpu_run(vcpu);
exit_reason = vcpu->run->exit_reason; TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
TEST_ASSERT(exit_reason == KVM_EXIT_IO,
"exited with unexpected exit reason %u-%s, expected KVM_EXIT_IO",
exit_reason, exit_reason_str(exit_reason));
TEST_ASSERT(get_ucall(vcpu, &uc) == UCALL_SYNC, TEST_ASSERT(get_ucall(vcpu, &uc) == UCALL_SYNC,
"Expect UCALL_SYNC\n"); "Expect UCALL_SYNC\n");
TEST_ASSERT(uc.args[1] == SYNC_GP, "#GP is expected."); TEST_ASSERT(uc.args[1] == SYNC_GP, "#GP is expected.");
...@@ -182,7 +178,6 @@ static void *run_ucna_injection(void *arg) ...@@ -182,7 +178,6 @@ static void *run_ucna_injection(void *arg)
struct ucall uc; struct ucall uc;
int old; int old;
int r; int r;
unsigned int exit_reason;
r = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old); r = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old);
TEST_ASSERT(r == 0, TEST_ASSERT(r == 0,
...@@ -191,10 +186,7 @@ static void *run_ucna_injection(void *arg) ...@@ -191,10 +186,7 @@ static void *run_ucna_injection(void *arg)
vcpu_run(params->vcpu); vcpu_run(params->vcpu);
exit_reason = params->vcpu->run->exit_reason; TEST_ASSERT_KVM_EXIT_REASON(params->vcpu, KVM_EXIT_IO);
TEST_ASSERT(exit_reason == KVM_EXIT_IO,
"unexpected exit reason %u-%s, expected KVM_EXIT_IO",
exit_reason, exit_reason_str(exit_reason));
TEST_ASSERT(get_ucall(params->vcpu, &uc) == UCALL_SYNC, TEST_ASSERT(get_ucall(params->vcpu, &uc) == UCALL_SYNC,
"Expect UCALL_SYNC\n"); "Expect UCALL_SYNC\n");
TEST_ASSERT(uc.args[1] == SYNC_FIRST_UCNA, "Injecting first UCNA."); TEST_ASSERT(uc.args[1] == SYNC_FIRST_UCNA, "Injecting first UCNA.");
...@@ -204,10 +196,7 @@ static void *run_ucna_injection(void *arg) ...@@ -204,10 +196,7 @@ static void *run_ucna_injection(void *arg)
inject_ucna(params->vcpu, FIRST_UCNA_ADDR); inject_ucna(params->vcpu, FIRST_UCNA_ADDR);
vcpu_run(params->vcpu); vcpu_run(params->vcpu);
exit_reason = params->vcpu->run->exit_reason; TEST_ASSERT_KVM_EXIT_REASON(params->vcpu, KVM_EXIT_IO);
TEST_ASSERT(exit_reason == KVM_EXIT_IO,
"unexpected exit reason %u-%s, expected KVM_EXIT_IO",
exit_reason, exit_reason_str(exit_reason));
TEST_ASSERT(get_ucall(params->vcpu, &uc) == UCALL_SYNC, TEST_ASSERT(get_ucall(params->vcpu, &uc) == UCALL_SYNC,
"Expect UCALL_SYNC\n"); "Expect UCALL_SYNC\n");
TEST_ASSERT(uc.args[1] == SYNC_SECOND_UCNA, "Injecting second UCNA."); TEST_ASSERT(uc.args[1] == SYNC_SECOND_UCNA, "Injecting second UCNA.");
...@@ -217,10 +206,7 @@ static void *run_ucna_injection(void *arg) ...@@ -217,10 +206,7 @@ static void *run_ucna_injection(void *arg)
inject_ucna(params->vcpu, SECOND_UCNA_ADDR); inject_ucna(params->vcpu, SECOND_UCNA_ADDR);
vcpu_run(params->vcpu); vcpu_run(params->vcpu);
exit_reason = params->vcpu->run->exit_reason; TEST_ASSERT_KVM_EXIT_REASON(params->vcpu, KVM_EXIT_IO);
TEST_ASSERT(exit_reason == KVM_EXIT_IO,
"unexpected exit reason %u-%s, expected KVM_EXIT_IO",
exit_reason, exit_reason_str(exit_reason));
if (get_ucall(params->vcpu, &uc) == UCALL_ABORT) { if (get_ucall(params->vcpu, &uc) == UCALL_ABORT) {
TEST_ASSERT(false, "vCPU assertion failure: %s.\n", TEST_ASSERT(false, "vCPU assertion failure: %s.\n",
(const char *)uc.args[0]); (const char *)uc.args[0]);
......
...@@ -63,11 +63,7 @@ int main(int argc, char *argv[]) ...@@ -63,11 +63,7 @@ int main(int argc, char *argv[])
while (1) { while (1) {
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
"Unexpected exit reason: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
if (get_ucall(vcpu, &uc)) if (get_ucall(vcpu, &uc))
break; break;
......
...@@ -410,10 +410,7 @@ static void process_rdmsr(struct kvm_vcpu *vcpu, uint32_t msr_index) ...@@ -410,10 +410,7 @@ static void process_rdmsr(struct kvm_vcpu *vcpu, uint32_t msr_index)
check_for_guest_assert(vcpu); check_for_guest_assert(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_X86_RDMSR, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_X86_RDMSR);
"Unexpected exit reason: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
TEST_ASSERT(run->msr.index == msr_index, TEST_ASSERT(run->msr.index == msr_index,
"Unexpected msr (0x%04x), expected 0x%04x", "Unexpected msr (0x%04x), expected 0x%04x",
run->msr.index, msr_index); run->msr.index, msr_index);
...@@ -445,10 +442,7 @@ static void process_wrmsr(struct kvm_vcpu *vcpu, uint32_t msr_index) ...@@ -445,10 +442,7 @@ static void process_wrmsr(struct kvm_vcpu *vcpu, uint32_t msr_index)
check_for_guest_assert(vcpu); check_for_guest_assert(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_X86_WRMSR, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_X86_WRMSR);
"Unexpected exit reason: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
TEST_ASSERT(run->msr.index == msr_index, TEST_ASSERT(run->msr.index == msr_index,
"Unexpected msr (0x%04x), expected 0x%04x", "Unexpected msr (0x%04x), expected 0x%04x",
run->msr.index, msr_index); run->msr.index, msr_index);
...@@ -472,15 +466,11 @@ static void process_wrmsr(struct kvm_vcpu *vcpu, uint32_t msr_index) ...@@ -472,15 +466,11 @@ static void process_wrmsr(struct kvm_vcpu *vcpu, uint32_t msr_index)
static void process_ucall_done(struct kvm_vcpu *vcpu) static void process_ucall_done(struct kvm_vcpu *vcpu)
{ {
struct kvm_run *run = vcpu->run;
struct ucall uc; struct ucall uc;
check_for_guest_assert(vcpu); check_for_guest_assert(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Unexpected exit reason: %u (%s)",
run->exit_reason,
exit_reason_str(run->exit_reason));
TEST_ASSERT(get_ucall(vcpu, &uc) == UCALL_DONE, TEST_ASSERT(get_ucall(vcpu, &uc) == UCALL_DONE,
"Unexpected ucall command: %lu, expected UCALL_DONE (%d)", "Unexpected ucall command: %lu, expected UCALL_DONE (%d)",
...@@ -489,15 +479,11 @@ static void process_ucall_done(struct kvm_vcpu *vcpu) ...@@ -489,15 +479,11 @@ static void process_ucall_done(struct kvm_vcpu *vcpu)
static uint64_t process_ucall(struct kvm_vcpu *vcpu) static uint64_t process_ucall(struct kvm_vcpu *vcpu)
{ {
struct kvm_run *run = vcpu->run;
struct ucall uc = {}; struct ucall uc = {};
check_for_guest_assert(vcpu); check_for_guest_assert(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Unexpected exit reason: %u (%s)",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_SYNC: case UCALL_SYNC:
......
...@@ -96,21 +96,14 @@ int main(int argc, char *argv[]) ...@@ -96,21 +96,14 @@ int main(int argc, char *argv[])
vcpu_run(vcpu); vcpu_run(vcpu);
if (apic_access_addr == high_gpa) { if (apic_access_addr == high_gpa) {
TEST_ASSERT(run->exit_reason == TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_INTERNAL_ERROR);
KVM_EXIT_INTERNAL_ERROR,
"Got exit reason other than KVM_EXIT_INTERNAL_ERROR: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
TEST_ASSERT(run->internal.suberror == TEST_ASSERT(run->internal.suberror ==
KVM_INTERNAL_ERROR_EMULATION, KVM_INTERNAL_ERROR_EMULATION,
"Got internal suberror other than KVM_INTERNAL_ERROR_EMULATION: %u\n", "Got internal suberror other than KVM_INTERNAL_ERROR_EMULATION: %u\n",
run->internal.suberror); run->internal.suberror);
break; break;
} }
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
...@@ -64,10 +64,7 @@ int main(int argc, char *argv[]) ...@@ -64,10 +64,7 @@ int main(int argc, char *argv[])
struct ucall uc; struct ucall uc;
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
if (run->io.port == PORT_L0_EXIT) if (run->io.port == PORT_L0_EXIT)
break; break;
......
...@@ -73,7 +73,6 @@ int main(int argc, char *argv[]) ...@@ -73,7 +73,6 @@ int main(int argc, char *argv[])
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_run *run;
struct ucall uc; struct ucall uc;
bool done = false; bool done = false;
...@@ -84,7 +83,6 @@ int main(int argc, char *argv[]) ...@@ -84,7 +83,6 @@ int main(int argc, char *argv[])
vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code); vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
vmx = vcpu_alloc_vmx(vm, &vmx_pages_gva); vmx = vcpu_alloc_vmx(vm, &vmx_pages_gva);
vcpu_args_set(vcpu, 1, vmx_pages_gva); vcpu_args_set(vcpu, 1, vmx_pages_gva);
run = vcpu->run;
/* Add an extra memory slot for testing dirty logging */ /* Add an extra memory slot for testing dirty logging */
vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS,
...@@ -117,10 +115,7 @@ int main(int argc, char *argv[]) ...@@ -117,10 +115,7 @@ int main(int argc, char *argv[])
while (!done) { while (!done) {
memset(host_test_mem, 0xaa, TEST_MEM_PAGES * 4096); memset(host_test_mem, 0xaa, TEST_MEM_PAGES * 4096);
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Unexpected exit reason: %u (%s),\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
...@@ -26,9 +26,7 @@ static void __run_vcpu_with_invalid_state(struct kvm_vcpu *vcpu) ...@@ -26,9 +26,7 @@ static void __run_vcpu_with_invalid_state(struct kvm_vcpu *vcpu)
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_INTERNAL_ERROR, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_INTERNAL_ERROR);
"Expected KVM_EXIT_INTERNAL_ERROR, got %d (%s)\n",
run->exit_reason, exit_reason_str(run->exit_reason));
TEST_ASSERT(run->emulation_failure.suberror == KVM_INTERNAL_ERROR_EMULATION, TEST_ASSERT(run->emulation_failure.suberror == KVM_INTERNAL_ERROR_EMULATION,
"Expected emulation failure, got %d\n", "Expected emulation failure, got %d\n",
run->emulation_failure.suberror); run->emulation_failure.suberror);
......
...@@ -74,9 +74,7 @@ int main(int argc, char *argv[]) ...@@ -74,9 +74,7 @@ int main(int argc, char *argv[])
* The first exit to L0 userspace should be an I/O access from L2. * The first exit to L0 userspace should be an I/O access from L2.
* Running L1 should launch L2 without triggering an exit to userspace. * Running L1 should launch L2 without triggering an exit to userspace.
*/ */
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Expected KVM_EXIT_IO, got: %u (%s)\n",
run->exit_reason, exit_reason_str(run->exit_reason));
TEST_ASSERT(run->io.port == ARBITRARY_IO_PORT, TEST_ASSERT(run->io.port == ARBITRARY_IO_PORT,
"Expected IN from port %d from L2, got port %d", "Expected IN from port %d from L2, got port %d",
......
...@@ -183,14 +183,10 @@ int main(int argc, char *argv[]) ...@@ -183,14 +183,10 @@ int main(int argc, char *argv[])
vcpu_ioctl(vcpu, KVM_SET_TSC_KHZ, (void *) (tsc_khz / l1_scale_factor)); vcpu_ioctl(vcpu, KVM_SET_TSC_KHZ, (void *) (tsc_khz / l1_scale_factor));
for (;;) { for (;;) {
volatile struct kvm_run *run = vcpu->run;
struct ucall uc; struct ucall uc;
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
...@@ -157,7 +157,6 @@ int main(int argc, char *argv[]) ...@@ -157,7 +157,6 @@ int main(int argc, char *argv[])
struct kvm_regs regs1, regs2; struct kvm_regs regs1, regs2;
struct kvm_vm *vm; struct kvm_vm *vm;
struct kvm_run *run;
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_x86_state *state; struct kvm_x86_state *state;
struct ucall uc; struct ucall uc;
...@@ -173,7 +172,6 @@ int main(int argc, char *argv[]) ...@@ -173,7 +172,6 @@ int main(int argc, char *argv[])
/* Create VM */ /* Create VM */
vm = vm_create_with_one_vcpu(&vcpu, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
run = vcpu->run;
vcpu_regs_get(vcpu, &regs1); vcpu_regs_get(vcpu, &regs1);
...@@ -182,10 +180,7 @@ int main(int argc, char *argv[]) ...@@ -182,10 +180,7 @@ int main(int argc, char *argv[])
for (stage = 1;; stage++) { for (stage = 1;; stage++) {
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Stage %d: unexpected exit reason: %u (%s),\n",
stage, run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
...@@ -237,7 +232,6 @@ int main(int argc, char *argv[]) ...@@ -237,7 +232,6 @@ int main(int argc, char *argv[])
/* Restore state in a new VM. */ /* Restore state in a new VM. */
vcpu = vm_recreate_with_one_vcpu(vm); vcpu = vm_recreate_with_one_vcpu(vm);
vcpu_load_state(vcpu, state); vcpu_load_state(vcpu, state);
run = vcpu->run;
kvm_x86_state_cleanup(state); kvm_x86_state_cleanup(state);
memset(&regs2, 0, sizeof(regs2)); memset(&regs2, 0, sizeof(regs2));
......
...@@ -131,14 +131,10 @@ int main(int argc, char *argv[]) ...@@ -131,14 +131,10 @@ int main(int argc, char *argv[])
vcpu_args_set(vcpu, 1, vmx_pages_gva); vcpu_args_set(vcpu, 1, vmx_pages_gva);
for (;;) { for (;;) {
volatile struct kvm_run *run = vcpu->run;
struct ucall uc; struct ucall uc;
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
...@@ -198,7 +198,6 @@ static void *vcpu_thread(void *arg) ...@@ -198,7 +198,6 @@ static void *vcpu_thread(void *arg)
struct ucall uc; struct ucall uc;
int old; int old;
int r; int r;
unsigned int exit_reason;
r = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old); r = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old);
TEST_ASSERT(r == 0, TEST_ASSERT(r == 0,
...@@ -207,11 +206,8 @@ static void *vcpu_thread(void *arg) ...@@ -207,11 +206,8 @@ static void *vcpu_thread(void *arg)
fprintf(stderr, "vCPU thread running vCPU %u\n", vcpu->id); fprintf(stderr, "vCPU thread running vCPU %u\n", vcpu->id);
vcpu_run(vcpu); vcpu_run(vcpu);
exit_reason = vcpu->run->exit_reason;
TEST_ASSERT(exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"vCPU %u exited with unexpected exit reason %u-%s, expected KVM_EXIT_IO",
vcpu->id, exit_reason, exit_reason_str(exit_reason));
if (get_ucall(vcpu, &uc) == UCALL_ABORT) { if (get_ucall(vcpu, &uc) == UCALL_ABORT) {
TEST_ASSERT(false, TEST_ASSERT(false,
......
...@@ -622,15 +622,10 @@ int main(int argc, char *argv[]) ...@@ -622,15 +622,10 @@ int main(int argc, char *argv[])
bool evtchn_irq_expected = false; bool evtchn_irq_expected = false;
for (;;) { for (;;) {
volatile struct kvm_run *run = vcpu->run;
struct ucall uc; struct ucall uc;
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
"Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
...@@ -122,10 +122,7 @@ int main(int argc, char *argv[]) ...@@ -122,10 +122,7 @@ int main(int argc, char *argv[])
continue; continue;
} }
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
"Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
run->exit_reason,
exit_reason_str(run->exit_reason));
switch (get_ucall(vcpu, &uc)) { switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment