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

[Xen-changelog] [xen-unstable] VT-d: handle return value of deassign_device



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1264065066 0
# Node ID acd7d3f06d9aea147dcd7ea3830574cb64bce41b
# Parent  6a5d8284b6e686fd3570bdb1d4ad8aba65b41bf7
VT-d: handle return value of deassign_device

deassign_device may fail, so need to capture its failure for
appropriate handling. This patch captures return values of
deassign_device, and prints error messages if it fails.

In addition, this patch also fixes some code style issues.

Signed-off-by: Weidong Han <Weidong.han@xxxxxxxxx>
---
 xen/arch/ia64/xen/dom0_ops.c    |   18 ++++++++++++------
 xen/arch/x86/domctl.c           |   25 ++++++++++++-------------
 xen/drivers/passthrough/iommu.c |   16 ++++++++++++----
 xen/drivers/passthrough/pci.c   |    5 ++++-
 4 files changed, 40 insertions(+), 24 deletions(-)

diff -r 6a5d8284b6e6 -r acd7d3f06d9a xen/arch/ia64/xen/dom0_ops.c
--- a/xen/arch/ia64/xen/dom0_ops.c      Thu Jan 21 09:03:20 2010 +0000
+++ b/xen/arch/ia64/xen/dom0_ops.c      Thu Jan 21 09:11:06 2010 +0000
@@ -354,8 +354,10 @@ long arch_do_domctl(xen_domctl_t *op, XE
         }
 
         ret = assign_device(d, bus, devfn);
-        gdprintk(XENLOG_INFO, "XEN_DOMCTL_assign_device: bdf = %x:%x.%x\n",
-                 bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
+        if ( ret )
+            gdprintk(XENLOG_ERR, "XEN_DOMCTL_assign_device: "
+                     "assign device (%x:%x.%x) failed\n",
+                     bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
         put_domain(d);
     }
     break;
@@ -388,10 +390,14 @@ long arch_do_domctl(xen_domctl_t *op, XE
         if ( !device_assigned(bus, devfn) )
             break;
 
-        ret = 0;
-        deassign_device(d, bus, devfn);
-        gdprintk(XENLOG_INFO, "XEN_DOMCTL_deassign_device: bdf = %x:%x.%x\n",
-            bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
+        spin_lock(&pcidevs_lock);
+        ret = deassign_device(d, bus, devfn);
+        spin_unlock(&pcidevs_lock);
+        if ( ret )
+            gdprintk(XENLOG_ERR, "XEN_DOMCTL_deassign_device: "
+                     "deassign device (%x:%x.%x) failed\n",
+                     bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
+
         put_domain(d);
     }
     break;
diff -r 6a5d8284b6e6 -r acd7d3f06d9a xen/arch/x86/domctl.c
--- a/xen/arch/x86/domctl.c     Thu Jan 21 09:03:20 2010 +0000
+++ b/xen/arch/x86/domctl.c     Thu Jan 21 09:11:06 2010 +0000
@@ -842,11 +842,8 @@ long arch_do_domctl(
         if ( !iommu_pv_enabled && !is_hvm_domain(d) )
         {
             ret = -ENOSYS;
-            put_domain(d);
-            break;
-        }
-
-        ret = -EINVAL;
+            goto assign_device_out;
+        }
 
         ret = assign_device(d, bus, devfn);
         if ( ret )
@@ -872,7 +869,7 @@ long arch_do_domctl(
         if ( unlikely((d = get_domain_by_id(domctl->domain)) == NULL) )
         {
             gdprintk(XENLOG_ERR,
-                "XEN_DOMCTL_deassign_device: get_domain_by_id() failed\n"); 
+                "XEN_DOMCTL_deassign_device: get_domain_by_id() failed\n");
             break;
         }
 
@@ -886,15 +883,15 @@ long arch_do_domctl(
         if ( !iommu_pv_enabled && !is_hvm_domain(d) )
         {
             ret = -ENOSYS;
-            put_domain(d);
-            break;
-        }
-        ret = 0;
+            goto deassign_device_out;
+        }
         spin_lock(&pcidevs_lock);
         ret = deassign_device(d, bus, devfn);
         spin_unlock(&pcidevs_lock);
-        gdprintk(XENLOG_INFO, "XEN_DOMCTL_deassign_device: bdf = %x:%x.%x\n",
-            bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
+        if ( ret )
+            gdprintk(XENLOG_ERR, "XEN_DOMCTL_deassign_device: "
+                     "deassign device (%x:%x.%x) failed\n",
+                     bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
 
     deassign_device_out:
         put_domain(d);
@@ -948,7 +945,7 @@ long arch_do_domctl(
         ret = -EPERM;
         if ( !IS_PRIV(current->domain) &&
              !irq_access_permitted(current->domain, bind->machine_irq) )
-            goto bind_out;
+            goto unbind_out;
 
         if ( iommu_enabled )
         {
@@ -958,6 +955,8 @@ long arch_do_domctl(
         }
         if ( ret < 0 )
             gdprintk(XENLOG_ERR, "pt_irq_destroy_bind failed!\n");
+
+    unbind_out:
         rcu_unlock_domain(d);
     }
     break;
diff -r 6a5d8284b6e6 -r acd7d3f06d9a xen/drivers/passthrough/iommu.c
--- a/xen/drivers/passthrough/iommu.c   Thu Jan 21 09:03:20 2010 +0000
+++ b/xen/drivers/passthrough/iommu.c   Thu Jan 21 09:11:06 2010 +0000
@@ -234,23 +234,31 @@ int deassign_device(struct domain *d, u8
 {
     struct hvm_iommu *hd = domain_hvm_iommu(d);
     struct pci_dev *pdev = NULL;
+    int ret = 0;
 
     if ( !iommu_enabled || !hd->platform_ops )
         return -EINVAL;
 
     ASSERT(spin_is_locked(&pcidevs_lock));
     pdev = pci_get_pdev(bus, devfn);
-    if (!pdev)
+    if ( !pdev )
         return -ENODEV;
 
-    if (pdev->domain != d)
+    if ( pdev->domain != d )
     {
         gdprintk(XENLOG_ERR VTDPREFIX,
                 "IOMMU: deassign a device not owned\n");
         return -EINVAL;
     }
 
-    hd->platform_ops->reassign_device(d, dom0, bus, devfn);
+    ret = hd->platform_ops->reassign_device(d, dom0, bus, devfn);
+    if ( ret )
+    {
+        gdprintk(XENLOG_ERR VTDPREFIX,
+                 "Deassign device (%x:%x.%x) failed!\n",
+                 bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
+        return ret;
+    }
 
     if ( !has_arch_pdevs(d) && need_iommu(d) )
     {
@@ -258,7 +266,7 @@ int deassign_device(struct domain *d, u8
         hd->platform_ops->teardown(d);
     }
 
-    return 0;
+    return ret;
 }
 
 int iommu_setup(void)
diff -r 6a5d8284b6e6 -r acd7d3f06d9a xen/drivers/passthrough/pci.c
--- a/xen/drivers/passthrough/pci.c     Thu Jan 21 09:03:20 2010 +0000
+++ b/xen/drivers/passthrough/pci.c     Thu Jan 21 09:11:06 2010 +0000
@@ -286,7 +286,10 @@ void pci_release_devices(struct domain *
     {
         pci_cleanup_msi(pdev);
         bus = pdev->bus; devfn = pdev->devfn;
-        deassign_device(d, bus, devfn);
+        if ( deassign_device(d, bus, devfn) )
+            printk("domain %d: deassign device (%02x:%02x.%x) failed!\n",
+                   d->domain_id, pdev->bus, PCI_SLOT(pdev->devfn),
+                   PCI_FUNC(pdev->devfn));
     }
     spin_unlock(&pcidevs_lock);
 }

_______________________________________________
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®.