Commit 32d1b3ab authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by Paolo Bonzini

KVM: selftests: evmcs_test: Check that VMLAUNCH with bogus EVMPTR is causing #UD

'run->exit_reason == KVM_EXIT_SHUTDOWN' check is not ideal as we may be
getting some unexpected exception. Directly check for #UD instead.
Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Message-Id: <20210505151823.1341678-2-vkuznets@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent f5c7e842
...@@ -19,6 +19,14 @@ ...@@ -19,6 +19,14 @@
#define VCPU_ID 5 #define VCPU_ID 5
static int ud_count;
static void guest_ud_handler(struct ex_regs *regs)
{
ud_count++;
regs->rip += 3; /* VMLAUNCH */
}
void l2_guest_code(void) void l2_guest_code(void)
{ {
GUEST_SYNC(7); GUEST_SYNC(7);
...@@ -71,11 +79,11 @@ void guest_code(struct vmx_pages *vmx_pages) ...@@ -71,11 +79,11 @@ void guest_code(struct vmx_pages *vmx_pages)
if (vmx_pages) if (vmx_pages)
l1_guest_code(vmx_pages); l1_guest_code(vmx_pages);
GUEST_DONE();
/* Try enlightened vmptrld with an incorrect GPA */ /* Try enlightened vmptrld with an incorrect GPA */
evmcs_vmptrld(0xdeadbeef, vmx_pages->enlightened_vmcs); evmcs_vmptrld(0xdeadbeef, vmx_pages->enlightened_vmcs);
GUEST_ASSERT(vmlaunch()); GUEST_ASSERT(vmlaunch());
GUEST_ASSERT(ud_count == 1);
GUEST_DONE();
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
...@@ -109,6 +117,10 @@ int main(int argc, char *argv[]) ...@@ -109,6 +117,10 @@ int main(int argc, char *argv[])
vcpu_alloc_vmx(vm, &vmx_pages_gva); vcpu_alloc_vmx(vm, &vmx_pages_gva);
vcpu_args_set(vm, VCPU_ID, 1, vmx_pages_gva); vcpu_args_set(vm, VCPU_ID, 1, vmx_pages_gva);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vm, VCPU_ID);
vm_handle_exception(vm, UD_VECTOR, guest_ud_handler);
for (stage = 1;; stage++) { for (stage = 1;; stage++) {
_vcpu_run(vm, VCPU_ID); _vcpu_run(vm, VCPU_ID);
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
...@@ -124,7 +136,7 @@ int main(int argc, char *argv[]) ...@@ -124,7 +136,7 @@ int main(int argc, char *argv[])
case UCALL_SYNC: case UCALL_SYNC:
break; break;
case UCALL_DONE: case UCALL_DONE:
goto part1_done; goto done;
default: default:
TEST_FAIL("Unknown ucall %lu", uc.cmd); TEST_FAIL("Unknown ucall %lu", uc.cmd);
} }
...@@ -156,10 +168,6 @@ int main(int argc, char *argv[]) ...@@ -156,10 +168,6 @@ int main(int argc, char *argv[])
(ulong) regs2.rdi, (ulong) regs2.rsi); (ulong) regs2.rdi, (ulong) regs2.rsi);
} }
part1_done: done:
_vcpu_run(vm, VCPU_ID);
TEST_ASSERT(run->exit_reason == KVM_EXIT_SHUTDOWN,
"Unexpected successful VMEnter with invalid eVMCS pointer!");
kvm_vm_free(vm); kvm_vm_free(vm);
} }
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