From: Nicolin Chen Date: Thu, 10 Jul 2025 20:23:54 +0000 (-0700) Subject: iommufd: Do not allow _iommufd_object_alloc_ucmd if abort op is set X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5510bd89da24508f0e9ae04396e7eb6929ec0e18;p=thirdparty%2Fkernel%2Flinux.git 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. Link: https://patch.msgid.link/r/20250710202354.1658511-1-nicolinc@nvidia.com Suggested-by: Xu Yilun Signed-off-by: Nicolin Chen Reviewed-by: Kevin Tian Reviewed-by: Xu Yilun Signed-off-by: Jason Gunthorpe --- diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 0fb81a905cb13..69c2195e77cad 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -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;