I am doing research with Linux Power Management interactions with USB devices. Which is why I would like to be able to wake a qemu vm from suspend with a passed through USB device. I have been able to pass through the usb device from the launch command and enable the wakeup file with a udev rule for the /sys/bus/usb/devices/usb#/power/wakeup
file. But the issue is that the actual device’s wakeup files are missing (/sys/bus/usb/devices/#-#/power/wakeup
). These files are present on my linux host where the keyboard wakes the host from suspend just fine. I know that these files come from the gadget’s bmAttribute
byte having the correct bits set to inform the host that it can perform remote wakeup. Since these files originate from that low of a level, is this even a problem with my qemu configuration or is this something that is even supported by qemu’s usb passthrough?
I have also been able to suspend the vm and wake it from the qemu shell using system_wake so I know that the vm wakes properly. I have also seen old posts about using evdev to pass through usb devices, but this seems to be old and not the best method.
Here are the details of my configuration:
Launch Script:
qemu-system-x86_64
-m 2G
-smp 2
-kernel /home/darrion/linux-6.10-rc4/arch/x86/boot/bzImage
-append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0"
-drive file=qemu_image/bookworm.img,format=raw
-net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22
-net nic,model=e1000
-monitor unix:qemu-monitor-socket,server,nowait
-enable-kvm
-cpu host
-usb
-device nec-usb-xhci
-device usb-host,hostbus=3,hostaddr=5
-nographic
-D ./log.txt
-pidfile vm.pid
2>&1 | tee vm.log
Debian 12 Image from: https://github.com/google/syzkaller/blob/master/tools/create-image.sh
Qemu:
Tried using version 6.2 from apt and 9.0.90 from source
Linux Kernel:
Tried 6.10, 6.10-rc4, 6.6.43
Config: https://github.com/google/syzkaller/blob/master/dashboard/config/linux/upstream-usb.config (with CONFIG_KCOV_INSTRUMENT_ALL
turned off since this breaks suspend/resume)
Also tried the standard kvm_guest.config generated config
Edit: I was able to find that the remote_wakeup bit was being suppressed in the qemu source code by default (https://github.com/qemu/qemu/blob/master/hw/usb/host-libusb.c#L1780) changing this initialization to false made the device’s wakeup files reappear. Unfortunately the external device still does not wake the vm.
Testing with the GUI (was using -nographic before) gave interesting results. Any usb device connected to the computer that is not the one specified by the passthrough command will wake up the vm (but only in GUI mode). Also if the device specified to be passed through to the vm is unplugged and then plugged back in it is then able to wake up the vm. The passed through device must be a valid device though. No idea why this is the case as it makes no sense.