Skip to content

Commit 4afb666

Browse files
mingqiangchiNanlinXie
authored andcommitted
hv:cleanup vcpu_id compare with phys_cpu_num
Currently we compare vcpu_id with phys_cpu_num, vcpu_id is not related with phys_cpu_num, this patch cleanup them. Tracked-On: #861 Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com> Reviewed-by: Li, Fei1 <fei1.li@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 3eb45b9 commit 4afb666

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ vlapic_calcdest(struct vm *vm, uint64_t *dmask, uint32_t dest,
987987
*/
988988
*dmask = 0UL;
989989
vcpu_id = vm_apicid2vcpu_id(vm, (uint8_t)dest);
990-
if (vcpu_id < phys_cpu_num) {
990+
if (vcpu_id < vm->hw.created_vcpus) {
991991
bitmap_set_lock(vcpu_id, dmask);
992992
}
993993
} else {
@@ -1619,9 +1619,6 @@ vlapic_reset(struct acrn_vlapic *vlapic)
16191619
void
16201620
vlapic_init(struct acrn_vlapic *vlapic)
16211621
{
1622-
ASSERT(vlapic->vcpu->vcpu_id < phys_cpu_num,
1623-
"%s: vcpu_id is not initialized", __func__);
1624-
16251622
/*
16261623
* If the vlapic is configured in x2apic mode then it will be
16271624
* 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)
18481845
int error;
18491846
uint16_t vcpu_id = vcpu_id_arg;
18501847

1851-
if ((vcpu_id != BROADCAST_CPU_ID) && (vcpu_id >= phys_cpu_num)) {
1848+
if ((vcpu_id != BROADCAST_CPU_ID) && (vcpu_id >= vm->hw.created_vcpus)) {
18521849
return -EINVAL;
18531850
}
18541851

hypervisor/arch/x86/guest/vm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ int prepare_vm0(void)
406406
}
407407

408408
/* Allocate all cpus to vm0 at the beginning */
409-
for (i = 0U; i < phys_cpu_num; i++) {
409+
for (i = 0U; i < vm0_desc.vm_hw_num_cores; i++) {
410410
err = prepare_vcpu(vm, i);
411411
if (err != 0) {
412412
return err;

hypervisor/debug/shell.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -640,19 +640,16 @@ static int shell_vcpu_dumpreg(int argc, char **argv)
640640
}
641641
vm_id = (uint16_t)status;
642642
vcpu_id = (uint16_t)atoi(argv[2]);
643-
if (vcpu_id >= phys_cpu_num) {
644-
status = -EINVAL;
645-
goto out;
646-
}
643+
647644
vm = get_vm_from_vmid(vm_id);
648645
if (vm == NULL) {
649646
shell_puts("No vm found in the input <vm_id, vcpu_id>\r\n");
650647
status = -EINVAL;
651648
goto out;
652649
}
653650

654-
if (vcpu_id >= CONFIG_MAX_VCPUS_PER_VM) {
655-
shell_puts("No vcpu found in the input <vm_id, vcpu_id>\r\n");
651+
if (vcpu_id >= vm->hw.created_vcpus) {
652+
shell_puts("vcpu id is out of range\r\n");
656653
status = -EINVAL;
657654
goto out;
658655
}

0 commit comments

Comments
 (0)