Bug 1379603 - RFE: support hotplugging virtio input devices
Summary: RFE: support hotplugging virtio input devices
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.3
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Ján Tomko
QA Contact: jiyan
URL:
Whiteboard:
Depends On: 1509866
Blocks: 1473046
TreeView+ depends on / blocked
 
Reported: 2016-09-27 08:22 UTC by Fangge Jin
Modified: 2018-04-10 10:39 UTC (History)
9 users (show)

Fixed In Version: libvirt-3.9.0-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-04-10 10:39:40 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2018:0704 0 normal SHIPPED_LIVE libvirt bug fix and enhancement update 2018-04-10 15:57:35 UTC

Description Fangge Jin 2016-09-27 08:22:10 UTC
Description of problem:
Virtio input devices are introduced since RHEL7.3

qemu-kvm-rhev supports hotplugging virtio input devices, libvirt should support this too.

Version-Release number of selected component (if applicable):
libvirt-2.0.0-10.el7.x86_64
qemu-kvm-rhev-2.6.0-26.el7.x86_64

Steps to Reproduce:
1.Prepare a running guest:
# virsh start rhel7

2.Prepare a file as below, take virtio mouse as example:
# cat /tmp/input.xml 
    <input type='mouse' bus='virtio'/>

3.Hotplug input device to guest:
# virsh attach-device rhel7 /tmp/input.xml
error: Failed to attach device from /tmp/input.xml
error: Operation not supported: live attach of device 'input' is not supported

Coldplugging is not supported too:
# virsh attach-device rhel7 /tmp/input.xml --config
error: Failed to attach device from /tmp/input.xml
error: Operation not supported: persistent attach of device 'input' is not supported

Comment 1 Fangge Jin 2016-09-27 08:24:09 UTC
Hotplug/hotunplug virtio input devices by qemu monitor command:
1) add/delete a virtio mouse
# virsh qemu-monitor-command rhel7 '{"execute":"device_add","arguments":{"driver":"virtio-mouse-pci","id":"input1","bus":"pci.0","addr":"0xa"}}'
{"return":{},"id":"libvirt-19"}

check the current mouse
# virsh qemu-monitor-command rhel7 --hmp info mice
  Mouse #2: QEMU PS/2 Mouse
* Mouse #3: QEMU Virtio Mouse

delete the virtio mouse
# virsh qemu-monitor-command rhel7 '{"execute":"device_del","arguments":{"id":"input1"}}'{"return":{},"id":"libvirt-22"}

check the current mouse again
# virsh qemu-monitor-command rhel7 --hmp info mice
* Mouse #2: QEMU PS/2 Mouse

2) add/delete a virtio keyboard
# virsh qemu-monitor-command rhel7 '{"execute":"device_add","arguments":{"driver":"virtio-keyboard-pci","id":"input1","bus":"pci.0","addr":"0xa"}}'
{"return":{},"id":"libvirt-25"}

# virsh qemu-monitor-command rhel7 '{"execute":"device_del","arguments":{"id":"input1"}}'
{"return":{},"id":"libvirt-26"}

3) add/delete a virtio tablet
# virsh qemu-monitor-command rhel7 '{"execute":"device_add","arguments":{"driver":"virtio-tablet-pci","id":"input1","bus":"pci.0","addr":"0xa"}}'
{"return":{},"id":"libvirt-27"}

# virsh qemu-monitor-command rhel7 '{"execute":"device_del","arguments":{"id":"input1"}}'{"return":{},"id":"libvirt-28"}

4) add/delete a host input device to/from guest(but I run into permission issue)
# chown qemu:qemu /dev/input/event3
# chcon system_u:object_r:svirt_image_t:s0 /dev/input/event3

# virsh qemu-monitor-command rhel7 '{"execute":"device_add","arguments":{"driver":"virtio-input-host-pci","id":"input2","evdev":"/dev/input/event3","bus":"pci.0","addr":"0xb"}}'
{"id":"libvirt-23","error":{"class":"GenericError","desc":"Could not open '/dev/input/event3': Operation not permitted"}}

Comment 2 Ján Tomko 2017-10-17 15:05:11 UTC
Upstream patches:
https://www.redhat.com/archives/libvir-list/2017-October/msg00684.html

Comment 3 Ján Tomko 2017-10-20 14:21:11 UTC
Pushed upstream as:
commit bc9ffafcc776fd84bb0bdaa7e621572e48e81841
Author:     Ján Tomko <jtomko@redhat.com>
CommitDate: 2017-10-19 14:43:22 +0200

    qemu: implement input device hotplug
    
    For both virtio input devices and USB input devices.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1379603

commit 67486bb2957ff3ac266df6844a9b3d960f410555
Author:     Ján Tomko <jtomko@redhat.com>
CommitDate: 2017-10-19 14:43:22 +0200

    qemu: implement input device hotunplug
    
    Allow unplugging USB and virtio USB devices.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1379603

git describe: v3.8.0-185-g67486bb29

Comment 5 Han Han 2017-11-08 07:50:46 UTC
Test hot-plug/hot-unplug on input devices on libvirt-3.9.0-1.el7.x86_64 qemu-kvm-rhev-2.10.0-4.el7.x86_64
Since virtio-input-passthrough device is not supported now. Test keyboard/mouse/tablet device on usb or virtio bus.
1. Prepare devices xml:
/tmp/usb-keyboard.xml:
<input type='keyboard' bus='usb'/>

/tmp/usb-mouse.xml:
<input type='mouse' bus='usb'/>

/tmp/usb-tablet.xml:
<input type='tablet' bus='usb'/>

/tmp/virtio-keyboard.xml:
<input type='keyboard' bus='virtio'/>

/tmp/virtio-mouse.xml:
<input type='mouse' bus='virtio'/>

/tmp/virtio-tablet.xml:
<input type='tablet' bus='virtio'/>

2. hot-plug/hot-unplug on input devices
# virsh list      
 Id    Name                           State
----------------------------------------------------
 4     V                              running

```
#!/bin/bash
for i in /tmp/virtio-*.xml;do
    virsh attach-device V $i
done
for i in /tmp/usb-*.xml;do
    virsh attach-device V $i
done

for i in /tmp/virtio-*.xml;do
    virsh detach-device V $i
done
for i in /tmp/usb-*.xml;do
    virsh detach-device V $i
done
```
Device attached successfully

Device attached successfully

Device attached successfully

Device attached successfully

Device attached successfully

Device attached successfully

Device detached successfully

Device detached successfully

Device detached successfully

Device detached successfully

Device detached successfully

Device detached successfully



hot-plug/hot-unplug works well.

Comment 6 jiyan 2017-12-06 08:28:54 UTC
Test components' version
qemu-kvm-rhev-2.10.0-11.el7.x86_64
kernel-3.10.0-799.el7.x86_64
libvirt-3.9.0-5.el7.x86_64


Test env
Physical host with USB keyboard and mouse plugged in and the event info is as following:
# cat /proc/bus/input/devices 
N: Name="Dell Dell USB Entry Keyboard"
P: Phys=usb-0000:00:1d.0-1.8/input0
S: Sysfs=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.8/2-1.8:1.0/input/input2
H: Handlers=sysrq kbd leds event2 
# cat /proc/bus/input/devices 
N: Name="PixArt HP USB Optical Mouse"
P: Phys=usb-0000:00:1a.0-1.4/input0
S: Sysfs=/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.4/1-1.4:1.0/input/input14
H: Handlers=mouse0 event3 
# ll /dev/input/event2
crw-rw----. 1 root input 13, 66 Dec  6 14:48 /dev/input/event2
# ll /dev/input/event3
crw-rw----. 1 root input 13, 67 Dec  6 14:53 /dev/input/event3


Preparation: Prepare the following device xml files
# cat usbkbd.xml
<input type='keyboard' bus='usb'/>
# cat usbmouse.xml
<input type='mouse' bus='usb'/>
# cat usbtablet.xml
<input type='tablet' bus='usb'/>
# cat virtiokbd.xml
<input type='keyboard' bus='virtio'/>
# cat virtiomouse.xml
<input type='mouse' bus='virtio'/>
# cat virtiotablet.xml
<input type='tablet' bus='virtio'/>
# cat passthroughkbd.xml 
    <input type='passthrough' bus='virtio'>
      <source evdev='/dev/input/event2'/>
    </input>
# cat passthroughmouse.xml 
<input type='passthrough' bus='virtio'>
  <source evdev='/dev/input/event3'/>
</input>  

Test scenarios
Scenario-1: Hot-plug/unplug operation
Step1. Prepare a running VM
# virsh domstate pc
running

Step2. Hot-plug operation
# for i in *; do virsh attach-device pc $i; done
Device attached successfully
Device attached successfully
Device attached successfully
Device attached successfully
Device attached successfully
Device attached successfully
Device attached successfully
Device attached successfully

# virsh dumpxml pc |grep input
    <input type='passthrough' bus='virtio'>
      <source evdev='/dev/input/event2'/>
      <alias name='input2'/>
    </input>
    <input type='passthrough' bus='virtio'>
      <source evdev='/dev/input/event3'/>
      <alias name='input3'/>
    </input>
    <input type='keyboard' bus='usb'>
      <alias name='input4'/>
    </input>
    <input type='mouse' bus='usb'>
      <alias name='input5'/>
    </input>
    <input type='tablet' bus='usb'>
      <alias name='input6'/>
    </input>
    <input type='keyboard' bus='virtio'>
      <alias name='input7'/>
    </input>
    <input type='mouse' bus='virtio'>
      <alias name='input8'/>
    </input>
    <input type='tablet' bus='virtio'>
      <alias name='input9'/>
    </input>


Step3. Hot-unplug operation
# for i in *; do virsh detach-device pc $i; done
Device detached successfully
Device detached successfully
Device detached successfully
Device detached successfully
Device detached successfully
Device detached successfully
Device detached successfully
Device detached successfully

# virsh dumpxml pc |grep input
No output


Scenario-2: Cold-plug/Hot-unplug operation
Step1. Prepare a shutdown VM
# virsh domstate pc
shut off

Step2. Cold-plug operation
# for i in *; do virsh attach-device pc $i --config; done
Device attached successfully
Device attached successfully
Device attached successfully
Device attached successfully
Device attached successfully
Device attached successfully
Device attached successfully
Device attached successfully

# virsh dumpxml pc --inactive|grep input
    <input type='passthrough' bus='virtio'>
      <source evdev='/dev/input/event2'/>
    </input>
    <input type='passthrough' bus='virtio'>
      <source evdev='/dev/input/event3'/>
    </input>
    <input type='keyboard' bus='usb'>
    </input>
    <input type='mouse' bus='usb'>
    </input>
    <input type='tablet' bus='usb'>
    </input>
    <input type='keyboard' bus='virtio'>
    </input>
    <input type='mouse' bus='virtio'>
    </input>
    <input type='tablet' bus='virtio'>
    </input>

Step3. Start VM
# virsh start pc
Domain pc started

# virsh domstate pc
running

# virsh dumpxml pc |grep input
    <input type='passthrough' bus='virtio'>
      <source evdev='/dev/input/event2'/>
      <alias name='input2'/>
    </input>
    <input type='passthrough' bus='virtio'>
      <source evdev='/dev/input/event3'/>
      <alias name='input3'/>
    </input>
    <input type='keyboard' bus='usb'>
      <alias name='input4'/>
    </input>
    <input type='mouse' bus='usb'>
      <alias name='input5'/>
    </input>
    <input type='tablet' bus='usb'>
      <alias name='input6'/>
    </input>
    <input type='keyboard' bus='virtio'>
      <alias name='input7'/>
    </input>
    <input type='mouse' bus='virtio'>
      <alias name='input8'/>
    </input>
    <input type='tablet' bus='virtio'>
      <alias name='input9'/>
    </input>

# ps -ef |grep pc |sed 's/-device/\n-device/g'
-device virtio-input-host-pci,id=input2,evdev=/dev/input/event2,bus=pci.0,addr=0xa 
-device virtio-input-host-pci,id=input3,evdev=/dev/input/event3,bus=pci.0,addr=0xb 
-device usb-kbd,id=input4,bus=ua-usb.0,port=3 
-device usb-mouse,id=input5,bus=ua-usb.0,port=4 
-device usb-tablet,id=input6,bus=ua-usb.0,port=5 
-device virtio-keyboard-pci,id=input7,bus=pci.0,addr=0xc 
-device virtio-mouse-pci,id=input8,bus=pci.0,addr=0xd 
-device virtio-tablet-pci,id=input9,bus=pci.0,addr=0xe

Step4. Hot-unplug operation
# for i in *; do virsh detach-device pc $i ; done
Device detached successfully
Device detached successfully
Device detached successfully
Device detached successfully
Device detached successfully
Device detached successfully
Device detached successfully
Device detached successfully

# virsh dumpxml pc |grep input
No output

All results are as expected, move this bug to be verified.

Comment 10 errata-xmlrpc 2018-04-10 10:39:40 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2018:0704


Note You need to log in before you can comment on or make changes to this bug.