Commit 72a610f3 authored by Miaohe Lin's avatar Miaohe Lin Committed by Marc Zyngier

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: default avatarMiaohe Lin <linmiaohe@huawei.com>
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
Reviewed-by: default avatarEric Auger <eric.auger@redhat.com>
Reviewed-by: default avatarSteven Price <steven.price@arm.com>
Link: https://lore.kernel.org/r/1575081918-11401-1-git-send-email-linmiaohe@huawei.com
parent 0bda9498
...@@ -70,7 +70,7 @@ void kvm_vgic_early_init(struct kvm *kvm) ...@@ -70,7 +70,7 @@ void kvm_vgic_early_init(struct kvm *kvm)
*/ */
int kvm_vgic_create(struct kvm *kvm, u32 type) int kvm_vgic_create(struct kvm *kvm, u32 type)
{ {
int i, vcpu_lock_idx = -1, ret; int i, ret;
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
if (irqchip_in_kernel(kvm)) if (irqchip_in_kernel(kvm))
...@@ -86,17 +86,9 @@ int kvm_vgic_create(struct kvm *kvm, u32 type) ...@@ -86,17 +86,9 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
!kvm_vgic_global_state.can_emulate_gicv2) !kvm_vgic_global_state.can_emulate_gicv2)
return -ENODEV; return -ENODEV;
/*
* Any time a vcpu is run, vcpu_load is called which tries to grab the
* vcpu->mutex. By grabbing the vcpu->mutex of all VCPUs we ensure
* that no other VCPUs are run while we create the vgic.
*/
ret = -EBUSY; ret = -EBUSY;
kvm_for_each_vcpu(i, vcpu, kvm) { if (!lock_all_vcpus(kvm))
if (!mutex_trylock(&vcpu->mutex)) return ret;
goto out_unlock;
vcpu_lock_idx = i;
}
kvm_for_each_vcpu(i, vcpu, kvm) { kvm_for_each_vcpu(i, vcpu, kvm) {
if (vcpu->arch.has_run_once) if (vcpu->arch.has_run_once)
...@@ -125,10 +117,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type) ...@@ -125,10 +117,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
INIT_LIST_HEAD(&kvm->arch.vgic.rd_regions); INIT_LIST_HEAD(&kvm->arch.vgic.rd_regions);
out_unlock: out_unlock:
for (; vcpu_lock_idx >= 0; vcpu_lock_idx--) { unlock_all_vcpus(kvm);
vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx);
mutex_unlock(&vcpu->mutex);
}
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment