RE: Re: Re: Subject: [PATCH v1] USB:Core: BugFix: Proper handling of Race Condition when two USB class drivers try to call init_usb_class simultaneously

From: Ajay Kaher
Date: Wed Feb 01 2017 - 03:34:46 EST


Â
>> At boot time, probe function of multiple connected devices
>> (proprietary devices) execute simultaneously.
>
>What exactly do you mean here? How can probe happen "simultaneously"?
>The USB core prevents this, right?

I have observed two scenarios to call probe function:

Scenario #1: Driver inserted and attaching USB Device:
Yes, you are right, two probes at same time is not happening
in this scenario.

Scenario #2: USB Device attached and inserting Driver:
In this case probe has been called in context of insmod,
refer following code flow:
init -> usb_register_driver -> driver_register -> bus_add_driver ->
driver_attach -> bus_for_each_dev -> __driver_attach ->
driver_probe_device -> usb_probe_interface -> probe -> usb_register_dev

I have observed the crash in Scenario #2, as two probes executes at
same time in this scenario. And init_usb_class_mutex lock require to
prevent race condition.

>> And because of the following code path race condition happens:
>> probe->usb_register_dev->init_usb_class
>
>Why is this just showing up now, and hasn't been an issue for the decade
>or so this code has been around? What changed?
>
>> Tested with these changes, and problem has been solved.
>
>What changes?

Tested with my patch (i.e. locking with init_usb_class_mutex).

thanks,

ajay kaher


Â
--------- Original Message ---------
Sender : gregkh@xxxxxxxxxxxxxxxxxxxÂ<gregkh@xxxxxxxxxxxxxxxxxxx>
Date : 2017-01-31 12:31 (GMT+5:30)
Title : Re: Re: Subject: [PATCH v1] USB:Core: BugFix: Proper handling of Race Condition when two USB class drivers try to call init_usb_class simultaneously
Â
A:Âhttp://en.wikipedia.org/wiki/Top_post
Q:ÂWereÂdoÂIÂfindÂinfoÂaboutÂthisÂthingÂcalledÂtop-posting?
A:ÂBecauseÂitÂmessesÂupÂtheÂorderÂinÂwhichÂpeopleÂnormallyÂreadÂtext.
Q:ÂWhyÂisÂtop-postingÂsuchÂaÂbadÂthing?
A:ÂTop-posting.
Q:ÂWhatÂisÂtheÂmostÂannoyingÂthingÂinÂe-mail?
Â
A:ÂNo.
Q:ÂShouldÂIÂincludeÂquotationsÂafterÂmyÂreply?
Â
Â
http://daringfireball.net/2007/07/on_top
Â
OnÂTue,ÂJanÂ31,Â2017ÂatÂ05:21:46AMÂ+0000,ÂAjayÂKaherÂwrote:
>Â
>ÂÂ
>ÂAtÂbootÂtime,ÂprobeÂfunctionÂofÂmultipleÂconnectedÂdevices
>Â(proprietaryÂdevices)ÂexecuteÂsimultaneously.
Â
WhatÂexactlyÂdoÂyouÂmeanÂhere?ÂÂHowÂcanÂprobeÂhappenÂ"simultaneously"?
TheÂUSBÂcoreÂpreventsÂthis,Âright?
Â
AndÂwhatÂdoÂyouÂmeanÂexactlyÂbyÂ"(proprietaryÂdevices)"?
Â
>ÂAndÂbecauseÂofÂtheÂfollowingÂcodeÂpathÂraceÂconditionÂhappens:
>Âprobe->usb_register_dev->init_usb_class
Â
WhyÂisÂthisÂjustÂshowingÂupÂnow,ÂandÂhasn'tÂbeenÂanÂissueÂforÂtheÂdecade
orÂsoÂthisÂcodeÂhasÂbeenÂaround?ÂÂWhatÂchanged?
Â
>ÂTestedÂwithÂtheseÂchanges,ÂandÂproblemÂhasÂbeenÂsolved.
Â
WhatÂchanges?
Â
thanks,
Â
gregÂk-h
Â
Â
Thanks and Regards,
Ajay Kaher