All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: iommu@lists.linux.dev, Joerg Roedel <joro@8bytes.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Will Deacon <will@kernel.org>
Cc: Lu Baolu <baolu.lu@linux.intel.com>,
	Kevin Tian <kevin.tian@intel.com>,
	Nicolin Chen <nicolinc@nvidia.com>
Subject: [PATCH 9/9] iommu: Remove __iommu_group_for_each_dev()
Date: Tue, 21 Mar 2023 16:53:21 -0300	[thread overview]
Message-ID: <9-v1-20507a7e6b7e+2d6-iommu_err_unwind_jgg@nvidia.com> (raw)
In-Reply-To: <0-v1-20507a7e6b7e+2d6-iommu_err_unwind_jgg@nvidia.com>

The last two users of it are quite trivial, just open code the one line
loop.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c | 55 +++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 31 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index e129f55587def2..bb6140067353e7 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1119,20 +1119,6 @@ static int iommu_group_device_count(struct iommu_group *group)
 	return ret;
 }
 
-static int __iommu_group_for_each_dev(struct iommu_group *group, void *data,
-				      int (*fn)(struct device *, void *))
-{
-	struct group_device *device;
-	int ret = 0;
-
-	list_for_each_entry(device, &group->devices, list) {
-		ret = fn(device->dev, data);
-		if (ret)
-			break;
-	}
-	return ret;
-}
-
 /**
  * iommu_group_for_each_dev - iterate over each device in the group
  * @group: the group
@@ -1147,10 +1133,15 @@ static int __iommu_group_for_each_dev(struct iommu_group *group, void *data,
 int iommu_group_for_each_dev(struct iommu_group *group, void *data,
 			     int (*fn)(struct device *, void *))
 {
-	int ret;
+	struct group_device *device;
+	int ret = 0;
 
 	mutex_lock(&group->mutex);
-	ret = __iommu_group_for_each_dev(group, data, fn);
+	list_for_each_entry(device, &group->devices, list) {
+		ret = fn(device->dev, data);
+		if (ret)
+			break;
+	}
 	mutex_unlock(&group->mutex);
 
 	return ret;
@@ -1727,9 +1718,9 @@ struct __group_domain_type {
 	unsigned int count;
 };
 
-static int probe_get_default_domain_type(struct device *dev, void *data)
+static int probe_get_default_domain_type(struct device *dev,
+					 struct __group_domain_type *gtype)
 {
-	struct __group_domain_type *gtype = data;
 	unsigned int type = iommu_get_def_domain_type(dev);
 
 	gtype->count++;
@@ -1768,8 +1759,8 @@ static int iommu_setup_default_domain(struct iommu_group *group)
 		return 0;
 
 	/* Ask for default domain requirements of all devices in the group */
-	__iommu_group_for_each_dev(group, &gtype,
-				   probe_get_default_domain_type);
+	list_for_each_entry(gdev, &group->devices, list)
+		probe_get_default_domain_type(gdev->dev, &gtype);
 
 	if (!gtype.type)
 		gtype.type = iommu_def_domain_type;
@@ -1818,20 +1809,12 @@ static int iommu_setup_default_domain(struct iommu_group *group)
 	return 0;
 }
 
-static int iommu_group_do_probe_finalize(struct device *dev, void *data)
+static void iommu_group_do_probe_finalize(struct device *dev)
 {
 	const struct iommu_ops *ops = dev_iommu_ops(dev);
 
 	if (ops->probe_finalize)
 		ops->probe_finalize(dev);
-
-	return 0;
-}
-
-static void __iommu_group_dma_finalize(struct iommu_group *group)
-{
-	__iommu_group_for_each_dev(group, group->default_domain,
-				   iommu_group_do_probe_finalize);
 }
 
 int bus_iommu_probe(struct bus_type *bus)
@@ -1850,6 +1833,8 @@ int bus_iommu_probe(struct bus_type *bus)
 		return ret;
 
 	list_for_each_entry_safe(group, next, &group_list, entry) {
+		struct group_device *gdev;
+
 		mutex_lock(&group->mutex);
 
 		/* Remove item from the list */
@@ -1859,7 +1844,15 @@ int bus_iommu_probe(struct bus_type *bus)
 		mutex_unlock(&group->mutex);
 		if (ret)
 			return ret;
-		__iommu_group_dma_finalize(group);
+
+		/*
+		 * Mis-locked because the ops->probe_finalize() call-back of
+		 * some IOMMU drivers calls arm_iommu_attach_device() which
+		 * in-turn might call back into IOMMU core code, where it tries
+		 * to take group->mutex, resulting in a deadlock.
+		 */
+		list_for_each_entry(gdev, &group->devices, list)
+			iommu_group_do_probe_finalize(gdev->dev);
 	}
 
 	return 0;
@@ -2992,7 +2985,7 @@ static int iommu_change_dev_def_domain(struct iommu_group *group,
 	mutex_unlock(&group->mutex);
 
 	/* Make sure dma_ops is appropriatley set */
-	iommu_group_do_probe_finalize(dev, group->default_domain);
+	iommu_group_do_probe_finalize(dev);
 	iommu_domain_free(prev_dom);
 	return 0;
 
-- 
2.40.0


  parent reply	other threads:[~2023-03-21 19:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21 19:53 [PATCH 0/9] Consolidate the error handling around device attachment Jason Gunthorpe
2023-03-21 19:53 ` [PATCH 1/9] iommu: Make __iommu_group_set_domain() handle error unwind Jason Gunthorpe
2023-03-24  7:17   ` Tian, Kevin
2023-03-24 15:17     ` Jason Gunthorpe
2023-03-21 19:53 ` [PATCH 2/9] iommu: Use __iommu_group_set_domain() for __iommu_attach_group() Jason Gunthorpe
2023-03-24  7:18   ` Tian, Kevin
2023-03-21 19:53 ` [PATCH 3/9] iommu: Use __iommu_group_set_domain() in iommu_change_dev_def_domain() Jason Gunthorpe
2023-03-24  7:19   ` Tian, Kevin
2023-03-24 13:17     ` Jason Gunthorpe
2023-03-21 19:53 ` [PATCH 4/9] iommu: Replace __iommu_group_dma_first_attach() with set_domain Jason Gunthorpe
2023-03-24  7:20   ` Tian, Kevin
2023-03-21 19:53 ` [PATCH 5/9] iommu: Make iommu_group_do_dma_first_attach() simpler Jason Gunthorpe
2023-03-24  7:23   ` Tian, Kevin
2023-03-24 15:23     ` Jason Gunthorpe
2023-03-21 19:53 ` [PATCH 6/9] iommu: Fix iommu_probe_device() to attach the right domain Jason Gunthorpe
2023-03-24  7:29   ` Tian, Kevin
2023-03-24 15:42     ` Jason Gunthorpe
2023-03-24 19:36     ` Jason Gunthorpe
2023-03-21 19:53 ` [PATCH 7/9] iommu: Remove the assignment of group->domain during default domain alloc Jason Gunthorpe
2023-03-24  7:30   ` Tian, Kevin
2023-03-21 19:53 ` [PATCH 8/9] iommu: Consolidate the default_domain setup to one function Jason Gunthorpe
2023-03-21 19:53 ` Jason Gunthorpe [this message]
2023-03-22 13:08   ` [PATCH 9/9] iommu: Remove __iommu_group_for_each_dev() Joerg Roedel
2023-03-22 13:41     ` Jason Gunthorpe

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=9-v1-20507a7e6b7e+2d6-iommu_err_unwind_jgg@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=nicolinc@nvidia.com \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.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.