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

[XEN][RFC PATCH v4 08/16] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Tue, 6 Dec 2022 22:18:07 -0800
  • 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=qd0QFdZvzHUGWrw0BfIrEu3cWkp8jWSV4vPT9FURuHE=; b=hikzcibQ0nJOOKfCK5FgUvIPTCOdqHLUb/xiWwNXEa1M3jUmktZctPe1ByZF0GVsk/+0BM1XDum5OosYsGUJJEDT5v8w8jubwt+gtuHFiX1QEy1yErWKZWSgC3I23cuXA1u5PB/XJ2I+1eIli5kfzIHRRO+BnSbqvi5v5EVoDJPQ4cPYiKVZA8i/xgpVxAjs7OxbSE2Cq3N1rUW/NdtqaaFquIv1L/C5uvlNIG2Huh/54Bd18dldS8P+MqBwP4wrCJJpNThevjKJqK16/RUm6swkwVxzo8JkFZxxdxNdPhIvMuZq9wtoCDsRUpq0EnYJYH/8g8gk6wDFJdvo0CKZxw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=COXahS98tM4FADTgTRdCU6PTsyCqJ90PakUz/8fXKjZw5LsbiM6Wuj+SHG0lWu79gwATRYIpEMMP4lqE4mfNw9juwYBBl69Vv1HdisG1hIiHeVkzER0NKpw/LXALWsX7OI34v/YSLIk7DLQACK1d/FmcU0Ep006hHn67WCxsKWFlG+RFwRtuf2TdwNArnT3c0NSunt0HNKCLXS2ixaWf2p+Bm1LQkcLVp1RF6bCD8vS2Rqj1UoZBNo++Ss/1E6UqoCffmUkg40CnRna3IV/eKBc0VQ3nocsxbHoIhOWXCDPCwLLo6yZgqfweiDHdlgC0+Zpkf3JQZ9tKAOdw5NiFOA==
  • Cc: <sstabellini@xxxxxxxxxx>, <julien@xxxxxxx>, <vikram.garhwal@xxxxxxx>, <Luca.Fancellu@xxxxxxx>
  • Delivery-date: Wed, 07 Dec 2022 06:18:32 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Protect iommu_add_dt_device() with dtdevs_lock to prevent concurrent access add.

Signed-off-by: Vikram Garhwal <vikram.garhwal@xxxxxxx>
Reviewed-by: Luca Fancellu <luca.fancellu@xxxxxxx>
---
 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 bb4cf7784d..457df333a0 100644
--- a/xen/drivers/passthrough/device_tree.c
+++ b/xen/drivers/passthrough/device_tree.c
@@ -146,6 +146,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.
@@ -158,7 +160,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;
@@ -189,6 +194,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®.