All of lore.kernel.org
 help / color / mirror / Atom feed
* [XEN][RFC PATCH v4 07/16] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller
@ 2022-12-07  6:18 Vikram Garhwal
  2022-12-07  6:18 ` [XEN][RFC PATCH v4 08/16] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Vikram Garhwal
                   ` (9 more replies)
  0 siblings, 10 replies; 31+ messages in thread
From: Vikram Garhwal @ 2022-12-07  6:18 UTC (permalink / raw)
  To: xen-devel; +Cc: sstabellini, julien, vikram.garhwal, Luca.Fancellu

Rename iommu_dt_device_is_assigned() to iommu_dt_device_is_assigned_lock().

Moving spin_lock to caller was done to prevent the concurrent access to
iommu_dt_device_is_assigned while doing add/remove/assign/deassign.

Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
---
 xen/drivers/passthrough/device_tree.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c
index 1c32d7b50c..bb4cf7784d 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -83,16 +83,15 @@ fail:
     return rc;
 }
 
-static bool_t iommu_dt_device_is_assigned(const struct dt_device_node *dev)
+static bool_t
+    iommu_dt_device_is_assigned_locked(const struct dt_device_node *dev)
 {
     bool_t assigned = 0;
 
     if ( !dt_device_is_protected(dev) )
         return 0;
 
-    spin_lock(&dtdevs_lock);
     assigned = !list_empty(&dev->domain_list);
-    spin_unlock(&dtdevs_lock);
 
     return assigned;
 }
@@ -213,27 +212,43 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d,
         if ( (d && d->is_dying) || domctl->u.assign_device.flags )
             break;
 
+        spin_lock(&dtdevs_lock);
+
         ret = dt_find_node_by_gpath(domctl->u.assign_device.u.dt.path,
                                     domctl->u.assign_device.u.dt.size,
                                     &dev);
         if ( ret )
+        {
+            spin_unlock(&dtdevs_lock);
+
             break;
+        }
 
         ret = xsm_assign_dtdevice(XSM_HOOK, d, dt_node_full_name(dev));
         if ( ret )
+        {
+            spin_unlock(&dtdevs_lock);
+
             break;
+        }
 
         if ( domctl->cmd == XEN_DOMCTL_test_assign_device )
         {
-            if ( iommu_dt_device_is_assigned(dev) )
+
+            if ( iommu_dt_device_is_assigned_locked(dev) )
             {
                 printk(XENLOG_G_ERR "%s already assigned.\n",
                        dt_node_full_name(dev));
                 ret = -EINVAL;
             }
+
+            spin_unlock(&dtdevs_lock);
+
             break;
         }
 
+        spin_unlock(&dtdevs_lock);
+
         if ( d == dom_io )
             return -EINVAL;
 
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2023-02-10 23:24 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07  6:18 [XEN][RFC PATCH v4 07/16] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Vikram Garhwal
2022-12-07  6:18 ` [XEN][RFC PATCH v4 08/16] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Vikram Garhwal
2022-12-07  6:18 ` [XEN][RFC PATCH v4 09/16] xen/iommu: Introduce iommu_remove_dt_device() Vikram Garhwal
2023-01-23 10:00   ` Michal Orzel
2023-01-23 10:06     ` Julien Grall
2023-02-10  7:06     ` Vikram Garhwal
2022-12-07  6:18 ` [XEN][RFC PATCH v4 10/16] asm/smp.h: move cpu related function to asm/cpu.h Vikram Garhwal
2022-12-07  8:38   ` Jan Beulich
2022-12-07 16:28   ` Julien Grall
2022-12-07 19:39     ` Vikram Garhwal
2022-12-08  8:18       ` Jan Beulich
2022-12-07  6:18 ` [XEN][RFC PATCH v4 11/16] common/device_tree: Add rwlock for dt_host Vikram Garhwal
2022-12-07 16:31   ` Julien Grall
2023-02-01 17:05     ` Vikram Garhwal
2023-02-10 18:48       ` Julien Grall
2022-12-07  6:18 ` [XEN][RFC PATCH v4 12/16] xen/arm: Implement device tree node removal functionalities Vikram Garhwal
2022-12-07  8:41   ` Jan Beulich
2023-02-01 17:21     ` Vikram Garhwal
2023-01-24  9:01   ` Michal Orzel
2023-02-10 23:24     ` Vikram Garhwal
2022-12-07  6:18 ` [XEN][RFC PATCH v4 13/16] xen/arm: Implement device tree node addition functionalities Vikram Garhwal
2023-01-24 10:56   ` Michal Orzel
2022-12-07  6:18 ` [XEN][RFC PATCH v4 14/16] tools/libs/ctrl: Implement new xc interfaces for dt overlay Vikram Garhwal
2022-12-09 16:07   ` Anthony PERARD
2022-12-07  6:18 ` [XEN][RFC PATCH v4 15/16] tools/libs/light: Implement new libxl functions for device tree overlay ops Vikram Garhwal
2022-12-09 16:59   ` Anthony PERARD
2023-02-01 17:22     ` Vikram Garhwal
2022-12-07  6:18 ` [XEN][RFC PATCH v4 16/16] tools/xl: Add new xl command overlay for device tree overlay support Vikram Garhwal
2022-12-09 17:55   ` Anthony PERARD
2023-02-01 17:24     ` Vikram Garhwal
2023-01-23  9:54 ` [XEN][RFC PATCH v4 07/16] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Michal Orzel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.