]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Revert "usb: xhci: Avoid Stop Endpoint retry loop if the endpoint seems Running"
authorMichal Pecio <michal.pecio@gmail.com>
Wed, 17 Sep 2025 21:07:20 +0000 (00:07 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 15 Oct 2025 09:56:34 +0000 (11:56 +0200)
[ Upstream commit 08fa726e66039dfa80226dfa112931f60ad4c898 ]

This reverts commit 28a76fcc4c85dd39633fb96edb643c91820133e3.

No actual HW bugs are known where Endpoint Context shows Running state
but Stop Endpoint fails repeatedly with Context State Error and leaves
the endpoint state unchanged. Stop Endpoint retries on Running EPs have
been performed since early 2021 with no such issues reported so far.

Trying to handle this hypothetical case brings a more realistic danger:
if Stop Endpoint fails on an endpoint which hasn't yet started after a
doorbell ring and enough latency occurs before this completion event is
handled, the driver may time out and begin removing cancelled TDs from
a running endpoint, even though one more retry would stop it reliably.

Such high latency is rare but not impossible, and removing TDs from a
running endpoint can cause more damage than not giving back a cancelled
URB (which wasn't happening anyway). So err on the side of caution and
revert to the old policy of always retrying if the EP appears running.

[Remove stable tag as we are dealing with theoretical cases -Mathias]

Fixes: 28a76fcc4c85d ("usb: xhci: Avoid Stop Endpoint retry loop if the endpoint seems Running")
Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20250917210726.97100-2-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/host/xhci-ring.c

index c8e1ead0c09e6562a35e3e6e28a09f9a5361a279..cb0bf8b6e017254e31c61e99531a1471979f9380 100644 (file)
@@ -1175,19 +1175,16 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id,
                         * Stopped state, but it will soon change to Running.
                         *
                         * Assume this bug on unexpected Stop Endpoint failures.
-                        * Keep retrying until the EP starts and stops again.
+                        * Keep retrying until the EP starts and stops again, on
+                        * chips where this is known to help. Wait for 100ms.
                         */
+                       if (time_is_before_jiffies(ep->stop_time + msecs_to_jiffies(100)))
+                               break;
                        fallthrough;
                case EP_STATE_RUNNING:
                        /* Race, HW handled stop ep cmd before ep was running */
                        xhci_dbg(xhci, "Stop ep completion ctx error, ctx_state %d\n",
                                        GET_EP_CTX_STATE(ep_ctx));
-                       /*
-                        * Don't retry forever if we guessed wrong or a defective HC never starts
-                        * the EP or says 'Running' but fails the command. We must give back TDs.
-                        */
-                       if (time_is_before_jiffies(ep->stop_time + msecs_to_jiffies(100)))
-                               break;
 
                        command = xhci_alloc_command(xhci, false, GFP_ATOMIC);
                        if (!command) {