linux/drivers/usb
Michal Pecio 484c3bab2d usb: xhci: Fix TD invalidation under pending Set TR Dequeue
xhci_invalidate_cancelled_tds() may not work correctly if the hardware
is modifying endpoint or stream contexts at the same time by executing
a Set TR Dequeue command. And even if it worked, it would be unable to
queue Set TR Dequeue for the next stream, failing to clear xHC cache.

On stream endpoints, a chain of Set TR Dequeue commands may take some
time to execute and we may want to cancel more TDs during this time.
Currently this leads to Stop Endpoint completion handler calling this
function without testing for SET_DEQ_PENDING, which will trigger the
aforementioned problems when it happens.

On all endpoints, a halt condition causes Reset Endpoint to be queued
and an error status given to the class driver, which may unlink more
URBs in response. Stop Endpoint is queued and its handler may execute
concurrently with Set TR Dequeue queued by Reset Endpoint handler.

(Reset Endpoint handler calls this function too, but there seems to
be no possibility of it running concurrently with Set TR Dequeue).

Fix xhci_invalidate_cancelled_tds() to work correctly under a pending
Set TR Dequeue. Bail out of the function when SET_DEQ_PENDING is set,
then make the completion handler call the function again and also call
xhci_giveback_invalidated_tds(), which needs to be called next.

This seems to fix another potential bug, where the handler would call
xhci_invalidate_cancelled_tds(), which may clear some deferred TDs if
a sanity check fails, and the TDs wouldn't be given back promptly.

Said sanity check seems to be wrong and prone to false positives when
the endpoint halts, but fixing it is beyond the scope of this change,
besides ensuring that cleared TDs are given back properly.

Fixes: 5ceac4402f ("xhci: Handle TD clearing for multiple streams case")
CC: stable@vger.kernel.org
Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20241106101459.775897-33-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-11-06 13:26:16 +01:00
..
atm Merge 6.12-rc3 into usb-next 2024-10-14 08:03:44 +02:00
c67x00 usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
cdns3 usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
chipidea usb: Use (of|device)_property_present() for non-boolean properties 2024-11-05 13:29:26 +01:00
class move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
common usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
core Merge v6.12-rc6 into usb-next 2024-11-05 09:56:08 +01:00
dwc2 Merge v6.12-rc6 into usb-next 2024-11-05 09:56:08 +01:00
dwc3 usb: Use (of|device)_property_present() for non-boolean properties 2024-11-05 13:29:26 +01:00
early
fotg210 Merge 6.12-rc3 into usb-next 2024-10-14 08:03:44 +02:00
gadget Merge 6.12-rc4 into usb-next 2024-10-21 08:53:43 +02:00
host usb: xhci: Fix TD invalidation under pending Set TR Dequeue 2024-11-06 13:26:16 +01:00
image scsi: core: Add a dma_alignment field to the host and host template 2024-04-11 21:37:48 -04:00
isp1760 Merge 6.12-rc3 into usb-next 2024-10-14 08:03:44 +02:00
misc Merge 6.12-rc3 into usb-next 2024-10-14 08:03:44 +02:00
mon [tree-wide] finally take no_llseek out 2024-09-27 08:18:43 -07:00
mtu3 usb: Use (of|device)_property_present() for non-boolean properties 2024-11-05 13:29:26 +01:00
musb Merge 6.12-rc3 into usb-next 2024-10-14 08:03:44 +02:00
phy usb: Use (of|device)_property_present() for non-boolean properties 2024-11-05 13:29:26 +01:00
renesas_usbhs usb: Use (of|device)_property_present() for non-boolean properties 2024-11-05 13:29:26 +01:00
roles usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
serial USB: serial: option: add Telit FN920C04 MBIM compositions 2024-10-17 16:38:02 +02:00
storage usb: storage: use US_BULK_FLAG_OUT instead of constant values 2024-10-29 04:33:25 +01:00
typec Merge v6.12-rc6 into usb-next 2024-11-05 09:56:08 +01:00
usbip usb: Switch back to struct platform_driver::remove() 2024-10-04 15:13:03 +02:00
Kconfig usb: pci-quirks: handle HAS_IOPORT dependency for AMD quirk 2023-10-02 16:19:12 +02:00
Makefile USB: xen-hcd: Traverse host/ when CONFIG_USB_XEN_HCD is selected 2024-06-04 15:33:38 +02:00
usb-skeleton.c