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

[XEN][PATCH v12 12/20] xen/smmu: Add remove_device callback for smmu_iommu ops


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Tue, 5 Sep 2023 18:16:22 -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=1SW4wKXQYKIhPbVrs0COOCkOCwqWA0YoU6tRZStnLaY=; b=K8xgQEPwiBp28p44BBLFce4Gmu555Noe+My3/9s/md9FUenqQWBKIx0m2E8Hz5MOEDnCnX4gceVMg7aToZpfFR3auaKvwsZzOVWyDzPY29c8eQA2jOo8W0WkaryI4cfYP4aJK7snLfls5HBm6sm7NGpV7UHRpEdt392n2j1Nba6hK3Z74fkxz6RUKKQ1ORoj6KKvjfqibIHCZseX8rZ6PZCeiTo3BpYy5VNfFLIf5tOhb7YlKKqqYykb+cQfzWY2MkVBsNBL6nrujEliYhGOGBNl/+HDXtj/M2L9ImUjz21mr45pZksmgqwh+9Iqbd8L+eP2hCavEq7Z6l+JVVJukA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MTS5niPUpI3bBgY1brrkFz1jq7XueygLFpQStz/ob76cPRWBr4zwC0nBZBxD6D1bcnD1G8Fpp4l+UFiI1NkDeek9khatGgmWbbZtbyDZhRKTmZ1u89/YYtS3VaRROHSXrTNjCiEOTqIt0Nt4I1eake+4fDOPnSUZETZ32k+ozVaLCco6mfP36I6q5o8hgjYOokJzlrGAxY7Qf7w5tciwMBzJEDB+N59LBgU84+tH9GlfNcz6RIVt2tpS27T04xTgbMGdKMCpJeyimbcHXiuTwIOWI0/5pdkkuOO7QMhW1SeFDHL9N8Bnl0yP6Ymd6QVyw9i+93lVH8WzSNdmq10Jew==
  • Cc: <vikram.garhwal@xxxxxxx>, <julien@xxxxxxx>, <michal.orzel@xxxxxxx>, <sstabellini@xxxxxxxxxx>, Rahul Singh <rahul.singh@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Wed, 06 Sep 2023 01:28:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Add remove_device callback for removing the device entry from smmu-master using
following steps:
1. Find if SMMU master exists for the device node.
2. Check if device is currently in use.
3. Remove the SMMU master.

Signed-off-by: Vikram Garhwal <vikram.garhwal@xxxxxxx>
Acked-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>

---
 Changes from v9:
    Remove iommu_dt_device_is_assigned_locked().
    Add comment regarding caller holding the locks to protect concurrent access.
 Changes from v7:
        Added comments on arm_smmu_dt_remove_device_generic().
---
---
 xen/drivers/passthrough/arm/smmu.c | 60 ++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/xen/drivers/passthrough/arm/smmu.c 
b/xen/drivers/passthrough/arm/smmu.c
index c37fa9af13..71799064f8 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -815,6 +815,19 @@ static int insert_smmu_master(struct arm_smmu_device *smmu,
        return 0;
 }
 
+static int remove_smmu_master(struct arm_smmu_device *smmu,
+                             struct arm_smmu_master *master)
+{
+       if (!smmu->masters.rb_node) {
+               ASSERT_UNREACHABLE();
+               return -ENOENT;
+       }
+
+       rb_erase(&master->node, &smmu->masters);
+
+       return 0;
+}
+
 static int arm_smmu_dt_add_device_legacy(struct arm_smmu_device *smmu,
                                         struct device *dev,
                                         struct iommu_fwspec *fwspec)
@@ -852,6 +865,32 @@ static int arm_smmu_dt_add_device_legacy(struct 
arm_smmu_device *smmu,
        return insert_smmu_master(smmu, master);
 }
 
+static int arm_smmu_dt_remove_device_legacy(struct arm_smmu_device *smmu,
+                                        struct device *dev)
+{
+       struct arm_smmu_master *master;
+       struct device_node *dev_node = dev_get_dev_node(dev);
+       int ret;
+
+       master = find_smmu_master(smmu, dev_node);
+       if (master == NULL) {
+               dev_err(dev,
+                       "No registrations found for master device %s\n",
+                       dev_node->name);
+               return -EINVAL;
+       }
+
+       ret = remove_smmu_master(smmu, master);
+       if (ret)
+               return ret;
+
+       /* Protected by dt_host_lock and dtdevs_lock as caller holds these 
locks. */
+       dev_node->is_protected = false;
+
+       kfree(master);
+       return 0;
+}
+
 static int register_smmu_master(struct arm_smmu_device *smmu,
                                struct device *dev,
                                struct of_phandle_args *masterspec)
@@ -875,6 +914,26 @@ static int register_smmu_master(struct arm_smmu_device 
*smmu,
                                             fwspec);
 }
 
+/*
+ * The driver which supports generic IOMMU DT bindings must have this
+ * callback implemented.
+ */
+static int arm_smmu_dt_remove_device_generic(u8 devfn, struct device *dev)
+{
+       struct arm_smmu_device *smmu;
+       struct iommu_fwspec *fwspec;
+
+       fwspec = dev_iommu_fwspec_get(dev);
+       if (fwspec == NULL)
+               return -ENXIO;
+
+       smmu = find_smmu(fwspec->iommu_dev);
+       if (smmu == NULL)
+               return -ENXIO;
+
+       return arm_smmu_dt_remove_device_legacy(smmu, dev);
+}
+
 static int arm_smmu_dt_add_device_generic(u8 devfn, struct device *dev)
 {
        struct arm_smmu_device *smmu;
@@ -2859,6 +2918,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = {
     .init = arm_smmu_iommu_domain_init,
     .hwdom_init = arch_iommu_hwdom_init,
     .add_device = arm_smmu_dt_add_device_generic,
+    .remove_device = arm_smmu_dt_remove_device_generic,
     .teardown = arm_smmu_iommu_domain_teardown,
     .iotlb_flush = arm_smmu_iotlb_flush,
     .assign_device = arm_smmu_assign_dev,
-- 
2.17.1




 


Rackspace

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