From 3353ebf35cb4f852362bd6a9ca603d276e10c408 Mon Sep 17 00:00:00 2001 From: osy Date: Tue, 10 Nov 2026 22:08:28 -0800 Subject: [PATCH] libusb: stop UTM freezing when a USB 3 drive is disconnected Disconnecting a USB drive that the guest uses through USB Attached SCSI (most USB 3 drives and SSD enclosures) froze UTM: the USB menu and every other part of the app stopped answering, and after UTM was ended the drive did not come back to macOS until it was replugged. When a device is released, usbredirhost cancels its transfers and waits for them to complete. libusb on macOS refused to cancel bulk stream transfers (LIBUSB_ERROR_INVALID_PARAM), and USB Attached SCSI always has one pending on its status pipe, so the wait never ended while it held the lock the main thread needs. Pick up c1c01e6593 from the UTM libusb fork (utmapp/libusb#1), which cancels bulk stream transfers the way plain bulk transfers are. The change is by giovariot, who included it in #7928. Assisted-by: Claude:claude-fable-5-2 --- patches/libusb-1.0.25.patch | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/patches/libusb-1.0.25.patch b/patches/libusb-1.0.25.patch index b184bb0ba0..351657126d 100644 --- a/patches/libusb-1.0.25.patch +++ b/patches/libusb-1.0.25.patch @@ -1042,3 +1042,47 @@ index d385a0e8..6407d7b6 100644 -- 2.41.0 +From c1c01e65937e375e025027b8692500aa95e34f0d Mon Sep 17 00:00:00 2001 +From: Giova +Date: Fri, 2 Oct 2026 17:00:00 +0200 +Subject: [PATCH] darwin: allow cancelling bulk stream transfers + +darwin_cancel_transfer() routes bulk, interrupt and isochronous +transfers to darwin_abort_transfers(), which already knows how to abort +a single bulk stream with AbortStreamsPipe(). LIBUSB_TRANSFER_TYPE_BULK_STREAM +was missing from the switch, so libusb_cancel_transfer() returned +LIBUSB_ERROR_INVALID_PARAM for every stream transfer. + +USB Attached SCSI uses the command tag as the bulk stream id, so a +redirection host cancels stream transfers constantly. When the cancel is +not applied the transfer stays in flight on the host controller and the +guest's command never completes, which surfaces as a 30 second SCSI +timeout and a device reset in the guest. + +A caller that cancels its transfers and waits for them to complete, as +usbredirhost does when it releases a device, waits forever while a +stream transfer is pending, and USB Attached SCSI keeps one pending on +its status pipe. + +Assisted-by: OpenCode:deepseek-v4.1-flash +Assisted-by: Claude:claude-fable-5-2 +--- + libusb/os/darwin_usb.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c +index 6407d7b6..0a672029 100644 +--- a/libusb/os/darwin_usb.c ++++ b/libusb/os/darwin_usb.c +@@ -2329,6 +2329,7 @@ static int darwin_cancel_transfer(struct usbi_transfer *itransfer) { + case LIBUSB_TRANSFER_TYPE_BULK: + case LIBUSB_TRANSFER_TYPE_INTERRUPT: + case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS: ++ case LIBUSB_TRANSFER_TYPE_BULK_STREAM: + return darwin_abort_transfers (itransfer); + default: + usbi_err (TRANSFER_CTX(transfer), "unknown endpoint type %d", transfer->type); +-- +2.54.0 (Apple Git-157) + +