Commit 6b50f540 authored by Christoffer Dall's avatar Christoffer Dall Committed by Paolo Bonzini

arm/arm64: KVM: vgic: Fix error code in kvm_vgic_create()

If we detect another vCPU is running we just exit and return 0 as if we
succesfully created the VGIC, but the VGIC wouldn't actual be created.

This shouldn't break in-kernel behavior because the kernel will not
observe the failed the attempt to create the VGIC, but userspace could
be rightfully confused.

Cc: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: default avatarChristoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent db7dedd0
...@@ -1933,7 +1933,7 @@ int kvm_vgic_init(struct kvm *kvm) ...@@ -1933,7 +1933,7 @@ int kvm_vgic_init(struct kvm *kvm)
int kvm_vgic_create(struct kvm *kvm) int kvm_vgic_create(struct kvm *kvm)
{ {
int i, vcpu_lock_idx = -1, ret = 0; int i, vcpu_lock_idx = -1, ret;
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
mutex_lock(&kvm->lock); mutex_lock(&kvm->lock);
...@@ -1948,6 +1948,7 @@ int kvm_vgic_create(struct kvm *kvm) ...@@ -1948,6 +1948,7 @@ int kvm_vgic_create(struct kvm *kvm)
* vcpu->mutex. By grabbing the vcpu->mutex of all VCPUs we ensure * vcpu->mutex. By grabbing the vcpu->mutex of all VCPUs we ensure
* that no other VCPUs are run while we create the vgic. * that no other VCPUs are run while we create the vgic.
*/ */
ret = -EBUSY;
kvm_for_each_vcpu(i, vcpu, kvm) { kvm_for_each_vcpu(i, vcpu, kvm) {
if (!mutex_trylock(&vcpu->mutex)) if (!mutex_trylock(&vcpu->mutex))
goto out_unlock; goto out_unlock;
...@@ -1955,11 +1956,10 @@ int kvm_vgic_create(struct kvm *kvm) ...@@ -1955,11 +1956,10 @@ int kvm_vgic_create(struct kvm *kvm)
} }
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)
ret = -EBUSY;
goto out_unlock; goto out_unlock;
}
} }
ret = 0;
spin_lock_init(&kvm->arch.vgic.lock); spin_lock_init(&kvm->arch.vgic.lock);
kvm->arch.vgic.in_kernel = true; kvm->arch.vgic.in_kernel = true;
......
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