aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2025-11-04 16:58:25 +0000
committerMark Johnston <markj@FreeBSD.org>2025-11-04 16:58:25 +0000
commitf3a7ed2047dffaebbfbb3920e993e9df424be728 (patch)
tree07d763fe6afd9c08e50d90e47f4d92b5331de04a
parentf999ffdce3813eb946f10999ccffb8275c324469 (diff)
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
-rw-r--r--sys/arm64/vmm/vmm.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/sys/arm64/vmm/vmm.c b/sys/arm64/vmm/vmm.c
index 1304a68b80f8..31d2fb3f516b 100644
--- a/sys/arm64/vmm/vmm.c
+++ b/sys/arm64/vmm/vmm.c
@@ -373,10 +373,6 @@ vm_alloc_vcpu(struct vm *vm, int vcpuid)
if (vcpuid < 0 || vcpuid >= vm_get_maxcpus(vm))
return (NULL);
- /* Some interrupt controllers may have a CPU limit */
- if (vcpuid >= vgic_max_cpu_count(vm->cookie))
- return (NULL);
-
vcpu = (struct vcpu *)
atomic_load_acq_ptr((uintptr_t *)&vm->vcpu[vcpuid]);
if (__predict_true(vcpu != NULL))
@@ -385,6 +381,12 @@ vm_alloc_vcpu(struct vm *vm, int vcpuid)
sx_xlock(&vm->vcpus_init_lock);
vcpu = vm->vcpu[vcpuid];
if (vcpu == NULL && !vm->dying) {
+ /* Some interrupt controllers may have a CPU limit */
+ if (vcpuid >= vgic_max_cpu_count(vm->cookie)) {
+ sx_xunlock(&vm->vcpus_init_lock);
+ return (NULL);
+ }
+
vcpu = vcpu_alloc(vm, vcpuid);
vcpu_init(vcpu);