xref: /freebsd/usr.sbin/bhyvectl/bhyvectl.c (revision 0572ccaa4543b0abef8ef81e384c1d04de9f3da1)
1 /*-
2  * Copyright (c) 2011 NetApp, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/sysctl.h>
35 #include <sys/errno.h>
36 #include <sys/mman.h>
37 
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <unistd.h>
41 #include <libgen.h>
42 #include <libutil.h>
43 #include <fcntl.h>
44 #include <string.h>
45 #include <getopt.h>
46 #include <assert.h>
47 
48 #include <machine/vmm.h>
49 #include <vmmapi.h>
50 
51 #include "intel/vmcs.h"
52 
53 #define	MB	(1UL << 20)
54 #define	GB	(1UL << 30)
55 
56 #define	REQ_ARG		required_argument
57 #define	NO_ARG		no_argument
58 #define	OPT_ARG		optional_argument
59 
60 static const char *progname;
61 
62 static void
63 usage(void)
64 {
65 
66 	(void)fprintf(stderr,
67 	"Usage: %s --vm=<vmname>\n"
68 	"       [--cpu=<vcpu_number>]\n"
69 	"       [--create]\n"
70 	"       [--destroy]\n"
71 	"       [--get-all]\n"
72 	"       [--get-stats]\n"
73 	"       [--set-desc-ds]\n"
74 	"       [--get-desc-ds]\n"
75 	"       [--set-desc-es]\n"
76 	"       [--get-desc-es]\n"
77 	"       [--set-desc-gs]\n"
78 	"       [--get-desc-gs]\n"
79 	"       [--set-desc-fs]\n"
80 	"       [--get-desc-fs]\n"
81 	"       [--set-desc-cs]\n"
82 	"       [--get-desc-cs]\n"
83 	"       [--set-desc-ss]\n"
84 	"       [--get-desc-ss]\n"
85 	"       [--set-desc-tr]\n"
86 	"       [--get-desc-tr]\n"
87 	"       [--set-desc-ldtr]\n"
88 	"       [--get-desc-ldtr]\n"
89 	"       [--set-desc-gdtr]\n"
90 	"       [--get-desc-gdtr]\n"
91 	"       [--set-desc-idtr]\n"
92 	"       [--get-desc-idtr]\n"
93 	"       [--run]\n"
94 	"       [--capname=<capname>]\n"
95 	"       [--getcap]\n"
96 	"       [--setcap=<0|1>]\n"
97 	"       [--desc-base=<BASE>]\n"
98 	"       [--desc-limit=<LIMIT>]\n"
99 	"       [--desc-access=<ACCESS>]\n"
100 	"       [--set-cr0=<CR0>]\n"
101 	"       [--get-cr0]\n"
102 	"       [--set-cr3=<CR3>]\n"
103 	"       [--get-cr3]\n"
104 	"       [--set-cr4=<CR4>]\n"
105 	"       [--get-cr4]\n"
106 	"       [--set-dr7=<DR7>]\n"
107 	"       [--get-dr7]\n"
108 	"       [--set-rsp=<RSP>]\n"
109 	"       [--get-rsp]\n"
110 	"       [--set-rip=<RIP>]\n"
111 	"       [--get-rip]\n"
112 	"       [--get-rax]\n"
113 	"       [--set-rax=<RAX>]\n"
114 	"       [--get-rbx]\n"
115 	"       [--get-rcx]\n"
116 	"       [--get-rdx]\n"
117 	"       [--get-rsi]\n"
118 	"       [--get-rdi]\n"
119 	"       [--get-rbp]\n"
120 	"       [--get-r8]\n"
121 	"       [--get-r9]\n"
122 	"       [--get-r10]\n"
123 	"       [--get-r11]\n"
124 	"       [--get-r12]\n"
125 	"       [--get-r13]\n"
126 	"       [--get-r14]\n"
127 	"       [--get-r15]\n"
128 	"       [--set-rflags=<RFLAGS>]\n"
129 	"       [--get-rflags]\n"
130 	"       [--set-cs]\n"
131 	"       [--get-cs]\n"
132 	"       [--set-ds]\n"
133 	"       [--get-ds]\n"
134 	"       [--set-es]\n"
135 	"       [--get-es]\n"
136 	"       [--set-fs]\n"
137 	"       [--get-fs]\n"
138 	"       [--set-gs]\n"
139 	"       [--get-gs]\n"
140 	"       [--set-ss]\n"
141 	"       [--get-ss]\n"
142 	"       [--get-tr]\n"
143 	"       [--get-ldtr]\n"
144 	"       [--get-vmcs-pinbased-ctls]\n"
145 	"       [--get-vmcs-procbased-ctls]\n"
146 	"       [--get-vmcs-procbased-ctls2]\n"
147 	"       [--get-vmcs-entry-interruption-info]\n"
148 	"       [--set-vmcs-entry-interruption-info=<info>]\n"
149 	"       [--get-vmcs-eptp]\n"
150 	"       [--get-vmcs-guest-physical-address\n"
151 	"       [--get-vmcs-guest-linear-address\n"
152 	"       [--set-vmcs-exception-bitmap]\n"
153 	"       [--get-vmcs-exception-bitmap]\n"
154 	"       [--get-vmcs-io-bitmap-address]\n"
155 	"       [--get-vmcs-tsc-offset]\n"
156 	"       [--get-vmcs-guest-pat]\n"
157 	"       [--get-vmcs-host-pat]\n"
158 	"       [--get-vmcs-host-cr0]\n"
159 	"       [--get-vmcs-host-cr3]\n"
160 	"       [--get-vmcs-host-cr4]\n"
161 	"       [--get-vmcs-host-rip]\n"
162 	"       [--get-vmcs-host-rsp]\n"
163 	"       [--get-vmcs-cr0-mask]\n"
164 	"       [--get-vmcs-cr0-shadow]\n"
165 	"       [--get-vmcs-cr4-mask]\n"
166 	"       [--get-vmcs-cr4-shadow]\n"
167 	"       [--get-vmcs-cr3-targets]\n"
168 	"       [--get-vmcs-apic-access-address]\n"
169 	"       [--get-vmcs-virtual-apic-address]\n"
170 	"       [--get-vmcs-tpr-threshold]\n"
171 	"       [--get-vmcs-msr-bitmap]\n"
172 	"       [--get-vmcs-msr-bitmap-address]\n"
173 	"       [--get-vmcs-vpid]\n"
174 	"       [--get-vmcs-ple-gap]\n"
175 	"       [--get-vmcs-ple-window]\n"
176 	"       [--get-vmcs-instruction-error]\n"
177 	"       [--get-vmcs-exit-ctls]\n"
178 	"       [--get-vmcs-entry-ctls]\n"
179 	"       [--get-vmcs-guest-sysenter]\n"
180 	"       [--get-vmcs-link]\n"
181 	"       [--get-vmcs-exit-reason]\n"
182 	"       [--get-vmcs-exit-qualification]\n"
183 	"       [--get-vmcs-exit-interruption-info]\n"
184 	"       [--get-vmcs-exit-interruption-error]\n"
185 	"       [--get-vmcs-interruptibility]\n"
186 	"       [--set-x2apic-state=<state>]\n"
187 	"       [--get-x2apic-state]\n"
188 	"       [--unassign-pptdev=<bus/slot/func>]\n"
189 	"       [--set-mem=<memory in units of MB>]\n"
190 	"       [--get-lowmem]\n"
191 	"       [--get-highmem]\n"
192 	"       [--get-gpa-pmap]\n"
193 	"       [--assert-lapic-lvt=<pin>]\n"
194 	"       [--inject-nmi]\n"
195 	"       [--force-reset]\n"
196 	"       [--force-poweroff]\n",
197 	progname);
198 	exit(1);
199 }
200 
201 static int get_stats, getcap, setcap, capval, get_gpa_pmap;
202 static int inject_nmi, assert_lapic_lvt;
203 static int force_reset, force_poweroff;
204 static const char *capname;
205 static int create, destroy, get_lowmem, get_highmem;
206 static uint64_t memsize;
207 static int set_cr0, get_cr0, set_cr3, get_cr3, set_cr4, get_cr4;
208 static int set_efer, get_efer;
209 static int set_dr7, get_dr7;
210 static int set_rsp, get_rsp, set_rip, get_rip, set_rflags, get_rflags;
211 static int set_rax, get_rax;
212 static int get_rbx, get_rcx, get_rdx, get_rsi, get_rdi, get_rbp;
213 static int get_r8, get_r9, get_r10, get_r11, get_r12, get_r13, get_r14, get_r15;
214 static int set_desc_ds, get_desc_ds;
215 static int set_desc_es, get_desc_es;
216 static int set_desc_fs, get_desc_fs;
217 static int set_desc_gs, get_desc_gs;
218 static int set_desc_cs, get_desc_cs;
219 static int set_desc_ss, get_desc_ss;
220 static int set_desc_gdtr, get_desc_gdtr;
221 static int set_desc_idtr, get_desc_idtr;
222 static int set_desc_tr, get_desc_tr;
223 static int set_desc_ldtr, get_desc_ldtr;
224 static int set_cs, set_ds, set_es, set_fs, set_gs, set_ss, set_tr, set_ldtr;
225 static int get_cs, get_ds, get_es, get_fs, get_gs, get_ss, get_tr, get_ldtr;
226 static int set_x2apic_state, get_x2apic_state;
227 enum x2apic_state x2apic_state;
228 static int unassign_pptdev, bus, slot, func;
229 static int run;
230 
231 /*
232  * VMCS-specific fields
233  */
234 static int get_pinbased_ctls, get_procbased_ctls, get_procbased_ctls2;
235 static int get_eptp, get_io_bitmap, get_tsc_offset;
236 static int get_vmcs_entry_interruption_info, set_vmcs_entry_interruption_info;
237 static int get_vmcs_interruptibility;
238 uint32_t vmcs_entry_interruption_info;
239 static int get_vmcs_gpa, get_vmcs_gla;
240 static int get_exception_bitmap, set_exception_bitmap, exception_bitmap;
241 static int get_cr0_mask, get_cr0_shadow;
242 static int get_cr4_mask, get_cr4_shadow;
243 static int get_cr3_targets;
244 static int get_apic_access_addr, get_virtual_apic_addr, get_tpr_threshold;
245 static int get_msr_bitmap, get_msr_bitmap_address;
246 static int get_vpid, get_ple_gap, get_ple_window;
247 static int get_inst_err, get_exit_ctls, get_entry_ctls;
248 static int get_host_cr0, get_host_cr3, get_host_cr4;
249 static int get_host_rip, get_host_rsp;
250 static int get_guest_pat, get_host_pat;
251 static int get_guest_sysenter, get_vmcs_link;
252 static int get_vmcs_exit_reason, get_vmcs_exit_qualification;
253 static int get_vmcs_exit_interruption_info, get_vmcs_exit_interruption_error;
254 
255 static uint64_t desc_base;
256 static uint32_t desc_limit, desc_access;
257 
258 static int get_all;
259 
260 static void
261 dump_vm_run_exitcode(struct vm_exit *vmexit, int vcpu)
262 {
263 	printf("vm exit[%d]\n", vcpu);
264 	printf("\trip\t\t0x%016lx\n", vmexit->rip);
265 	printf("\tinst_length\t%d\n", vmexit->inst_length);
266 	switch (vmexit->exitcode) {
267 	case VM_EXITCODE_INOUT:
268 		printf("\treason\t\tINOUT\n");
269 		printf("\tdirection\t%s\n", vmexit->u.inout.in ? "IN" : "OUT");
270 		printf("\tbytes\t\t%d\n", vmexit->u.inout.bytes);
271 		printf("\tflags\t\t%s%s\n",
272 			vmexit->u.inout.string ? "STRING " : "",
273 			vmexit->u.inout.rep ? "REP " : "");
274 		printf("\tport\t\t0x%04x\n", vmexit->u.inout.port);
275 		printf("\teax\t\t0x%08x\n", vmexit->u.inout.eax);
276 		break;
277 	case VM_EXITCODE_VMX:
278 		printf("\treason\t\tVMX\n");
279 		printf("\tstatus\t\t%d\n", vmexit->u.vmx.status);
280 		printf("\texit_reason\t0x%08x (%u)\n",
281 		    vmexit->u.vmx.exit_reason, vmexit->u.vmx.exit_reason);
282 		printf("\tqualification\t0x%016lx\n",
283 			vmexit->u.vmx.exit_qualification);
284 		printf("\tinst_type\t\t%d\n", vmexit->u.vmx.inst_type);
285 		printf("\tinst_error\t\t%d\n", vmexit->u.vmx.inst_error);
286 		break;
287 	default:
288 		printf("*** unknown vm run exitcode %d\n", vmexit->exitcode);
289 		break;
290 	}
291 }
292 
293 static int
294 dump_vmcs_msr_bitmap(int vcpu, u_long addr)
295 {
296 	int error, fd, byte, bit, readable, writeable;
297 	u_int msr;
298 	const char *bitmap;
299 
300 	error = -1;
301 	bitmap = MAP_FAILED;
302 
303 	fd = open("/dev/mem", O_RDONLY, 0);
304 	if (fd < 0)
305 		goto done;
306 
307 	bitmap = mmap(NULL, PAGE_SIZE, PROT_READ, 0, fd, addr);
308 	if (bitmap == MAP_FAILED)
309 		goto done;
310 
311 	for (msr = 0; msr < 0x2000; msr++) {
312 		byte = msr / 8;
313 		bit = msr & 0x7;
314 
315 		/* Look at MSRs in the range 0x00000000 to 0x00001FFF */
316 		readable = (bitmap[byte] & (1 << bit)) ? 0 : 1;
317 		writeable = (bitmap[2048 + byte] & (1 << bit)) ? 0 : 1;
318 		if (readable || writeable) {
319 			printf("msr 0x%08x[%d]\t\t%c%c\n", msr, vcpu,
320 				readable ? 'R' : '-',
321 				writeable ? 'W' : '-');
322 		}
323 
324 		/* Look at MSRs in the range 0xC0000000 to 0xC0001FFF */
325 		byte += 1024;
326 		readable = (bitmap[byte] & (1 << bit)) ? 0 : 1;
327 		writeable = (bitmap[2048 + byte] & (1 << bit)) ? 0 : 1;
328 		if (readable || writeable) {
329 			printf("msr 0x%08x[%d]\t\t%c%c\n",
330 				0xc0000000 + msr, vcpu,
331 				readable ? 'R' : '-',
332 				writeable ? 'W' : '-');
333 		}
334 	}
335 
336 	error = 0;
337 done:
338 	if (bitmap != MAP_FAILED)
339 		munmap((void *)bitmap, PAGE_SIZE);
340 	if (fd >= 0)
341 		close(fd);
342 	return (error);
343 }
344 
345 static int
346 vm_get_vmcs_field(struct vmctx *ctx, int vcpu, int field, uint64_t *ret_val)
347 {
348 
349 	return (vm_get_register(ctx, vcpu, VMCS_IDENT(field), ret_val));
350 }
351 
352 static int
353 vm_set_vmcs_field(struct vmctx *ctx, int vcpu, int field, uint64_t val)
354 {
355 
356 	return (vm_set_register(ctx, vcpu, VMCS_IDENT(field), val));
357 }
358 
359 enum {
360 	VMNAME = 1000,	/* avoid collision with return values from getopt */
361 	VCPU,
362 	SET_MEM,
363 	SET_EFER,
364 	SET_CR0,
365 	SET_CR3,
366 	SET_CR4,
367 	SET_DR7,
368 	SET_RSP,
369 	SET_RIP,
370 	SET_RAX,
371 	SET_RFLAGS,
372 	DESC_BASE,
373 	DESC_LIMIT,
374 	DESC_ACCESS,
375 	SET_CS,
376 	SET_DS,
377 	SET_ES,
378 	SET_FS,
379 	SET_GS,
380 	SET_SS,
381 	SET_TR,
382 	SET_LDTR,
383 	SET_X2APIC_STATE,
384 	SET_VMCS_EXCEPTION_BITMAP,
385 	SET_VMCS_ENTRY_INTERRUPTION_INFO,
386 	SET_CAP,
387 	CAPNAME,
388 	UNASSIGN_PPTDEV,
389 	GET_GPA_PMAP,
390 	ASSERT_LAPIC_LVT,
391 };
392 
393 int
394 main(int argc, char *argv[])
395 {
396 	char *vmname;
397 	int error, ch, vcpu, ptenum;
398 	vm_paddr_t gpa, gpa_pmap;
399 	size_t len;
400 	struct vm_exit vmexit;
401 	uint64_t ctl, eptp, bm, addr, u64, pteval[4], *pte;
402 	struct vmctx *ctx;
403 	int wired;
404 
405 	uint64_t cr0, cr3, cr4, dr7, rsp, rip, rflags, efer, pat;
406 	uint64_t rax, rbx, rcx, rdx, rsi, rdi, rbp;
407 	uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
408 	uint64_t cs, ds, es, fs, gs, ss, tr, ldtr;
409 
410 	struct option opts[] = {
411 		{ "vm",		REQ_ARG,	0,	VMNAME },
412 		{ "cpu",	REQ_ARG,	0,	VCPU },
413 		{ "set-mem",	REQ_ARG,	0,	SET_MEM },
414 		{ "set-efer",	REQ_ARG,	0,	SET_EFER },
415 		{ "set-cr0",	REQ_ARG,	0,	SET_CR0 },
416 		{ "set-cr3",	REQ_ARG,	0,	SET_CR3 },
417 		{ "set-cr4",	REQ_ARG,	0,	SET_CR4 },
418 		{ "set-dr7",	REQ_ARG,	0,	SET_DR7 },
419 		{ "set-rsp",	REQ_ARG,	0,	SET_RSP },
420 		{ "set-rip",	REQ_ARG,	0,	SET_RIP },
421 		{ "set-rax",	REQ_ARG,	0,	SET_RAX },
422 		{ "set-rflags",	REQ_ARG,	0,	SET_RFLAGS },
423 		{ "desc-base",	REQ_ARG,	0,	DESC_BASE },
424 		{ "desc-limit",	REQ_ARG,	0,	DESC_LIMIT },
425 		{ "desc-access",REQ_ARG,	0,	DESC_ACCESS },
426 		{ "set-cs",	REQ_ARG,	0,	SET_CS },
427 		{ "set-ds",	REQ_ARG,	0,	SET_DS },
428 		{ "set-es",	REQ_ARG,	0,	SET_ES },
429 		{ "set-fs",	REQ_ARG,	0,	SET_FS },
430 		{ "set-gs",	REQ_ARG,	0,	SET_GS },
431 		{ "set-ss",	REQ_ARG,	0,	SET_SS },
432 		{ "set-tr",	REQ_ARG,	0,	SET_TR },
433 		{ "set-ldtr",	REQ_ARG,	0,	SET_LDTR },
434 		{ "set-x2apic-state",REQ_ARG,	0,	SET_X2APIC_STATE },
435 		{ "set-vmcs-exception-bitmap",
436 				REQ_ARG,	0, SET_VMCS_EXCEPTION_BITMAP },
437 		{ "set-vmcs-entry-interruption-info",
438 				REQ_ARG, 0, SET_VMCS_ENTRY_INTERRUPTION_INFO },
439 		{ "capname",	REQ_ARG,	0,	CAPNAME },
440 		{ "unassign-pptdev", REQ_ARG,	0,	UNASSIGN_PPTDEV },
441 		{ "setcap",	REQ_ARG,	0,	SET_CAP },
442 		{ "get-gpa-pmap", REQ_ARG,	0,	GET_GPA_PMAP },
443 		{ "assert-lapic-lvt", REQ_ARG,	0,	ASSERT_LAPIC_LVT },
444 		{ "getcap",	NO_ARG,		&getcap,	1 },
445 		{ "get-stats",	NO_ARG,		&get_stats,	1 },
446 		{ "get-desc-ds",NO_ARG,		&get_desc_ds,	1 },
447 		{ "set-desc-ds",NO_ARG,		&set_desc_ds,	1 },
448 		{ "get-desc-es",NO_ARG,		&get_desc_es,	1 },
449 		{ "set-desc-es",NO_ARG,		&set_desc_es,	1 },
450 		{ "get-desc-ss",NO_ARG,		&get_desc_ss,	1 },
451 		{ "set-desc-ss",NO_ARG,		&set_desc_ss,	1 },
452 		{ "get-desc-cs",NO_ARG,		&get_desc_cs,	1 },
453 		{ "set-desc-cs",NO_ARG,		&set_desc_cs,	1 },
454 		{ "get-desc-fs",NO_ARG,		&get_desc_fs,	1 },
455 		{ "set-desc-fs",NO_ARG,		&set_desc_fs,	1 },
456 		{ "get-desc-gs",NO_ARG,		&get_desc_gs,	1 },
457 		{ "set-desc-gs",NO_ARG,		&set_desc_gs,	1 },
458 		{ "get-desc-tr",NO_ARG,		&get_desc_tr,	1 },
459 		{ "set-desc-tr",NO_ARG,		&set_desc_tr,	1 },
460 		{ "set-desc-ldtr", NO_ARG,	&set_desc_ldtr,	1 },
461 		{ "get-desc-ldtr", NO_ARG,	&get_desc_ldtr,	1 },
462 		{ "set-desc-gdtr", NO_ARG,	&set_desc_gdtr, 1 },
463 		{ "get-desc-gdtr", NO_ARG,	&get_desc_gdtr, 1 },
464 		{ "set-desc-idtr", NO_ARG,	&set_desc_idtr, 1 },
465 		{ "get-desc-idtr", NO_ARG,	&get_desc_idtr, 1 },
466 		{ "get-lowmem", NO_ARG,		&get_lowmem,	1 },
467 		{ "get-highmem",NO_ARG,		&get_highmem,	1 },
468 		{ "get-efer",	NO_ARG,		&get_efer,	1 },
469 		{ "get-cr0",	NO_ARG,		&get_cr0,	1 },
470 		{ "get-cr3",	NO_ARG,		&get_cr3,	1 },
471 		{ "get-cr4",	NO_ARG,		&get_cr4,	1 },
472 		{ "get-dr7",	NO_ARG,		&get_dr7,	1 },
473 		{ "get-rsp",	NO_ARG,		&get_rsp,	1 },
474 		{ "get-rip",	NO_ARG,		&get_rip,	1 },
475 		{ "get-rax",	NO_ARG,		&get_rax,	1 },
476 		{ "get-rbx",	NO_ARG,		&get_rbx,	1 },
477 		{ "get-rcx",	NO_ARG,		&get_rcx,	1 },
478 		{ "get-rdx",	NO_ARG,		&get_rdx,	1 },
479 		{ "get-rsi",	NO_ARG,		&get_rsi,	1 },
480 		{ "get-rdi",	NO_ARG,		&get_rdi,	1 },
481 		{ "get-rbp",	NO_ARG,		&get_rbp,	1 },
482 		{ "get-r8",	NO_ARG,		&get_r8,	1 },
483 		{ "get-r9",	NO_ARG,		&get_r9,	1 },
484 		{ "get-r10",	NO_ARG,		&get_r10,	1 },
485 		{ "get-r11",	NO_ARG,		&get_r11,	1 },
486 		{ "get-r12",	NO_ARG,		&get_r12,	1 },
487 		{ "get-r13",	NO_ARG,		&get_r13,	1 },
488 		{ "get-r14",	NO_ARG,		&get_r14,	1 },
489 		{ "get-r15",	NO_ARG,		&get_r15,	1 },
490 		{ "get-rflags",	NO_ARG,		&get_rflags,	1 },
491 		{ "get-cs",	NO_ARG,		&get_cs,	1 },
492 		{ "get-ds",	NO_ARG,		&get_ds,	1 },
493 		{ "get-es",	NO_ARG,		&get_es,	1 },
494 		{ "get-fs",	NO_ARG,		&get_fs,	1 },
495 		{ "get-gs",	NO_ARG,		&get_gs,	1 },
496 		{ "get-ss",	NO_ARG,		&get_ss,	1 },
497 		{ "get-tr",	NO_ARG,		&get_tr,	1 },
498 		{ "get-ldtr",	NO_ARG,		&get_ldtr,	1 },
499 		{ "get-vmcs-pinbased-ctls",
500 				NO_ARG,		&get_pinbased_ctls, 1 },
501 		{ "get-vmcs-procbased-ctls",
502 				NO_ARG,		&get_procbased_ctls, 1 },
503 		{ "get-vmcs-procbased-ctls2",
504 				NO_ARG,		&get_procbased_ctls2, 1 },
505 		{ "get-vmcs-guest-linear-address",
506 				NO_ARG,		&get_vmcs_gla,	1 },
507 		{ "get-vmcs-guest-physical-address",
508 				NO_ARG,		&get_vmcs_gpa,	1 },
509 		{ "get-vmcs-entry-interruption-info",
510 				NO_ARG, &get_vmcs_entry_interruption_info, 1},
511 		{ "get-vmcs-eptp", NO_ARG,	&get_eptp,	1 },
512 		{ "get-vmcs-exception-bitmap",
513 				NO_ARG,		&get_exception_bitmap, 1 },
514 		{ "get-vmcs-io-bitmap-address",
515 				NO_ARG,		&get_io_bitmap,	1 },
516 		{ "get-vmcs-tsc-offset", NO_ARG,&get_tsc_offset, 1 },
517 		{ "get-vmcs-cr0-mask", NO_ARG,	&get_cr0_mask,	1 },
518 		{ "get-vmcs-cr0-shadow", NO_ARG,&get_cr0_shadow, 1 },
519 		{ "get-vmcs-cr4-mask", NO_ARG,	&get_cr4_mask,	1 },
520 		{ "get-vmcs-cr4-shadow", NO_ARG,&get_cr4_shadow, 1 },
521 		{ "get-vmcs-cr3-targets", NO_ARG, &get_cr3_targets, 1},
522 		{ "get-vmcs-apic-access-address",
523 				NO_ARG,		&get_apic_access_addr, 1},
524 		{ "get-vmcs-virtual-apic-address",
525 				NO_ARG,		&get_virtual_apic_addr, 1},
526 		{ "get-vmcs-tpr-threshold",
527 				NO_ARG,		&get_tpr_threshold, 1 },
528 		{ "get-vmcs-msr-bitmap",
529 				NO_ARG,		&get_msr_bitmap, 1 },
530 		{ "get-vmcs-msr-bitmap-address",
531 				NO_ARG,		&get_msr_bitmap_address, 1 },
532 		{ "get-vmcs-vpid", NO_ARG,	&get_vpid,	1 },
533 		{ "get-vmcs-ple-gap", NO_ARG,	&get_ple_gap,	1 },
534 		{ "get-vmcs-ple-window", NO_ARG,&get_ple_window,1 },
535 		{ "get-vmcs-instruction-error",
536 				NO_ARG,		&get_inst_err,	1 },
537 		{ "get-vmcs-exit-ctls", NO_ARG,	&get_exit_ctls,	1 },
538 		{ "get-vmcs-entry-ctls",
539 					NO_ARG,	&get_entry_ctls, 1 },
540 		{ "get-vmcs-guest-pat",	NO_ARG,	&get_guest_pat,	1 },
541 		{ "get-vmcs-host-pat",	NO_ARG,	&get_host_pat,	1 },
542 		{ "get-vmcs-host-cr0",
543 				NO_ARG,		&get_host_cr0,	1 },
544 		{ "get-vmcs-host-cr3",
545 				NO_ARG,		&get_host_cr3,	1 },
546 		{ "get-vmcs-host-cr4",
547 				NO_ARG,		&get_host_cr4,	1 },
548 		{ "get-vmcs-host-rip",
549 				NO_ARG,		&get_host_rip,	1 },
550 		{ "get-vmcs-host-rsp",
551 				NO_ARG,		&get_host_rsp,	1 },
552 		{ "get-vmcs-guest-sysenter",
553 				NO_ARG,		&get_guest_sysenter, 1 },
554 		{ "get-vmcs-link", NO_ARG,	&get_vmcs_link, 1 },
555 		{ "get-vmcs-exit-reason",
556 				NO_ARG,		&get_vmcs_exit_reason, 1 },
557 		{ "get-vmcs-exit-qualification",
558 			NO_ARG,		&get_vmcs_exit_qualification, 1 },
559 		{ "get-vmcs-exit-interruption-info",
560 				NO_ARG,	&get_vmcs_exit_interruption_info, 1},
561 		{ "get-vmcs-exit-interruption-error",
562 				NO_ARG,	&get_vmcs_exit_interruption_error, 1},
563 		{ "get-vmcs-interruptibility",
564 				NO_ARG, &get_vmcs_interruptibility, 1 },
565 		{ "get-x2apic-state",NO_ARG,	&get_x2apic_state, 1 },
566 		{ "get-all",	NO_ARG,		&get_all,	1 },
567 		{ "run",	NO_ARG,		&run,		1 },
568 		{ "create",	NO_ARG,		&create,	1 },
569 		{ "destroy",	NO_ARG,		&destroy,	1 },
570 		{ "inject-nmi",	NO_ARG,		&inject_nmi,	1 },
571 		{ "force-reset",	NO_ARG,	&force_reset,	1 },
572 		{ "force-poweroff", NO_ARG,	&force_poweroff, 1 },
573 		{ NULL,		0,		NULL,		0 }
574 	};
575 
576 	vcpu = 0;
577 	vmname = NULL;
578 	assert_lapic_lvt = -1;
579 	progname = basename(argv[0]);
580 
581 	while ((ch = getopt_long(argc, argv, "", opts, NULL)) != -1) {
582 		switch (ch) {
583 		case 0:
584 			break;
585 		case VMNAME:
586 			vmname = optarg;
587 			break;
588 		case VCPU:
589 			vcpu = atoi(optarg);
590 			break;
591 		case SET_MEM:
592 			memsize = atoi(optarg) * MB;
593 			memsize = roundup(memsize, 2 * MB);
594 			break;
595 		case SET_EFER:
596 			efer = strtoul(optarg, NULL, 0);
597 			set_efer = 1;
598 			break;
599 		case SET_CR0:
600 			cr0 = strtoul(optarg, NULL, 0);
601 			set_cr0 = 1;
602 			break;
603 		case SET_CR3:
604 			cr3 = strtoul(optarg, NULL, 0);
605 			set_cr3 = 1;
606 			break;
607 		case SET_CR4:
608 			cr4 = strtoul(optarg, NULL, 0);
609 			set_cr4 = 1;
610 			break;
611 		case SET_DR7:
612 			dr7 = strtoul(optarg, NULL, 0);
613 			set_dr7 = 1;
614 			break;
615 		case SET_RSP:
616 			rsp = strtoul(optarg, NULL, 0);
617 			set_rsp = 1;
618 			break;
619 		case SET_RIP:
620 			rip = strtoul(optarg, NULL, 0);
621 			set_rip = 1;
622 			break;
623 		case SET_RAX:
624 			rax = strtoul(optarg, NULL, 0);
625 			set_rax = 1;
626 			break;
627 		case SET_RFLAGS:
628 			rflags = strtoul(optarg, NULL, 0);
629 			set_rflags = 1;
630 			break;
631 		case DESC_BASE:
632 			desc_base = strtoul(optarg, NULL, 0);
633 			break;
634 		case DESC_LIMIT:
635 			desc_limit = strtoul(optarg, NULL, 0);
636 			break;
637 		case DESC_ACCESS:
638 			desc_access = strtoul(optarg, NULL, 0);
639 			break;
640 		case SET_CS:
641 			cs = strtoul(optarg, NULL, 0);
642 			set_cs = 1;
643 			break;
644 		case SET_DS:
645 			ds = strtoul(optarg, NULL, 0);
646 			set_ds = 1;
647 			break;
648 		case SET_ES:
649 			es = strtoul(optarg, NULL, 0);
650 			set_es = 1;
651 			break;
652 		case SET_FS:
653 			fs = strtoul(optarg, NULL, 0);
654 			set_fs = 1;
655 			break;
656 		case SET_GS:
657 			gs = strtoul(optarg, NULL, 0);
658 			set_gs = 1;
659 			break;
660 		case SET_SS:
661 			ss = strtoul(optarg, NULL, 0);
662 			set_ss = 1;
663 			break;
664 		case SET_TR:
665 			tr = strtoul(optarg, NULL, 0);
666 			set_tr = 1;
667 			break;
668 		case SET_LDTR:
669 			ldtr = strtoul(optarg, NULL, 0);
670 			set_ldtr = 1;
671 			break;
672 		case SET_X2APIC_STATE:
673 			x2apic_state = strtol(optarg, NULL, 0);
674 			set_x2apic_state = 1;
675 			break;
676 		case SET_VMCS_EXCEPTION_BITMAP:
677 			exception_bitmap = strtoul(optarg, NULL, 0);
678 			set_exception_bitmap = 1;
679 			break;
680 		case SET_VMCS_ENTRY_INTERRUPTION_INFO:
681 			vmcs_entry_interruption_info = strtoul(optarg, NULL, 0);
682 			set_vmcs_entry_interruption_info = 1;
683 			break;
684 		case SET_CAP:
685 			capval = strtoul(optarg, NULL, 0);
686 			setcap = 1;
687 			break;
688 		case GET_GPA_PMAP:
689 			gpa_pmap = strtoul(optarg, NULL, 0);
690 			get_gpa_pmap = 1;
691 			break;
692 		case CAPNAME:
693 			capname = optarg;
694 			break;
695 		case UNASSIGN_PPTDEV:
696 			unassign_pptdev = 1;
697 			if (sscanf(optarg, "%d/%d/%d", &bus, &slot, &func) != 3)
698 				usage();
699 			break;
700 		case ASSERT_LAPIC_LVT:
701 			assert_lapic_lvt = atoi(optarg);
702 			break;
703 		default:
704 			usage();
705 		}
706 	}
707 	argc -= optind;
708 	argv += optind;
709 
710 	if (vmname == NULL)
711 		usage();
712 
713 	error = 0;
714 
715 	if (!error && create)
716 		error = vm_create(vmname);
717 
718 	if (!error) {
719 		ctx = vm_open(vmname);
720 		if (ctx == NULL)
721 			error = -1;
722 	}
723 
724 	if (!error && memsize)
725 		error = vm_setup_memory(ctx, memsize, VM_MMAP_NONE);
726 
727 	if (!error && set_efer)
728 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_EFER, efer);
729 
730 	if (!error && set_cr0)
731 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR0, cr0);
732 
733 	if (!error && set_cr3)
734 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR3, cr3);
735 
736 	if (!error && set_cr4)
737 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR4, cr4);
738 
739 	if (!error && set_dr7)
740 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DR7, dr7);
741 
742 	if (!error && set_rsp)
743 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RSP, rsp);
744 
745 	if (!error && set_rip)
746 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RIP, rip);
747 
748 	if (!error && set_rax)
749 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, rax);
750 
751 	if (!error && set_rflags) {
752 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS,
753 					rflags);
754 	}
755 
756 	if (!error && set_desc_ds) {
757 		error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_DS,
758 				    desc_base, desc_limit, desc_access);
759 	}
760 
761 	if (!error && set_desc_es) {
762 		error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_ES,
763 				    desc_base, desc_limit, desc_access);
764 	}
765 
766 	if (!error && set_desc_ss) {
767 		error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_SS,
768 				    desc_base, desc_limit, desc_access);
769 	}
770 
771 	if (!error && set_desc_cs) {
772 		error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_CS,
773 				    desc_base, desc_limit, desc_access);
774 	}
775 
776 	if (!error && set_desc_fs) {
777 		error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_FS,
778 				    desc_base, desc_limit, desc_access);
779 	}
780 
781 	if (!error && set_desc_gs) {
782 		error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_GS,
783 				    desc_base, desc_limit, desc_access);
784 	}
785 
786 	if (!error && set_desc_tr) {
787 		error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_TR,
788 				    desc_base, desc_limit, desc_access);
789 	}
790 
791 	if (!error && set_desc_ldtr) {
792 		error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_LDTR,
793 				    desc_base, desc_limit, desc_access);
794 	}
795 
796 	if (!error && set_desc_gdtr) {
797 		error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_GDTR,
798 				    desc_base, desc_limit, 0);
799 	}
800 
801 	if (!error && set_desc_idtr) {
802 		error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_IDTR,
803 				    desc_base, desc_limit, 0);
804 	}
805 
806 	if (!error && set_cs)
807 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CS, cs);
808 
809 	if (!error && set_ds)
810 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DS, ds);
811 
812 	if (!error && set_es)
813 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_ES, es);
814 
815 	if (!error && set_fs)
816 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_FS, fs);
817 
818 	if (!error && set_gs)
819 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_GS, gs);
820 
821 	if (!error && set_ss)
822 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_SS, ss);
823 
824 	if (!error && set_tr)
825 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_TR, tr);
826 
827 	if (!error && set_ldtr)
828 		error = vm_set_register(ctx, vcpu, VM_REG_GUEST_LDTR, ldtr);
829 
830 	if (!error && set_x2apic_state)
831 		error = vm_set_x2apic_state(ctx, vcpu, x2apic_state);
832 
833 	if (!error && unassign_pptdev)
834 		error = vm_unassign_pptdev(ctx, bus, slot, func);
835 
836 	if (!error && set_exception_bitmap) {
837 		error = vm_set_vmcs_field(ctx, vcpu, VMCS_EXCEPTION_BITMAP,
838 					  exception_bitmap);
839 	}
840 
841 	if (!error && set_vmcs_entry_interruption_info) {
842 		error = vm_set_vmcs_field(ctx, vcpu, VMCS_ENTRY_INTR_INFO,
843 					  vmcs_entry_interruption_info);
844 	}
845 
846 	if (!error && inject_nmi) {
847 		error = vm_inject_nmi(ctx, vcpu);
848 	}
849 
850 	if (!error && assert_lapic_lvt != -1) {
851 		error = vm_lapic_local_irq(ctx, vcpu, assert_lapic_lvt);
852 	}
853 
854 	if (!error && (get_lowmem || get_all)) {
855 		gpa = 0;
856 		error = vm_get_memory_seg(ctx, gpa, &len, &wired);
857 		if (error == 0)
858 			printf("lowmem\t\t0x%016lx/%ld%s\n", gpa, len,
859 			    wired ? " wired" : "");
860 	}
861 
862 	if (!error && (get_highmem || get_all)) {
863 		gpa = 4 * GB;
864 		error = vm_get_memory_seg(ctx, gpa, &len, &wired);
865 		if (error == 0)
866 			printf("highmem\t\t0x%016lx/%ld%s\n", gpa, len,
867 			    wired ? " wired" : "");
868 	}
869 
870 	if (!error && (get_efer || get_all)) {
871 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_EFER, &efer);
872 		if (error == 0)
873 			printf("efer[%d]\t\t0x%016lx\n", vcpu, efer);
874 	}
875 
876 	if (!error && (get_cr0 || get_all)) {
877 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR0, &cr0);
878 		if (error == 0)
879 			printf("cr0[%d]\t\t0x%016lx\n", vcpu, cr0);
880 	}
881 
882 	if (!error && (get_cr3 || get_all)) {
883 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR3, &cr3);
884 		if (error == 0)
885 			printf("cr3[%d]\t\t0x%016lx\n", vcpu, cr3);
886 	}
887 
888 	if (!error && (get_cr4 || get_all)) {
889 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR4, &cr4);
890 		if (error == 0)
891 			printf("cr4[%d]\t\t0x%016lx\n", vcpu, cr4);
892 	}
893 
894 	if (!error && (get_dr7 || get_all)) {
895 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DR7, &dr7);
896 		if (error == 0)
897 			printf("dr7[%d]\t\t0x%016lx\n", vcpu, dr7);
898 	}
899 
900 	if (!error && (get_rsp || get_all)) {
901 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RSP, &rsp);
902 		if (error == 0)
903 			printf("rsp[%d]\t\t0x%016lx\n", vcpu, rsp);
904 	}
905 
906 	if (!error && (get_rip || get_all)) {
907 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RIP, &rip);
908 		if (error == 0)
909 			printf("rip[%d]\t\t0x%016lx\n", vcpu, rip);
910 	}
911 
912 	if (!error && (get_rax || get_all)) {
913 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RAX, &rax);
914 		if (error == 0)
915 			printf("rax[%d]\t\t0x%016lx\n", vcpu, rax);
916 	}
917 
918 	if (!error && (get_rbx || get_all)) {
919 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RBX, &rbx);
920 		if (error == 0)
921 			printf("rbx[%d]\t\t0x%016lx\n", vcpu, rbx);
922 	}
923 
924 	if (!error && (get_rcx || get_all)) {
925 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RCX, &rcx);
926 		if (error == 0)
927 			printf("rcx[%d]\t\t0x%016lx\n", vcpu, rcx);
928 	}
929 
930 	if (!error && (get_rdx || get_all)) {
931 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RDX, &rdx);
932 		if (error == 0)
933 			printf("rdx[%d]\t\t0x%016lx\n", vcpu, rdx);
934 	}
935 
936 	if (!error && (get_rsi || get_all)) {
937 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RSI, &rsi);
938 		if (error == 0)
939 			printf("rsi[%d]\t\t0x%016lx\n", vcpu, rsi);
940 	}
941 
942 	if (!error && (get_rdi || get_all)) {
943 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RDI, &rdi);
944 		if (error == 0)
945 			printf("rdi[%d]\t\t0x%016lx\n", vcpu, rdi);
946 	}
947 
948 	if (!error && (get_rbp || get_all)) {
949 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RBP, &rbp);
950 		if (error == 0)
951 			printf("rbp[%d]\t\t0x%016lx\n", vcpu, rbp);
952 	}
953 
954 	if (!error && (get_r8 || get_all)) {
955 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_R8, &r8);
956 		if (error == 0)
957 			printf("r8[%d]\t\t0x%016lx\n", vcpu, r8);
958 	}
959 
960 	if (!error && (get_r9 || get_all)) {
961 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_R9, &r9);
962 		if (error == 0)
963 			printf("r9[%d]\t\t0x%016lx\n", vcpu, r9);
964 	}
965 
966 	if (!error && (get_r10 || get_all)) {
967 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_R10, &r10);
968 		if (error == 0)
969 			printf("r10[%d]\t\t0x%016lx\n", vcpu, r10);
970 	}
971 
972 	if (!error && (get_r11 || get_all)) {
973 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_R11, &r11);
974 		if (error == 0)
975 			printf("r11[%d]\t\t0x%016lx\n", vcpu, r11);
976 	}
977 
978 	if (!error && (get_r12 || get_all)) {
979 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_R12, &r12);
980 		if (error == 0)
981 			printf("r12[%d]\t\t0x%016lx\n", vcpu, r12);
982 	}
983 
984 	if (!error && (get_r13 || get_all)) {
985 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_R13, &r13);
986 		if (error == 0)
987 			printf("r13[%d]\t\t0x%016lx\n", vcpu, r13);
988 	}
989 
990 	if (!error && (get_r14 || get_all)) {
991 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_R14, &r14);
992 		if (error == 0)
993 			printf("r14[%d]\t\t0x%016lx\n", vcpu, r14);
994 	}
995 
996 	if (!error && (get_r15 || get_all)) {
997 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_R15, &r15);
998 		if (error == 0)
999 			printf("r15[%d]\t\t0x%016lx\n", vcpu, r15);
1000 	}
1001 
1002 	if (!error && (get_rflags || get_all)) {
1003 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RFLAGS,
1004 					&rflags);
1005 		if (error == 0)
1006 			printf("rflags[%d]\t0x%016lx\n", vcpu, rflags);
1007 	}
1008 
1009 	if (!error && (get_stats || get_all)) {
1010 		int i, num_stats;
1011 		uint64_t *stats;
1012 		struct timeval tv;
1013 		const char *desc;
1014 
1015 		stats = vm_get_stats(ctx, vcpu, &tv, &num_stats);
1016 		if (stats != NULL) {
1017 			printf("vcpu%d\n", vcpu);
1018 			for (i = 0; i < num_stats; i++) {
1019 				desc = vm_get_stat_desc(ctx, i);
1020 				printf("%-40s\t%ld\n", desc, stats[i]);
1021 			}
1022 		}
1023 	}
1024 
1025 	if (!error && (get_desc_ds || get_all)) {
1026 		error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_DS,
1027 				    &desc_base, &desc_limit, &desc_access);
1028 		if (error == 0) {
1029 			printf("ds desc[%d]\t0x%016lx/0x%08x/0x%08x\n",
1030 			       vcpu, desc_base, desc_limit, desc_access);
1031 		}
1032 	}
1033 
1034 	if (!error && (get_desc_es || get_all)) {
1035 		error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_ES,
1036 				    &desc_base, &desc_limit, &desc_access);
1037 		if (error == 0) {
1038 			printf("es desc[%d]\t0x%016lx/0x%08x/0x%08x\n",
1039 			       vcpu, desc_base, desc_limit, desc_access);
1040 		}
1041 	}
1042 
1043 	if (!error && (get_desc_fs || get_all)) {
1044 		error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_FS,
1045 				    &desc_base, &desc_limit, &desc_access);
1046 		if (error == 0) {
1047 			printf("fs desc[%d]\t0x%016lx/0x%08x/0x%08x\n",
1048 			       vcpu, desc_base, desc_limit, desc_access);
1049 		}
1050 	}
1051 
1052 	if (!error && (get_desc_gs || get_all)) {
1053 		error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_GS,
1054 				    &desc_base, &desc_limit, &desc_access);
1055 		if (error == 0) {
1056 			printf("gs desc[%d]\t0x%016lx/0x%08x/0x%08x\n",
1057 			       vcpu, desc_base, desc_limit, desc_access);
1058 		}
1059 	}
1060 
1061 	if (!error && (get_desc_ss || get_all)) {
1062 		error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_SS,
1063 				    &desc_base, &desc_limit, &desc_access);
1064 		if (error == 0) {
1065 			printf("ss desc[%d]\t0x%016lx/0x%08x/0x%08x\n",
1066 			       vcpu, desc_base, desc_limit, desc_access);
1067 		}
1068 	}
1069 
1070 	if (!error && (get_desc_cs || get_all)) {
1071 		error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_CS,
1072 				    &desc_base, &desc_limit, &desc_access);
1073 		if (error == 0) {
1074 			printf("cs desc[%d]\t0x%016lx/0x%08x/0x%08x\n",
1075 			       vcpu, desc_base, desc_limit, desc_access);
1076 		}
1077 	}
1078 
1079 	if (!error && (get_desc_tr || get_all)) {
1080 		error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_TR,
1081 				    &desc_base, &desc_limit, &desc_access);
1082 		if (error == 0) {
1083 			printf("tr desc[%d]\t0x%016lx/0x%08x/0x%08x\n",
1084 			       vcpu, desc_base, desc_limit, desc_access);
1085 		}
1086 	}
1087 
1088 	if (!error && (get_desc_ldtr || get_all)) {
1089 		error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_LDTR,
1090 				    &desc_base, &desc_limit, &desc_access);
1091 		if (error == 0) {
1092 			printf("ldtr desc[%d]\t0x%016lx/0x%08x/0x%08x\n",
1093 			       vcpu, desc_base, desc_limit, desc_access);
1094 		}
1095 	}
1096 
1097 	if (!error && (get_desc_gdtr || get_all)) {
1098 		error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_GDTR,
1099 				    &desc_base, &desc_limit, &desc_access);
1100 		if (error == 0) {
1101 			printf("gdtr[%d]\t\t0x%016lx/0x%08x\n",
1102 			       vcpu, desc_base, desc_limit);
1103 		}
1104 	}
1105 
1106 	if (!error && (get_desc_idtr || get_all)) {
1107 		error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_IDTR,
1108 				    &desc_base, &desc_limit, &desc_access);
1109 		if (error == 0) {
1110 			printf("idtr[%d]\t\t0x%016lx/0x%08x\n",
1111 			       vcpu, desc_base, desc_limit);
1112 		}
1113 	}
1114 
1115 	if (!error && (get_cs || get_all)) {
1116 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CS, &cs);
1117 		if (error == 0)
1118 			printf("cs[%d]\t\t0x%04lx\n", vcpu, cs);
1119 	}
1120 
1121 	if (!error && (get_ds || get_all)) {
1122 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DS, &ds);
1123 		if (error == 0)
1124 			printf("ds[%d]\t\t0x%04lx\n", vcpu, ds);
1125 	}
1126 
1127 	if (!error && (get_es || get_all)) {
1128 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_ES, &es);
1129 		if (error == 0)
1130 			printf("es[%d]\t\t0x%04lx\n", vcpu, es);
1131 	}
1132 
1133 	if (!error && (get_fs || get_all)) {
1134 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_FS, &fs);
1135 		if (error == 0)
1136 			printf("fs[%d]\t\t0x%04lx\n", vcpu, fs);
1137 	}
1138 
1139 	if (!error && (get_gs || get_all)) {
1140 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_GS, &gs);
1141 		if (error == 0)
1142 			printf("gs[%d]\t\t0x%04lx\n", vcpu, gs);
1143 	}
1144 
1145 	if (!error && (get_ss || get_all)) {
1146 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_SS, &ss);
1147 		if (error == 0)
1148 			printf("ss[%d]\t\t0x%04lx\n", vcpu, ss);
1149 	}
1150 
1151 	if (!error && (get_tr || get_all)) {
1152 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_TR, &tr);
1153 		if (error == 0)
1154 			printf("tr[%d]\t\t0x%04lx\n", vcpu, tr);
1155 	}
1156 
1157 	if (!error && (get_ldtr || get_all)) {
1158 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_LDTR, &ldtr);
1159 		if (error == 0)
1160 			printf("ldtr[%d]\t\t0x%04lx\n", vcpu, ldtr);
1161 	}
1162 
1163 	if (!error && (get_x2apic_state || get_all)) {
1164 		error = vm_get_x2apic_state(ctx, vcpu, &x2apic_state);
1165 		if (error == 0)
1166 			printf("x2apic_state[%d]\t%d\n", vcpu, x2apic_state);
1167 	}
1168 
1169 	if (!error && (get_pinbased_ctls || get_all)) {
1170 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_PIN_BASED_CTLS, &ctl);
1171 		if (error == 0)
1172 			printf("pinbased_ctls[%d]\t0x%08lx\n", vcpu, ctl);
1173 	}
1174 
1175 	if (!error && (get_procbased_ctls || get_all)) {
1176 		error = vm_get_vmcs_field(ctx, vcpu,
1177 					  VMCS_PRI_PROC_BASED_CTLS, &ctl);
1178 		if (error == 0)
1179 			printf("procbased_ctls[%d]\t0x%08lx\n", vcpu, ctl);
1180 	}
1181 
1182 	if (!error && (get_procbased_ctls2 || get_all)) {
1183 		error = vm_get_vmcs_field(ctx, vcpu,
1184 					  VMCS_SEC_PROC_BASED_CTLS, &ctl);
1185 		if (error == 0)
1186 			printf("procbased_ctls2[%d]\t0x%08lx\n", vcpu, ctl);
1187 	}
1188 
1189 	if (!error && (get_vmcs_gla || get_all)) {
1190 		error = vm_get_vmcs_field(ctx, vcpu,
1191 					  VMCS_GUEST_LINEAR_ADDRESS, &u64);
1192 		if (error == 0)
1193 			printf("gla[%d]\t\t0x%016lx\n", vcpu, u64);
1194 	}
1195 
1196 	if (!error && (get_vmcs_gpa || get_all)) {
1197 		error = vm_get_vmcs_field(ctx, vcpu,
1198 					  VMCS_GUEST_PHYSICAL_ADDRESS, &u64);
1199 		if (error == 0)
1200 			printf("gpa[%d]\t\t0x%016lx\n", vcpu, u64);
1201 	}
1202 
1203 	if (!error && (get_vmcs_entry_interruption_info || get_all)) {
1204 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_ENTRY_INTR_INFO,&u64);
1205 		if (error == 0) {
1206 			printf("entry_interruption_info[%d]\t0x%08lx\n",
1207 				vcpu, u64);
1208 		}
1209 	}
1210 
1211 	if (!error && (get_eptp || get_all)) {
1212 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_EPTP, &eptp);
1213 		if (error == 0)
1214 			printf("eptp[%d]\t\t0x%016lx\n", vcpu, eptp);
1215 	}
1216 
1217 	if (!error && (get_exception_bitmap || get_all)) {
1218 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXCEPTION_BITMAP,
1219 					  &bm);
1220 		if (error == 0)
1221 			printf("exception_bitmap[%d]\t0x%08lx\n", vcpu, bm);
1222 	}
1223 
1224 	if (!error && (get_io_bitmap || get_all)) {
1225 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_IO_BITMAP_A, &bm);
1226 		if (error == 0)
1227 			printf("io_bitmap_a[%d]\t0x%08lx\n", vcpu, bm);
1228 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_IO_BITMAP_B, &bm);
1229 		if (error == 0)
1230 			printf("io_bitmap_b[%d]\t0x%08lx\n", vcpu, bm);
1231 	}
1232 
1233 	if (!error && (get_tsc_offset || get_all)) {
1234 		uint64_t tscoff;
1235 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_TSC_OFFSET, &tscoff);
1236 		if (error == 0)
1237 			printf("tsc_offset[%d]\t0x%016lx\n", vcpu, tscoff);
1238 	}
1239 
1240 	if (!error && (get_cr0_mask || get_all)) {
1241 		uint64_t cr0mask;
1242 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR0_MASK, &cr0mask);
1243 		if (error == 0)
1244 			printf("cr0_mask[%d]\t\t0x%016lx\n", vcpu, cr0mask);
1245 	}
1246 
1247 	if (!error && (get_cr0_shadow || get_all)) {
1248 		uint64_t cr0shadow;
1249 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR0_SHADOW,
1250 					  &cr0shadow);
1251 		if (error == 0)
1252 			printf("cr0_shadow[%d]\t\t0x%016lx\n", vcpu, cr0shadow);
1253 	}
1254 
1255 	if (!error && (get_cr4_mask || get_all)) {
1256 		uint64_t cr4mask;
1257 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR4_MASK, &cr4mask);
1258 		if (error == 0)
1259 			printf("cr4_mask[%d]\t\t0x%016lx\n", vcpu, cr4mask);
1260 	}
1261 
1262 	if (!error && (get_cr4_shadow || get_all)) {
1263 		uint64_t cr4shadow;
1264 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR4_SHADOW,
1265 					  &cr4shadow);
1266 		if (error == 0)
1267 			printf("cr4_shadow[%d]\t\t0x%016lx\n", vcpu, cr4shadow);
1268 	}
1269 
1270 	if (!error && (get_cr3_targets || get_all)) {
1271 		uint64_t target_count, target_addr;
1272 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR3_TARGET_COUNT,
1273 					  &target_count);
1274 		if (error == 0) {
1275 			printf("cr3_target_count[%d]\t0x%08lx\n",
1276 				vcpu, target_count);
1277 		}
1278 
1279 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR3_TARGET0,
1280 					  &target_addr);
1281 		if (error == 0) {
1282 			printf("cr3_target0[%d]\t\t0x%016lx\n",
1283 				vcpu, target_addr);
1284 		}
1285 
1286 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR3_TARGET1,
1287 					  &target_addr);
1288 		if (error == 0) {
1289 			printf("cr3_target1[%d]\t\t0x%016lx\n",
1290 				vcpu, target_addr);
1291 		}
1292 
1293 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR3_TARGET2,
1294 					  &target_addr);
1295 		if (error == 0) {
1296 			printf("cr3_target2[%d]\t\t0x%016lx\n",
1297 				vcpu, target_addr);
1298 		}
1299 
1300 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR3_TARGET3,
1301 					  &target_addr);
1302 		if (error == 0) {
1303 			printf("cr3_target3[%d]\t\t0x%016lx\n",
1304 				vcpu, target_addr);
1305 		}
1306 	}
1307 
1308 	if (!error && (get_apic_access_addr || get_all)) {
1309 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_APIC_ACCESS, &addr);
1310 		if (error == 0)
1311 			printf("apic_access_addr[%d]\t0x%016lx\n", vcpu, addr);
1312 	}
1313 
1314 	if (!error && (get_virtual_apic_addr || get_all)) {
1315 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_VIRTUAL_APIC, &addr);
1316 		if (error == 0)
1317 			printf("virtual_apic_addr[%d]\t0x%016lx\n", vcpu, addr);
1318 	}
1319 
1320 	if (!error && (get_tpr_threshold || get_all)) {
1321 		uint64_t threshold;
1322 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_TPR_THRESHOLD,
1323 					  &threshold);
1324 		if (error == 0)
1325 			printf("tpr_threshold[%d]\t0x%08lx\n", vcpu, threshold);
1326 	}
1327 
1328 	if (!error && (get_msr_bitmap_address || get_all)) {
1329 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_MSR_BITMAP, &addr);
1330 		if (error == 0)
1331 			printf("msr_bitmap[%d]\t\t0x%016lx\n", vcpu, addr);
1332 	}
1333 
1334 	if (!error && (get_msr_bitmap || get_all)) {
1335 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_MSR_BITMAP, &addr);
1336 		if (error == 0)
1337 			error = dump_vmcs_msr_bitmap(vcpu, addr);
1338 	}
1339 
1340 	if (!error && (get_vpid || get_all)) {
1341 		uint64_t vpid;
1342 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_VPID, &vpid);
1343 		if (error == 0)
1344 			printf("vpid[%d]\t\t0x%04lx\n", vcpu, vpid);
1345 	}
1346 
1347 	if (!error && (get_ple_window || get_all)) {
1348 		uint64_t window;
1349 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_PLE_WINDOW, &window);
1350 		if (error == 0)
1351 			printf("ple_window[%d]\t\t0x%08lx\n", vcpu, window);
1352 	}
1353 
1354 	if (!error && (get_ple_gap || get_all)) {
1355 		uint64_t gap;
1356 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_PLE_GAP, &gap);
1357 		if (error == 0)
1358 			printf("ple_gap[%d]\t\t0x%08lx\n", vcpu, gap);
1359 	}
1360 
1361 	if (!error && (get_inst_err || get_all)) {
1362 		uint64_t insterr;
1363 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_INSTRUCTION_ERROR,
1364 					  &insterr);
1365 		if (error == 0) {
1366 			printf("instruction_error[%d]\t0x%08lx\n",
1367 				vcpu, insterr);
1368 		}
1369 	}
1370 
1371 	if (!error && (get_exit_ctls || get_all)) {
1372 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_CTLS, &ctl);
1373 		if (error == 0)
1374 			printf("exit_ctls[%d]\t\t0x%08lx\n", vcpu, ctl);
1375 	}
1376 
1377 	if (!error && (get_entry_ctls || get_all)) {
1378 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_ENTRY_CTLS, &ctl);
1379 		if (error == 0)
1380 			printf("entry_ctls[%d]\t\t0x%08lx\n", vcpu, ctl);
1381 	}
1382 
1383 	if (!error && (get_host_pat || get_all)) {
1384 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_IA32_PAT, &pat);
1385 		if (error == 0)
1386 			printf("host_pat[%d]\t\t0x%016lx\n", vcpu, pat);
1387 	}
1388 
1389 	if (!error && (get_guest_pat || get_all)) {
1390 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_GUEST_IA32_PAT, &pat);
1391 		if (error == 0)
1392 			printf("guest_pat[%d]\t\t0x%016lx\n", vcpu, pat);
1393 	}
1394 
1395 	if (!error && (get_host_cr0 || get_all)) {
1396 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_CR0, &cr0);
1397 		if (error == 0)
1398 			printf("host_cr0[%d]\t\t0x%016lx\n", vcpu, cr0);
1399 	}
1400 
1401 	if (!error && (get_host_cr3 || get_all)) {
1402 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_CR3, &cr3);
1403 		if (error == 0)
1404 			printf("host_cr3[%d]\t\t0x%016lx\n", vcpu, cr3);
1405 	}
1406 
1407 	if (!error && (get_host_cr4 || get_all)) {
1408 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_CR4, &cr4);
1409 		if (error == 0)
1410 			printf("host_cr4[%d]\t\t0x%016lx\n", vcpu, cr4);
1411 	}
1412 
1413 	if (!error && (get_host_rip || get_all)) {
1414 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_RIP, &rip);
1415 		if (error == 0)
1416 			printf("host_rip[%d]\t\t0x%016lx\n", vcpu, rip);
1417 	}
1418 
1419 	if (!error && (get_host_rsp || get_all)) {
1420 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_RSP, &rsp);
1421 		if (error == 0)
1422 			printf("host_rsp[%d]\t\t0x%016lx\n", vcpu, rsp);
1423 	}
1424 
1425 	if (!error && (get_guest_sysenter || get_all)) {
1426 		error = vm_get_vmcs_field(ctx, vcpu,
1427 					  VMCS_GUEST_IA32_SYSENTER_CS, &cs);
1428 		if (error == 0)
1429 			printf("guest_sysenter_cs[%d]\t0x%08lx\n", vcpu, cs);
1430 
1431 		error = vm_get_vmcs_field(ctx, vcpu,
1432 					  VMCS_GUEST_IA32_SYSENTER_ESP, &rsp);
1433 		if (error == 0)
1434 			printf("guest_sysenter_sp[%d]\t0x%016lx\n", vcpu, rsp);
1435 		error = vm_get_vmcs_field(ctx, vcpu,
1436 					  VMCS_GUEST_IA32_SYSENTER_EIP, &rip);
1437 		if (error == 0)
1438 			printf("guest_sysenter_ip[%d]\t0x%016lx\n", vcpu, rip);
1439 	}
1440 
1441 	if (!error && (get_vmcs_link || get_all)) {
1442 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_LINK_POINTER, &addr);
1443 		if (error == 0)
1444 			printf("vmcs_pointer[%d]\t0x%016lx\n", vcpu, addr);
1445 	}
1446 
1447 	if (!error && (get_vmcs_exit_reason || get_all)) {
1448 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_REASON, &u64);
1449 		if (error == 0)
1450 			printf("vmcs_exit_reason[%d]\t0x%016lx\n", vcpu, u64);
1451 	}
1452 
1453 	if (!error && (get_vmcs_exit_qualification || get_all)) {
1454 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_QUALIFICATION,
1455 					  &u64);
1456 		if (error == 0)
1457 			printf("vmcs_exit_qualification[%d]\t0x%016lx\n",
1458 				vcpu, u64);
1459 	}
1460 
1461 	if (!error && (get_vmcs_exit_interruption_info || get_all)) {
1462 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_INTR_INFO, &u64);
1463 		if (error == 0) {
1464 			printf("vmcs_exit_interruption_info[%d]\t0x%08lx\n",
1465 				vcpu, u64);
1466 		}
1467 	}
1468 
1469 	if (!error && (get_vmcs_exit_interruption_error || get_all)) {
1470 		error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_INTR_ERRCODE,
1471 		    &u64);
1472 		if (error == 0) {
1473 			printf("vmcs_exit_interruption_error[%d]\t0x%08lx\n",
1474 				vcpu, u64);
1475 		}
1476 	}
1477 
1478 	if (!error && (get_vmcs_interruptibility || get_all)) {
1479 		error = vm_get_vmcs_field(ctx, vcpu,
1480 					  VMCS_GUEST_INTERRUPTIBILITY, &u64);
1481 		if (error == 0) {
1482 			printf("vmcs_guest_interruptibility[%d]\t0x%08lx\n",
1483 				vcpu, u64);
1484 		}
1485 	}
1486 
1487 	if (!error && setcap) {
1488 		int captype;
1489 		captype = vm_capability_name2type(capname);
1490 		error = vm_set_capability(ctx, vcpu, captype, capval);
1491 		if (error != 0 && errno == ENOENT)
1492 			printf("Capability \"%s\" is not available\n", capname);
1493 	}
1494 
1495 	if (!error && get_gpa_pmap) {
1496 		error = vm_get_gpa_pmap(ctx, gpa_pmap, pteval, &ptenum);
1497 		if (error == 0) {
1498 			printf("gpa %#lx:", gpa_pmap);
1499 			pte = &pteval[0];
1500 			while (ptenum-- > 0)
1501 				printf(" %#lx", *pte++);
1502 			printf("\n");
1503 		}
1504 	}
1505 
1506 	if (!error && (getcap || get_all)) {
1507 		int captype, val, getcaptype;
1508 
1509 		if (getcap && capname)
1510 			getcaptype = vm_capability_name2type(capname);
1511 		else
1512 			getcaptype = -1;
1513 
1514 		for (captype = 0; captype < VM_CAP_MAX; captype++) {
1515 			if (getcaptype >= 0 && captype != getcaptype)
1516 				continue;
1517 			error = vm_get_capability(ctx, vcpu, captype, &val);
1518 			if (error == 0) {
1519 				printf("Capability \"%s\" is %s on vcpu %d\n",
1520 					vm_capability_type2name(captype),
1521 					val ? "set" : "not set", vcpu);
1522 			} else if (errno == ENOENT) {
1523 				error = 0;
1524 				printf("Capability \"%s\" is not available\n",
1525 					vm_capability_type2name(captype));
1526 			} else {
1527 				break;
1528 			}
1529 		}
1530 	}
1531 
1532 	if (!error && run) {
1533 		error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RIP, &rip);
1534 		assert(error == 0);
1535 
1536 		error = vm_run(ctx, vcpu, rip, &vmexit);
1537 		if (error == 0)
1538 			dump_vm_run_exitcode(&vmexit, vcpu);
1539 		else
1540 			printf("vm_run error %d\n", error);
1541 	}
1542 
1543 	if (!error && force_reset)
1544 		error = vm_suspend(ctx, VM_SUSPEND_RESET);
1545 
1546 	if (!error && force_poweroff)
1547 		error = vm_suspend(ctx, VM_SUSPEND_POWEROFF);
1548 
1549 	if (error)
1550 		printf("errno = %d\n", errno);
1551 
1552 	if (!error && destroy)
1553 		vm_destroy(ctx);
1554 
1555 	exit(error);
1556 }
1557