KVM: Maintain back mapping from irqchip/pin to gsi
authorGleb Natapov <gleb@redhat.com>
Mon, 24 Aug 2009 08:54:21 +0000 (11:54 +0300)
committerAvi Kivity <avi@redhat.com>
Thu, 3 Dec 2009 07:32:07 +0000 (09:32 +0200)
Maintain back mapping from irqchip/pin to gsi to speedup
interrupt acknowledgment notifications.

[avi: build fix on non-x86/ia64]

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/ia64/include/asm/kvm.h
arch/x86/include/asm/kvm.h
include/linux/kvm_host.h
virt/kvm/irq_comm.c

index 18a7e49abbc5ec7ebd445ba6b785263c2193602a..bc90c75adf6716f8423fe92935fa9fbd7be89cf2 100644 (file)
@@ -60,6 +60,7 @@ struct kvm_ioapic_state {
 #define KVM_IRQCHIP_PIC_MASTER   0
 #define KVM_IRQCHIP_PIC_SLAVE    1
 #define KVM_IRQCHIP_IOAPIC       2
+#define KVM_NR_IRQCHIPS          3
 
 #define KVM_CONTEXT_SIZE       8*1024
 
index 4a5fe914dc59dceaf9f631eb24a97e978efff3d8..f02e87a5206f24118d0e2d942770ab9ecda9ff49 100644 (file)
@@ -79,6 +79,7 @@ struct kvm_ioapic_state {
 #define KVM_IRQCHIP_PIC_MASTER   0
 #define KVM_IRQCHIP_PIC_SLAVE    1
 #define KVM_IRQCHIP_IOAPIC       2
+#define KVM_NR_IRQCHIPS          3
 
 /* for KVM_GET_REGS and KVM_SET_REGS */
 struct kvm_regs {
index f403e66557fb07148dc950fb58271bd807be3ee2..cc2d7493598b47818403f213596b2d8d3d3991ce 100644 (file)
@@ -131,7 +131,10 @@ struct kvm_kernel_irq_routing_entry {
        struct hlist_node link;
 };
 
+#ifdef __KVM_HAVE_IOAPIC
+
 struct kvm_irq_routing_table {
+       int chip[KVM_NR_IRQCHIPS][KVM_IOAPIC_NUM_PINS];
        struct kvm_kernel_irq_routing_entry *rt_entries;
        u32 nr_rt_entries;
        /*
@@ -141,6 +144,12 @@ struct kvm_irq_routing_table {
        struct hlist_head map[0];
 };
 
+#else
+
+struct kvm_irq_routing_table {};
+
+#endif
+
 struct kvm {
        spinlock_t mmu_lock;
        spinlock_t requests_lock;
index 81950f6f6fd97e0ef6d803542cb2b12fec473387..59cf8dae0062bb907abef75f56ad24f063f7d2b0 100644 (file)
@@ -175,25 +175,16 @@ void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin)
 {
        struct kvm_irq_ack_notifier *kian;
        struct hlist_node *n;
-       unsigned gsi = pin;
-       int i;
+       int gsi;
 
        trace_kvm_ack_irq(irqchip, pin);
 
-       for (i = 0; i < kvm->irq_routing->nr_rt_entries; i++) {
-               struct kvm_kernel_irq_routing_entry *e;
-               e = &kvm->irq_routing->rt_entries[i];
-               if (e->type == KVM_IRQ_ROUTING_IRQCHIP &&
-                   e->irqchip.irqchip == irqchip &&
-                   e->irqchip.pin == pin) {
-                       gsi = e->gsi;
-                       break;
-               }
-       }
-
-       hlist_for_each_entry(kian, n, &kvm->arch.irq_ack_notifier_list, link)
-               if (kian->gsi == gsi)
-                       kian->irq_acked(kian);
+       gsi = kvm->irq_routing->chip[irqchip][pin];
+       if (gsi != -1)
+               hlist_for_each_entry(kian, n, &kvm->arch.irq_ack_notifier_list,
+                                    link)
+                       if (kian->gsi == gsi)
+                               kian->irq_acked(kian);
 }
 
 void kvm_register_irq_ack_notifier(struct kvm *kvm,
@@ -332,6 +323,9 @@ static int setup_routing_entry(struct kvm_irq_routing_table *rt,
                }
                e->irqchip.irqchip = ue->u.irqchip.irqchip;
                e->irqchip.pin = ue->u.irqchip.pin + delta;
+               if (e->irqchip.pin >= KVM_IOAPIC_NUM_PINS)
+                       goto out;
+               rt->chip[ue->u.irqchip.irqchip][e->irqchip.pin] = ue->gsi;
                break;
        case KVM_IRQ_ROUTING_MSI:
                e->set = kvm_set_msi;
@@ -356,7 +350,7 @@ int kvm_set_irq_routing(struct kvm *kvm,
                        unsigned flags)
 {
        struct kvm_irq_routing_table *new, *old;
-       u32 i, nr_rt_entries = 0;
+       u32 i, j, nr_rt_entries = 0;
        int r;
 
        for (i = 0; i < nr; ++i) {
@@ -377,6 +371,9 @@ int kvm_set_irq_routing(struct kvm *kvm,
        new->rt_entries = (void *)&new->map[nr_rt_entries];
 
        new->nr_rt_entries = nr_rt_entries;
+       for (i = 0; i < 3; i++)
+               for (j = 0; j < KVM_IOAPIC_NUM_PINS; j++)
+                       new->chip[i][j] = -1;
 
        for (i = 0; i < nr; ++i) {
                r = -EINVAL;