Linux USB
 help / color / mirror / Atom feed
From: Michal Pecio <michal.pecio@gmail.com>
To: Henry Tseng <henrytseng@qnap.com>
Cc: Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org
Subject: Re: [PATCH 1/2] xhci: make xhci_handshake() timeout wall-clock based again
Date: Fri, 4 Dec 2026 12:13:16 +0100	[thread overview]
Message-ID: <20261204121316.71a9cf59.michal.pecio@gmail.com> (raw)
In-Reply-To: <20260930101752.15794-2-henrytseng@qnap.com>

On Wed, 30 Sep 2026 18:17:51 +0800, Henry Tseng wrote:
> xhci_abort_cmd_ring() waits for the command ring to stop with
> xhci_handshake() and a 5 s timeout. On an AMD Raven USB 3.1 xHCI
> (1022:15e0), after a configure endpoint command failed to complete
> during device disconnect, that handshake returned -ETIMEDOUT 15.8 s
> later:
> 
>   [   86.086412] xhci_hcd 0000:0c:00.3: Command timeout, USBSTS: 0x00000010 PCD
>   [   86.086450] xhci_hcd 0000:0c:00.3: Abort command ring
>   [  101.924383] xhci_hcd 0000:0c:00.3: Abort failed to stop command ring: -110
> 
> xhci_abort_cmd_ring() is called from xhci_handle_command_timeout() with
> xhci->lock held, so interrupts were disabled on that CPU for the whole
> 15.8 s.
> 
> The timeout budget is no longer tied to elapsed time. xhci_handshake()
> originally polled with readl(), udelay(1) and a decrementing
> microsecond counter. Commit f7fac17ca925 ("xhci: Convert
> xhci_handshake() to use readl_poll_timeout_atomic()") replaced that loop
> with readl_poll_timeout_atomic(), which at the time computed its
> deadline with ktime_get(). Its commit message notes that this also
> fixed a bug on AMD Stoneyridge, where udelay(1) sometimes took over
> 10 ms and a 5 s timeout ran for over 15 s, triggering the watchdog.
> Commit 7349a69cf312 ("iopoll: Do not use timekeeping in
> read_poll_timeout_atomic()") then replaced that deadline with a locally
> estimated one, which does not account for the readl(), however long it
> takes.
> 
> To fix this, restore the readl() and udelay() loop, with the
> decrementing microsecond counter replaced by a ktime deadline.
> 
> Signed-off-by: Henry Tseng <henrytseng@qnap.com>

These timeouts are indeed longer than intended, I have seen it myself.
But there is another option: increase 'delay_us'. For example, going
from 1 to 10 reduces abort timeout from 16s to 6s on my system, without
reinventing the wheel. Seems good enough?

Regards,
Michal

  reply	other threads:[~2026-12-04 11:13 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 10:17 [PATCH 0/2] xhci: handshake timeout overrun and configure endpoint hang on device disconnect Henry Tseng
2026-09-30 10:17 ` [PATCH 1/2] xhci: make xhci_handshake() timeout wall-clock based again Henry Tseng
2026-12-04 11:13   ` Michal Pecio [this message]
2026-09-30 10:17 ` [PATCH 2/2] xhci: skip configure endpoint when dropping endpoints of a disconnected device Henry Tseng
2026-10-02  9:30 ` [PATCH 0/2] xhci: handshake timeout overrun and configure endpoint hang on device disconnect Michal Pecio
2026-10-07  9:52   ` Henry Tseng
2026-10-08  9:06     ` Michal Pecio
2026-10-08  9:13       ` Michal Pecio
2026-10-08 10:25       ` Henry Tseng
2026-10-09 15:35         ` Michal Pecio
2026-10-16 10:11           ` Henry Tseng
2026-10-26  9:10             ` Michal Pecio
2026-10-30 10:15               ` Henry Tseng
2026-10-30 10:55                 ` Michal Pecio
2026-10-22 10:03 ` Henry Tseng
2026-11-27 10:17 ` Henry Tseng
2026-12-04 10:58   ` Michal Pecio
2026-12-04 16:17     ` Mathias Nyman

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=20261204121316.71a9cf59.michal.pecio@gmail.com \
    --to=michal.pecio@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=henrytseng@qnap.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.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