git: 72ae04c73347 - main - vmm: fix vcpu atomic load

From: Ruslan Bukin <br_at_FreeBSD.org>
Date: Tue, 29 Oct 2024 16:22:55 UTC
The branch main has been updated by br:

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

commit 72ae04c7334743c0fec2e8c99ac13fd8ca63f51b
Author:     Ruslan Bukin <br@FreeBSD.org>
AuthorDate: 2024-10-29 16:19:03 +0000
Commit:     Ruslan Bukin <br@FreeBSD.org>
CommitDate: 2024-10-29 16:19:49 +0000

    vmm: fix vcpu atomic load
    
    Load vcpu with acquire semantics as we are making a critical code
    section between creating vcpu and using it.
    
    Tested on risc-v only.
    
    Pointed out by: markj
    Reviewed by: jhb, markj
    Differential Revision: https://reviews.freebsd.org/D47306
---
 sys/amd64/vmm/vmm.c | 3 ++-
 sys/arm64/vmm/vmm.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c
index 12ebc1671641..07d3f74b8365 100644
--- a/sys/amd64/vmm/vmm.c
+++ b/sys/amd64/vmm/vmm.c
@@ -559,7 +559,8 @@ vm_alloc_vcpu(struct vm *vm, int vcpuid)
 	if (vcpuid < 0 || vcpuid >= vm_get_maxcpus(vm))
 		return (NULL);
 
-	vcpu = atomic_load_ptr(&vm->vcpu[vcpuid]);
+	vcpu = (struct vcpu *)
+	    atomic_load_acq_ptr((uintptr_t *)&vm->vcpu[vcpuid]);
 	if (__predict_true(vcpu != NULL))
 		return (vcpu);
 
diff --git a/sys/arm64/vmm/vmm.c b/sys/arm64/vmm/vmm.c
index fe5f43495262..4127fad5cd59 100644
--- a/sys/arm64/vmm/vmm.c
+++ b/sys/arm64/vmm/vmm.c
@@ -443,7 +443,8 @@ vm_alloc_vcpu(struct vm *vm, int vcpuid)
 	if (vcpuid >= vgic_max_cpu_count(vm->cookie))
 		return (NULL);
 
-	vcpu = atomic_load_ptr(&vm->vcpu[vcpuid]);
+	vcpu = (struct vcpu *)
+	    atomic_load_acq_ptr((uintptr_t *)&vm->vcpu[vcpuid]);
 	if (__predict_true(vcpu != NULL))
 		return (vcpu);