From: Elson Serrao <quic_eserrao@quicinc.com>
To: Roger Quadros <rogerq@kernel.org>, <Thinh.Nguyen@synopsys.com>,
<stern@rowland.harvard.edu>
Cc: <gregkh@linuxfoundation.org>, <linux-kernel@vger.kernel.org>,
<linux-usb@vger.kernel.org>, <quic_wcheng@quicinc.com>,
<quic_jackp@quicinc.com>
Subject: Re: [PATCH v3 3/3] usb: dwc3: Modify runtime pm ops to handle bus suspend
Date: Fri, 14 Jul 2023 13:34:36 -0700 [thread overview]
Message-ID: <be57511d-2005-a1f5-d5a5-809e71029aec@quicinc.com> (raw)
In-Reply-To: <8b10d8a5-a9df-6a2e-61b9-7119961e2401@kernel.org>
On 7/14/2023 5:23 AM, Roger Quadros wrote:
>
>
>>>>>> }
>>>>>> static void dwc3_gadget_interrupt(struct dwc3 *dwc,
>>>>>> @@ -4718,7 +4736,15 @@ void dwc3_gadget_process_pending_events(struct dwc3 *dwc)
>>>>>> {
>>>>>> if (dwc->pending_events) {
>>>>>> dwc3_interrupt(dwc->irq_gadget, dwc->ev_buf);
>>>>>> + pm_runtime_put(dwc->dev);
>>>>>
>>>>> Why the put here?
>>>>>
>>>>
>>>> To balance the get() called when setting the pending_events flag in dwc3_check_event_buf()
>>>>
>>>> if (pm_runtime_suspended(dwc->dev)) {
>>>> pm_runtime_get(dwc->dev);
>>>> disable_irq_nosync(dwc->irq_gadget);
>>>> dwc->pending_events = true;
>>>> return IRQ_HANDLED;
>>>> }
>>>>
>>>
>>> No this wrong. We want the device to be active from now on.
>>>
>>> runtime suspended->interrupt->pm_runtime_get->runtime_resume->process_pending_events->USB gadget resumed
>>>
>>> Only on next USB suspend you want to do the pm_runtime_put like you are doing it
>>> in dwc3_gadget_suspend_interrupt() by pm_request_autosuspend()
>>>
>>
>> That would break/block dwc3 runtime suspend during DISCONNECT case in below scenario
>>
>> runtime suspended->interrupt->pm_runtime_get (runtime usage count is 1)->runtime_resume->process_pending_events->USB gadget resumed -> USB disconnect (autosuspend blocked due to runtime usage count being 1 due to unbalanced get() ).
>>
>> The idea here is to balance the get() that was requested for processing the pending events, after processing those events. (like how we balance get() of ep_queue through put() in ep_dequeue)
>>
>> Also pm_request_autosuspend() doesnt decrement the usage count, it only requests for autosuspend.
>
> Ah, indeed.
>
>>
>> But I think better approach in terms of ordering is below
>
> ok, but should dwc->pending_events be set before calling pm_runtime_get() in dwc3_check_event_buf()?
Yes that would be a better approach (just in case if there is any race
between dwc3_check_event_buf() and the resume() path).
> Can we add a comment there that the get will be balanced out in dwc3_gadget_process_pending_events()?
Sure.
>
>>
>> @@ -4718,7 +4736,15 @@ void dwc3_gadget_process_pending_events(struct dwc3 *dwc)
>> {
>> if (dwc->pending_events) {
>> dwc3_interrupt(dwc->irq_gadget, dwc->ev_buf);
>> + /*
>> + * We have only stored the pending events as part
>> + * of dwc3_interrupt() above, but those events are
>> + * not yet handled. So explicitly invoke the
>> + * interrupt handler for handling those events.
>> + */
>> + dwc3_thread_interrupt(dwc->irq_gadget, dwc->ev_buf);
>> dwc->pending_events = false;
>> enable_irq(dwc->irq_gadget);
>> + pm_runtime_put(dwc->dev);
>
> We could do the put right after dwc3_thread_interrupt().
Ack.
>
>>
>> }
>> }
>
> I think this fix should be an independent patch
> as this fixes an issue that existed prior to this series?
> also need to -cc stable?
>
Agree. Both dwc3_thread_interrupt() and pm_runtime_put() above are
addressing an issue that existed prior. I will submit a separate patch
for this modification.
Thanks
Elson
next prev parent reply other threads:[~2023-07-14 20:34 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-11 17:43 [PATCH v3 0/3] Support dwc3 runtime suspend during bus suspend Elson Roy Serrao
2023-07-11 17:43 ` [PATCH v3 1/3] usb: function: u_ether: Handle rx requests during suspend/resume Elson Roy Serrao
2023-07-11 17:43 ` [PATCH v3 2/3] dt-bindings: usb: snps,dwc3: Add allow-rtsusp-on-u3 property Elson Roy Serrao
2023-07-11 21:56 ` Thinh Nguyen
2023-07-11 22:38 ` Elson Serrao
2023-07-12 11:53 ` Roger Quadros
2023-07-12 22:34 ` Thinh Nguyen
2023-07-12 5:47 ` Krzysztof Kozlowski
2023-07-11 17:43 ` [PATCH v3 3/3] usb: dwc3: Modify runtime pm ops to handle bus suspend Elson Roy Serrao
2023-07-11 22:07 ` Thinh Nguyen
2023-07-11 22:51 ` Elson Serrao
2023-07-11 23:22 ` Elson Serrao
2023-07-12 13:46 ` Roger Quadros
2023-07-12 22:57 ` Elson Serrao
2023-07-13 12:56 ` Roger Quadros
2023-07-13 22:31 ` Elson Serrao
2023-07-14 12:23 ` Roger Quadros
2023-07-14 20:34 ` Elson Serrao [this message]
2023-07-11 21:58 ` [PATCH v3 0/3] Support dwc3 runtime suspend during " Thinh Nguyen
2023-07-12 12:16 ` Roger Quadros
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=be57511d-2005-a1f5-d5a5-809e71029aec@quicinc.com \
--to=quic_eserrao@quicinc.com \
--cc=Thinh.Nguyen@synopsys.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=quic_jackp@quicinc.com \
--cc=quic_wcheng@quicinc.com \
--cc=rogerq@kernel.org \
--cc=stern@rowland.harvard.edu \
/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