The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Alan Stern <stern@rowland.harvard.edu>,
	Michal Pecio <michal.pecio@gmail.com>
Cc: Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: xhci: Fix isochronous scheduling regression
Date: Mon, 24 Aug 2026 18:21:22 +0300	[thread overview]
Message-ID: <5aa2f501-6980-44c8-b7fd-77f6b3b98bd5@linux.intel.com> (raw)
In-Reply-To: <de41d8f4-e8d2-47d6-8be2-f191b28aecd9@rowland.harvard.edu>

On 8/22/26 05:38, Alan Stern wrote:
> On Fri, Aug 21, 2026 at 06:03:50PM +0200, Michal Pecio wrote:
>> On Fri, 21 Aug 2026 10:44:07 -0400, Alan Stern wrote:
>>> Maybe it's time to correct the hcd_periodic_completion_in_progress()
>>> implementation.
>>>
>>> For instance, we could add an atomic giveback_count field to the
>>> usb_host_endpoint struct.  The HCD would increment the field (while
>>> still holding its private lock) before doing a giveback, and
>>> __usb_hcd_giveback_urb() would decrement the field after calling the
>>> completion handler.
>>>
>>> What do you think?
>>
>> I would go as far as incrementing it on successful usb_submit_urb() and
>> completely doing away with those list_empty(td_list) checks in HCDs.

This sounds like a good idea.

Regarding theoretical race conditions:  If URBs for some odd and unknown
reason are submitted by several callers to the same endpoint (no idea why
or how this would happen) then, usb_hcd_submit_urb() could theoretically call
hcd->driver->urb_enqueue(hcd) for the second URB right when .urb_enqueue(hcd)
returned for the first URB, but _before_ increasing the atomic counter.

In this case hcd would incorrectly assume both first and second URB start a
new isoc stream. This would be avoided by hcd still checking list_empty(td_list)

Anyway, suggested solution still sounds like an improvement compared to what
we currently have.

>>
>> I wrote an xhci-only (less compilation and module reloading) prototype
>> which relies on hijacking completions of isoc URBs for counting, it
>> worked, results identical as with the standard solution in a few test
>> runs with snd-usb-audio.
>>
>> Theoretical race condition: it seems we can't prevent new submissions
>> after completion releases its lock and class driver considers the pipe
>> idle, but before the counter is decremented to zero. That would be
>> another case of "scheduling to the past" unexpectedly.
>>
>> Seems low probability, but this type of bug hasn't existed so far, we
>> generally have the opposite problem.
>>
>> Or does it exist in non-BH HCDs?
> 
> It does.  It's impossible for a non-BH HCD to reacquire its private lock
> exactly when the completion handler returns, so somewhere around that
> time the class driver and the HCD will inevitably have differing
> opinions about whether the iso queue is empty.
> 
>> Maybe the documented API guarantee just isn't feasible?
> 
> I'm not averse to your proposed solution.  As for that race, just update
> the API documentation to take it into account.  Seriously -- it's an
> unavoidable defect and that's all we can do about it.
> 
> Possible alternative: Make the URB_ISO_ASAP flag take precedence over
> the "queue is non-empty" condition.

xhci driver does this. If URB_ISO_ASAP is set then xhci driver always sets
the SIA "Start Isoch ASAP" flag for the transfer blocks.

The urb->start_frame value set by xhci driver might not be correct in this
case.
Thanks
Mathias

  reply	other threads:[~2026-08-24 15:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21  9:47 [PATCH] usb: xhci: Fix isochronous scheduling regression Michal Pecio
2026-08-21 12:05 ` Mathias Nyman
2026-08-21 14:46   ` Michal Pecio
2026-08-21 14:44 ` Alan Stern
2026-08-21 16:03   ` Michal Pecio
2026-08-22  2:38     ` Alan Stern
2026-08-24 15:21       ` Mathias Nyman [this message]
2026-08-24 15:51         ` Alan Stern

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=5aa2f501-6980-44c8-b7fd-77f6b3b98bd5@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=stern@rowland.harvard.edu \
    /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