Skip to contentSkip to conversation

VT-d: Fix resource leaks on error paths

PATCH In review Igor Mammedov 2 participants 3 messages May 11, 2011 – May 12, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 VT-d: Fix resource leaks on error paths

On error exit from function, maped pages should be unmapped and acquired locks released.

xen/drivers/passthrough/vtd/intremap.c +8 -2
diff -r 4b0692880dfa -r da93d9e43b3c xen/drivers/passthrough/vtd/intremap.c
@@ -210,7 +210,8 @@
     if ( iremap_entries )
         unmap_vtd_domain_page(iremap_entries);
 
-    ir_ctrl->iremap_num++;
+    if ( i < IREMAP_ENTRY_NR ) 
+	    ir_ctrl->iremap_num++;
     return i;
 }
 
@@ -246,6 +247,8 @@
         dprintk(XENLOG_ERR VTDPREFIX,
                 "%s: index (%d) get an empty entry!\n",
                 __func__, index);
+	unmap_vtd_domain_page(iremap_entries);
+	spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
         return -EFAULT;
     }
 
@@ -281,7 +284,8 @@
     if ( index < 0 )
     {
         index = alloc_remap_entry(iommu);
-        apic_pin_2_ir_idx[apic][ioapic_pin] = index;
+        if ( index < IREMAP_ENTRY_NR )
+            apic_pin_2_ir_idx[apic][ioapic_pin] = index;
     }
 
     if ( index > IREMAP_ENTRY_NR - 1 )
@@ -546,6 +550,8 @@
         dprintk(XENLOG_ERR VTDPREFIX,
                 "%s: index (%d) get an empty entry!\n",
                 __func__, index);
+	unmap_vtd_domain_page(iremap_entries);
+	spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
         return -EFAULT;
     }
#1 lore raw

Will need an Ack from a VT-d maintainer (Allen Kay is listed in our MAINTAINERS file, and is CC'ed). Also needs a Signed-off-by line.

-- Keir

Quoted 49 lines · Igor Mammedov

On error exit from function, maped pages should be unmapped and acquired locks released.

diff -r 4b0692880dfa -r da93d9e43b3c xen/drivers/passthrough/vtd/intremap.c

xen/drivers/passthrough/vtd/intremap.c Wed May 11 12:29:54 2011 +0200 renamed from xen/drivers/passthrough/vtd/intremap.c Thu May 05 17:40:34 2011 +0100 +8 -2
@@ -210,7 +210,8 @@
     if ( iremap_entries )
         unmap_vtd_domain_page(iremap_entries);
 
-    ir_ctrl->iremap_num++;
+    if ( i < IREMAP_ENTRY_NR )
+     ir_ctrl->iremap_num++;
     return i;
 }
 
@@ -246,6 +247,8 @@
         dprintk(XENLOG_ERR VTDPREFIX,
                 "%s: index (%d) get an empty entry!\n",
                 __func__, index);
+ unmap_vtd_domain_page(iremap_entries);
+ spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
         return -EFAULT;
     }
 
@@ -281,7 +284,8 @@
     if ( index < 0 )
     {
         index = alloc_remap_entry(iommu);
-        apic_pin_2_ir_idx[apic][ioapic_pin] = index;
+        if ( index < IREMAP_ENTRY_NR )
+            apic_pin_2_ir_idx[apic][ioapic_pin] = index;
     }
 
     if ( index > IREMAP_ENTRY_NR - 1 )
@@ -546,6 +550,8 @@
         dprintk(XENLOG_ERR VTDPREFIX,
                 "%s: index (%d) get an empty entry!\n",
                 __func__, index);
+ unmap_vtd_domain_page(iremap_entries);
+ spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
         return -EFAULT;
     }
 

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

#2 lore raw

Thanks Keir,

I'll repost patch and cc Allen

Quoted 57 lines · Keir Fraser

Will need an Ack from a VT-d maintainer (Allen Kay is listed in our MAINTAINERS file, and is CC'ed). Also needs a Signed-off-by line.

-- Keir

Quoted 49 lines · Igor Mammedov

On error exit from function, maped pages should be unmapped and acquired locks released.

diff -r 4b0692880dfa -r da93d9e43b3c xen/drivers/passthrough/vtd/intremap.c

xen/drivers/passthrough/vtd/intremap.c Wed May 11 12:29:54 2011 +0200 renamed from xen/drivers/passthrough/vtd/intremap.c Thu May 05 17:40:34 2011 +0100 +8 -2
@@ -210,7 +210,8 @@
      if ( iremap_entries )
          unmap_vtd_domain_page(iremap_entries);
 
-    ir_ctrl->iremap_num++;
+    if ( i<  IREMAP_ENTRY_NR )
+     ir_ctrl->iremap_num++;
      return i;
  }
 
@@ -246,6 +247,8 @@
          dprintk(XENLOG_ERR VTDPREFIX,
                  "%s: index (%d) get an empty entry!\n",
                  __func__, index);
+ unmap_vtd_domain_page(iremap_entries);
+ spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
          return -EFAULT;
      }
 
@@ -281,7 +284,8 @@
      if ( index<  0 )
      {
          index = alloc_remap_entry(iommu);
-        apic_pin_2_ir_idx[apic][ioapic_pin] = index;
+        if ( index<  IREMAP_ENTRY_NR )
+            apic_pin_2_ir_idx[apic][ioapic_pin] = index;
      }
 
      if ( index>  IREMAP_ENTRY_NR - 1 )
@@ -546,6 +550,8 @@
          dprintk(XENLOG_ERR VTDPREFIX,
                  "%s: index (%d) get an empty entry!\n",
                  __func__, index);
+ unmap_vtd_domain_page(iremap_entries);
+ spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
          return -EFAULT;
      }
 

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