Re: [PATCH v2 5/8] iommu: Switch __iommu_domain_alloc() to device ops

Jason Gunthorpe
2023-01-30T17:51:22Z

On Thu, Jan 26, 2023 at 06:26:20PM +0000, Robin Murphy wrote:

> @@ -1980,9 +1978,30 @@ static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
> return domain;
> }
>
> +static int __iommu_domain_alloc_dev(struct device *dev, void *data)
> +{
> + struct device **alloc_dev = data;
> +
> + if (!dev_iommu_ops_valid(dev))
> + return 0;

This valid check is necessary to be done in __iommu_domain_alloc()
because the callback coming from iommu_device_claim_dma_owner() never
validated that the device/group has an iommu driver:

> @@ -3120,13 +3139,13 @@ static int __iommu_group_alloc_blocking_domain(struct iommu_group *group)
> if (group->blocking_domain)
> return 0;
>
> - group->blocking_domain = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_BLOCKED);
> + group->blocking_domain = __iommu_domain_alloc(dev, IOMMU_DOMAIN_BLOCKED);

Jason