From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Badhri Jagan Sridharan <badhri@google.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"felipe.balbi@linux.intel.com" <felipe.balbi@linux.intel.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"jameswei@google.com" <jameswei@google.com>,
"stable@kernel.org" <stable@kernel.org>
Subject: Re: [PATCH v3] usb: dwc3: gadget: Prevent irq storm when TH re-executes
Date: Wed, 19 Feb 2025 22:31:42 +0000 [thread overview]
Message-ID: <20250219223127.hbni4oesfdva2bxp@synopsys.com> (raw)
In-Reply-To: <20250216223003.3568039-1-badhri@google.com>
On Sun, Feb 16, 2025, Badhri Jagan Sridharan wrote:
> While commit d325a1de49d6 ("usb: dwc3: gadget: Prevent losing events in
> event cache") makes sure that top half(TH) does not end up overwriting the
> cached events before processing them when the TH gets invoked more than one
> time, returning IRQ_HANDLED results in occasional irq storm where the TH
> hogs the CPU. The irq storm can be prevented by the flag before event
> handler busy is cleared. Default enable interrupt moderation in all
> versions which support them.
>
> ftrace event stub during dwc3 irq storm:
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000866: irq_handler_exit: irq=14 ret=handled
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000872: irq_handler_entry: irq=504 name=dwc3
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000874: irq_handler_exit: irq=504 ret=handled
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000881: irq_handler_entry: irq=504 name=dwc3
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000883: irq_handler_exit: irq=504 ret=handled
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000889: irq_handler_entry: irq=504 name=dwc3
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000892: irq_handler_exit: irq=504 ret=handled
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000898: irq_handler_entry: irq=504 name=dwc3
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000901: irq_handler_exit: irq=504 ret=handled
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000907: irq_handler_entry: irq=504 name=dwc3
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000909: irq_handler_exit: irq=504 ret=handled
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000915: irq_handler_entry: irq=504 name=dwc3
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000918: irq_handler_exit: irq=504 ret=handled
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000924: irq_handler_entry: irq=504 name=dwc3
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000927: irq_handler_exit: irq=504 ret=handled
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000933: irq_handler_entry: irq=504 name=dwc3
> irq/504_dwc3-1111 ( 1111) [000] .... 70.000935: irq_handler_exit: irq=504 ret=handled
> ....
>
> Cc: stable@kernel.org
> Suggested-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
> Fixes: d325a1de49d6 ("usb: dwc3: gadget: Prevent losing events in event cache")
> Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
> ---
> Changes since v2:
> * Consolidate logic for default enabling interrupt moderation as suggested
> by Thinh.Nguyen@
> ---
> drivers/usb/dwc3/core.c | 16 ++++++----------
> drivers/usb/dwc3/gadget.c | 10 +++++++---
> 2 files changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index dfa1b5fe48dc..2c472cb97f6c 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -1835,8 +1835,6 @@ static void dwc3_get_properties(struct dwc3 *dwc)
> dwc->tx_thr_num_pkt_prd = tx_thr_num_pkt_prd;
> dwc->tx_max_burst_prd = tx_max_burst_prd;
>
> - dwc->imod_interval = 0;
> -
> dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num;
> }
>
> @@ -1854,21 +1852,19 @@ static void dwc3_check_params(struct dwc3 *dwc)
> unsigned int hwparam_gen =
> DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3);
>
> - /* Check for proper value of imod_interval */
> - if (dwc->imod_interval && !dwc3_has_imod(dwc)) {
> - dev_warn(dwc->dev, "Interrupt moderation not supported\n");
> - dwc->imod_interval = 0;
> - }
> -
> /*
> + * Enable IMOD for all supporting controllers.
> + *
> + * Particularly, DWC_usb3 v3.00a must enable this feature for
> + * the following reason:
> + *
> * Workaround for STAR 9000961433 which affects only version
> * 3.00a of the DWC_usb3 core. This prevents the controller
> * interrupt from being masked while handling events. IMOD
> * allows us to work around this issue. Enable it for the
> * affected version.
> */
> - if (!dwc->imod_interval &&
> - DWC3_VER_IS(DWC3, 300A))
> + if (dwc3_has_imod((dwc)))
> dwc->imod_interval = 1;
>
> /* Check the maximum_speed parameter */
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index d27af65eb08a..fad115113d28 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -4467,14 +4467,18 @@ static irqreturn_t dwc3_process_event_buf(struct dwc3_event_buffer *evt)
> dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
> DWC3_GEVNTSIZ_SIZE(evt->length));
>
> + evt->flags &= ~DWC3_EVENT_PENDING;
> + /*
> + * Add an explicit write memory barrier to make sure that the update of
> + * clearing DWC3_EVENT_PENDING is observed in dwc3_check_event_buf()
> + */
> + wmb();
> +
> if (dwc->imod_interval) {
> dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), DWC3_GEVNTCOUNT_EHB);
> dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), dwc->imod_interval);
> }
>
> - /* Keep the clearing of DWC3_EVENT_PENDING at the end */
> - evt->flags &= ~DWC3_EVENT_PENDING;
> -
> return ret;
> }
>
>
> base-commit: 9682c35ff6ecd76d9462d4749b8b413d3e8e605e
> --
> 2.48.1.601.g30ceb7b040-goog
>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Thanks,
Thinh
prev parent reply other threads:[~2025-02-19 22:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-16 22:30 [PATCH v3] usb: dwc3: gadget: Prevent irq storm when TH re-executes Badhri Jagan Sridharan
2025-02-19 22:31 ` Thinh Nguyen [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=20250219223127.hbni4oesfdva2bxp@synopsys.com \
--to=thinh.nguyen@synopsys.com \
--cc=badhri@google.com \
--cc=felipe.balbi@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jameswei@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stable@kernel.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