From: Pranjal Shrivastava <praan@google.com>
To: Nicolin Chen <nicolinc@nvidia.com>
Cc: jgg@nvidia.com, will@kernel.org, joro@8bytes.org,
robin.murphy@arm.com, linux-arm-kernel@lists.infradead.org,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-tegra@vger.kernel.org
Subject: Re: [PATCH v3 1/2] iommu/arm-smmu-v3: Do not bother impl_ops if IOMMU_VIOMMU_TYPE_ARM_SMMUV3
Date: Wed, 23 Jul 2025 13:19:31 +0000 [thread overview]
Message-ID: <aIDhY3JTaT3JC9T4@google.com> (raw)
In-Reply-To: <20250721200444.1740461-2-nicolinc@nvidia.com>
On Mon, Jul 21, 2025 at 01:04:43PM -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 it must be a driver bug
> that its vsmmu_size and vsmmu_init ops aren't paired. Warn these two cases.
>
> Suggested-by: Will Deacon <will@kernel.org>
> Acked-by: Will Deacon <will@kernel.org>
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Pranjal Shrivastava <praan@google.com>
> ---
> .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 24 ++++++++++---------
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 14 +++++++++++
> 2 files changed, 27 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..c034d6c5468f 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,15 @@ 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;
> + /* Unsupported type was rejected in arm_smmu_get_viommu_size() */
> + if (WARN_ON(viommu->type != smmu->impl_ops->vsmmu_type))
> + return -EOPNOTSUPP;
> + return smmu->impl_ops->vsmmu_init(vsmmu, user_data);
> }
>
> int arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, u64 *evt)
> 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 181d07bc1a9d..9f4ad3705801 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -4703,6 +4703,7 @@ static void arm_smmu_impl_remove(void *data)
> static struct arm_smmu_device *arm_smmu_impl_probe(struct arm_smmu_device *smmu)
> {
> struct arm_smmu_device *new_smmu = ERR_PTR(-ENODEV);
> + const struct arm_smmu_impl_ops *ops;
> int ret;
>
> if (smmu->impl_dev && (smmu->options & ARM_SMMU_OPT_TEGRA241_CMDQV))
> @@ -4713,11 +4714,24 @@ static struct arm_smmu_device *arm_smmu_impl_probe(struct arm_smmu_device *smmu)
> if (IS_ERR(new_smmu))
> return new_smmu;
>
> + ops = new_smmu->impl_ops;
> + if (ops) {
> + /* vsmmu_size and vsmmu_init ops must be paired */
> + if (WARN_ON(!ops->vsmmu_size != !ops->vsmmu_init)) {
> + ret = -EINVAL;
> + goto err_remove;
> + }
> + }
> +
> ret = devm_add_action_or_reset(new_smmu->dev, arm_smmu_impl_remove,
> new_smmu);
> if (ret)
> return ERR_PTR(ret);
> return new_smmu;
> +
> +err_remove:
> + arm_smmu_impl_remove(new_smmu);
> + return ERR_PTR(ret);
> }
>
> static int arm_smmu_device_probe(struct platform_device *pdev)
> --
> 2.43.0
>
>
next prev parent reply other threads:[~2025-07-23 14:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-21 20:04 [PATCH v3 0/2] iommu/arm-smmu-v3: Two vsmmu impl_ops cleanups Nicolin Chen
2025-07-21 20:04 ` [PATCH v3 1/2] iommu/arm-smmu-v3: Do not bother impl_ops if IOMMU_VIOMMU_TYPE_ARM_SMMUV3 Nicolin Chen
2025-07-23 13:19 ` Pranjal Shrivastava [this message]
2025-07-21 20:04 ` [PATCH v3 2/2] iommu/arm-smmu-v3: Replace vsmmu_size/type with get_viommu_size Nicolin Chen
2025-07-23 13:37 ` Pranjal Shrivastava
2025-07-23 18:05 ` Nicolin Chen
2025-07-23 18:58 ` Pranjal Shrivastava
2025-07-24 20:55 ` Pranjal Shrivastava
2025-07-24 21:49 ` Nicolin Chen
2025-07-25 5:11 ` Pranjal Shrivastava
2025-07-25 16:03 ` Nicolin Chen
2025-07-25 17:47 ` Pranjal Shrivastava
2025-07-25 9:18 ` Mostafa Saleh
2025-07-25 16:24 ` Nicolin Chen
2025-07-25 18:12 ` Mostafa Saleh
2025-07-25 19:01 ` Nicolin Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aIDhY3JTaT3JC9T4@google.com \
--to=praan@google.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=nicolinc@nvidia.com \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).