Skip to content

Commit f3a7ed2

Browse files
committed
arm64/vmm: Move the vgic_max_cpu_count() check
vm_alloc_vcpu() is called quite frequently, and we don't need to apply the vgic limit unless we're actually allocating a vcpu structure for the first time. No functional change intended. Reviewed by: andrew MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53580
1 parent f999ffd commit f3a7ed2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

sys/arm64/vmm/vmm.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,6 @@ vm_alloc_vcpu(struct vm *vm, int vcpuid)
373373
if (vcpuid < 0 || vcpuid >= vm_get_maxcpus(vm))
374374
return (NULL);
375375

376-
/* Some interrupt controllers may have a CPU limit */
377-
if (vcpuid >= vgic_max_cpu_count(vm->cookie))
378-
return (NULL);
379-
380376
vcpu = (struct vcpu *)
381377
atomic_load_acq_ptr((uintptr_t *)&vm->vcpu[vcpuid]);
382378
if (__predict_true(vcpu != NULL))
@@ -385,6 +381,12 @@ vm_alloc_vcpu(struct vm *vm, int vcpuid)
385381
sx_xlock(&vm->vcpus_init_lock);
386382
vcpu = vm->vcpu[vcpuid];
387383
if (vcpu == NULL && !vm->dying) {
384+
/* Some interrupt controllers may have a CPU limit */
385+
if (vcpuid >= vgic_max_cpu_count(vm->cookie)) {
386+
sx_xunlock(&vm->vcpus_init_lock);
387+
return (NULL);
388+
}
389+
388390
vcpu = vcpu_alloc(vm, vcpuid);
389391
vcpu_init(vcpu);
390392

0 commit comments

Comments
 (0)