WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] VT-d: correct allocation failure checks

To: <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] VT-d: correct allocation failure checks
From: "Jan Beulich" <jbeulich@xxxxxxxxxx>
Date: Fri, 17 Oct 2008 16:12:03 +0100
Delivery-date: Fri, 17 Oct 2008 08:11:35 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Checking the return value of map_domain_page() (and hence
map_vtd_domain_page()) against NULL is pointless, checking the return
value of alloc_domheap_page() (and thus alloc_pgtable_maddr()) is
mandatory, however.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>

Index: 2008-09-19/xen/drivers/passthrough/vtd/intremap.c
===================================================================
--- 2008-09-19.orig/xen/drivers/passthrough/vtd/intremap.c      2008-08-29 
14:26:56.000000000 +0200
+++ 2008-09-19/xen/drivers/passthrough/vtd/intremap.c   2008-10-17 
15:28:46.000000000 +0200
@@ -469,7 +469,7 @@ int intremap_setup(struct iommu *iommu)
         {
             dprintk(XENLOG_WARNING VTDPREFIX,
                     "Cannot allocate memory for ir_ctrl->iremap_maddr\n");
-            return -ENODEV;
+            return -ENOMEM;
         }
         ir_ctrl->iremap_index = -1;
     }
Index: 2008-09-19/xen/drivers/passthrough/vtd/iommu.c
===================================================================
--- 2008-09-19.orig/xen/drivers/passthrough/vtd/iommu.c 2008-09-17 
09:26:41.000000000 +0200
+++ 2008-09-19/xen/drivers/passthrough/vtd/iommu.c      2008-10-17 
15:24:55.000000000 +0200
@@ -220,10 +220,10 @@ static u64 addr_to_dma_page_maddr(struct
             if ( !alloc )
                 break;
             maddr = alloc_pgtable_maddr();
+            if ( !maddr )
+                break;
             dma_set_pte_addr(*pte, maddr);
             vaddr = map_vtd_domain_page(maddr);
-            if ( !vaddr )
-                break;
 
             /*
              * high level table always sets r/w, last level
@@ -236,8 +236,6 @@ static u64 addr_to_dma_page_maddr(struct
         else
         {
             vaddr = map_vtd_domain_page(pte->val);
-            if ( !vaddr )
-                break;
         }
 
         if ( level == 2 )
Index: 2008-09-19/xen/drivers/passthrough/vtd/qinval.c
===================================================================
--- 2008-09-19.orig/xen/drivers/passthrough/vtd/qinval.c        2008-07-18 
16:19:34.000000000 +0200
+++ 2008-09-19/xen/drivers/passthrough/vtd/qinval.c     2008-10-17 
15:29:24.000000000 +0200
@@ -429,7 +429,11 @@ int qinval_setup(struct iommu *iommu)
     {
         qi_ctrl->qinval_maddr = alloc_pgtable_maddr();
         if ( qi_ctrl->qinval_maddr == 0 )
-            panic("Cannot allocate memory for qi_ctrl->qinval_maddr\n");
+        {
+            dprintk(XENLOG_WARNING VTDPREFIX,
+                    "Cannot allocate memory for qi_ctrl->qinval_maddr\n");
+            return -ENOMEM;
+        }
         flush->context = flush_context_qi;
         flush->iotlb = flush_iotlb_qi;
     }
Index: 2008-09-19/xen/drivers/passthrough/vtd/x86/vtd.c
===================================================================
--- 2008-09-19.orig/xen/drivers/passthrough/vtd/x86/vtd.c       2008-06-02 
09:52:09.000000000 +0200
+++ 2008-09-19/xen/drivers/passthrough/vtd/x86/vtd.c    2008-10-17 
15:20:46.000000000 +0200
@@ -41,17 +41,19 @@ u64 alloc_pgtable_maddr(void)
 {
     struct page_info *pg;
     u64 *vaddr;
+    unsigned long mfn;
 
     pg = alloc_domheap_page(NULL, 0);
-    vaddr = map_domain_page(page_to_mfn(pg));
-    if ( !vaddr )
+    if ( !pg )
         return 0;
+    mfn = page_to_mfn(pg);
+    vaddr = map_domain_page(mfn);
     memset(vaddr, 0, PAGE_SIZE);
 
     iommu_flush_cache_page(vaddr);
     unmap_domain_page(vaddr);
 
-    return page_to_maddr(pg);
+    return (u64)mfn << PAGE_SHIFT_4K;
 }
 
 void free_pgtable_maddr(u64 maddr)




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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] VT-d: correct allocation failure checks, Jan Beulich <=