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

[XEN][PATCH v11 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: Thu, 31 Aug 2023 21:59:36 -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=WEOO1lNx/ONa1/nR//BBauJgW25xq4jXfGIfpWrsOLc=; b=k7b2W91nzQFMU6ESbBF1UvA30Fkm9sybCmpyb5lFZ80KKO1HwtFI1E9VnUMwHzy50A6GTMU38YAyCeT71hP+gB9ILxXcnk+3iziYcucEvLJpAD+0Wl6xXRWgAmbQpF3QPcP+YQ/mW1eA+QsKcaE3RTyoLeHR2sFw/gqqCl4Ag1FTGeqb9pdcp5FrAZv6ugeRAEKhrsd3tc7vP6+/ynEPhsH02lHJPFSakDNKycu8jNCdHE/NpBJ1AokSX/3NdmvFxbBzgHhPBHY6P1gfnisbJBvMcmYoWt8GgcQ+bl5Uyny2BWlw6dl/o6LkNQJCQPgAu06wNqYmy0TmGiEaJXygqw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dr5mBEqYlmHRjj1Im62kymab8EtDJgUc9wueBAxgJggdavG6pukTli+nCzSbI5Q6FA2GLnPQUIot67oWzOQpZwVpReDHGeIvb4K/GEzz1q14g0q4Twn6YiJQTDF06s/otON5Ln3qwkecY+sNOS04BHyRbUS5UFBP1w43USpHQWfqkGIyV96bDOTvE5X6AIpqatYps9eoJwk4hPs5P5hVAfsiTYE3LAfEpjEbKAyuhHoxpPq+DMZOUqxOoTd0lrqYBuE6vV6hRmALEjJS2yVv7oF0TbQUw49zOp025yUlllJX+uGKXZY5iP1J40K/JsgubDXQMRj7AvLADlTTbiLAgg==
  • Cc: <vikram.garhwal@xxxxxxx>, <julien@xxxxxxx>, <michal.orzel@xxxxxxx>, <sstabellini@xxxxxxxxxx>
  • Delivery-date: Fri, 01 Sep 2023 05:11:15 +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>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
---
Changes from v10:
    Move spin_lock before iommu_dt_device_is_assigned_locked() call.
    Rebase the patch with latest Xen.
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 | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/xen/drivers/passthrough/device_tree.c 
b/xen/drivers/passthrough/device_tree.c
index 3c0322c797..a7d86a20a0 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -83,16 +83,16 @@ fail:
     return rc;
 }
 
-static bool iommu_dt_device_is_assigned(const struct dt_device_node *dev)
+static bool iommu_dt_device_is_assigned_locked(const struct dt_device_node 
*dev)
 {
     bool assigned = false;
 
+    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;
 }
@@ -225,12 +225,16 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct 
domain *d,
 
         if ( domctl->cmd == XEN_DOMCTL_test_assign_device )
         {
-            if ( iommu_dt_device_is_assigned(dev) )
+            spin_lock(&dtdevs_lock);
+
+            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;
         }
 
-- 
2.17.1




 


Rackspace

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