1

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.

3
  • Dang. I didn't look at the counts of followers on your tags until just now. Add linux and change suspend to a computer language your used to. Hopefully python. Commented Aug 16, 2024 at 13:23
  • If you can construct a mcve , and you delete here and repost to Stack Overflow I will upvote and provide a bounty there (after 48 hrs). (I find [qemu] stuff very interesting). A small set of c code would be ideal. Note there are more than 2X more Q/A with tag [qemu] on StackOverflow. (Yes, this problem does seem linuxy, and I get why you posted here first, but if you have code, then it is a programming problem. You'll likely get more people looking at this StackOverflow (although some duplicate readers too). Commented Aug 18, 2024 at 2:13
  • Thanks for the suggestions. I could provide steps on how to recreate my issue but there would not be any code since it is just qemu configuration/setup. I would consider reposting on stack overflow if I am able to locate some issue in the qemu source code that may be responsible. But I am not sure where the issue in the source code is or if there is something else. I have also tried reaching out the qemu mailing list but haven't heard anything. I will try posting an issue to their gitlab since that seems to be more active. Will update here if I learn anything. Commented Aug 19, 2024 at 21:03

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.