diff mbox

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

Message ID 1318419034-15287-1-git-send-email-kraxel@redhat.com
State New
Headers show

Commit Message

Gerd Hoffmann Oct. 12, 2011, 11:30 a.m. UTC
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.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb-hid.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

Comments

TeLeMan Oct. 13, 2011, 2:09 a.m. UTC | #1
On Wed, Oct 12, 2011 at 19:30, Gerd Hoffmann <kraxel@redhat.com> wrote:
> 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.

> 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.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/usb-hid.c |   11 +++++++++++
>  1 files changed, 11 insertions(+), 0 deletions(-)
>
> diff --git a/hw/usb-hid.c b/hw/usb-hid.c
> index 7c564b6..997f828 100644
> --- a/hw/usb-hid.c
> +++ b/hw/usb-hid.c
> @@ -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
>
>
>
Gerd Hoffmann Oct. 13, 2011, 10:48 a.m. UTC | #2
On 10/13/11 04:09, TeLeMan wrote:
> On Wed, Oct 12, 2011 at 19:30, Gerd Hoffmann<kraxel@redhat.com>  wrote:
>> 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
TeLeMan Oct. 16, 2011, 8:54 a.m. UTC | #3
On Thu, Oct 13, 2011 at 18:48, Gerd Hoffmann <kraxel@redhat.com> wrote:
> On 10/13/11 04:09, TeLeMan wrote:
>>
>> On Wed, Oct 12, 2011 at 19:30, Gerd Hoffmann<kraxel@redhat.com>  wrote:
>>>
>>> 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

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.

> cheers,
>  Gerd
>
>
Gerd Hoffmann Oct. 21, 2011, 9:22 a.m. UTC | #4
Hi,

> 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
Peter Lieven Feb. 20, 2012, 10:42 a.m. UTC | #5
On 21.10.2011 11:22, Gerd Hoffmann wrote:
>    Hi,
>
>> 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?
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
> thanks,
>    Gerd
>
>
Peter Lieven Feb. 21, 2012, 4:25 p.m. UTC | #6
On 16.10.2011 10:54, TeLeMan wrote:
> On Thu, Oct 13, 2011 at 18:48, Gerd Hoffmann<kraxel@redhat.com>  wrote:
>> On 10/13/11 04:09, TeLeMan wrote:
>>> On Wed, Oct 12, 2011 at 19:30, Gerd Hoffmann<kraxel@redhat.com>    wrote:
>>>> 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
>
> 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
diff mbox

Patch

diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 7c564b6..997f828 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -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),