[RFC,01/21] KVM: x86: race between KVM_SET_GSI_ROUTING and KVM_CREATE_IRQCHIP
diff mbox

Message ID 20170306131815.12033-2-david@redhat.com
State New
Headers show

Commit Message

David Hildenbrand March 6, 2017, 1:17 p.m. UTC
Avoid races between KVM_SET_GSI_ROUTING and KVM_CREATE_IRQCHIP by taking
the kvm->lock when setting up routes.

If KVM_CREATE_IRQCHIP fails, KVM_SET_GSI_ROUTING could have already set
up routes pointing at pic/ioapic, being silently removed already.

Signed-off-by: David Hildenbrand <david@redhat.com>
 virt/kvm/kvm_main.c | 3 +++
 1 file changed, 3 insertions(+)

diff mbox

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index c6b7aff..9cd6a34 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3077,8 +3077,11 @@  static long kvm_vm_ioctl(struct file *filp,
 					   routing.nr * sizeof(*entries)))
 				goto out_free_irq_routing;
+		/* avoid races with KVM_CREATE_IRQCHIP on x86 */
+		mutex_lock(&kvm->lock);
 		r = kvm_set_irq_routing(kvm, entries, routing.nr,
+		mutex_unlock(&kvm->lock);