You are not logged in.

#1 2015-04-29 18:03:25

fkoehler
Member
Registered: 2015-04-17
Posts: 7

[QEMU/KVM] Use KVM switch to switch mouse/kayboard between host and VM

I finally have my QEMU/KVM setup running and working as I want it, except for one thing. I have a KVM switch (a piece of hardware not the hypervisor wink) to switch audio and video. It also offers the feature to switch mouse/keyboard between to Computers. Here is the relevant excerpt from my lsusb:

...
Bus 002 Device 048: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 002 Device 047: ID 0557:8021 ATEN International Co., Ltd CS1764A [CubiQ DVI KVMP Switch]
Bus 002 Device 046: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 002 Device 045: ID 0557:8021 ATEN International Co., Ltd CS1764A [CubiQ DVI KVMP Switch]
...

The device named "Logitech, Inc. Unifying Receiver" is the dongle for my mouse and keyboard. The first problem is that both devices (in both states of the switch they both appear) have the same device id 046d:c52b. This can be solved by telling qemu to identify the device by #bus.#device instead of the id. The problem is that after each switching the device number increases. This makes sense as for the system the switching process is as if the device was unplugged and plugged in in a different usb port. Therefore the device would probably be disconnected from the VM when it was assigned on the VM's startup (is there a way to add usb devices on the fly to a vm without typing an add_usb command in the qemu shell). Do you have any ideas what I could do?

EDIT: Just found about QMP. Would it be possible to save an initial condition (mouse/keyboard is on host) and fetch new devices busses after switching (udev?) and switch the saved sate? If the state is now "m/k should be on the vm" one could send qemu an adequate add command.

EDIT2: I found out that my mainboard's usb is organized using 3 usb controllers (2x2.0, 1x3.0 each with 4 ports). I want to pass one of those PCI controllers to the VM but all I get is a black screen.

EDIT3: I tried the other usb controller and it worked. Well, kind of. I moved the mouse in a circle and made a right click. Than I was not able to use the mouse or the keyboard anymore. Should I consider buying a PCI USB2.0 controller as that might be easier to forward?

Last edited by fkoehler (2015-04-29 23:50:07)

Offline

#2 2015-04-30 15:58:58

noctlos
Member
Registered: 2013-08-26
Posts: 36

Re: [QEMU/KVM] Use KVM switch to switch mouse/kayboard between host and VM

This article has someinteresting information in the comments. You don't have to use a kvm switch neccessarily. I for one prefer a software solution.

Okay, so to make things clear: I do not switch keyboard/mouse. I keep them shared between both OS, using Synergy. The host OS runs a web server, and the guest OS runs a client – they exchange mouse position information, so that at any time only one of them receives ‘clicks’. This is great for both multi- and single-monitor setups.
Another story is that I have two video outputs connected to a single monitor, and I would like to switch between them without using the buttons on the monitor itself. For this, I use the I2C that is embedded within HDMI or DP.
Almost all monitors support DDC, but there are scarce apps that can make us of it. There is DDCcontrol for linux, but it is completely outdated, and failed to work with my particular monitor. So I ended up getting to know the VESA DDC standard, reading the source of that tool and several similar ones, and created a simple C program (source) that works in case of my setup. Most likely it will not work elsewhere, but it should give you a nice starting point for communicating with the monitor. The fragile spots are line 41 – you may need to change the i2c bus number the the one correct for your system, and you may need to prepare other data to send to the monitor (68 and 71) if you want to switch between other outputs than I do. Refer to the standard in order to prepare them.

As for how to change his source code to help you, I am not of much help right now as I do not know the DDC protocol. Hope that helps.

Last edited by noctlos (2015-04-30 16:01:45)

Offline

#3 2015-04-30 17:40:28

fkoehler
Member
Registered: 2015-04-17
Posts: 7

Re: [QEMU/KVM] Use KVM switch to switch mouse/kayboard between host and VM

Thanks for the article. I prefer a hardware solution, as I already had this kvm switch laying around. It is nice as it switches between two dvi ports, two audio ports (mic and speaker each) and seperate usb ports for mouse/keyboard. I will probably end up buying a pci usb controller (9€ ~ 10$) and just forward that (as my experience with pci forwarding has been so positive. I think the problem is that I tried to use one of the controllers on the mainboard itself (I read an article where one guy succeeded doing this but it is not working out for me).

Offline

#4 2016-02-26 21:45:00

tanasis
Member
From: Delft
Registered: 2015-03-20
Posts: 6

Re: [QEMU/KVM] Use KVM switch to switch mouse/kayboard between host and VM

Any luck with this?

Offline

Board footer

Powered by FluxBB