bhyvectl.c (bf21cd9318e0a3a51b7f02c14a7c1b1aef2dc861) | bhyvectl.c (4c87aefe8930bd07275b8dd2e96ea5f24d93a52e) |
---|---|
1/*- | 1/*- |
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * |
|
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. --- 8 unchanged lines hidden (view full) --- 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 * | 4 * Copyright (c) 2011 NetApp, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. --- 8 unchanged lines hidden (view full) --- 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * |
26 * $FreeBSD: head/usr.sbin/bhyvectl/bhyvectl.c 273375 2014-10-21 07:10:43Z neel $ | 28 * $FreeBSD$ |
27 */ 28/* 29 * This file and its contents are supplied under the terms of the 30 * Common Development and Distribution License ("CDDL"), version 1.0. 31 * You may only use this file in accordance with the terms of version 32 * 1.0 of the CDDL. 33 * 34 * A full copy of the text of the CDDL should have accompanied this 35 * source. A copy of the CDDL is also available via the Internet at 36 * http://www.illumos.org/license/CDDL. 37 */ 38 39/* 40 * Copyright 2015 Pluribus Networks Inc. | 29 */ 30/* 31 * This file and its contents are supplied under the terms of the 32 * Common Development and Distribution License ("CDDL"), version 1.0. 33 * You may only use this file in accordance with the terms of version 34 * 1.0 of the CDDL. 35 * 36 * A full copy of the text of the CDDL should have accompanied this 37 * source. A copy of the CDDL is also available via the Internet at 38 * http://www.illumos.org/license/CDDL. 39 */ 40 41/* 42 * Copyright 2015 Pluribus Networks Inc. |
43 * Copyright 2019 Joyent, Inc. |
|
41 */ 42 43#include <sys/cdefs.h> | 44 */ 45 46#include <sys/cdefs.h> |
44__FBSDID("$FreeBSD: head/usr.sbin/bhyvectl/bhyvectl.c 273375 2014-10-21 07:10:43Z neel $"); | 47__FBSDID("$FreeBSD$"); |
45 46#include <sys/param.h> 47#include <sys/types.h> 48#include <sys/sysctl.h> 49#include <sys/errno.h> 50#include <sys/mman.h> | 48 49#include <sys/param.h> 50#include <sys/types.h> 51#include <sys/sysctl.h> 52#include <sys/errno.h> 53#include <sys/mman.h> |
54#include <sys/cpuset.h> |
|
51 52#include <stdio.h> 53#include <stdlib.h> | 55 56#include <stdio.h> 57#include <stdlib.h> |
58#include <stdbool.h> 59#include <string.h> |
|
54#include <unistd.h> 55#include <libgen.h> 56#include <libutil.h> 57#include <fcntl.h> | 60#include <unistd.h> 61#include <libgen.h> 62#include <libutil.h> 63#include <fcntl.h> |
58#include <string.h> | |
59#include <getopt.h> | 64#include <getopt.h> |
65#include <time.h> |
|
60#include <assert.h> | 66#include <assert.h> |
67#include <libutil.h> |
|
61 | 68 |
69#include <machine/cpufunc.h> 70#include <machine/specialreg.h> |
|
62#include <machine/vmm.h> | 71#include <machine/vmm.h> |
72#include <machine/vmm_dev.h> |
|
63#include <vmmapi.h> 64 | 73#include <vmmapi.h> 74 |
75#include "amd/vmcb.h" |
|
65#include "intel/vmcs.h" 66 67#define MB (1UL << 20) 68#define GB (1UL << 30) 69 70#define REQ_ARG required_argument 71#define NO_ARG no_argument 72#define OPT_ARG optional_argument 73 74static const char *progname; 75 76static void | 76#include "intel/vmcs.h" 77 78#define MB (1UL << 20) 79#define GB (1UL << 30) 80 81#define REQ_ARG required_argument 82#define NO_ARG no_argument 83#define OPT_ARG optional_argument 84 85static const char *progname; 86 87static void |
77usage(void) | 88usage(bool cpu_intel) |
78{ 79 80 (void)fprintf(stderr, 81 "Usage: %s --vm=<vmname>\n" 82 " [--cpu=<vcpu_number>]\n" 83 " [--create]\n" 84 " [--destroy]\n" | 89{ 90 91 (void)fprintf(stderr, 92 "Usage: %s --vm=<vmname>\n" 93 " [--cpu=<vcpu_number>]\n" 94 " [--create]\n" 95 " [--destroy]\n" |
96#ifndef __FreeBSD__ 97 " [--wrlock-cycle]\n" 98#endif |
|
85 " [--get-all]\n" 86 " [--get-stats]\n" 87 " [--set-desc-ds]\n" 88 " [--get-desc-ds]\n" 89 " [--set-desc-es]\n" 90 " [--get-desc-es]\n" 91 " [--set-desc-gs]\n" 92 " [--get-desc-gs]\n" --- 15 unchanged lines hidden (view full) --- 108 " [--capname=<capname>]\n" 109 " [--getcap]\n" 110 " [--setcap=<0|1>]\n" 111 " [--desc-base=<BASE>]\n" 112 " [--desc-limit=<LIMIT>]\n" 113 " [--desc-access=<ACCESS>]\n" 114 " [--set-cr0=<CR0>]\n" 115 " [--get-cr0]\n" | 99 " [--get-all]\n" 100 " [--get-stats]\n" 101 " [--set-desc-ds]\n" 102 " [--get-desc-ds]\n" 103 " [--set-desc-es]\n" 104 " [--get-desc-es]\n" 105 " [--set-desc-gs]\n" 106 " [--get-desc-gs]\n" --- 15 unchanged lines hidden (view full) --- 122 " [--capname=<capname>]\n" 123 " [--getcap]\n" 124 " [--setcap=<0|1>]\n" 125 " [--desc-base=<BASE>]\n" 126 " [--desc-limit=<LIMIT>]\n" 127 " [--desc-access=<ACCESS>]\n" 128 " [--set-cr0=<CR0>]\n" 129 " [--get-cr0]\n" |
130 " [--set-cr2=<CR2>]\n" 131 " [--get-cr2]\n" |
|
116 " [--set-cr3=<CR3>]\n" 117 " [--get-cr3]\n" 118 " [--set-cr4=<CR4>]\n" 119 " [--get-cr4]\n" | 132 " [--set-cr3=<CR3>]\n" 133 " [--get-cr3]\n" 134 " [--set-cr4=<CR4>]\n" 135 " [--get-cr4]\n" |
136 " [--set-dr0=<DR0>]\n" 137 " [--get-dr0]\n" 138 " [--set-dr1=<DR1>]\n" 139 " [--get-dr1]\n" 140 " [--set-dr2=<DR2>]\n" 141 " [--get-dr2]\n" 142 " [--set-dr3=<DR3>]\n" 143 " [--get-dr3]\n" 144 " [--set-dr6=<DR6>]\n" 145 " [--get-dr6]\n" |
|
120 " [--set-dr7=<DR7>]\n" 121 " [--get-dr7]\n" 122 " [--set-rsp=<RSP>]\n" 123 " [--get-rsp]\n" 124 " [--set-rip=<RIP>]\n" 125 " [--get-rip]\n" 126 " [--get-rax]\n" 127 " [--set-rax=<RAX>]\n" --- 22 unchanged lines hidden (view full) --- 150 " [--set-fs]\n" 151 " [--get-fs]\n" 152 " [--set-gs]\n" 153 " [--get-gs]\n" 154 " [--set-ss]\n" 155 " [--get-ss]\n" 156 " [--get-tr]\n" 157 " [--get-ldtr]\n" | 146 " [--set-dr7=<DR7>]\n" 147 " [--get-dr7]\n" 148 " [--set-rsp=<RSP>]\n" 149 " [--get-rsp]\n" 150 " [--set-rip=<RIP>]\n" 151 " [--get-rip]\n" 152 " [--get-rax]\n" 153 " [--set-rax=<RAX>]\n" --- 22 unchanged lines hidden (view full) --- 176 " [--set-fs]\n" 177 " [--get-fs]\n" 178 " [--set-gs]\n" 179 " [--get-gs]\n" 180 " [--set-ss]\n" 181 " [--get-ss]\n" 182 " [--get-tr]\n" 183 " [--get-ldtr]\n" |
158 " [--get-vmcs-pinbased-ctls]\n" 159 " [--get-vmcs-procbased-ctls]\n" 160 " [--get-vmcs-procbased-ctls2]\n" 161 " [--get-vmcs-entry-interruption-info]\n" 162 " [--set-vmcs-entry-interruption-info=<info>]\n" 163 " [--get-vmcs-eptp]\n" 164 " [--get-vmcs-guest-physical-address\n" 165 " [--get-vmcs-guest-linear-address\n" 166 " [--set-vmcs-exception-bitmap]\n" 167 " [--get-vmcs-exception-bitmap]\n" 168 " [--get-vmcs-io-bitmap-address]\n" 169 " [--get-vmcs-tsc-offset]\n" 170 " [--get-vmcs-guest-pat]\n" 171 " [--get-vmcs-host-pat]\n" 172 " [--get-vmcs-host-cr0]\n" 173 " [--get-vmcs-host-cr3]\n" 174 " [--get-vmcs-host-cr4]\n" 175 " [--get-vmcs-host-rip]\n" 176 " [--get-vmcs-host-rsp]\n" 177 " [--get-vmcs-cr0-mask]\n" 178 " [--get-vmcs-cr0-shadow]\n" 179 " [--get-vmcs-cr4-mask]\n" 180 " [--get-vmcs-cr4-shadow]\n" 181 " [--get-vmcs-cr3-targets]\n" 182 " [--get-vmcs-apic-access-address]\n" 183 " [--get-vmcs-virtual-apic-address]\n" 184 " [--get-vmcs-tpr-threshold]\n" 185 " [--get-vmcs-msr-bitmap]\n" 186 " [--get-vmcs-msr-bitmap-address]\n" 187 " [--get-vmcs-vpid]\n" 188 " [--get-vmcs-ple-gap]\n" 189 " [--get-vmcs-ple-window]\n" 190 " [--get-vmcs-instruction-error]\n" 191 " [--get-vmcs-exit-ctls]\n" 192 " [--get-vmcs-entry-ctls]\n" 193 " [--get-vmcs-guest-sysenter]\n" 194 " [--get-vmcs-link]\n" 195 " [--get-vmcs-exit-reason]\n" 196 " [--get-vmcs-exit-qualification]\n" 197 " [--get-vmcs-exit-interruption-info]\n" 198 " [--get-vmcs-exit-interruption-error]\n" 199 " [--get-vmcs-interruptibility]\n" | |
200 " [--set-x2apic-state=<state>]\n" 201 " [--get-x2apic-state]\n" 202 " [--unassign-pptdev=<bus/slot/func>]\n" 203 " [--set-mem=<memory in units of MB>]\n" 204 " [--get-lowmem]\n" | 184 " [--set-x2apic-state=<state>]\n" 185 " [--get-x2apic-state]\n" 186 " [--unassign-pptdev=<bus/slot/func>]\n" 187 " [--set-mem=<memory in units of MB>]\n" 188 " [--get-lowmem]\n" |
205 " [--get-highmem]\n", | 189 " [--get-highmem]\n" 190 " [--get-gpa-pmap]\n" 191 " [--assert-lapic-lvt=<pin>]\n" 192 " [--inject-nmi]\n" 193 " [--force-reset]\n" 194 " [--force-poweroff]\n" 195 " [--get-rtc-time]\n" 196 " [--set-rtc-time=<secs>]\n" 197 " [--get-rtc-nvram]\n" 198 " [--set-rtc-nvram=<val>]\n" 199 " [--rtc-nvram-offset=<offset>]\n" 200 " [--get-active-cpus]\n" 201 " [--get-suspended-cpus]\n" 202 " [--get-intinfo]\n" 203 " [--get-eptp]\n" 204 " [--set-exception-bitmap]\n" 205 " [--get-exception-bitmap]\n" 206 " [--get-tsc-offset]\n" 207 " [--get-guest-pat]\n" 208 " [--get-io-bitmap-address]\n" 209 " [--get-msr-bitmap]\n" 210 " [--get-msr-bitmap-address]\n" 211 " [--get-guest-sysenter]\n" 212 " [--get-exit-reason]\n" 213 " [--get-cpu-topology]\n", |
206 progname); | 214 progname); |
215 216 if (cpu_intel) { 217 (void)fprintf(stderr, 218 " [--get-vmcs-pinbased-ctls]\n" 219 " [--get-vmcs-procbased-ctls]\n" 220 " [--get-vmcs-procbased-ctls2]\n" 221 " [--get-vmcs-entry-interruption-info]\n" 222 " [--set-vmcs-entry-interruption-info=<info>]\n" 223 " [--get-vmcs-guest-physical-address\n" 224 " [--get-vmcs-guest-linear-address\n" 225 " [--get-vmcs-host-pat]\n" 226 " [--get-vmcs-host-cr0]\n" 227 " [--get-vmcs-host-cr3]\n" 228 " [--get-vmcs-host-cr4]\n" 229 " [--get-vmcs-host-rip]\n" 230 " [--get-vmcs-host-rsp]\n" 231 " [--get-vmcs-cr0-mask]\n" 232 " [--get-vmcs-cr0-shadow]\n" 233 " [--get-vmcs-cr4-mask]\n" 234 " [--get-vmcs-cr4-shadow]\n" 235 " [--get-vmcs-cr3-targets]\n" 236 " [--get-vmcs-apic-access-address]\n" 237 " [--get-vmcs-virtual-apic-address]\n" 238 " [--get-vmcs-tpr-threshold]\n" 239 " [--get-vmcs-vpid]\n" 240 " [--get-vmcs-instruction-error]\n" 241 " [--get-vmcs-exit-ctls]\n" 242 " [--get-vmcs-entry-ctls]\n" 243 " [--get-vmcs-link]\n" 244 " [--get-vmcs-exit-qualification]\n" 245 " [--get-vmcs-exit-interruption-info]\n" 246 " [--get-vmcs-exit-interruption-error]\n" 247 " [--get-vmcs-interruptibility]\n" 248 ); 249 } else { 250 (void)fprintf(stderr, 251 " [--get-vmcb-intercepts]\n" 252 " [--get-vmcb-asid]\n" 253 " [--get-vmcb-exit-details]\n" 254 " [--get-vmcb-tlb-ctrl]\n" 255 " [--get-vmcb-virq]\n" 256 " [--get-avic-apic-bar]\n" 257 " [--get-avic-backing-page]\n" 258 " [--get-avic-table]\n" 259 ); 260 } |
|
207 exit(1); 208} 209 | 261 exit(1); 262} 263 |
210static int get_stats, getcap, setcap, capval; | 264static int get_rtc_time, set_rtc_time; 265static int get_rtc_nvram, set_rtc_nvram; 266static int rtc_nvram_offset; 267static uint8_t rtc_nvram_value; 268static time_t rtc_secs; 269 270static int get_stats, getcap, setcap, capval, get_gpa_pmap; 271static int inject_nmi, assert_lapic_lvt; 272static int force_reset, force_poweroff; |
211static const char *capname; | 273static const char *capname; |
212static int create, destroy, get_lowmem, get_highmem; | 274static int create, destroy, get_memmap, get_memseg; 275static int get_intinfo; 276static int get_active_cpus, get_suspended_cpus; |
213static uint64_t memsize; | 277static uint64_t memsize; |
214static int set_cr0, get_cr0, set_cr3, get_cr3, set_cr4, get_cr4; | 278static int set_cr0, get_cr0, set_cr2, get_cr2, set_cr3, get_cr3; 279static int set_cr4, get_cr4; |
215static int set_efer, get_efer; | 280static int set_efer, get_efer; |
281static int set_dr0, get_dr0; 282static int set_dr1, get_dr1; 283static int set_dr2, get_dr2; 284static int set_dr3, get_dr3; 285static int set_dr6, get_dr6; |
|
216static int set_dr7, get_dr7; 217static int set_rsp, get_rsp, set_rip, get_rip, set_rflags, get_rflags; 218static int set_rax, get_rax; 219static int get_rbx, get_rcx, get_rdx, get_rsi, get_rdi, get_rbp; 220static int get_r8, get_r9, get_r10, get_r11, get_r12, get_r13, get_r14, get_r15; 221static int set_desc_ds, get_desc_ds; 222static int set_desc_es, get_desc_es; 223static int set_desc_fs, get_desc_fs; --- 5 unchanged lines hidden (view full) --- 229static int set_desc_tr, get_desc_tr; 230static int set_desc_ldtr, get_desc_ldtr; 231static int set_cs, set_ds, set_es, set_fs, set_gs, set_ss, set_tr, set_ldtr; 232static int get_cs, get_ds, get_es, get_fs, get_gs, get_ss, get_tr, get_ldtr; 233static int set_x2apic_state, get_x2apic_state; 234enum x2apic_state x2apic_state; 235static int unassign_pptdev, bus, slot, func; 236static int run; | 286static int set_dr7, get_dr7; 287static int set_rsp, get_rsp, set_rip, get_rip, set_rflags, get_rflags; 288static int set_rax, get_rax; 289static int get_rbx, get_rcx, get_rdx, get_rsi, get_rdi, get_rbp; 290static int get_r8, get_r9, get_r10, get_r11, get_r12, get_r13, get_r14, get_r15; 291static int set_desc_ds, get_desc_ds; 292static int set_desc_es, get_desc_es; 293static int set_desc_fs, get_desc_fs; --- 5 unchanged lines hidden (view full) --- 299static int set_desc_tr, get_desc_tr; 300static int set_desc_ldtr, get_desc_ldtr; 301static int set_cs, set_ds, set_es, set_fs, set_gs, set_ss, set_tr, set_ldtr; 302static int get_cs, get_ds, get_es, get_fs, get_gs, get_ss, get_tr, get_ldtr; 303static int set_x2apic_state, get_x2apic_state; 304enum x2apic_state x2apic_state; 305static int unassign_pptdev, bus, slot, func; 306static int run; |
307static int get_cpu_topology; 308#ifndef __FreeBSD__ 309static int wrlock_cycle; 310#endif |
|
237 238/* | 311 312/* |
313 * VMCB specific. 314 */ 315static int get_vmcb_intercept, get_vmcb_exit_details, get_vmcb_tlb_ctrl; 316static int get_vmcb_virq, get_avic_table; 317 318/* |
|
239 * VMCS-specific fields 240 */ 241static int get_pinbased_ctls, get_procbased_ctls, get_procbased_ctls2; 242static int get_eptp, get_io_bitmap, get_tsc_offset; 243static int get_vmcs_entry_interruption_info, set_vmcs_entry_interruption_info; 244static int get_vmcs_interruptibility; 245uint32_t vmcs_entry_interruption_info; 246static int get_vmcs_gpa, get_vmcs_gla; 247static int get_exception_bitmap, set_exception_bitmap, exception_bitmap; 248static int get_cr0_mask, get_cr0_shadow; 249static int get_cr4_mask, get_cr4_shadow; 250static int get_cr3_targets; 251static int get_apic_access_addr, get_virtual_apic_addr, get_tpr_threshold; 252static int get_msr_bitmap, get_msr_bitmap_address; | 319 * VMCS-specific fields 320 */ 321static int get_pinbased_ctls, get_procbased_ctls, get_procbased_ctls2; 322static int get_eptp, get_io_bitmap, get_tsc_offset; 323static int get_vmcs_entry_interruption_info, set_vmcs_entry_interruption_info; 324static int get_vmcs_interruptibility; 325uint32_t vmcs_entry_interruption_info; 326static int get_vmcs_gpa, get_vmcs_gla; 327static int get_exception_bitmap, set_exception_bitmap, exception_bitmap; 328static int get_cr0_mask, get_cr0_shadow; 329static int get_cr4_mask, get_cr4_shadow; 330static int get_cr3_targets; 331static int get_apic_access_addr, get_virtual_apic_addr, get_tpr_threshold; 332static int get_msr_bitmap, get_msr_bitmap_address; |
253static int get_vpid, get_ple_gap, get_ple_window; | 333static int get_vpid_asid; |
254static int get_inst_err, get_exit_ctls, get_entry_ctls; 255static int get_host_cr0, get_host_cr3, get_host_cr4; 256static int get_host_rip, get_host_rsp; 257static int get_guest_pat, get_host_pat; 258static int get_guest_sysenter, get_vmcs_link; | 334static int get_inst_err, get_exit_ctls, get_entry_ctls; 335static int get_host_cr0, get_host_cr3, get_host_cr4; 336static int get_host_rip, get_host_rsp; 337static int get_guest_pat, get_host_pat; 338static int get_guest_sysenter, get_vmcs_link; |
259static int get_vmcs_exit_reason, get_vmcs_exit_qualification; | 339static int get_exit_reason, get_vmcs_exit_qualification; |
260static int get_vmcs_exit_interruption_info, get_vmcs_exit_interruption_error; | 340static int get_vmcs_exit_interruption_info, get_vmcs_exit_interruption_error; |
341static int get_vmcs_exit_inst_length; |
|
261 262static uint64_t desc_base; 263static uint32_t desc_limit, desc_access; 264 265static int get_all; 266 267static void 268dump_vm_run_exitcode(struct vm_exit *vmexit, int vcpu) --- 17 unchanged lines hidden (view full) --- 286 printf("\tstatus\t\t%d\n", vmexit->u.vmx.status); 287 printf("\texit_reason\t0x%08x (%u)\n", 288 vmexit->u.vmx.exit_reason, vmexit->u.vmx.exit_reason); 289 printf("\tqualification\t0x%016lx\n", 290 vmexit->u.vmx.exit_qualification); 291 printf("\tinst_type\t\t%d\n", vmexit->u.vmx.inst_type); 292 printf("\tinst_error\t\t%d\n", vmexit->u.vmx.inst_error); 293 break; | 342 343static uint64_t desc_base; 344static uint32_t desc_limit, desc_access; 345 346static int get_all; 347 348static void 349dump_vm_run_exitcode(struct vm_exit *vmexit, int vcpu) --- 17 unchanged lines hidden (view full) --- 367 printf("\tstatus\t\t%d\n", vmexit->u.vmx.status); 368 printf("\texit_reason\t0x%08x (%u)\n", 369 vmexit->u.vmx.exit_reason, vmexit->u.vmx.exit_reason); 370 printf("\tqualification\t0x%016lx\n", 371 vmexit->u.vmx.exit_qualification); 372 printf("\tinst_type\t\t%d\n", vmexit->u.vmx.inst_type); 373 printf("\tinst_error\t\t%d\n", vmexit->u.vmx.inst_error); 374 break; |
375 case VM_EXITCODE_SVM: 376 printf("\treason\t\tSVM\n"); 377 printf("\texit_reason\t\t%#lx\n", vmexit->u.svm.exitcode); 378 printf("\texitinfo1\t\t%#lx\n", vmexit->u.svm.exitinfo1); 379 printf("\texitinfo2\t\t%#lx\n", vmexit->u.svm.exitinfo2); 380 break; |
|
294 default: 295 printf("*** unknown vm run exitcode %d\n", vmexit->exitcode); 296 break; 297 } 298} 299 | 381 default: 382 printf("*** unknown vm run exitcode %d\n", vmexit->exitcode); 383 break; 384 } 385} 386 |
300static int 301dump_vmcs_msr_bitmap(int vcpu, u_long addr) | 387/* AMD 6th generation and Intel compatible MSRs */ 388#define MSR_AMD6TH_START 0xC0000000 389#define MSR_AMD6TH_END 0xC0001FFF 390/* AMD 7th and 8th generation compatible MSRs */ 391#define MSR_AMD7TH_START 0xC0010000 392#define MSR_AMD7TH_END 0xC0011FFF 393 394static const char * 395msr_name(uint32_t msr) |
302{ | 396{ |
303 int error, fd, byte, bit, readable, writeable; 304 u_int msr; 305 const char *bitmap; | 397 static char buf[32]; |
306 | 398 |
307 error = -1; 308 bitmap = MAP_FAILED; | 399 switch(msr) { 400 case MSR_TSC: 401 return ("MSR_TSC"); 402 case MSR_EFER: 403 return ("MSR_EFER"); 404 case MSR_STAR: 405 return ("MSR_STAR"); 406 case MSR_LSTAR: 407 return ("MSR_LSTAR"); 408 case MSR_CSTAR: 409 return ("MSR_CSTAR"); 410 case MSR_SF_MASK: 411 return ("MSR_SF_MASK"); 412 case MSR_FSBASE: 413 return ("MSR_FSBASE"); 414 case MSR_GSBASE: 415 return ("MSR_GSBASE"); 416 case MSR_KGSBASE: 417 return ("MSR_KGSBASE"); 418 case MSR_SYSENTER_CS_MSR: 419 return ("MSR_SYSENTER_CS_MSR"); 420 case MSR_SYSENTER_ESP_MSR: 421 return ("MSR_SYSENTER_ESP_MSR"); 422 case MSR_SYSENTER_EIP_MSR: 423 return ("MSR_SYSENTER_EIP_MSR"); 424 case MSR_PAT: 425 return ("MSR_PAT"); 426 } 427 snprintf(buf, sizeof(buf), "MSR %#08x", msr); |
309 | 428 |
310 fd = open("/dev/mem", O_RDONLY, 0); 311 if (fd < 0) 312 goto done; | 429 return (buf); 430} |
313 | 431 |
314 bitmap = mmap(NULL, PAGE_SIZE, PROT_READ, 0, fd, addr); 315 if (bitmap == MAP_FAILED) 316 goto done; | 432static inline void 433print_msr_pm(uint64_t msr, int vcpu, int readable, int writeable) 434{ |
317 | 435 |
436 if (readable || writeable) { 437 printf("%-20s[%d]\t\t%c%c\n", msr_name(msr), vcpu, 438 readable ? 'R' : '-', writeable ? 'W' : '-'); 439 } 440} 441 442/* 443 * Reference APM vol2, section 15.11 MSR Intercepts. 444 */ 445static void 446dump_amd_msr_pm(const char *bitmap, int vcpu) 447{ 448 int byte, bit, readable, writeable; 449 uint32_t msr; 450 |
|
318 for (msr = 0; msr < 0x2000; msr++) { | 451 for (msr = 0; msr < 0x2000; msr++) { |
452 byte = msr / 4; 453 bit = (msr % 4) * 2; 454 455 /* Look at MSRs in the range 0x00000000 to 0x00001FFF */ 456 readable = (bitmap[byte] & (1 << bit)) ? 0 : 1; 457 writeable = (bitmap[byte] & (2 << bit)) ? 0 : 1; 458 print_msr_pm(msr, vcpu, readable, writeable); 459 460 /* Look at MSRs in the range 0xC0000000 to 0xC0001FFF */ 461 byte += 2048; 462 readable = (bitmap[byte] & (1 << bit)) ? 0 : 1; 463 writeable = (bitmap[byte] & (2 << bit)) ? 0 : 1; 464 print_msr_pm(msr + MSR_AMD6TH_START, vcpu, readable, 465 writeable); 466 467 /* MSR 0xC0010000 to 0xC0011FF is only for AMD */ 468 byte += 4096; 469 readable = (bitmap[byte] & (1 << bit)) ? 0 : 1; 470 writeable = (bitmap[byte] & (2 << bit)) ? 0 : 1; 471 print_msr_pm(msr + MSR_AMD7TH_START, vcpu, readable, 472 writeable); 473 } 474} 475 476/* 477 * Reference Intel SDM Vol3 Section 24.6.9 MSR-Bitmap Address 478 */ 479static void 480dump_intel_msr_pm(const char *bitmap, int vcpu) 481{ 482 int byte, bit, readable, writeable; 483 uint32_t msr; 484 485 for (msr = 0; msr < 0x2000; msr++) { |
|
319 byte = msr / 8; 320 bit = msr & 0x7; 321 322 /* Look at MSRs in the range 0x00000000 to 0x00001FFF */ 323 readable = (bitmap[byte] & (1 << bit)) ? 0 : 1; | 486 byte = msr / 8; 487 bit = msr & 0x7; 488 489 /* Look at MSRs in the range 0x00000000 to 0x00001FFF */ 490 readable = (bitmap[byte] & (1 << bit)) ? 0 : 1; |
324 writeable = (bitmap[2048 + byte] & (1 << bit)) ? 0 : 1; 325 if (readable || writeable) { 326 printf("msr 0x%08x[%d]\t\t%c%c\n", msr, vcpu, 327 readable ? 'R' : '-', 328 writeable ? 'W' : '-'); 329 } | 491 writeable = (bitmap[2048 + byte] & (1 << bit)) ? 0 : 1; 492 print_msr_pm(msr, vcpu, readable, writeable); |
330 331 /* Look at MSRs in the range 0xC0000000 to 0xC0001FFF */ 332 byte += 1024; 333 readable = (bitmap[byte] & (1 << bit)) ? 0 : 1; | 493 494 /* Look at MSRs in the range 0xC0000000 to 0xC0001FFF */ 495 byte += 1024; 496 readable = (bitmap[byte] & (1 << bit)) ? 0 : 1; |
334 writeable = (bitmap[2048 + byte] & (1 << bit)) ? 0 : 1; 335 if (readable || writeable) { 336 printf("msr 0x%08x[%d]\t\t%c%c\n", 337 0xc0000000 + msr, vcpu, 338 readable ? 'R' : '-', 339 writeable ? 'W' : '-'); 340 } | 497 writeable = (bitmap[2048 + byte] & (1 << bit)) ? 0 : 1; 498 print_msr_pm(msr + MSR_AMD6TH_START, vcpu, readable, 499 writeable); |
341 } | 500 } |
501} |
|
342 | 502 |
503static int 504dump_msr_bitmap(int vcpu, uint64_t addr, bool cpu_intel) 505{ 506 int error, fd, map_size; 507 const char *bitmap; 508 509 error = -1; 510 bitmap = MAP_FAILED; 511 512 fd = open("/dev/mem", O_RDONLY, 0); 513 if (fd < 0) { 514 perror("Couldn't open /dev/mem"); 515 goto done; 516 } 517 518 if (cpu_intel) 519 map_size = PAGE_SIZE; 520 else 521 map_size = 2 * PAGE_SIZE; 522 523 bitmap = mmap(NULL, map_size, PROT_READ, MAP_SHARED, fd, addr); 524 if (bitmap == MAP_FAILED) { 525 perror("mmap failed"); 526 goto done; 527 } 528 529 if (cpu_intel) 530 dump_intel_msr_pm(bitmap, vcpu); 531 else 532 dump_amd_msr_pm(bitmap, vcpu); 533 |
|
343 error = 0; 344done: 345 if (bitmap != MAP_FAILED) | 534 error = 0; 535done: 536 if (bitmap != MAP_FAILED) |
346 munmap((void *)bitmap, PAGE_SIZE); | 537 munmap((void *)bitmap, map_size); |
347 if (fd >= 0) 348 close(fd); | 538 if (fd >= 0) 539 close(fd); |
540 |
|
349 return (error); 350} 351 352static int 353vm_get_vmcs_field(struct vmctx *ctx, int vcpu, int field, uint64_t *ret_val) 354{ 355 356 return (vm_get_register(ctx, vcpu, VMCS_IDENT(field), ret_val)); 357} 358 359static int 360vm_set_vmcs_field(struct vmctx *ctx, int vcpu, int field, uint64_t val) 361{ 362 363 return (vm_set_register(ctx, vcpu, VMCS_IDENT(field), val)); 364} 365 | 541 return (error); 542} 543 544static int 545vm_get_vmcs_field(struct vmctx *ctx, int vcpu, int field, uint64_t *ret_val) 546{ 547 548 return (vm_get_register(ctx, vcpu, VMCS_IDENT(field), ret_val)); 549} 550 551static int 552vm_set_vmcs_field(struct vmctx *ctx, int vcpu, int field, uint64_t val) 553{ 554 555 return (vm_set_register(ctx, vcpu, VMCS_IDENT(field), val)); 556} 557 |
558static int 559vm_get_vmcb_field(struct vmctx *ctx, int vcpu, int off, int bytes, 560 uint64_t *ret_val) 561{ 562 563 return (vm_get_register(ctx, vcpu, VMCB_ACCESS(off, bytes), ret_val)); 564} 565 566static int 567vm_set_vmcb_field(struct vmctx *ctx, int vcpu, int off, int bytes, 568 uint64_t val) 569{ 570 571 return (vm_set_register(ctx, vcpu, VMCB_ACCESS(off, bytes), val)); 572} 573 |
|
366enum { 367 VMNAME = 1000, /* avoid collision with return values from getopt */ 368 VCPU, 369 SET_MEM, 370 SET_EFER, 371 SET_CR0, | 574enum { 575 VMNAME = 1000, /* avoid collision with return values from getopt */ 576 VCPU, 577 SET_MEM, 578 SET_EFER, 579 SET_CR0, |
580 SET_CR2, |
|
372 SET_CR3, 373 SET_CR4, | 581 SET_CR3, 582 SET_CR4, |
583 SET_DR0, 584 SET_DR1, 585 SET_DR2, 586 SET_DR3, 587 SET_DR6, |
|
374 SET_DR7, 375 SET_RSP, 376 SET_RIP, 377 SET_RAX, 378 SET_RFLAGS, 379 DESC_BASE, 380 DESC_LIMIT, 381 DESC_ACCESS, 382 SET_CS, 383 SET_DS, 384 SET_ES, 385 SET_FS, 386 SET_GS, 387 SET_SS, 388 SET_TR, 389 SET_LDTR, 390 SET_X2APIC_STATE, | 588 SET_DR7, 589 SET_RSP, 590 SET_RIP, 591 SET_RAX, 592 SET_RFLAGS, 593 DESC_BASE, 594 DESC_LIMIT, 595 DESC_ACCESS, 596 SET_CS, 597 SET_DS, 598 SET_ES, 599 SET_FS, 600 SET_GS, 601 SET_SS, 602 SET_TR, 603 SET_LDTR, 604 SET_X2APIC_STATE, |
391 SET_VMCS_EXCEPTION_BITMAP, | 605 SET_EXCEPTION_BITMAP, |
392 SET_VMCS_ENTRY_INTERRUPTION_INFO, 393 SET_CAP, 394 CAPNAME, 395 UNASSIGN_PPTDEV, | 606 SET_VMCS_ENTRY_INTERRUPTION_INFO, 607 SET_CAP, 608 CAPNAME, 609 UNASSIGN_PPTDEV, |
610 GET_GPA_PMAP, 611 ASSERT_LAPIC_LVT, 612 SET_RTC_TIME, 613 SET_RTC_NVRAM, 614 RTC_NVRAM_OFFSET, |
|
396}; 397 | 615}; 616 |
398int 399main(int argc, char *argv[]) | 617static void 618print_cpus(const char *banner, const cpuset_t *cpus) |
400{ | 619{ |
401 char *vmname; 402 int error, ch, vcpu; 403 vm_paddr_t gpa; 404 size_t len; 405 struct vm_exit vmexit; 406 uint64_t ctl, eptp, bm, addr, u64; 407 struct vmctx *ctx; 408 int wired; | 620 int i; 621 int first; |
409 | 622 |
410 uint64_t cr0, cr3, cr4, dr7, rsp, rip, rflags, efer, pat; 411 uint64_t rax, rbx, rcx, rdx, rsi, rdi, rbp; 412 uint64_t r8, r9, r10, r11, r12, r13, r14, r15; 413 uint64_t cs, ds, es, fs, gs, ss, tr, ldtr; | 623 first = 1; 624 printf("%s:\t", banner); 625 if (!CPU_EMPTY(cpus)) { 626 for (i = 0; i < CPU_SETSIZE; i++) { 627 if (CPU_ISSET(i, cpus)) { 628 printf("%s%d", first ? " " : ", ", i); 629 first = 0; 630 } 631 } 632 } else 633 printf(" (none)"); 634 printf("\n"); 635} |
414 | 636 |
415 struct option opts[] = { 416 { "vm", REQ_ARG, 0, VMNAME }, 417 { "cpu", REQ_ARG, 0, VCPU }, 418 { "set-mem", REQ_ARG, 0, SET_MEM }, 419 { "set-efer", REQ_ARG, 0, SET_EFER }, 420 { "set-cr0", REQ_ARG, 0, SET_CR0 }, 421 { "set-cr3", REQ_ARG, 0, SET_CR3 }, 422 { "set-cr4", REQ_ARG, 0, SET_CR4 }, 423 { "set-dr7", REQ_ARG, 0, SET_DR7 }, 424 { "set-rsp", REQ_ARG, 0, SET_RSP }, 425 { "set-rip", REQ_ARG, 0, SET_RIP }, 426 { "set-rax", REQ_ARG, 0, SET_RAX }, 427 { "set-rflags", REQ_ARG, 0, SET_RFLAGS }, 428 { "desc-base", REQ_ARG, 0, DESC_BASE }, 429 { "desc-limit", REQ_ARG, 0, DESC_LIMIT }, 430 { "desc-access",REQ_ARG, 0, DESC_ACCESS }, 431 { "set-cs", REQ_ARG, 0, SET_CS }, 432 { "set-ds", REQ_ARG, 0, SET_DS }, 433 { "set-es", REQ_ARG, 0, SET_ES }, 434 { "set-fs", REQ_ARG, 0, SET_FS }, 435 { "set-gs", REQ_ARG, 0, SET_GS }, 436 { "set-ss", REQ_ARG, 0, SET_SS }, 437 { "set-tr", REQ_ARG, 0, SET_TR }, 438 { "set-ldtr", REQ_ARG, 0, SET_LDTR }, 439 { "set-x2apic-state",REQ_ARG, 0, SET_X2APIC_STATE }, 440 { "set-vmcs-exception-bitmap", 441 REQ_ARG, 0, SET_VMCS_EXCEPTION_BITMAP }, 442 { "set-vmcs-entry-interruption-info", 443 REQ_ARG, 0, SET_VMCS_ENTRY_INTERRUPTION_INFO }, 444 { "capname", REQ_ARG, 0, CAPNAME }, 445 { "unassign-pptdev", REQ_ARG, 0, UNASSIGN_PPTDEV }, 446 { "setcap", REQ_ARG, 0, SET_CAP }, 447 { "getcap", NO_ARG, &getcap, 1 }, 448 { "get-stats", NO_ARG, &get_stats, 1 }, 449 { "get-desc-ds",NO_ARG, &get_desc_ds, 1 }, 450 { "set-desc-ds",NO_ARG, &set_desc_ds, 1 }, 451 { "get-desc-es",NO_ARG, &get_desc_es, 1 }, 452 { "set-desc-es",NO_ARG, &set_desc_es, 1 }, 453 { "get-desc-ss",NO_ARG, &get_desc_ss, 1 }, 454 { "set-desc-ss",NO_ARG, &set_desc_ss, 1 }, 455 { "get-desc-cs",NO_ARG, &get_desc_cs, 1 }, 456 { "set-desc-cs",NO_ARG, &set_desc_cs, 1 }, 457 { "get-desc-fs",NO_ARG, &get_desc_fs, 1 }, 458 { "set-desc-fs",NO_ARG, &set_desc_fs, 1 }, 459 { "get-desc-gs",NO_ARG, &get_desc_gs, 1 }, 460 { "set-desc-gs",NO_ARG, &set_desc_gs, 1 }, 461 { "get-desc-tr",NO_ARG, &get_desc_tr, 1 }, 462 { "set-desc-tr",NO_ARG, &set_desc_tr, 1 }, 463 { "set-desc-ldtr", NO_ARG, &set_desc_ldtr, 1 }, 464 { "get-desc-ldtr", NO_ARG, &get_desc_ldtr, 1 }, 465 { "set-desc-gdtr", NO_ARG, &set_desc_gdtr, 1 }, 466 { "get-desc-gdtr", NO_ARG, &get_desc_gdtr, 1 }, 467 { "set-desc-idtr", NO_ARG, &set_desc_idtr, 1 }, 468 { "get-desc-idtr", NO_ARG, &get_desc_idtr, 1 }, 469 { "get-lowmem", NO_ARG, &get_lowmem, 1 }, 470 { "get-highmem",NO_ARG, &get_highmem, 1 }, 471 { "get-efer", NO_ARG, &get_efer, 1 }, 472 { "get-cr0", NO_ARG, &get_cr0, 1 }, 473 { "get-cr3", NO_ARG, &get_cr3, 1 }, 474 { "get-cr4", NO_ARG, &get_cr4, 1 }, 475 { "get-dr7", NO_ARG, &get_dr7, 1 }, 476 { "get-rsp", NO_ARG, &get_rsp, 1 }, 477 { "get-rip", NO_ARG, &get_rip, 1 }, 478 { "get-rax", NO_ARG, &get_rax, 1 }, 479 { "get-rbx", NO_ARG, &get_rbx, 1 }, 480 { "get-rcx", NO_ARG, &get_rcx, 1 }, 481 { "get-rdx", NO_ARG, &get_rdx, 1 }, 482 { "get-rsi", NO_ARG, &get_rsi, 1 }, 483 { "get-rdi", NO_ARG, &get_rdi, 1 }, 484 { "get-rbp", NO_ARG, &get_rbp, 1 }, 485 { "get-r8", NO_ARG, &get_r8, 1 }, 486 { "get-r9", NO_ARG, &get_r9, 1 }, 487 { "get-r10", NO_ARG, &get_r10, 1 }, 488 { "get-r11", NO_ARG, &get_r11, 1 }, 489 { "get-r12", NO_ARG, &get_r12, 1 }, 490 { "get-r13", NO_ARG, &get_r13, 1 }, 491 { "get-r14", NO_ARG, &get_r14, 1 }, 492 { "get-r15", NO_ARG, &get_r15, 1 }, 493 { "get-rflags", NO_ARG, &get_rflags, 1 }, 494 { "get-cs", NO_ARG, &get_cs, 1 }, 495 { "get-ds", NO_ARG, &get_ds, 1 }, 496 { "get-es", NO_ARG, &get_es, 1 }, 497 { "get-fs", NO_ARG, &get_fs, 1 }, 498 { "get-gs", NO_ARG, &get_gs, 1 }, 499 { "get-ss", NO_ARG, &get_ss, 1 }, 500 { "get-tr", NO_ARG, &get_tr, 1 }, 501 { "get-ldtr", NO_ARG, &get_ldtr, 1 }, 502 { "get-vmcs-pinbased-ctls", 503 NO_ARG, &get_pinbased_ctls, 1 }, 504 { "get-vmcs-procbased-ctls", 505 NO_ARG, &get_procbased_ctls, 1 }, 506 { "get-vmcs-procbased-ctls2", 507 NO_ARG, &get_procbased_ctls2, 1 }, 508 { "get-vmcs-guest-linear-address", 509 NO_ARG, &get_vmcs_gla, 1 }, 510 { "get-vmcs-guest-physical-address", 511 NO_ARG, &get_vmcs_gpa, 1 }, 512 { "get-vmcs-entry-interruption-info", 513 NO_ARG, &get_vmcs_entry_interruption_info, 1}, 514 { "get-vmcs-eptp", NO_ARG, &get_eptp, 1 }, 515 { "get-vmcs-exception-bitmap", 516 NO_ARG, &get_exception_bitmap, 1 }, 517 { "get-vmcs-io-bitmap-address", 518 NO_ARG, &get_io_bitmap, 1 }, 519 { "get-vmcs-tsc-offset", NO_ARG,&get_tsc_offset, 1 }, 520 { "get-vmcs-cr0-mask", NO_ARG, &get_cr0_mask, 1 }, 521 { "get-vmcs-cr0-shadow", NO_ARG,&get_cr0_shadow, 1 }, 522 { "get-vmcs-cr4-mask", NO_ARG, &get_cr4_mask, 1 }, 523 { "get-vmcs-cr4-shadow", NO_ARG,&get_cr4_shadow, 1 }, 524 { "get-vmcs-cr3-targets", NO_ARG, &get_cr3_targets, 1}, 525 { "get-vmcs-apic-access-address", 526 NO_ARG, &get_apic_access_addr, 1}, 527 { "get-vmcs-virtual-apic-address", 528 NO_ARG, &get_virtual_apic_addr, 1}, 529 { "get-vmcs-tpr-threshold", 530 NO_ARG, &get_tpr_threshold, 1 }, 531 { "get-vmcs-msr-bitmap", 532 NO_ARG, &get_msr_bitmap, 1 }, 533 { "get-vmcs-msr-bitmap-address", 534 NO_ARG, &get_msr_bitmap_address, 1 }, 535 { "get-vmcs-vpid", NO_ARG, &get_vpid, 1 }, 536 { "get-vmcs-ple-gap", NO_ARG, &get_ple_gap, 1 }, 537 { "get-vmcs-ple-window", NO_ARG,&get_ple_window,1 }, 538 { "get-vmcs-instruction-error", 539 NO_ARG, &get_inst_err, 1 }, 540 { "get-vmcs-exit-ctls", NO_ARG, &get_exit_ctls, 1 }, 541 { "get-vmcs-entry-ctls", 542 NO_ARG, &get_entry_ctls, 1 }, 543 { "get-vmcs-guest-pat", NO_ARG, &get_guest_pat, 1 }, 544 { "get-vmcs-host-pat", NO_ARG, &get_host_pat, 1 }, 545 { "get-vmcs-host-cr0", 546 NO_ARG, &get_host_cr0, 1 }, 547 { "get-vmcs-host-cr3", 548 NO_ARG, &get_host_cr3, 1 }, 549 { "get-vmcs-host-cr4", 550 NO_ARG, &get_host_cr4, 1 }, 551 { "get-vmcs-host-rip", 552 NO_ARG, &get_host_rip, 1 }, 553 { "get-vmcs-host-rsp", 554 NO_ARG, &get_host_rsp, 1 }, 555 { "get-vmcs-guest-sysenter", 556 NO_ARG, &get_guest_sysenter, 1 }, 557 { "get-vmcs-link", NO_ARG, &get_vmcs_link, 1 }, 558 { "get-vmcs-exit-reason", 559 NO_ARG, &get_vmcs_exit_reason, 1 }, 560 { "get-vmcs-exit-qualification", 561 NO_ARG, &get_vmcs_exit_qualification, 1 }, 562 { "get-vmcs-exit-interruption-info", 563 NO_ARG, &get_vmcs_exit_interruption_info, 1}, 564 { "get-vmcs-exit-interruption-error", 565 NO_ARG, &get_vmcs_exit_interruption_error, 1}, 566 { "get-vmcs-interruptibility", 567 NO_ARG, &get_vmcs_interruptibility, 1 }, 568 { "get-x2apic-state",NO_ARG, &get_x2apic_state, 1 }, 569 { "get-all", NO_ARG, &get_all, 1 }, 570 { "run", NO_ARG, &run, 1 }, 571 { "create", NO_ARG, &create, 1 }, 572 { "destroy", NO_ARG, &destroy, 1 }, 573 { NULL, 0, NULL, 0 } 574 }; | 637static void 638print_intinfo(const char *banner, uint64_t info) 639{ 640 int type; |
575 | 641 |
576 vcpu = 0; 577 progname = basename(argv[0]); 578 579 while ((ch = getopt_long(argc, argv, "", opts, NULL)) != -1) { 580 switch (ch) { 581 case 0: | 642 printf("%s:\t", banner); 643 if (info & VM_INTINFO_VALID) { 644 type = info & VM_INTINFO_TYPE; 645 switch (type) { 646 case VM_INTINFO_HWINTR: 647 printf("extint"); |
582 break; | 648 break; |
583 case VMNAME: 584 vmname = optarg; | 649 case VM_INTINFO_NMI: 650 printf("nmi"); |
585 break; | 651 break; |
586 case VCPU: 587 vcpu = atoi(optarg); | 652 case VM_INTINFO_SWINTR: 653 printf("swint"); |
588 break; | 654 break; |
589 case SET_MEM: 590 memsize = atoi(optarg) * MB; 591 memsize = roundup(memsize, 2 * MB); 592 break; 593 case SET_EFER: 594 efer = strtoul(optarg, NULL, 0); 595 set_efer = 1; 596 break; 597 case SET_CR0: 598 cr0 = strtoul(optarg, NULL, 0); 599 set_cr0 = 1; 600 break; 601 case SET_CR3: 602 cr3 = strtoul(optarg, NULL, 0); 603 set_cr3 = 1; 604 break; 605 case SET_CR4: 606 cr4 = strtoul(optarg, NULL, 0); 607 set_cr4 = 1; 608 break; 609 case SET_DR7: 610 dr7 = strtoul(optarg, NULL, 0); 611 set_dr7 = 1; 612 break; 613 case SET_RSP: 614 rsp = strtoul(optarg, NULL, 0); 615 set_rsp = 1; 616 break; 617 case SET_RIP: 618 rip = strtoul(optarg, NULL, 0); 619 set_rip = 1; 620 break; 621 case SET_RAX: 622 rax = strtoul(optarg, NULL, 0); 623 set_rax = 1; 624 break; 625 case SET_RFLAGS: 626 rflags = strtoul(optarg, NULL, 0); 627 set_rflags = 1; 628 break; 629 case DESC_BASE: 630 desc_base = strtoul(optarg, NULL, 0); 631 break; 632 case DESC_LIMIT: 633 desc_limit = strtoul(optarg, NULL, 0); 634 break; 635 case DESC_ACCESS: 636 desc_access = strtoul(optarg, NULL, 0); 637 break; 638 case SET_CS: 639 cs = strtoul(optarg, NULL, 0); 640 set_cs = 1; 641 break; 642 case SET_DS: 643 ds = strtoul(optarg, NULL, 0); 644 set_ds = 1; 645 break; 646 case SET_ES: 647 es = strtoul(optarg, NULL, 0); 648 set_es = 1; 649 break; 650 case SET_FS: 651 fs = strtoul(optarg, NULL, 0); 652 set_fs = 1; 653 break; 654 case SET_GS: 655 gs = strtoul(optarg, NULL, 0); 656 set_gs = 1; 657 break; 658 case SET_SS: 659 ss = strtoul(optarg, NULL, 0); 660 set_ss = 1; 661 break; 662 case SET_TR: 663 tr = strtoul(optarg, NULL, 0); 664 set_tr = 1; 665 break; 666 case SET_LDTR: 667 ldtr = strtoul(optarg, NULL, 0); 668 set_ldtr = 1; 669 break; 670 case SET_X2APIC_STATE: 671 x2apic_state = strtol(optarg, NULL, 0); 672 set_x2apic_state = 1; 673 break; 674 case SET_VMCS_EXCEPTION_BITMAP: 675 exception_bitmap = strtoul(optarg, NULL, 0); 676 set_exception_bitmap = 1; 677 break; 678 case SET_VMCS_ENTRY_INTERRUPTION_INFO: 679 vmcs_entry_interruption_info = strtoul(optarg, NULL, 0); 680 set_vmcs_entry_interruption_info = 1; 681 break; 682 case SET_CAP: 683 capval = strtoul(optarg, NULL, 0); 684 setcap = 1; 685 break; 686 case CAPNAME: 687 capname = optarg; 688 break; 689 case UNASSIGN_PPTDEV: 690 unassign_pptdev = 1; 691 if (sscanf(optarg, "%d/%d/%d", &bus, &slot, &func) != 3) 692 usage(); 693 break; | |
694 default: | 655 default: |
695 usage(); | 656 printf("exception"); 657 break; |
696 } | 658 } |
659 printf(" vector %d", (int)VM_INTINFO_VECTOR(info)); 660 if (info & VM_INTINFO_DEL_ERRCODE) 661 printf(" errcode %#x", (u_int)(info >> 32)); 662 } else { 663 printf("n/a"); |
|
697 } | 664 } |
698 argc -= optind; 699 argv += optind; | 665 printf("\n"); 666} |
700 | 667 |
701 if (vmname == NULL) 702 usage(); | 668static bool 669cpu_vendor_intel(void) 670{ 671 u_int regs[4]; 672 char cpu_vendor[13]; |
703 | 673 |
704 error = 0; | 674 do_cpuid(0, regs); 675 ((u_int *)&cpu_vendor)[0] = regs[1]; 676 ((u_int *)&cpu_vendor)[1] = regs[3]; 677 ((u_int *)&cpu_vendor)[2] = regs[2]; 678 cpu_vendor[12] = '\0'; |
705 | 679 |
706 if (!error && create) 707 error = vm_create(vmname); 708 709 if (!error) { 710 ctx = vm_open(vmname); 711 if (ctx == NULL) 712 error = -1; | 680 if (strcmp(cpu_vendor, "AuthenticAMD") == 0) { 681 return (false); 682 } else if (strcmp(cpu_vendor, "GenuineIntel") == 0) { 683 return (true); 684 } else { 685 fprintf(stderr, "Unknown cpu vendor \"%s\"\n", cpu_vendor); 686 exit(1); |
713 } | 687 } |
688} |
|
714 | 689 |
715 if (!error && memsize) 716 error = vm_setup_memory(ctx, memsize, VM_MMAP_NONE); | 690static int 691get_all_registers(struct vmctx *ctx, int vcpu) 692{ 693 uint64_t cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7; 694 uint64_t rsp, rip, rflags, efer; 695 uint64_t rax, rbx, rcx, rdx, rsi, rdi, rbp; 696 uint64_t r8, r9, r10, r11, r12, r13, r14, r15; 697 int error = 0; |
717 | 698 |
718 if (!error && set_efer) 719 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_EFER, efer); 720 721 if (!error && set_cr0) 722 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR0, cr0); 723 724 if (!error && set_cr3) 725 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR3, cr3); 726 727 if (!error && set_cr4) 728 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR4, cr4); 729 730 if (!error && set_dr7) 731 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DR7, dr7); 732 733 if (!error && set_rsp) 734 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RSP, rsp); 735 736 if (!error && set_rip) 737 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RIP, rip); 738 739 if (!error && set_rax) 740 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, rax); 741 742 if (!error && set_rflags) { 743 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, 744 rflags); | 699 if (!error && (get_efer || get_all)) { 700 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_EFER, &efer); 701 if (error == 0) 702 printf("efer[%d]\t\t0x%016lx\n", vcpu, efer); |
745 } 746 | 703 } 704 |
747 if (!error && set_desc_ds) { 748 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_DS, 749 desc_base, desc_limit, desc_access); | 705 if (!error && (get_cr0 || get_all)) { 706 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR0, &cr0); 707 if (error == 0) 708 printf("cr0[%d]\t\t0x%016lx\n", vcpu, cr0); |
750 } 751 | 709 } 710 |
752 if (!error && set_desc_es) { 753 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_ES, 754 desc_base, desc_limit, desc_access); | 711 if (!error && (get_cr2 || get_all)) { 712 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR2, &cr2); 713 if (error == 0) 714 printf("cr2[%d]\t\t0x%016lx\n", vcpu, cr2); |
755 } 756 | 715 } 716 |
757 if (!error && set_desc_ss) { 758 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_SS, 759 desc_base, desc_limit, desc_access); | 717 if (!error && (get_cr3 || get_all)) { 718 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR3, &cr3); 719 if (error == 0) 720 printf("cr3[%d]\t\t0x%016lx\n", vcpu, cr3); |
760 } 761 | 721 } 722 |
762 if (!error && set_desc_cs) { 763 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_CS, 764 desc_base, desc_limit, desc_access); 765 } 766 767 if (!error && set_desc_fs) { 768 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_FS, 769 desc_base, desc_limit, desc_access); 770 } 771 772 if (!error && set_desc_gs) { 773 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_GS, 774 desc_base, desc_limit, desc_access); 775 } 776 777 if (!error && set_desc_tr) { 778 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_TR, 779 desc_base, desc_limit, desc_access); 780 } 781 782 if (!error && set_desc_ldtr) { 783 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_LDTR, 784 desc_base, desc_limit, desc_access); 785 } 786 787 if (!error && set_desc_gdtr) { 788 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_GDTR, 789 desc_base, desc_limit, 0); 790 } 791 792 if (!error && set_desc_idtr) { 793 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_IDTR, 794 desc_base, desc_limit, 0); 795 } 796 797 if (!error && set_cs) 798 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CS, cs); 799 800 if (!error && set_ds) 801 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DS, ds); 802 803 if (!error && set_es) 804 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_ES, es); 805 806 if (!error && set_fs) 807 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_FS, fs); 808 809 if (!error && set_gs) 810 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_GS, gs); 811 812 if (!error && set_ss) 813 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_SS, ss); 814 815 if (!error && set_tr) 816 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_TR, tr); 817 818 if (!error && set_ldtr) 819 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_LDTR, ldtr); 820 821 if (!error && set_x2apic_state) 822 error = vm_set_x2apic_state(ctx, vcpu, x2apic_state); 823 824#ifdef __FreeBSD__ 825 if (!error && unassign_pptdev) 826 error = vm_unassign_pptdev(ctx, bus, slot, func); 827#endif 828 829 if (!error && set_exception_bitmap) { 830 error = vm_set_vmcs_field(ctx, vcpu, VMCS_EXCEPTION_BITMAP, 831 exception_bitmap); 832 } 833 834 if (!error && set_vmcs_entry_interruption_info) { 835 error = vm_set_vmcs_field(ctx, vcpu, VMCS_ENTRY_INTR_INFO, 836 vmcs_entry_interruption_info); 837 } 838 839 if (!error && (get_lowmem || get_all)) { 840 gpa = 0; 841 error = vm_get_memory_seg(ctx, gpa, &len, &wired); | 723 if (!error && (get_cr4 || get_all)) { 724 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR4, &cr4); |
842 if (error == 0) | 725 if (error == 0) |
843 printf("lowmem\t\t0x%016lx/%ld%s\n", gpa, len, 844 wired ? " wired" : ""); | 726 printf("cr4[%d]\t\t0x%016lx\n", vcpu, cr4); |
845 } 846 | 727 } 728 |
847 if (!error && (get_highmem || get_all)) { 848 gpa = 4 * GB; 849 error = vm_get_memory_seg(ctx, gpa, &len, &wired); | 729 if (!error && (get_dr0 || get_all)) { 730 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DR0, &dr0); |
850 if (error == 0) | 731 if (error == 0) |
851 printf("highmem\t\t0x%016lx/%ld%s\n", gpa, len, 852 wired ? " wired" : ""); | 732 printf("dr0[%d]\t\t0x%016lx\n", vcpu, dr0); |
853 } 854 | 733 } 734 |
855 if (!error && (get_efer || get_all)) { 856 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_EFER, &efer); | 735 if (!error && (get_dr1 || get_all)) { 736 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DR1, &dr1); |
857 if (error == 0) | 737 if (error == 0) |
858 printf("efer[%d]\t\t0x%016lx\n", vcpu, efer); | 738 printf("dr1[%d]\t\t0x%016lx\n", vcpu, dr1); |
859 } 860 | 739 } 740 |
861 if (!error && (get_cr0 || get_all)) { 862 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR0, &cr0); | 741 if (!error && (get_dr2 || get_all)) { 742 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DR2, &dr2); |
863 if (error == 0) | 743 if (error == 0) |
864 printf("cr0[%d]\t\t0x%016lx\n", vcpu, cr0); | 744 printf("dr2[%d]\t\t0x%016lx\n", vcpu, dr2); |
865 } 866 | 745 } 746 |
867 if (!error && (get_cr3 || get_all)) { 868 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR3, &cr3); | 747 if (!error && (get_dr3 || get_all)) { 748 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DR3, &dr3); |
869 if (error == 0) | 749 if (error == 0) |
870 printf("cr3[%d]\t\t0x%016lx\n", vcpu, cr3); | 750 printf("dr3[%d]\t\t0x%016lx\n", vcpu, dr3); |
871 } 872 | 751 } 752 |
873 if (!error && (get_cr4 || get_all)) { 874 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CR4, &cr4); | 753 if (!error && (get_dr6 || get_all)) { 754 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DR6, &dr6); |
875 if (error == 0) | 755 if (error == 0) |
876 printf("cr4[%d]\t\t0x%016lx\n", vcpu, cr4); | 756 printf("dr6[%d]\t\t0x%016lx\n", vcpu, dr6); |
877 } 878 879 if (!error && (get_dr7 || get_all)) { 880 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DR7, &dr7); 881 if (error == 0) 882 printf("dr7[%d]\t\t0x%016lx\n", vcpu, dr7); 883 } 884 --- 101 unchanged lines hidden (view full) --- 986 987 if (!error && (get_rflags || get_all)) { 988 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, 989 &rflags); 990 if (error == 0) 991 printf("rflags[%d]\t0x%016lx\n", vcpu, rflags); 992 } 993 | 757 } 758 759 if (!error && (get_dr7 || get_all)) { 760 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DR7, &dr7); 761 if (error == 0) 762 printf("dr7[%d]\t\t0x%016lx\n", vcpu, dr7); 763 } 764 --- 101 unchanged lines hidden (view full) --- 866 867 if (!error && (get_rflags || get_all)) { 868 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, 869 &rflags); 870 if (error == 0) 871 printf("rflags[%d]\t0x%016lx\n", vcpu, rflags); 872 } 873 |
994#ifdef __FreeBSD__ 995 if (!error && (get_stats || get_all)) { 996 int i, num_stats; 997 uint64_t *stats; 998 struct timeval tv; 999 const char *desc; | 874 return (error); 875} |
1000 | 876 |
1001 stats = vm_get_stats(ctx, vcpu, &tv, &num_stats); 1002 if (stats != NULL) { 1003 printf("vcpu%d\n", vcpu); 1004 for (i = 0; i < num_stats; i++) { 1005 desc = vm_get_stat_desc(ctx, i); 1006 printf("%-40s\t%ld\n", desc, stats[i]); 1007 } 1008 } 1009 } 1010#endif | 877static int 878get_all_segments(struct vmctx *ctx, int vcpu) 879{ 880 uint64_t cs, ds, es, fs, gs, ss, tr, ldtr; 881 int error = 0; |
1011 1012 if (!error && (get_desc_ds || get_all)) { 1013 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_DS, | 882 883 if (!error && (get_desc_ds || get_all)) { 884 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_DS, |
1014 &desc_base, &desc_limit, &desc_access); | 885 &desc_base, &desc_limit, &desc_access); |
1015 if (error == 0) { 1016 printf("ds desc[%d]\t0x%016lx/0x%08x/0x%08x\n", | 886 if (error == 0) { 887 printf("ds desc[%d]\t0x%016lx/0x%08x/0x%08x\n", |
1017 vcpu, desc_base, desc_limit, desc_access); | 888 vcpu, desc_base, desc_limit, desc_access); |
1018 } 1019 } 1020 1021 if (!error && (get_desc_es || get_all)) { 1022 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_ES, 1023 &desc_base, &desc_limit, &desc_access); 1024 if (error == 0) { 1025 printf("es desc[%d]\t0x%016lx/0x%08x/0x%08x\n", | 889 } 890 } 891 892 if (!error && (get_desc_es || get_all)) { 893 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_ES, 894 &desc_base, &desc_limit, &desc_access); 895 if (error == 0) { 896 printf("es desc[%d]\t0x%016lx/0x%08x/0x%08x\n", |
1026 vcpu, desc_base, desc_limit, desc_access); | 897 vcpu, desc_base, desc_limit, desc_access); |
1027 } 1028 } 1029 1030 if (!error && (get_desc_fs || get_all)) { 1031 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_FS, 1032 &desc_base, &desc_limit, &desc_access); 1033 if (error == 0) { 1034 printf("fs desc[%d]\t0x%016lx/0x%08x/0x%08x\n", | 898 } 899 } 900 901 if (!error && (get_desc_fs || get_all)) { 902 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_FS, 903 &desc_base, &desc_limit, &desc_access); 904 if (error == 0) { 905 printf("fs desc[%d]\t0x%016lx/0x%08x/0x%08x\n", |
1035 vcpu, desc_base, desc_limit, desc_access); | 906 vcpu, desc_base, desc_limit, desc_access); |
1036 } 1037 } 1038 1039 if (!error && (get_desc_gs || get_all)) { 1040 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_GS, 1041 &desc_base, &desc_limit, &desc_access); 1042 if (error == 0) { 1043 printf("gs desc[%d]\t0x%016lx/0x%08x/0x%08x\n", | 907 } 908 } 909 910 if (!error && (get_desc_gs || get_all)) { 911 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_GS, 912 &desc_base, &desc_limit, &desc_access); 913 if (error == 0) { 914 printf("gs desc[%d]\t0x%016lx/0x%08x/0x%08x\n", |
1044 vcpu, desc_base, desc_limit, desc_access); | 915 vcpu, desc_base, desc_limit, desc_access); |
1045 } 1046 } 1047 1048 if (!error && (get_desc_ss || get_all)) { 1049 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_SS, 1050 &desc_base, &desc_limit, &desc_access); 1051 if (error == 0) { 1052 printf("ss desc[%d]\t0x%016lx/0x%08x/0x%08x\n", | 916 } 917 } 918 919 if (!error && (get_desc_ss || get_all)) { 920 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_SS, 921 &desc_base, &desc_limit, &desc_access); 922 if (error == 0) { 923 printf("ss desc[%d]\t0x%016lx/0x%08x/0x%08x\n", |
1053 vcpu, desc_base, desc_limit, desc_access); | 924 vcpu, desc_base, desc_limit, desc_access); |
1054 } 1055 } 1056 1057 if (!error && (get_desc_cs || get_all)) { 1058 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_CS, 1059 &desc_base, &desc_limit, &desc_access); 1060 if (error == 0) { 1061 printf("cs desc[%d]\t0x%016lx/0x%08x/0x%08x\n", | 925 } 926 } 927 928 if (!error && (get_desc_cs || get_all)) { 929 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_CS, 930 &desc_base, &desc_limit, &desc_access); 931 if (error == 0) { 932 printf("cs desc[%d]\t0x%016lx/0x%08x/0x%08x\n", |
1062 vcpu, desc_base, desc_limit, desc_access); | 933 vcpu, desc_base, desc_limit, desc_access); |
1063 } 1064 } 1065 1066 if (!error && (get_desc_tr || get_all)) { 1067 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_TR, 1068 &desc_base, &desc_limit, &desc_access); 1069 if (error == 0) { 1070 printf("tr desc[%d]\t0x%016lx/0x%08x/0x%08x\n", | 934 } 935 } 936 937 if (!error && (get_desc_tr || get_all)) { 938 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_TR, 939 &desc_base, &desc_limit, &desc_access); 940 if (error == 0) { 941 printf("tr desc[%d]\t0x%016lx/0x%08x/0x%08x\n", |
1071 vcpu, desc_base, desc_limit, desc_access); | 942 vcpu, desc_base, desc_limit, desc_access); |
1072 } 1073 } 1074 1075 if (!error && (get_desc_ldtr || get_all)) { 1076 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_LDTR, 1077 &desc_base, &desc_limit, &desc_access); 1078 if (error == 0) { 1079 printf("ldtr desc[%d]\t0x%016lx/0x%08x/0x%08x\n", | 943 } 944 } 945 946 if (!error && (get_desc_ldtr || get_all)) { 947 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_LDTR, 948 &desc_base, &desc_limit, &desc_access); 949 if (error == 0) { 950 printf("ldtr desc[%d]\t0x%016lx/0x%08x/0x%08x\n", |
1080 vcpu, desc_base, desc_limit, desc_access); | 951 vcpu, desc_base, desc_limit, desc_access); |
1081 } 1082 } 1083 1084 if (!error && (get_desc_gdtr || get_all)) { 1085 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_GDTR, 1086 &desc_base, &desc_limit, &desc_access); 1087 if (error == 0) { 1088 printf("gdtr[%d]\t\t0x%016lx/0x%08x\n", | 952 } 953 } 954 955 if (!error && (get_desc_gdtr || get_all)) { 956 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_GDTR, 957 &desc_base, &desc_limit, &desc_access); 958 if (error == 0) { 959 printf("gdtr[%d]\t\t0x%016lx/0x%08x\n", |
1089 vcpu, desc_base, desc_limit); | 960 vcpu, desc_base, desc_limit); |
1090 } 1091 } 1092 1093 if (!error && (get_desc_idtr || get_all)) { 1094 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_IDTR, 1095 &desc_base, &desc_limit, &desc_access); 1096 if (error == 0) { 1097 printf("idtr[%d]\t\t0x%016lx/0x%08x\n", | 961 } 962 } 963 964 if (!error && (get_desc_idtr || get_all)) { 965 error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_IDTR, 966 &desc_base, &desc_limit, &desc_access); 967 if (error == 0) { 968 printf("idtr[%d]\t\t0x%016lx/0x%08x\n", |
1098 vcpu, desc_base, desc_limit); | 969 vcpu, desc_base, desc_limit); |
1099 } 1100 } 1101 1102 if (!error && (get_cs || get_all)) { 1103 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CS, &cs); 1104 if (error == 0) 1105 printf("cs[%d]\t\t0x%04lx\n", vcpu, cs); 1106 } --- 35 unchanged lines hidden (view full) --- 1142 } 1143 1144 if (!error && (get_ldtr || get_all)) { 1145 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_LDTR, &ldtr); 1146 if (error == 0) 1147 printf("ldtr[%d]\t\t0x%04lx\n", vcpu, ldtr); 1148 } 1149 | 970 } 971 } 972 973 if (!error && (get_cs || get_all)) { 974 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CS, &cs); 975 if (error == 0) 976 printf("cs[%d]\t\t0x%04lx\n", vcpu, cs); 977 } --- 35 unchanged lines hidden (view full) --- 1013 } 1014 1015 if (!error && (get_ldtr || get_all)) { 1016 error = vm_get_register(ctx, vcpu, VM_REG_GUEST_LDTR, &ldtr); 1017 if (error == 0) 1018 printf("ldtr[%d]\t\t0x%04lx\n", vcpu, ldtr); 1019 } 1020 |
1150 if (!error && (get_x2apic_state || get_all)) { 1151 error = vm_get_x2apic_state(ctx, vcpu, &x2apic_state); 1152 if (error == 0) 1153 printf("x2apic_state[%d]\t%d\n", vcpu, x2apic_state); 1154 } | 1021 return (error); 1022} |
1155 | 1023 |
1156 if (!error && (get_pinbased_ctls || get_all)) { 1157 error = vm_get_vmcs_field(ctx, vcpu, VMCS_PIN_BASED_CTLS, &ctl); 1158 if (error == 0) 1159 printf("pinbased_ctls[%d]\t0x%08lx\n", vcpu, ctl); 1160 } | 1024static int 1025get_misc_vmcs(struct vmctx *ctx, int vcpu) 1026{ 1027 uint64_t ctl, cr0, cr3, cr4, rsp, rip, pat, addr, u64; 1028 int error = 0; |
1161 | 1029 |
1162 if (!error && (get_procbased_ctls || get_all)) { 1163 error = vm_get_vmcs_field(ctx, vcpu, 1164 VMCS_PRI_PROC_BASED_CTLS, &ctl); 1165 if (error == 0) 1166 printf("procbased_ctls[%d]\t0x%08lx\n", vcpu, ctl); 1167 } 1168 1169 if (!error && (get_procbased_ctls2 || get_all)) { 1170 error = vm_get_vmcs_field(ctx, vcpu, 1171 VMCS_SEC_PROC_BASED_CTLS, &ctl); 1172 if (error == 0) 1173 printf("procbased_ctls2[%d]\t0x%08lx\n", vcpu, ctl); 1174 } 1175 1176 if (!error && (get_vmcs_gla || get_all)) { 1177 error = vm_get_vmcs_field(ctx, vcpu, 1178 VMCS_GUEST_LINEAR_ADDRESS, &u64); 1179 if (error == 0) 1180 printf("gla[%d]\t\t0x%016lx\n", vcpu, u64); 1181 } 1182 1183 if (!error && (get_vmcs_gpa || get_all)) { 1184 error = vm_get_vmcs_field(ctx, vcpu, 1185 VMCS_GUEST_PHYSICAL_ADDRESS, &u64); 1186 if (error == 0) 1187 printf("gpa[%d]\t\t0x%016lx\n", vcpu, u64); 1188 } 1189 1190 if (!error && (get_vmcs_entry_interruption_info || get_all)) { 1191 error = vm_get_vmcs_field(ctx, vcpu, VMCS_ENTRY_INTR_INFO,&u64); 1192 if (error == 0) { 1193 printf("entry_interruption_info[%d]\t0x%08lx\n", 1194 vcpu, u64); 1195 } 1196 } 1197 1198 if (!error && (get_eptp || get_all)) { 1199 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EPTP, &eptp); 1200 if (error == 0) 1201 printf("eptp[%d]\t\t0x%016lx\n", vcpu, eptp); 1202 } 1203 1204 if (!error && (get_exception_bitmap || get_all)) { 1205 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXCEPTION_BITMAP, 1206 &bm); 1207 if (error == 0) 1208 printf("exception_bitmap[%d]\t0x%08lx\n", vcpu, bm); 1209 } 1210 1211 if (!error && (get_io_bitmap || get_all)) { 1212 error = vm_get_vmcs_field(ctx, vcpu, VMCS_IO_BITMAP_A, &bm); 1213 if (error == 0) 1214 printf("io_bitmap_a[%d]\t0x%08lx\n", vcpu, bm); 1215 error = vm_get_vmcs_field(ctx, vcpu, VMCS_IO_BITMAP_B, &bm); 1216 if (error == 0) 1217 printf("io_bitmap_b[%d]\t0x%08lx\n", vcpu, bm); 1218 } 1219 1220 if (!error && (get_tsc_offset || get_all)) { 1221 uint64_t tscoff; 1222 error = vm_get_vmcs_field(ctx, vcpu, VMCS_TSC_OFFSET, &tscoff); 1223 if (error == 0) 1224 printf("tsc_offset[%d]\t0x%016lx\n", vcpu, tscoff); 1225 } 1226 | |
1227 if (!error && (get_cr0_mask || get_all)) { 1228 uint64_t cr0mask; 1229 error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR0_MASK, &cr0mask); 1230 if (error == 0) 1231 printf("cr0_mask[%d]\t\t0x%016lx\n", vcpu, cr0mask); 1232 } 1233 1234 if (!error && (get_cr0_shadow || get_all)) { --- 19 unchanged lines hidden (view full) --- 1254 printf("cr4_shadow[%d]\t\t0x%016lx\n", vcpu, cr4shadow); 1255 } 1256 1257 if (!error && (get_cr3_targets || get_all)) { 1258 uint64_t target_count, target_addr; 1259 error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR3_TARGET_COUNT, 1260 &target_count); 1261 if (error == 0) { | 1030 if (!error && (get_cr0_mask || get_all)) { 1031 uint64_t cr0mask; 1032 error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR0_MASK, &cr0mask); 1033 if (error == 0) 1034 printf("cr0_mask[%d]\t\t0x%016lx\n", vcpu, cr0mask); 1035 } 1036 1037 if (!error && (get_cr0_shadow || get_all)) { --- 19 unchanged lines hidden (view full) --- 1057 printf("cr4_shadow[%d]\t\t0x%016lx\n", vcpu, cr4shadow); 1058 } 1059 1060 if (!error && (get_cr3_targets || get_all)) { 1061 uint64_t target_count, target_addr; 1062 error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR3_TARGET_COUNT, 1063 &target_count); 1064 if (error == 0) { |
1262 printf("cr3_target_count[%d]\t0x%08lx\n", | 1065 printf("cr3_target_count[%d]\t0x%016lx\n", |
1263 vcpu, target_count); 1264 } 1265 1266 error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR3_TARGET0, 1267 &target_addr); 1268 if (error == 0) { 1269 printf("cr3_target0[%d]\t\t0x%016lx\n", 1270 vcpu, target_addr); --- 16 unchanged lines hidden (view full) --- 1287 error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR3_TARGET3, 1288 &target_addr); 1289 if (error == 0) { 1290 printf("cr3_target3[%d]\t\t0x%016lx\n", 1291 vcpu, target_addr); 1292 } 1293 } 1294 | 1066 vcpu, target_count); 1067 } 1068 1069 error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR3_TARGET0, 1070 &target_addr); 1071 if (error == 0) { 1072 printf("cr3_target0[%d]\t\t0x%016lx\n", 1073 vcpu, target_addr); --- 16 unchanged lines hidden (view full) --- 1090 error = vm_get_vmcs_field(ctx, vcpu, VMCS_CR3_TARGET3, 1091 &target_addr); 1092 if (error == 0) { 1093 printf("cr3_target3[%d]\t\t0x%016lx\n", 1094 vcpu, target_addr); 1095 } 1096 } 1097 |
1295 if (!error && (get_apic_access_addr || get_all)) { 1296 error = vm_get_vmcs_field(ctx, vcpu, VMCS_APIC_ACCESS, &addr); | 1098 if (!error && (get_pinbased_ctls || get_all)) { 1099 error = vm_get_vmcs_field(ctx, vcpu, VMCS_PIN_BASED_CTLS, &ctl); |
1297 if (error == 0) | 1100 if (error == 0) |
1298 printf("apic_access_addr[%d]\t0x%016lx\n", vcpu, addr); | 1101 printf("pinbased_ctls[%d]\t0x%016lx\n", vcpu, ctl); |
1299 } 1300 | 1102 } 1103 |
1301 if (!error && (get_virtual_apic_addr || get_all)) { 1302 error = vm_get_vmcs_field(ctx, vcpu, VMCS_VIRTUAL_APIC, &addr); | 1104 if (!error && (get_procbased_ctls || get_all)) { 1105 error = vm_get_vmcs_field(ctx, vcpu, 1106 VMCS_PRI_PROC_BASED_CTLS, &ctl); |
1303 if (error == 0) | 1107 if (error == 0) |
1304 printf("virtual_apic_addr[%d]\t0x%016lx\n", vcpu, addr); | 1108 printf("procbased_ctls[%d]\t0x%016lx\n", vcpu, ctl); |
1305 } 1306 | 1109 } 1110 |
1307 if (!error && (get_tpr_threshold || get_all)) { 1308 uint64_t threshold; 1309 error = vm_get_vmcs_field(ctx, vcpu, VMCS_TPR_THRESHOLD, 1310 &threshold); | 1111 if (!error && (get_procbased_ctls2 || get_all)) { 1112 error = vm_get_vmcs_field(ctx, vcpu, 1113 VMCS_SEC_PROC_BASED_CTLS, &ctl); |
1311 if (error == 0) | 1114 if (error == 0) |
1312 printf("tpr_threshold[%d]\t0x%08lx\n", vcpu, threshold); | 1115 printf("procbased_ctls2[%d]\t0x%016lx\n", vcpu, ctl); |
1313 } 1314 | 1116 } 1117 |
1315 if (!error && (get_msr_bitmap_address || get_all)) { 1316 error = vm_get_vmcs_field(ctx, vcpu, VMCS_MSR_BITMAP, &addr); | 1118 if (!error && (get_vmcs_gla || get_all)) { 1119 error = vm_get_vmcs_field(ctx, vcpu, 1120 VMCS_GUEST_LINEAR_ADDRESS, &u64); |
1317 if (error == 0) | 1121 if (error == 0) |
1318 printf("msr_bitmap[%d]\t\t0x%016lx\n", vcpu, addr); | 1122 printf("gla[%d]\t\t0x%016lx\n", vcpu, u64); |
1319 } 1320 | 1123 } 1124 |
1321 if (!error && (get_msr_bitmap || get_all)) { 1322 error = vm_get_vmcs_field(ctx, vcpu, VMCS_MSR_BITMAP, &addr); | 1125 if (!error && (get_vmcs_gpa || get_all)) { 1126 error = vm_get_vmcs_field(ctx, vcpu, 1127 VMCS_GUEST_PHYSICAL_ADDRESS, &u64); |
1323 if (error == 0) | 1128 if (error == 0) |
1324 error = dump_vmcs_msr_bitmap(vcpu, addr); | 1129 printf("gpa[%d]\t\t0x%016lx\n", vcpu, u64); |
1325 } 1326 | 1130 } 1131 |
1327 if (!error && (get_vpid || get_all)) { 1328 uint64_t vpid; 1329 error = vm_get_vmcs_field(ctx, vcpu, VMCS_VPID, &vpid); 1330 if (error == 0) 1331 printf("vpid[%d]\t\t0x%04lx\n", vcpu, vpid); | 1132 if (!error && (get_vmcs_entry_interruption_info || 1133 get_all)) { 1134 error = vm_get_vmcs_field(ctx, vcpu, VMCS_ENTRY_INTR_INFO,&u64); 1135 if (error == 0) { 1136 printf("entry_interruption_info[%d]\t0x%016lx\n", 1137 vcpu, u64); 1138 } |
1332 } | 1139 } |
1333 1334 if (!error && (get_ple_window || get_all)) { 1335 uint64_t window; 1336 error = vm_get_vmcs_field(ctx, vcpu, VMCS_PLE_WINDOW, &window); 1337 if (error == 0) 1338 printf("ple_window[%d]\t\t0x%08lx\n", vcpu, window); 1339 } | |
1340 | 1140 |
1341 if (!error && (get_ple_gap || get_all)) { 1342 uint64_t gap; 1343 error = vm_get_vmcs_field(ctx, vcpu, VMCS_PLE_GAP, &gap); | 1141 if (!error && (get_tpr_threshold || get_all)) { 1142 uint64_t threshold; 1143 error = vm_get_vmcs_field(ctx, vcpu, VMCS_TPR_THRESHOLD, 1144 &threshold); |
1344 if (error == 0) | 1145 if (error == 0) |
1345 printf("ple_gap[%d]\t\t0x%08lx\n", vcpu, gap); | 1146 printf("tpr_threshold[%d]\t0x%016lx\n", vcpu, threshold); |
1346 } 1347 1348 if (!error && (get_inst_err || get_all)) { 1349 uint64_t insterr; 1350 error = vm_get_vmcs_field(ctx, vcpu, VMCS_INSTRUCTION_ERROR, 1351 &insterr); 1352 if (error == 0) { | 1147 } 1148 1149 if (!error && (get_inst_err || get_all)) { 1150 uint64_t insterr; 1151 error = vm_get_vmcs_field(ctx, vcpu, VMCS_INSTRUCTION_ERROR, 1152 &insterr); 1153 if (error == 0) { |
1353 printf("instruction_error[%d]\t0x%08lx\n", | 1154 printf("instruction_error[%d]\t0x%016lx\n", |
1354 vcpu, insterr); 1355 } 1356 } 1357 1358 if (!error && (get_exit_ctls || get_all)) { 1359 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_CTLS, &ctl); 1360 if (error == 0) | 1155 vcpu, insterr); 1156 } 1157 } 1158 1159 if (!error && (get_exit_ctls || get_all)) { 1160 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_CTLS, &ctl); 1161 if (error == 0) |
1361 printf("exit_ctls[%d]\t\t0x%08lx\n", vcpu, ctl); | 1162 printf("exit_ctls[%d]\t\t0x%016lx\n", vcpu, ctl); |
1362 } 1363 1364 if (!error && (get_entry_ctls || get_all)) { 1365 error = vm_get_vmcs_field(ctx, vcpu, VMCS_ENTRY_CTLS, &ctl); 1366 if (error == 0) | 1163 } 1164 1165 if (!error && (get_entry_ctls || get_all)) { 1166 error = vm_get_vmcs_field(ctx, vcpu, VMCS_ENTRY_CTLS, &ctl); 1167 if (error == 0) |
1367 printf("entry_ctls[%d]\t\t0x%08lx\n", vcpu, ctl); | 1168 printf("entry_ctls[%d]\t\t0x%016lx\n", vcpu, ctl); |
1368 } 1369 1370 if (!error && (get_host_pat || get_all)) { 1371 error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_IA32_PAT, &pat); 1372 if (error == 0) 1373 printf("host_pat[%d]\t\t0x%016lx\n", vcpu, pat); 1374 } 1375 | 1169 } 1170 1171 if (!error && (get_host_pat || get_all)) { 1172 error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_IA32_PAT, &pat); 1173 if (error == 0) 1174 printf("host_pat[%d]\t\t0x%016lx\n", vcpu, pat); 1175 } 1176 |
1376 if (!error && (get_guest_pat || get_all)) { 1377 error = vm_get_vmcs_field(ctx, vcpu, VMCS_GUEST_IA32_PAT, &pat); 1378 if (error == 0) 1379 printf("guest_pat[%d]\t\t0x%016lx\n", vcpu, pat); 1380 } 1381 | |
1382 if (!error && (get_host_cr0 || get_all)) { 1383 error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_CR0, &cr0); 1384 if (error == 0) 1385 printf("host_cr0[%d]\t\t0x%016lx\n", vcpu, cr0); 1386 } 1387 1388 if (!error && (get_host_cr3 || get_all)) { 1389 error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_CR3, &cr3); --- 14 unchanged lines hidden (view full) --- 1404 } 1405 1406 if (!error && (get_host_rsp || get_all)) { 1407 error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_RSP, &rsp); 1408 if (error == 0) 1409 printf("host_rsp[%d]\t\t0x%016lx\n", vcpu, rsp); 1410 } 1411 | 1177 if (!error && (get_host_cr0 || get_all)) { 1178 error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_CR0, &cr0); 1179 if (error == 0) 1180 printf("host_cr0[%d]\t\t0x%016lx\n", vcpu, cr0); 1181 } 1182 1183 if (!error && (get_host_cr3 || get_all)) { 1184 error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_CR3, &cr3); --- 14 unchanged lines hidden (view full) --- 1199 } 1200 1201 if (!error && (get_host_rsp || get_all)) { 1202 error = vm_get_vmcs_field(ctx, vcpu, VMCS_HOST_RSP, &rsp); 1203 if (error == 0) 1204 printf("host_rsp[%d]\t\t0x%016lx\n", vcpu, rsp); 1205 } 1206 |
1412 if (!error && (get_guest_sysenter || get_all)) { 1413 error = vm_get_vmcs_field(ctx, vcpu, 1414 VMCS_GUEST_IA32_SYSENTER_CS, &cs); 1415 if (error == 0) 1416 printf("guest_sysenter_cs[%d]\t0x%08lx\n", vcpu, cs); 1417 1418 error = vm_get_vmcs_field(ctx, vcpu, 1419 VMCS_GUEST_IA32_SYSENTER_ESP, &rsp); 1420 if (error == 0) 1421 printf("guest_sysenter_sp[%d]\t0x%016lx\n", vcpu, rsp); 1422 error = vm_get_vmcs_field(ctx, vcpu, 1423 VMCS_GUEST_IA32_SYSENTER_EIP, &rip); 1424 if (error == 0) 1425 printf("guest_sysenter_ip[%d]\t0x%016lx\n", vcpu, rip); 1426 } 1427 | |
1428 if (!error && (get_vmcs_link || get_all)) { 1429 error = vm_get_vmcs_field(ctx, vcpu, VMCS_LINK_POINTER, &addr); 1430 if (error == 0) 1431 printf("vmcs_pointer[%d]\t0x%016lx\n", vcpu, addr); 1432 } 1433 | 1207 if (!error && (get_vmcs_link || get_all)) { 1208 error = vm_get_vmcs_field(ctx, vcpu, VMCS_LINK_POINTER, &addr); 1209 if (error == 0) 1210 printf("vmcs_pointer[%d]\t0x%016lx\n", vcpu, addr); 1211 } 1212 |
1434 if (!error && (get_vmcs_exit_reason || get_all)) { 1435 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_REASON, &u64); 1436 if (error == 0) 1437 printf("vmcs_exit_reason[%d]\t0x%016lx\n", vcpu, u64); 1438 } 1439 1440 if (!error && (get_vmcs_exit_qualification || get_all)) { 1441 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_QUALIFICATION, 1442 &u64); 1443 if (error == 0) 1444 printf("vmcs_exit_qualification[%d]\t0x%016lx\n", 1445 vcpu, u64); 1446 } 1447 | |
1448 if (!error && (get_vmcs_exit_interruption_info || get_all)) { 1449 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_INTR_INFO, &u64); 1450 if (error == 0) { | 1213 if (!error && (get_vmcs_exit_interruption_info || get_all)) { 1214 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_INTR_INFO, &u64); 1215 if (error == 0) { |
1451 printf("vmcs_exit_interruption_info[%d]\t0x%08lx\n", | 1216 printf("vmcs_exit_interruption_info[%d]\t0x%016lx\n", |
1452 vcpu, u64); 1453 } 1454 } 1455 1456 if (!error && (get_vmcs_exit_interruption_error || get_all)) { 1457 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_INTR_ERRCODE, | 1217 vcpu, u64); 1218 } 1219 } 1220 1221 if (!error && (get_vmcs_exit_interruption_error || get_all)) { 1222 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_INTR_ERRCODE, |
1458 &u64); | 1223 &u64); |
1459 if (error == 0) { | 1224 if (error == 0) { |
1460 printf("vmcs_exit_interruption_error[%d]\t0x%08lx\n", | 1225 printf("vmcs_exit_interruption_error[%d]\t0x%016lx\n", |
1461 vcpu, u64); 1462 } 1463 } 1464 1465 if (!error && (get_vmcs_interruptibility || get_all)) { 1466 error = vm_get_vmcs_field(ctx, vcpu, 1467 VMCS_GUEST_INTERRUPTIBILITY, &u64); 1468 if (error == 0) { | 1226 vcpu, u64); 1227 } 1228 } 1229 1230 if (!error && (get_vmcs_interruptibility || get_all)) { 1231 error = vm_get_vmcs_field(ctx, vcpu, 1232 VMCS_GUEST_INTERRUPTIBILITY, &u64); 1233 if (error == 0) { |
1469 printf("vmcs_guest_interruptibility[%d]\t0x%08lx\n", | 1234 printf("vmcs_guest_interruptibility[%d]\t0x%016lx\n", |
1470 vcpu, u64); 1471 } 1472 } 1473 | 1235 vcpu, u64); 1236 } 1237 } 1238 |
1239 if (!error && (get_vmcs_exit_inst_length || get_all)) { 1240 error = vm_get_vmcs_field(ctx, vcpu, 1241 VMCS_EXIT_INSTRUCTION_LENGTH, &u64); 1242 if (error == 0) 1243 printf("vmcs_exit_inst_length[%d]\t0x%08x\n", vcpu, 1244 (uint32_t)u64); 1245 } 1246 1247 if (!error && (get_vmcs_exit_qualification || get_all)) { 1248 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_QUALIFICATION, 1249 &u64); 1250 if (error == 0) 1251 printf("vmcs_exit_qualification[%d]\t0x%016lx\n", 1252 vcpu, u64); 1253 } 1254 1255 return (error); 1256} 1257 1258static int 1259get_misc_vmcb(struct vmctx *ctx, int vcpu) 1260{ 1261 uint64_t ctl, addr; 1262 int error = 0; 1263 1264 if (!error && (get_vmcb_intercept || get_all)) { 1265 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_CR_INTERCEPT, 4, 1266 &ctl); 1267 if (error == 0) 1268 printf("cr_intercept[%d]\t0x%08x\n", vcpu, (int)ctl); 1269 1270 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_DR_INTERCEPT, 4, 1271 &ctl); 1272 if (error == 0) 1273 printf("dr_intercept[%d]\t0x%08x\n", vcpu, (int)ctl); 1274 1275 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_EXC_INTERCEPT, 4, 1276 &ctl); 1277 if (error == 0) 1278 printf("exc_intercept[%d]\t0x%08x\n", vcpu, (int)ctl); 1279 1280 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_INST1_INTERCEPT, 1281 4, &ctl); 1282 if (error == 0) 1283 printf("inst1_intercept[%d]\t0x%08x\n", vcpu, (int)ctl); 1284 1285 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_INST2_INTERCEPT, 1286 4, &ctl); 1287 if (error == 0) 1288 printf("inst2_intercept[%d]\t0x%08x\n", vcpu, (int)ctl); 1289 } 1290 1291 if (!error && (get_vmcb_tlb_ctrl || get_all)) { 1292 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_TLB_CTRL, 1293 4, &ctl); 1294 if (error == 0) 1295 printf("TLB ctrl[%d]\t0x%016lx\n", vcpu, ctl); 1296 } 1297 1298 if (!error && (get_vmcb_exit_details || get_all)) { 1299 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_EXITINFO1, 1300 8, &ctl); 1301 if (error == 0) 1302 printf("exitinfo1[%d]\t0x%016lx\n", vcpu, ctl); 1303 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_EXITINFO2, 1304 8, &ctl); 1305 if (error == 0) 1306 printf("exitinfo2[%d]\t0x%016lx\n", vcpu, ctl); 1307 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_EXITINTINFO, 1308 8, &ctl); 1309 if (error == 0) 1310 printf("exitintinfo[%d]\t0x%016lx\n", vcpu, ctl); 1311 } 1312 1313 if (!error && (get_vmcb_virq || get_all)) { 1314 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_VIRQ, 1315 8, &ctl); 1316 if (error == 0) 1317 printf("v_irq/tpr[%d]\t0x%016lx\n", vcpu, ctl); 1318 } 1319 1320 if (!error && (get_apic_access_addr || get_all)) { 1321 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_AVIC_BAR, 8, 1322 &addr); 1323 if (error == 0) 1324 printf("AVIC apic_bar[%d]\t0x%016lx\n", vcpu, addr); 1325 } 1326 1327 if (!error && (get_virtual_apic_addr || get_all)) { 1328 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_AVIC_PAGE, 8, 1329 &addr); 1330 if (error == 0) 1331 printf("AVIC backing page[%d]\t0x%016lx\n", vcpu, addr); 1332 } 1333 1334 if (!error && (get_avic_table || get_all)) { 1335 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_AVIC_LT, 8, 1336 &addr); 1337 if (error == 0) 1338 printf("AVIC logical table[%d]\t0x%016lx\n", 1339 vcpu, addr); 1340 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_AVIC_PT, 8, 1341 &addr); 1342 if (error == 0) 1343 printf("AVIC physical table[%d]\t0x%016lx\n", 1344 vcpu, addr); 1345 } 1346 1347 return (error); 1348} 1349 1350static struct option * 1351setup_options(bool cpu_intel) 1352{ 1353 const struct option common_opts[] = { 1354 { "vm", REQ_ARG, 0, VMNAME }, 1355 { "cpu", REQ_ARG, 0, VCPU }, 1356 { "set-mem", REQ_ARG, 0, SET_MEM }, 1357 { "set-efer", REQ_ARG, 0, SET_EFER }, 1358 { "set-cr0", REQ_ARG, 0, SET_CR0 }, 1359 { "set-cr2", REQ_ARG, 0, SET_CR2 }, 1360 { "set-cr3", REQ_ARG, 0, SET_CR3 }, 1361 { "set-cr4", REQ_ARG, 0, SET_CR4 }, 1362 { "set-dr0", REQ_ARG, 0, SET_DR0 }, 1363 { "set-dr1", REQ_ARG, 0, SET_DR1 }, 1364 { "set-dr2", REQ_ARG, 0, SET_DR2 }, 1365 { "set-dr3", REQ_ARG, 0, SET_DR3 }, 1366 { "set-dr6", REQ_ARG, 0, SET_DR6 }, 1367 { "set-dr7", REQ_ARG, 0, SET_DR7 }, 1368 { "set-rsp", REQ_ARG, 0, SET_RSP }, 1369 { "set-rip", REQ_ARG, 0, SET_RIP }, 1370 { "set-rax", REQ_ARG, 0, SET_RAX }, 1371 { "set-rflags", REQ_ARG, 0, SET_RFLAGS }, 1372 { "desc-base", REQ_ARG, 0, DESC_BASE }, 1373 { "desc-limit", REQ_ARG, 0, DESC_LIMIT }, 1374 { "desc-access",REQ_ARG, 0, DESC_ACCESS }, 1375 { "set-cs", REQ_ARG, 0, SET_CS }, 1376 { "set-ds", REQ_ARG, 0, SET_DS }, 1377 { "set-es", REQ_ARG, 0, SET_ES }, 1378 { "set-fs", REQ_ARG, 0, SET_FS }, 1379 { "set-gs", REQ_ARG, 0, SET_GS }, 1380 { "set-ss", REQ_ARG, 0, SET_SS }, 1381 { "set-tr", REQ_ARG, 0, SET_TR }, 1382 { "set-ldtr", REQ_ARG, 0, SET_LDTR }, 1383 { "set-x2apic-state",REQ_ARG, 0, SET_X2APIC_STATE }, 1384 { "set-exception-bitmap", 1385 REQ_ARG, 0, SET_EXCEPTION_BITMAP }, 1386 { "capname", REQ_ARG, 0, CAPNAME }, 1387 { "unassign-pptdev", REQ_ARG, 0, UNASSIGN_PPTDEV }, 1388 { "setcap", REQ_ARG, 0, SET_CAP }, 1389 { "get-gpa-pmap", REQ_ARG, 0, GET_GPA_PMAP }, 1390 { "assert-lapic-lvt", REQ_ARG, 0, ASSERT_LAPIC_LVT }, 1391 { "get-rtc-time", NO_ARG, &get_rtc_time, 1 }, 1392 { "set-rtc-time", REQ_ARG, 0, SET_RTC_TIME }, 1393 { "rtc-nvram-offset", REQ_ARG, 0, RTC_NVRAM_OFFSET }, 1394 { "get-rtc-nvram", NO_ARG, &get_rtc_nvram, 1 }, 1395 { "set-rtc-nvram", REQ_ARG, 0, SET_RTC_NVRAM }, 1396 { "getcap", NO_ARG, &getcap, 1 }, 1397 { "get-stats", NO_ARG, &get_stats, 1 }, 1398 { "get-desc-ds",NO_ARG, &get_desc_ds, 1 }, 1399 { "set-desc-ds",NO_ARG, &set_desc_ds, 1 }, 1400 { "get-desc-es",NO_ARG, &get_desc_es, 1 }, 1401 { "set-desc-es",NO_ARG, &set_desc_es, 1 }, 1402 { "get-desc-ss",NO_ARG, &get_desc_ss, 1 }, 1403 { "set-desc-ss",NO_ARG, &set_desc_ss, 1 }, 1404 { "get-desc-cs",NO_ARG, &get_desc_cs, 1 }, 1405 { "set-desc-cs",NO_ARG, &set_desc_cs, 1 }, 1406 { "get-desc-fs",NO_ARG, &get_desc_fs, 1 }, 1407 { "set-desc-fs",NO_ARG, &set_desc_fs, 1 }, 1408 { "get-desc-gs",NO_ARG, &get_desc_gs, 1 }, 1409 { "set-desc-gs",NO_ARG, &set_desc_gs, 1 }, 1410 { "get-desc-tr",NO_ARG, &get_desc_tr, 1 }, 1411 { "set-desc-tr",NO_ARG, &set_desc_tr, 1 }, 1412 { "set-desc-ldtr", NO_ARG, &set_desc_ldtr, 1 }, 1413 { "get-desc-ldtr", NO_ARG, &get_desc_ldtr, 1 }, 1414 { "set-desc-gdtr", NO_ARG, &set_desc_gdtr, 1 }, 1415 { "get-desc-gdtr", NO_ARG, &get_desc_gdtr, 1 }, 1416 { "set-desc-idtr", NO_ARG, &set_desc_idtr, 1 }, 1417 { "get-desc-idtr", NO_ARG, &get_desc_idtr, 1 }, 1418 { "get-memmap", NO_ARG, &get_memmap, 1 }, 1419 { "get-memseg", NO_ARG, &get_memseg, 1 }, 1420 { "get-efer", NO_ARG, &get_efer, 1 }, 1421 { "get-cr0", NO_ARG, &get_cr0, 1 }, 1422 { "get-cr2", NO_ARG, &get_cr2, 1 }, 1423 { "get-cr3", NO_ARG, &get_cr3, 1 }, 1424 { "get-cr4", NO_ARG, &get_cr4, 1 }, 1425 { "get-dr0", NO_ARG, &get_dr0, 1 }, 1426 { "get-dr1", NO_ARG, &get_dr1, 1 }, 1427 { "get-dr2", NO_ARG, &get_dr2, 1 }, 1428 { "get-dr3", NO_ARG, &get_dr3, 1 }, 1429 { "get-dr6", NO_ARG, &get_dr6, 1 }, 1430 { "get-dr7", NO_ARG, &get_dr7, 1 }, 1431 { "get-rsp", NO_ARG, &get_rsp, 1 }, 1432 { "get-rip", NO_ARG, &get_rip, 1 }, 1433 { "get-rax", NO_ARG, &get_rax, 1 }, 1434 { "get-rbx", NO_ARG, &get_rbx, 1 }, 1435 { "get-rcx", NO_ARG, &get_rcx, 1 }, 1436 { "get-rdx", NO_ARG, &get_rdx, 1 }, 1437 { "get-rsi", NO_ARG, &get_rsi, 1 }, 1438 { "get-rdi", NO_ARG, &get_rdi, 1 }, 1439 { "get-rbp", NO_ARG, &get_rbp, 1 }, 1440 { "get-r8", NO_ARG, &get_r8, 1 }, 1441 { "get-r9", NO_ARG, &get_r9, 1 }, 1442 { "get-r10", NO_ARG, &get_r10, 1 }, 1443 { "get-r11", NO_ARG, &get_r11, 1 }, 1444 { "get-r12", NO_ARG, &get_r12, 1 }, 1445 { "get-r13", NO_ARG, &get_r13, 1 }, 1446 { "get-r14", NO_ARG, &get_r14, 1 }, 1447 { "get-r15", NO_ARG, &get_r15, 1 }, 1448 { "get-rflags", NO_ARG, &get_rflags, 1 }, 1449 { "get-cs", NO_ARG, &get_cs, 1 }, 1450 { "get-ds", NO_ARG, &get_ds, 1 }, 1451 { "get-es", NO_ARG, &get_es, 1 }, 1452 { "get-fs", NO_ARG, &get_fs, 1 }, 1453 { "get-gs", NO_ARG, &get_gs, 1 }, 1454 { "get-ss", NO_ARG, &get_ss, 1 }, 1455 { "get-tr", NO_ARG, &get_tr, 1 }, 1456 { "get-ldtr", NO_ARG, &get_ldtr, 1 }, 1457 { "get-eptp", NO_ARG, &get_eptp, 1 }, 1458 { "get-exception-bitmap", 1459 NO_ARG, &get_exception_bitmap, 1 }, 1460 { "get-io-bitmap-address", 1461 NO_ARG, &get_io_bitmap, 1 }, 1462 { "get-tsc-offset", NO_ARG, &get_tsc_offset, 1 }, 1463 { "get-msr-bitmap", 1464 NO_ARG, &get_msr_bitmap, 1 }, 1465 { "get-msr-bitmap-address", 1466 NO_ARG, &get_msr_bitmap_address, 1 }, 1467 { "get-guest-pat", NO_ARG, &get_guest_pat, 1 }, 1468 { "get-guest-sysenter", 1469 NO_ARG, &get_guest_sysenter, 1 }, 1470 { "get-exit-reason", 1471 NO_ARG, &get_exit_reason, 1 }, 1472 { "get-x2apic-state", NO_ARG, &get_x2apic_state, 1 }, 1473 { "get-all", NO_ARG, &get_all, 1 }, 1474 { "run", NO_ARG, &run, 1 }, 1475 { "create", NO_ARG, &create, 1 }, 1476 { "destroy", NO_ARG, &destroy, 1 }, 1477 { "inject-nmi", NO_ARG, &inject_nmi, 1 }, 1478 { "force-reset", NO_ARG, &force_reset, 1 }, 1479 { "force-poweroff", NO_ARG, &force_poweroff, 1 }, 1480 { "get-active-cpus", NO_ARG, &get_active_cpus, 1 }, 1481 { "get-suspended-cpus", NO_ARG, &get_suspended_cpus, 1 }, 1482 { "get-intinfo", NO_ARG, &get_intinfo, 1 }, 1483 { "get-cpu-topology", NO_ARG, &get_cpu_topology, 1 }, 1484#ifndef __FreeBSD__ 1485 { "wrlock-cycle", NO_ARG, &wrlock_cycle, 1 }, 1486#endif 1487 }; 1488 1489 const struct option intel_opts[] = { 1490 { "get-vmcs-pinbased-ctls", 1491 NO_ARG, &get_pinbased_ctls, 1 }, 1492 { "get-vmcs-procbased-ctls", 1493 NO_ARG, &get_procbased_ctls, 1 }, 1494 { "get-vmcs-procbased-ctls2", 1495 NO_ARG, &get_procbased_ctls2, 1 }, 1496 { "get-vmcs-guest-linear-address", 1497 NO_ARG, &get_vmcs_gla, 1 }, 1498 { "get-vmcs-guest-physical-address", 1499 NO_ARG, &get_vmcs_gpa, 1 }, 1500 { "get-vmcs-entry-interruption-info", 1501 NO_ARG, &get_vmcs_entry_interruption_info, 1}, 1502 { "get-vmcs-cr0-mask", NO_ARG, &get_cr0_mask, 1 }, 1503 { "get-vmcs-cr0-shadow", NO_ARG,&get_cr0_shadow, 1 }, 1504 { "get-vmcs-cr4-mask", NO_ARG, &get_cr4_mask, 1 }, 1505 { "get-vmcs-cr4-shadow", NO_ARG, &get_cr4_shadow, 1 }, 1506 { "get-vmcs-cr3-targets", NO_ARG, &get_cr3_targets, 1 }, 1507 { "get-vmcs-tpr-threshold", 1508 NO_ARG, &get_tpr_threshold, 1 }, 1509 { "get-vmcs-vpid", NO_ARG, &get_vpid_asid, 1 }, 1510 { "get-vmcs-exit-ctls", NO_ARG, &get_exit_ctls, 1 }, 1511 { "get-vmcs-entry-ctls", 1512 NO_ARG, &get_entry_ctls, 1 }, 1513 { "get-vmcs-instruction-error", 1514 NO_ARG, &get_inst_err, 1 }, 1515 { "get-vmcs-host-pat", NO_ARG, &get_host_pat, 1 }, 1516 { "get-vmcs-host-cr0", 1517 NO_ARG, &get_host_cr0, 1 }, 1518 { "set-vmcs-entry-interruption-info", 1519 REQ_ARG, 0, SET_VMCS_ENTRY_INTERRUPTION_INFO }, 1520 { "get-vmcs-exit-qualification", 1521 NO_ARG, &get_vmcs_exit_qualification, 1 }, 1522 { "get-vmcs-exit-inst-length", 1523 NO_ARG, &get_vmcs_exit_inst_length, 1 }, 1524 { "get-vmcs-interruptibility", 1525 NO_ARG, &get_vmcs_interruptibility, 1 }, 1526 { "get-vmcs-exit-interruption-error", 1527 NO_ARG, &get_vmcs_exit_interruption_error, 1 }, 1528 { "get-vmcs-exit-interruption-info", 1529 NO_ARG, &get_vmcs_exit_interruption_info, 1 }, 1530 { "get-vmcs-link", NO_ARG, &get_vmcs_link, 1 }, 1531 { "get-vmcs-host-cr3", 1532 NO_ARG, &get_host_cr3, 1 }, 1533 { "get-vmcs-host-cr4", 1534 NO_ARG, &get_host_cr4, 1 }, 1535 { "get-vmcs-host-rip", 1536 NO_ARG, &get_host_rip, 1 }, 1537 { "get-vmcs-host-rsp", 1538 NO_ARG, &get_host_rsp, 1 }, 1539 { "get-apic-access-address", 1540 NO_ARG, &get_apic_access_addr, 1}, 1541 { "get-virtual-apic-address", 1542 NO_ARG, &get_virtual_apic_addr, 1} 1543 }; 1544 1545 const struct option amd_opts[] = { 1546 { "get-vmcb-intercepts", 1547 NO_ARG, &get_vmcb_intercept, 1 }, 1548 { "get-vmcb-asid", 1549 NO_ARG, &get_vpid_asid, 1 }, 1550 { "get-vmcb-exit-details", 1551 NO_ARG, &get_vmcb_exit_details, 1 }, 1552 { "get-vmcb-tlb-ctrl", 1553 NO_ARG, &get_vmcb_tlb_ctrl, 1 }, 1554 { "get-vmcb-virq", 1555 NO_ARG, &get_vmcb_virq, 1 }, 1556 { "get-avic-apic-bar", 1557 NO_ARG, &get_apic_access_addr, 1 }, 1558 { "get-avic-backing-page", 1559 NO_ARG, &get_virtual_apic_addr, 1 }, 1560 { "get-avic-table", 1561 NO_ARG, &get_avic_table, 1 } 1562 }; 1563 1564 const struct option null_opt = { 1565 NULL, 0, NULL, 0 1566 }; 1567 1568 struct option *all_opts; 1569 char *cp; 1570 int optlen; 1571 1572 optlen = sizeof(common_opts); 1573 1574 if (cpu_intel) 1575 optlen += sizeof(intel_opts); 1576 else 1577 optlen += sizeof(amd_opts); 1578 1579 optlen += sizeof(null_opt); 1580 1581 all_opts = malloc(optlen); 1582 1583 cp = (char *)all_opts; 1584 memcpy(cp, common_opts, sizeof(common_opts)); 1585 cp += sizeof(common_opts); 1586 1587 if (cpu_intel) { 1588 memcpy(cp, intel_opts, sizeof(intel_opts)); 1589 cp += sizeof(intel_opts); 1590 } else { 1591 memcpy(cp, amd_opts, sizeof(amd_opts)); 1592 cp += sizeof(amd_opts); 1593 } 1594 1595 memcpy(cp, &null_opt, sizeof(null_opt)); 1596 cp += sizeof(null_opt); 1597 1598 return (all_opts); 1599} 1600 1601static const char * 1602wday_str(int idx) 1603{ 1604 static const char *weekdays[] = { 1605 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 1606 }; 1607 1608 if (idx >= 0 && idx < 7) 1609 return (weekdays[idx]); 1610 else 1611 return ("UNK"); 1612} 1613 1614static const char * 1615mon_str(int idx) 1616{ 1617 static const char *months[] = { 1618 "Jan", "Feb", "Mar", "Apr", "May", "Jun", 1619 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 1620 }; 1621 1622 if (idx >= 0 && idx < 12) 1623 return (months[idx]); 1624 else 1625 return ("UNK"); 1626} 1627 1628static int 1629show_memmap(struct vmctx *ctx) 1630{ 1631 char name[SPECNAMELEN + 1], numbuf[8]; 1632 vm_ooffset_t segoff; 1633 vm_paddr_t gpa; 1634 size_t maplen, seglen; 1635 int error, flags, prot, segid, delim; 1636 1637 printf("Address Length Segment Offset "); 1638 printf("Prot Flags\n"); 1639 1640 gpa = 0; 1641 while (1) { 1642 error = vm_mmap_getnext(ctx, &gpa, &segid, &segoff, &maplen, 1643 &prot, &flags); 1644 if (error) 1645 return (errno == ENOENT ? 0 : error); 1646 1647 error = vm_get_memseg(ctx, segid, &seglen, name, sizeof(name)); 1648 if (error) 1649 return (error); 1650 1651 printf("%-12lX", gpa); 1652 humanize_number(numbuf, sizeof(numbuf), maplen, "B", 1653 HN_AUTOSCALE, HN_NOSPACE); 1654 printf("%-12s", numbuf); 1655 1656 printf("%-12s", name[0] ? name : "sysmem"); 1657 printf("%-12lX", segoff); 1658 printf("%c%c%c ", prot & PROT_READ ? 'R' : '-', 1659 prot & PROT_WRITE ? 'W' : '-', 1660 prot & PROT_EXEC ? 'X' : '-'); 1661 1662 delim = '\0'; 1663 if (flags & VM_MEMMAP_F_WIRED) { 1664 printf("%cwired", delim); 1665 delim = '/'; 1666 } 1667 if (flags & VM_MEMMAP_F_IOMMU) { 1668 printf("%ciommu", delim); 1669 delim = '/'; 1670 } 1671 printf("\n"); 1672 1673 gpa += maplen; 1674 } 1675} 1676 1677static int 1678show_memseg(struct vmctx *ctx) 1679{ 1680 char name[SPECNAMELEN + 1], numbuf[8]; 1681 size_t seglen; 1682 int error, segid; 1683 1684 printf("ID Length Name\n"); 1685 1686 segid = 0; 1687 while (1) { 1688 error = vm_get_memseg(ctx, segid, &seglen, name, sizeof(name)); 1689 if (error) 1690 return (errno == EINVAL ? 0 : error); 1691 1692 if (seglen) { 1693 printf("%-4d", segid); 1694 humanize_number(numbuf, sizeof(numbuf), seglen, "B", 1695 HN_AUTOSCALE, HN_NOSPACE); 1696 printf("%-12s", numbuf); 1697 printf("%s", name[0] ? name : "sysmem"); 1698 printf("\n"); 1699 } 1700 segid++; 1701 } 1702} 1703 1704int 1705main(int argc, char *argv[]) 1706{ 1707 char *vmname; 1708 int error, ch, vcpu, ptenum; 1709 vm_paddr_t gpa_pmap; 1710 struct vm_exit vmexit; 1711 uint64_t rax, cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7; 1712 uint64_t rsp, rip, rflags, efer, pat; 1713 uint64_t eptp, bm, addr, u64, pteval[4], *pte, info[2]; 1714 struct vmctx *ctx; 1715 cpuset_t cpus; 1716 bool cpu_intel; 1717 uint64_t cs, ds, es, fs, gs, ss, tr, ldtr; 1718 struct tm tm; 1719 struct option *opts; 1720 1721 cpu_intel = cpu_vendor_intel(); 1722 opts = setup_options(cpu_intel); 1723 1724 vcpu = 0; 1725 vmname = NULL; 1726 assert_lapic_lvt = -1; 1727 progname = basename(argv[0]); 1728 1729 while ((ch = getopt_long(argc, argv, "", opts, NULL)) != -1) { 1730 switch (ch) { 1731 case 0: 1732 break; 1733 case VMNAME: 1734 vmname = optarg; 1735 break; 1736 case VCPU: 1737 vcpu = atoi(optarg); 1738 break; 1739 case SET_MEM: 1740 memsize = atoi(optarg) * MB; 1741 memsize = roundup(memsize, 2 * MB); 1742 break; 1743 case SET_EFER: 1744 efer = strtoul(optarg, NULL, 0); 1745 set_efer = 1; 1746 break; 1747 case SET_CR0: 1748 cr0 = strtoul(optarg, NULL, 0); 1749 set_cr0 = 1; 1750 break; 1751 case SET_CR2: 1752 cr2 = strtoul(optarg, NULL, 0); 1753 set_cr2 = 1; 1754 break; 1755 case SET_CR3: 1756 cr3 = strtoul(optarg, NULL, 0); 1757 set_cr3 = 1; 1758 break; 1759 case SET_CR4: 1760 cr4 = strtoul(optarg, NULL, 0); 1761 set_cr4 = 1; 1762 break; 1763 case SET_DR0: 1764 dr0 = strtoul(optarg, NULL, 0); 1765 set_dr0 = 1; 1766 break; 1767 case SET_DR1: 1768 dr1 = strtoul(optarg, NULL, 0); 1769 set_dr1 = 1; 1770 break; 1771 case SET_DR2: 1772 dr2 = strtoul(optarg, NULL, 0); 1773 set_dr2 = 1; 1774 break; 1775 case SET_DR3: 1776 dr3 = strtoul(optarg, NULL, 0); 1777 set_dr3 = 1; 1778 break; 1779 case SET_DR6: 1780 dr6 = strtoul(optarg, NULL, 0); 1781 set_dr6 = 1; 1782 break; 1783 case SET_DR7: 1784 dr7 = strtoul(optarg, NULL, 0); 1785 set_dr7 = 1; 1786 break; 1787 case SET_RSP: 1788 rsp = strtoul(optarg, NULL, 0); 1789 set_rsp = 1; 1790 break; 1791 case SET_RIP: 1792 rip = strtoul(optarg, NULL, 0); 1793 set_rip = 1; 1794 break; 1795 case SET_RAX: 1796 rax = strtoul(optarg, NULL, 0); 1797 set_rax = 1; 1798 break; 1799 case SET_RFLAGS: 1800 rflags = strtoul(optarg, NULL, 0); 1801 set_rflags = 1; 1802 break; 1803 case DESC_BASE: 1804 desc_base = strtoul(optarg, NULL, 0); 1805 break; 1806 case DESC_LIMIT: 1807 desc_limit = strtoul(optarg, NULL, 0); 1808 break; 1809 case DESC_ACCESS: 1810 desc_access = strtoul(optarg, NULL, 0); 1811 break; 1812 case SET_CS: 1813 cs = strtoul(optarg, NULL, 0); 1814 set_cs = 1; 1815 break; 1816 case SET_DS: 1817 ds = strtoul(optarg, NULL, 0); 1818 set_ds = 1; 1819 break; 1820 case SET_ES: 1821 es = strtoul(optarg, NULL, 0); 1822 set_es = 1; 1823 break; 1824 case SET_FS: 1825 fs = strtoul(optarg, NULL, 0); 1826 set_fs = 1; 1827 break; 1828 case SET_GS: 1829 gs = strtoul(optarg, NULL, 0); 1830 set_gs = 1; 1831 break; 1832 case SET_SS: 1833 ss = strtoul(optarg, NULL, 0); 1834 set_ss = 1; 1835 break; 1836 case SET_TR: 1837 tr = strtoul(optarg, NULL, 0); 1838 set_tr = 1; 1839 break; 1840 case SET_LDTR: 1841 ldtr = strtoul(optarg, NULL, 0); 1842 set_ldtr = 1; 1843 break; 1844 case SET_X2APIC_STATE: 1845 x2apic_state = strtol(optarg, NULL, 0); 1846 set_x2apic_state = 1; 1847 break; 1848 case SET_EXCEPTION_BITMAP: 1849 exception_bitmap = strtoul(optarg, NULL, 0); 1850 set_exception_bitmap = 1; 1851 break; 1852 case SET_VMCS_ENTRY_INTERRUPTION_INFO: 1853 vmcs_entry_interruption_info = strtoul(optarg, NULL, 0); 1854 set_vmcs_entry_interruption_info = 1; 1855 break; 1856 case SET_CAP: 1857 capval = strtoul(optarg, NULL, 0); 1858 setcap = 1; 1859 break; 1860 case SET_RTC_TIME: 1861 rtc_secs = strtoul(optarg, NULL, 0); 1862 set_rtc_time = 1; 1863 break; 1864 case SET_RTC_NVRAM: 1865 rtc_nvram_value = (uint8_t)strtoul(optarg, NULL, 0); 1866 set_rtc_nvram = 1; 1867 break; 1868 case RTC_NVRAM_OFFSET: 1869 rtc_nvram_offset = strtoul(optarg, NULL, 0); 1870 break; 1871 case GET_GPA_PMAP: 1872 gpa_pmap = strtoul(optarg, NULL, 0); 1873 get_gpa_pmap = 1; 1874 break; 1875 case CAPNAME: 1876 capname = optarg; 1877 break; 1878 case UNASSIGN_PPTDEV: 1879 unassign_pptdev = 1; 1880 if (sscanf(optarg, "%d/%d/%d", &bus, &slot, &func) != 3) 1881 usage(cpu_intel); 1882 break; 1883 case ASSERT_LAPIC_LVT: 1884 assert_lapic_lvt = atoi(optarg); 1885 break; 1886 default: 1887 usage(cpu_intel); 1888 } 1889 } 1890 argc -= optind; 1891 argv += optind; 1892 1893 if (vmname == NULL) 1894 usage(cpu_intel); 1895 1896 error = 0; 1897 1898 if (!error && create) 1899 error = vm_create(vmname); 1900 1901 if (!error) { 1902 ctx = vm_open(vmname); 1903 if (ctx == NULL) { 1904 printf("VM:%s is not created.\n", vmname); 1905 exit (1); 1906 } 1907 } 1908 1909#ifndef __FreeBSD__ 1910 if (!error && wrlock_cycle) { 1911 error = vm_wrlock_cycle(ctx); 1912 exit(error); 1913 } 1914#endif /* __FreeBSD__ */ 1915 1916 if (!error && memsize) 1917 error = vm_setup_memory(ctx, memsize, VM_MMAP_ALL); 1918 1919 if (!error && set_efer) 1920 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_EFER, efer); 1921 1922 if (!error && set_cr0) 1923 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR0, cr0); 1924 1925 if (!error && set_cr2) 1926 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR2, cr2); 1927 1928 if (!error && set_cr3) 1929 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR3, cr3); 1930 1931 if (!error && set_cr4) 1932 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CR4, cr4); 1933 1934 if (!error && set_dr0) 1935 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DR0, dr0); 1936 1937 if (!error && set_dr1) 1938 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DR1, dr1); 1939 1940 if (!error && set_dr2) 1941 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DR2, dr2); 1942 1943 if (!error && set_dr3) 1944 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DR3, dr3); 1945 1946 if (!error && set_dr6) 1947 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DR6, dr6); 1948 1949 if (!error && set_dr7) 1950 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DR7, dr7); 1951 1952 if (!error && set_rsp) 1953 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RSP, rsp); 1954 1955 if (!error && set_rip) 1956 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RIP, rip); 1957 1958 if (!error && set_rax) 1959 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, rax); 1960 1961 if (!error && set_rflags) { 1962 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, 1963 rflags); 1964 } 1965 1966 if (!error && set_desc_ds) { 1967 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_DS, 1968 desc_base, desc_limit, desc_access); 1969 } 1970 1971 if (!error && set_desc_es) { 1972 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_ES, 1973 desc_base, desc_limit, desc_access); 1974 } 1975 1976 if (!error && set_desc_ss) { 1977 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_SS, 1978 desc_base, desc_limit, desc_access); 1979 } 1980 1981 if (!error && set_desc_cs) { 1982 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_CS, 1983 desc_base, desc_limit, desc_access); 1984 } 1985 1986 if (!error && set_desc_fs) { 1987 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_FS, 1988 desc_base, desc_limit, desc_access); 1989 } 1990 1991 if (!error && set_desc_gs) { 1992 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_GS, 1993 desc_base, desc_limit, desc_access); 1994 } 1995 1996 if (!error && set_desc_tr) { 1997 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_TR, 1998 desc_base, desc_limit, desc_access); 1999 } 2000 2001 if (!error && set_desc_ldtr) { 2002 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_LDTR, 2003 desc_base, desc_limit, desc_access); 2004 } 2005 2006 if (!error && set_desc_gdtr) { 2007 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_GDTR, 2008 desc_base, desc_limit, 0); 2009 } 2010 2011 if (!error && set_desc_idtr) { 2012 error = vm_set_desc(ctx, vcpu, VM_REG_GUEST_IDTR, 2013 desc_base, desc_limit, 0); 2014 } 2015 2016 if (!error && set_cs) 2017 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CS, cs); 2018 2019 if (!error && set_ds) 2020 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DS, ds); 2021 2022 if (!error && set_es) 2023 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_ES, es); 2024 2025 if (!error && set_fs) 2026 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_FS, fs); 2027 2028 if (!error && set_gs) 2029 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_GS, gs); 2030 2031 if (!error && set_ss) 2032 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_SS, ss); 2033 2034 if (!error && set_tr) 2035 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_TR, tr); 2036 2037 if (!error && set_ldtr) 2038 error = vm_set_register(ctx, vcpu, VM_REG_GUEST_LDTR, ldtr); 2039 2040 if (!error && set_x2apic_state) 2041 error = vm_set_x2apic_state(ctx, vcpu, x2apic_state); 2042 2043 if (!error && unassign_pptdev) 2044 error = vm_unassign_pptdev(ctx, bus, slot, func); 2045 2046 if (!error && set_exception_bitmap) { 2047 if (cpu_intel) 2048 error = vm_set_vmcs_field(ctx, vcpu, 2049 VMCS_EXCEPTION_BITMAP, 2050 exception_bitmap); 2051 else 2052 error = vm_set_vmcb_field(ctx, vcpu, 2053 VMCB_OFF_EXC_INTERCEPT, 2054 4, exception_bitmap); 2055 } 2056 2057 if (!error && cpu_intel && set_vmcs_entry_interruption_info) { 2058 error = vm_set_vmcs_field(ctx, vcpu, VMCS_ENTRY_INTR_INFO, 2059 vmcs_entry_interruption_info); 2060 } 2061 2062 if (!error && inject_nmi) { 2063 error = vm_inject_nmi(ctx, vcpu); 2064 } 2065 2066 if (!error && assert_lapic_lvt != -1) { 2067 error = vm_lapic_local_irq(ctx, vcpu, assert_lapic_lvt); 2068 } 2069 2070 if (!error && (get_memseg || get_all)) 2071 error = show_memseg(ctx); 2072 2073 if (!error && (get_memmap || get_all)) 2074 error = show_memmap(ctx); 2075 2076 if (!error) 2077 error = get_all_registers(ctx, vcpu); 2078 2079 if (!error) 2080 error = get_all_segments(ctx, vcpu); 2081 2082 if (!error) { 2083 if (cpu_intel) 2084 error = get_misc_vmcs(ctx, vcpu); 2085 else 2086 error = get_misc_vmcb(ctx, vcpu); 2087 } 2088 2089 if (!error && (get_x2apic_state || get_all)) { 2090 error = vm_get_x2apic_state(ctx, vcpu, &x2apic_state); 2091 if (error == 0) 2092 printf("x2apic_state[%d]\t%d\n", vcpu, x2apic_state); 2093 } 2094 2095 if (!error && (get_eptp || get_all)) { 2096 if (cpu_intel) 2097 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EPTP, &eptp); 2098 else 2099 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_NPT_BASE, 2100 8, &eptp); 2101 if (error == 0) 2102 printf("%s[%d]\t\t0x%016lx\n", 2103 cpu_intel ? "eptp" : "rvi/npt", vcpu, eptp); 2104 } 2105 2106 if (!error && (get_exception_bitmap || get_all)) { 2107 if(cpu_intel) 2108 error = vm_get_vmcs_field(ctx, vcpu, 2109 VMCS_EXCEPTION_BITMAP, &bm); 2110 else 2111 error = vm_get_vmcb_field(ctx, vcpu, 2112 VMCB_OFF_EXC_INTERCEPT, 2113 4, &bm); 2114 if (error == 0) 2115 printf("exception_bitmap[%d]\t%#lx\n", vcpu, bm); 2116 } 2117 2118 if (!error && (get_io_bitmap || get_all)) { 2119 if (cpu_intel) { 2120 error = vm_get_vmcs_field(ctx, vcpu, VMCS_IO_BITMAP_A, 2121 &bm); 2122 if (error == 0) 2123 printf("io_bitmap_a[%d]\t%#lx\n", vcpu, bm); 2124 error = vm_get_vmcs_field(ctx, vcpu, VMCS_IO_BITMAP_B, 2125 &bm); 2126 if (error == 0) 2127 printf("io_bitmap_b[%d]\t%#lx\n", vcpu, bm); 2128 } else { 2129 error = vm_get_vmcb_field(ctx, vcpu, 2130 VMCB_OFF_IO_PERM, 8, &bm); 2131 if (error == 0) 2132 printf("io_bitmap[%d]\t%#lx\n", vcpu, bm); 2133 } 2134 } 2135 2136 if (!error && (get_tsc_offset || get_all)) { 2137 uint64_t tscoff; 2138 if (cpu_intel) 2139 error = vm_get_vmcs_field(ctx, vcpu, VMCS_TSC_OFFSET, 2140 &tscoff); 2141 else 2142 error = vm_get_vmcb_field(ctx, vcpu, 2143 VMCB_OFF_TSC_OFFSET, 2144 8, &tscoff); 2145 if (error == 0) 2146 printf("tsc_offset[%d]\t0x%016lx\n", vcpu, tscoff); 2147 } 2148 2149 if (!error && (get_msr_bitmap_address || get_all)) { 2150 if (cpu_intel) 2151 error = vm_get_vmcs_field(ctx, vcpu, VMCS_MSR_BITMAP, 2152 &addr); 2153 else 2154 error = vm_get_vmcb_field(ctx, vcpu, 2155 VMCB_OFF_MSR_PERM, 8, &addr); 2156 if (error == 0) 2157 printf("msr_bitmap[%d]\t\t%#lx\n", vcpu, addr); 2158 } 2159 2160 if (!error && (get_msr_bitmap || get_all)) { 2161 if (cpu_intel) { 2162 error = vm_get_vmcs_field(ctx, vcpu, 2163 VMCS_MSR_BITMAP, &addr); 2164 } else { 2165 error = vm_get_vmcb_field(ctx, vcpu, 2166 VMCB_OFF_MSR_PERM, 8, 2167 &addr); 2168 } 2169 2170 if (error == 0) 2171 error = dump_msr_bitmap(vcpu, addr, cpu_intel); 2172 } 2173 2174 if (!error && (get_vpid_asid || get_all)) { 2175 uint64_t vpid; 2176 if (cpu_intel) 2177 error = vm_get_vmcs_field(ctx, vcpu, VMCS_VPID, &vpid); 2178 else 2179 error = vm_get_vmcb_field(ctx, vcpu, VMCB_OFF_ASID, 2180 4, &vpid); 2181 if (error == 0) 2182 printf("%s[%d]\t\t0x%04lx\n", 2183 cpu_intel ? "vpid" : "asid", vcpu, vpid); 2184 } 2185 2186 if (!error && (get_guest_pat || get_all)) { 2187 if (cpu_intel) 2188 error = vm_get_vmcs_field(ctx, vcpu, 2189 VMCS_GUEST_IA32_PAT, &pat); 2190 else 2191 error = vm_get_vmcb_field(ctx, vcpu, 2192 VMCB_OFF_GUEST_PAT, 8, &pat); 2193 if (error == 0) 2194 printf("guest_pat[%d]\t\t0x%016lx\n", vcpu, pat); 2195 } 2196 2197 if (!error && (get_guest_sysenter || get_all)) { 2198 if (cpu_intel) 2199 error = vm_get_vmcs_field(ctx, vcpu, 2200 VMCS_GUEST_IA32_SYSENTER_CS, 2201 &cs); 2202 else 2203 error = vm_get_vmcb_field(ctx, vcpu, 2204 VMCB_OFF_SYSENTER_CS, 8, 2205 &cs); 2206 2207 if (error == 0) 2208 printf("guest_sysenter_cs[%d]\t%#lx\n", vcpu, cs); 2209 if (cpu_intel) 2210 error = vm_get_vmcs_field(ctx, vcpu, 2211 VMCS_GUEST_IA32_SYSENTER_ESP, 2212 &rsp); 2213 else 2214 error = vm_get_vmcb_field(ctx, vcpu, 2215 VMCB_OFF_SYSENTER_ESP, 8, 2216 &rsp); 2217 2218 if (error == 0) 2219 printf("guest_sysenter_sp[%d]\t%#lx\n", vcpu, rsp); 2220 if (cpu_intel) 2221 error = vm_get_vmcs_field(ctx, vcpu, 2222 VMCS_GUEST_IA32_SYSENTER_EIP, 2223 &rip); 2224 else 2225 error = vm_get_vmcb_field(ctx, vcpu, 2226 VMCB_OFF_SYSENTER_EIP, 8, 2227 &rip); 2228 if (error == 0) 2229 printf("guest_sysenter_ip[%d]\t%#lx\n", vcpu, rip); 2230 } 2231 2232 if (!error && (get_exit_reason || get_all)) { 2233 if (cpu_intel) 2234 error = vm_get_vmcs_field(ctx, vcpu, VMCS_EXIT_REASON, 2235 &u64); 2236 else 2237 error = vm_get_vmcb_field(ctx, vcpu, 2238 VMCB_OFF_EXIT_REASON, 8, 2239 &u64); 2240 if (error == 0) 2241 printf("exit_reason[%d]\t%#lx\n", vcpu, u64); 2242 } 2243 |
|
1474 if (!error && setcap) { 1475 int captype; 1476 captype = vm_capability_name2type(capname); 1477 error = vm_set_capability(ctx, vcpu, captype, capval); 1478 if (error != 0 && errno == ENOENT) 1479 printf("Capability \"%s\" is not available\n", capname); 1480 } 1481 | 2244 if (!error && setcap) { 2245 int captype; 2246 captype = vm_capability_name2type(capname); 2247 error = vm_set_capability(ctx, vcpu, captype, capval); 2248 if (error != 0 && errno == ENOENT) 2249 printf("Capability \"%s\" is not available\n", capname); 2250 } 2251 |
2252 if (!error && get_gpa_pmap) { 2253 error = vm_get_gpa_pmap(ctx, gpa_pmap, pteval, &ptenum); 2254 if (error == 0) { 2255 printf("gpa %#lx:", gpa_pmap); 2256 pte = &pteval[0]; 2257 while (ptenum-- > 0) 2258 printf(" %#lx", *pte++); 2259 printf("\n"); 2260 } 2261 } 2262 2263 if (!error && set_rtc_nvram) 2264 error = vm_rtc_write(ctx, rtc_nvram_offset, rtc_nvram_value); 2265 2266 if (!error && (get_rtc_nvram || get_all)) { 2267 error = vm_rtc_read(ctx, rtc_nvram_offset, &rtc_nvram_value); 2268 if (error == 0) { 2269 printf("rtc nvram[%03d]: 0x%02x\n", rtc_nvram_offset, 2270 rtc_nvram_value); 2271 } 2272 } 2273 2274 if (!error && set_rtc_time) 2275 error = vm_rtc_settime(ctx, rtc_secs); 2276 2277 if (!error && (get_rtc_time || get_all)) { 2278 error = vm_rtc_gettime(ctx, &rtc_secs); 2279 if (error == 0) { 2280 gmtime_r(&rtc_secs, &tm); 2281 printf("rtc time %#lx: %s %s %02d %02d:%02d:%02d %d\n", 2282 rtc_secs, wday_str(tm.tm_wday), mon_str(tm.tm_mon), 2283 tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, 2284 1900 + tm.tm_year); 2285 } 2286 } 2287 |
|
1482 if (!error && (getcap || get_all)) { 1483 int captype, val, getcaptype; 1484 1485 if (getcap && capname) 1486 getcaptype = vm_capability_name2type(capname); 1487 else 1488 getcaptype = -1; 1489 --- 10 unchanged lines hidden (view full) --- 1500 printf("Capability \"%s\" is not available\n", 1501 vm_capability_type2name(captype)); 1502 } else { 1503 break; 1504 } 1505 } 1506 } 1507 | 2288 if (!error && (getcap || get_all)) { 2289 int captype, val, getcaptype; 2290 2291 if (getcap && capname) 2292 getcaptype = vm_capability_name2type(capname); 2293 else 2294 getcaptype = -1; 2295 --- 10 unchanged lines hidden (view full) --- 2306 printf("Capability \"%s\" is not available\n", 2307 vm_capability_type2name(captype)); 2308 } else { 2309 break; 2310 } 2311 } 2312 } 2313 |
2314 if (!error && (get_active_cpus || get_all)) { 2315 error = vm_active_cpus(ctx, &cpus); 2316 if (!error) 2317 print_cpus("active cpus", &cpus); 2318 } 2319 2320 if (!error && (get_suspended_cpus || get_all)) { 2321 error = vm_suspended_cpus(ctx, &cpus); 2322 if (!error) 2323 print_cpus("suspended cpus", &cpus); 2324 } 2325 2326 if (!error && (get_intinfo || get_all)) { 2327 error = vm_get_intinfo(ctx, vcpu, &info[0], &info[1]); 2328 if (!error) { 2329 print_intinfo("pending", info[0]); 2330 print_intinfo("current", info[1]); 2331 } 2332 } 2333 2334 if (!error && (get_stats || get_all)) { 2335 int i, num_stats; 2336 uint64_t *stats; 2337 struct timeval tv; 2338 const char *desc; 2339 2340 stats = vm_get_stats(ctx, vcpu, &tv, &num_stats); 2341 if (stats != NULL) { 2342 printf("vcpu%d stats:\n", vcpu); 2343 for (i = 0; i < num_stats; i++) { 2344 desc = vm_get_stat_desc(ctx, i); 2345 printf("%-40s\t%ld\n", desc, stats[i]); 2346 } 2347 } 2348 } 2349 2350 if (!error && (get_cpu_topology || get_all)) { 2351 uint16_t sockets, cores, threads, maxcpus; 2352 2353 vm_get_topology(ctx, &sockets, &cores, &threads, &maxcpus); 2354 printf("cpu_topology:\tsockets=%hu, cores=%hu, threads=%hu, " 2355 "maxcpus=%hu\n", sockets, cores, threads, maxcpus); 2356 } 2357 |
|
1508 if (!error && run) { 1509 error = vm_run(ctx, vcpu, &vmexit); 1510 if (error == 0) 1511 dump_vm_run_exitcode(&vmexit, vcpu); 1512 else 1513 printf("vm_run error %d\n", error); 1514 } 1515 | 2358 if (!error && run) { 2359 error = vm_run(ctx, vcpu, &vmexit); 2360 if (error == 0) 2361 dump_vm_run_exitcode(&vmexit, vcpu); 2362 else 2363 printf("vm_run error %d\n", error); 2364 } 2365 |
2366 if (!error && force_reset) 2367 error = vm_suspend(ctx, VM_SUSPEND_RESET); 2368 2369 if (!error && force_poweroff) 2370 error = vm_suspend(ctx, VM_SUSPEND_POWEROFF); 2371 |
|
1516 if (error) 1517 printf("errno = %d\n", errno); 1518 1519 if (!error && destroy) | 2372 if (error) 2373 printf("errno = %d\n", errno); 2374 2375 if (!error && destroy) |
1520 error = vm_destroy(ctx); | 2376 vm_destroy(ctx); |
1521 | 2377 |
2378 free (opts); |
|
1522 exit(error); 1523} | 2379 exit(error); 2380} |