The branch main has been updated by markj:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=f3a7ed2047dffaebbfbb3920e993e9df424be728

commit f3a7ed2047dffaebbfbb3920e993e9df424be728
Author:     Mark Johnston <[email protected]>
AuthorDate: 2025-11-04 16:58:25 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2025-11-04 16:58:25 +0000

    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
---
 sys/arm64/vmm/vmm.c | 10 ++++++----
 1 file 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);
 

Reply via email to