Re: [PATCH v4 3/7] iommufd: Add a pre_destroy() op for objects
From: Jason Gunthorpe
Date: Thu Jul 10 2025 - 13:15:35 EST
On Thu, Jul 10, 2025 at 07:40:58AM +0000, Tian, Kevin wrote:
> > From: Xu Yilun <yilun.xu@xxxxxxxxxxxxxxx>
> > Sent: Wednesday, July 9, 2025 12:03 PM
> >
> > Add a pre_destroy() op which gives objects a chance to clear their
> > short term users references before destruction. This op is intended for
> > external driver created objects (e.g. idev) which does deterministic
> > destruction.
> >
> > In order to manage the lifecycle of interrelated objects as well as the
> > deterministic destruction (e.g. vdev can't outlive idev, and idev
> > destruction can't fail), short term users references are allowed to
> > live out of an ioctl execution. An immediate use case is, vdev holds
> > idev's short term user reference until vdev destruction completes, idev
> > leverages existing wait_shortterm mechanism to ensure it is destroyed
> > after vdev.
> >
> > This extended usage makes the referenced object unable to just wait for
> > its reference gone. It needs to actively trigger the reference removal,
> > as well as prevent new references before wait. Should implement these
> > work in pre_destroy().
> >
> > Suggested-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
> > Signed-off-by: Xu Yilun <yilun.xu@xxxxxxxxxxxxxxx>
>
> Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>
>
> btw is it clearer to rename 'shortterm_users' as 'wait_cnt', as the
> meaning now is beyond shortterm and is really about the need of
> waiting?
Probably so, as a followup change would be fine if we don't need a v5
/*
* Destroy will sleep and wait for wait_cnt to go to zero. This
* allows concurrent users of the ID to reliably avoid causing a
* spurious destroy failure. Incrementing this count should either be
* short lived or be revoked and blocked during pre_destroy
*/
refcount_t wait_cnt;
?
Jason