* [PATCH v2 0/3] iommu: Clean up and fixes
@ 2022-09-22 8:09 Yuan Can
2022-09-22 8:09 ` [PATCH v2 1/3] iommu: return early when devices in a group require different domain type Yuan Can
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Yuan Can @ 2022-09-22 8:09 UTC (permalink / raw)
To: joro, will, robin.murphy, iommu; +Cc: yuancan
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(-)
--
2.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] iommu: return early when devices in a group require different domain type
2022-09-22 8:09 [PATCH v2 0/3] iommu: Clean up and fixes Yuan Can
@ 2022-09-22 8:09 ` Yuan Can
2022-09-22 8:09 ` [PATCH v2 2/3] iommu: fix resource leak in iommu_group_alloc Yuan Can
2022-09-22 8:09 ` [PATCH v2 3/3] iommu/ioasid: Add missing new line for info message Yuan Can
2 siblings, 0 replies; 4+ messages in thread
From: Yuan Can @ 2022-09-22 8:09 UTC (permalink / raw)
To: joro, will, robin.murphy, iommu; +Cc: yuancan
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.
Signed-off-by: Yuan Can <yuancan@huawei.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/iommu/iommu.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 4893c2429ca5..34c16f6f44b2 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -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) {
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] iommu: fix resource leak in iommu_group_alloc
2022-09-22 8:09 [PATCH v2 0/3] iommu: Clean up and fixes Yuan Can
2022-09-22 8:09 ` [PATCH v2 1/3] iommu: return early when devices in a group require different domain type Yuan Can
@ 2022-09-22 8:09 ` Yuan Can
2022-09-22 8:09 ` [PATCH v2 3/3] iommu/ioasid: Add missing new line for info message Yuan Can
2 siblings, 0 replies; 4+ messages in thread
From: Yuan Can @ 2022-09-22 8:09 UTC (permalink / raw)
To: joro, will, robin.murphy, iommu; +Cc: yuancan
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.
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
drivers/iommu/iommu.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 34c16f6f44b2..698512580c6a 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -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);
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] iommu/ioasid: Add missing new line for info message
2022-09-22 8:09 [PATCH v2 0/3] iommu: Clean up and fixes Yuan Can
2022-09-22 8:09 ` [PATCH v2 1/3] iommu: return early when devices in a group require different domain type Yuan Can
2022-09-22 8:09 ` [PATCH v2 2/3] iommu: fix resource leak in iommu_group_alloc Yuan Can
@ 2022-09-22 8:09 ` Yuan Can
2 siblings, 0 replies; 4+ messages in thread
From: Yuan Can @ 2022-09-22 8:09 UTC (permalink / raw)
To: joro, will, robin.murphy, iommu; +Cc: yuancan
A new line in the end of the log is expected, otherwise it will be mixed with
later logs.
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
drivers/iommu/ioasid.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/ioasid.c b/drivers/iommu/ioasid.c
index a786c034907c..1af51ee10175 100644
--- a/drivers/iommu/ioasid.c
+++ b/drivers/iommu/ioasid.c
@@ -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;
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-22 8:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-22 8:09 [PATCH v2 0/3] iommu: Clean up and fixes Yuan Can
2022-09-22 8:09 ` [PATCH v2 1/3] iommu: return early when devices in a group require different domain type Yuan Can
2022-09-22 8:09 ` [PATCH v2 2/3] iommu: fix resource leak in iommu_group_alloc Yuan Can
2022-09-22 8:09 ` [PATCH v2 3/3] iommu/ioasid: Add missing new line for info message Yuan Can
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).