Skip to contentSkip to conversation

ARM: SMMU: add devices attached to the SMMU to an IOMMU group

PATCH In review Antonios Motakis 3 participants 3 messages Oct 18, 2013 – Oct 29, 2013 IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ARM: SMMU: add devices attached to the SMMU to an IOMMU group

IOMMU groups are expected by certain users of the IOMMU API, e.g. VFIO. Add new devices found by the SMMU driver to an IOMMU group to satisfy those users.

Changes from v1:
* Added check that dev->archdata.iommu has not been set already by an IOMMU driver. This way we can also skip checking for an existing IOMMU group.

---
 drivers/iommu/arm-smmu.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/iommu/arm-smmu.c +18 -1
index 0f45a48..6762885 100644
@@ -1502,6 +1502,13 @@ static int arm_smmu_add_device(struct device *dev)
 {
 	struct arm_smmu_device *child, *parent, *smmu;
 	struct arm_smmu_master *master = NULL;
+	struct iommu_group *group;
+	int ret;
+
+	if (dev->archdata.iommu) {
+		dev_warn(dev, "IOMMU driver already assigned to device\n");
+		return -EINVAL;
+	}
 
 	spin_lock(&arm_smmu_devices_lock);
 	list_for_each_entry(parent, &arm_smmu_devices, list) {
@@ -1534,13 +1541,23 @@ static int arm_smmu_add_device(struct device *dev)
 	if (!master)
 		return -ENODEV;
 
+	group = iommu_group_alloc();
+	if (IS_ERR(group)) {
+		dev_err(dev, "Failed to allocate IOMMU group\n");
+		return PTR_ERR(group);
+	}
+
+	ret = iommu_group_add_device(group, dev);
+	iommu_group_put(group);
 	dev->archdata.iommu = smmu;
-	return 0;
+
+	return ret;
 }
 
 static void arm_smmu_remove_device(struct device *dev)
 {
 	dev->archdata.iommu = NULL;
+	iommu_group_remove_device(dev);
 }
 
 static struct iommu_ops arm_smmu_ops = {
Signature · 1 line
1.8.1.2
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Antonios Motakis

IOMMU groups are expected by certain users of the IOMMU API, e.g. VFIO. Add new devices found by the SMMU driver to an IOMMU group to satisfy those users.

Changes from v1:
* Added check that dev->archdata.iommu has not been set already by an IOMMU driver. This way we can also skip checking for an existing IOMMU group.

Looks ok to me.

Quoted 47 lines
---
 drivers/iommu/arm-smmu.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/iommu/arm-smmu.c +18 -1
index 0f45a48..6762885 100644
@@ -1502,6 +1502,13 @@ static int arm_smmu_add_device(struct device *dev)
 {
 	struct arm_smmu_device *child, *parent, *smmu;
 	struct arm_smmu_master *master = NULL;
+	struct iommu_group *group;
+	int ret;
+
+	if (dev->archdata.iommu) {
+		dev_warn(dev, "IOMMU driver already assigned to device\n");
+		return -EINVAL;
+	}
 
 	spin_lock(&arm_smmu_devices_lock);
 	list_for_each_entry(parent, &arm_smmu_devices, list) {
@@ -1534,13 +1541,23 @@ static int arm_smmu_add_device(struct device *dev)
 	if (!master)
 		return -ENODEV;
 
+	group = iommu_group_alloc();
+	if (IS_ERR(group)) {
+		dev_err(dev, "Failed to allocate IOMMU group\n");
+		return PTR_ERR(group);
+	}
+
+	ret = iommu_group_add_device(group, dev);
+	iommu_group_put(group);
 	dev->archdata.iommu = smmu;
-	return 0;
+
+	return ret;
 }
 
 static void arm_smmu_remove_device(struct device *dev)
 {
 	dev->archdata.iommu = NULL;
+	iommu_group_remove_device(dev);
 }
 
 static struct iommu_ops arm_smmu_ops = {
#2 lore raw
Quoted 9 lines · Alex Williamson
Quoted 8 lines · Antonios Motakis

IOMMU groups are expected by certain users of the IOMMU API, e.g. VFIO. Add new devices found by the SMMU driver to an IOMMU group to satisfy those users.

Changes from v1:
* Added check that dev->archdata.iommu has not been set already by an IOMMU driver. This way we can also skip checking for an existing IOMMU group.

Quoted 6 lines
Quoted 1 line

Looks ok to me.

Yup, looks fine to me too. I'm travelling until next week, so I'll start picking things up then.

Cheers,

Will