]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: dwc3: gadget: Prevent irq storm when TH re-executes
authorBadhri Jagan Sridharan <badhri@google.com>
Sun, 16 Feb 2025 22:30:02 +0000 (22:30 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:51:08 +0000 (12:51 +0100)
commit 69c58deec19628c8a686030102176484eb94fed4 upstream.

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 <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>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/20250216223003.3568039-1-badhri@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/core.c
drivers/usb/dwc3/gadget.c

index 8c4a292634e5684d2d1c487eff052bac69527e7c..bb20d8dd187918d72270547570a81360e22f3325 100644 (file)
@@ -1456,8 +1456,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;
 }
 
@@ -1475,21 +1473,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 */
index 0735a45c995922e12059455a87f5b5f85b2ab4de..fda00639ff0cbf218e16f1f19eb6b3fe3abd9832 100644 (file)
@@ -4297,14 +4297,18 @@ static irqreturn_t dwc3_process_event_buf(struct dwc3_event_buffer *evt)
        reg &= ~DWC3_GEVNTSIZ_INTMASK;
        dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), reg);
 
+       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;
 }