Commit f842ea20 authored by Nicolin Chen's avatar Nicolin Chen Committed by Jason Gunthorpe
Browse files

iommu: Deprecate viommu_alloc op

To ease the for-driver iommufd APIs, get_viommu_size and viommu_init ops
are introduced. Now, those existing vIOMMU supported drivers implemented
these two ops, replacing the viommu_alloc one. So, there is no use of it.

Remove it from the headers and the viommu core.

Link: https://patch.msgid.link/r/5b32d4499d7ed02a63e57a293c11b642d226ef8d.1749882255.git.nicolinc@nvidia.com


Suggested-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Signed-off-by: default avatarNicolin Chen <nicolinc@nvidia.com>
Reviewed-by: default avatarPranjal Shrivastava <praan@google.com>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 3961f2f5
Loading
Loading
Loading
Loading
+5 −15
Original line number Diff line number Diff line
@@ -33,8 +33,6 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)

	ops = dev_iommu_ops(idev->dev);
	if (!ops->get_viommu_size || !ops->viommu_init) {
		if (ops->viommu_alloc)
			goto get_hwpt_paging;
		rc = -EOPNOTSUPP;
		goto out_put_idev;
	}
@@ -54,7 +52,6 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
		goto out_put_idev;
	}

get_hwpt_paging:
	hwpt_paging = iommufd_get_hwpt_paging(ucmd, cmd->hwpt_id);
	if (IS_ERR(hwpt_paging)) {
		rc = PTR_ERR(hwpt_paging);
@@ -66,11 +63,6 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
		goto out_put_hwpt;
	}

	if (ops->viommu_alloc)
		viommu = ops->viommu_alloc(idev->dev,
					   hwpt_paging->common.domain,
					   ucmd->ictx, cmd->type);
	else
	viommu = (struct iommufd_viommu *)_iommufd_object_alloc(
		ucmd->ictx, viommu_size, IOMMUFD_OBJ_VIOMMU);
	if (IS_ERR(viommu)) {
@@ -92,11 +84,9 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
	 */
	viommu->iommu_dev = __iommu_get_iommu_dev(idev->dev);

	if (!ops->viommu_alloc) {
	rc = ops->viommu_init(viommu, hwpt_paging->common.domain);
	if (rc)
		goto out_abort;
	}

	/* It is a driver bug that viommu->ops isn't filled */
	if (WARN_ON_ONCE(!viommu->ops)) {
+0 −11
Original line number Diff line number Diff line
@@ -607,14 +607,6 @@ iommu_copy_struct_from_full_user_array(void *kdst, size_t kdst_entry_size,
 *               resources shared/passed to user space IOMMU instance. Associate
 *               it with a nesting @parent_domain. It is required for driver to
 *               set @viommu->ops pointing to its own viommu_ops
 * @viommu_alloc: Allocate an iommufd_viommu on a physical IOMMU instance behind
 *                the @dev, as the set of virtualization resources shared/passed
 *                to user space IOMMU instance. And associate it with a nesting
 *                @parent_domain. The @viommu_type must be defined in the header
 *                include/uapi/linux/iommufd.h
 *                It is required to call iommufd_viommu_alloc() helper for
 *                a bundled allocation of the core and the driver structures,
 *                using the given @ictx pointer.
 * @pgsize_bitmap: bitmap of all possible supported page sizes
 * @owner: Driver module providing these ops
 * @identity_domain: An always available, always attachable identity
@@ -669,9 +661,6 @@ struct iommu_ops {
				  enum iommu_viommu_type viommu_type);
	int (*viommu_init)(struct iommufd_viommu *viommu,
			   struct iommu_domain *parent_domain);
	struct iommufd_viommu *(*viommu_alloc)(
		struct device *dev, struct iommu_domain *parent_domain,
		struct iommufd_ctx *ictx, unsigned int viommu_type);

	const struct iommu_domain_ops *default_domain_ops;
	unsigned long pgsize_bitmap;
+0 −18
Original line number Diff line number Diff line
@@ -234,22 +234,4 @@ static inline int iommufd_viommu_report_event(struct iommufd_viommu *viommu,
	 BUILD_BUG_ON_ZERO(offsetof(drv_struct, member)) +                     \
	 BUILD_BUG_ON_ZERO(!__same_type(struct iommufd_viommu,                 \
					((drv_struct *)NULL)->member)))

/*
 * Helpers for IOMMU driver to allocate driver structures that will be freed by
 * the iommufd core. The free op will be called prior to freeing the memory.
 */
#define iommufd_viommu_alloc(ictx, drv_struct, member, viommu_ops)             \
	({                                                                     \
		drv_struct *ret;                                               \
									       \
		static_assert(__same_type(struct iommufd_viommu,               \
					  ((drv_struct *)NULL)->member));      \
		static_assert(offsetof(drv_struct, member.obj) == 0);          \
		ret = (drv_struct *)_iommufd_object_alloc(                     \
			ictx, sizeof(drv_struct), IOMMUFD_OBJ_VIOMMU);         \
		if (!IS_ERR(ret))                                              \
			ret->member.ops = viommu_ops;                          \
		ret;                                                           \
	})
#endif