[PATCH] iommu/arm-smmu-v3: Stop queue allocation retry at PAGE_SIZE

Will Deacon will at kernel.org
Tue Apr 21 08:26:42 PDT 2026


On Sat, Apr 18, 2026 at 01:31:43PM +0800, leo.jiang1224 at foxmail.com wrote:
> From: LoserJL <leo.jiang1224 at foxmail.com>
> 
> In arm_smmu_init_one_queue(), the loop reduces max_n_shift if
> dmam_alloc_coherent() fails. However, since dmam_alloc_coherent()
> allocates at least PAGE_SIZE, retrying with a smaller size after
> a PAGE_SIZE failure is logically redundant.
> 
> Moreover, if a sub-page retry were to succeed due to concurrent memory
> release, the hardware would be configured with a smaller queue depth
> despite a full page being allocated. This leads to inefficient memory
> usage and unnecessary hardware performance limitation.
> 
> Terminate the loop once qsz reaches PAGE_SIZE to ensure logical
> consistency and optimal hardware configuration.
> 
> Signed-off-by: LoserJL <leo.jiang1224 at foxmail.com>

No pseudonyms, please.

> ---
>  drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> index e8d7dbe495f0..e0ec118ff560 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -4418,7 +4418,14 @@ int arm_smmu_init_one_queue(struct arm_smmu_device *smmu,
>  		qsz = ((1 << q->llq.max_n_shift) * dwords) << 3;
>  		q->base = dmam_alloc_coherent(smmu->dev, qsz, &q->base_dma,
>  					      GFP_KERNEL);
> -		if (q->base || qsz < PAGE_SIZE)
> +		/*
> +		 * If allocation succeeds, we're done. If it fails, only retry
> +		 * if the requested size is still larger than a page. Since
> +		 * dmam_alloc_coherent() allocates at least PAGE_SIZE, retrying
> +		 * with a sub-page size is logically redundant and could lead
> +		 * to sub-optimal hardware configuration.

What do you mean by "sub-optimal hardware configuration"? I think you can
probably just drop this comment.

> +		 */
> +		if (q->base || qsz <= PAGE_SIZE)
>  			break;

I think this part is fine.

Will



More information about the linux-arm-kernel mailing list