[PATCH v2 07/15] iommu: Add iommu_realloc_dev_group()

From: John Garry
Date: Mon May 10 2021 - 10:27:13 EST


Add a function to re-alloc IOMMU group default domain.

Signed-off-by: John Garry <john.garry@xxxxxxxxxx>
---
drivers/iommu/iommu.c | 12 ++++++++++++
include/linux/iommu.h | 6 ++++++
2 files changed, 18 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index f7253a973ab9..bdb9aa47dfca 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3191,6 +3191,18 @@ static int iommu_change_dev_def_domain(struct iommu_group *group,
return ret;
}

+int iommu_realloc_dev_group(struct device *dev)
+{
+ struct iommu_group *group;
+ int ret;
+
+ group = iommu_group_get(dev);
+ ret = iommu_change_dev_def_domain(group, dev, 0, true);
+ iommu_group_put(group);
+
+ return ret;
+}
+
/*
* Changing the default domain or any other IOMMU group attribute through sysfs
* requires the users to unbind the drivers from the devices in the IOMMU group.
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index e26abda94792..6e187746af0f 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -482,6 +482,7 @@ bool iommu_get_dma_strict(struct iommu_domain *domain);

extern int report_iommu_fault(struct iommu_domain *domain, struct device *dev,
unsigned long iova, int flags);
+extern int iommu_realloc_dev_group(struct device *dev);

static inline void iommu_flush_iotlb_all(struct iommu_domain *domain)
{
@@ -699,6 +700,11 @@ static inline size_t iommu_map_sg_atomic(struct iommu_domain *domain,
return 0;
}

+static inline int iommu_realloc_dev_group(struct device *dev)
+{
+ return -ENODEV;
+}
+
static inline void iommu_flush_iotlb_all(struct iommu_domain *domain)
{
}
--
2.26.2