Commit f05427fa authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Sync stage before VM is freed in hypercalls test

Sync the next stage using the VM before said VM is potentially freed by
the TEST_STAGE_HVC_IFACE_FEAT_DISABLED stage.

Opportunistically take a double pointer in anticipation of also having to
set the new vCPU pointer once the test stops hardcoding '0' everywhere.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent bfff0f60
...@@ -246,32 +246,31 @@ static struct kvm_vm *test_vm_create(void) ...@@ -246,32 +246,31 @@ static struct kvm_vm *test_vm_create(void)
return vm; return vm;
} }
static struct kvm_vm *test_guest_stage(struct kvm_vm *vm) static void test_guest_stage(struct kvm_vm **vm)
{ {
struct kvm_vm *ret_vm = vm; int prev_stage = stage;
pr_debug("Stage: %d\n", stage); pr_debug("Stage: %d\n", prev_stage);
switch (stage) { /* Sync the stage early, the VM might be freed below. */
stage++;
sync_global_to_guest(*vm, stage);
switch (prev_stage) {
case TEST_STAGE_REG_IFACE: case TEST_STAGE_REG_IFACE:
test_fw_regs_after_vm_start(vm); test_fw_regs_after_vm_start(*vm);
break; break;
case TEST_STAGE_HVC_IFACE_FEAT_DISABLED: case TEST_STAGE_HVC_IFACE_FEAT_DISABLED:
/* Start a new VM so that all the features are now enabled by default */ /* Start a new VM so that all the features are now enabled by default */
kvm_vm_free(vm); kvm_vm_free(*vm);
ret_vm = test_vm_create(); *vm = test_vm_create();
break; break;
case TEST_STAGE_HVC_IFACE_FEAT_ENABLED: case TEST_STAGE_HVC_IFACE_FEAT_ENABLED:
case TEST_STAGE_HVC_IFACE_FALSE_INFO: case TEST_STAGE_HVC_IFACE_FALSE_INFO:
break; break;
default: default:
TEST_FAIL("Unknown test stage: %d\n", stage); TEST_FAIL("Unknown test stage: %d\n", prev_stage);
} }
stage++;
sync_global_to_guest(vm, stage);
return ret_vm;
} }
static void test_run(void) static void test_run(void)
...@@ -289,7 +288,7 @@ static void test_run(void) ...@@ -289,7 +288,7 @@ static void test_run(void)
switch (get_ucall(vm, 0, &uc)) { switch (get_ucall(vm, 0, &uc)) {
case UCALL_SYNC: case UCALL_SYNC:
vm = test_guest_stage(vm); test_guest_stage(&vm);
break; break;
case UCALL_DONE: case UCALL_DONE:
guest_done = true; guest_done = true;
......
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