xref: /illumos-gate/usr/src/test/bhyve-tests/tests/kdev/vlapic_msr_access.c (revision dd72704bd9e794056c558153663c739e2012d721)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2022 Oxide Computer Company
14  */
15 
16 #include <stdio.h>
17 #include <unistd.h>
18 #include <stdlib.h>
19 #include <strings.h>
20 #include <libgen.h>
21 #include <assert.h>
22 
23 #include <sys/types.h>
24 #include <sys/sysmacros.h>
25 #include <sys/debug.h>
26 #include <sys/vmm.h>
27 #include <sys/vmm_dev.h>
28 #include <vmmapi.h>
29 
30 #include "in_guest.h"
31 #include "test_defs.h"
32 
33 int
34 main(int argc, char *argv[])
35 {
36 	const char *test_suite_name = basename(argv[0]);
37 	struct vmctx *ctx = NULL;
38 	int err;
39 
40 	ctx = test_initialize(test_suite_name);
41 
42 	err = test_setup_vcpu(ctx, 0, MEM_LOC_PAYLOAD, MEM_LOC_STACK);
43 	if (err != 0) {
44 		test_fail_errno(err, "Could not initialize vcpu0");
45 	}
46 
47 	err = vm_set_x2apic_state(ctx, 0, X2APIC_ENABLED);
48 	if (err != 0) {
49 		test_fail_errno(err, "Could not enable x2apic on vcpu0");
50 	}
51 
52 	struct vm_entry ventry = { 0 };
53 	struct vm_exit vexit = { 0 };
54 
55 	do {
56 		const enum vm_exit_kind kind =
57 		    test_run_vcpu(ctx, 0, &ventry, &vexit);
58 		switch (kind) {
59 		case VEK_REENTR:
60 			break;
61 		case VEK_TEST_PASS:
62 			test_pass();
63 			break;
64 		case VEK_TEST_FAIL:
65 			test_fail_msg("payload signaled failure");
66 			break;
67 		case VEK_UNHANDLED:
68 		default:
69 			test_fail_vmexit(&vexit);
70 			break;
71 		}
72 	} while (true);
73 }
74