Skip to contentSkip to conversation

iommu: Clean up and fixes

PATCH New Yuan Can 1 participant 4 messages Sep 22, 2022 IOMMU

lore
Share & tools
lore

Yuan Can

author
#0 lore raw

v2 cover iommu: Clean up and fixes

This series contains two cleanups and one fix.

Changes in v2:
- Update the comments.

Yuan Can (3):
iommu: return early when devices in a group require different domain
type
iommu: fix resource leak in iommu_group_alloc iommu/ioasid: Add missing new line for info message

 drivers/iommu/ioasid.c |  2 +-
 drivers/iommu/iommu.c  | 12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/3 iommu: return early when devices in a group require different domain type

When alloc default domain for an iommu_group in probe_alloc_default_domain, the expected domain type of each device in the iommu_group is checked in a loop, if two devices require different types, the loop can be broken since the default domain will be set to iommu_def_domain_type.
Return 1 when this happened to break the loop in __iommu_group_for_each_dev.

---
 drivers/iommu/iommu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/iommu.c +1 -0
index 4893c2429ca5..34c16f6f44b2 100644
@@ -1706,6 +1706,7 @@ static int probe_get_default_domain_type(struct device *dev, void *data)
 				 dev_name(gtype->dev),
 				 iommu_domain_type_str(gtype->type));
 			gtype->type = 0;
+			return 1; /* end the outer loop */
 		}
 
 		if (!gtype->dev) {
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v2 2/3 iommu: fix resource leak in iommu_group_alloc

In reply to Yuan Can

When it fails to create file for reserved_regions and type of an iommu_group, the iommu_group_alloc returns ERR_PTR without releasing the iommu_group. Add error handling to cleanup leaking resources.

---
 drivers/iommu/iommu.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/iommu/iommu.c +9 -2
index 34c16f6f44b2..698512580c6a 100644
@@ -734,15 +734,22 @@ struct iommu_group *iommu_group_alloc(void)
 	ret = iommu_group_create_file(group,
 				      &iommu_group_attr_reserved_regions);
 	if (ret)
-		return ERR_PTR(ret);
+		goto out_put_group;
 
 	ret = iommu_group_create_file(group, &iommu_group_attr_type);
 	if (ret)
-		return ERR_PTR(ret);
+		goto out_remove_file;
 
 	pr_debug("Allocated group %d\n", group->id);
 
 	return group;
+
+out_remove_file:
+	iommu_group_remove_file(group, &iommu_group_attr_reserved_regions);
+out_put_group:
+	iommu_group_put(group);
+
+	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(iommu_group_alloc);
 
Signature · 1 line
2.17.1
author
#3 lore raw

PATCH v2 3/3 iommu/ioasid: Add missing new line for info message

In reply to Yuan Can

A new line in the end of the log is expected, otherwise it will be mixed with later logs.

---
 drivers/iommu/ioasid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/ioasid.c +1 -1
index a786c034907c..1af51ee10175 100644
@@ -234,7 +234,7 @@ void ioasid_unregister_allocator(struct ioasid_allocator_ops *ops)
 				rcu_assign_pointer(active_allocator,
 						list_first_entry(&allocators_list,
 								struct ioasid_allocator_data, list));
-				pr_info("IOASID allocator changed");
+				pr_info("IOASID allocator changed.\n");
 			}
 			kfree_rcu(pallocator, rcu);
 			break;
Signature · 1 line
2.17.1