[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] vt-d: Fix ISA IRQ alias issue



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1195835985 0
# Node ID 81e63d66a64db06bc1912eb022fc468c4111abc8
# Parent  e40015e20548a14a71f437600f6b31313280360b
vt-d: Fix ISA IRQ alias issue

When assign multiple devices to guest which uses PIC, ISA IRQ alias
may occur. This patch splits ISA IRQ and GSI eoi function. In ISA IRQ
eoi function, searches all assigned mirqs and does eoi for the
corresponding mirqs which match the eoi ISA IRQ. Therefore fix ISA IRQ
alias issue.

Signed-off-by: Weidong Han <weidong.han@xxxxxxxxx>
---
 xen/arch/x86/hvm/irq.c        |   17 ++++--
 xen/arch/x86/hvm/vmx/intr.c   |   10 +--
 xen/arch/x86/hvm/vmx/vtd/io.c |  109 +++++++++++++++++++++++++++++-------------
 xen/include/asm-x86/hvm/irq.h |   13 +++--
 4 files changed, 102 insertions(+), 47 deletions(-)

diff -r e40015e20548 -r 81e63d66a64d xen/arch/x86/hvm/irq.c
--- a/xen/arch/x86/hvm/irq.c    Fri Nov 23 16:25:59 2007 +0000
+++ b/xen/arch/x86/hvm/irq.c    Fri Nov 23 16:39:45 2007 +0000
@@ -181,6 +181,7 @@ void hvm_set_pci_link_route(struct domai
 {
     struct hvm_irq *hvm_irq = &d->arch.hvm_domain.irq;
     u8 old_isa_irq;
+    int i;
 
     ASSERT((link <= 3) && (isa_irq <= 15));
 
@@ -192,12 +193,16 @@ void hvm_set_pci_link_route(struct domai
     hvm_irq->pci_link.route[link] = isa_irq;
 
     /* PCI pass-through fixup. */
-    if ( hvm_irq->dpci && hvm_irq->dpci->link[link].valid )
-    {
-        hvm_irq->dpci->girq[isa_irq] = hvm_irq->dpci->link[link];
-        if ( hvm_irq->dpci->girq[old_isa_irq].device ==
-             hvm_irq->dpci->link[link].device )
-            hvm_irq->dpci->girq[old_isa_irq].valid = 0;
+    if ( hvm_irq->dpci )
+    {
+        if ( old_isa_irq )
+            clear_bit(old_isa_irq, &hvm_irq->dpci->isairq_map);
+
+        for ( i = 0; i < NR_LINK; i++ )
+            if ( test_bit(i, &hvm_irq->dpci->link_map) &&
+                 hvm_irq->pci_link.route[i] )
+                set_bit(hvm_irq->pci_link.route[i],
+                        &hvm_irq->dpci->isairq_map);
     }
 
     if ( hvm_irq->pci_link_assert_count[link] == 0 )
diff -r e40015e20548 -r 81e63d66a64d xen/arch/x86/hvm/vmx/intr.c
--- a/xen/arch/x86/hvm/vmx/intr.c       Fri Nov 23 16:25:59 2007 +0000
+++ b/xen/arch/x86/hvm/vmx/intr.c       Fri Nov 23 16:39:45 2007 +0000
@@ -113,7 +113,7 @@ static void vmx_dirq_assist(struct vcpu 
     uint32_t device, intx;
     struct domain *d = v->domain;
     struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
-    struct dev_intx_gsi *dig;
+    struct dev_intx_gsi_link *digl;
 
     if ( !vtd_enabled || (v->vcpu_id != 0) || (hvm_irq_dpci == NULL) )
         return;
@@ -125,10 +125,10 @@ static void vmx_dirq_assist(struct vcpu 
         stop_timer(&hvm_irq_dpci->hvm_timer[irq_to_vector(irq)]);
         clear_bit(irq, &hvm_irq_dpci->dirq_mask);
 
-        list_for_each_entry ( dig, &hvm_irq_dpci->mirq[irq].dig_list, list )
-        {
-            device = dig->device;
-            intx = dig->intx;
+        list_for_each_entry ( digl, &hvm_irq_dpci->mirq[irq].digl_list, list )
+        {
+            device = digl->device;
+            intx = digl->intx;
             hvm_pci_intx_assert(d, device, intx);
             spin_lock(&hvm_irq_dpci->dirq_lock);
             hvm_irq_dpci->mirq[irq].pending++;
diff -r e40015e20548 -r 81e63d66a64d xen/arch/x86/hvm/vmx/vtd/io.c
--- a/xen/arch/x86/hvm/vmx/vtd/io.c     Fri Nov 23 16:25:59 2007 +0000
+++ b/xen/arch/x86/hvm/vmx/vtd/io.c     Fri Nov 23 16:39:45 2007 +0000
@@ -50,15 +50,15 @@ static void pt_irq_time_out(void *data)
     struct hvm_mirq_dpci_mapping *irq_map = data;
     unsigned int guest_gsi, machine_gsi = 0;
     struct hvm_irq_dpci *dpci = irq_map->dom->arch.hvm_domain.irq.dpci;
-    struct dev_intx_gsi *dig;
+    struct dev_intx_gsi_link *digl;
     uint32_t device, intx;
 
-    list_for_each_entry ( dig, &irq_map->dig_list, list )
-    {
-        guest_gsi = dig->gsi;
+    list_for_each_entry ( digl, &irq_map->digl_list, list )
+    {
+        guest_gsi = digl->gsi;
         machine_gsi = dpci->girq[guest_gsi].machine_gsi;
-        device = dig->device;
-        intx = dig->intx;
+        device = digl->device;
+        intx = digl->intx;
         hvm_pci_intx_deassert(irq_map->dom, device, intx);
     }
 
@@ -76,7 +76,7 @@ int pt_irq_create_bind_vtd(
     struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
     uint32_t machine_gsi, guest_gsi;
     uint32_t device, intx, link;
-    struct dev_intx_gsi *dig;
+    struct dev_intx_gsi_link *digl;
 
     if ( hvm_irq_dpci == NULL )
     {
@@ -87,7 +87,7 @@ int pt_irq_create_bind_vtd(
         memset(hvm_irq_dpci, 0, sizeof(*hvm_irq_dpci));
         spin_lock_init(&hvm_irq_dpci->dirq_lock);
         for ( int i = 0; i < NR_IRQS; i++ )
-            INIT_LIST_HEAD(&hvm_irq_dpci->mirq[i].dig_list);
+            INIT_LIST_HEAD(&hvm_irq_dpci->mirq[i].digl_list);
 
         if ( cmpxchg((unsigned long *)&d->arch.hvm_domain.irq.dpci,
                      0, (unsigned long)hvm_irq_dpci) != 0 )
@@ -101,26 +101,23 @@ int pt_irq_create_bind_vtd(
     intx = pt_irq_bind->u.pci.intx;
     guest_gsi = hvm_pci_intx_gsi(device, intx);
     link = hvm_pci_intx_link(device, intx);
-
-    dig = xmalloc(struct dev_intx_gsi);
-    if ( !dig )
+    set_bit(link, hvm_irq_dpci->link_map);
+
+    digl = xmalloc(struct dev_intx_gsi_link);
+    if ( !digl )
         return -ENOMEM;
 
-    dig->device = device;
-    dig->intx = intx;
-    dig->gsi = guest_gsi;
-    list_add_tail(&dig->list,
-                  &hvm_irq_dpci->mirq[machine_gsi].dig_list);
- 
+    digl->device = device;
+    digl->intx = intx;
+    digl->gsi = guest_gsi;
+    digl->link = link;
+    list_add_tail(&digl->list,
+                  &hvm_irq_dpci->mirq[machine_gsi].digl_list);
+
     hvm_irq_dpci->girq[guest_gsi].valid = 1;
     hvm_irq_dpci->girq[guest_gsi].device = device;
     hvm_irq_dpci->girq[guest_gsi].intx = intx;
     hvm_irq_dpci->girq[guest_gsi].machine_gsi = machine_gsi;
-
-    hvm_irq_dpci->link[link].valid = 1;
-    hvm_irq_dpci->link[link].device = device;
-    hvm_irq_dpci->link[link].intx = intx;
-    hvm_irq_dpci->link[link].machine_gsi = machine_gsi;
 
     /* Bind the same mirq once in the same domain */
     if ( !hvm_irq_dpci->mirq[machine_gsi].valid )
@@ -162,6 +159,46 @@ int hvm_do_IRQ_dpci(struct domain *d, un
     return 1;
 }
 
+static void hvm_dpci_isairq_eoi(struct domain *d, unsigned int isairq)
+{
+    struct hvm_irq *hvm_irq = &d->arch.hvm_domain.irq;
+    struct hvm_irq_dpci *dpci = hvm_irq->dpci;
+    struct dev_intx_gsi_link *digl, *tmp;
+    int i;
+
+    ASSERT(isairq < NR_ISAIRQS);
+    if ( !vtd_enabled || !dpci ||
+         !test_bit(isairq, dpci->isairq_map) )
+        return;
+
+    /* Multiple mirq may be mapped to one isa irq */
+    for ( i = 0; i < NR_IRQS; i++ )
+    {
+        if ( !dpci->mirq[i].valid )
+            continue;
+
+        list_for_each_entry_safe ( digl, tmp,
+            &dpci->mirq[i].digl_list, list )
+        {
+            if ( hvm_irq->pci_link.route[digl->link] == isairq )
+            {
+                hvm_pci_intx_deassert(d, digl->device, digl->intx);
+                spin_lock(&dpci->dirq_lock);
+                if ( --dpci->mirq[i].pending == 0 )
+                {
+                    spin_unlock(&dpci->dirq_lock);
+                    gdprintk(XENLOG_INFO,
+                             "hvm_dpci_isairq_eoi:: mirq = %x\n", i);
+                    stop_timer(&dpci->hvm_timer[irq_to_vector(i)]);
+                    pirq_guest_eoi(d, i);
+                }
+                else
+                    spin_unlock(&dpci->dirq_lock);
+            }
+        }
+    }
+}
+
 void hvm_dpci_eoi(struct domain *d, unsigned int guest_gsi,
                   union vioapic_redir_entry *ent)
 {
@@ -169,14 +206,21 @@ void hvm_dpci_eoi(struct domain *d, unsi
     uint32_t device, intx, machine_gsi;
 
     if ( !vtd_enabled || (hvm_irq_dpci == NULL) ||
-         !hvm_irq_dpci->girq[guest_gsi].valid )
-        return;
+         (guest_gsi >= NR_ISAIRQS &&
+          !hvm_irq_dpci->girq[guest_gsi].valid) )
+        return;
+
+    if ( guest_gsi < NR_ISAIRQS )
+    {
+        hvm_dpci_isairq_eoi(d, guest_gsi);
+        return;
+    }
 
     machine_gsi = hvm_irq_dpci->girq[guest_gsi].machine_gsi;
     device = hvm_irq_dpci->girq[guest_gsi].device;
     intx = hvm_irq_dpci->girq[guest_gsi].intx;
     hvm_pci_intx_deassert(d, device, intx);
- 
+
     spin_lock(&hvm_irq_dpci->dirq_lock);
     if ( --hvm_irq_dpci->mirq[machine_gsi].pending == 0 )
     {
@@ -196,9 +240,9 @@ void iommu_domain_destroy(struct domain 
     struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci;
     uint32_t i;
     struct hvm_iommu *hd  = domain_hvm_iommu(d);
-    struct list_head *ioport_list, *dig_list, *tmp;
+    struct list_head *ioport_list, *digl_list, *tmp;
     struct g2m_ioport *ioport;
-    struct dev_intx_gsi *dig;
+    struct dev_intx_gsi_link *digl;
 
     if ( !vtd_enabled )
         return;
@@ -211,12 +255,13 @@ void iommu_domain_destroy(struct domain 
                 pirq_guest_unbind(d, i);
                 kill_timer(&hvm_irq_dpci->hvm_timer[irq_to_vector(i)]);
 
-                list_for_each_safe ( dig_list, tmp,
-                                     &hvm_irq_dpci->mirq[i].dig_list )
+                list_for_each_safe ( digl_list, tmp,
+                                     &hvm_irq_dpci->mirq[i].digl_list )
                 {
-                    dig = list_entry(dig_list, struct dev_intx_gsi, list);
-                    list_del(&dig->list);
-                    xfree(dig);
+                    digl = list_entry(digl_list,
+                                      struct dev_intx_gsi_link, list);
+                    list_del(&digl->list);
+                    xfree(digl);
                 }
             }
 
diff -r e40015e20548 -r 81e63d66a64d xen/include/asm-x86/hvm/irq.h
--- a/xen/include/asm-x86/hvm/irq.h     Fri Nov 23 16:25:59 2007 +0000
+++ b/xen/include/asm-x86/hvm/irq.h     Fri Nov 23 16:39:45 2007 +0000
@@ -30,17 +30,18 @@
 #include <asm/hvm/vioapic.h>
 #include <public/hvm/save.h>
 
-struct dev_intx_gsi {
+struct dev_intx_gsi_link {
     struct list_head list;
     uint8_t device;
     uint8_t intx;
     uint8_t gsi;
+    uint8_t link;
 };
 
 struct hvm_mirq_dpci_mapping {
     uint8_t valid;
     int pending;
-    struct list_head dig_list;
+    struct list_head digl_list;
     struct domain *dom;
 };
 
@@ -51,15 +52,19 @@ struct hvm_girq_dpci_mapping {
     uint8_t machine_gsi;
 };
 
+#define NR_ISAIRQS  16
+#define NR_LINK     4
 struct hvm_irq_dpci {
     spinlock_t dirq_lock;
     /* Machine IRQ to guest device/intx mapping. */
     struct hvm_mirq_dpci_mapping mirq[NR_IRQS];
     /* Guest IRQ to guest device/intx mapping. */
     struct hvm_girq_dpci_mapping girq[NR_IRQS];
-    /* Link to guest device/intx mapping. */
-    struct hvm_girq_dpci_mapping link[4];
     DECLARE_BITMAP(dirq_mask, NR_IRQS);
+    /* Record of mapped ISA IRQs */
+    DECLARE_BITMAP(isairq_map, NR_ISAIRQS);
+    /* Record of mapped Links */
+    DECLARE_BITMAP(link_map, NR_LINK);
     struct timer hvm_timer[NR_IRQS];
 };
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.