forked from luck/tmp_suning_uos_patched
KVM: arm/arm64: vgic: Fix deadlock on error handling
Dmitry Vyukov reported that the syzkaller fuzzer triggered a deadlock in the vgic setup code when an error was detected, as the cleanup code tries to take a lock that is already held by the setup code. The fix is to avoid retaking the lock when cleaning up, by telling the cleanup function that we already hold it. Cc: stable@vger.kernel.org Reported-by: Dmitry Vyukov <dvyukov@google.com> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org> Reviewed-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
This commit is contained in:
parent
488f94d721
commit
1193e6aeec
|
@ -268,15 +268,11 @@ static void kvm_vgic_dist_destroy(struct kvm *kvm)
|
||||||
{
|
{
|
||||||
struct vgic_dist *dist = &kvm->arch.vgic;
|
struct vgic_dist *dist = &kvm->arch.vgic;
|
||||||
|
|
||||||
mutex_lock(&kvm->lock);
|
|
||||||
|
|
||||||
dist->ready = false;
|
dist->ready = false;
|
||||||
dist->initialized = false;
|
dist->initialized = false;
|
||||||
|
|
||||||
kfree(dist->spis);
|
kfree(dist->spis);
|
||||||
dist->nr_spis = 0;
|
dist->nr_spis = 0;
|
||||||
|
|
||||||
mutex_unlock(&kvm->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
|
void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
|
||||||
|
@ -286,7 +282,8 @@ void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
|
||||||
INIT_LIST_HEAD(&vgic_cpu->ap_list_head);
|
INIT_LIST_HEAD(&vgic_cpu->ap_list_head);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvm_vgic_destroy(struct kvm *kvm)
|
/* To be called with kvm->lock held */
|
||||||
|
static void __kvm_vgic_destroy(struct kvm *kvm)
|
||||||
{
|
{
|
||||||
struct kvm_vcpu *vcpu;
|
struct kvm_vcpu *vcpu;
|
||||||
int i;
|
int i;
|
||||||
|
@ -297,6 +294,13 @@ void kvm_vgic_destroy(struct kvm *kvm)
|
||||||
kvm_vgic_vcpu_destroy(vcpu);
|
kvm_vgic_vcpu_destroy(vcpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void kvm_vgic_destroy(struct kvm *kvm)
|
||||||
|
{
|
||||||
|
mutex_lock(&kvm->lock);
|
||||||
|
__kvm_vgic_destroy(kvm);
|
||||||
|
mutex_unlock(&kvm->lock);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* vgic_lazy_init: Lazy init is only allowed if the GIC exposed to the guest
|
* vgic_lazy_init: Lazy init is only allowed if the GIC exposed to the guest
|
||||||
* is a GICv2. A GICv3 must be explicitly initialized by the guest using the
|
* is a GICv2. A GICv3 must be explicitly initialized by the guest using the
|
||||||
|
@ -348,6 +352,10 @@ int kvm_vgic_map_resources(struct kvm *kvm)
|
||||||
ret = vgic_v2_map_resources(kvm);
|
ret = vgic_v2_map_resources(kvm);
|
||||||
else
|
else
|
||||||
ret = vgic_v3_map_resources(kvm);
|
ret = vgic_v3_map_resources(kvm);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
__kvm_vgic_destroy(kvm);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
mutex_unlock(&kvm->lock);
|
mutex_unlock(&kvm->lock);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -293,8 +293,6 @@ int vgic_v2_map_resources(struct kvm *kvm)
|
||||||
dist->ready = true;
|
dist->ready = true;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (ret)
|
|
||||||
kvm_vgic_destroy(kvm);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -302,8 +302,6 @@ int vgic_v3_map_resources(struct kvm *kvm)
|
||||||
dist->ready = true;
|
dist->ready = true;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (ret)
|
|
||||||
kvm_vgic_destroy(kvm);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user