From: Robin Murphy <robin.murphy@arm.com>
To: joro@8bytes.org, will@kernel.org
Cc: iommu@lists.linux.dev, jgg@nvidia.com, baolu.lu@linux.intel.com,
linux-kernel@vger.kernel.org
Subject: [PATCH v4 4/7] iommu: Switch __iommu_domain_alloc() to device ops
Date: Mon, 2 Oct 2023 14:49:12 +0100 [thread overview]
Message-ID: <458dd0ed839541693a49da33239b33cf4c48b8ec.1696253096.git.robin.murphy@arm.com> (raw)
In-Reply-To: <cover.1696253096.git.robin.murphy@arm.com>
In all the places we allocate default domains, we have (or can easily
get hold of) a device from which to resolve the right IOMMU ops; only
the public iommu_domain_alloc() interface actually depends on bus ops.
Reworking the public API is a big enough mission in its own right, but
in the meantime we can still decouple it from bus ops internally to move
forward.
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
v3: Make sure blocking domains are covered as well
v4: Reinstate correct bus_for_each_dev() handling from v2
---
drivers/iommu/iommu.c | 48 ++++++++++++++++++++++++++++---------------
1 file changed, 31 insertions(+), 17 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 7c79a58ef010..c5b5408d1dd7 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -95,8 +95,8 @@ static const char * const iommu_group_resv_type_string[] = {
static int iommu_bus_notifier(struct notifier_block *nb,
unsigned long action, void *data);
static void iommu_release_device(struct device *dev);
-static struct iommu_domain *
-__iommu_group_domain_alloc(struct iommu_group *group, unsigned int type);
+static struct iommu_domain *__iommu_domain_alloc(struct device *dev,
+ unsigned type);
static int __iommu_attach_device(struct iommu_domain *domain,
struct device *dev);
static int __iommu_attach_group(struct iommu_domain *domain,
@@ -1763,7 +1763,7 @@ __iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
{
if (group->default_domain && group->default_domain->type == req_type)
return group->default_domain;
- return __iommu_group_domain_alloc(group, req_type);
+ return __iommu_domain_alloc(iommu_group_first_dev(group), req_type);
}
/*
@@ -2082,10 +2082,10 @@ void iommu_set_fault_handler(struct iommu_domain *domain,
}
EXPORT_SYMBOL_GPL(iommu_set_fault_handler);
-static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
- struct device *dev,
- unsigned int type)
+static struct iommu_domain *__iommu_domain_alloc(struct device *dev,
+ unsigned type)
{
+ const struct iommu_ops *ops = dev_iommu_ops(dev);
struct iommu_domain *domain;
unsigned int alloc_type = type & IOMMU_DOMAIN_ALLOC_FLAGS;
@@ -2120,20 +2120,30 @@ static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
return domain;
}
-static struct iommu_domain *
-__iommu_group_domain_alloc(struct iommu_group *group, unsigned int type)
+static int __iommu_domain_alloc_dev(struct device *dev, void *data)
{
- struct device *dev = iommu_group_first_dev(group);
+ struct device **alloc_dev = data;
- return __iommu_domain_alloc(dev_iommu_ops(dev), dev, type);
+ if (!dev_has_iommu(dev))
+ return 0;
+
+ WARN_ONCE(*alloc_dev && dev_iommu_ops(dev) != dev_iommu_ops(*alloc_dev),
+ "Multiple IOMMU drivers present, which the public IOMMU API can't fully support yet. You may still need to disable one or more to get the expected result here, sorry!\n");
+
+ *alloc_dev = dev;
+ return 0;
}
struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus)
{
- if (bus == NULL || bus->iommu_ops == NULL)
+ struct device *dev = NULL;
+
+ /* We always check the whole bus, so the return value isn't useful */
+ bus_for_each_dev(bus, NULL, &dev, __iommu_domain_alloc_dev);
+ if (!dev)
return NULL;
- return __iommu_domain_alloc(bus->iommu_ops, NULL,
- IOMMU_DOMAIN_UNMANAGED);
+
+ return __iommu_domain_alloc(dev, IOMMU_DOMAIN_UNMANAGED);
}
EXPORT_SYMBOL_GPL(iommu_domain_alloc);
@@ -3256,18 +3266,22 @@ void iommu_device_unuse_default_domain(struct device *dev)
static int __iommu_group_alloc_blocking_domain(struct iommu_group *group)
{
+ struct device *dev = iommu_group_first_dev(group);
+
if (group->blocking_domain)
return 0;
- group->blocking_domain =
- __iommu_group_domain_alloc(group, IOMMU_DOMAIN_BLOCKED);
+ /* noiommu groups should never be here */
+ if (WARN_ON(!dev_has_iommu(dev)))
+ return -ENODEV;
+
+ group->blocking_domain = __iommu_domain_alloc(dev, IOMMU_DOMAIN_BLOCKED);
if (!group->blocking_domain) {
/*
* For drivers that do not yet understand IOMMU_DOMAIN_BLOCKED
* create an empty domain instead.
*/
- group->blocking_domain = __iommu_group_domain_alloc(
- group, IOMMU_DOMAIN_UNMANAGED);
+ group->blocking_domain = __iommu_domain_alloc(dev, IOMMU_DOMAIN_UNMANAGED);
if (!group->blocking_domain)
return -EINVAL;
}
--
2.39.2.101.g768bb238c484.dirty
next prev parent reply other threads:[~2023-10-02 13:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-02 13:49 [PATCH v4 0/7] iommu: Retire bus ops Robin Murphy
2023-10-02 13:49 ` [PATCH v4 1/7] iommu: Factor out some helpers Robin Murphy
2023-10-02 13:49 ` [PATCH v4 2/7] iommu: Decouple iommu_present() from bus ops Robin Murphy
2023-10-02 14:17 ` Jason Gunthorpe
2023-10-02 14:32 ` Robin Murphy
2023-10-02 13:49 ` [PATCH v4 3/7] iommu: Validate that devices match domains Robin Murphy
2023-10-02 13:49 ` Robin Murphy [this message]
2023-10-02 14:16 ` [PATCH v4 4/7] iommu: Switch __iommu_domain_alloc() to device ops Jason Gunthorpe
2023-10-02 19:02 ` Robin Murphy
2023-10-02 19:36 ` Jason Gunthorpe
2023-10-04 17:23 ` Robin Murphy
2023-10-04 21:35 ` Jason Gunthorpe
2023-10-02 13:49 ` [PATCH v4 5/7] iommu/arm-smmu: Don't register fwnode for legacy binding Robin Murphy
2023-10-02 13:49 ` [PATCH v4 6/7] iommu: Retire bus ops Robin Murphy
2023-10-02 13:49 ` [PATCH v4 7/7] iommu: Clean up open-coded ownership checks Robin Murphy
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=458dd0ed839541693a49da33239b33cf4c48b8ec.1696253096.git.robin.murphy@arm.com \
--to=robin.murphy@arm.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®