Lines Matching +full:timer +full:- +full:cannot +full:- +full:wake +full:- +full:cpu

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
60 #include <machine/cpu.h>
106 int hostcpu; /* (o) vcpu's host cpu */
109 void *cookie; /* (i) cpu-specific data */
128 #define vcpu_lock_init(v) mtx_init(&((v)->mtx), "vcpu lock", 0, MTX_SPIN)
129 #define vcpu_lock_destroy(v) mtx_destroy(&((v)->mtx))
130 #define vcpu_lock(v) mtx_lock_spin(&((v)->mtx))
131 #define vcpu_unlock(v) mtx_unlock_spin(&((v)->mtx))
132 #define vcpu_assert_locked(v) mtx_assert(&((v)->mtx), MA_OWNED)
146 void *cookie; /* (i) cpu-specific data */
147 void *iommu; /* (x) iommu-specific data */
152 struct vpmtmr *vpmtmr; /* (i) virtual ACPI PM timer */
170 /* The following describe the vm cpu topology */
179 VCPU_CTR0((vcpu)->vm, (vcpu)->vcpuid, format)
182 VCPU_CTR1((vcpu)->vm, (vcpu)->vcpuid, format, p1)
185 VCPU_CTR2((vcpu)->vm, (vcpu)->vcpuid, format, p1, p2)
188 VCPU_CTR3((vcpu)->vm, (vcpu)->vcpuid, format, p1, p2, p3)
191 VCPU_CTR4((vcpu)->vm, (vcpu)->vcpuid, format, p1, p2, p3, p4)
272 "WBINVD triggers a VM-exit");
304 * Upper limit on vm_maxcpu. Limited by use of uint16_t types for CPU
305 * counts as well as range of vpid values for VT-x and by the capacity
307 * vmx.c requires 'vm_maxcpu + 1 <= 0xffff', hence the '- 1' below.
309 #define VM_MAXCPU MIN(0xffff - 1, CPU_SETSIZE)
334 vmmops_vlapic_cleanup(vcpu->vlapic); in vcpu_cleanup()
335 vmmops_vcpu_cleanup(vcpu->cookie); in vcpu_cleanup()
336 vcpu->cookie = NULL; in vcpu_cleanup()
338 vmm_stat_free(vcpu->stats); in vcpu_cleanup()
339 fpu_save_area_free(vcpu->guestfpu); in vcpu_cleanup()
350 KASSERT(vcpu_id >= 0 && vcpu_id < vm->maxcpus, in vcpu_alloc()
355 vcpu->state = VCPU_IDLE; in vcpu_alloc()
356 vcpu->hostcpu = NOCPU; in vcpu_alloc()
357 vcpu->vcpuid = vcpu_id; in vcpu_alloc()
358 vcpu->vm = vm; in vcpu_alloc()
359 vcpu->guestfpu = fpu_save_area_alloc(); in vcpu_alloc()
360 vcpu->stats = vmm_stat_alloc(); in vcpu_alloc()
361 vcpu->tsc_offset = 0; in vcpu_alloc()
368 vcpu->cookie = vmmops_vcpu_init(vcpu->vm->cookie, vcpu, vcpu->vcpuid); in vcpu_init()
369 vcpu->vlapic = vmmops_vlapic_init(vcpu->cookie); in vcpu_init()
371 vcpu->reqidle = 0; in vcpu_init()
372 vcpu->exitintinfo = 0; in vcpu_init()
373 vcpu->nmi_pending = 0; in vcpu_init()
374 vcpu->extint_pending = 0; in vcpu_init()
375 vcpu->exception_pending = 0; in vcpu_init()
376 vcpu->guest_xcr0 = XFEATURE_ENABLED_X87; in vcpu_init()
377 fpu_save_area_reset(vcpu->guestfpu); in vcpu_init()
378 vmm_stat_init(vcpu->stats); in vcpu_init()
397 return (&vcpu->exitinfo); in vm_exitinfo()
403 return (&vcpu->exitinfo_cpuset); in vm_exitinfo_cpuset()
466 * Something bad happened - prevent new in vmm_handler()
492 * - VT-x initialization requires smp_rendezvous() and therefore must happen
494 * - vmm device initialization requires an initialized devfs.
502 vm->cookie = vmmops_init(vm, vmspace_pmap(vm->vmspace)); in vm_init()
503 vm->iommu = NULL; in vm_init()
504 vm->vioapic = vioapic_init(vm); in vm_init()
505 vm->vhpet = vhpet_init(vm); in vm_init()
506 vm->vatpic = vatpic_init(vm); in vm_init()
507 vm->vatpit = vatpit_init(vm); in vm_init()
508 vm->vpmtmr = vpmtmr_init(vm); in vm_init()
510 vm->vrtc = vrtc_init(vm); in vm_init()
512 CPU_ZERO(&vm->active_cpus); in vm_init()
513 CPU_ZERO(&vm->debug_cpus); in vm_init()
514 CPU_ZERO(&vm->startup_cpus); in vm_init()
516 vm->suspend = 0; in vm_init()
517 CPU_ZERO(&vm->suspended_cpus); in vm_init()
520 for (int i = 0; i < vm->maxcpus; i++) { in vm_init()
521 if (vm->vcpu[i] != NULL) in vm_init()
522 vcpu_init(vm->vcpu[i]); in vm_init()
530 sx_xlock(&vm->vcpus_init_lock); in vm_disable_vcpu_creation()
531 vm->dying = true; in vm_disable_vcpu_creation()
532 sx_xunlock(&vm->vcpus_init_lock); in vm_disable_vcpu_creation()
544 atomic_load_acq_ptr((uintptr_t *)&vm->vcpu[vcpuid]); in vm_alloc_vcpu()
548 sx_xlock(&vm->vcpus_init_lock); in vm_alloc_vcpu()
549 vcpu = vm->vcpu[vcpuid]; in vm_alloc_vcpu()
550 if (vcpu == NULL && !vm->dying) { in vm_alloc_vcpu()
558 atomic_store_rel_ptr((uintptr_t *)&vm->vcpu[vcpuid], in vm_alloc_vcpu()
561 sx_xunlock(&vm->vcpus_init_lock); in vm_alloc_vcpu()
568 sx_slock(&vm->vcpus_init_lock); in vm_slock_vcpus()
574 sx_unlock(&vm->vcpus_init_lock); in vm_unlock_vcpus()
578 * The default CPU topology is a single thread per package.
605 strcpy(vm->name, name); in vm_create()
606 vm->vmspace = vmspace; in vm_create()
607 vm_mem_init(&vm->mem); in vm_create()
608 mtx_init(&vm->rendezvous_mtx, "vm rendezvous lock", 0, MTX_DEF); in vm_create()
609 sx_init(&vm->vcpus_init_lock, "vm vcpus"); in vm_create()
610 vm->vcpu = malloc(sizeof(*vm->vcpu) * vm_maxcpu, M_VM, M_WAITOK | in vm_create()
613 vm->sockets = 1; in vm_create()
614 vm->cores = cores_per_package; /* XXX backwards compatibility */ in vm_create()
615 vm->threads = threads_per_core; /* XXX backwards compatibility */ in vm_create()
616 vm->maxcpus = vm_maxcpu; in vm_create()
628 *sockets = vm->sockets; in vm_get_topology()
629 *cores = vm->cores; in vm_get_topology()
630 *threads = vm->threads; in vm_get_topology()
631 *maxcpus = vm->maxcpus; in vm_get_topology()
637 return (vm->maxcpus); in vm_get_maxcpus()
645 if ((sockets * cores * threads) > vm->maxcpus) in vm_set_topology()
647 vm->sockets = sockets; in vm_set_topology()
648 vm->cores = cores; in vm_set_topology()
649 vm->threads = threads; in vm_set_topology()
663 if (vm->iommu != NULL) in vm_cleanup()
664 iommu_destroy_domain(vm->iommu); in vm_cleanup()
667 vrtc_cleanup(vm->vrtc); in vm_cleanup()
669 vrtc_reset(vm->vrtc); in vm_cleanup()
670 vpmtmr_cleanup(vm->vpmtmr); in vm_cleanup()
671 vatpit_cleanup(vm->vatpit); in vm_cleanup()
672 vhpet_cleanup(vm->vhpet); in vm_cleanup()
673 vatpic_cleanup(vm->vatpic); in vm_cleanup()
674 vioapic_cleanup(vm->vioapic); in vm_cleanup()
676 for (int i = 0; i < vm->maxcpus; i++) { in vm_cleanup()
677 if (vm->vcpu[i] != NULL) in vm_cleanup()
678 vcpu_cleanup(vm->vcpu[i], destroy); in vm_cleanup()
681 vmmops_cleanup(vm->cookie); in vm_cleanup()
688 vmmops_vmspace_free(vm->vmspace); in vm_cleanup()
689 vm->vmspace = NULL; in vm_cleanup()
691 free(vm->vcpu, M_VM); in vm_cleanup()
692 sx_destroy(&vm->vcpus_init_lock); in vm_cleanup()
693 mtx_destroy(&vm->rendezvous_mtx); in vm_cleanup()
712 if (CPU_CMP(&vm->suspended_cpus, &vm->active_cpus) == 0) { in vm_reinit()
726 return (vm->name); in vm_name()
734 if ((obj = vmm_mmio_alloc(vm->vmspace, gpa, len, hpa)) == NULL) in vm_map_mmio()
744 vmm_mmio_free(vm->vmspace, gpa, len); in vm_unmap_mmio()
755 sx_assert(&vm->mem.mem_segs_lock, SX_LOCKED); in vm_iommu_map()
761 mm = &vm->mem.mem_maps[i]; in vm_iommu_map()
762 KASSERT((mm->flags & VM_MEMMAP_F_IOMMU) == 0, in vm_iommu_map()
764 mm->gpa, mm->len, mm->flags)); in vm_iommu_map()
765 if ((mm->flags & VM_MEMMAP_F_WIRED) == 0) in vm_iommu_map()
767 mm->flags |= VM_MEMMAP_F_IOMMU; in vm_iommu_map()
769 for (gpa = mm->gpa; gpa < mm->gpa + mm->len; gpa += PAGE_SIZE) { in vm_iommu_map()
770 hpa = pmap_extract(vmspace_pmap(vm->vmspace), gpa); in vm_iommu_map()
775 * Because we are in pass-through mode, the in vm_iommu_map()
788 iommu_create_mapping(vm->iommu, gpa, hpa, PAGE_SIZE); in vm_iommu_map()
803 sx_assert(&vm->mem.mem_segs_lock, SX_LOCKED); in vm_iommu_unmap()
809 mm = &vm->mem.mem_maps[i]; in vm_iommu_unmap()
810 if ((mm->flags & VM_MEMMAP_F_IOMMU) == 0) in vm_iommu_unmap()
812 mm->flags &= ~VM_MEMMAP_F_IOMMU; in vm_iommu_unmap()
813 KASSERT((mm->flags & VM_MEMMAP_F_WIRED) != 0, in vm_iommu_unmap()
815 mm->gpa, mm->len, mm->flags)); in vm_iommu_unmap()
817 for (gpa = mm->gpa; gpa < mm->gpa + mm->len; gpa += PAGE_SIZE) { in vm_iommu_unmap()
819 vmspace_pmap(vm->vmspace), gpa))), in vm_iommu_unmap()
822 iommu_remove_mapping(vm->iommu, gpa, PAGE_SIZE); in vm_iommu_unmap()
830 error = iommu_invalidate_tlb(vm->iommu); in vm_iommu_unmap()
858 KASSERT(vm->iommu == NULL, in vm_assign_pptdev()
861 vm->iommu = iommu_create_domain(maxaddr); in vm_assign_pptdev()
862 if (vm->iommu == NULL) in vm_assign_pptdev()
880 return (vmmops_getreg(vcpu->cookie, reg, retval)); in vm_get_register()
891 error = vmmops_setreg(vcpu->cookie, reg, val); in vm_set_register()
897 vcpu->nextrip = val; in vm_set_register()
940 return (vmmops_getdesc(vcpu->cookie, reg, desc)); in vm_get_seg_desc()
950 return (vmmops_setdesc(vcpu->cookie, reg, desc)); in vm_set_seg_desc()
962 fpurestore(vcpu->guestfpu); in restore_guest_fpustate()
966 load_xcr(0, vcpu->guest_xcr0); in restore_guest_fpustate()
984 vcpu->guest_xcr0 = rxcr(0); in save_guest_fpustate()
990 fpusave(vcpu->guestfpu); in save_guest_fpustate()
1010 while (vcpu->state != VCPU_IDLE) { in vcpu_set_state_locked()
1011 vcpu->reqidle = 1; in vcpu_set_state_locked()
1014 "idle requested", vcpu_state2str(vcpu->state)); in vcpu_set_state_locked()
1015 msleep_spin(&vcpu->state, &vcpu->mtx, "vmstat", hz); in vcpu_set_state_locked()
1018 KASSERT(vcpu->state != VCPU_IDLE, ("invalid transition from " in vcpu_set_state_locked()
1022 if (vcpu->state == VCPU_RUNNING) { in vcpu_set_state_locked()
1023 KASSERT(vcpu->hostcpu == curcpu, ("curcpu %d and hostcpu %d " in vcpu_set_state_locked()
1024 "mismatch for running vcpu", curcpu, vcpu->hostcpu)); in vcpu_set_state_locked()
1026 KASSERT(vcpu->hostcpu == NOCPU, ("Invalid hostcpu %d for a " in vcpu_set_state_locked()
1027 "vcpu that is not running", vcpu->hostcpu)); in vcpu_set_state_locked()
1032 * IDLE -> FROZEN -> IDLE in vcpu_set_state_locked()
1033 * FROZEN -> RUNNING -> FROZEN in vcpu_set_state_locked()
1034 * FROZEN -> SLEEPING -> FROZEN in vcpu_set_state_locked()
1036 switch (vcpu->state) { in vcpu_set_state_locked()
1054 vcpu_state2str(vcpu->state), vcpu_state2str(newstate)); in vcpu_set_state_locked()
1056 vcpu->state = newstate; in vcpu_set_state_locked()
1058 vcpu->hostcpu = curcpu; in vcpu_set_state_locked()
1060 vcpu->hostcpu = NOCPU; in vcpu_set_state_locked()
1063 wakeup(&vcpu->state); in vcpu_set_state_locked()
1089 struct vm *vm = vcpu->vm; in vm_handle_rendezvous()
1094 vcpuid = vcpu->vcpuid; in vm_handle_rendezvous()
1096 mtx_lock(&vm->rendezvous_mtx); in vm_handle_rendezvous()
1097 while (vm->rendezvous_func != NULL) { in vm_handle_rendezvous()
1099 CPU_AND(&vm->rendezvous_req_cpus, &vm->rendezvous_req_cpus, &vm->active_cpus); in vm_handle_rendezvous()
1101 if (CPU_ISSET(vcpuid, &vm->rendezvous_req_cpus) && in vm_handle_rendezvous()
1102 !CPU_ISSET(vcpuid, &vm->rendezvous_done_cpus)) { in vm_handle_rendezvous()
1104 (*vm->rendezvous_func)(vcpu, vm->rendezvous_arg); in vm_handle_rendezvous()
1105 CPU_SET(vcpuid, &vm->rendezvous_done_cpus); in vm_handle_rendezvous()
1107 if (CPU_CMP(&vm->rendezvous_req_cpus, in vm_handle_rendezvous()
1108 &vm->rendezvous_done_cpus) == 0) { in vm_handle_rendezvous()
1110 CPU_ZERO(&vm->rendezvous_req_cpus); in vm_handle_rendezvous()
1111 vm->rendezvous_func = NULL; in vm_handle_rendezvous()
1112 wakeup(&vm->rendezvous_func); in vm_handle_rendezvous()
1116 mtx_sleep(&vm->rendezvous_func, &vm->rendezvous_mtx, 0, in vm_handle_rendezvous()
1119 mtx_unlock(&vm->rendezvous_mtx); in vm_handle_rendezvous()
1123 mtx_lock(&vm->rendezvous_mtx); in vm_handle_rendezvous()
1126 mtx_unlock(&vm->rendezvous_mtx); in vm_handle_rendezvous()
1136 struct vm *vm = vcpu->vm; in vm_handle_hlt()
1141 vcpuid = vcpu->vcpuid; in vm_handle_hlt()
1147 KASSERT(!CPU_ISSET(vcpuid, &vm->halted_cpus), ("vcpu already halted")); in vm_handle_hlt()
1160 if (vm->rendezvous_func != NULL || vm->suspend || vcpu->reqidle) in vm_handle_hlt()
1166 vlapic_pending_intr(vcpu->vlapic, NULL)) { in vm_handle_hlt()
1189 CPU_SET_ATOMIC(vcpuid, &vm->halted_cpus); in vm_handle_hlt()
1191 if (CPU_CMP(&vm->halted_cpus, &vm->active_cpus) == 0) { in vm_handle_hlt()
1202 * XXX msleep_spin() cannot be interrupted by signals so in vm_handle_hlt()
1203 * wake up periodically to check pending signals. in vm_handle_hlt()
1205 msleep_spin(vcpu, &vcpu->mtx, wmesg, hz); in vm_handle_hlt()
1207 vmm_stat_incr(vcpu, VCPU_IDLE_TICKS, ticks - t); in vm_handle_hlt()
1214 &vm->halted_cpus); in vm_handle_hlt()
1223 CPU_CLR_ATOMIC(vcpuid, &vm->halted_cpus); in vm_handle_hlt()
1236 struct vm *vm = vcpu->vm; in vm_handle_paging()
1241 vme = &vcpu->exitinfo; in vm_handle_paging()
1243 KASSERT(vme->inst_length == 0, ("%s: invalid inst_length %d", in vm_handle_paging()
1244 __func__, vme->inst_length)); in vm_handle_paging()
1246 ftype = vme->u.paging.fault_type; in vm_handle_paging()
1252 rv = pmap_emulate_accessed_dirty(vmspace_pmap(vm->vmspace), in vm_handle_paging()
1253 vme->u.paging.gpa, ftype); in vm_handle_paging()
1257 vme->u.paging.gpa); in vm_handle_paging()
1262 map = &vm->vmspace->vm_map; in vm_handle_paging()
1263 rv = vm_fault(map, vme->u.paging.gpa, ftype, VM_FAULT_NORMAL, NULL); in vm_handle_paging()
1266 "ftype = %d", rv, vme->u.paging.gpa, ftype); in vm_handle_paging()
1286 vme = &vcpu->exitinfo; in vm_handle_inst_emul()
1288 KASSERT(vme->inst_length == 0, ("%s: invalid inst_length %d", in vm_handle_inst_emul()
1289 __func__, vme->inst_length)); in vm_handle_inst_emul()
1291 gla = vme->u.inst_emul.gla; in vm_handle_inst_emul()
1292 gpa = vme->u.inst_emul.gpa; in vm_handle_inst_emul()
1293 cs_base = vme->u.inst_emul.cs_base; in vm_handle_inst_emul()
1294 cs_d = vme->u.inst_emul.cs_d; in vm_handle_inst_emul()
1295 vie = &vme->u.inst_emul.vie; in vm_handle_inst_emul()
1296 paging = &vme->u.inst_emul.paging; in vm_handle_inst_emul()
1297 cpu_mode = paging->cpu_mode; in vm_handle_inst_emul()
1302 if (vie->num_valid == 0) { in vm_handle_inst_emul()
1303 error = vmm_fetch_instruction(vcpu, paging, vme->rip + cs_base, in vm_handle_inst_emul()
1316 vme->rip + cs_base); in vm_handle_inst_emul()
1324 vme->inst_length = vie->num_processed; in vm_handle_inst_emul()
1325 vcpu->nextrip += vie->num_processed; in vm_handle_inst_emul()
1327 vcpu->nextrip); in vm_handle_inst_emul()
1329 /* return to userland unless this is an in-kernel emulated device */ in vm_handle_inst_emul()
1353 struct vm *vm = vcpu->vm; in vm_handle_suspend()
1360 CPU_SET_ATOMIC(vcpu->vcpuid, &vm->suspended_cpus); in vm_handle_suspend()
1371 if (CPU_CMP(&vm->suspended_cpus, &vm->active_cpus) == 0) { in vm_handle_suspend()
1376 if (vm->rendezvous_func == NULL) { in vm_handle_suspend()
1379 msleep_spin(vcpu, &vcpu->mtx, "vmsusp", hz); in vm_handle_suspend()
1398 for (i = 0; i < vm->maxcpus; i++) { in vm_handle_suspend()
1399 if (CPU_ISSET(i, &vm->suspended_cpus)) { in vm_handle_suspend()
1412 KASSERT(vcpu->reqidle, ("invalid vcpu reqidle %d", vcpu->reqidle)); in vm_handle_reqidle()
1413 vcpu->reqidle = 0; in vm_handle_reqidle()
1428 if (!vme->u.dbg.pushf_intercept || vme->u.dbg.tf_shadow_val != 0) { in vm_handle_db()
1433 error = vm_copy_setup(vcpu, &vme->u.dbg.paging, rsp, sizeof(uint64_t), in vm_handle_db()
1461 if (atomic_cmpset_int(&vm->suspend, 0, how) == 0) { in vm_suspend()
1463 vm->suspend, how); in vm_suspend()
1472 for (i = 0; i < vm->maxcpus; i++) { in vm_suspend()
1473 if (CPU_ISSET(i, &vm->active_cpus)) in vm_suspend()
1483 struct vm *vm = vcpu->vm; in vm_exit_suspended()
1486 KASSERT(vm->suspend > VM_SUSPEND_NONE && vm->suspend < VM_SUSPEND_LAST, in vm_exit_suspended()
1487 ("vm_exit_suspended: invalid suspend type %d", vm->suspend)); in vm_exit_suspended()
1490 vmexit->rip = rip; in vm_exit_suspended()
1491 vmexit->inst_length = 0; in vm_exit_suspended()
1492 vmexit->exitcode = VM_EXITCODE_SUSPENDED; in vm_exit_suspended()
1493 vmexit->u.suspended.how = vm->suspend; in vm_exit_suspended()
1502 vmexit->rip = rip; in vm_exit_debug()
1503 vmexit->inst_length = 0; in vm_exit_debug()
1504 vmexit->exitcode = VM_EXITCODE_DEBUG; in vm_exit_debug()
1513 vmexit->rip = rip; in vm_exit_rendezvous()
1514 vmexit->inst_length = 0; in vm_exit_rendezvous()
1515 vmexit->exitcode = VM_EXITCODE_RENDEZVOUS; in vm_exit_rendezvous()
1525 vmexit->rip = rip; in vm_exit_reqidle()
1526 vmexit->inst_length = 0; in vm_exit_reqidle()
1527 vmexit->exitcode = VM_EXITCODE_REQIDLE; in vm_exit_reqidle()
1537 vmexit->rip = rip; in vm_exit_astpending()
1538 vmexit->inst_length = 0; in vm_exit_astpending()
1539 vmexit->exitcode = VM_EXITCODE_BOGUS; in vm_exit_astpending()
1546 struct vm *vm = vcpu->vm; in vm_run()
1555 vcpuid = vcpu->vcpuid; in vm_run()
1557 if (!CPU_ISSET(vcpuid, &vm->active_cpus)) in vm_run()
1560 if (CPU_ISSET(vcpuid, &vm->suspended_cpus)) in vm_run()
1563 pmap = vmspace_pmap(vm->vmspace); in vm_run()
1564 vme = &vcpu->exitinfo; in vm_run()
1565 evinfo.rptr = &vm->rendezvous_req_cpus; in vm_run()
1566 evinfo.sptr = &vm->suspend; in vm_run()
1567 evinfo.iptr = &vcpu->reqidle; in vm_run()
1571 KASSERT(!CPU_ISSET(curcpu, &pmap->pm_active), in vm_run()
1582 error = vmmops_run(vcpu->cookie, vcpu->nextrip, pmap, &evinfo); in vm_run()
1587 vmm_stat_incr(vcpu, VCPU_TOTAL_RUNTIME, rdtsc() - tscval); in vm_run()
1593 vcpu->nextrip = vme->rip + vme->inst_length; in vm_run()
1594 switch (vme->exitcode) { in vm_run()
1602 vioapic_process_eoi(vm, vme->u.ioapic_eoi.vector); in vm_run()
1608 intr_disabled = ((vme->u.hlt.rflags & PSL_I) == 0); in vm_run()
1639 if (error == 0 && vme->exitcode == VM_EXITCODE_IPI) in vm_run()
1646 VMM_CTR2(vcpu, "retu %d/%d", error, vme->exitcode); in vm_run()
1666 vcpu->exitinfo.inst_length = 0; in vm_restart_instruction()
1668 "setting inst_length to zero", vcpu->exitinfo.rip); in vm_restart_instruction()
1679 "nextrip from %#lx to %#lx", vcpu->nextrip, rip); in vm_restart_instruction()
1680 vcpu->nextrip = rip; in vm_restart_instruction()
1705 vcpu->exitintinfo = info; in vm_exit_intinfo()
1726 /* Table 6-4, "Interrupt and Exception Classes", Intel SDM, Vol 3 */ in exception_class()
1736 * SVM and VT-x use identical type values to represent NMI, in exception_class()
1739 * SVM uses type '3' for all exceptions. VT-x uses type '3' in exception_class()
1774 * If an exception occurs while attempting to call the double-fault in nested_fault()
1782 vm_suspend(vcpu->vm, VM_SUSPEND_TRIPLEFAULT); in nested_fault()
1788 * Table 6-5 "Conditions for Generating a Double Fault", Intel SDM, Vol3 in nested_fault()
1810 if (vcpu->exception_pending) { in vcpu_exception_intinfo()
1811 info = vcpu->exc_vector & 0xff; in vcpu_exception_intinfo()
1813 if (vcpu->exc_errcode_valid) { in vcpu_exception_intinfo()
1815 info |= (uint64_t)vcpu->exc_errcode << 32; in vcpu_exception_intinfo()
1827 info1 = vcpu->exitintinfo; in vm_entry_intinfo()
1828 vcpu->exitintinfo = 0; in vm_entry_intinfo()
1831 if (vcpu->exception_pending) { in vm_entry_intinfo()
1833 vcpu->exception_pending = 0; in vm_entry_intinfo()
1835 vcpu->exc_vector, info2); in vm_entry_intinfo()
1861 *info1 = vcpu->exitintinfo; in vm_get_intinfo()
1884 if (vcpu->exception_pending) { in vm_inject_exception()
1886 "pending exception %d", vector, vcpu->exc_vector); in vm_inject_exception()
1913 vcpu->exception_pending = 1; in vm_inject_exception()
1914 vcpu->exc_vector = vector; in vm_inject_exception()
1915 vcpu->exc_errcode = errcode; in vm_inject_exception()
1916 vcpu->exc_errcode_valid = errcode_valid; in vm_inject_exception()
1953 vcpu->nmi_pending = 1; in vm_inject_nmi()
1961 return (vcpu->nmi_pending); in vm_nmi_pending()
1967 if (vcpu->nmi_pending == 0) in vm_nmi_clear()
1970 vcpu->nmi_pending = 0; in vm_nmi_clear()
1980 vcpu->extint_pending = 1; in vm_inject_extint()
1988 return (vcpu->extint_pending); in vm_extint_pending()
1994 if (vcpu->extint_pending == 0) in vm_extint_clear()
1997 vcpu->extint_pending = 0; in vm_extint_clear()
2007 return (vmmops_getcap(vcpu->cookie, type, retval)); in vm_get_capability()
2016 return (vmmops_setcap(vcpu->cookie, type, val)); in vm_set_capability()
2022 return (vcpu->vm); in vcpu_vm()
2028 return (vcpu->vcpuid); in vcpu_vcpuid()
2034 return (vm->vcpu[vcpuid]); in vm_vcpu()
2040 return (vcpu->vlapic); in vm_lapic()
2047 return (vm->vioapic); in vm_ioapic()
2054 return (vm->vhpet); in vm_hpet()
2071 * names instead of a single one - yuck! in vmm_is_pptdev()
2103 return (vm->iommu); in vm_iommu_domain()
2124 state = vcpu->state; in vcpu_get_state()
2126 *hostcpu = vcpu->hostcpu; in vcpu_get_state()
2135 struct vm *vm = vcpu->vm; in vm_activate_cpu()
2137 if (CPU_ISSET(vcpu->vcpuid, &vm->active_cpus)) in vm_activate_cpu()
2141 CPU_SET_ATOMIC(vcpu->vcpuid, &vm->active_cpus); in vm_activate_cpu()
2149 vm->debug_cpus = vm->active_cpus; in vm_suspend_cpu()
2150 for (int i = 0; i < vm->maxcpus; i++) { in vm_suspend_cpu()
2151 if (CPU_ISSET(i, &vm->active_cpus)) in vm_suspend_cpu()
2155 if (!CPU_ISSET(vcpu->vcpuid, &vm->active_cpus)) in vm_suspend_cpu()
2158 CPU_SET_ATOMIC(vcpu->vcpuid, &vm->debug_cpus); in vm_suspend_cpu()
2169 CPU_ZERO(&vm->debug_cpus); in vm_resume_cpu()
2171 if (!CPU_ISSET(vcpu->vcpuid, &vm->debug_cpus)) in vm_resume_cpu()
2174 CPU_CLR_ATOMIC(vcpu->vcpuid, &vm->debug_cpus); in vm_resume_cpu()
2183 return (CPU_ISSET(vcpu->vcpuid, &vcpu->vm->debug_cpus)); in vcpu_debugged()
2190 return (vm->active_cpus); in vm_active_cpus()
2197 return (vm->debug_cpus); in vm_debug_cpus()
2204 return (vm->suspended_cpus); in vm_suspended_cpus()
2216 mtx_lock(&vm->rendezvous_mtx); in vm_start_cpus()
2217 CPU_AND(&set, &vm->startup_cpus, tostart); in vm_start_cpus()
2218 CPU_ANDNOT(&vm->startup_cpus, &vm->startup_cpus, &set); in vm_start_cpus()
2219 mtx_unlock(&vm->rendezvous_mtx); in vm_start_cpus()
2226 mtx_lock(&vm->rendezvous_mtx); in vm_await_start()
2227 CPU_OR(&vm->startup_cpus, &vm->startup_cpus, waiting); in vm_await_start()
2228 mtx_unlock(&vm->rendezvous_mtx); in vm_await_start()
2235 return (vcpu->stats); in vcpu_stats()
2241 *state = vcpu->x2apic_state; in vm_get_x2apic_state()
2252 vcpu->x2apic_state = state; in vm_set_x2apic_state()
2262 * - If the vcpu thread is sleeping then it is woken up.
2263 * - If the vcpu is running on a different host_cpu then an IPI will be directed
2271 hostcpu = vcpu->hostcpu; in vcpu_notify_event_locked()
2272 if (vcpu->state == VCPU_RUNNING) { in vcpu_notify_event_locked()
2276 vlapic_post_intr(vcpu->vlapic, hostcpu, in vcpu_notify_event_locked()
2291 "with hostcpu %d", vcpu->state, hostcpu)); in vcpu_notify_event_locked()
2292 if (vcpu->state == VCPU_SLEEPING) in vcpu_notify_event_locked()
2308 return (vm->vmspace); in vm_vmspace()
2314 return (&vm->mem); in vm_mem()
2330 struct vm *vm = vcpu->vm; in vm_smp_rendezvous()
2339 mtx_lock(&vm->rendezvous_mtx); in vm_smp_rendezvous()
2340 if (vm->rendezvous_func != NULL) { in vm_smp_rendezvous()
2347 mtx_unlock(&vm->rendezvous_mtx); in vm_smp_rendezvous()
2353 KASSERT(vm->rendezvous_func == NULL, ("vm_smp_rendezvous: previous " in vm_smp_rendezvous()
2357 vm->rendezvous_req_cpus = dest; in vm_smp_rendezvous()
2358 CPU_ZERO(&vm->rendezvous_done_cpus); in vm_smp_rendezvous()
2359 vm->rendezvous_arg = arg; in vm_smp_rendezvous()
2360 vm->rendezvous_func = func; in vm_smp_rendezvous()
2361 mtx_unlock(&vm->rendezvous_mtx); in vm_smp_rendezvous()
2364 * Wake up any sleeping vcpus and trigger a VM-exit in any running in vm_smp_rendezvous()
2367 for (i = 0; i < vm->maxcpus; i++) { in vm_smp_rendezvous()
2378 return (vm->vatpic); in vm_atpic()
2384 return (vm->vatpit); in vm_atpit()
2391 return (vm->vpmtmr); in vm_pmtmr()
2398 return (vm->vrtc); in vm_rtc()
2451 n = min(remaining, PAGE_SIZE - off); in vm_copy_setup()
2454 remaining -= n; in vm_copy_setup()
2487 len -= copyinfo[idx].len; in vm_copyin()
2503 len -= copyinfo[idx].len; in vm_copyout()
2510 * Return the amount of in-use and wired memory for the VM. Since
2520 if (vcpu->vcpuid == 0) { in vm_get_rescnt()
2522 vmspace_resident_count(vcpu->vm->vmspace)); in vm_get_rescnt()
2530 if (vcpu->vcpuid == 0) { in vm_get_wiredcnt()
2532 pmap_wired_count(vmspace_pmap(vcpu->vm->vmspace))); in vm_get_wiredcnt()
2551 vcpu = vm->vcpu[i]; in vm_snapshot_vcpus()
2555 SNAPSHOT_VAR_OR_LEAVE(vcpu->x2apic_state, meta, ret, done); in vm_snapshot_vcpus()
2556 SNAPSHOT_VAR_OR_LEAVE(vcpu->exitintinfo, meta, ret, done); in vm_snapshot_vcpus()
2557 SNAPSHOT_VAR_OR_LEAVE(vcpu->exc_vector, meta, ret, done); in vm_snapshot_vcpus()
2558 SNAPSHOT_VAR_OR_LEAVE(vcpu->exc_errcode_valid, meta, ret, done); in vm_snapshot_vcpus()
2559 SNAPSHOT_VAR_OR_LEAVE(vcpu->exc_errcode, meta, ret, done); in vm_snapshot_vcpus()
2560 SNAPSHOT_VAR_OR_LEAVE(vcpu->guest_xcr0, meta, ret, done); in vm_snapshot_vcpus()
2561 SNAPSHOT_VAR_OR_LEAVE(vcpu->exitinfo, meta, ret, done); in vm_snapshot_vcpus()
2562 SNAPSHOT_VAR_OR_LEAVE(vcpu->nextrip, meta, ret, done); in vm_snapshot_vcpus()
2570 tsc = now + vcpu->tsc_offset; in vm_snapshot_vcpus()
2572 if (meta->op == VM_SNAPSHOT_RESTORE) in vm_snapshot_vcpus()
2573 vcpu->tsc_offset = tsc; in vm_snapshot_vcpus()
2589 SNAPSHOT_VAR_OR_LEAVE(vm->startup_cpus, meta, ret, done); in vm_snapshot_vm()
2605 vcpu = vm->vcpu[i]; in vm_snapshot_vcpu()
2609 error = vmmops_vcpu_snapshot(vcpu->cookie, meta); in vm_snapshot_vcpu()
2622 * Save kernel-side structures to user-space for snapshotting.
2629 switch (meta->dev_req) { in vm_snapshot_req()
2659 __func__, meta->dev_req); in vm_snapshot_req()
2668 vcpu->tsc_offset = offset; in vm_set_tsc_offset()
2687 vcpu = vm->vcpu[i]; in vm_restore_time()
2691 error = vmmops_restore_tsc(vcpu->cookie, in vm_restore_time()
2692 vcpu->tsc_offset - now); in vm_restore_time()