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

[PATCH v6 2/4] xen: do not return -EEXIST if iommu_add_dt_device is called twice

iommu_add_dt_device() returns -EEXIST if the device was already
registered. At the moment, this can only happen if the device was
already assigned to a domain (either dom0 at boot or via

In a follow-up patch, we will convert the SMMU driver to use the FW
spec. When the legacy bindings are used, all the devices will be
registered at probe. Therefore, iommu_add_dt_device() will always
returns -EEXIST.

Currently, one caller (XEN_DOMCTL_assign_device) will check the return
and ignore -EEXIST. All the other will fail because it was technically a
programming error.

However, there is no harm to call iommu_add_dt_device() twice, so we can
simply return 0.

With that in place the caller doesn't need to check -EEXIST anymore, so
remove the check.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxx>
Changes in v6:
- improve in-code comment
- improve commit message
- remove stale in-code comment

Changes in v5:
- new patch
 xen/drivers/passthrough/device_tree.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/xen/drivers/passthrough/device_tree.c 
index 999b831d90..9249f21c01 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -140,8 +140,12 @@ int iommu_add_dt_device(struct dt_device_node *np)
     if ( !ops )
         return -EINVAL;
+    /*
+     * The device may already have been registered. As there is no harm in
+     * it just return success early.
+     */
     if ( dev_iommu_fwspec_get(dev) )
-        return -EEXIST;
+        return 0;
      * According to the Documentation/devicetree/bindings/iommu/iommu.txt
@@ -249,12 +253,7 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct 
domain *d,
             return -EINVAL;
         ret = iommu_add_dt_device(dev);
-        /*
-         * Ignore "-EEXIST" error code as it would mean that the device is
-         * already added to the IOMMU (positive result). Such happens after
-         * re-creating guest domain.
-         */
-        if ( ret < 0 && ret != -EEXIST )
+        if ( ret < 0 )
             printk(XENLOG_G_ERR "Failed to add %s to the IOMMU\n",



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.