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

[XEN][PATCH v10 09/20] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Fri, 25 Aug 2023 01:02:11 -0700
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bbLjByfblu66od1Vdrl71+ZR1WzFVQiYpHtzjdK7oJE=; b=JgZmabtjnrUSQyY139mI246NXEqOR1/m/2UoBHxKatWJL89GUW00VJ3Klx9L/AIPgDVcorP0eE86dyNmruwLPyy0ySnMrqXBmXkeAXdBc2KP8iou0dj25+fQ4jvt7YH4idFgmizqAIcXnct6FjkNRmCFLdRIzSSrnve9OtjH/ocTbrG1l0V3vkPSBE7jYnUOj6Fi0oXY89rKj0J7PuwksTBEguN2kGjm8GhXIzZtqoH71xtib1pk4doILmFEokRVv0Ipebpet7tUyeRZzJ4GY2kuhg7VWqOkPYz3L71/ShjRXFokZh33XY9uqj8wjye2Zs8roOy3aKIm0DsVy4zrEg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AibZfvB1j1eJmcQxa9jPL9SsdKUIKL/J9ZgWdVJa7KcwnVhYskpucGOZe+RQOlvyp0BS/fjbW4ruHwhZO9VCl/WlEZNaEEaVn6huN9UoGbi+2D0rWMMbPdOFbwe+lM24cB7QCzJI7rtvxpN4bVL01sO5Z6MRuRZpx8ti+eW0G5v78UJITyyLFsQlHMzcqOXZAK0Kvwxhx40hFPuwsQ5Q/SOxggG7pd8wRHZHT2GHDzPhmFkCpJ1AEaVn3EXVh8E+2fU3NvWfauKO+DulTq5r1gDUDNEhb0x6SCSYCMThOkeBvWwVz4bDIwsV84dThCYjlPo3SPzSh2TQJHVld4WLag==
  • Cc: <michal.orzel@xxxxxxx>, <sstabellini@xxxxxxxxxx>, <vikram.garhwal@xxxxxxx>, <julien@xxxxxxx>
  • Delivery-date: Fri, 25 Aug 2023 08:03:20 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Rename iommu_dt_device_is_assigned() to iommu_dt_device_is_assigned_locked().

Moving spin_lock to caller was done to prevent the concurrent access to
iommu_dt_device_is_assigned while doing add/remove/assign/deassign. Follow-up
patches in this series introduces node add/remove feature.

Signed-off-by: Vikram Garhwal <vikram.garhwal@xxxxxxx>

---
Changes from v9:
    Make iommu_dt_device_is_assigned_locked() static and delete header.
    Move dtdevs_lock before iommu_dt_device_is_assigned_locked().
Changes from v7:
    Update commit message.
    Add ASSERT().
---
---
 xen/drivers/passthrough/device_tree.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/xen/drivers/passthrough/device_tree.c 
b/xen/drivers/passthrough/device_tree.c
index 1c32d7b50c..5d84c07b50 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -83,16 +83,17 @@ 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;
 
+    ASSERT(spin_is_locked(&dtdevs_lock));
+
     if ( !dt_device_is_protected(dev) )
         return 0;
 
-    spin_lock(&dtdevs_lock);
     assigned = !list_empty(&dev->domain_list);
-    spin_unlock(&dtdevs_lock);
 
     return assigned;
 }
@@ -223,17 +224,24 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct 
domain *d,
         if ( ret )
             break;
 
+        spin_lock(&dtdevs_lock);
+
         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




 


Rackspace

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