WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / kvm / x86_64 / svm_vmcall_test.c
blobbe2ca157485b67d610d7227a6d182c32b56c9e82
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * svm_vmcall_test
5 * Copyright (C) 2020, Red Hat, Inc.
7 * Nested SVM testing: VMCALL
8 */
10 #include "test_util.h"
11 #include "kvm_util.h"
12 #include "processor.h"
13 #include "svm_util.h"
15 #define VCPU_ID 5
17 static struct kvm_vm *vm;
19 static void l2_guest_code(struct svm_test_data *svm)
21 __asm__ __volatile__("vmcall");
24 static void l1_guest_code(struct svm_test_data *svm)
26 #define L2_GUEST_STACK_SIZE 64
27 unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE];
28 struct vmcb *vmcb = svm->vmcb;
30 /* Prepare for L2 execution. */
31 generic_svm_setup(svm, l2_guest_code,
32 &l2_guest_stack[L2_GUEST_STACK_SIZE]);
34 run_guest(vmcb, svm->vmcb_gpa);
36 GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
37 GUEST_DONE();
40 int main(int argc, char *argv[])
42 vm_vaddr_t svm_gva;
44 nested_svm_check_supported();
46 vm = vm_create_default(VCPU_ID, 0, (void *) l1_guest_code);
48 vcpu_alloc_svm(vm, &svm_gva);
49 vcpu_args_set(vm, VCPU_ID, 1, svm_gva);
51 for (;;) {
52 volatile struct kvm_run *run = vcpu_state(vm, VCPU_ID);
53 struct ucall uc;
55 vcpu_run(vm, VCPU_ID);
56 TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
57 "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
58 run->exit_reason,
59 exit_reason_str(run->exit_reason));
61 switch (get_ucall(vm, VCPU_ID, &uc)) {
62 case UCALL_ABORT:
63 TEST_FAIL("%s", (const char *)uc.args[0]);
64 /* NOT REACHED */
65 case UCALL_SYNC:
66 break;
67 case UCALL_DONE:
68 goto done;
69 default:
70 TEST_FAIL("Unknown ucall 0x%lx.", uc.cmd);
73 done:
74 kvm_vm_free(vm);
75 return 0;