[PATCH v8 06/29] iommu: Pass in a driver-level user data structure to viommu_init op

Vasant Hegde vasant.hegde at amd.com
Mon Jul 7 01:05:36 PDT 2025



On 7/5/2025 6:43 AM, Nicolin Chen wrote:
> The new type of vIOMMU for tegra241-cmdqv allows user space VM to use one
> of its virtual command queue HW resources exclusively. This requires user
> space to mmap the corresponding MMIO page from kernel space for direct HW
> control.
> 
> To forward the mmap info (offset and length), iommufd should add a driver
> specific data structure to the IOMMUFD_CMD_VIOMMU_ALLOC ioctl, for driver
> to output the info during the vIOMMU initialization back to user space.
> 
> Similar to the existing ioctls and their IOMMU handlers, add a user_data
> to viommu_init op to bridge between iommufd and drivers.

This is useful for AMD driver as well. We can allocate/configure guest specific
things including MMIO page.

> 
> Reviewed-by: Jason Gunthorpe <jgg at nvidia.com>
> Reviewed-by: Lu Baolu <baolu.lu at linux.intel.com>
> Reviewed-by: Pranjal Shrivastava <praan at google.com>
> Reviewed-by: Kevin Tian <kevin.tian at intel.com>
> Signed-off-by: Nicolin Chen <nicolinc at nvidia.com>

Reviewed-by: Vasant Hegde <vasant.hegde at amd.com>

-Vasant

> ---
>  drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h         | 3 ++-
>  include/linux/iommu.h                               | 3 ++-
>  drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 3 ++-
>  drivers/iommu/iommufd/selftest.c                    | 3 ++-
>  drivers/iommu/iommufd/viommu.c                      | 2 +-
>  5 files changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
> index bb39af84e6b0..7eed5c8c72dd 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
> @@ -1037,7 +1037,8 @@ void *arm_smmu_hw_info(struct device *dev, u32 *length, u32 *type);
>  size_t arm_smmu_get_viommu_size(struct device *dev,
>  				enum iommu_viommu_type viommu_type);
>  int arm_vsmmu_init(struct iommufd_viommu *viommu,
> -		   struct iommu_domain *parent_domain);
> +		   struct iommu_domain *parent_domain,
> +		   const struct iommu_user_data *user_data);
>  int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state,
>  				    struct arm_smmu_nested_domain *nested_domain);
>  void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state);
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index fd7319706684..e06a0fbe4bc7 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -700,7 +700,8 @@ struct iommu_ops {
>  	size_t (*get_viommu_size)(struct device *dev,
>  				  enum iommu_viommu_type viommu_type);
>  	int (*viommu_init)(struct iommufd_viommu *viommu,
> -			   struct iommu_domain *parent_domain);
> +			   struct iommu_domain *parent_domain,
> +			   const struct iommu_user_data *user_data);
>  
>  	const struct iommu_domain_ops *default_domain_ops;
>  	unsigned long pgsize_bitmap;
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
> index 69bbe39e28de..170d69162848 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
> @@ -419,7 +419,8 @@ size_t arm_smmu_get_viommu_size(struct device *dev,
>  }
>  
>  int arm_vsmmu_init(struct iommufd_viommu *viommu,
> -		   struct iommu_domain *parent_domain)
> +		   struct iommu_domain *parent_domain,
> +		   const struct iommu_user_data *user_data)
>  {
>  	struct arm_vsmmu *vsmmu = container_of(viommu, struct arm_vsmmu, core);
>  	struct arm_smmu_device *smmu =
> diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
> index 7a9abe3f47d5..0d896a89ace7 100644
> --- a/drivers/iommu/iommufd/selftest.c
> +++ b/drivers/iommu/iommufd/selftest.c
> @@ -779,7 +779,8 @@ static size_t mock_get_viommu_size(struct device *dev,
>  }
>  
>  static int mock_viommu_init(struct iommufd_viommu *viommu,
> -			    struct iommu_domain *parent_domain)
> +			    struct iommu_domain *parent_domain,
> +			    const struct iommu_user_data *user_data)
>  {
>  	struct mock_iommu_device *mock_iommu = container_of(
>  		viommu->iommu_dev, struct mock_iommu_device, iommu_dev);
> diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
> index bc8796e6684e..2009a421efae 100644
> --- a/drivers/iommu/iommufd/viommu.c
> +++ b/drivers/iommu/iommufd/viommu.c
> @@ -84,7 +84,7 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
>  	 */
>  	viommu->iommu_dev = __iommu_get_iommu_dev(idev->dev);
>  
> -	rc = ops->viommu_init(viommu, hwpt_paging->common.domain);
> +	rc = ops->viommu_init(viommu, hwpt_paging->common.domain, NULL);
>  	if (rc)
>  		goto out_put_hwpt;
>  




More information about the linux-arm-kernel mailing list