[PATCH v4 10/17] iommu: Do iommu_group_create_direct_mappings() before attach

Jason Gunthorpe
2023-04-12T13:52:06Z

The iommu_probe_device() path calls iommu_create_device_direct_mappings()
after attaching the device.

IOMMU_RESV_DIRECT maps need to be continually in place, so if a hotplugged
device has new ranges the should have been mapped into the default domain
before it is attached.

Move the iommu_create_device_direct_mappings() call up.

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/iommu/iommu.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 9076fbbb7d50cd..f0dcc7a559b55a 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -418,6 +418,8 @@ int iommu_probe_device(struct device *dev)

mutex_lock(&group->mutex);

+ iommu_create_device_direct_mappings(group, dev);
+
if (group->domain) {
ret = __iommu_device_set_domain(group, dev, group->domain, 0);
} else if (!group->default_domain) {
@@ -429,9 +431,11 @@ int iommu_probe_device(struct device *dev)
*/
iommu_alloc_default_domain(group, dev);
group->domain = NULL;
- if (group->default_domain)
+ if (group->default_domain) {
+ iommu_create_device_direct_mappings(group, dev);
ret = __iommu_group_set_domain(group,
group->default_domain);
+ }

/*
* We assume that the iommu driver starts up the device in
@@ -442,8 +446,6 @@ int iommu_probe_device(struct device *dev)
if (ret)
goto err_unlock;

- iommu_create_device_direct_mappings(group, dev);
-
mutex_unlock(&group->mutex);
iommu_group_put(group);

--
2.40.0