Changeset View
Changeset View
Standalone View
Standalone View
sys/amd64/vmm/vmm.c
Show First 20 Lines • Show All 2,800 Lines • ▼ Show 20 Lines | |||||
VMM_STAT_FUNC(VMM_MEM_WIRED, "Wired memory", vm_get_wiredcnt); | VMM_STAT_FUNC(VMM_MEM_WIRED, "Wired memory", vm_get_wiredcnt); | ||||
#ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
static int | static int | ||||
vm_snapshot_vcpus(struct vm *vm, struct vm_snapshot_meta *meta) | vm_snapshot_vcpus(struct vm *vm, struct vm_snapshot_meta *meta) | ||||
{ | { | ||||
uint64_t tsc, now; | uint64_t tsc, now; | ||||
int ret; | int ret; | ||||
int i; | |||||
struct vcpu *vcpu; | struct vcpu *vcpu; | ||||
uint16_t i, maxcpus; | |||||
now = rdtsc(); | now = rdtsc(); | ||||
for (i = 0; i < VM_MAXCPU; i++) { | maxcpus = vm_get_maxcpus(vm); | ||||
for (i = 0; i < maxcpus; i++) { | |||||
vcpu = &vm->vcpu[i]; | vcpu = &vm->vcpu[i]; | ||||
SNAPSHOT_VAR_OR_LEAVE(vcpu->x2apic_state, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(vcpu->x2apic_state, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(vcpu->exitintinfo, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(vcpu->exitintinfo, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(vcpu->exc_vector, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(vcpu->exc_vector, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(vcpu->exc_errcode_valid, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(vcpu->exc_errcode_valid, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(vcpu->exc_errcode, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(vcpu->exc_errcode, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(vcpu->guest_xcr0, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(vcpu->guest_xcr0, meta, ret, done); | ||||
Show All 25 Lines | |||||
done: | done: | ||||
return (ret); | return (ret); | ||||
} | } | ||||
static int | static int | ||||
vm_snapshot_vmcx(struct vm *vm, struct vm_snapshot_meta *meta) | vm_snapshot_vmcx(struct vm *vm, struct vm_snapshot_meta *meta) | ||||
{ | { | ||||
int i, error; | int error; | ||||
uint16_t i, maxcpus; | |||||
error = 0; | error = 0; | ||||
for (i = 0; i < VM_MAXCPU; i++) { | maxcpus = vm_get_maxcpus(vm); | ||||
for (i = 0; i < maxcpus; i++) { | |||||
error = vmmops_vmcx_snapshot(vm->cookie, meta, i); | error = vmmops_vmcx_snapshot(vm->cookie, meta, i); | ||||
if (error != 0) { | if (error != 0) { | ||||
printf("%s: failed to snapshot vmcs/vmcb data for " | printf("%s: failed to snapshot vmcs/vmcb data for " | ||||
"vCPU: %d; error: %d\n", __func__, i, error); | "vCPU: %d; error: %d\n", __func__, i, error); | ||||
goto done; | goto done; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | vm_snapshot_req(struct vm *vm, struct vm_snapshot_meta *meta) | ||||
return (ret); | return (ret); | ||||
} | } | ||||
int | int | ||||
vm_set_tsc_offset(struct vm *vm, int vcpuid, uint64_t offset) | vm_set_tsc_offset(struct vm *vm, int vcpuid, uint64_t offset) | ||||
{ | { | ||||
struct vcpu *vcpu; | struct vcpu *vcpu; | ||||
if (vcpuid < 0 || vcpuid >= VM_MAXCPU) | if (vcpuid < 0 || vcpuid >= vm_get_maxcpus(vm)) | ||||
return (EINVAL); | return (EINVAL); | ||||
vcpu = &vm->vcpu[vcpuid]; | vcpu = &vm->vcpu[vcpuid]; | ||||
vcpu->tsc_offset = offset; | vcpu->tsc_offset = offset; | ||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
vm_restore_time(struct vm *vm) | vm_restore_time(struct vm *vm) | ||||
{ | { | ||||
int error, i; | int error; | ||||
uint64_t now; | uint64_t now; | ||||
struct vcpu *vcpu; | struct vcpu *vcpu; | ||||
uint16_t i, maxcpus; | |||||
now = rdtsc(); | now = rdtsc(); | ||||
error = vhpet_restore_time(vm_hpet(vm)); | error = vhpet_restore_time(vm_hpet(vm)); | ||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
for (i = 0; i < nitems(vm->vcpu); i++) { | maxcpus = vm_get_maxcpus(vm); | ||||
for (i = 0; i < maxcpus; i++) { | |||||
vcpu = &vm->vcpu[i]; | vcpu = &vm->vcpu[i]; | ||||
error = vmmops_restore_tsc(vm->cookie, i, vcpu->tsc_offset - | error = vmmops_restore_tsc(vm->cookie, i, vcpu->tsc_offset - | ||||
now); | now); | ||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
#endif | #endif |