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

[xen master] xen: do not return -EEXIST if iommu_add_dt_device is called twice



commit 3be443e726626913e328a9a7123cdd19f1c49edb
Author:     Stefano Stabellini <sstabellini@xxxxxxxxxx>
AuthorDate: Mon Aug 2 17:24:07 2021 -0700
Commit:     Julien Grall <jgrall@xxxxxxxxxx>
CommitDate: Tue Aug 3 10:38:55 2021 +0100

    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
    XEN_DOMCTL_assign_device).
    
    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>
    Acked-by: Julien Grall <jgrall@xxxxxxxxxx>
---
 xen/drivers/passthrough/device_tree.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/xen/drivers/passthrough/device_tree.c 
b/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",
                    dt_node_full_name(dev));
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

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