All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vikram Garhwal <vikram.garhwal@amd.com>
To: <xen-devel@lists.xenproject.org>
Cc: <michal.orzel@amd.com>, <sstabellini@kernel.org>,
	<vikram.garhwal@amd.com>, <julien@xen.org>,
	Rahul Singh <rahul.singh@arm.com>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>
Subject: [XEN][PATCH v10 12/20] xen/smmu: Add remove_device callback for smmu_iommu ops
Date: Fri, 25 Aug 2023 01:02:14 -0700	[thread overview]
Message-ID: <20230825080222.14247-13-vikram.garhwal@amd.com> (raw)
In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com>

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@amd.com>

---
 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



  parent reply	other threads:[~2023-08-25  8:03 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-25  8:02 [XEN][PATCH v10 00/20] dynamic node programming using overlay dtbo Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 01/20] common/device_tree: handle memory allocation failure in __unflatten_device_tree() Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 02/20] common/device_tree.c: unflatten_device_tree() propagate errors Vikram Garhwal
2023-08-28  1:41   ` Henry Wang
2023-08-29  7:09   ` Michal Orzel
2023-08-29 22:24   ` Stefano Stabellini
2023-08-25  8:02 ` [XEN][PATCH v10 03/20] xen/arm/device: Remove __init from function type Vikram Garhwal
2023-08-28  1:53   ` Henry Wang
2023-08-28 16:21     ` Vikram Garhwal
2023-08-29  7:17   ` Michal Orzel
2023-08-30 17:16     ` Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 04/20] common/device_tree: Export __unflatten_device_tree() Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 05/20] xen/arm: Add CONFIG_OVERLAY_DTB Vikram Garhwal
2023-08-29  7:23   ` Michal Orzel
2023-08-30 17:16     ` Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 06/20] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 07/20] libfdt: overlay: change overlay_get_target() Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 08/20] xen/device-tree: Add device_tree_find_node_by_path() to find nodes in device tree Vikram Garhwal
2023-08-28  1:59   ` Henry Wang
2023-08-29  7:41   ` Michal Orzel
2023-08-29 22:27   ` Stefano Stabellini
2023-08-25  8:02 ` [XEN][PATCH v10 09/20] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Vikram Garhwal
2023-08-29  8:05   ` Michal Orzel
2023-08-30 17:20     ` Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 10/20] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Vikram Garhwal
2023-08-28 16:29   ` Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 11/20] xen/iommu: Introduce iommu_remove_dt_device() Vikram Garhwal
2023-08-29  8:23   ` Michal Orzel
2023-08-30 17:48     ` Vikram Garhwal
2023-08-31  0:35       ` Stefano Stabellini
2023-08-31  7:23       ` Michal Orzel
2023-08-31  7:32         ` Michal Orzel
2023-09-01  2:01           ` Vikram Garhwal
2023-08-25  8:02 ` Vikram Garhwal [this message]
2023-08-29  8:51   ` [XEN][PATCH v10 12/20] xen/smmu: Add remove_device callback for smmu_iommu ops Michal Orzel
2023-08-29 22:45     ` Stefano Stabellini
2023-08-30  9:17       ` Michal Orzel
2023-08-25  8:02 ` [XEN][PATCH v10 13/20] asm/smp.h: Fix circular dependency for device_tree.h and rwlock.h Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 14/20] common/device_tree: Add rwlock for dt_host Vikram Garhwal
2023-08-28 16:26   ` Vikram Garhwal
2023-08-29  9:27   ` Michal Orzel
2023-08-25  8:02 ` [XEN][PATCH v10 15/20] arm/asm/setup.h: Update struct map_range_data to add rangeset Vikram Garhwal
2023-08-29 12:16   ` Michal Orzel
2023-08-25  8:02 ` [XEN][PATCH v10 16/20] xen/arm: Implement device tree node removal functionalities Vikram Garhwal
2023-08-29 23:45   ` Stefano Stabellini
2023-08-25  8:02 ` [XEN][PATCH v10 17/20] xen/arm: Implement device tree node addition functionalities Vikram Garhwal
2023-08-29 23:45   ` Stefano Stabellini
2023-08-25  8:02 ` [XEN][PATCH v10 18/20] tools/libs/ctrl: Implement new xc interfaces for dt overlay Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 19/20] tools/libs/light: Implement new libxl functions for device tree overlay ops Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 20/20] tools/xl: Add new xl command overlay for device tree overlay support Vikram Garhwal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230825080222.14247-13-vikram.garhwal@amd.com \
    --to=vikram.garhwal@amd.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=rahul.singh@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.