From: Felipe Balbi <balbi@kernel.org>
To: Wesley Cheng <wcheng@codeaurora.org>
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: dwc3: gadget: Avoid starting DWC3 gadget during UDC unbind
Date: Fri, 17 Sep 2021 12:37:55 +0300 [thread overview]
Message-ID: <87h7eja6ey.fsf@kernel.org> (raw)
In-Reply-To: <474148e5-37e2-ea0c-7d78-9e71155314d9@codeaurora.org>
Wesley Cheng <wcheng@codeaurora.org> writes:
> Hi,
>
> On 9/16/2021 10:17 PM, Felipe Balbi wrote:
>>
>> Hi,
>>
>> Wesley Cheng <wcheng@codeaurora.org> writes:
>>
>>> There is a race present where the DWC3 runtime resume runs in parallel
>>> to the UDC unbind sequence. This will eventually lead to a possible
>>> scenario where we are enabling the run/stop bit, without a valid
>>> composition defined.
>>>
>>> Thread#1 (handling UDC unbind):
>>> usb_gadget_remove_driver()
>>> -->usb_gadget_disconnect()
>>> -->dwc3_gadget_pullup(0)
>>> --> continue UDC unbind sequence
>>> -->Thread#2 is running in parallel here
>>>
>>> Thread#2 (handing next cable connect)
>>> __dwc3_set_mode()
>>> -->pm_runtime_get_sync()
>>> -->dwc3_gadget_resume()
>>> -->dwc->gadget_driver is NOT NULL yet
>>> -->dwc3_gadget_run_stop(1)
>>> --> _dwc3gadget_start()
>>> ...
>>>
>>> Fix this by tracking the pullup disable routine, and avoiding resuming
>>> of the DWC3 gadget. Once the UDC is re-binded, that will trigger the
>>> pullup enable routine, which would handle enabling the DWC3 gadget.
>>>
>>> Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
>
> Thanks, Felipe!
>
>>
>> This looks okay to me, but needs to be tested by a few folks ;-)
>>
>> Acked-by: Felipe Balbi <balbi@kernel.org>
>>
> Yes, would be good to get some functions using
> usb_gadget_activate/deactivate(). It should be OK for those situations
> as well, but just to make sure :)
IIRC, the UVC function relies on those. You could give it a shot ;-)
--
balbi
prev parent reply other threads:[~2021-09-17 9:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-17 2:18 [PATCH] usb: dwc3: gadget: Avoid starting DWC3 gadget during UDC unbind Wesley Cheng
2021-09-17 5:17 ` Felipe Balbi
2021-09-17 6:28 ` Wesley Cheng
2021-09-17 9:37 ` Felipe Balbi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h7eja6ey.fsf@kernel.org \
--to=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=wcheng@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).