Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

xhci: Prevent early endpoint restart when handling STALL errors.

Ensure that an endpoint halted due to device STALL is not
restarted before a Clear_Feature(ENDPOINT_HALT) request is sent to
the device.

The host side of the endpoint may otherwise be started early by the
'Set TR Deq' command completion handler which is called if dequeue
is moved past a cancelled or halted TD.

Prevent this with a new flag set for bulk and interrupt endpoints
when a Stall Error is received. Clear it in hcd->endpoint_reset()
which is called after Clear_Feature(ENDPOINT_HALT) is sent.

Also add a debug message if a class driver queues a new URB after the
STALL. Note that class driver might not be aware of the STALL
yet when it submits the URB as URBs are given back in BH.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20250306144954.3507700-13-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Mathias Nyman and committed by
Greg Kroah-Hartman
860f5d0d 9a7f4bc4

+13 -3
+5 -2
drivers/usb/host/xhci-ring.c
··· 556 556 * pointer command pending because the device can choose to start any 557 557 * stream once the endpoint is on the HW schedule. 558 558 */ 559 - if ((ep_state & EP_STOP_CMD_PENDING) || (ep_state & SET_DEQ_PENDING) || 560 - (ep_state & EP_HALTED) || (ep_state & EP_CLEARING_TT)) 559 + if (ep_state & (EP_STOP_CMD_PENDING | SET_DEQ_PENDING | EP_HALTED | 560 + EP_CLEARING_TT | EP_STALLED)) 561 561 return; 562 562 563 563 trace_xhci_ring_ep_doorbell(slot_id, DB_VALUE(ep_index, stream_id)); ··· 2555 2555 2556 2556 xhci_handle_halted_endpoint(xhci, ep, td, EP_SOFT_RESET); 2557 2557 return; 2558 + case COMP_STALL_ERROR: 2559 + ep->ep_state |= EP_STALLED; 2560 + break; 2558 2561 default: 2559 2562 /* do nothing */ 2560 2563 break;
+6
drivers/usb/host/xhci.c
··· 1604 1604 goto free_priv; 1605 1605 } 1606 1606 1607 + /* Class driver might not be aware ep halted due to async URB giveback */ 1608 + if (*ep_state & EP_STALLED) 1609 + dev_dbg(&urb->dev->dev, "URB %p queued before clearing halt\n", 1610 + urb); 1611 + 1607 1612 switch (usb_endpoint_type(&urb->ep->desc)) { 1608 1613 1609 1614 case USB_ENDPOINT_XFER_CONTROL: ··· 3207 3202 return; 3208 3203 3209 3204 ep = &vdev->eps[ep_index]; 3205 + ep->ep_state &= ~EP_STALLED; 3210 3206 3211 3207 /* Bail out if toggle is already being cleared by a endpoint reset */ 3212 3208 spin_lock_irqsave(&xhci->lock, flags);
+2 -1
drivers/usb/host/xhci.h
··· 664 664 unsigned int err_count; 665 665 unsigned int ep_state; 666 666 #define SET_DEQ_PENDING (1 << 0) 667 - #define EP_HALTED (1 << 1) /* For stall handling */ 667 + #define EP_HALTED (1 << 1) /* Halted host ep handling */ 668 668 #define EP_STOP_CMD_PENDING (1 << 2) /* For URB cancellation */ 669 669 /* Transitioning the endpoint to using streams, don't enqueue URBs */ 670 670 #define EP_GETTING_STREAMS (1 << 3) ··· 675 675 #define EP_SOFT_CLEAR_TOGGLE (1 << 7) 676 676 /* usb_hub_clear_tt_buffer is in progress */ 677 677 #define EP_CLEARING_TT (1 << 8) 678 + #define EP_STALLED (1 << 9) /* For stall handling */ 678 679 /* ---- Related to URB cancellation ---- */ 679 680 struct list_head cancelled_td_list; 680 681 struct xhci_hcd *xhci;