From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF67014B094 for ; Mon, 16 Sep 2024 12:41:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.33 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726490521; cv=none; b=WVb6J3jpsODua2VprimtElfZwCn8FGMT7HJdz0I954FKRzuKUHUTH0/T2FxgSqHmF5sD5U3WEDuUlZM3VVphx0uzo9wFfYfLiv2VoEYS2TSCD0Sf7J1a9XIe1ju3SgU7kt6ylv0vHdQhr+sx/AUUFJXNYxOZLYfI8DzQzqQMgIA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726490521; c=relaxed/simple; bh=LVQhGf/phDF9ol7oIFjlYIZ6YfQASkzCPjJQXD/bWow=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:From:In-Reply-To: Content-Type:References; b=MHn3+uPWyMr3mGvUsN5EzOxCN9ipmxAQkb7EJy5rjWGeFl6JVeLm+am3qHpa+9E0wZ//WPCG/wuyBBDEPrchymp1VeAlkyQthacDQKtLIFLT+MRXn9gREMi7reaqfQWUBrseM+CVqsSQqhk2wcQncOu2LiyjsqY2haaTifgzUxE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=DjY6Eii+; arc=none smtp.client-ip=203.254.224.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="DjY6Eii+" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20240916124150epoutp0377921c73166059cd4ffe07d04ec1dc2d~1ufi-nfIs3200432004epoutp03H for ; Mon, 16 Sep 2024 12:41:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20240916124150epoutp0377921c73166059cd4ffe07d04ec1dc2d~1ufi-nfIs3200432004epoutp03H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1726490510; bh=jbpUw94AxqwSx4gxFSFoZGLytJ7WYFOTOim6PSfGg4I=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=DjY6Eii+AAYjc9ilnLm9YxYDA+Q4uYqCO7MLLIApQnHlrHvIqbFUHlVdN/u0i57TJ HKS5T51wpUd7uwir9LtrgIQ8uaIegDoxwZQIdHyh2gpjlYZh3JjspQPOvdP2I46l+A PlQYBNtxOiX5anB9m85JwHRp3S48gY7kH1EfQ8Iw= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20240916124149epcas5p425cc2e973ae48acbc7c1207b95b22d76~1ufissW_i0791007910epcas5p4r; Mon, 16 Sep 2024 12:41:49 +0000 (GMT) Received: from epsmgec5p1new.samsung.com (unknown [182.195.38.178]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4X6l0X4dyNz4x9Pr; Mon, 16 Sep 2024 12:41:48 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmgec5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 43.DB.08855.C8728E66; Mon, 16 Sep 2024 21:41:48 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20240916124148epcas5p1dae1c77d28e79aac184968591c1f8375~1ufhENgl01284312843epcas5p10; Mon, 16 Sep 2024 12:41:48 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240916124148epsmtrp28d39448da670e604fab3834dca67535d~1ufhDf2ik0425104251epsmtrp2n; Mon, 16 Sep 2024 12:41:48 +0000 (GMT) X-AuditID: b6c32a44-15fb870000002297-33-66e8278cbf7b Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id C9.72.19367.B8728E66; Mon, 16 Sep 2024 21:41:47 +0900 (KST) Received: from [107.122.5.126] (unknown [107.122.5.126]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240916124146epsmtip2df36b8dfbcb32c9b09e17e482b0e9c03~1uffJ2ERW1921019210epsmtip2J; Mon, 16 Sep 2024 12:41:45 +0000 (GMT) Message-ID: <2cf9624b-8612-46aa-a528-a8948ef4f5e1@samsung.com> Date: Mon, 16 Sep 2024 18:11:44 +0530 Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] usb: dwc3: Potential fix of possible dwc3 interrupt storm To: Thinh Nguyen Cc: "gregkh@linuxfoundation.org" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "jh0801.jung@samsung.com" , "dh10.jung@samsung.com" , "naushad@samsung.com" , "akash.m5@samsung.com" , "rc93.raju@samsung.com" , "taehyun.cho@samsung.com" , "hongpooh.kim@samsung.com" , "eomji.oh@samsung.com" , "shijie.cai@samsung.com" Content-Language: en-US From: Selvarasu Ganesan In-Reply-To: <20240913175106.qbav2aigzwaj7pvd@synopsys.com> Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIJsWRmVeSWpSXmKPExsWy7bCmpm6P+os0g/d7lC3eXF3FanFnwTQm i1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HDMasn3jX76v8Vpi+yChW/N0 zIGzU1qmqeln3JFaKjDZ0E5VVbmsr1z5qyjfeyWW4oxEQy3mouJEALUcP98dAwAA X-CMS-MailID: 20240916124148epcas5p1dae1c77d28e79aac184968591c1f8375 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240911002436epcas5p19be55e1144edd6f77184192c7f22a85e References: <20240905231825.6r2sp2bapxidur7a@synopsys.com> <64d049cc-d55d-4376-b6b9-402eb6f170c0@samsung.com> <20240906005935.caugoe3mqqdqwqao@synopsys.com> <30ca8527-419b-4e44-a21b-18e494b39076@samsung.com> <20240907003946.qn6t3xw65qwl2cn7@synopsys.com> <20240911002408.gr4fv5vkst7ukxd5@synopsys.com> <20240913175106.qbav2aigzwaj7pvd@synopsys.com> On 9/13/2024 11:21 PM, Thinh Nguyen wrote: > Hi, > > On Fri, Sep 13, 2024, Selvarasu Ganesan wrote: >> Hi Thinh, >> >> So far, there have been no reported error instances. But, we suspecting >> that the issue may be related to our glue driver. In our glue driver, we >> access the reference of evt->flags when starting or stopping the gadget >> based on a VBUS notification. We apologize for sharing this information >> so late, as we only became aware of it recently. >> >> The following sequence outlines the possible scenarios of race conditions: >> >> Thread#1 (Our glue Driver Sequence) >> =================================== >> ->USB VBUS notification >> ->Start/Stop gadget >> ->dwc->ev_buf->flags |= BIT(20); (It's for our reference) >> ->Call dwc3 exynos runtime suspend/resume >> ->dwc->ev_buf->flags &= ~BIT(20); >> ->Call dwc3 core runtime suspend/resume >> >> Thread#2 >> ======== >> ->dwc3_interrupt() >> ->evt->flags |= DWC3_EVENT_PENDING; >> ->dwc3_thread_interrupt() >> ->evt->flags &= ~DWC3_EVENT_PENDING; >> > This is great! That's likely the problem. Glad you found it. > >> >> After our internal discussions, we have decided to remove the >> unnecessary access to evt->flag in our glue driver. We have made these >> changes and initiated testing. >> >> Thank you for your help so far to understand more into our glue driver code. >> >> And We are thinking that it would be fine to reset evt->flag when the >> USB controller is started, along with the changes you suggested earlier. >> This additional measure will help prevent similar issues from occurring >> in the future. >> >> Please let us know your thoughts on this proposal. If it is not >> necessary, we understand and will proceed accordingly. >> > You can submit the change I suggested. That's a valid change. However, > we should not include the reset of the DWC3_EVENT_PENDING flag. Had we > done this, you may not found the issue above. It serves no purpose for > the core driver logic and will be an extra burden for us to maintain. (I > don't want to scratch my head in the future to figure out why that > change was needed or concern whether it can be removed without causing > regression). Yeah I understand. Please reconfirm the below changes once with commit message. I will post new version if this changes are fine. [PATCH] usb: dwc3: core: Stop processing of pending events if controller is halted This commit addresses an issue where events were being processed when the controller was in a halted state. To fix this issue by stop processing the events as the event count was considered stale or invalid when the controller was halted. Fixes: fc8bb91bc83e ("usb: dwc3: implement runtime PM") Cc: stable Signed-off-by: Selvarasu Ganesan Suggested-by: Thinh Nguyen ---  drivers/usb/dwc3/core.c   | 17 +++++++++++++++--  drivers/usb/dwc3/core.h   |  4 ----  drivers/usb/dwc3/gadget.c | 22 +++++++++++-----------  3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 9eb085f359ce..f47b20bc2d1f 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -544,6 +544,7 @@ static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned int length)  int dwc3_event_buffers_setup(struct dwc3 *dwc)  {         struct dwc3_event_buffer        *evt; +       u32                             reg;         if (!dwc->ev_buf)                 return 0; @@ -556,8 +557,10 @@ int dwc3_event_buffers_setup(struct dwc3 *dwc)                         upper_32_bits(evt->dma));         dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),                         DWC3_GEVNTSIZ_SIZE(evt->length)); -       dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); +       /* Clear any stale event */ +       reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); +       dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg);         return 0;  } @@ -2499,7 +2502,11 @@ static int dwc3_runtime_resume(struct device *dev)         switch (dwc->current_dr_role) {         case DWC3_GCTL_PRTCAP_DEVICE: -               dwc3_gadget_process_pending_events(dwc); +               if (dwc->pending_events) { +                       pm_runtime_put(dwc->dev); +                       dwc->pending_events = false; +                       enable_irq(dwc->irq_gadget); +               }                 break;         case DWC3_GCTL_PRTCAP_HOST:         default: @@ -2589,6 +2596,12 @@ static void dwc3_complete(struct device *dev)  static const struct dev_pm_ops dwc3_dev_pm_ops = {         SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)         .complete = dwc3_complete, + +       /* +        * Runtime suspend halts the controller on disconnection. It replies on +        * platforms with custom connection notification to start the controller +        * again. +        */         SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume,                         dwc3_runtime_idle)  }; diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index c71240e8f7c7..9c508e0c5cdf 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1675,7 +1675,6 @@ static inline void dwc3_otg_host_init(struct dwc3 *dwc)  #if !IS_ENABLED(CONFIG_USB_DWC3_HOST)  int dwc3_gadget_suspend(struct dwc3 *dwc);  int dwc3_gadget_resume(struct dwc3 *dwc); -void dwc3_gadget_process_pending_events(struct dwc3 *dwc);  #else  static inline int dwc3_gadget_suspend(struct dwc3 *dwc)  { @@ -1687,9 +1686,6 @@ static inline int dwc3_gadget_resume(struct dwc3 *dwc)         return 0;  } -static inline void dwc3_gadget_process_pending_events(struct dwc3 *dwc) -{ -}  #endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */  #if IS_ENABLED(CONFIG_USB_DWC3_ULPI) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 291bc549935b..a32c3a292353 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -4483,6 +4483,17 @@ static irqreturn_t dwc3_check_event_buf(struct dwc3_event_buffer *evt)                 return IRQ_HANDLED;         count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); + +       /* +        * If the controller is halted, the event count is stale/invalid. Ignore +        * them. This happens if the interrupt assertion is from an out-of-band +        * resume notification. +        */ +       if (!dwc->pullups_connected && count) { +               dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), count); +               return IRQ_HANDLED; +       } +         count &= DWC3_GEVNTCOUNT_MASK;         if (!count)                 return IRQ_NONE; @@ -4728,14 +4739,3 @@ int dwc3_gadget_resume(struct dwc3 *dwc)         return dwc3_gadget_soft_connect(dwc);  } - -void dwc3_gadget_process_pending_events(struct dwc3 *dwc) -{ -       if (dwc->pending_events) { -               dwc3_interrupt(dwc->irq_gadget, dwc->ev_buf); -               dwc3_thread_interrupt(dwc->irq_gadget, dwc->ev_buf); -               pm_runtime_put(dwc->dev); -               dwc->pending_events = false; -               enable_irq(dwc->irq_gadget); -       } -} -- 2.17.1 Thanks, Selva > Thanks, > Thinh