Re: [PATCH 2/2] usb: dwc3: drd: Fix lock-up on ID change during system suspend/resume
From: Roger Quadros
Date: Mon Feb 12 2018 - 05:48:38 EST
Felipe,
On 12/02/18 10:54, Felipe Balbi wrote:
>
> Hi,
>
> Roger Quadros <rogerq@xxxxxx> writes:
>> Adding/removing host/gadget controller before .pm_complete()
>> causes a lock-up. Let's prevent any dual-role state change
>> between .pm_prepare() and .pm_complete() to fix this.
>>
>> Signed-off-by: Roger Quadros <rogerq@xxxxxx>
>> ---
>> drivers/usb/dwc3/core.c | 31 +++++++++++++++++++++++++++++++
>> drivers/usb/dwc3/core.h | 5 +++++
>> drivers/usb/dwc3/drd.c | 10 ++++++----
>> 3 files changed, 42 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>> index 42379cc..85388dd 100644
>> --- a/drivers/usb/dwc3/core.c
>> +++ b/drivers/usb/dwc3/core.c
>> @@ -1414,6 +1414,33 @@ static int dwc3_runtime_idle(struct device *dev)
>> #endif /* CONFIG_PM */
>>
>> #ifdef CONFIG_PM_SLEEP
>> +static int dwc3_prepare(struct device *dev)
>> +{
>> + struct dwc3 *dwc = dev_get_drvdata(dev);
>> + unsigned long flags;
>> +
>> + if (dwc->dr_mode == USB_DR_MODE_OTG) {
>> + spin_lock_irqsave(&dwc->lock, flags);
>> + dwc->dr_keep_role = true;
>> + spin_unlock_irqrestore(&dwc->lock, flags);
>> + }
>> +
>> + return 0;
>> +}
>> +
>> +static void dwc3_complete(struct device *dev)
>> +{
>> + struct dwc3 *dwc = dev_get_drvdata(dev);
>> + unsigned long flags;
>> +
>> + if (dwc->dr_mode == USB_DR_MODE_OTG) {
>> + spin_lock_irqsave(&dwc->lock, flags);
>> + dwc->dr_keep_role = false;
>> + spin_unlock_irqrestore(&dwc->lock, flags);
>> + dwc3_drd_update(dwc);
>> + }
>> +}
>
> wouldn't it be far easier to just disable OTG IRQ in prepare? and,
> perhaps, also flush_work_sync() ?
>
There was some more discussion on this here [1]. Apparently using system_freezable_wq
and a patch mentioned at end of [1] is sufficient as well
[1] https://lkml.org/lkml/2018/1/25/384
Could you please share your view there?
--
cheers,
-roger
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki