debuggers.hg

changeset 20878:acd7d3f06d9a

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@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 21 09:11:06 2010 +0000 (2010-01-21)
parents 6a5d8284b6e6
children 961acb357740
files xen/arch/ia64/xen/dom0_ops.c xen/arch/x86/domctl.c xen/drivers/passthrough/iommu.c xen/drivers/passthrough/pci.c
line diff
     1.1 --- a/xen/arch/ia64/xen/dom0_ops.c	Thu Jan 21 09:03:20 2010 +0000
     1.2 +++ b/xen/arch/ia64/xen/dom0_ops.c	Thu Jan 21 09:11:06 2010 +0000
     1.3 @@ -354,8 +354,10 @@ long arch_do_domctl(xen_domctl_t *op, XE
     1.4          }
     1.5  
     1.6          ret = assign_device(d, bus, devfn);
     1.7 -        gdprintk(XENLOG_INFO, "XEN_DOMCTL_assign_device: bdf = %x:%x.%x\n",
     1.8 -                 bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
     1.9 +        if ( ret )
    1.10 +            gdprintk(XENLOG_ERR, "XEN_DOMCTL_assign_device: "
    1.11 +                     "assign device (%x:%x.%x) failed\n",
    1.12 +                     bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
    1.13          put_domain(d);
    1.14      }
    1.15      break;
    1.16 @@ -388,10 +390,14 @@ long arch_do_domctl(xen_domctl_t *op, XE
    1.17          if ( !device_assigned(bus, devfn) )
    1.18              break;
    1.19  
    1.20 -        ret = 0;
    1.21 -        deassign_device(d, bus, devfn);
    1.22 -        gdprintk(XENLOG_INFO, "XEN_DOMCTL_deassign_device: bdf = %x:%x.%x\n",
    1.23 -            bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
    1.24 +        spin_lock(&pcidevs_lock);
    1.25 +        ret = deassign_device(d, bus, devfn);
    1.26 +        spin_unlock(&pcidevs_lock);
    1.27 +        if ( ret )
    1.28 +            gdprintk(XENLOG_ERR, "XEN_DOMCTL_deassign_device: "
    1.29 +                     "deassign device (%x:%x.%x) failed\n",
    1.30 +                     bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
    1.31 +
    1.32          put_domain(d);
    1.33      }
    1.34      break;
     2.1 --- a/xen/arch/x86/domctl.c	Thu Jan 21 09:03:20 2010 +0000
     2.2 +++ b/xen/arch/x86/domctl.c	Thu Jan 21 09:11:06 2010 +0000
     2.3 @@ -842,12 +842,9 @@ long arch_do_domctl(
     2.4          if ( !iommu_pv_enabled && !is_hvm_domain(d) )
     2.5          {
     2.6              ret = -ENOSYS;
     2.7 -            put_domain(d);
     2.8 -            break;
     2.9 +            goto assign_device_out;
    2.10          }
    2.11  
    2.12 -        ret = -EINVAL;
    2.13 -
    2.14          ret = assign_device(d, bus, devfn);
    2.15          if ( ret )
    2.16              gdprintk(XENLOG_ERR, "XEN_DOMCTL_assign_device: "
    2.17 @@ -872,7 +869,7 @@ long arch_do_domctl(
    2.18          if ( unlikely((d = get_domain_by_id(domctl->domain)) == NULL) )
    2.19          {
    2.20              gdprintk(XENLOG_ERR,
    2.21 -                "XEN_DOMCTL_deassign_device: get_domain_by_id() failed\n"); 
    2.22 +                "XEN_DOMCTL_deassign_device: get_domain_by_id() failed\n");
    2.23              break;
    2.24          }
    2.25  
    2.26 @@ -886,15 +883,15 @@ long arch_do_domctl(
    2.27          if ( !iommu_pv_enabled && !is_hvm_domain(d) )
    2.28          {
    2.29              ret = -ENOSYS;
    2.30 -            put_domain(d);
    2.31 -            break;
    2.32 +            goto deassign_device_out;
    2.33          }
    2.34 -        ret = 0;
    2.35          spin_lock(&pcidevs_lock);
    2.36          ret = deassign_device(d, bus, devfn);
    2.37          spin_unlock(&pcidevs_lock);
    2.38 -        gdprintk(XENLOG_INFO, "XEN_DOMCTL_deassign_device: bdf = %x:%x.%x\n",
    2.39 -            bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
    2.40 +        if ( ret )
    2.41 +            gdprintk(XENLOG_ERR, "XEN_DOMCTL_deassign_device: "
    2.42 +                     "deassign device (%x:%x.%x) failed\n",
    2.43 +                     bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
    2.44  
    2.45      deassign_device_out:
    2.46          put_domain(d);
    2.47 @@ -948,7 +945,7 @@ long arch_do_domctl(
    2.48          ret = -EPERM;
    2.49          if ( !IS_PRIV(current->domain) &&
    2.50               !irq_access_permitted(current->domain, bind->machine_irq) )
    2.51 -            goto bind_out;
    2.52 +            goto unbind_out;
    2.53  
    2.54          if ( iommu_enabled )
    2.55          {
    2.56 @@ -958,6 +955,8 @@ long arch_do_domctl(
    2.57          }
    2.58          if ( ret < 0 )
    2.59              gdprintk(XENLOG_ERR, "pt_irq_destroy_bind failed!\n");
    2.60 +
    2.61 +    unbind_out:
    2.62          rcu_unlock_domain(d);
    2.63      }
    2.64      break;
     3.1 --- a/xen/drivers/passthrough/iommu.c	Thu Jan 21 09:03:20 2010 +0000
     3.2 +++ b/xen/drivers/passthrough/iommu.c	Thu Jan 21 09:11:06 2010 +0000
     3.3 @@ -234,23 +234,31 @@ int deassign_device(struct domain *d, u8
     3.4  {
     3.5      struct hvm_iommu *hd = domain_hvm_iommu(d);
     3.6      struct pci_dev *pdev = NULL;
     3.7 +    int ret = 0;
     3.8  
     3.9      if ( !iommu_enabled || !hd->platform_ops )
    3.10          return -EINVAL;
    3.11  
    3.12      ASSERT(spin_is_locked(&pcidevs_lock));
    3.13      pdev = pci_get_pdev(bus, devfn);
    3.14 -    if (!pdev)
    3.15 +    if ( !pdev )
    3.16          return -ENODEV;
    3.17  
    3.18 -    if (pdev->domain != d)
    3.19 +    if ( pdev->domain != d )
    3.20      {
    3.21          gdprintk(XENLOG_ERR VTDPREFIX,
    3.22                  "IOMMU: deassign a device not owned\n");
    3.23          return -EINVAL;
    3.24      }
    3.25  
    3.26 -    hd->platform_ops->reassign_device(d, dom0, bus, devfn);
    3.27 +    ret = hd->platform_ops->reassign_device(d, dom0, bus, devfn);
    3.28 +    if ( ret )
    3.29 +    {
    3.30 +        gdprintk(XENLOG_ERR VTDPREFIX,
    3.31 +                 "Deassign device (%x:%x.%x) failed!\n",
    3.32 +                 bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
    3.33 +        return ret;
    3.34 +    }
    3.35  
    3.36      if ( !has_arch_pdevs(d) && need_iommu(d) )
    3.37      {
    3.38 @@ -258,7 +266,7 @@ int deassign_device(struct domain *d, u8
    3.39          hd->platform_ops->teardown(d);
    3.40      }
    3.41  
    3.42 -    return 0;
    3.43 +    return ret;
    3.44  }
    3.45  
    3.46  int iommu_setup(void)
     4.1 --- a/xen/drivers/passthrough/pci.c	Thu Jan 21 09:03:20 2010 +0000
     4.2 +++ b/xen/drivers/passthrough/pci.c	Thu Jan 21 09:11:06 2010 +0000
     4.3 @@ -286,7 +286,10 @@ void pci_release_devices(struct domain *
     4.4      {
     4.5          pci_cleanup_msi(pdev);
     4.6          bus = pdev->bus; devfn = pdev->devfn;
     4.7 -        deassign_device(d, bus, devfn);
     4.8 +        if ( deassign_device(d, bus, devfn) )
     4.9 +            printk("domain %d: deassign device (%02x:%02x.%x) failed!\n",
    4.10 +                   d->domain_id, pdev->bus, PCI_SLOT(pdev->devfn),
    4.11 +                   PCI_FUNC(pdev->devfn));
    4.12      }
    4.13      spin_unlock(&pcidevs_lock);
    4.14  }