Skip to contentSkip to conversation

iommu: return early when devices in a group require different domain type

PATCH RESEND Superseded Yuan Can 2 participants 5 messages Sep 21, 2022 – Sep 22, 2022 IOMMU

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH RESEND 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
#1 lore raw

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

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
#2 lore raw

PATCH RESEND 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
#3 lore raw
In reply to Yuan Can
Quoted 8 lines · Yuan Can

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.

As I commented here

https://lore.kernel.org/linux-iommu/[email protected]/

Please use up the allowed number of characters per line before wrapping.

Best regards,
baolu

author
#4 lore raw
Quoted 10 lines · Baolu Lu
Quoted 8 lines · Yuan Can

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.

Quoted 7 lines

As I commented here

https://lore.kernel.org/linux-iommu/[email protected]/

Please use up the allowed number of characters per line before wrapping.

OK, thanks for the notice.

Best regards,

Yuan Can