Re: [PATCH v4 4/7] iommufd: Destroy vdevice on idevice destroy
From: Xu Yilun
Date: Mon Jul 14 2025 - 14:13:55 EST
On Mon, Jul 14, 2025 at 10:34:21AM -0700, Nicolin Chen wrote:
> On Mon, Jul 14, 2025 at 01:53:46PM -0300, Jason Gunthorpe wrote:
> > On Tue, Jul 15, 2025 at 12:40:40AM +0800, Xu Yilun wrote:
> > > diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
> > > index 702ae248df17..bdd5a5227cbf 100644
> > > --- a/drivers/iommu/iommufd/viommu.c
> > > +++ b/drivers/iommu/iommufd/viommu.c
> > > @@ -128,7 +128,8 @@ void iommufd_vdevice_destroy(struct iommufd_object *obj)
> > > mutex_lock(&idev->igroup->lock);
> > > iommufd_vdevice_abort(obj);
> > > mutex_unlock(&idev->igroup->lock);
> > > - iommufd_put_object(idev->ictx, &idev->obj);
> > > + refcount_dec(&idev->obj.shortterm_users);
> > > + wake_up_interruptible_all(&vdev->viommu->ictx->destroy_wait);
> > > }
> >
> > I think the main point of keeping both refcounts is to keep the above
> > hidden in the main functions and out of the object functions.
>
> I see. Maybe we can just update the comments that we are keeping
> both refcounts but using shortterm_users only to do the trick.
I don't think we need special comments. The new usage is not a trick.
It follows the existing mechanism of iommufd_get/put_object().
https://lore.kernel.org/linux-iommu/20250707122502.GS1410929@xxxxxxxxxx/
Adding a patch to rename shortterm_users -> wait_cnt should make
thing clear.
Thanks,
Yilun
>
> Otherwise, we'd need an iommufd_lock_obj_shortterm..
>
> Thanks
> Nicolin