diff options
author | Christoffer Dall <christoffer.dall@arm.com> | 2018-07-03 22:54:14 +0200 |
---|---|---|
committer | Marc Zyngier <marc.zyngier@arm.com> | 2018-07-21 16:02:07 +0100 |
commit | 1d47191de7e15900f8fbfe7cccd7c6e1c2d7c31a (patch) | |
tree | 2595c1920c0bda904e609e1d504afca86f7d2963 /virt | |
parent | de73708915adc1b3f05e617a86da6b2d68fae141 (diff) | |
download | linux-1d47191de7e15900f8fbfe7cccd7c6e1c2d7c31a.tar.bz2 |
KVM: arm/arm64: Fix vgic init race
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: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Christoffer Dall <christoffer.dall@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Diffstat (limited to 'virt')
-rw-r--r-- | virt/kvm/arm/vgic/vgic-init.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c index 2673efce65f3..b71417913741 100644 --- a/virt/kvm/arm/vgic/vgic-init.c +++ b/virt/kvm/arm/vgic/vgic-init.c @@ -271,6 +271,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) dist->nr_spis = VGIC_NR_IRQS_LEGACY - VGIC_NR_PRIVATE_IRQS; |