vmexit.c (7228ad8da93bcce820c85b733972d0d9cc767d27) vmexit.c (b0936440b8fcee523c0b26fdbbef7c3b2b5098bf)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
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

--- 69 unchanged lines hidden (view full) ---

78
79 vme = vmrun->vm_exit;
80 port = vme->u.inout.port;
81 bytes = vme->u.inout.bytes;
82 in = vme->u.inout.in;
83
84 error = emulate_inout(ctx, vcpu, vme);
85 if (error) {
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
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

--- 69 unchanged lines hidden (view full) ---

78
79 vme = vmrun->vm_exit;
80 port = vme->u.inout.port;
81 bytes = vme->u.inout.bytes;
82 in = vme->u.inout.in;
83
84 error = emulate_inout(ctx, vcpu, vme);
85 if (error) {
86 fprintf(stderr, "Unhandled %s%c 0x%04x at 0x%lx\n",
86 EPRINTLN("Unhandled %s%c 0x%04x at 0x%lx",
87 in ? "in" : "out",
88 bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'),
89 port, vme->rip);
90 return (VMEXIT_ABORT);
91 } else {
92 return (VMEXIT_CONTINUE);
93 }
94}

--- 7 unchanged lines hidden (view full) ---

102 uint32_t eax, edx;
103 int error;
104
105 vme = vmrun->vm_exit;
106
107 val = 0;
108 error = emulate_rdmsr(vcpu, vme->u.msr.code, &val);
109 if (error != 0) {
87 in ? "in" : "out",
88 bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'),
89 port, vme->rip);
90 return (VMEXIT_ABORT);
91 } else {
92 return (VMEXIT_CONTINUE);
93 }
94}

--- 7 unchanged lines hidden (view full) ---

102 uint32_t eax, edx;
103 int error;
104
105 vme = vmrun->vm_exit;
106
107 val = 0;
108 error = emulate_rdmsr(vcpu, vme->u.msr.code, &val);
109 if (error != 0) {
110 fprintf(stderr, "rdmsr to register %#x on vcpu %d\n",
110 EPRINTLN("rdmsr to register %#x on vcpu %d",
111 vme->u.msr.code, vcpu_id(vcpu));
112 if (get_config_bool("x86.strictmsr")) {
113 vm_inject_gp(vcpu);
114 return (VMEXIT_CONTINUE);
115 }
116 }
117
118 eax = val;

--- 13 unchanged lines hidden (view full) ---

132{
133 struct vm_exit *vme;
134 int error;
135
136 vme = vmrun->vm_exit;
137
138 error = emulate_wrmsr(vcpu, vme->u.msr.code, vme->u.msr.wval);
139 if (error != 0) {
111 vme->u.msr.code, vcpu_id(vcpu));
112 if (get_config_bool("x86.strictmsr")) {
113 vm_inject_gp(vcpu);
114 return (VMEXIT_CONTINUE);
115 }
116 }
117
118 eax = val;

--- 13 unchanged lines hidden (view full) ---

132{
133 struct vm_exit *vme;
134 int error;
135
136 vme = vmrun->vm_exit;
137
138 error = emulate_wrmsr(vcpu, vme->u.msr.code, vme->u.msr.wval);
139 if (error != 0) {
140 fprintf(stderr, "wrmsr to register %#x(%#lx) on vcpu %d\n",
140 EPRINTLN("wrmsr to register %#x(%#lx) on vcpu %d",
141 vme->u.msr.code, vme->u.msr.wval, vcpu_id(vcpu));
142 if (get_config_bool("x86.strictmsr")) {
143 vm_inject_gp(vcpu);
144 return (VMEXIT_CONTINUE);
145 }
146 }
147 return (VMEXIT_CONTINUE);
148}

--- 85 unchanged lines hidden (view full) ---

234
235static int
236vmexit_vmx(struct vmctx *ctx, struct vcpu *vcpu, struct vm_run *vmrun)
237{
238 struct vm_exit *vme;
239
240 vme = vmrun->vm_exit;
241
141 vme->u.msr.code, vme->u.msr.wval, vcpu_id(vcpu));
142 if (get_config_bool("x86.strictmsr")) {
143 vm_inject_gp(vcpu);
144 return (VMEXIT_CONTINUE);
145 }
146 }
147 return (VMEXIT_CONTINUE);
148}

--- 85 unchanged lines hidden (view full) ---

234
235static int
236vmexit_vmx(struct vmctx *ctx, struct vcpu *vcpu, struct vm_run *vmrun)
237{
238 struct vm_exit *vme;
239
240 vme = vmrun->vm_exit;
241
242 fprintf(stderr, "vm exit[%d]\n", vcpu_id(vcpu));
243 fprintf(stderr, "\treason\t\tVMX\n");
244 fprintf(stderr, "\trip\t\t0x%016lx\n", vme->rip);
245 fprintf(stderr, "\tinst_length\t%d\n", vme->inst_length);
246 fprintf(stderr, "\tstatus\t\t%d\n", vme->u.vmx.status);
247 fprintf(stderr, "\texit_reason\t%u (%s)\n", vme->u.vmx.exit_reason,
242 EPRINTLN("vm exit[%d]", vcpu_id(vcpu));
243 EPRINTLN("\treason\t\tVMX");
244 EPRINTLN("\trip\t\t0x%016lx", vme->rip);
245 EPRINTLN("\tinst_length\t%d", vme->inst_length);
246 EPRINTLN("\tstatus\t\t%d", vme->u.vmx.status);
247 EPRINTLN("\texit_reason\t%u (%s)", vme->u.vmx.exit_reason,
248 vmexit_vmx_desc(vme->u.vmx.exit_reason));
248 vmexit_vmx_desc(vme->u.vmx.exit_reason));
249 fprintf(stderr, "\tqualification\t0x%016lx\n",
249 EPRINTLN("\tqualification\t0x%016lx",
250 vme->u.vmx.exit_qualification);
250 vme->u.vmx.exit_qualification);
251 fprintf(stderr, "\tinst_type\t\t%d\n", vme->u.vmx.inst_type);
252 fprintf(stderr, "\tinst_error\t\t%d\n", vme->u.vmx.inst_error);
251 EPRINTLN("\tinst_type\t\t%d", vme->u.vmx.inst_type);
252 EPRINTLN("\tinst_error\t\t%d", vme->u.vmx.inst_error);
253#ifdef DEBUG_EPT_MISCONFIG
254 if (vme->u.vmx.exit_reason == EXIT_REASON_EPT_MISCONFIG) {
255 vm_get_register(vcpu,
256 VMCS_IDENT(VMCS_GUEST_PHYSICAL_ADDRESS),
257 &ept_misconfig_gpa);
258 vm_get_gpa_pmap(ctx, ept_misconfig_gpa, ept_misconfig_pte,
259 &ept_misconfig_ptenum);
253#ifdef DEBUG_EPT_MISCONFIG
254 if (vme->u.vmx.exit_reason == EXIT_REASON_EPT_MISCONFIG) {
255 vm_get_register(vcpu,
256 VMCS_IDENT(VMCS_GUEST_PHYSICAL_ADDRESS),
257 &ept_misconfig_gpa);
258 vm_get_gpa_pmap(ctx, ept_misconfig_gpa, ept_misconfig_pte,
259 &ept_misconfig_ptenum);
260 fprintf(stderr, "\tEPT misconfiguration:\n");
261 fprintf(stderr, "\t\tGPA: %#lx\n", ept_misconfig_gpa);
262 fprintf(stderr, "\t\tPTE(%d): %#lx %#lx %#lx %#lx\n",
260 EPRINTLN("\tEPT misconfiguration:");
261 EPRINTLN("\t\tGPA: %#lx", ept_misconfig_gpa);
262 EPRINTLN("\t\tPTE(%d): %#lx %#lx %#lx %#lx",
263 ept_misconfig_ptenum, ept_misconfig_pte[0],
264 ept_misconfig_pte[1], ept_misconfig_pte[2],
265 ept_misconfig_pte[3]);
266 }
267#endif /* DEBUG_EPT_MISCONFIG */
268 return (VMEXIT_ABORT);
269}
270
271static int
272vmexit_svm(struct vmctx *ctx __unused, struct vcpu *vcpu, struct vm_run *vmrun)
273{
274 struct vm_exit *vme;
275
276 vme = vmrun->vm_exit;
277
263 ept_misconfig_ptenum, ept_misconfig_pte[0],
264 ept_misconfig_pte[1], ept_misconfig_pte[2],
265 ept_misconfig_pte[3]);
266 }
267#endif /* DEBUG_EPT_MISCONFIG */
268 return (VMEXIT_ABORT);
269}
270
271static int
272vmexit_svm(struct vmctx *ctx __unused, struct vcpu *vcpu, struct vm_run *vmrun)
273{
274 struct vm_exit *vme;
275
276 vme = vmrun->vm_exit;
277
278 fprintf(stderr, "vm exit[%d]\n", vcpu_id(vcpu));
279 fprintf(stderr, "\treason\t\tSVM\n");
280 fprintf(stderr, "\trip\t\t0x%016lx\n", vme->rip);
281 fprintf(stderr, "\tinst_length\t%d\n", vme->inst_length);
282 fprintf(stderr, "\texitcode\t%#lx\n", vme->u.svm.exitcode);
283 fprintf(stderr, "\texitinfo1\t%#lx\n", vme->u.svm.exitinfo1);
284 fprintf(stderr, "\texitinfo2\t%#lx\n", vme->u.svm.exitinfo2);
278 EPRINTLN("vm exit[%d]", vcpu_id(vcpu));
279 EPRINTLN("\treason\t\tSVM");
280 EPRINTLN("\trip\t\t0x%016lx", vme->rip);
281 EPRINTLN("\tinst_length\t%d", vme->inst_length);
282 EPRINTLN("\texitcode\t%#lx", vme->u.svm.exitcode);
283 EPRINTLN("\texitinfo1\t%#lx", vme->u.svm.exitinfo1);
284 EPRINTLN("\texitinfo2\t%#lx", vme->u.svm.exitinfo2);
285 return (VMEXIT_ABORT);
286}
287
288static int
289vmexit_bogus(struct vmctx *ctx __unused, struct vcpu *vcpu __unused,
290 struct vm_run *vmrun)
291{
292 assert(vmrun->vm_exit->inst_length == 0);

--- 115 unchanged lines hidden (view full) ---

408 if (get_config_bool_default("destroy_on_poweroff", false))
409 vm_destroy(ctx);
410 exit(1);
411 case VM_SUSPEND_HALT:
412 exit(2);
413 case VM_SUSPEND_TRIPLEFAULT:
414 exit(3);
415 default:
285 return (VMEXIT_ABORT);
286}
287
288static int
289vmexit_bogus(struct vmctx *ctx __unused, struct vcpu *vcpu __unused,
290 struct vm_run *vmrun)
291{
292 assert(vmrun->vm_exit->inst_length == 0);

--- 115 unchanged lines hidden (view full) ---

408 if (get_config_bool_default("destroy_on_poweroff", false))
409 vm_destroy(ctx);
410 exit(1);
411 case VM_SUSPEND_HALT:
412 exit(2);
413 case VM_SUSPEND_TRIPLEFAULT:
414 exit(3);
415 default:
416 fprintf(stderr, "vmexit_suspend: invalid reason %d\n", how);
416 EPRINTLN("vmexit_suspend: invalid reason %d", how);
417 exit(100);
418 }
419 return (0); /* NOTREACHED */
420}
421
422static int
423vmexit_debug(struct vmctx *ctx __unused, struct vcpu *vcpu,
424 struct vm_run *vmrun __unused)

--- 82 unchanged lines hidden ---
417 exit(100);
418 }
419 return (0); /* NOTREACHED */
420}
421
422static int
423vmexit_debug(struct vmctx *ctx __unused, struct vcpu *vcpu,
424 struct vm_run *vmrun __unused)

--- 82 unchanged lines hidden ---