From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Michal Pecio <michal.pecio@gmail.com>,
Mathias Nyman <mathias.nyman@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Pedro Fonseca <pedro@fonseca.com.pt>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: xhci: Unlock for command abort polling
Date: Fri, 2 Oct 2026 13:37:13 +0300 [thread overview]
Message-ID: <8707533e-8cbc-4046-92af-90b55031383d@linux.intel.com> (raw)
In-Reply-To: <20261002113302.3fe23d24.michal.pecio@gmail.com>
On 10/2/26 12:33, Michal Pecio wrote:
> On Mon, 24 Aug 2026 09:59:44 +0200, Michal Pecio wrote:
>> xhci_abort_cmd_ring() requests abort, waits for the CRR bit to clear,
>> drops xhci->lock and waits for the Command Ring Stopped event.
>>
>> The CRR wait timeout is 5 seconds as suggested by xHCI 4.6.1.2, which
>> means that if the xHC fails to complete the operation at all, we poll
>> with the lock held and IRQs disabled for several seconds. If any other
>> CPU tries to acquire the lock, it will spin likewise. IRQs get delays,
>> drivers log errors, tasks freeze, it's a mess.
>>
>> So drop the lock earlier, before waiting for the CRR bit. It should be
>> safe - the sole caller sets cmd_ring_state to CMD_RING_STATE_ABORTED
>> before calling us, which will prevent others from ringing the command
>> doorbell and interfering with the abort. Queuing new commands during
>> this time poses no danger, and if the command we try to abort actually
>> completes concurrently, existing code already needs to deal with this.
>> And in my testing it does - it's trivial to trigger this on ASM1042,
>> where Address Device can't be aborted, but it completes as soon as the
>> offending device is unplugged, including during abort attempt.
>>
>> Note that the lock still covers reinit_completion(), so it won't race
>> with complete() being called by the event handler. And works are not
>> reentrant, so another timeout can't expire while the lock is dropped.
>> We will configure timeout anew when restarting the ring.
>>
>> One other difference is that now we also drop the lock if abort fails.
>> This too should be harmless. Commands queued during this time will be
>> released like any other pending commands. If the aborted command does
>> complete before we regain the lock, it's a waste, but not regression.
>>
>> Reported-by: Pedro Fonseca <pedro@fonseca.com.pt>
>> Link: https://lore.kernel.org/linux-usb/16f65081-5a3c-4c30-9811-9017796a3373@fonseca.com.pt/
>> Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
>> ---
>>
>> This has been annoying me and various others for years, only the latest
>> incident is listed above.
>>
>> I expected a nightmare of race conditions, but after finally taking a
>> serious look I think it really is quite simple. It helps that the lock
>> was already being dropped and existing code seems to handle it fine.
>
> Hi Mathias,
>
> Any thoughts about this one? Seems we haven't got any response from
> Pedro, but the patch worked for me (and it solves an annoying bug).
Just added this and a couple of others of your patches for my for-usb-next branch
Thanks
Mathias
prev parent reply other threads:[~2026-10-02 10:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 7:59 Michal Pecio
2026-10-02 9:33 ` Michal Pecio
2026-10-02 10:37 ` Mathias Nyman [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=8707533e-8cbc-4046-92af-90b55031383d@linux.intel.com \
--to=mathias.nyman@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=michal.pecio@gmail.com \
--cc=pedro@fonseca.com.pt \
/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
all inboxes | Powered by JetHome®