diff --git a/sys/amd64/vmm/amd/svm.c b/sys/amd64/vmm/amd/svm.c --- a/sys/amd64/vmm/amd/svm.c +++ b/sys/amd64/vmm/amd/svm.c @@ -2422,14 +2422,15 @@ /* struct svm_softc is AMD's representation for SVM softc */ struct svm_softc *sc; struct svm_vcpu *vcpu; - int i; int ret; + uint16_t i, maxcpus; sc = arg; KASSERT(sc != NULL, ("%s: arg was NULL", __func__)); - for (i = 0; i < VM_MAXCPU; i++) { + maxcpus = vm_get_maxcpus(sc->vm); + for (i = 0; i < maxcpus; i++) { vcpu = &sc->vcpu[i]; /* Snapshot swctx for virtual cpu i */ diff --git a/sys/amd64/vmm/amd/vmcb.c b/sys/amd64/vmm/amd/vmcb.c --- a/sys/amd64/vmm/amd/vmcb.c +++ b/sys/amd64/vmm/amd/vmcb.c @@ -463,7 +463,7 @@ { int error = 0; - if (vcpu < 0 || vcpu >= VM_MAXCPU) { + if (vcpu < 0 || vcpu >= vm_get_maxcpus(sc->vm)) { error = EINVAL; goto err; } @@ -484,7 +484,7 @@ { int error = 0; - if (vcpu < 0 || vcpu >= VM_MAXCPU) { + if (vcpu < 0 || vcpu >= vm_get_maxcpus(sc->vm)) { error = EINVAL; goto err; } diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c --- a/sys/amd64/vmm/intel/vmx.c +++ b/sys/amd64/vmm/intel/vmx.c @@ -1029,12 +1029,12 @@ static void * vmx_init(struct vm *vm, pmap_t pmap) { - uint16_t vpid[VM_MAXCPU]; int i, error; struct vmx *vmx; struct vmcs *vmcs; uint32_t exc_bitmap; - uint16_t maxcpus; + uint16_t maxcpus = vm_get_maxcpus(vm); + uint16_t vpid[maxcpus]; vmx = malloc(sizeof(struct vmx), M_VMX, M_WAITOK | M_ZERO); if ((uintptr_t)vmx & PAGE_MASK) { @@ -1097,7 +1097,7 @@ ((cap_rdpid || cap_rdtscp) && guest_msr_ro(vmx, MSR_TSC_AUX))) panic("vmx_init: error setting guest msr access"); - vpid_alloc(vpid, VM_MAXCPU); + vpid_alloc(vpid, maxcpus); if (virtual_interrupt_delivery) { error = vm_map_mmio(vm, DEFAULT_APIC_BASE, PAGE_SIZE, @@ -1106,7 +1106,6 @@ KASSERT(error == 0, ("vm_map_mmio(apicbase) error %d", error)); } - maxcpus = vm_get_maxcpus(vm); for (i = 0; i < maxcpus; i++) { vmcs = &vmx->vmcs[i]; vmcs->identifier = vmx_revision(); @@ -4074,14 +4073,15 @@ { struct vmx *vmx; struct vmxctx *vmxctx; - int i; int ret; + uint16_t i, maxcpus; vmx = arg; KASSERT(vmx != NULL, ("%s: arg was NULL", __func__)); - for (i = 0; i < VM_MAXCPU; i++) { + maxcpus = vm_get_maxcpus(vmx->vm); + for (i = 0; i < maxcpus; i++) { SNAPSHOT_BUF_OR_LEAVE(vmx->guest_msrs[i], sizeof(vmx->guest_msrs[i]), meta, ret, done); diff --git a/sys/amd64/vmm/io/vlapic.c b/sys/amd64/vmm/io/vlapic.c --- a/sys/amd64/vmm/io/vlapic.c +++ b/sys/amd64/vmm/io/vlapic.c @@ -1857,16 +1857,18 @@ int vlapic_snapshot(struct vm *vm, struct vm_snapshot_meta *meta) { - int i, ret; + int ret; struct vlapic *vlapic; struct LAPIC *lapic; uint32_t ccr; + uint16_t i, maxcpus; KASSERT(vm != NULL, ("%s: arg was NULL", __func__)); ret = 0; - for (i = 0; i < VM_MAXCPU; i++) { + maxcpus = vm_get_maxcpus(vm); + for (i = 0; i < maxcpus; i++) { vlapic = vm_lapic(vm, i); /* snapshot the page first; timer period depends on icr_timer */ diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c --- a/sys/amd64/vmm/vmm.c +++ b/sys/amd64/vmm/vmm.c @@ -2806,11 +2806,12 @@ { uint64_t tsc, now; int ret; - int i; struct vcpu *vcpu; + uint16_t i, maxcpus; now = rdtsc(); - for (i = 0; i < VM_MAXCPU; i++) { + maxcpus = vm_get_maxcpus(vm); + for (i = 0; i < maxcpus; i++) { vcpu = &vm->vcpu[i]; SNAPSHOT_VAR_OR_LEAVE(vcpu->x2apic_state, meta, ret, done); @@ -2852,11 +2853,13 @@ static int vm_snapshot_vmcx(struct vm *vm, struct vm_snapshot_meta *meta) { - int i, error; + int error; + uint16_t i, maxcpus; 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); if (error != 0) { printf("%s: failed to snapshot vmcs/vmcb data for " @@ -2921,7 +2924,7 @@ { struct vcpu *vcpu; - if (vcpuid < 0 || vcpuid >= VM_MAXCPU) + if (vcpuid < 0 || vcpuid >= vm_get_maxcpus(vm)) return (EINVAL); vcpu = &vm->vcpu[vcpuid]; @@ -2933,9 +2936,10 @@ int vm_restore_time(struct vm *vm) { - int error, i; + int error; uint64_t now; struct vcpu *vcpu; + uint16_t i, maxcpus; now = rdtsc(); @@ -2943,7 +2947,8 @@ if (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]; error = vmmops_restore_tsc(vm->cookie, i, vcpu->tsc_offset -