Skip to content

Commit d257344

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Replace __iommu_group_dma_first_attach() with set_domain
Reorganize the attach_deferred logic to set dev->iommu->attach_deferred immediately during probe and then have __iommu_device_set_domain() check it and not attach the default_domain. This is to prepare for removing the group->domain set from iommu_group_alloc_default_domain() by calling __iommu_group_set_domain() to set the group->domain. Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Tested-by: Heiko Stuebner <heiko@sntech.de> Tested-by: Niklas Schnelle <schnelle@linux.ibm.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/6-v5-1b99ae392328+44574-iommu_err_unwind_jgg@nvidia.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 4c8ad9d commit d257344

1 file changed

Lines changed: 11 additions & 21 deletions

File tree

drivers/iommu/iommu.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
365365

366366
dev->iommu->iommu_dev = iommu_dev;
367367
dev->iommu->max_pasids = dev_iommu_get_max_pasids(dev);
368+
if (ops->is_attach_deferred)
369+
dev->iommu->attach_deferred = ops->is_attach_deferred(dev);
368370

369371
group = iommu_group_get_for_dev(dev);
370372
if (IS_ERR(group)) {
@@ -399,27 +401,14 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
399401
return ret;
400402
}
401403

402-
static bool iommu_is_attach_deferred(struct device *dev)
403-
{
404-
const struct iommu_ops *ops = dev_iommu_ops(dev);
405-
406-
if (ops->is_attach_deferred)
407-
return ops->is_attach_deferred(dev);
408-
409-
return false;
410-
}
411-
412404
static int iommu_group_do_dma_first_attach(struct device *dev, void *data)
413405
{
414406
struct iommu_domain *domain = data;
415407

416408
lockdep_assert_held(&dev->iommu_group->mutex);
417409

418-
if (iommu_is_attach_deferred(dev)) {
419-
dev->iommu->attach_deferred = 1;
410+
if (dev->iommu->attach_deferred)
420411
return 0;
421-
}
422-
423412
return __iommu_attach_device(domain, dev);
424413
}
425414

@@ -1831,12 +1820,6 @@ static void probe_alloc_default_domain(const struct bus_type *bus,
18311820

18321821
}
18331822

1834-
static int __iommu_group_dma_first_attach(struct iommu_group *group)
1835-
{
1836-
return __iommu_group_for_each_dev(group, group->default_domain,
1837-
iommu_group_do_dma_first_attach);
1838-
}
1839-
18401823
static int iommu_group_do_probe_finalize(struct device *dev, void *data)
18411824
{
18421825
const struct iommu_ops *ops = dev_iommu_ops(dev);
@@ -1899,7 +1882,8 @@ int bus_iommu_probe(const struct bus_type *bus)
18991882

19001883
iommu_group_create_direct_mappings(group);
19011884

1902-
ret = __iommu_group_dma_first_attach(group);
1885+
group->domain = NULL;
1886+
ret = __iommu_group_set_domain(group, group->default_domain);
19031887

19041888
mutex_unlock(&group->mutex);
19051889

@@ -2200,6 +2184,12 @@ static int __iommu_device_set_domain(struct iommu_group *group,
22002184
{
22012185
int ret;
22022186

2187+
if (dev->iommu->attach_deferred) {
2188+
if (new_domain == group->default_domain)
2189+
return 0;
2190+
dev->iommu->attach_deferred = 0;
2191+
}
2192+
22032193
ret = __iommu_attach_device(new_domain, dev);
22042194
if (ret) {
22052195
/*

0 commit comments

Comments
 (0)