]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - arch/x86/kvm/irq_comm.c
KVM: x86: check for pic and ioapic presence before use
[mirror_ubuntu-artful-kernel.git] / arch / x86 / kvm / irq_comm.c
index 4da03030d5a7f4d75aa715e4fa326014f9827cdf..6c0191615f23a34bae5c0972a20025cf5b695af9 100644 (file)
@@ -41,6 +41,15 @@ static int kvm_set_pic_irq(struct kvm_kernel_irq_routing_entry *e,
                           bool line_status)
 {
        struct kvm_pic *pic = pic_irqchip(kvm);
+
+       /*
+        * XXX: rejecting pic routes when pic isn't in use would be better,
+        * but the default routing table is installed while kvm->arch.vpic is
+        * NULL and KVM_CREATE_IRQCHIP can race with KVM_IRQ_LINE.
+        */
+       if (!pic)
+               return -1;
+
        return kvm_pic_set_irq(pic, e->irqchip.pin, irq_source_id, level);
 }
 
@@ -49,6 +58,10 @@ static int kvm_set_ioapic_irq(struct kvm_kernel_irq_routing_entry *e,
                              bool line_status)
 {
        struct kvm_ioapic *ioapic = kvm->arch.vioapic;
+
+       if (!ioapic)
+               return -1;
+
        return kvm_ioapic_set_irq(ioapic, e->irqchip.pin, irq_source_id, level,
                                line_status);
 }