Skip to contentSkip to conversation

iommufd: Do not allow _iommufd_object_alloc_ucmd if abort op is set

PATCH Applied Nicolin Chen 4 participants 4 messages Jul 10, 2025 – Jul 14, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommufd: Do not allow _iommufd_object_alloc_ucmd if abort op is set

An abort op was introduced to allow its caller to invoke it within a lock in the caller's function. On the other hand, _iommufd_object_alloc_ucmd() would invoke the abort op in iommufd_object_abort_and_destroy() that must be outside the caller's lock. So, these two cannot work together.

Add a validation in the _iommufd_object_alloc_ucmd(). Pick -EOPNOTSUPP to reject the function call, indicating that the object allocator is buggy.

---
 drivers/iommu/iommufd/main.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/iommu/iommufd/main.c +9 -0
index 0fb81a905cb1..69c2195e77ca 100644
@@ -71,6 +71,15 @@ struct iommufd_object *_iommufd_object_alloc_ucmd(struct iommufd_ucmd *ucmd,
 	if (WARN_ON(ucmd->new_obj))
 		return ERR_PTR(-EBUSY);
 
+	/*
+	 * An abort op means that its caller needs to invoke it within a lock in
+	 * the caller. So it doesn't work with _iommufd_object_alloc_ucmd() that
+	 * will invoke the abort op in iommufd_object_abort_and_destroy(), which
+	 * must be outside the caller's lock.
+	 */
+	if (WARN_ON(iommufd_object_ops[type].abort))
+		return ERR_PTR(-EOPNOTSUPP);
+
 	new_obj = _iommufd_object_alloc(ucmd->ictx, size, type);
 	if (IS_ERR(new_obj))
 		return new_obj;
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines

From: Nicolin Chen <[email protected]>
Sent: Friday, July 11, 2025 4:24 AM

An abort op was introduced to allow its caller to invoke it within a lock in the caller's function. On the other hand, _iommufd_object_alloc_ucmd() would invoke the abort op in iommufd_object_abort_and_destroy() that must
be outside the caller's lock. So, these two cannot work together.

Quoted 6 lines

Add a validation in the _iommufd_object_alloc_ucmd(). Pick -EOPNOTSUPP to
reject the function call, indicating that the object allocator is buggy.

Reviewed-by
#2 lore raw
Quoted 9 lines · Kevin
Quoted 9 lines

From: Nicolin Chen <[email protected]>
Sent: Friday, July 11, 2025 4:24 AM

An abort op was introduced to allow its caller to invoke it within a lock in the caller's function. On the other hand, _iommufd_object_alloc_ucmd() would invoke the abort op in iommufd_object_abort_and_destroy() that must
be outside the caller's lock. So, these two cannot work together.

Quoted 8 lines
Quoted 6 lines

Add a validation in the _iommufd_object_alloc_ucmd(). Pick -EOPNOTSUPP to
reject the function call, indicating that the object allocator is buggy.

maintainer Applied
#3 lore raw
In reply to Nicolin Chen
Quoted 5 lines · Nicolin Chen

An abort op was introduced to allow its caller to invoke it within a lock in the caller's function. On the other hand, _iommufd_object_alloc_ucmd() would invoke the abort op in iommufd_object_abort_and_destroy() that must be outside the caller's lock. So, these two cannot work together.

Quoted 8 lines

Add a validation in the _iommufd_object_alloc_ucmd(). Pick -EOPNOTSUPP to reject the function call, indicating that the object allocator is buggy.

---
 drivers/iommu/iommufd/main.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Applied

Thanks,
Jason