Commit 83b3836b authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Joerg Roedel

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: 2ad56efa ("powerpc/iommu: Setup a default domain and remove set_platform_dma_ops")
Fixes: 0f6a9043 ("iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled")
Reported-by: default avatarOvidiu Panait <ovidiu.panait@windriver.com>
Closes: https://lore.kernel.org/linux-iommu/20240123165829.630276-1-ovidiu.panait@windriver.com/Reported-by: default avatarShivaprasad 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: default avatarOvidiu Panait <ovidiu.panait@windriver.com>
Tested-by: default avatarShivaprasad G Bhat <sbhat@linux.ibm.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/0-v1-755bd21c4a64+525b8-iommu_def_dom_fix_jgg@nvidia.comSigned-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 41bccc98
...@@ -1799,7 +1799,7 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type) ...@@ -1799,7 +1799,7 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
* domain. Do not use in new drivers. * domain. Do not use in new drivers.
*/ */
if (ops->default_domain) { if (ops->default_domain) {
if (req_type) if (req_type != ops->default_domain->type)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
return ops->default_domain; return ops->default_domain;
} }
...@@ -1871,10 +1871,18 @@ static int iommu_get_def_domain_type(struct iommu_group *group, ...@@ -1871,10 +1871,18 @@ static int iommu_get_def_domain_type(struct iommu_group *group,
const struct iommu_ops *ops = dev_iommu_ops(dev); const struct iommu_ops *ops = dev_iommu_ops(dev);
int type; int type;
if (!ops->def_domain_type) if (ops->default_domain) {
return cur_type; /*
* Drivers that declare a global static default_domain will
* always choose that.
*/
type = ops->default_domain->type;
} else {
if (ops->def_domain_type)
type = ops->def_domain_type(dev); type = ops->def_domain_type(dev);
else
return cur_type;
}
if (!type || cur_type == type) if (!type || cur_type == type)
return cur_type; return cur_type;
if (!cur_type) if (!cur_type)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment