Skip to content

Commit 72a610f

Browse files
MiaoheLinMarc Zyngier
authored andcommitted
KVM: arm/arm64: vgic: Use wrapper function to lock/unlock all vcpus in kvm_vgic_create()
Use wrapper function lock_all_vcpus()/unlock_all_vcpus() in kvm_vgic_create() to remove duplicated code dealing with locking and unlocking all vcpus in a vm. Signed-off-by: Miaohe Lin <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Eric Auger <[email protected]> Reviewed-by: Steven Price <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0bda949 commit 72a610f

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

virt/kvm/arm/vgic/vgic-init.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void kvm_vgic_early_init(struct kvm *kvm)
7070
*/
7171
int kvm_vgic_create(struct kvm *kvm, u32 type)
7272
{
73-
int i, vcpu_lock_idx = -1, ret;
73+
int i, ret;
7474
struct kvm_vcpu *vcpu;
7575

7676
if (irqchip_in_kernel(kvm))
@@ -86,17 +86,9 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
8686
!kvm_vgic_global_state.can_emulate_gicv2)
8787
return -ENODEV;
8888

89-
/*
90-
* Any time a vcpu is run, vcpu_load is called which tries to grab the
91-
* vcpu->mutex. By grabbing the vcpu->mutex of all VCPUs we ensure
92-
* that no other VCPUs are run while we create the vgic.
93-
*/
9489
ret = -EBUSY;
95-
kvm_for_each_vcpu(i, vcpu, kvm) {
96-
if (!mutex_trylock(&vcpu->mutex))
97-
goto out_unlock;
98-
vcpu_lock_idx = i;
99-
}
90+
if (!lock_all_vcpus(kvm))
91+
return ret;
10092

10193
kvm_for_each_vcpu(i, vcpu, kvm) {
10294
if (vcpu->arch.has_run_once)
@@ -125,10 +117,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
125117
INIT_LIST_HEAD(&kvm->arch.vgic.rd_regions);
126118

127119
out_unlock:
128-
for (; vcpu_lock_idx >= 0; vcpu_lock_idx--) {
129-
vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx);
130-
mutex_unlock(&vcpu->mutex);
131-
}
120+
unlock_all_vcpus(kvm);
132121
return ret;
133122
}
134123

0 commit comments

Comments
 (0)