[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y9gcyX0HAjaxoBJd@Asurada-Nvidia>
Date: Mon, 30 Jan 2023 11:38:49 -0800
From: Nicolin Chen <nicolinc@...dia.com>
To: Jason Gunthorpe <jgg@...dia.com>
CC: <kevin.tian@...el.com>, <yi.l.liu@...el.com>,
<iommu@...ts.linux.dev>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 2/3] iommufd/device: Make hwpt_list list_add/del
symmetric
On Mon, Jan 30, 2023 at 03:07:50PM -0400, Jason Gunthorpe wrote:
> On Mon, Jan 30, 2023 at 11:03:09AM -0800, Nicolin Chen wrote:
> > On Mon, Jan 30, 2023 at 10:59:32AM -0400, Jason Gunthorpe wrote:
> > > On Sat, Jan 28, 2023 at 01:18:10PM -0800, Nicolin Chen wrote:
> > > > Since the list_del() of hwpt_item is done in iommufd_device_detach(), move
> > > > its list_add_tail() to a similar place in iommufd_device_do_attach().
> > > >
> > > > Also move and place the mutex outside the iommufd_device_auto_get_domain()
> > > > and iommufd_device_do_attach() calls, to serialize attach/detach routines.
> > > > This adds an additional locking protection so that the following patch can
> > > > safely remove devices_lock.
> > >
> > > That should be two patches then, this is just moving one line of code
> > > from what I can tell?
> >
> > The mutex is used to protect the list. So moving the list means
> > we'd need to the mutex too. What this patch does is to enlarge
> > the protection scope a bit to cover iommufd_device_do_attach()
> > and iommufd_device_auto_get_domain().
>
> That doesn't explain why iommufd_device_auto_get_domain was changed
> around, it already had the lock
That is trying to make the code look like this:
iommufd_device_attach {
...
case IOMMUFD_OBJ_HW_PAGETABLE:
+ mutex_lock(&hwpt->ioas->mutex);
rc = iommufd_device_do_attach(idev, hwpt);
+ mutex_unlock(&hwpt->ioas->mutex);
...
case IOMMUFD_OBJ_IOAS:
...
+ mutex_lock(&ioas->mutex);
rc = iommufd_device_auto_get_domain(idev, ioas);
+ mutex_unlock(&ioas->mutex);
...
}
If you don't think that's necessary, I can make things intact
in iommufd_device_auto_get_domain().
Thanks
Nic
Powered by blists - more mailing lists