[PATCH v10 14/18] iommufd/viommu: Identify physical IOMMU backing with a tag

Jacob Pan jacob.pan at linux.microsoft.com
Wed Dec 2 17:10:49 PST 2026


Hi Aneesh,

On Wed, 25 Nov 2026 13:41:17 +0530
"Aneesh Kumar K.V (Arm)" <aneesh.kumar at kernel.org> wrote:

> When allocating a vDEVICE or nested HWPT, IOMMUFD checks that the
> device and its vIOMMU use the same physical IOMMU.
> 
> The next patch adds vIOMMUs implemented by a TSM. These store a TSM
> pointer instead of a physical IOMMU pointer, so the same comparison
> cannot be used.
> 
> Add a backing field to identify vIOMMUs that use a physical IOMMU, and
> perform the comparison only for those vIOMMUs. All existing vIOMMUs
> select that value, so their behavior is unchanged.
> 
> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar at kernel.org>
> ---
>  drivers/iommu/iommufd/hw_pagetable.c | 10 ++++++----
>  drivers/iommu/iommufd/viommu.c       | 11 +++++++----
>  include/linux/iommufd.h              |  5 +++++
>  3 files changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iommu/iommufd/hw_pagetable.c
> b/drivers/iommu/iommufd/hw_pagetable.c index
> ae62db50885c..859eadf05f1d 100644 ---
> a/drivers/iommu/iommufd/hw_pagetable.c +++
> b/drivers/iommu/iommufd/hw_pagetable.c @@ -404,10 +404,12 @@ int
> iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd) struct iommufd_viommu
> *viommu; 
>  		viommu = container_of(pt_obj, struct iommufd_viommu,
> obj);
> -		iommu_dev = iommufd_device_get_iommu_dev(idev);
> -		if (!iommu_dev || viommu->iommu_dev != iommu_dev) {
> -			rc = -EINVAL;
> -			goto out_unlock;
> +		if (viommu->backing == IOMMUFD_VIOMMU_BACKING_IOMMU)
> {
> +			iommu_dev =
> iommufd_device_get_iommu_dev(idev);
> +			if (!iommu_dev || viommu->iommu_dev !=
> iommu_dev) {
> +				rc = -EINVAL;
> +				goto out_unlock;
> +			}
>  		}
>  		hwpt_nested = iommufd_viommu_alloc_hwpt_nested(
>  			viommu, cmd->flags, &user_data);
> diff --git a/drivers/iommu/iommufd/viommu.c
> b/drivers/iommu/iommufd/viommu.c index 472381b96a8e..dab499d24c45
> 100644 --- a/drivers/iommu/iommufd/viommu.c
> +++ b/drivers/iommu/iommufd/viommu.c
> @@ -105,6 +105,7 @@ int iommufd_viommu_alloc_ioctl(struct
> iommufd_ucmd *ucmd)
>  	 * pluggable IOMMU instance (if exists) is responsible for
> refcounting
>  	 * on its own.
>  	 */
> +	viommu->backing = IOMMUFD_VIOMMU_BACKING_IOMMU;
>  	viommu->iommu_dev = iommu_dev;
>  
>  	rc = ops->viommu_init(viommu, idev->dev,
> @@ -218,10 +219,12 @@ int iommufd_vdevice_alloc_ioctl(struct
> iommufd_ucmd *ucmd) goto out_put_idev;
>  	}
>  
> -	iommu_dev = iommufd_device_get_iommu_dev(idev);
> -	if (!iommu_dev || viommu->iommu_dev != iommu_dev) {
> -		rc = -EINVAL;
> -		goto out_put_idev;
> +	if (viommu->backing == IOMMUFD_VIOMMU_BACKING_IOMMU) {
> +		iommu_dev = iommufd_device_get_iommu_dev(idev);
> +		if (!iommu_dev || viommu->iommu_dev != iommu_dev) {
> +			rc = -EINVAL;
> +			goto out_put_idev;
> +		}
>  	}
>  
>  	mutex_lock(&idev->igroup->lock);
> diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h
> index 5f5c67b24134..192d46b8ccfd 100644
> --- a/include/linux/iommufd.h
> +++ b/include/linux/iommufd.h
> @@ -98,9 +98,14 @@ void iommufd_access_detach(struct iommufd_access
> *access); 
>  void iommufd_ctx_get(struct iommufd_ctx *ictx);
>  
> +enum iommufd_viommu_backing {
> +	IOMMUFD_VIOMMU_BACKING_IOMMU,
> +};
> +
>  struct iommufd_viommu {
>  	struct iommufd_object obj;
>  	struct iommufd_ctx *ictx;
> +	enum iommufd_viommu_backing backing;
>  	struct iommu_device *iommu_dev;
>  	struct iommufd_hwpt_paging *hwpt;
>  	struct file *kvm_file;
Reviewed-by: Jacob Pan <jacob.pan at linux.microsoft.com>

FYI, for MSHV/hypervisor external attachment viommu usage, I am
considering a hypervisor-managed backing which does not require
viommu->iommu_dev.




More information about the linux-arm-kernel mailing list