USB SX lock hang with mass storage device

From: Daniel O'Connor <darius_at_dons.net.au>
Date: Mon, 14 Nov 2022 12:10:19 UTC
Hi,
I have a USB 3 HD dock I use to backup a ZFS system (with zrepl) and mostly works pretty well, however I have repeatedly had it stuck and then usbconfig hangs (I can kill it).
Pressing ctrl-t shows:
load: 15.02  cmd: usbconfig 39354 [USB config SX lock] 116.44r 0.00u 0.00s 0% 2712k
mi_switch+0xc2 sleepq_catch_signals+0x2e6 sleepq_wait_sig+0x9 _sx_xlock_hard+0x454 usbd_enum_lock_sig+0xa1 usb_ref_device+0x221 usb_open+0x100 devfs_open+0x146 VOP_OPEN_APV+0x1c vn_open_vnode+0x1b2 vn_open_cred+0x655 kern_openat+0x283 amd64_syscall+0x10c fast_syscall_common+0xf8

If I run procstat -a -k I can see the usbconfig:
And usbconfig:
39354 118526 usbconfig           -                   mi_switch sleepq_catch_signals sleepq_wait_sig _sx_xlock_hard usbd_enum_lock_sig usb_ref_device usb_open devfs_open VOP_OPEN_APV vn_open_vnode vn_open_cred kern_openat amd64_syscall fast_syscall_common

The other usb related processes look very similar to:
   15 100468 usb                 usbus0              mi_switch _cv_wait usb_process fork_exit fork_trampoline

And a thread stuck waiting to free a SIM:
  PID    TID COMM                TDNAME              KSTACK
   15 100471 usb                 usbus0              mi_switch _sleep cam_sim_free umass_detach device_detach device_delete_child usb_detach_device usb_unconfigure usb_free_device uhub_detach device_detach device_delete_child usb_detach_device usb_unconfigure usbd_set_config_index usb_bus_suspend usb_bus_reset usb_process

Which I presume is the cam_sim_free in umass_cam_detach_sim. Not sure if some more wisdom could be obtained via dtrace script or the like but I am open to suggestions :)

It is currently running FreeBSD 13.1-RELEASE and it is a Supermicro AMD system (H12SSL-I).

I can't easily update to -current but I can definitely try patches.

Thanks.

--
Daniel O'Connor
"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum