Lines Matching refs:vcpu

102 struct vcpu {  struct
169 struct vcpu **vcpu; /* (o) guest vcpus */ member
178 #define VMM_CTR0(vcpu, format) \ argument
179 VCPU_CTR0((vcpu)->vm, (vcpu)->vcpuid, format)
181 #define VMM_CTR1(vcpu, format, p1) \ argument
182 VCPU_CTR1((vcpu)->vm, (vcpu)->vcpuid, format, p1)
184 #define VMM_CTR2(vcpu, format, p1, p2) \ argument
185 VCPU_CTR2((vcpu)->vm, (vcpu)->vcpuid, format, p1, p2)
187 #define VMM_CTR3(vcpu, format, p1, p2, p3) \ argument
188 VCPU_CTR3((vcpu)->vm, (vcpu)->vcpuid, format, p1, p2, p3)
190 #define VMM_CTR4(vcpu, format, p1, p2, p3, p4) \ argument
191 VCPU_CTR4((vcpu)->vm, (vcpu)->vcpuid, format, p1, p2, p3, p4)
222 DEFINE_VMMOPS_IFUNC(void *, vcpu_init, (void *vmi, struct vcpu *vcpu,
278 static void vcpu_notify_event_locked(struct vcpu *vcpu, bool lapic_intr);
332 vcpu_cleanup(struct vcpu *vcpu, bool destroy) in vcpu_cleanup() argument
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()
340 vcpu_lock_destroy(vcpu); in vcpu_cleanup()
341 free(vcpu, M_VM); in vcpu_cleanup()
345 static struct vcpu *
348 struct vcpu *vcpu; in vcpu_alloc() local
353 vcpu = malloc(sizeof(*vcpu), M_VM, M_WAITOK | M_ZERO); in vcpu_alloc()
354 vcpu_lock_init(vcpu); 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()
362 return (vcpu); in vcpu_alloc()
366 vcpu_init(struct vcpu *vcpu) in vcpu_init() argument
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()
370 vm_set_x2apic_state(vcpu, X2APIC_DISABLED); 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()
382 vcpu_trace_exceptions(struct vcpu *vcpu) in vcpu_trace_exceptions() argument
389 vcpu_trap_wbinvd(struct vcpu *vcpu) in vcpu_trap_wbinvd() argument
395 vm_exitinfo(struct vcpu *vcpu) in vm_exitinfo() argument
397 return (&vcpu->exitinfo); in vm_exitinfo()
401 vm_exitinfo_cpuset(struct vcpu *vcpu) in vm_exitinfo_cpuset() argument
403 return (&vcpu->exitinfo_cpuset); in vm_exitinfo_cpuset()
521 if (vm->vcpu[i] != NULL) in vm_init()
522 vcpu_init(vm->vcpu[i]); in vm_init()
535 struct vcpu *
538 struct vcpu *vcpu; in vm_alloc_vcpu() local
543 vcpu = (struct vcpu *) in vm_alloc_vcpu()
544 atomic_load_acq_ptr((uintptr_t *)&vm->vcpu[vcpuid]); in vm_alloc_vcpu()
545 if (__predict_true(vcpu != NULL)) in vm_alloc_vcpu()
546 return (vcpu); in vm_alloc_vcpu()
549 vcpu = vm->vcpu[vcpuid]; in vm_alloc_vcpu()
550 if (vcpu == NULL && !vm->dying) { in vm_alloc_vcpu()
551 vcpu = vcpu_alloc(vm, vcpuid); in vm_alloc_vcpu()
552 vcpu_init(vcpu); in vm_alloc_vcpu()
558 atomic_store_rel_ptr((uintptr_t *)&vm->vcpu[vcpuid], in vm_alloc_vcpu()
559 (uintptr_t)vcpu); in vm_alloc_vcpu()
562 return (vcpu); in vm_alloc_vcpu()
610 vm->vcpu = malloc(sizeof(*vm->vcpu) * vm_maxcpu, M_VM, M_WAITOK | in vm_create()
677 if (vm->vcpu[i] != NULL) in vm_cleanup()
678 vcpu_cleanup(vm->vcpu[i], destroy); in vm_cleanup()
691 free(vm->vcpu, M_VM); in vm_cleanup()
869 vm_get_register(struct vcpu *vcpu, int reg, uint64_t *retval) in vm_get_register() argument
875 return (vmmops_getreg(vcpu->cookie, reg, retval)); in vm_get_register()
879 vm_set_register(struct vcpu *vcpu, int reg, uint64_t val) in vm_set_register() argument
886 error = vmmops_setreg(vcpu->cookie, reg, val); in vm_set_register()
891 VMM_CTR1(vcpu, "Setting nextrip to %#lx", val); in vm_set_register()
892 vcpu->nextrip = val; in vm_set_register()
929 vm_get_seg_desc(struct vcpu *vcpu, int reg, struct seg_desc *desc) in vm_get_seg_desc() argument
935 return (vmmops_getdesc(vcpu->cookie, reg, desc)); in vm_get_seg_desc()
939 vm_set_seg_desc(struct vcpu *vcpu, int reg, struct seg_desc *desc) in vm_set_seg_desc() argument
945 return (vmmops_setdesc(vcpu->cookie, reg, desc)); in vm_set_seg_desc()
949 restore_guest_fpustate(struct vcpu *vcpu) in restore_guest_fpustate() argument
957 fpurestore(vcpu->guestfpu); in restore_guest_fpustate()
961 load_xcr(0, vcpu->guest_xcr0); in restore_guest_fpustate()
971 save_guest_fpustate(struct vcpu *vcpu) in save_guest_fpustate() argument
979 vcpu->guest_xcr0 = rxcr(0); in save_guest_fpustate()
985 fpusave(vcpu->guestfpu); in save_guest_fpustate()
992 vcpu_set_state_locked(struct vcpu *vcpu, enum vcpu_state newstate, in vcpu_set_state_locked() argument
997 vcpu_assert_locked(vcpu); in vcpu_set_state_locked()
1005 while (vcpu->state != VCPU_IDLE) { in vcpu_set_state_locked()
1006 vcpu->reqidle = 1; in vcpu_set_state_locked()
1007 vcpu_notify_event_locked(vcpu, false); in vcpu_set_state_locked()
1008 VMM_CTR1(vcpu, "vcpu state change from %s to " in vcpu_set_state_locked()
1009 "idle requested", vcpu_state2str(vcpu->state)); in vcpu_set_state_locked()
1010 msleep_spin(&vcpu->state, &vcpu->mtx, "vmstat", hz); in vcpu_set_state_locked()
1013 KASSERT(vcpu->state != VCPU_IDLE, ("invalid transition from " in vcpu_set_state_locked()
1017 if (vcpu->state == VCPU_RUNNING) { in vcpu_set_state_locked()
1018 KASSERT(vcpu->hostcpu == curcpu, ("curcpu %d and hostcpu %d " in vcpu_set_state_locked()
1019 "mismatch for running vcpu", curcpu, vcpu->hostcpu)); in vcpu_set_state_locked()
1021 KASSERT(vcpu->hostcpu == NOCPU, ("Invalid hostcpu %d for a " in vcpu_set_state_locked()
1022 "vcpu that is not running", vcpu->hostcpu)); in vcpu_set_state_locked()
1031 switch (vcpu->state) { in vcpu_set_state_locked()
1048 VMM_CTR2(vcpu, "vcpu state changed from %s to %s", in vcpu_set_state_locked()
1049 vcpu_state2str(vcpu->state), vcpu_state2str(newstate)); in vcpu_set_state_locked()
1051 vcpu->state = newstate; in vcpu_set_state_locked()
1053 vcpu->hostcpu = curcpu; in vcpu_set_state_locked()
1055 vcpu->hostcpu = NOCPU; in vcpu_set_state_locked()
1058 wakeup(&vcpu->state); in vcpu_set_state_locked()
1064 vcpu_require_state(struct vcpu *vcpu, enum vcpu_state newstate) in vcpu_require_state() argument
1068 if ((error = vcpu_set_state(vcpu, newstate, false)) != 0) in vcpu_require_state()
1073 vcpu_require_state_locked(struct vcpu *vcpu, enum vcpu_state newstate) in vcpu_require_state_locked() argument
1077 if ((error = vcpu_set_state_locked(vcpu, newstate, false)) != 0) in vcpu_require_state_locked()
1082 vm_handle_rendezvous(struct vcpu *vcpu) in vm_handle_rendezvous() argument
1084 struct vm *vm = vcpu->vm; in vm_handle_rendezvous()
1089 vcpuid = vcpu->vcpuid; in vm_handle_rendezvous()
1098 VMM_CTR0(vcpu, "Calling rendezvous func"); in vm_handle_rendezvous()
1099 (*vm->rendezvous_func)(vcpu, vm->rendezvous_arg); in vm_handle_rendezvous()
1104 VMM_CTR0(vcpu, "Rendezvous completed"); in vm_handle_rendezvous()
1110 VMM_CTR0(vcpu, "Wait for rendezvous completion"); in vm_handle_rendezvous()
1129 vm_handle_hlt(struct vcpu *vcpu, bool intr_disabled, bool *retu) in vm_handle_hlt() argument
1131 struct vm *vm = vcpu->vm; in vm_handle_hlt()
1136 vcpuid = vcpu->vcpuid; in vm_handle_hlt()
1144 vcpu_lock(vcpu); in vm_handle_hlt()
1155 if (vm->rendezvous_func != NULL || vm->suspend || vcpu->reqidle) in vm_handle_hlt()
1157 if (vm_nmi_pending(vcpu)) in vm_handle_hlt()
1160 if (vm_extint_pending(vcpu) || in vm_handle_hlt()
1161 vlapic_pending_intr(vcpu->vlapic, NULL)) { in vm_handle_hlt()
1167 if (vcpu_should_yield(vcpu)) in vm_handle_hlt()
1170 if (vcpu_debugged(vcpu)) in vm_handle_hlt()
1181 VMM_CTR0(vcpu, "Halted"); in vm_handle_hlt()
1195 vcpu_require_state_locked(vcpu, VCPU_SLEEPING); in vm_handle_hlt()
1200 msleep_spin(vcpu, &vcpu->mtx, wmesg, hz); in vm_handle_hlt()
1201 vcpu_require_state_locked(vcpu, VCPU_FROZEN); in vm_handle_hlt()
1202 vmm_stat_incr(vcpu, VCPU_IDLE_TICKS, ticks - t); in vm_handle_hlt()
1204 vcpu_unlock(vcpu); in vm_handle_hlt()
1213 vcpu_lock(vcpu); in vm_handle_hlt()
1220 vcpu_unlock(vcpu); in vm_handle_hlt()
1229 vm_handle_paging(struct vcpu *vcpu, bool *retu) in vm_handle_paging() argument
1231 struct vm *vm = vcpu->vm; in vm_handle_paging()
1236 vme = &vcpu->exitinfo; in vm_handle_paging()
1250 VMM_CTR2(vcpu, "%s bit emulation for gpa %#lx", in vm_handle_paging()
1260 VMM_CTR3(vcpu, "vm_handle_paging rv = %d, gpa = %#lx, " in vm_handle_paging()
1270 vm_handle_inst_emul(struct vcpu *vcpu, bool *retu) in vm_handle_inst_emul() argument
1281 vme = &vcpu->exitinfo; in vm_handle_inst_emul()
1294 VMM_CTR1(vcpu, "inst_emul fault accessing gpa %#lx", gpa); in vm_handle_inst_emul()
1298 error = vmm_fetch_instruction(vcpu, paging, vme->rip + cs_base, in vm_handle_inst_emul()
1309 if (vmm_decode_instruction(vcpu, gla, cpu_mode, cs_d, vie) != 0) { in vm_handle_inst_emul()
1310 VMM_CTR1(vcpu, "Error decoding instruction at %#lx", in vm_handle_inst_emul()
1320 vcpu->nextrip += vie->num_processed; in vm_handle_inst_emul()
1321 VMM_CTR1(vcpu, "nextrip updated to %#lx after instruction decoding", in vm_handle_inst_emul()
1322 vcpu->nextrip); in vm_handle_inst_emul()
1339 error = vmm_emulate_instruction(vcpu, gpa, vie, paging, mread, mwrite, in vm_handle_inst_emul()
1346 vm_handle_suspend(struct vcpu *vcpu, bool *retu) in vm_handle_suspend() argument
1348 struct vm *vm = vcpu->vm; in vm_handle_suspend()
1355 CPU_SET_ATOMIC(vcpu->vcpuid, &vm->suspended_cpus); in vm_handle_suspend()
1364 vcpu_lock(vcpu); in vm_handle_suspend()
1367 VMM_CTR0(vcpu, "All vcpus suspended"); in vm_handle_suspend()
1372 VMM_CTR0(vcpu, "Sleeping during suspend"); in vm_handle_suspend()
1373 vcpu_require_state_locked(vcpu, VCPU_SLEEPING); in vm_handle_suspend()
1374 msleep_spin(vcpu, &vcpu->mtx, "vmsusp", hz); in vm_handle_suspend()
1375 vcpu_require_state_locked(vcpu, VCPU_FROZEN); in vm_handle_suspend()
1377 vcpu_unlock(vcpu); in vm_handle_suspend()
1379 vcpu_lock(vcpu); in vm_handle_suspend()
1382 VMM_CTR0(vcpu, "Rendezvous during suspend"); in vm_handle_suspend()
1383 vcpu_unlock(vcpu); in vm_handle_suspend()
1384 error = vm_handle_rendezvous(vcpu); in vm_handle_suspend()
1385 vcpu_lock(vcpu); in vm_handle_suspend()
1388 vcpu_unlock(vcpu); in vm_handle_suspend()
1404 vm_handle_reqidle(struct vcpu *vcpu, bool *retu) in vm_handle_reqidle() argument
1406 vcpu_lock(vcpu); in vm_handle_reqidle()
1407 KASSERT(vcpu->reqidle, ("invalid vcpu reqidle %d", vcpu->reqidle)); in vm_handle_reqidle()
1408 vcpu->reqidle = 0; in vm_handle_reqidle()
1409 vcpu_unlock(vcpu); in vm_handle_reqidle()
1415 vm_handle_db(struct vcpu *vcpu, struct vm_exit *vme, bool *retu) in vm_handle_db() argument
1427 vm_get_register(vcpu, VM_REG_GUEST_RSP, &rsp); in vm_handle_db()
1428 error = vm_copy_setup(vcpu, &vme->u.dbg.paging, rsp, sizeof(uint64_t), in vm_handle_db()
1476 vm_exit_suspended(struct vcpu *vcpu, uint64_t rip) in vm_exit_suspended() argument
1478 struct vm *vm = vcpu->vm; in vm_exit_suspended()
1484 vmexit = vm_exitinfo(vcpu); in vm_exit_suspended()
1492 vm_exit_debug(struct vcpu *vcpu, uint64_t rip) in vm_exit_debug() argument
1496 vmexit = vm_exitinfo(vcpu); in vm_exit_debug()
1503 vm_exit_rendezvous(struct vcpu *vcpu, uint64_t rip) in vm_exit_rendezvous() argument
1507 vmexit = vm_exitinfo(vcpu); in vm_exit_rendezvous()
1511 vmm_stat_incr(vcpu, VMEXIT_RENDEZVOUS, 1); in vm_exit_rendezvous()
1515 vm_exit_reqidle(struct vcpu *vcpu, uint64_t rip) in vm_exit_reqidle() argument
1519 vmexit = vm_exitinfo(vcpu); in vm_exit_reqidle()
1523 vmm_stat_incr(vcpu, VMEXIT_REQIDLE, 1); in vm_exit_reqidle()
1527 vm_exit_astpending(struct vcpu *vcpu, uint64_t rip) in vm_exit_astpending() argument
1531 vmexit = vm_exitinfo(vcpu); in vm_exit_astpending()
1535 vmm_stat_incr(vcpu, VMEXIT_ASTPENDING, 1); in vm_exit_astpending()
1539 vm_run(struct vcpu *vcpu) in vm_run() argument
1541 struct vm *vm = vcpu->vm; in vm_run()
1550 vcpuid = vcpu->vcpuid; in vm_run()
1559 vme = &vcpu->exitinfo; in vm_run()
1562 evinfo.iptr = &vcpu->reqidle; in vm_run()
1574 restore_guest_fpustate(vcpu); in vm_run()
1576 vcpu_require_state(vcpu, VCPU_RUNNING); in vm_run()
1577 error = vmmops_run(vcpu->cookie, vcpu->nextrip, pmap, &evinfo); in vm_run()
1578 vcpu_require_state(vcpu, VCPU_FROZEN); in vm_run()
1580 save_guest_fpustate(vcpu); in vm_run()
1582 vmm_stat_incr(vcpu, VCPU_TOTAL_RUNTIME, rdtsc() - tscval); in vm_run()
1588 vcpu->nextrip = vme->rip + vme->inst_length; in vm_run()
1591 error = vm_handle_reqidle(vcpu, &retu); in vm_run()
1594 error = vm_handle_suspend(vcpu, &retu); in vm_run()
1600 error = vm_handle_rendezvous(vcpu); in vm_run()
1604 error = vm_handle_hlt(vcpu, intr_disabled, &retu); in vm_run()
1607 error = vm_handle_paging(vcpu, &retu); in vm_run()
1610 error = vm_handle_inst_emul(vcpu, &retu); in vm_run()
1614 error = vm_handle_inout(vcpu, vme, &retu); in vm_run()
1617 error = vm_handle_db(vcpu, vme, &retu); in vm_run()
1622 vm_inject_ud(vcpu); in vm_run()
1635 error = vm_handle_ipi(vcpu, vme, &retu); in vm_run()
1640 vmm_stat_incr(vcpu, VMEXIT_USERSPACE, 1); in vm_run()
1641 VMM_CTR2(vcpu, "retu %d/%d", error, vme->exitcode); in vm_run()
1647 vm_restart_instruction(struct vcpu *vcpu) in vm_restart_instruction() argument
1653 state = vcpu_get_state(vcpu, NULL); in vm_restart_instruction()
1661 vcpu->exitinfo.inst_length = 0; in vm_restart_instruction()
1662 VMM_CTR1(vcpu, "restarting instruction at %#lx by " in vm_restart_instruction()
1663 "setting inst_length to zero", vcpu->exitinfo.rip); in vm_restart_instruction()
1671 error = vm_get_register(vcpu, VM_REG_GUEST_RIP, &rip); in vm_restart_instruction()
1673 VMM_CTR2(vcpu, "restarting instruction by updating " in vm_restart_instruction()
1674 "nextrip from %#lx to %#lx", vcpu->nextrip, rip); in vm_restart_instruction()
1675 vcpu->nextrip = rip; in vm_restart_instruction()
1683 vm_exit_intinfo(struct vcpu *vcpu, uint64_t info) in vm_exit_intinfo() argument
1699 VMM_CTR2(vcpu, "%s: info1(%#lx)", __func__, info); in vm_exit_intinfo()
1700 vcpu->exitintinfo = info; in vm_exit_intinfo()
1759 nested_fault(struct vcpu *vcpu, uint64_t info1, uint64_t info2, in nested_fault() argument
1775 VMM_CTR2(vcpu, "triple fault: info1(%#lx), info2(%#lx)", in nested_fault()
1777 vm_suspend(vcpu->vm, VM_SUSPEND_TRIPLEFAULT); in nested_fault()
1801 vcpu_exception_intinfo(struct vcpu *vcpu) in vcpu_exception_intinfo() argument
1805 if (vcpu->exception_pending) { in vcpu_exception_intinfo()
1806 info = vcpu->exc_vector & 0xff; in vcpu_exception_intinfo()
1808 if (vcpu->exc_errcode_valid) { in vcpu_exception_intinfo()
1810 info |= (uint64_t)vcpu->exc_errcode << 32; in vcpu_exception_intinfo()
1817 vm_entry_intinfo(struct vcpu *vcpu, uint64_t *retinfo) in vm_entry_intinfo() argument
1822 info1 = vcpu->exitintinfo; in vm_entry_intinfo()
1823 vcpu->exitintinfo = 0; in vm_entry_intinfo()
1826 if (vcpu->exception_pending) { in vm_entry_intinfo()
1827 info2 = vcpu_exception_intinfo(vcpu); in vm_entry_intinfo()
1828 vcpu->exception_pending = 0; in vm_entry_intinfo()
1829 VMM_CTR2(vcpu, "Exception %d delivered: %#lx", in vm_entry_intinfo()
1830 vcpu->exc_vector, info2); in vm_entry_intinfo()
1834 valid = nested_fault(vcpu, info1, info2, retinfo); in vm_entry_intinfo()
1846 VMM_CTR4(vcpu, "%s: info1(%#lx), info2(%#lx), " in vm_entry_intinfo()
1854 vm_get_intinfo(struct vcpu *vcpu, uint64_t *info1, uint64_t *info2) in vm_get_intinfo() argument
1856 *info1 = vcpu->exitintinfo; in vm_get_intinfo()
1857 *info2 = vcpu_exception_intinfo(vcpu); in vm_get_intinfo()
1862 vm_inject_exception(struct vcpu *vcpu, int vector, int errcode_valid, in vm_inject_exception() argument
1879 if (vcpu->exception_pending) { in vm_inject_exception()
1880 VMM_CTR2(vcpu, "Unable to inject exception %d due to " in vm_inject_exception()
1881 "pending exception %d", vector, vcpu->exc_vector); in vm_inject_exception()
1889 error = vm_get_register(vcpu, VM_REG_GUEST_CR0, &regval); in vm_inject_exception()
1901 error = vm_set_register(vcpu, VM_REG_GUEST_INTR_SHADOW, 0); in vm_inject_exception()
1906 vm_restart_instruction(vcpu); in vm_inject_exception()
1908 vcpu->exception_pending = 1; in vm_inject_exception()
1909 vcpu->exc_vector = vector; in vm_inject_exception()
1910 vcpu->exc_errcode = errcode; in vm_inject_exception()
1911 vcpu->exc_errcode_valid = errcode_valid; in vm_inject_exception()
1912 VMM_CTR1(vcpu, "Exception %d pending", vector); in vm_inject_exception()
1917 vm_inject_fault(struct vcpu *vcpu, int vector, int errcode_valid, int errcode) in vm_inject_fault() argument
1923 error = vm_inject_exception(vcpu, vector, errcode_valid, in vm_inject_fault()
1929 vm_inject_pf(struct vcpu *vcpu, int error_code, uint64_t cr2) in vm_inject_pf() argument
1933 VMM_CTR2(vcpu, "Injecting page fault: error_code %#x, cr2 %#lx", in vm_inject_pf()
1936 error = vm_set_register(vcpu, VM_REG_GUEST_CR2, cr2); in vm_inject_pf()
1939 vm_inject_fault(vcpu, IDT_PF, 1, error_code); in vm_inject_pf()
1945 vm_inject_nmi(struct vcpu *vcpu) in vm_inject_nmi() argument
1948 vcpu->nmi_pending = 1; in vm_inject_nmi()
1949 vcpu_notify_event(vcpu, false); in vm_inject_nmi()
1954 vm_nmi_pending(struct vcpu *vcpu) in vm_nmi_pending() argument
1956 return (vcpu->nmi_pending); in vm_nmi_pending()
1960 vm_nmi_clear(struct vcpu *vcpu) in vm_nmi_clear() argument
1962 if (vcpu->nmi_pending == 0) in vm_nmi_clear()
1965 vcpu->nmi_pending = 0; in vm_nmi_clear()
1966 vmm_stat_incr(vcpu, VCPU_NMI_COUNT, 1); in vm_nmi_clear()
1972 vm_inject_extint(struct vcpu *vcpu) in vm_inject_extint() argument
1975 vcpu->extint_pending = 1; in vm_inject_extint()
1976 vcpu_notify_event(vcpu, false); in vm_inject_extint()
1981 vm_extint_pending(struct vcpu *vcpu) in vm_extint_pending() argument
1983 return (vcpu->extint_pending); in vm_extint_pending()
1987 vm_extint_clear(struct vcpu *vcpu) in vm_extint_clear() argument
1989 if (vcpu->extint_pending == 0) in vm_extint_clear()
1992 vcpu->extint_pending = 0; in vm_extint_clear()
1993 vmm_stat_incr(vcpu, VCPU_EXTINT_COUNT, 1); in vm_extint_clear()
1997 vm_get_capability(struct vcpu *vcpu, int type, int *retval) in vm_get_capability() argument
2002 return (vmmops_getcap(vcpu->cookie, type, retval)); in vm_get_capability()
2006 vm_set_capability(struct vcpu *vcpu, int type, int val) in vm_set_capability() argument
2011 return (vmmops_setcap(vcpu->cookie, type, val)); in vm_set_capability()
2015 vcpu_vm(struct vcpu *vcpu) in vcpu_vm() argument
2017 return (vcpu->vm); in vcpu_vm()
2021 vcpu_vcpuid(struct vcpu *vcpu) in vcpu_vcpuid() argument
2023 return (vcpu->vcpuid); in vcpu_vcpuid()
2026 struct vcpu *
2029 return (vm->vcpu[vcpuid]); in vm_vcpu()
2033 vm_lapic(struct vcpu *vcpu) in vm_lapic() argument
2035 return (vcpu->vlapic); in vm_lapic()
2102 vcpu_set_state(struct vcpu *vcpu, enum vcpu_state newstate, bool from_idle) in vcpu_set_state() argument
2106 vcpu_lock(vcpu); in vcpu_set_state()
2107 error = vcpu_set_state_locked(vcpu, newstate, from_idle); in vcpu_set_state()
2108 vcpu_unlock(vcpu); in vcpu_set_state()
2114 vcpu_get_state(struct vcpu *vcpu, int *hostcpu) in vcpu_get_state() argument
2118 vcpu_lock(vcpu); in vcpu_get_state()
2119 state = vcpu->state; in vcpu_get_state()
2121 *hostcpu = vcpu->hostcpu; in vcpu_get_state()
2122 vcpu_unlock(vcpu); in vcpu_get_state()
2128 vm_activate_cpu(struct vcpu *vcpu) in vm_activate_cpu() argument
2130 struct vm *vm = vcpu->vm; in vm_activate_cpu()
2132 if (CPU_ISSET(vcpu->vcpuid, &vm->active_cpus)) in vm_activate_cpu()
2135 VMM_CTR0(vcpu, "activated"); in vm_activate_cpu()
2136 CPU_SET_ATOMIC(vcpu->vcpuid, &vm->active_cpus); in vm_activate_cpu()
2141 vm_suspend_cpu(struct vm *vm, struct vcpu *vcpu) in vm_suspend_cpu() argument
2143 if (vcpu == NULL) { in vm_suspend_cpu()
2150 if (!CPU_ISSET(vcpu->vcpuid, &vm->active_cpus)) in vm_suspend_cpu()
2153 CPU_SET_ATOMIC(vcpu->vcpuid, &vm->debug_cpus); in vm_suspend_cpu()
2154 vcpu_notify_event(vcpu, false); in vm_suspend_cpu()
2160 vm_resume_cpu(struct vm *vm, struct vcpu *vcpu) in vm_resume_cpu() argument
2163 if (vcpu == NULL) { in vm_resume_cpu()
2166 if (!CPU_ISSET(vcpu->vcpuid, &vm->debug_cpus)) in vm_resume_cpu()
2169 CPU_CLR_ATOMIC(vcpu->vcpuid, &vm->debug_cpus); in vm_resume_cpu()
2175 vcpu_debugged(struct vcpu *vcpu) in vcpu_debugged() argument
2178 return (CPU_ISSET(vcpu->vcpuid, &vcpu->vm->debug_cpus)); in vcpu_debugged()
2227 vcpu_stats(struct vcpu *vcpu) in vcpu_stats() argument
2230 return (vcpu->stats); in vcpu_stats()
2234 vm_get_x2apic_state(struct vcpu *vcpu, enum x2apic_state *state) in vm_get_x2apic_state() argument
2236 *state = vcpu->x2apic_state; in vm_get_x2apic_state()
2242 vm_set_x2apic_state(struct vcpu *vcpu, enum x2apic_state state) in vm_set_x2apic_state() argument
2247 vcpu->x2apic_state = state; in vm_set_x2apic_state()
2249 vlapic_set_x2apic_state(vcpu, state); in vm_set_x2apic_state()
2262 vcpu_notify_event_locked(struct vcpu *vcpu, bool lapic_intr) in vcpu_notify_event_locked() argument
2266 hostcpu = vcpu->hostcpu; in vcpu_notify_event_locked()
2267 if (vcpu->state == VCPU_RUNNING) { in vcpu_notify_event_locked()
2271 vlapic_post_intr(vcpu->vlapic, hostcpu, in vcpu_notify_event_locked()
2286 "with hostcpu %d", vcpu->state, hostcpu)); in vcpu_notify_event_locked()
2287 if (vcpu->state == VCPU_SLEEPING) in vcpu_notify_event_locked()
2288 wakeup_one(vcpu); in vcpu_notify_event_locked()
2293 vcpu_notify_event(struct vcpu *vcpu, bool lapic_intr) in vcpu_notify_event() argument
2295 vcpu_lock(vcpu); in vcpu_notify_event()
2296 vcpu_notify_event_locked(vcpu, lapic_intr); in vcpu_notify_event()
2297 vcpu_unlock(vcpu); in vcpu_notify_event()
2322 vm_smp_rendezvous(struct vcpu *vcpu, cpuset_t dest, in vm_smp_rendezvous() argument
2325 struct vm *vm = vcpu->vm; in vm_smp_rendezvous()
2341 VMM_CTR0(vcpu, "Rendezvous already in progress"); in vm_smp_rendezvous()
2343 error = vm_handle_rendezvous(vcpu); in vm_smp_rendezvous()
2351 VMM_CTR0(vcpu, "Initiating rendezvous"); in vm_smp_rendezvous()
2367 return (vm_handle_rendezvous(vcpu)); in vm_smp_rendezvous()
2426 vm_copy_setup(struct vcpu *vcpu, struct vm_guest_paging *paging, in vm_copy_setup() argument
2442 error = vm_gla2gpa(vcpu, paging, gla, prot, &gpa, fault); in vm_copy_setup()
2455 hva = vm_gpa_hold(vcpu, copyinfo[idx].gpa, in vm_copy_setup()
2512 vm_get_rescnt(struct vcpu *vcpu, struct vmm_stat_type *stat) in vm_get_rescnt() argument
2515 if (vcpu->vcpuid == 0) { in vm_get_rescnt()
2516 vmm_stat_set(vcpu, VMM_MEM_RESIDENT, PAGE_SIZE * in vm_get_rescnt()
2517 vmspace_resident_count(vcpu->vm->vmspace)); in vm_get_rescnt()
2522 vm_get_wiredcnt(struct vcpu *vcpu, struct vmm_stat_type *stat) in vm_get_wiredcnt() argument
2525 if (vcpu->vcpuid == 0) { in vm_get_wiredcnt()
2526 vmm_stat_set(vcpu, VMM_MEM_WIRED, PAGE_SIZE * in vm_get_wiredcnt()
2527 pmap_wired_count(vmspace_pmap(vcpu->vm->vmspace))); in vm_get_wiredcnt()
2540 struct vcpu *vcpu; in vm_snapshot_vcpus() local
2546 vcpu = vm->vcpu[i]; in vm_snapshot_vcpus()
2547 if (vcpu == NULL) in vm_snapshot_vcpus()
2550 SNAPSHOT_VAR_OR_LEAVE(vcpu->x2apic_state, meta, ret, done); in vm_snapshot_vcpus()
2551 SNAPSHOT_VAR_OR_LEAVE(vcpu->exitintinfo, meta, ret, done); in vm_snapshot_vcpus()
2552 SNAPSHOT_VAR_OR_LEAVE(vcpu->exc_vector, meta, ret, done); in vm_snapshot_vcpus()
2553 SNAPSHOT_VAR_OR_LEAVE(vcpu->exc_errcode_valid, meta, ret, done); in vm_snapshot_vcpus()
2554 SNAPSHOT_VAR_OR_LEAVE(vcpu->exc_errcode, meta, ret, done); in vm_snapshot_vcpus()
2555 SNAPSHOT_VAR_OR_LEAVE(vcpu->guest_xcr0, meta, ret, done); in vm_snapshot_vcpus()
2556 SNAPSHOT_VAR_OR_LEAVE(vcpu->exitinfo, meta, ret, done); in vm_snapshot_vcpus()
2557 SNAPSHOT_VAR_OR_LEAVE(vcpu->nextrip, meta, ret, done); in vm_snapshot_vcpus()
2565 tsc = now + vcpu->tsc_offset; in vm_snapshot_vcpus()
2568 vcpu->tsc_offset = tsc; in vm_snapshot_vcpus()
2593 struct vcpu *vcpu; in vm_snapshot_vcpu() local
2600 vcpu = vm->vcpu[i]; in vm_snapshot_vcpu()
2601 if (vcpu == NULL) in vm_snapshot_vcpu()
2604 error = vmmops_vcpu_snapshot(vcpu->cookie, meta); in vm_snapshot_vcpu()
2661 vm_set_tsc_offset(struct vcpu *vcpu, uint64_t offset) in vm_set_tsc_offset() argument
2663 vcpu->tsc_offset = offset; in vm_set_tsc_offset()
2671 struct vcpu *vcpu; in vm_restore_time() local
2682 vcpu = vm->vcpu[i]; in vm_restore_time()
2683 if (vcpu == NULL) in vm_restore_time()
2686 error = vmmops_restore_tsc(vcpu->cookie, in vm_restore_time()
2687 vcpu->tsc_offset - now); in vm_restore_time()