[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aH4-wuIjtjyo3aOo@willie-the-truck>
Date: Mon, 21 Jul 2025 14:21:06 +0100
From: Will Deacon <will@...nel.org>
To: Nicolin Chen <nicolinc@...dia.com>
Cc: jgg@...dia.com, joro@...tes.org, robin.murphy@....com,
linux-arm-kernel@...ts.infradead.org, iommu@...ts.linux.dev,
linux-kernel@...r.kernel.org, linux-tegra@...r.kernel.org
Subject: Re: [PATCH 1/2] iommu/arm-smmu-v3: Do not bother impl_ops if
IOMMU_VIOMMU_TYPE_ARM_SMMUV3
On Fri, Jul 18, 2025 at 04:48:21PM -0700, Nicolin Chen wrote:
> When viommu type is IOMMU_VIOMMU_TYPE_ARM_SMMUV3, always return or init the
> standard struct arm_vsmmu, instead of going through impl_ops that must have
> its own viommu type than the standard IOMMU_VIOMMU_TYPE_ARM_SMMUV3.
>
> Given that arm_vsmmu_init() is called after arm_smmu_get_viommu_size(), any
> unsupported viommu->type must be a corruption. And missing a pairing impl's
> vsmmu_init should be a driver bug too. Warn these two cases.
>
> Suggested-by: Will Deacon <will@...nel.org>
> Signed-off-by: Nicolin Chen <nicolinc@...dia.com>
> ---
> .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 30 ++++++++++++-------
> 1 file changed, 19 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
> index d9bea8f1f636..0b2acb80f41b 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
> @@ -420,14 +420,13 @@ size_t arm_smmu_get_viommu_size(struct device *dev,
> !(smmu->features & ARM_SMMU_FEAT_S2FWB))
> return 0;
>
> - if (smmu->impl_ops && smmu->impl_ops->vsmmu_size &&
> - viommu_type == smmu->impl_ops->vsmmu_type)
> - return smmu->impl_ops->vsmmu_size;
> + if (viommu_type == IOMMU_VIOMMU_TYPE_ARM_SMMUV3)
> + return VIOMMU_STRUCT_SIZE(struct arm_vsmmu, core);
>
> - if (viommu_type != IOMMU_VIOMMU_TYPE_ARM_SMMUV3)
> + if (!smmu->impl_ops || !smmu->impl_ops->vsmmu_size ||
> + viommu_type != smmu->impl_ops->vsmmu_type)
> return 0;
> -
> - return VIOMMU_STRUCT_SIZE(struct arm_vsmmu, core);
> + return smmu->impl_ops->vsmmu_size;
> }
>
> int arm_vsmmu_init(struct iommufd_viommu *viommu,
> @@ -447,12 +446,21 @@ int arm_vsmmu_init(struct iommufd_viommu *viommu,
> /* FIXME Move VMID allocation from the S2 domain allocation to here */
> vsmmu->vmid = s2_parent->s2_cfg.vmid;
>
> - if (smmu->impl_ops && smmu->impl_ops->vsmmu_init &&
> - viommu->type == smmu->impl_ops->vsmmu_type)
> - return smmu->impl_ops->vsmmu_init(vsmmu, user_data);
> + if (viommu->type == IOMMU_VIOMMU_TYPE_ARM_SMMUV3) {
> + viommu->ops = &arm_vsmmu_ops;
> + return 0;
> + }
>
> - viommu->ops = &arm_vsmmu_ops;
> - return 0;
> + /*
> + * If a non standard type was supported in arm_smmu_get_viommu_size() by
> + * an implementation, a pairing vsmmu_init op must exist.
> + */
> + if (WARN_ON_ONCE(!smmu->impl_ops || !smmu->impl_ops->vsmmu_init))
> + return -EOPNOTSUPP;
It might be cleaner to check the impl_ops in arm_smmu_impl_probe() where
we're in a slightly better situation for failing gracefully and
deterministically.
Otherwise, looks good. Thanks!
Will
Powered by blists - more mailing lists