diff --git a/hypervisor/arch/x86/guest/vlapic.c b/hypervisor/arch/x86/guest/vlapic.c index d46981634..6d644143e 100644 --- a/hypervisor/arch/x86/guest/vlapic.c +++ b/hypervisor/arch/x86/guest/vlapic.c @@ -987,7 +987,7 @@ vlapic_calcdest(struct vm *vm, uint64_t *dmask, uint32_t dest, */ *dmask = 0UL; vcpu_id = vm_apicid2vcpu_id(vm, (uint8_t)dest); - if (vcpu_id < phys_cpu_num) { + if (vcpu_id < vm->hw.created_vcpus) { bitmap_set_lock(vcpu_id, dmask); } } else { @@ -1619,9 +1619,6 @@ vlapic_reset(struct acrn_vlapic *vlapic) void vlapic_init(struct acrn_vlapic *vlapic) { - ASSERT(vlapic->vcpu->vcpu_id < phys_cpu_num, - "%s: vcpu_id is not initialized", __func__); - /* * If the vlapic is configured in x2apic mode then it will be * accessed in the critical section via the MSR emulation code. @@ -1848,7 +1845,7 @@ vlapic_set_local_intr(struct vm *vm, uint16_t vcpu_id_arg, uint32_t vector) int error; uint16_t vcpu_id = vcpu_id_arg; - if ((vcpu_id != BROADCAST_CPU_ID) && (vcpu_id >= phys_cpu_num)) { + if ((vcpu_id != BROADCAST_CPU_ID) && (vcpu_id >= vm->hw.created_vcpus)) { return -EINVAL; } diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index abe928461..35baa14b0 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -406,7 +406,7 @@ int prepare_vm0(void) } /* Allocate all cpus to vm0 at the beginning */ - for (i = 0U; i < phys_cpu_num; i++) { + for (i = 0U; i < vm0_desc.vm_hw_num_cores; i++) { err = prepare_vcpu(vm, i); if (err != 0) { return err; diff --git a/hypervisor/debug/shell.c b/hypervisor/debug/shell.c index a4a62c796..2606d2abf 100644 --- a/hypervisor/debug/shell.c +++ b/hypervisor/debug/shell.c @@ -640,10 +640,7 @@ static int shell_vcpu_dumpreg(int argc, char **argv) } vm_id = (uint16_t)status; vcpu_id = (uint16_t)atoi(argv[2]); - if (vcpu_id >= phys_cpu_num) { - status = -EINVAL; - goto out; - } + vm = get_vm_from_vmid(vm_id); if (vm == NULL) { shell_puts("No vm found in the input \r\n"); @@ -651,8 +648,8 @@ static int shell_vcpu_dumpreg(int argc, char **argv) goto out; } - if (vcpu_id >= CONFIG_MAX_VCPUS_PER_VM) { - shell_puts("No vcpu found in the input \r\n"); + if (vcpu_id >= vm->hw.created_vcpus) { + shell_puts("vcpu id is out of range\r\n"); status = -EINVAL; goto out; }