[RFC PATCH v6 05/11] iommu: Add a helper to validate a vIOMMU parent
From: Aneesh Kumar K.V (Arm)
Date: Thu Sep 17 2026 - 10:23:56 EST
Let a vIOMMU implementation ask the physical IOMMU driver whether a
device and nesting parent are compatible. Return EOPNOTSUPP when the
driver does not supply the validation callback.
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@xxxxxxxxxx>
---
drivers/iommu/iommu.c | 11 +++++++++++
include/linux/iommu.h | 8 ++++++++
2 files changed, 19 insertions(+)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index e8f13dcebbde..04cd5a686e18 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -47,6 +47,17 @@ static unsigned int iommu_def_domain_type __read_mostly;
static bool iommu_dma_strict __read_mostly = IS_ENABLED(CONFIG_IOMMU_DEFAULT_DMA_STRICT);
static u32 iommu_cmd_line __read_mostly;
+int iommu_viommu_validate_parent(struct device *dev,
+ enum iommu_viommu_type type, struct iommu_domain *parent_domain)
+{
+ const struct iommu_ops *ops = dev_iommu_ops(dev);
+
+ if (!ops->viommu_validate_parent)
+ return -EOPNOTSUPP;
+ return ops->viommu_validate_parent(dev, type, parent_domain);
+}
+EXPORT_SYMBOL_GPL(iommu_viommu_validate_parent);
+
/* Tags used with xa_tag_pointer() in group->pasid_array */
enum { IOMMU_PASID_ARRAY_DOMAIN = 0, IOMMU_PASID_ARRAY_HANDLE = 1 };
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index d20aa6f6863a..ee016a7c7a41 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -435,6 +435,9 @@ struct iommu_user_data {
size_t len;
};
+int iommu_viommu_validate_parent(struct device *dev,
+ enum iommu_viommu_type type, struct iommu_domain *parent_domain);
+
/**
* struct iommu_user_data_array - iommu driver specific user space data array
* @type: The data type of all the entries in the user buffer array
@@ -679,6 +682,8 @@ __iommu_copy_struct_to_user(const struct iommu_user_data *dst_data,
* resources shared/passed to user space IOMMU instance. Associate
* it with a nesting @parent_domain. It is required for driver to
* set @viommu->ops pointing to its own viommu_ops
+ * @viommu_validate_parent: Validate that @parent_domain is compatible with
+ * @dev for @viommu_type.
* @owner: Driver module providing these ops
* @identity_domain: An always available, always attachable identity
* translation.
@@ -734,6 +739,9 @@ struct iommu_ops {
int (*viommu_init)(struct iommufd_viommu *viommu,
struct iommu_domain *parent_domain,
const struct iommu_user_data *user_data);
+ int (*viommu_validate_parent)(struct device *dev,
+ enum iommu_viommu_type viommu_type,
+ struct iommu_domain *parent_domain);
const struct iommu_domain_ops *default_domain_ops;
struct module *owner;
--
2.43.0