From: Michal Pecio <michal.pecio@gmail.com>
To: "Mathias Nyman" <mathias.nyman@linux.intel.com>,
<gregkh@linuxfoundation.org>
Cc: sashiko-bot@kernel.org, sashiko-reviews@lists.linux.dev,
linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 02/11] usb: xhci: Unlock for command abort polling
Date: Sat, 10 Oct 2026 08:36:18 +0200 [thread overview]
Message-ID: <20261010083618.24da3062.michal.pecio@gmail.com> (raw)
In-Reply-To: <sashiko-outbox-165772@kernel.org>
On Fri, 09 Oct 2026 15:27:25 +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] usb: xhci: 5-second udelay() busy-wait in sleepable command timeout path
> --
>
> commit 8ece4a222044715c34357d2e1240af7af9feef1a
> Author: Michal Pecio <michal.pecio@gmail.com>
>
> usb: xhci: Unlock for command abort polling
>
> This commit drops the xhci->lock earlier during xhci_abort_cmd_ring() to
> prevent stalling other CPUs while polling for the command ring to stop.
> It subsequently waits for the command ring stop completion event.
>
> Link: https://lore.kernel.org/linux-usb/16f65081-5a3c-4c30-9811-9017796a3373@fonseca.com.pt/
>
> > diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> > --- a/drivers/usb/host/xhci-ring.c
> > +++ b/drivers/usb/host/xhci-ring.c
> [ ... ]
> > @@ -521,25 +521,27 @@ static int xhci_abort_cmd_ring(struct xhci_hcd *xhci, unsigned long flags)
> > * In the future we should distinguish between -ENODEV and -ETIMEDOUT
> > * and try to recover a -ETIMEDOUT with a host controller reset.
> > */
> > + spin_unlock_irqrestore(&xhci->lock, flags);
> > ret = xhci_handshake(&xhci->op_regs->cmd_ring,
> > CMD_RING_RUNNING, 0, 5 * 1000 * 1000);
>
> [Severity: Medium]
> The patch drops xhci->lock here to avoid stalling other CPUs, but
> xhci_handshake() unconditionally uses readl_poll_timeout_atomic():
>
> int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, u64 timeout_us)
> {
> ...
> ret = readl_poll_timeout_atomic(ptr, result,
> (result & mask) == done ||
> result == U32_MAX,
> 1, timeout_us);
>
> Since the context allows sleeping (the lock is dropped, and we call
> wait_for_completion_timeout() right after), does this code burn 100% of
> a CPU core in a busy-wait for up to 5 seconds if the hardware fails?
Does it not? :)
Still an improvement over the status quo.
> Could this use a non-atomic polling macro like readl_poll_timeout()
> with an appropriate usleep_range to yield the CPU instead?
Maybe, but other callers still haven't been fixed to stop being atomic.
My plan was to omit xhci_handshake() in this case and instead increase
the timeout for subsequent completion wait to 5 seconds, but I realized
that this slows down abort processing on HCs that fail to generate the
event we are wating for.
Mathias, do you know what was the buggy HW mentioned in 3425aa03f484d?
Was it really a bug in HW and not SW, maybe it was Intel HW that you
still have access to? None of my HCs exhibit such behavior.
If it's important, I could split the completion wait into stages, poll
USBSTS in between and stop waiting if CRR stays clear for 2 seconds.
Still, I consider all of that outside the scope of *this* patch.
Regards,
Michal
next prev parent reply other threads:[~2026-10-10 6:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 15:16 [PATCH v2 00/11] xhci features and fixes for usb-next Mathias Nyman
2026-10-09 15:16 ` [PATCH v2 01/11] usb: xhci: return an error if the host is not halted Mathias Nyman
2026-10-09 15:24 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 02/11] usb: xhci: Unlock for command abort polling Mathias Nyman
2026-10-09 15:27 ` sashiko-bot
2026-10-10 6:36 ` Michal Pecio [this message]
2026-10-09 15:16 ` [PATCH v2 03/11] usb: xhci: fix typos in comments Mathias Nyman
2026-10-09 15:18 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 04/11] xhci: check device notification type before forwarding wake event Mathias Nyman
2026-10-09 15:23 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 05/11] xhci: dbc: lock the minor IDR on registration failure Mathias Nyman
2026-10-09 15:25 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 06/11] usb: xhci: Guarantee URB giveback on Ring Underrun/Overrun Mathias Nyman
2026-10-09 15:25 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 07/11] usb: xhci: Don't set the skip flag on non-isoc endpoints Mathias Nyman
2026-10-09 15:23 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 08/11] usb: xhci: Shorten the TD skipping loop Mathias Nyman
2026-10-09 15:22 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 09/11] usb: xhci: Rework and improve the TD matching and skipping logic Mathias Nyman
2026-10-09 15:34 ` sashiko-bot
2026-10-10 6:16 ` Michal Pecio
2026-10-09 15:16 ` [PATCH v2 10/11] usb: xhci: Fix bounce buffer overflow Mathias Nyman
2026-10-09 15:28 ` sashiko-bot
2026-10-09 15:16 ` [PATCH v2 11/11] xhci: Prevent invalid vdev dereference during sideband unregister Mathias Nyman
2026-10-09 15:30 ` sashiko-bot
2026-10-09 22:47 ` 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=20261010083618.24da3062.michal.pecio@gmail.com \
--to=michal.pecio@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
--cc=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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