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

Aneesh Kumar K.V (Arm) aneesh.kumar at kernel.org
Wed Nov 25 00:11:17 PST 2026


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;
-- 
2.43.0




More information about the linux-arm-kernel mailing list