Skip to content

Commit 4208849

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Put domain allocation in __iommu_group_alloc_blocking_domain()
There is no longer a reason to call __iommu_domain_alloc() to allocate the blocking domain. All drivers that support a native blocking domain provide it via the ops, for other drivers we should call iommu_paging_domain_alloc(). __iommu_group_alloc_blocking_domain() is the only place that allocates an BLOCKED domain, so move the ops->blocked_domain logic there. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Link: https://lore.kernel.org/r/20241028093810.5901-12-vasant.hegde@amd.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 4402f26 commit 4208849

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

drivers/iommu/iommu.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,8 +1956,6 @@ static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
19561956

19571957
if (alloc_type == IOMMU_DOMAIN_IDENTITY && ops->identity_domain)
19581958
return ops->identity_domain;
1959-
else if (alloc_type == IOMMU_DOMAIN_BLOCKED && ops->blocked_domain)
1960-
return ops->blocked_domain;
19611959
else if (type & __IOMMU_DOMAIN_PAGING && ops->domain_alloc_paging)
19621960
domain = ops->domain_alloc_paging(dev);
19631961
else if (ops->domain_alloc)
@@ -3147,22 +3145,25 @@ void iommu_device_unuse_default_domain(struct device *dev)
31473145

31483146
static int __iommu_group_alloc_blocking_domain(struct iommu_group *group)
31493147
{
3148+
struct device *dev = iommu_group_first_dev(group);
3149+
const struct iommu_ops *ops = dev_iommu_ops(dev);
31503150
struct iommu_domain *domain;
31513151

31523152
if (group->blocking_domain)
31533153
return 0;
31543154

3155-
domain = __iommu_group_domain_alloc(group, IOMMU_DOMAIN_BLOCKED);
3156-
if (IS_ERR(domain)) {
3157-
/*
3158-
* For drivers that do not yet understand IOMMU_DOMAIN_BLOCKED
3159-
* create an empty domain instead.
3160-
*/
3161-
domain = __iommu_group_domain_alloc(group,
3162-
IOMMU_DOMAIN_UNMANAGED);
3163-
if (IS_ERR(domain))
3164-
return PTR_ERR(domain);
3155+
if (ops->blocked_domain) {
3156+
group->blocking_domain = ops->blocked_domain;
3157+
return 0;
31653158
}
3159+
3160+
/*
3161+
* For drivers that do not yet understand IOMMU_DOMAIN_BLOCKED create an
3162+
* empty PAGING domain instead.
3163+
*/
3164+
domain = iommu_paging_domain_alloc(dev);
3165+
if (IS_ERR(domain))
3166+
return PTR_ERR(domain);
31663167
group->blocking_domain = domain;
31673168
return 0;
31683169
}

0 commit comments

Comments
 (0)