Hi! The more specific use case that does not work without this (not realized until after writing issue/commit) is devices that need to switch modes, or hot plugging new items to the specific physical port. In these scenarios the original device disconnects and later new one connects to the port. Detection of the new device does not work in any device combination without this commit.
Timo On Mon, 20 Jul 2026, 14.39 Gerd Hoffmann, <[email protected]> wrote: > On Mon, Jul 20, 2026 at 10:12:27AM +0200, Thomas Huth wrote: > > > > Hi Gerd, > > > > since you originally wrote commit e058fa2dd599, could you maybe have a > look > > at this patch? > > Not sure what is going on here, I'm confident I had tested this back > then. Maybe behavior depends on the kind of usb device or libusb > version or host os or a combination of those. If disconnect detection > does not work reliable (as written in the gitlab issue) turning > autoscan back on should indeed fix it and it should also not cause > other problems. > > Commit message should be a bit more verbose so it is not needed to > visit gitlab for additional info. With that: > > Acked-by: Gerd Hoffmann <[email protected]> > > take care, > Gerd > > > > > Thanks, > > Thomas > > > > > > On 12/09/2025 13.14, Timo Teräs wrote: > > > This is partial revert of commit e058fa2dd599. > > > > > > The portion to immediately validate the device is kept, but this > > > adds and enables again the autoscan functionality. This is needed > > > to detect and relay USB device disconnect event to the guest. > > > > > > Fixes: e058fa2dd599 ("usb-host: add special case for bus+addr") > > > Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3111 > > > Signed-off-by: Timo Teräs <[email protected]> > > > --- > > > hw/usb/host-libusb.c | 14 ++++---------- > > > 1 file changed, 4 insertions(+), 10 deletions(-) > > > > > > diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c > > > index > b74670ae25696b5252f0d034cb9b759e338a050f..f0baf6b2f2d12fbf8feb5b788b46d3187028df58 > 100644 > > > --- a/hw/usb/host-libusb.c > > > +++ b/hw/usb/host-libusb.c > > > @@ -90,7 +90,6 @@ struct USBHostDevice { > > > uint32_t iso_urb_frames; > > > uint32_t options; > > > uint32_t loglevel; > > > - bool needs_autoscan; > > > bool allow_one_guest_reset; > > > bool allow_all_guest_resets; > > > bool suppress_remote_wake; > > > @@ -1211,7 +1210,6 @@ static void usb_host_realize(USBDevice *udev, > Error **errp) > > > #if LIBUSB_API_VERSION >= 0x01000107 && !defined(CONFIG_WIN32) > > > if (s->hostdevice) { > > > int fd; > > > - s->needs_autoscan = false; > > > fd = qemu_open(s->hostdevice, O_RDWR, errp); > > > if (fd < 0) { > > > return; > > > @@ -1227,7 +1225,6 @@ static void usb_host_realize(USBDevice *udev, > Error **errp) > > > !s->match.vendor_id && > > > !s->match.product_id && > > > !s->match.port) { > > > - s->needs_autoscan = false; > > > ldev = usb_host_find_ref(s->match.bus_num, > > > s->match.addr); > > > if (!ldev) { > > > @@ -1242,14 +1239,13 @@ static void usb_host_realize(USBDevice *udev, > Error **errp) > > > s->match.bus_num, s->match.addr); > > > return; > > > } > > > - } else { > > > - s->needs_autoscan = true; > > > - QTAILQ_INSERT_TAIL(&hostdevs, s, next); > > > - usb_host_auto_check(NULL); > > > } > > > s->exit.notify = usb_host_exit_notifier; > > > qemu_add_exit_notifier(&s->exit); > > > + > > > + QTAILQ_INSERT_TAIL(&hostdevs, s, next); > > > + usb_host_auto_check(NULL); > > > } > > > static void usb_host_instance_init(Object *obj) > > > @@ -1267,9 +1263,7 @@ static void usb_host_unrealize(USBDevice *udev) > > > USBHostDevice *s = USB_HOST_DEVICE(udev); > > > qemu_remove_exit_notifier(&s->exit); > > > - if (s->needs_autoscan) { > > > - QTAILQ_REMOVE(&hostdevs, s, next); > > > - } > > > + QTAILQ_REMOVE(&hostdevs, s, next); > > > usb_host_close(s); > > > } > > > > > > --- > > > base-commit: 190d5d7fd725ff754f94e8e0cbfb69f279c82b5d > > > change-id: 20250912-usbhost-disconnect-192ecaa8fc3e > > > > > > Best regards, > > > > -- > >
