diff mbox series

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

Message ID b7acc7b61f1ffa156d5922a17e3974f41adb964b.1728491532.git.nicolinc@nvidia.com (mailing list archive)
State New
Headers show
Series cover-letter: iommufd: Add vIOMMU infrastructure (Part-2: vDEVICE) | expand

Commit Message

Nicolin Chen Oct. 9, 2024, 4:38 p.m. UTC
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@nvidia.com>
---
 include/linux/iommu.h          | 4 ++++
 drivers/iommu/iommufd/viommu.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

Comments

Jason Gunthorpe Oct. 17, 2024, 6:47 p.m. UTC | #1
On Wed, Oct 09, 2024 at 09:38:14AM -0700, Nicolin Chen wrote:
> 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.

Why? arm_smmu is now creating its own viommu object, so who will use
this?

Do we have any use for the default mode? It is already a bit
confusing, can we just drop it?

Jason
Nicolin Chen Oct. 17, 2024, 6:50 p.m. UTC | #2
On Thu, Oct 17, 2024 at 03:47:29PM -0300, Jason Gunthorpe wrote:
> On Wed, Oct 09, 2024 at 09:38:14AM -0700, Nicolin Chen wrote:
> > 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.
> 
> Why? arm_smmu is now creating its own viommu object, so who will use
> this?
> 
> Do we have any use for the default mode? It is already a bit
> confusing, can we just drop it?

Hmm, that would make the default model completely useless..

Should we unsupport a default viommu allocation?

Nicolin
Jason Gunthorpe Oct. 17, 2024, 6:52 p.m. UTC | #3
On Thu, Oct 17, 2024 at 11:50:44AM -0700, Nicolin Chen wrote:
> On Thu, Oct 17, 2024 at 03:47:29PM -0300, Jason Gunthorpe wrote:
> > On Wed, Oct 09, 2024 at 09:38:14AM -0700, Nicolin Chen wrote:
> > > 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.
> > 
> > Why? arm_smmu is now creating its own viommu object, so who will use
> > this?
> > 
> > Do we have any use for the default mode? It is already a bit
> > confusing, can we just drop it?
> 
> Hmm, that would make the default model completely useless..
> 
> Should we unsupport a default viommu allocation?

This is my ask?

Jason
diff mbox series

Patch

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;