1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2020, Red Hat, Inc.
7 * Nested SVM testing: VMCALL
10 #include "test_util.h"
12 #include "processor.h"
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
);
40 int main(int argc
, char *argv
[])
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
);
52 volatile struct kvm_run
*run
= vcpu_state(vm
, VCPU_ID
);
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",
59 exit_reason_str(run
->exit_reason
));
61 switch (get_ucall(vm
, VCPU_ID
, &uc
)) {
63 TEST_FAIL("%s", (const char *)uc
.args
[0]);
70 TEST_FAIL("Unknown ucall 0x%lx.", uc
.cmd
);