public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Michal Pecio <michal.pecio@gmail.com>
To: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Cc: "Alan Stern" <stern@rowland.harvard.edu>,
	"Oliver Neukum" <oneukum@suse.com>, "Bjørn Mork" <bjorn@mork.no>,
	"USB list" <linux-usb@vger.kernel.org>
Subject: Re: correctly handling EPROTO
Date: Fri, 20 Mar 2026 10:58:38 +0100	[thread overview]
Message-ID: <20260320105838.2eaebfe5.michal.pecio@gmail.com> (raw)
In-Reply-To: <20260319231620.3ukqxsrwqikp5zbd@synopsys.com>

On Thu, 19 Mar 2026 23:16:22 +0000, Thinh Nguyen wrote:
> On Wed, Mar 18, 2026, Alan Stern wrote:
> > I don't know about uas, but usb-storage handles transaction error 
> > recovery in approximately the same way.  A clear-halt is issued
> > only if the device sent a halt token -- but that's not considered a
> > transaction error.
> 
> That's -EPIPE right? With this, the storage driver knows that it
> needs to perform clear-halt because the bulk endpoint is STALL, not
> -EPROTO.

To be exact, EPIPE only means that the host got STALL handshake, but
not that the device originated it. Our good friend TT rendponds with
STALL after Bulk/Control transaction error on the downstream bus.
Similar error on Int produces a distinct ERR handshake. Don't ask me.

On IN endpoint both sides agree that the transaction didn't happen.
On OUT the device may have accepted the data (figure A-14). If you
mindlessly clear halt and resubmit it will accept same data again.

Some HCDs also report ETIME and EILSEQ, supposedly similar to EPROTO.

On xhci-hcd there is no ETIME, and EILSEQ means that the HW considers
our "transfer descriptors" ill formed. We don't bother unlocking the
endpoint, as retrying seems futile. No reports in at least two years.
Maybe other status would be more appropriate? But nobody complains.

> > Otherwise, for things like -EPROTO, usb-storage does a device reset
> > and the SCSI command is retried.  Possibly skipping some initial   
> 
> The recovery I'm thinking of doesn't involve a port reset. A port
> reset is very disruptive and will impact performance greatly. I'm
> referring to an intermediate recovery step at the usb storage driver
> without delegating to the SCSI layer.

Device reset is slow no doubt, but it may be the reason why there are
no users screaming about filesystem corruption despite the apparent
widespread neglect of TT corner cases and xhci-hcd bugs.

UAS is another can of worms, for example xHCI seems to require a
guarantee that a stream is inactive in the device (by class specific
means) before its URBs can be unlinked. See 4.6.10, 4.12.

> What I'd like to see is that the endpoint can be put in a state where
> the class driver can submit a new URB without unbind/reset/power
> cycle. With the current implementation of the xhci driver, we cannot
> do that for bulk endpoints with -EPROTO error.

It can already be done with usb_clear_halt() and this should generally
work for drivers which don't queue multiple URBs in advance (those are
subject to race conditions due to BH giveback, and to xhci-hcd bugs).

Double delivery is possible on retries after usb_clear_halt(). Probably
less likely at SuperSpeed (32 instead of 2 sequence states).

If you don't reset the pipe then xhci-hcd resets one end of it behind
your back. I could write a test patch which changes this behavior for
people to play with, but you seemed skeptical.

Alternatively, URB API would need changes to support xHCI native retry.

As you work for an xHCI IP vendor, do you know something we don't? ;)
It seems to me (and Mathias apparently too) that Reset Endpoint with
TSP followed by Set TR Dequeue would trick HW into retrying the failed
USB transaction with the data buffer of the new or resubmitted URB.

Except of course if TTs are involved. Retrying transactions involving
those is "undefined behavior" per xHCI spec. I suspect that even
ehci-hcd may not support retry by resubmission in such cases properly.

Regards,
Michal

  reply	other threads:[~2026-03-20  9:58 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 13:55 correctly handling EPROTO Oliver Neukum
2026-03-12 14:21 ` Alan Stern
2026-03-12 15:57   ` Oliver Neukum
2026-03-13  7:53     ` Michal Pecio
2026-03-13 10:33       ` Oliver Neukum
2026-03-13 15:28         ` Alan Stern
2026-03-13 22:45           ` Thinh Nguyen
2026-03-14  2:39             ` Alan Stern
2026-03-16 12:58               ` Oliver Neukum
2026-03-16 14:02                 ` Alan Stern
2026-03-16 14:47                   ` Oliver Neukum
2026-03-16 17:33                     ` Alan Stern
2026-03-16 19:32                       ` Oliver Neukum
2026-03-17  9:05                         ` Mathias Nyman
2026-03-17 14:31                         ` Alan Stern
2026-03-17 16:20                           ` Oliver Neukum
2026-03-17 18:03                             ` Alan Stern
2026-03-18  9:54                               ` Oliver Neukum
2026-03-18 17:46                                 ` Alan Stern
2026-03-18 21:38                                   ` Michal Pecio
2026-03-18 23:59                                     ` Thinh Nguyen
2026-03-19  2:07                                       ` Alan Stern
2026-03-19 23:16                                         ` Thinh Nguyen
2026-03-20  9:58                                           ` Michal Pecio [this message]
2026-03-20 16:20                                           ` Alan Stern
2026-03-20 17:49                                             ` Oliver Neukum
2026-03-21  2:14                                             ` Thinh Nguyen
2026-03-21  5:54                                               ` Michal Pecio
2026-03-21 15:58                                                 ` Alan Stern
2026-03-28 21:22                                                   ` Michal Pecio
2026-03-29  1:52                                                     ` Alan Stern
2026-03-29 16:46                                                       ` Michal Pecio
2026-03-23 10:26                                               ` Oliver Neukum
2026-03-24  1:06                                                 ` Thinh Nguyen
2026-03-24  9:28                                                   ` Oliver Neukum
2026-03-24 13:25                                                     ` Alan Stern
2026-03-25  1:44                                                     ` Thinh Nguyen
2026-03-19  1:56                                     ` Alan Stern
2026-03-19  8:40                                       ` Mathias Nyman
2026-03-19 23:34                                         ` Thinh Nguyen
2026-03-19  8:55                                       ` Michal Pecio
2026-03-19 14:24                                         ` 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=20260320105838.2eaebfe5.michal.pecio@gmail.com \
    --to=michal.pecio@gmail.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=bjorn@mork.no \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.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