public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] xHCI: Isochronous error handling fixes and improvements
@ 2025-02-10  7:37 Michal Pecio
  2025-02-10  7:38 ` [PATCH 1/5] usb: xhci: Complete 'error mid TD' transfers when handling Missed Service Michal Pecio
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Michal Pecio @ 2025-02-10  7:37 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman; +Cc: Niklas Neronin, linux-usb, linux-kernel

These patches reduce latency of error reporting in some cases related
to 'error mid TD' and Missed Service events and sometimes fix a failure
to give back such TDs altogether until they are cancelled.

Also included are fixes for potential packet loss or memory corruption
due to an obscure race. Whether it causes problems IRL is not known and
the worst case would be hard to reproduce, but exactly for this reason
if the worst case actually happens, it could be hard to debug too.

2/5 is a cleanup which makes 3/5 implementation shorter and simpler.

The first three should be safe. The fourth should also be safe, but it
relies on HC functionality Linux never relied on before, so I placed it
towards the end in case it would need some tweaks. I tested it on all
hardware I have and it worked just fine.

The last one is perhaps the most controversial, though it should be
OK with typical "complete -> resubmit" drivers. It's the only one here
which increases latency in some severe error cases. The intent is to
avoid potentially giving back URBs not yet executed by hardware.

Michal Pecio (5):
  usb: xhci: Complete 'error mid TD' transfers when handling Missed
    Service
  usb: xhci: Clean up the TD skipping loop
  usb: xhci: Fix isochronous Ring Underrun/Overrun event handling
  usb: xhci: Expedite skipping missed isoch TDs on modern HCs
  usb: xhci: Skip only one TD on Ring Underrun/Overrun

 drivers/usb/host/xhci-ring.c | 110 +++++++++++++++++++++--------------
 1 file changed, 67 insertions(+), 43 deletions(-)

^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH 0/5] Quick and effective handle_tx_event() cleanup
@ 2024-09-10 11:12 Michal Pecio
  2024-09-10 11:14 ` [PATCH 2/5] usb: xhci: Clean up the TD skipping loop Michal Pecio
  0 siblings, 1 reply; 15+ messages in thread
From: Michal Pecio @ 2024-09-10 11:12 UTC (permalink / raw)
  To: Mathias Nyman, Niklas Neronin; +Cc: linux-usb

Hi,

I mentioned that I came up with a simple way to clean up the messy
(and buggy) event handling loop. Here are the patches.

Total line count is reduced by 26 and the sole loop remaining has no
breaks or continues and 8 lines of code. Some functionally duplicate
code is merged into one path. No functional change besides bugfixes.

Six defects identified by code review are resolved along the way.
I successfully reproduced #1, and #4 was seen in the wild on linux-usb.

1. Error mid TD followed by Missed Service is misreported as missed.
2. If EP stops on the next TD after error-mid-TD, neither TD is handled.
3. Empty list quiety ignored after short TD on hosts without the quirk.
4. Emergency stall recovery not attempted after "TRB not part of TD".
5. A race could prematurely complete a TD after an isoch ring underrun.
6. Error-mid-TD transfer on buggy HC is stuck forever if it's the last.

Debugging of TD skipping is improved - we know if/how many TDs were
skipped, in addition to whether a match was found or not. This enables
quickly catching cases when suspiciously many TDs are skipped (I have
seen a case of 150 skipped TDs, turned out to be a HW bug.)

The event handling process becomes linear - check a condition, handle
something, check for another condition, handle it, and so on. This is
much easier to reason about and to modify.

To demonstrate this point, patch 5/5 fixes a pair of stupid issues by
inserting one check, which would be duplicated 3 times before cleanup.

This series should be a good base for future work to resolve remaining
bugs. For example, the skipping loop could change from (simplified):

    while (td && !trb_in_td(td, ep_trb_dma))
to
    while (td && trb_after_td(td, ep_trb))

subject to providing a working implementation of trb_after_td(). I have
tested three implementations, some based on pre-scanning the list and
some on direct comparison, but I'm not 100% happy with any so far.

Mathias had a clever idea to use ring segment numbers for this. I tried
and it compiled and worked flawlessly on the first go, but it requires
passing all those seg pointers and total ring size around. This happens
to complicate sharing implementation with trb_in_td(), because users of
the latter don't currently provide such information. And I would like
to share implementation of these functions, as they are very similar.

Regards,
Michal

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2025-02-24  0:02 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-10  7:37 [PATCH 0/5] xHCI: Isochronous error handling fixes and improvements Michal Pecio
2025-02-10  7:38 ` [PATCH 1/5] usb: xhci: Complete 'error mid TD' transfers when handling Missed Service Michal Pecio
2025-02-10  7:39 ` [PATCH 2/5] usb: xhci: Clean up the TD skipping loop Michal Pecio
2025-02-22 12:37   ` Neronin, Niklas
2025-02-24  0:02     ` Michał Pecio
2025-02-10  7:40 ` [PATCH 3/5] usb: xhci: Fix isochronous Ring Underrun/Overrun event handling Michal Pecio
2025-02-10  7:41 ` [PATCH 4/5] usb: xhci: Expedite skipping missed isoch TDs on modern HCs Michal Pecio
2025-02-10  7:42 ` [PATCH 5/5] usb: xhci: Skip only one TD on Ring Underrun/Overrun Michal Pecio
2025-02-11 15:41   ` Mathias Nyman
2025-02-12  7:30     ` Michał Pecio
2025-02-21  1:17     ` Michał Pecio
2025-02-21  1:18       ` [PATCH v2 3/5] usb: xhci: Fix isochronous Ring Underrun/Overrun event handling Michal Pecio
2025-02-21  1:20       ` [PATCH v2 5/5] usb: xhci: Skip only one TD on Ring Underrun/Overrun Michal Pecio
2025-02-21 13:17       ` [PATCH " Mathias Nyman
  -- strict thread matches above, loose matches on Subject: below --
2024-09-10 11:12 [PATCH 0/5] Quick and effective handle_tx_event() cleanup Michal Pecio
2024-09-10 11:14 ` [PATCH 2/5] usb: xhci: Clean up the TD skipping loop Michal Pecio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox