* [PATCH] iommufd: Do not allow _iommufd_object_alloc_ucmd if abort op is set
@ 2025-07-10 20:23 Nicolin Chen
2025-07-11 3:18 ` Tian, Kevin
2025-07-14 16:51 ` Jason Gunthorpe
0 siblings, 2 replies; 4+ messages in thread
From: Nicolin Chen @ 2025-07-10 20:23 UTC (permalink / raw)
To: jgg, kevin.tian; +Cc: yilun.xu, iommu, linux-kernel
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.
Suggested-by: Xu Yilun <yilun.xu@linux.intel.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/iommufd/main.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c
index 0fb81a905cb1..69c2195e77ca 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;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH] iommufd: Do not allow _iommufd_object_alloc_ucmd if abort op is set
2025-07-10 20:23 [PATCH] iommufd: Do not allow _iommufd_object_alloc_ucmd if abort op is set Nicolin Chen
@ 2025-07-11 3:18 ` Tian, Kevin
2025-07-11 9:40 ` Xu Yilun
2025-07-14 16:51 ` Jason Gunthorpe
1 sibling, 1 reply; 4+ messages in thread
From: Tian, Kevin @ 2025-07-11 3:18 UTC (permalink / raw)
To: Nicolin Chen, jgg@nvidia.com
Cc: yilun.xu@linux.intel.com, iommu@lists.linux.dev,
linux-kernel@vger.kernel.org
> From: Nicolin Chen <nicolinc@nvidia.com>
> 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.
>
> Add a validation in the _iommufd_object_alloc_ucmd(). Pick -EOPNOTSUPP
> to
> reject the function call, indicating that the object allocator is buggy.
>
> Suggested-by: Xu Yilun <yilun.xu@linux.intel.com>
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iommufd: Do not allow _iommufd_object_alloc_ucmd if abort op is set
2025-07-11 3:18 ` Tian, Kevin
@ 2025-07-11 9:40 ` Xu Yilun
0 siblings, 0 replies; 4+ messages in thread
From: Xu Yilun @ 2025-07-11 9:40 UTC (permalink / raw)
To: Tian, Kevin
Cc: Nicolin Chen, jgg@nvidia.com, iommu@lists.linux.dev,
linux-kernel@vger.kernel.org
On Fri, Jul 11, 2025 at 03:18:53AM +0000, Tian, Kevin wrote:
> > From: Nicolin Chen <nicolinc@nvidia.com>
> > 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.
> >
> > Add a validation in the _iommufd_object_alloc_ucmd(). Pick -EOPNOTSUPP
> > to
> > reject the function call, indicating that the object allocator is buggy.
> >
> > Suggested-by: Xu Yilun <yilun.xu@linux.intel.com>
> > Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
>
> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Xu Yilun <yilun.xu@linux.intel.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iommufd: Do not allow _iommufd_object_alloc_ucmd if abort op is set
2025-07-10 20:23 [PATCH] iommufd: Do not allow _iommufd_object_alloc_ucmd if abort op is set Nicolin Chen
2025-07-11 3:18 ` Tian, Kevin
@ 2025-07-14 16:51 ` Jason Gunthorpe
1 sibling, 0 replies; 4+ messages in thread
From: Jason Gunthorpe @ 2025-07-14 16:51 UTC (permalink / raw)
To: Nicolin Chen; +Cc: kevin.tian, yilun.xu, iommu, linux-kernel
On Thu, Jul 10, 2025 at 01:23:54PM -0700, Nicolin Chen wrote:
> 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.
>
> Suggested-by: Xu Yilun <yilun.xu@linux.intel.com>
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
> ---
> drivers/iommu/iommufd/main.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
Applied
Thanks,
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-14 16:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-10 20:23 [PATCH] iommufd: Do not allow _iommufd_object_alloc_ucmd if abort op is set Nicolin Chen
2025-07-11 3:18 ` Tian, Kevin
2025-07-11 9:40 ` Xu Yilun
2025-07-14 16:51 ` Jason Gunthorpe
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).