Skip to content

Commit 83b3836

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Allow ops->default_domain to work when !CONFIG_IOMMU_DMA
The ops->default_domain flow used a 0 req_type to select the default domain and this was enforced by iommu_group_alloc_default_domain(). When !CONFIG_IOMMU_DMA started forcing the old ARM32 drivers into IDENTITY it also overroad the 0 req_type of the ops->default_domain drivers to IDENTITY which ends up causing failures during device probe. Make iommu_group_alloc_default_domain() accept a req_type that matches the ops->default_domain and have iommu_group_alloc_default_domain() generate a req_type that matches the default_domain. This way the req_type always describes what kind of domain should be attached and ops->default_domain overrides all other mechanisms to choose the default domain. Fixes: 2ad56ef ("powerpc/iommu: Setup a default domain and remove set_platform_dma_ops") Fixes: 0f6a904 ("iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled") Reported-by: Ovidiu Panait <ovidiu.panait@windriver.com> Closes: https://lore.kernel.org/linux-iommu/20240123165829.630276-1-ovidiu.panait@windriver.com/ Reported-by: Shivaprasad G Bhat <sbhat@linux.ibm.com> Closes: https://lore.kernel.org/linux-iommu/170618452753.3805.4425669653666211728.stgit@ltcd48-lp2.aus.stglab.ibm.com/ Tested-by: Ovidiu Panait <ovidiu.panait@windriver.com> Tested-by: Shivaprasad G Bhat <sbhat@linux.ibm.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/0-v1-755bd21c4a64+525b8-iommu_def_dom_fix_jgg@nvidia.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 41bccc9 commit 83b3836

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

drivers/iommu/iommu.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,7 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
17991799
* domain. Do not use in new drivers.
18001800
*/
18011801
if (ops->default_domain) {
1802-
if (req_type)
1802+
if (req_type != ops->default_domain->type)
18031803
return ERR_PTR(-EINVAL);
18041804
return ops->default_domain;
18051805
}
@@ -1871,10 +1871,18 @@ static int iommu_get_def_domain_type(struct iommu_group *group,
18711871
const struct iommu_ops *ops = dev_iommu_ops(dev);
18721872
int type;
18731873

1874-
if (!ops->def_domain_type)
1875-
return cur_type;
1876-
1877-
type = ops->def_domain_type(dev);
1874+
if (ops->default_domain) {
1875+
/*
1876+
* Drivers that declare a global static default_domain will
1877+
* always choose that.
1878+
*/
1879+
type = ops->default_domain->type;
1880+
} else {
1881+
if (ops->def_domain_type)
1882+
type = ops->def_domain_type(dev);
1883+
else
1884+
return cur_type;
1885+
}
18781886
if (!type || cur_type == type)
18791887
return cur_type;
18801888
if (!cur_type)

0 commit comments

Comments
 (0)