From: Vasant Hegde <vasant.hegde@amd.com>
To: <iommu@lists.linux.dev>, <joro@8bytes.org>
Cc: <robin.murphy@arm.com>, <suravee.suthikulpanit@amd.com>,
Vasant Hegde <vasant.hegde@amd.com>
Subject: [RFC PATCH] iommu: Handle domain allocation failure gracefully
Date: Wed, 14 Sep 2022 14:44:24 +0000 [thread overview]
Message-ID: <20220914144424.7356-1-vasant.hegde@amd.com> (raw)
Current code does not validate domain allocation failures. This will
result in random failure at later stage. Hence handle domain allocation
failures.
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
Hi Joerg,
With current code whenever amd driver failes to allocate domain we hit
failure at late stage and it became difficult to debug. Hence I
thought of adding this fix.
I see that in commit 6e1aa2049154 you have intentionally didn't check
the return value. Looking into drivers/iommu/* it looks like all
drivers has domain_alloc() callback handler. But some drivers (like msm
- msm_iommu_domain_alloc()) allocates default domain for certain type
only. Hence I'm not sure whether its ok to handle domain allocation
failures or not. Hence I have marked this patch as RFC.
Let me know whether this patch is fine -OR- is there any other way we can
handle domain allocation failures?
-Vasant
drivers/iommu/iommu.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 780fb7071577..e8a1e7fbffb9 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -289,18 +289,21 @@ int iommu_probe_device(struct device *dev)
/*
* Try to allocate a default domain - needs support from the
- * IOMMU driver. There are still some drivers which don't
- * support default domains, so the return value is not yet
- * checked.
+ * IOMMU driver.
*/
mutex_lock(&group->mutex);
- iommu_alloc_default_domain(group, dev);
+ ret = iommu_alloc_default_domain(group, dev);
+ if (ret) {
+ mutex_unlock(&group->mutex);
+ iommu_group_put(group);
+ goto err_release;
+ }
/*
* If device joined an existing group which has been claimed, don't
* attach the default domain.
*/
- if (group->default_domain && !group->owner) {
+ if (!group->owner) {
ret = __iommu_attach_device(group->default_domain, dev);
if (ret) {
mutex_unlock(&group->mutex);
@@ -1665,7 +1668,7 @@ static int probe_get_default_domain_type(struct device *dev, void *data)
return 0;
}
-static void probe_alloc_default_domain(struct bus_type *bus,
+static int probe_alloc_default_domain(struct bus_type *bus,
struct iommu_group *group)
{
struct __group_domain_type gtype;
@@ -1679,7 +1682,7 @@ static void probe_alloc_default_domain(struct bus_type *bus,
if (!gtype.type)
gtype.type = iommu_def_domain_type;
- iommu_group_alloc_default_domain(bus, group, gtype.type);
+ return iommu_group_alloc_default_domain(bus, group, gtype.type);
}
@@ -1753,11 +1756,10 @@ int bus_iommu_probe(struct bus_type *bus)
mutex_lock(&group->mutex);
/* Try to allocate default domain */
- probe_alloc_default_domain(bus, group);
-
- if (!group->default_domain) {
+ ret = probe_alloc_default_domain(bus, group);
+ if (ret) {
mutex_unlock(&group->mutex);
- continue;
+ break;
}
iommu_group_create_direct_mappings(group);
--
2.31.1
next reply other threads:[~2022-09-14 14:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-14 14:44 Vasant Hegde [this message]
2022-09-15 3:14 ` [RFC PATCH] iommu: Handle domain allocation failure gracefully Baolu Lu
2022-09-15 6:13 ` Vasant Hegde
2022-09-15 7:28 ` Baolu Lu
2022-10-20 14:49 ` Vasant Hegde
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=20220914144424.7356-1-vasant.hegde@amd.com \
--to=vasant.hegde@amd.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=robin.murphy@arm.com \
--cc=suravee.suthikulpanit@amd.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox