[PATCH v2 5/5] iommu/arm-smmu: Convert to domain_alloc_paging()

Will Deacon will at kernel.org
Tue Dec 12 05:26:51 PST 2023


On Tue, Oct 17, 2023 at 03:11:44PM -0300, Jason Gunthorpe wrote:
> Now that the BLOCKED and IDENTITY behaviors are managed with their own
> domains change to the domain_alloc_paging() op.
> 
> The check for using_legacy_binding is now redundant,
> arm_smmu_def_domain_type() always returns IOMMU_DOMAIN_IDENTITY for this
> mode, so the core code will never attempt to create a DMA domain in the
> first place.
> 
> Since commit a4fdd9762272 ("iommu: Use flush queue capability") the core
> code only passes in IDENTITY/BLOCKED/UNMANAGED/DMA domain types. It will
> not pass in IDENTITY or BLOCKED if the global statics exist, so the test
> for DMA is also redundant now too.
> 
> Call arm_smmu_init_domain_context() early if a dev is available.
> 
> Signed-off-by: Jason Gunthorpe <jgg at nvidia.com>
> ---
>  drivers/iommu/arm/arm-smmu/arm-smmu.c | 21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c
> index 6340ee8ab7c482..cea25afe9e49db 100644
> --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c
> +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c
> @@ -842,14 +842,11 @@ static void arm_smmu_destroy_domain_context(struct arm_smmu_domain *smmu_domain)
>  	arm_smmu_rpm_put(smmu);
>  }
>  
> -static struct iommu_domain *arm_smmu_domain_alloc(unsigned type)
> +static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev)
>  {
> +	struct arm_smmu_master_cfg *cfg = NULL;
>  	struct arm_smmu_domain *smmu_domain;
>  
> -	if (type != IOMMU_DOMAIN_UNMANAGED) {
> -		if (using_legacy_binding || type != IOMMU_DOMAIN_DMA)
> -			return NULL;
> -	}
>  	/*
>  	 * Allocate the domain and initialise some of its data structures.
>  	 * We can't really do anything meaningful until we've added a
> @@ -862,6 +859,18 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type)
>  	mutex_init(&smmu_domain->init_mutex);
>  	spin_lock_init(&smmu_domain->cb_lock);
>  
> +	if (dev)
> +		cfg = dev_iommu_priv_get(dev);
> +	if (cfg) {
> +		int ret;
> +
> +		ret = arm_smmu_init_domain_context(smmu_domain, cfg->smmu, dev);
> +		if (ret) {
> +			kfree(smmu_domain);
> +			return NULL;

If we're just returning NULL, can we drop 'ret'?

> +		}
> +	}
> +
>  	return &smmu_domain->domain;

Why do we need to handle the 'dev && !cfg' case here, instead of just
returning NULL?

Will



More information about the linux-arm-kernel mailing list