This series fixes a hang in the usb-storage device that triggers when the data
phase of a READ command fits into a single bulk-IN transfer and the CSW is
queued behind the data packet before the disk read completes.

In that scenario the SCSI request completes synchronously from inside
usb_msd_copy_data(), so usb_packet_complete() processes the CSW packet queued
behind the data transfer while usb_msd_command_complete() is still running,
before it clears s->req. The device takes the "still in flight" branch, parks
the CSW again with USB_RET_ASYNC, and nothing ever completes it: the device
deadlocks.

The fix moves the s->req release to the top of usb_msd_command_complete().

Patch 2, from Junjie Cao, adds an xHCI qtest that reproduces the same
scheduling (data TD + CSW TD on the bulk IN ring, single doorbell, read held in
flight with a blkdebug breakpoint) and reproduces the hang without the fix.

Fixes: db4be873d312 ("usb: maintain async packet list per endpoint")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4658
Signed-off-by: Tommaso Califano <[email protected]>

Junjie Cao (1):
  tests/qtest/usb-hcd-xhci: test a CSW TD queued behind the data TD

Tommaso Califano (1):
  hw/usb/dev-storage: fix hang with CSW queued behind the data TD

 hw/usb/dev-storage.c            | 10 +++-
 tests/qtest/usb-hcd-xhci-test.c | 89 +++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 2 deletions(-)

-- 
2.56.0


Reply via email to