When user requests to change IOMMU domain to a new type, IOMMU generic
layer checks the requested type against the default domain type returned
by vendor-specific IOMMU driver.

However, there is only one default domain type, and current mechanism
does not allow if the requested type does not match the default type.

Introducing check_domain_type_supported() callback in iommu_ops,
which allows IOMMU generic layer to check with vendor-specific IOMMU driver
whether the requested type is supported. This allows user to request
types other than the default type.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>
---
 drivers/iommu/iommu.c | 13 ++++++++++++-
 include/linux/iommu.h |  2 ++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index f2c45b85b9fc..4afb956ce083 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1521,6 +1521,16 @@ struct iommu_group *fsl_mc_device_group(struct device 
*dev)
 }
 EXPORT_SYMBOL_GPL(fsl_mc_device_group);
 
+static bool iommu_domain_type_supported(struct device *dev, int type)
+{
+       const struct iommu_ops *ops = dev_iommu_ops(dev);
+
+       if (ops->domain_type_supported)
+               return ops->domain_type_supported(dev, type);
+
+       return true;
+}
+
 static int iommu_get_def_domain_type(struct device *dev)
 {
        const struct iommu_ops *ops = dev_iommu_ops(dev);
@@ -2937,7 +2947,8 @@ static int iommu_change_dev_def_domain(struct iommu_group 
*group,
                 * domain the device was booted with
                 */
                type = dev_def_dom ? : iommu_def_domain_type;
-       } else if (dev_def_dom && type != dev_def_dom) {
+       } else if (!iommu_domain_type_supported(dev, type) ||
+                  (dev_def_dom && type != dev_def_dom)) {
                dev_err_ratelimited(prev_dev, "Device cannot be in %s domain\n",
                                    iommu_domain_type_str(type));
                ret = -EINVAL;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index fecb72e1b11b..40c47ab15005 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -214,6 +214,7 @@ struct iommu_iotlb_gather {
  *             - IOMMU_DOMAIN_IDENTITY: must use an identity domain
  *             - IOMMU_DOMAIN_DMA: must use a dma domain
  *             - 0: use the default setting
+ * @domain_type_supported: check if the specified domain type is supported
  * @default_domain_ops: the default ops for domains
  * @pgsize_bitmap: bitmap of all possible supported page sizes
  * @owner: Driver module providing these ops
@@ -252,6 +253,7 @@ struct iommu_ops {
                             struct iommu_page_response *msg);
 
        int (*def_domain_type)(struct device *dev);
+       bool (*domain_type_supported)(struct device *dev, int type);
 
        const struct iommu_domain_ops *default_domain_ops;
        unsigned long pgsize_bitmap;
-- 
2.32.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to