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

[XEN][PATCH v7 12/19] xen/smmu: Add remove_device callback for smmu_iommu ops


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Thu, 1 Jun 2023 17:48:17 -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=x8f6Wjw45ONksBxgsuuhCKdaU9dyqrhh4lFwNBN7Yrs=; b=I4Q7k9x+ahBWBVj3K0eqhewn44sxhfRHxqvLBiaQsn7/4u9Sp0Zd87He1Zh+lTIVWaccV6zbPVA9TookyuWKgWyx3UDOBN5rPyP4e9dkPiwM293R8whvDNdHFlqZdH0UlOjSZG3hck45Qao1HV0MzaZ47xdBz9dKJ25z6kIeejmm9MllWFn5rjGqpyzBbye9wIutvKwkjg9MqaHx3/Pw3D9vtEMbFv3uj5DmU58yt8LEd94KqaCF2BLUKZ1wKkyU6Gvvqov8xh0x4hsPPzPA9jbiHP/29o0v76mEbxgfwkwIsi0w4ua0fBGJHRLZSEcpVMUJ9h9okfa+r29UKFfxCw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L26MiYxe1R9ZduPra0t4svbywQKYqhNTWmixJ5taaF5zewdJjHqDAmfKKl6aNoU71q70S4kEoRx5yKFaYKobDBkELfOQzPBePb9dIGNIF3klLyCPcJO6oCyWrTMGmiUSj0B1LBuOUYuRuXFvc0HC/+TNGBek4HamH4uDB/qdy/GAo/EbkxcRy66txfU3BX92X4qIzLqxAZfZAaBTZYMek9gq+UnRRJ4d+nVXVjmedtvNt3+v0mVFnsdoe7QAEQ6YzGA6uCH4K+AOlJ9w6HQ4BqqUisM7LLTR4vOKNP6yDEgymtYuQiKcIHrAS3a+yt1Aokx7bTixiq7UmSTY2+MtrQ==
  • Cc: <michal.orzel@xxxxxxx>, <sstabellini@xxxxxxxxxx>, <vikram.garhwal@xxxxxxx>, <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Rahul Singh <rahul.singh@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Fri, 02 Jun 2023 00:49:05 +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>
Reviewed-by: Luca Fancellu <luca.fancellu@xxxxxxx>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
---
 xen/drivers/passthrough/arm/smmu.c | 59 ++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/xen/drivers/passthrough/arm/smmu.c 
b/xen/drivers/passthrough/arm/smmu.c
index c37fa9af13..fdef6e7a7d 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -44,6 +44,7 @@
 #include <xen/irq.h>
 #include <xen/lib.h>
 #include <xen/list.h>
+#include <xen/iommu-private.h>
 #include <xen/mm.h>
 #include <xen/vmap.h>
 #include <xen/rbtree.h>
@@ -815,6 +816,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 +866,34 @@ 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;
+       }
+
+       if (iommu_dt_device_is_assigned_locked(dev_to_dt(dev)))
+               return -EBUSY;
+
+       ret = remove_smmu_master(smmu, master);
+       if (ret)
+               return ret;
+
+       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 +917,22 @@ static int register_smmu_master(struct arm_smmu_device 
*smmu,
                                             fwspec);
 }
 
+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 +2917,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®.