Commit f3662e33 authored by Christoffer Dall's avatar Christoffer Dall Committed by Greg Kroah-Hartman

KVM: arm/arm64: Fix vgic init race

[ Upstream commit 1d47191d ]

The vgic_init function can race with kvm_arch_vcpu_create() which does
not hold kvm_lock() and we therefore have no synchronization primitives
to ensure we're doing the right thing.

As the user is trying to initialize or run the VM while at the same time
creating more VCPUs, we just have to refuse to initialize the VGIC in
this case rather than silently failing with a broken VCPU.
Reviewed-by: 's avatarEric Auger <>
Signed-off-by: 's avatarChristoffer Dall <>
Signed-off-by: 's avatarMarc Zyngier <>
Signed-off-by: 's avatarSasha Levin <>
Signed-off-by: 's avatarGreg Kroah-Hartman <>
parent 9af3a46e
......@@ -277,6 +277,10 @@ int vgic_init(struct kvm *kvm)
if (vgic_initialized(kvm))
return 0;
/* Are we also in the middle of creating a VCPU? */
if (kvm->created_vcpus != atomic_read(&kvm->online_vcpus))
return -EBUSY;
/* freeze the number of spis */
if (!dist->nr_spis)
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