[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aFy++lne6X+1bFlM@yilunxu-OptiPlex-7050>
Date: Thu, 26 Jun 2025 11:31:06 +0800
From: Xu Yilun <yilun.xu@...ux.intel.com>
To: Jason Gunthorpe <jgg@...dia.com>
Cc: kevin.tian@...el.com, will@...nel.org, aneesh.kumar@...nel.org,
iommu@...ts.linux.dev, linux-kernel@...r.kernel.org,
joro@...tes.org, robin.murphy@....com, shuah@...nel.org,
nicolinc@...dia.com, aik@....com, dan.j.williams@...el.com,
baolu.lu@...ux.intel.com, yilun.xu@...el.com
Subject: Re: [PATCH v2 3/4] iommufd: Destroy vdevice on idevice destroy
On Wed, Jun 25, 2025 at 09:38:32AM -0300, Jason Gunthorpe wrote:
> On Wed, Jun 25, 2025 at 06:06:00PM +0800, Xu Yilun wrote:
> > > /*
> > > * We don't know what thread is actually going to destroy the vdev, but
> > > * once the vdev is destroyed the pointer is NULL'd. At this
> > > * point idev->users is 0 so no other thread can set a new vdev.
> > > */
> > > if (!wait_event_timeout(idev->ictx->destroy_wait,
> > > !READ_ONCE(idev->vdev),
> > > msecs_to_jiffies(60000)))
> > > pr_crit("Time out waiting for iommufd vdevice removed\n");
> > > }
> > >
> > > Though there is a cleaner option here, you could do:
> > >
> > > mutex_lock(&idev->igroup->lock);
> > > if (idev->vdev)
> > > iommufd_vdevice_abort(&idev->vdev->obj);
> > > mutex_unlock(&idev->igroup->lock);
> > >
> > > And make it safe to call abort twice, eg by setting dev to NULL and
> > > checking for that. First thread to get to the igroup lock, either via
> > > iommufd_vdevice_destroy() or via the above will do the actual abort
> > > synchronously without any wait_event_timeout. That seems better??
> >
> > I'm good to both options, but slightly tend not to make vdevice so
> > special from other objects, so still prefer the wait_event option.
>
> The wait_event is a ugly hack though, even in its existing code. The
> above version is better because it doesn't have any failure mode and
> doesn't introduce any unlocked use of the idev->vdev which is easier
> to reason about, no READ_ONCE/WRITE_ONCE/etc
>
> It sounds like you should largely leave the existing other parts the
> same as this v2, though can you try reorganize it to look a little
> more like the version I shared?
Sure. But may I confirm that your only want reentrant
iommufd_vdevice_abort() but not your iommufd_object_remove_tombstone()
changes?
To me, grab a shortterm_users but not a user is a new operation model. I
hesitate to add it when the existing refcount_inc(&obj->user) works for
this case.
Thanks,
Yilun
>
> Jason
>
Powered by blists - more mailing lists