Skip to contentSkip to conversation

usb-hid: activate usb tablet / mouse after migration.

PATCH In review Gerd Hoffmann 3 participants 7 messages Oct 12, 2011 – Feb 21, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb-hid: activate usb tablet / mouse after migration.

qemu uses the ps/2 mouse by default. The usb tablet (or mouse) is activated as soon as qemu sees some guest activity on the device, i.e. polling for HID events. That used to work fine for both fresh boot and migration.

Remote wakeup support changed the picture though: There will be no polling after migration in case the guest suspended the usb bus, waiting for wakeup events. Result is that the ps/2 mouse stays active.

Fix this by activating the usb tablet / mouse in post_load() in case the guest enabled remote wakeup.

---
 hw/usb-hid.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
hw/usb-hid.c +11 -0
index 7c564b6..997f828 100644
@@ -520,10 +520,21 @@ static int usb_keyboard_initfn(USBDevice *dev)
     return usb_hid_initfn(dev, HID_KEYBOARD);
 }
 
+static int usb_ptr_post_load(void *opaque, int version_id)
+{
+    USBHIDState *s = opaque;
+
+    if (s->dev.remote_wakeup) {
+        hid_pointer_activate(&s->hid);
+    }
+    return 0;
+}
+
 static const VMStateDescription vmstate_usb_ptr = {
     .name = "usb-ptr",
     .version_id = 1,
     .minimum_version_id = 1,
+    .post_load = usb_ptr_post_load,
     .fields = (VMStateField []) {
         VMSTATE_USB_DEVICE(dev, USBHIDState),
         VMSTATE_HID_POINTER_DEVICE(hid, USBHIDState),
Signature · 1 line
1.7.1
#1 lore raw
Quoted 4 lines · Gerd Hoffmann

qemu uses the ps/2 mouse by default.  The usb tablet (or mouse) is activated as soon as qemu sees some guest activity on the device, i.e. polling for HID events.  That used to work fine for both fresh boot and migration.

It does not fix usb tablet/mouse when starting vm directly from snapshot.

Quoted 44 lines

Remote wakeup support changed the picture though: There will be no polling after migration in case the guest suspended the usb bus, waiting for wakeup events.  Result is that the ps/2 mouse stays active.

Fix this by activating the usb tablet / mouse in post_load() in case the guest enabled remote wakeup.

---
 hw/usb-hid.c |   11 +++++++++++

 1 files changed, 11 insertions(+), 0 deletions(-)
hw/usb-hid.c +11 -1
index 7c564b6..997f828 100644
@@ -520,10 +520,21 @@ static int usb_keyboard_initfn(USBDevice *dev)
     return usb_hid_initfn(dev, HID_KEYBOARD);
  }
 
+static int usb_ptr_post_load(void *opaque, int version_id)
+{
+    USBHIDState *s = opaque;
+
+    if (s->dev.remote_wakeup) {
+        hid_pointer_activate(&s->hid);
+    }
+    return 0;
+}
+
  static const VMStateDescription vmstate_usb_ptr = {
     .name = "usb-ptr",
     .version_id = 1,
     .minimum_version_id = 1,
+    .post_load = usb_ptr_post_load,
     .fields = (VMStateField []) {
         VMSTATE_USB_DEVICE(dev, USBHIDState),
         VMSTATE_HID_POINTER_DEVICE(hid, USBHIDState),
--

1.7.1

#2 lore raw
Quoted 6 lines · TeLeMan
Quoted 4 lines · Gerd Hoffmann

qemu uses the ps/2 mouse by default. The usb tablet (or mouse) is activated as soon as qemu sees some guest activity on the device, i.e. polling for HID events. That used to work fine for both fresh boot and migration.

It does not fix usb tablet/mouse when starting vm directly from snapshot.

What does "info mice" print before/after snapshotting? Which guest? WinXP IIRC?

cheers,
Gerd

#3 lore raw
Quoted 9 lines · Gerd Hoffmann
Quoted 8 lines · TeLeMan
Quoted 5 lines · Gerd Hoffmann

qemu uses the ps/2 mouse by default.  The usb tablet (or mouse) is activated as soon as qemu sees some guest activity on the device, i.e. polling for HID events.  That used to work fine for both fresh boot and migration.

Quoted 4 lines
Quoted 1 line

It does not fix usb tablet/mouse when starting vm directly from snapshot.

What does "info mice" print before/after snapshotting? Which guest?  WinXP IIRC?

Yes, the guest is WinXP.

Original:
* Mouse #1: QEMU HID Tablet (absolute)
Mouse #0: QEMU PS/2 Mouse

Start from the snapshot:
* Mouse #0: QEMU PS/2 Mouse
Mouse #1: QEMU HID Tablet (absolute)

The active mouse device is not be saved into the snapshot.

Quoted 4 lines

cheers,
 Gerd

#4 lore raw

Hi,

Quoted 9 lines

Original:
* Mouse #1: QEMU HID Tablet (absolute)
Mouse #0: QEMU PS/2 Mouse

Start from the snapshot:
* Mouse #0: QEMU PS/2 Mouse
Mouse #1: QEMU HID Tablet (absolute)

The active mouse device is not be saved into the snapshot.

That shouldn't hurt though. When the guest polls the tablet the first time after starting from snapshot should activate it. In case it the guest doesn't pull because the guest activated remote wakeup and suspended the device we now (with the patch) activate it too.

It also doesn't reproduce here. /me wonders what is going on ...

What does 'info usb' print before and after snapshotting? Can you also post the full qemu command line?

thanks,
Gerd

#5 lore raw
Quoted 16 lines · Gerd Hoffmann
   Hi,
Quoted 9 lines

Original:
* Mouse #1: QEMU HID Tablet (absolute)
Mouse #0: QEMU PS/2 Mouse

Start from the snapshot:
* Mouse #0: QEMU PS/2 Mouse
Mouse #1: QEMU HID Tablet (absolute)

The active mouse device is not be saved into the snapshot.

That shouldn't hurt though. When the guest polls the tablet the first time after starting from snapshot should activate it. In case it the guest doesn't pull because the guest activated remote wakeup and suspended the device we now (with the patch) activate it too.

Quoted 4 lines

It also doesn't reproduce here. /me wonders what is going on ...

What does 'info usb' print before and after snapshotting? Can you also post the full qemu command line?

I see the same issue here, but not in my case it happens when migrating a VM.

Before migration:

(qemu) info usb
info usb
Device 0.1, Port 1, Speed 12 Mb/s, Product QEMU USB Tablet
(qemu) info mice
info mice
Mouse #0: QEMU PS/2 Mouse
* Mouse #1: QEMU HID Tablet (absolute)

After migration:
(qemu) info usb
info usb
Device 0.1, Port 1, Speed 12 Mb/s, Product QEMU USB Tablet
(qemu) info mice
info mice
Mouse #1: QEMU HID Tablet (absolute)
* Mouse #0: QEMU PS/2 Mouse

It seems the USB Tablet is not activated again. I can get it working by manually aktivating and deactivating the USB Hub in Windows Device Manager.

The guest is Windows7 32-bit.

cmdline:
/usr/bin/qemu-kvm-1.0 -net tap,vlan=141,script=no,downscript=no,ifname=tap0 -net nic,vlan=141,model=e1000,macaddr=52:54:00:ff:00:d3 -drive format=host_device,file=/dev/mapper/iqn.2001-05.com.equallogic:0-8a0906-eeef4e007-a8a9f3818674f2fc-lieven-windows7-r80788,if=virtio,cache=writethrough,aio=native -m 2048 -monitor tcp:0:4001,server,nowait -vnc :1 -name lieven-win7 -boot order=dc,menu=off -k de -pidfile /var/run/qemu/vm-187.pid -rtc base=localtime -vga std -usb -usbdevice tablet -cpu host

Thanks,
Peter

Quoted 4 lines

thanks,
Gerd

#6 lore raw
In reply to TeLeMan
Quoted 16 lines · TeLeMan
Quoted 9 lines · Gerd Hoffmann
Quoted 6 lines · TeLeMan
Quoted 4 lines · Gerd Hoffmann

qemu uses the ps/2 mouse by default. The usb tablet (or mouse) is activated as soon as qemu sees some guest activity on the device, i.e. polling for HID events. That used to work fine for both fresh boot and migration.

It does not fix usb tablet/mouse when starting vm directly from snapshot.

What does "info mice" print before/after snapshotting? Which guest? WinXP IIRC?

Yes, the guest is WinXP.

Original:
* Mouse #1: QEMU HID Tablet (absolute)
Mouse #0: QEMU PS/2 Mouse

Quoted 5 lines

Start from the snapshot:
* Mouse #0: QEMU PS/2 Mouse
Mouse #1: QEMU HID Tablet (absolute)

The active mouse device is not be saved into the snapshot.

it seems that the active mouse event receiver is messed up up after loading a vm.

if you issue a 'mouse_set 1' in the qemu monitor the tablet should work again.

can someone who is more familiar with the loadvm code check if the devices are just added in wrong order?

thanks
peter