vfio: powerpc/spapr: Rework groups attaching
authorAlexey Kardashevskiy <aik@ozlabs.ru>
Fri, 5 Jun 2015 06:35:04 +0000 (16:35 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 11 Jun 2015 05:14:56 +0000 (15:14 +1000)
This is to make extended ownership and multiple groups support patches
simpler for review.

This should cause no behavioural change.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
[aw: for the vfio related changes]
Acked-by: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
drivers/vfio/vfio_iommu_spapr_tce.c

index cf5d4a159ce97e4fdad3d1fbfabbe203c9df61ca..e65bc73cc8a8b8c421f73f5cde804f34af2182e7 100644 (file)
@@ -460,16 +460,21 @@ static int tce_iommu_attach_group(void *iommu_data,
                                iommu_group_id(container->tbl->it_group),
                                iommu_group_id(iommu_group));
                ret = -EBUSY;
-       } else if (container->enabled) {
+               goto unlock_exit;
+       }
+
+       if (container->enabled) {
                pr_err("tce_vfio: attaching group #%u to enabled container\n",
                                iommu_group_id(iommu_group));
                ret = -EBUSY;
-       } else {
-               ret = iommu_take_ownership(tbl);
-               if (!ret)
-                       container->tbl = tbl;
+               goto unlock_exit;
        }
 
+       ret = iommu_take_ownership(tbl);
+       if (!ret)
+               container->tbl = tbl;
+
+unlock_exit:
        mutex_unlock(&container->lock);
 
        return ret;
@@ -487,19 +492,22 @@ static void tce_iommu_detach_group(void *iommu_data,
                pr_warn("tce_vfio: detaching group #%u, expected group is #%u\n",
                                iommu_group_id(iommu_group),
                                iommu_group_id(tbl->it_group));
-       } else {
-               if (container->enabled) {
-                       pr_warn("tce_vfio: detaching group #%u from enabled container, forcing disable\n",
-                                       iommu_group_id(tbl->it_group));
-                       tce_iommu_disable(container);
-               }
+               goto unlock_exit;
+       }
 
-               /* pr_debug("tce_vfio: detaching group #%u from iommu %p\n",
-                               iommu_group_id(iommu_group), iommu_group); */
-               container->tbl = NULL;
-               tce_iommu_clear(container, tbl, tbl->it_offset, tbl->it_size);
-               iommu_release_ownership(tbl);
+       if (container->enabled) {
+               pr_warn("tce_vfio: detaching group #%u from enabled container, forcing disable\n",
+                               iommu_group_id(tbl->it_group));
+               tce_iommu_disable(container);
        }
+
+       /* pr_debug("tce_vfio: detaching group #%u from iommu %p\n",
+          iommu_group_id(iommu_group), iommu_group); */
+       container->tbl = NULL;
+       tce_iommu_clear(container, tbl, tbl->it_offset, tbl->it_size);
+       iommu_release_ownership(tbl);
+
+unlock_exit:
        mutex_unlock(&container->lock);
 }