]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu/arm-smmu-v3: Replace vsmmu_size/type with get_viommu_size
authorNicolin Chen <nicolinc@nvidia.com>
Thu, 24 Jul 2025 22:10:02 +0000 (15:10 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Mon, 28 Jul 2025 15:07:50 +0000 (12:07 -0300)
It's more flexible to have a get_viommu_size op. Replace static vsmmu_size
and vsmmu_type with that.

Link: https://patch.msgid.link/r/20250724221002.1883034-3-nicolinc@nvidia.com
Suggested-by: Will Deacon <will@kernel.org>
Acked-by: Will Deacon <will@kernel.org>
Reviewed-by: Pranjal Shrivastava <praan@google.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
drivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c

index b963b9b3de54232eade9bfd463f70952186ddc24..8cd8929bbfdf8102bd17c5a23942d7b054ebe2cc 100644 (file)
@@ -423,10 +423,9 @@ size_t arm_smmu_get_viommu_size(struct device *dev,
        if (viommu_type == IOMMU_VIOMMU_TYPE_ARM_SMMUV3)
                return VIOMMU_STRUCT_SIZE(struct arm_vsmmu, core);
 
-       if (!smmu->impl_ops || !smmu->impl_ops->vsmmu_size ||
-           viommu_type != smmu->impl_ops->vsmmu_type)
+       if (!smmu->impl_ops || !smmu->impl_ops->get_viommu_size)
                return 0;
-       return smmu->impl_ops->vsmmu_size;
+       return smmu->impl_ops->get_viommu_size(viommu_type);
 }
 
 int arm_vsmmu_init(struct iommufd_viommu *viommu,
@@ -451,12 +450,6 @@ int arm_vsmmu_init(struct iommufd_viommu *viommu,
                return 0;
        }
 
-       /*
-        * Unsupported type should be rejected by arm_smmu_get_viommu_size.
-        * Seeing one here indicates a kernel bug or some data corruption.
-        */
-       if (WARN_ON(viommu->type != smmu->impl_ops->vsmmu_type))
-               return -EOPNOTSUPP;
        return smmu->impl_ops->vsmmu_init(vsmmu, user_data);
 }
 
index 9f4ad370580104b6f6155e9d179acc58ad44a79d..f56113107c8adb40fd12a88e03b6db221c5357ea 100644 (file)
@@ -4716,8 +4716,8 @@ static struct arm_smmu_device *arm_smmu_impl_probe(struct arm_smmu_device *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)) {
+               /* get_viommu_size and vsmmu_init ops must be paired */
+               if (WARN_ON(!ops->get_viommu_size != !ops->vsmmu_init)) {
                        ret = -EINVAL;
                        goto err_remove;
                }
index 3fa02c51df9f34f4539e8549e9a8e86842a60ead..e332f5ba2f8a2f9c402c264019ded8c607395ead 100644 (file)
@@ -728,8 +728,7 @@ struct arm_smmu_impl_ops {
         */
        void *(*hw_info)(struct arm_smmu_device *smmu, u32 *length,
                         enum iommu_hw_info_type *type);
-       const size_t vsmmu_size;
-       const enum iommu_viommu_type vsmmu_type;
+       size_t (*get_viommu_size)(enum iommu_viommu_type viommu_type);
        int (*vsmmu_init)(struct arm_vsmmu *vsmmu,
                          const struct iommu_user_data *user_data);
 };
index 4c86eacd36b1607288f1feb6d7d2d1123d5eef57..be1aaaf8cd17c87d671a64be076ff48dec4180f7 100644 (file)
@@ -832,6 +832,13 @@ static void *tegra241_cmdqv_hw_info(struct arm_smmu_device *smmu, u32 *length,
        return info;
 }
 
+static size_t tegra241_cmdqv_get_vintf_size(enum iommu_viommu_type viommu_type)
+{
+       if (viommu_type != IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV)
+               return 0;
+       return VIOMMU_STRUCT_SIZE(struct tegra241_vintf, vsmmu.core);
+}
+
 static struct arm_smmu_impl_ops tegra241_cmdqv_impl_ops = {
        /* For in-kernel use */
        .get_secondary_cmdq = tegra241_cmdqv_get_cmdq,
@@ -839,8 +846,7 @@ static struct arm_smmu_impl_ops tegra241_cmdqv_impl_ops = {
        .device_remove = tegra241_cmdqv_remove,
        /* For user-space use */
        .hw_info = tegra241_cmdqv_hw_info,
-       .vsmmu_size = VIOMMU_STRUCT_SIZE(struct tegra241_vintf, vsmmu.core),
-       .vsmmu_type = IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV,
+       .get_viommu_size = tegra241_cmdqv_get_vintf_size,
        .vsmmu_init = tegra241_cmdqv_init_vintf_user,
 };
 
@@ -1273,6 +1279,13 @@ tegra241_cmdqv_init_vintf_user(struct arm_vsmmu *vsmmu,
        phys_addr_t page0_base;
        int ret;
 
+       /*
+        * Unsupported type should be rejected by tegra241_cmdqv_get_vintf_size.
+        * Seeing one here indicates a kernel bug or some data corruption.
+        */
+       if (WARN_ON(vsmmu->core.type != IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV))
+               return -EOPNOTSUPP;
+
        if (!user_data)
                return -EINVAL;