Commit 8df98ae0 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: assert on exit reason in CR4/cpuid sync test

...so that the test doesn't end up in an infinite loop if it fails for
whatever reason, e.g. SHUTDOWN due to gcc inserting stack canary code
into ucall() and attempting to derefence a null segment.

Fixes: ca359066 ("kvm: selftests: add cr4_cpuid_sync_test")
Cc: Wei Huang <wei@redhat.com>
Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 45def77e
...@@ -87,22 +87,25 @@ int main(int argc, char *argv[]) ...@@ -87,22 +87,25 @@ int main(int argc, char *argv[])
while (1) { while (1) {
rc = _vcpu_run(vm, VCPU_ID); rc = _vcpu_run(vm, VCPU_ID);
if (run->exit_reason == KVM_EXIT_IO) { TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
switch (get_ucall(vm, VCPU_ID, &uc)) { "Unexpected exit reason: %u (%s),\n",
case UCALL_SYNC: run->exit_reason,
/* emulate hypervisor clearing CR4.OSXSAVE */ exit_reason_str(run->exit_reason));
vcpu_sregs_get(vm, VCPU_ID, &sregs);
sregs.cr4 &= ~X86_CR4_OSXSAVE; switch (get_ucall(vm, VCPU_ID, &uc)) {
vcpu_sregs_set(vm, VCPU_ID, &sregs); case UCALL_SYNC:
break; /* emulate hypervisor clearing CR4.OSXSAVE */
case UCALL_ABORT: vcpu_sregs_get(vm, VCPU_ID, &sregs);
TEST_ASSERT(false, "Guest CR4 bit (OSXSAVE) unsynchronized with CPUID bit."); sregs.cr4 &= ~X86_CR4_OSXSAVE;
break; vcpu_sregs_set(vm, VCPU_ID, &sregs);
case UCALL_DONE: break;
goto done; case UCALL_ABORT:
default: TEST_ASSERT(false, "Guest CR4 bit (OSXSAVE) unsynchronized with CPUID bit.");
TEST_ASSERT(false, "Unknown ucall 0x%x.", uc.cmd); break;
} case UCALL_DONE:
goto done;
default:
TEST_ASSERT(false, "Unknown ucall 0x%x.", uc.cmd);
} }
} }
......
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