Linux USB
 help / color / mirror / Atom feed
From: Selvarasu Ganesan <selvarasu.g@samsung.com>
To: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"jh0801.jung@samsung.com" <jh0801.jung@samsung.com>,
	"dh10.jung@samsung.com" <dh10.jung@samsung.com>,
	"naushad@samsung.com" <naushad@samsung.com>,
	"akash.m5@samsung.com" <akash.m5@samsung.com>,
	"rc93.raju@samsung.com" <rc93.raju@samsung.com>,
	"taehyun.cho@samsung.com" <taehyun.cho@samsung.com>,
	"hongpooh.kim@samsung.com" <hongpooh.kim@samsung.com>,
	"eomji.oh@samsung.com" <eomji.oh@samsung.com>,
	"shijie.cai@samsung.com" <shijie.cai@samsung.com>
Subject: Re: [PATCH] usb: dwc3: Potential fix of possible dwc3 interrupt storm
Date: Sat, 10 Aug 2024 20:44:53 +0530	[thread overview]
Message-ID: <7fbd2cce-20a0-43c1-862a-3e0b756d8920@samsung.com> (raw)
In-Reply-To: <20240809234540.wyanxgos7j4d7cu2@synopsys.com>


On 8/10/2024 5:15 AM, Thinh Nguyen wrote:
> On Fri, Aug 09, 2024, Thinh Nguyen wrote:
>> On Thu, Aug 08, 2024, Selvarasu Ganesan wrote:
>>> On 8/8/2024 6:45 AM, Thinh Nguyen wrote:
>>>> On Wed, Aug 07, 2024, Selvarasu Ganesan wrote:
>>>>> On 8/7/2024 6:08 AM, Thinh Nguyen wrote:
>>>>>> On Fri, Jul 19, 2024, Selvarasu Ganesan wrote:
>>>>>>> In certain scenarios, there is a chance that the CPU may not be
>>>>>>> scheduled the bottom half of dwc3 interrupt. This is because the CPU
>>>>>>> may hang up where any work queue lockup has happened for the same CPU
>>>>>>> that is trying to schedule the dwc3 thread interrupt. In this scenario,
>>>>>>> the USB can enter runtime suspend as the bus may idle for a longer time
>>>>>>> , or user can reconnect the USB cable. Then, the dwc3 event interrupt
>>>>>>> can be enabled when runtime resume is happening with regardless of the
>>>>>>> previous event status. This can lead to a dwc3 IRQ storm due to the
>>>>>>> return from the interrupt handler by checking only the evt->flags as
>>>>>>> DWC3_EVENT_PENDING, where the same flag was set as DWC3_EVENT_PENDING
>>>>>>> in previous work queue lockup.
>>>>>>> Let's consider the following sequences in this scenario,
>>>>>>>
>>>>>>> Call trace of dwc3 IRQ after workqueue lockup scenario
>>>>>>> ======================================================
>>>>>>> IRQ #1:
>>>>>>> ->dwc3_interrupt()
>>>>>>>      ->dwc3_check_event_buf()
>>>>>>>            ->if (evt->flags & DWC3_EVENT_PENDING)
>>>>>>>                         return IRQ_HANDLED;
>>>>>>>            ->evt->flags |= DWC3_EVENT_PENDING;
>>>>>>>            ->/* Disable interrupt by setting DWC3_GEVNTSIZ_INTMASK  in
>>>>>>>                                                            DWC3_GEVNTSIZ
>>>>>>>            ->return IRQ_WAKE_THREAD; // No workqueue scheduled for dwc3
>>>>>>>                                         thread_fu due to workqueue lockup
>>>>>>>                                         even after return IRQ_WAKE_THREAD
>>>>>>>                                         from top-half.
>>>>>>>
>>>>>>> Thread #2:
>>>>>>> ->dwc3_runtime_resume()
>>>>>>>     ->dwc3_resume_common()
>>>>>>>       ->dwc3_gadget_resume()
>>>>>>>          ->dwc3_gadget_soft_connect()
>>>>>>>            ->dwc3_event_buffers_setup()
>>>>>>>               ->/*Enable interrupt by clearing  DWC3_GEVNTSIZ_INTMASK in
>>>>>>>                                                            DWC3_GEVNTSIZ*/
>>>>>>>
>>>>>>> Start IRQ Storming after enable dwc3 event in resume path
>>>>>>> =========================================================
>>>>>>> CPU0: IRQ
>>>>>>> dwc3_interrupt()
>>>>>>>     dwc3_check_event_buf()
>>>>>>>            if (evt->flags & DWC3_EVENT_PENDING)
>>>>>>>             return IRQ_HANDLED;
>>>>>>>
>>>>>>> CPU0: IRQ
>>>>>>> dwc3_interrupt()
>>>>>>>     dwc3_check_event_buf()
>>>>>>>            if (evt->flags & DWC3_EVENT_PENDING)
>>>>>>>             return IRQ_HANDLED;
>>>>>>> ..
>>>>>>> ..
>>>>>>>
>>>>>>> To fix this issue by avoiding enabling of the dwc3 event interrupt in
>>>>>>> the runtime resume path if dwc3 event processing is in progress.
>>>>>>>
>>>>>>> Signed-off-by: Selvarasu Ganesan <selvarasu.g@samsung.com>
>>>>>>> ---
>>>>>>>     drivers/usb/dwc3/core.c | 8 ++++++--
>>>>>>>     1 file changed, 6 insertions(+), 2 deletions(-)
>>>>>>>
>>>>>>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>>>>>>> index cb82557678dd..610792a70805 100644
>>>>>>> --- a/drivers/usb/dwc3/core.c
>>>>>>> +++ b/drivers/usb/dwc3/core.c
>>>>>>> @@ -549,8 +549,12 @@ int dwc3_event_buffers_setup(struct dwc3 *dwc)
>>>>>>>     			lower_32_bits(evt->dma));
>>>>>>>     	dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0),
>>>>>>>     			upper_32_bits(evt->dma));
>>>>>>> -	dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
>>>>>>> -			DWC3_GEVNTSIZ_SIZE(evt->length));
>>>>>>> +
>>>>>>> +	/* Skip enable dwc3 event interrupt if event is processing in middle */
>>>>>>> +	if (!(evt->flags & DWC3_EVENT_PENDING))
>>>>>>> +		dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
>>>>>>> +				DWC3_GEVNTSIZ_SIZE(evt->length));
>>>>>>> +
>>>>>>>     	dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
>>>>>>>     
>>>>>>>     	return 0;
>>>>>>> -- 
>>>>>>> 2.17.1
>>>>>>>
>>>>>> We're not waking up from a hibernation. So after a soft-reset and
>>>>>> resume, the events that weren't processed are stale. They should be
>>>>>> processed prior to entering suspend or be discarded before resume.
>>>>>>
>>>>>> The synchronize_irq() during suspend() was not sufficient to prevent
>>>>>> this? What are we missing here.
>>>>>>
>>>>>> Thanks,
>>>>>> Thinh
>>>>> I don’t think the triggering of interrupt would not be stopped even if
>>>>> do soft reset. It's because of event count is may be valid .
>>>> Ok. I think I see what you're referring to when you say "event is
>>>> processing in the middle" now.
>>>>
>>>> What you want to check is probably this in dwc3_event_buffers_setup().
>>>> Please confirm:
>>>>
>>>> if (dwc->pending_events)
>>>> 	dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
>>>> 			DWC3_GEVNTSIZ_INTMASK | DWC3_GEVNTSIZ_SIZE(evt->length));
>>>> else
>>>> 	dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_SIZE(evt->length));
>>> Yes, we are expecting the same. But, we must verify the status of
>>> evt->flags, which will indicate whether the event is currently
>>> processing in middle or not. The below code is for the reference.
>>>
>>> if (!(evt->flags & DWC3_EVENT_PENDING))
>>> 	dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
>>> 			 DWC3_GEVNTSIZ_SIZE(evt->length));
>>> else
>>> 	dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
>>> 			DWC3_GEVNTSIZ_INTMASK | DWC3_GEVNTSIZ_SIZE(evt->length));
>> So, this happens while pending_events is set right? I need to review
>> this runtime suspend flow next week. Something doesn't look right. When

yes. You are correct. Its happening while pending_events is set.
>> there's a suspend/resume runtime or not, there's a soft disconnect. We
>> shouldn't be processing any event prior to going into suspend. Also, we
> Clarification: I mean we shouldn't process any event that happened prior
> to suspend on resume because there was a disconnect.

Agree.
>
>> shouldn't be doing soft-disconnect while connected and in operation
>> unless we specifically tell it to.
> Thinh

  reply	other threads:[~2024-08-10 15:25 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20240719110149epcas5p3dd468685a095c094ed2e540279bf3ec2@epcas5p3.samsung.com>
2024-07-19 11:00 ` [PATCH] usb: dwc3: Potential fix of possible dwc3 interrupt storm Selvarasu Ganesan
2024-08-07  0:38   ` Thinh Nguyen
2024-08-07  6:20     ` Selvarasu Ganesan
2024-08-08  1:15       ` Thinh Nguyen
2024-08-08  6:23         ` Selvarasu Ganesan
2024-08-09 23:42           ` Thinh Nguyen
2024-08-09 23:45             ` Thinh Nguyen
2024-08-10 15:14               ` Selvarasu Ganesan [this message]
2024-08-30 12:16             ` Selvarasu Ganesan
2024-08-31  0:50               ` Thinh Nguyen
2024-09-02 11:27                 ` Selvarasu Ganesan
2024-09-03 23:41                   ` Thinh Nguyen
2024-09-04  1:03                   ` Thinh Nguyen
2024-09-04 15:50                     ` Selvarasu Ganesan
2024-09-05  0:26                       ` Thinh Nguyen
2024-09-05 13:19                         ` Selvarasu Ganesan
2024-09-05 21:13                           ` Thinh Nguyen
2024-09-05 23:05                             ` Selvarasu Ganesan
2024-09-05 23:18                               ` Thinh Nguyen
2024-09-06  0:28                                 ` Selvarasu Ganesan
2024-09-06  0:59                                   ` Thinh Nguyen
2024-09-06 19:02                                     ` Selvarasu Ganesan
2024-09-07  0:39                                       ` Thinh Nguyen
2024-09-10 13:37                                         ` Selvarasu Ganesan
2024-09-11  0:24                                           ` Thinh Nguyen
2024-09-13 12:42                                             ` Selvarasu Ganesan
2024-09-13 17:51                                               ` Thinh Nguyen
2024-09-13 18:00                                                 ` Thinh Nguyen
2024-09-16 12:43                                                   ` Selvarasu Ganesan
2024-09-16 21:19                                                     ` Thinh Nguyen
2024-09-16 12:41                                                 ` Selvarasu Ganesan
2024-09-16 21:18                                                   ` Thinh Nguyen
2024-09-16 22:54                                                     ` Selvarasu Ganesan

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=7fbd2cce-20a0-43c1-862a-3e0b756d8920@samsung.com \
    --to=selvarasu.g@samsung.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=akash.m5@samsung.com \
    --cc=dh10.jung@samsung.com \
    --cc=eomji.oh@samsung.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hongpooh.kim@samsung.com \
    --cc=jh0801.jung@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=naushad@samsung.com \
    --cc=rc93.raju@samsung.com \
    --cc=shijie.cai@samsung.com \
    --cc=taehyun.cho@samsung.com \
    /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