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

[XEN][PATCH v12 10/20] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Tue, 5 Sep 2023 18:16:20 -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=FrgEsWcwxI+fxIg7Dz5RugaxhcdPFLlME4+MrASnUSw=; b=AT2m9zaG7bjnMwOj/ZSaCea/fUOtdSk/P8DL9tZ1/S4CrtblrjG6RqPaP1VPQi5XZO2+WkDGxe+e4OYC3y0IhLQjnN3VLNkB6x9Q49i2O+ugqmHzr6YntFBLS7FNK+JNr6yOs/AiWE1Jkh+uhyqeAcNzbTLlMQtsJx3Tk6sxzzyEo8Ci0yyV7wB6Br2wGi+y5F9v8EnQ134k5G3oCuwful5C0rM9U6KM3WIdQfBRtYlGtIGQQb7G9yFK1N8AElW76UqzBCiBuWLb1oO74OD7VI20sh/4Fm/nKIl1tQeqFvTGjS21NilSq5uoDOfFnBRMmxI/CPYUC7t7v429jWWO7w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bBg1DDNhP8qXdAIAGp4WVRdfKNF/Vhc1E2Ef4e/v7RtotSiVJn6SCq6luUbAwTXNYukBzUTzieXkoTcgpGI4sZYaY2K/zNmrHKJVxOd1oNu7otn+udHaOeTptmdZtGJVLfSy8W2RIYSpfaI7OJwHcsMtAbWXdgq/mZkP7z1E6jVYiEqDzZYNgTG9k0uAjjn1s9tHNXf4I6UTMq8A8zAXJWWbecjUm/IJrJy4RRjy0Rn60LvRS1Thwz6xMkgEFoDLCG3GaMcVHUtixKYWZdZUebtPL9mfsIle/d+mhalC+I1hT8PwyAI7wcsgOhBPHtS6vpF8b3OkAm8t+TDWt62NTg==
  • Cc: <vikram.garhwal@xxxxxxx>, <julien@xxxxxxx>, <michal.orzel@xxxxxxx>, <sstabellini@xxxxxxxxxx>
  • Delivery-date: Wed, 06 Sep 2023 01:16:50 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Protect iommu_add_dt_device() with dtdevs_lock to prevent concurrent access
to add/remove/assign/deassign.
With addition of dynamic programming feature(follow-up patches in this series),
this function can be concurrently accessed by dynamic node add/remove using
device tree overlays.

Signed-off-by: Vikram Garhwal <vikram.garhwal@xxxxxxx>
Reviewed-by: Luca Fancellu <luca.fancellu@xxxxxxx>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
Acked-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>

---
    Changes from v7:
        Update commit message and fix indent.
---
---
 xen/drivers/passthrough/device_tree.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/xen/drivers/passthrough/device_tree.c 
b/xen/drivers/passthrough/device_tree.c
index a7d86a20a0..687c61e7da 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -147,6 +147,8 @@ int iommu_add_dt_device(struct dt_device_node *np)
     if ( dev_iommu_fwspec_get(dev) )
         return 0;
 
+    spin_lock(&dtdevs_lock);
+
     /*
      * According to the Documentation/devicetree/bindings/iommu/iommu.txt
      * from Linux.
@@ -159,7 +161,10 @@ int iommu_add_dt_device(struct dt_device_node *np)
          * these callback implemented.
          */
         if ( !ops->add_device || !ops->dt_xlate )
-            return -EINVAL;
+        {
+            rc = -EINVAL;
+            goto fail;
+        }
 
         if ( !dt_device_is_available(iommu_spec.np) )
             break;
@@ -190,6 +195,8 @@ int iommu_add_dt_device(struct dt_device_node *np)
     if ( rc < 0 )
         iommu_fwspec_free(dev);
 
+ fail:
+    spin_unlock(&dtdevs_lock);
     return rc;
 }
 
-- 
2.17.1




 


Rackspace

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