Re: [PATCH net v4] nfc: ... device_is_registered() is data race-able

From: Greg KH
Date: Thu Apr 28 2022 - 04:16:46 EST


On Thu, Apr 28, 2022 at 03:55:01PM +0800, Lin Ma wrote:
> Hello Greg,
>
>
> >
> > You should not be making these types of checks outside of the driver
> > core.
> >
> > > This is by no means matching our expectations as one of our previous patch relies on the device_is_registered code.
> >
> > Please do not do that.
> >
> > >
> > > -> the patch: 3e3b5dfcd16a ("NFC: reorder the logic in nfc_{un,}register_device")
> > >
> > <...>
> > >
> > > In another word, the device_del -> kobject_del -> __kobject_del is not protected by the device_lock.
> >
> > Nor should it be.
> >
>
> I may have mistakenly presented my point. In fact, there is nothing wrong with the device core, nothing to do with the internal of device_del and device_is_registered implementation. And, of course, we will not add any code or do any modification to the device/driver base code.
>
> The point is the combination of device_is_registered + device_del, which is used in NFC core, is not safe.

It shouldn't be, if you are using it properly :)

> That is to say, even the device_is_registered can return True even the device_del is executing in another thread.

Yes, you should almost never use that call. Seems the nfc subsystem is
the most common user of it for some reason :(

> (By debugging we think this is true, correct me if it is not)
>
> Hence we want to add additional state in nfc_dev object to fix that, not going to add any state in device/driver core.

What state are you trying to track here exactly?

thanks,

greg k-h