[PATCH v3 02/16] iommufd/viommu: Add a default_viommu_ops for IOMMU_VIOMMU_TYPE_DEFAULT

Nicolin Chen nicolinc at nvidia.com
Wed Oct 9 09:38:14 PDT 2024


An IOMMU_VIOMMU_TYPE_DEFAULT doesn't need a free() op since the core can
free everything in the destroy(). Now with the new vDEVICE structure, it
might want to allocate its own vDEVICEs.

Add a default_viommu_ops for driver to hook ops for default vIOMMUs.

Signed-off-by: Nicolin Chen <nicolinc at nvidia.com>
---
 include/linux/iommu.h          | 4 ++++
 drivers/iommu/iommufd/viommu.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 9105478bdbcd..1de2aebc4d92 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -44,6 +44,7 @@ struct iommu_dma_cookie;
 struct iommu_fault_param;
 struct iommufd_ctx;
 struct iommufd_viommu;
+struct iommufd_viommu_ops;
 
 #define IOMMU_FAULT_PERM_READ	(1 << 0) /* read */
 #define IOMMU_FAULT_PERM_WRITE	(1 << 1) /* write */
@@ -551,6 +552,8 @@ static inline int __iommu_copy_struct_from_user_array(
  *                It is suggested to call iommufd_viommu_alloc() helper for
  *                a bundled allocation of the core and the driver structures,
  *                using the given @ictx pointer.
+ * @default_viommu_ops: Driver can choose to use a default core-allocated vIOMMU
+ *                      object by providing a default_viommu_ops.
  * @pgsize_bitmap: bitmap of all possible supported page sizes
  * @owner: Driver module providing these ops
  * @identity_domain: An always available, always attachable identity
@@ -605,6 +608,7 @@ struct iommu_ops {
 					       struct iommu_domain *domain,
 					       struct iommufd_ctx *ictx,
 					       unsigned int viommu_type);
+	const struct iommufd_viommu_ops *default_viommu_ops;
 
 	const struct iommu_domain_ops *default_domain_ops;
 	unsigned long pgsize_bitmap;
diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
index 3a903baeee6a..f512dfb535fd 100644
--- a/drivers/iommu/iommufd/viommu.c
+++ b/drivers/iommu/iommufd/viommu.c
@@ -44,7 +44,7 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
 
 	if (cmd->type == IOMMU_VIOMMU_TYPE_DEFAULT) {
 		viommu = __iommufd_viommu_alloc(ucmd->ictx, sizeof(*viommu),
-						NULL);
+						ops->default_viommu_ops);
 	} else {
 		if (!ops->viommu_alloc) {
 			rc = -EOPNOTSUPP;
-- 
2.43.0




More information about the linux-arm-kernel mailing list