Skip to contentSkip to conversation

Free unused interrupt remapping table entry

PATCH New Zhai, Edwin 1 participant 1 message Nov 27, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Free unused interrupt remapping table entry

This patch changes the IRTE allocation method, and frees unused IRTE when device is de-assigned.

xen/arch/x86/msi.c +5 -0
Index: xen-dev/xen/arch/x86/msi.c
===================================================================
@@ -438,6 +438,11 @@ int msi_free_irq(struct msi_desc *entry)
         start = (unsigned long)entry->mask_base & ~(PAGE_SIZE - 1);
         msix_put_fixmap(entry->dev, virt_to_fix(start));
     }
+
+    /* Free the unused IRTE if intr remap enabled */
+    if ( iommu_enabled )
+        iommu_update_ire_from_msi(entry, NULL);
+
     list_del(&entry->list);
     xfree(entry);
     return 0;
xen/drivers/passthrough/vtd/intremap.c +109 -36

237 lines not on this page · raw message

xen/drivers/passthrough/vtd/iommu.h +15 -1
Index: xen-dev/xen/drivers/passthrough/vtd/iommu.h
===================================================================
@@ -325,6 +325,20 @@ struct iremap_entry {
 #define iremap_set_present(v) do {(v).lo |= 1;} while(0)
 #define iremap_clear_present(v) do {(v).lo &= ~1;} while(0)
 
+/*
+ * Get the intr remap entry:
+ * maddr   - machine addr of the table
+ * index   - index of the entry
+ * entries - return addr of the page holding this entry, need unmap it
+ * entry   - return required entry
+ */
+#define GET_IREMAP_ENTRY(maddr, index, entries, entry)                        \
+do {                                                                          \
+    entries = (struct iremap_entry *)map_vtd_domain_page(                     \
+              (maddr) + (( (index) >> IREMAP_ENTRY_ORDER ) << PAGE_SHIFT ) ); \
+    entry = &entries[(index) % (1 << IREMAP_ENTRY_ORDER)];                    \
+} while(0)
+
 /* queue invalidation entry */
 struct qinval_entry {
     union {
@@ -472,7 +486,7 @@ struct qi_ctrl {
 
 struct ir_ctrl {
     u64 iremap_maddr;            /* interrupt remap table machine address */
-    int iremap_index;            /* interrupt remap index */
+    int iremap_num;              /* total num of used interrupt remap entry */
     spinlock_t iremap_lock;      /* lock for irq remappping table */
 };
 
xen/drivers/passthrough/vtd/utils.c +11 -6
Index: xen-dev/xen/drivers/passthrough/vtd/utils.c
===================================================================
@@ -227,6 +227,7 @@ static void dump_iommu_info(unsigned cha
             u64 iremap_maddr = dmar_readq(iommu->reg, DMAR_IRTA_REG);
             int nr_entry = 1 << ((iremap_maddr & 0xF) + 1);
             struct iremap_entry *iremap_entries = NULL;
+            int print_cnt = 0;
 
             printk("  Interrupt remapping table (nr_entry=0x%x. "
                 "Only dump P=1 entries here):\n", nr_entry);
@@ -238,14 +239,14 @@ static void dump_iommu_info(unsigned cha
                 if ( i % (1 << IREMAP_ENTRY_ORDER) == 0 )
                 {
                     /* This entry across page boundry */
-                    u64 entry_base = iremap_maddr +
-                        (( i >> IREMAP_ENTRY_ORDER ) << PAGE_SHIFT );
                     if ( iremap_entries )
                         unmap_vtd_domain_page(iremap_entries);
-                    iremap_entries =
-                        (struct iremap_entry *)map_vtd_domain_page(entry_base);
+
+                    GET_IREMAP_ENTRY(iremap_maddr, i,
+                                     iremap_entries, p);
                 }
-                p = &iremap_entries[i % (1 << IREMAP_ENTRY_ORDER)];
+                else
+                    p = &iremap_entries[i % (1 << IREMAP_ENTRY_ORDER)];
 
                 if ( !p->lo.p )
                     continue;
@@ -255,9 +256,13 @@ static void dump_iommu_info(unsigned cha
                     (u32)p->lo.dst, (u32)p->lo.vector, (u32)p->lo.avail,
                     (u32)p->lo.dlm, (u32)p->lo.tm, (u32)p->lo.rh,
                     (u32)p->lo.dm, (u32)p->lo.fpd, (u32)p->lo.p);
+                print_cnt++;
             }
             if ( iremap_entries )
                 unmap_vtd_domain_page(iremap_entries);
+            if ( iommu_ir_ctrl(iommu)->iremap_num != print_cnt )
+                printk("Warning: Print %d IRTE (actually have %d)!\n",
+                        print_cnt, iommu_ir_ctrl(iommu)->iremap_num);
 
         }
     }
@@ -276,7 +281,7 @@ static void dump_iommu_info(unsigned cha
             iommu = ioapic_to_iommu(mp_ioapics[apic].mpc_apicid);
             ir_ctrl = iommu_ir_ctrl(iommu);
             if ( !iommu || !ir_ctrl || ir_ctrl->iremap_maddr == 0 ||
-                ir_ctrl->iremap_index == -1 )
+                ir_ctrl->iremap_num == 0 )
                 continue;
 
             printk( "\nRedirection table of IOAPIC %x:\n", apic);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel