Re: Race condition between driver_probe_device and device_shutdownâ

From: Ming Lei
Date: Thu May 24 2012 - 20:33:35 EST


On Thu, May 24, 2012 at 10:37 PM, Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote:
>
> The code there is racy already.  It does:
>
>                } else if (dev->driver && dev->driver->shutdown) {
>
> without any locking protection.  If the driver is unbound while this
> statement runs then dev->driver could be non-NULL for the first test
> and NULL for the second.

Yes, I missed this one, :-)

>
>> > to fix the race by prevent driver core from probing or releasing once
>> > shutdown is started.
>> >
>> > How about the below patch?
>>
>> How about waiting for the original poster to respond as to exactly how
>> they are hitting this race before doing anything?
>
> In addition, the patch is too complicated.  For this type of
> synchronization you should use SRCU.  See
> Documentation/RCU/whatisRCU.txt and related files.

Yes, the synchronization should be a many reader vs. one
writer problem, RCU should be suitable.

Looks we think alike, :-)

I have studied RCU yesterday, but was afraid that may introduce
much more code, so not applied it in the patch. Will study it further
to figure out a new version.


Thanks,
--
Ming Lei
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/