Re: [PATCH v4 05/23] iommufd/driver: Let iommufd_viommu_alloc helper save ictx to viommu->ictx

Jason Gunthorpe
2025-05-14T17:06:43Z

On Thu, May 08, 2025 at 08:02:26PM -0700, Nicolin Chen wrote:
> When an IOMMU driver calls iommufd_viommu_alloc(), it must pass in an ictx
> pointer as the underlying _iommufd_object_alloc() helper function requires
> that to allocate a new object. However, neither the iommufd_viommu_alloc()
> nor its underlying _iommufd_object_alloc() saves the ictx in the allocated
> viommu object, although viommu could hold an ictx pointer.
>
> When the IOMMU driver wants to use another iommufd function passing in the
> allocated viommu, it could have avoided passing in the ictx pointer again,
> if viommu->ictx is valid.
>
> Save ictx to viommu->ictx in the iommufd_viommu_alloc(), in order to ease
> a new vIOMMU-based helper that would then get the ictx from viommu->ictx.
>
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
> ---
> include/linux/iommufd.h | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)

It is OK, but please think carefully if the ictx is actually
needed. The reason most objects don't have an ictx in them is because
their contexts are always inside an ioctl so they get the ictx from
there.

We don't have a lot of viommu allocations so it isn't such a big deal,
but just generally that is how it was built that the ictx comes from
the ioctl not the object.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Jason