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

[XEN][PATCH v9 10/19] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Fri, 18 Aug 2023 17:28:41 -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=YKa7svLG+XqwpbOJFC3IlsmtdaRP7xcFFG8yBKHlK2o=; b=lYqbKxBkBS+DAixYE4eEHDruUCrR02Hm/uTQ05vT9FpQKqFAWB6GvHp7VS1oQ++JL81ix0spO+O3oPQQap5XTVM5HoUfD6nlj9bWs3U+tgW5oubWw1UPKcPrpvHze4vil/m0MOrnYS85hoHvf6SMV6V/S7knjc3bXLuNInjNIQPJ6l0CB4r4ZCJcIwNz92IXhZ3dnA9vM4RglcID9kbquswJZgMF0UTcOfF2klua3shcKVoJb1aGKsHVA9+MmlMrZTp5XaA1CsAk/7QE666M3oDMHDZihNyB3pa/PDNBE8aNKXwOaMn8GS13sl+iVC/vbWoCGHgba6goGQaeEsWXrw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fCoQ8wtHCHwHDrtwLz6Y+9J7/j7DVniT05wPorWsLHb5Q0FRLldPqFYYkngeNX4sc2wqY+TmykMGcIeF1a1gHKtw0EtWCHt/QIVvWf6AsaqhgeSZENbBR6bLGIJC7SOEhUIyfIKIW7/jKfK6fxpgqimZs+DC6r/NfBIgXGVnbViPo7D9grcxVImGLttq5Ydfa3iPS2DH/YTapJTK3Ag8leo+YEsVvid+rjRJyZEhgxMmzgc5aeDlRPGqG2GndZSmeWyVCcyyq5HWpX2mT4Q/qsBZh50FrtFXjulwCOLS19Hb6ILBikzkql0Tqxh7fV/w+BeSMgp5dqR5WD3E4Preng==
  • Cc: <michal.orzel@xxxxxxx>, <sstabellini@xxxxxxxxxx>, <vikram.garhwal@xxxxxxx>, <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>
  • Delivery-date: Sat, 19 Aug 2023 00:29:22 +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 access by pci device assign/deassign and also
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>

---
    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 5796ee1f93..096ef2dd68 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -148,6 +148,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.
@@ -160,7 +162,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;
@@ -191,6 +196,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®.