Subject: Re: [RFC PATCH v4 01/25] virtual-bus: Implementation of Virtual Bus

From: Jason Gunthorpe <[email-masked]>
Date: Thu, 20 Feb 2020 15:27:43 -0400

On Thu, Feb 20, 2020 at 06:55:28PM +0000, Ertman, David M wrote:
> > From: Greg KH <[email-masked]>
> > Sent: Friday, February 14, 2020 12:45 PM
> > To: Jason Gunthorpe <[email-masked]>
> > Cc: Kirsher, Jeffrey T <[email-masked]>; [email-masked];
> > Ertman, David M <[email-masked]>; [email-masked];
> > [email-masked]; [email-masked];
> > [email-masked]; [email-masked]; [email-masked];
> > [email-masked]; [email-masked];
> > [email-masked]; [email-masked]; [email-masked];
> > [email-masked]; [email-masked]; [email-masked];
> > [email-masked]; Patil, Kiran <[email-masked]>; Bowers, AndrewX
> > <[email-masked]>
> > Subject: Re: [RFC PATCH v4 01/25] virtual-bus: Implementation of Virtual Bus
> > 
> > On Fri, Feb 14, 2020 at 04:34:55PM -0400, Jason Gunthorpe wrote:
> > > On Fri, Feb 14, 2020 at 09:02:40AM -0800, Greg KH wrote:
> > > > > +	put_device(&vdev->dev);
> > > > > +	ida_simple_remove(&virtbus_dev_ida, vdev->id);
> > > >
> > > > You need to do this before put_device().
> > >
> > > Shouldn't it be in the release function? The ida index should not be
> > > re-used until the kref goes to zero..
> 
> The IDA should not be reused until the virtbus_device is unregistered.  We
> don't want another device with the same name and same IDA to be
> registered,

Unregistration of the virtbus_device always happens before release.

release is the point when the kref goes to zero and you can be
confident there are no other threads reading the index or the device
name.

Remember, the put_device() above is not guarenteed to be the one that
calls to release..

Jason