Bug 1025108
Summary: | hot-plug of USB device fails when only the vendor id and product id are specified | ||||||
---|---|---|---|---|---|---|---|
Product: | Red Hat Enterprise Linux 7 | Reporter: | Xuesong Zhang <xuzhang> | ||||
Component: | libvirt | Assignee: | Jiri Denemark <jdenemar> | ||||
Status: | CLOSED CURRENTRELEASE | QA Contact: | Virtualization Bugs <virt-bugs> | ||||
Severity: | medium | Docs Contact: | |||||
Priority: | medium | ||||||
Version: | 7.0 | CC: | acathrow, bili, dyuan, honzhang, mzhan, pkrempa | ||||
Target Milestone: | rc | ||||||
Target Release: | --- | ||||||
Hardware: | Unspecified | ||||||
OS: | Unspecified | ||||||
Whiteboard: | |||||||
Fixed In Version: | libvirt-1.1.1-15.el7 | Doc Type: | Bug Fix | ||||
Doc Text: | Story Points: | --- | |||||
Clone Of: | Environment: | ||||||
Last Closed: | 2014-06-13 10:13:28 UTC | Type: | Bug | ||||
Regression: | --- | Mount Type: | --- | ||||
Documentation: | --- | CRM: | |||||
Verified Versions: | Category: | --- | |||||
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||
Cloudforms Team: | --- | Target Upstream Version: | |||||
Embargoed: | |||||||
Attachments: |
|
Description
Xuesong Zhang
2013-10-31 03:04:48 UTC
Fixed upstream by v1.1.4-90-g05e149f: commit 05e149f94cbd34e4c3d4e9c7f6871e13cfe03d8c Author: Jiri Denemark <jdenemar> Date: Thu Nov 14 12:02:40 2013 +0100 qemu: Call qemuSetupHostdevCGroup later during hotplug https://bugzilla.redhat.com/show_bug.cgi?id=1025108 So far qemuSetupHostdevCGroup was called very early during hotplug, even before we knew the device we were about to hotplug was actually available. By calling the function later, we make sure QEMU won't be allowed to access devices used by other domains. Another important effect of this change is that hopluging USB devices specified by vendor and product (but not by their USB address) works again. This was broken since v1.0.5-171-g7d763ac, when the call to qemuFindHostdevUSBDevice was moved after the call to qemuSetupHostdevCGroup, which then used an uninitialized USB address. Verify it as follows , it is failed to hotplug usb to guest. Change its status to ASSIGNED. # lsusb ...... Bus 002 Device 003: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive # cat usb.xml <hostdev mode='subsystem' type='usb' managed='yes'> <source> <product id='0x090c'/> <vendor id='0x1000'/> </source> </hostdev> # virsh attach-device r6.4 usb.xml error: Failed to attach device from usb.xml error: unable to set user and group to '107:107' on '/dev/bus/usb/000/000': No such file or directory # vim /var/log/libvirtd_debug.log 2013-11-25 08:19:35.015+0000: 3915: debug : virUSBDeviceNew:366 : 0 0 000:000: initialized 2013-11-25 08:19:35.015+0000: 3915: info : virSecuritySELinuxSetFileconHelper:887 : Setting SELinux context on '/dev/bus/usb/000/000' to 'system_u:object_r:svirt_image_t:s0:c387,c595' 2013-11-25 08:19:35.015+0000: 3915: error : virSecuritySELinuxSetFileconHelper:910 : unable to set security context 'system_u:object_r:svirt_image_t:s0:c387,c595' on '/dev/bus/usb/000/000': No such file or directory 2013-11-25 08:19:35.015+0000: 3915: debug : virUSBDeviceFree:376 : 0 0 000:000: freeing 2013-11-25 08:19:35.015+0000: 3915: debug : virUSBDeviceNew:366 : 0 0 000:000: initialized 2013-11-25 08:19:35.015+0000: 3915: debug : virSecurityDACParseIds:89 : DAC seclabel for domain 'r6.4' wasn't found 2013-11-25 08:19:35.015+0000: 3915: info : virSecurityDACSetOwnership:255 : Setting DAC user and group on '/dev/bus/usb/000/000' to '107:107' 2013-11-25 08:19:35.015+0000: 3915: error : virSecurityDACSetOwnership:285 : unable to set user and group to '107:107' on '/dev/bus/usb/000/000': No such file or directory 2013-11-25 08:19:35.015+0000: 3915: debug : virUSBDeviceFree:376 : 0 0 000:000: freeing Versions # rpm -q libvirt qemu-kvm kernel libvirt-1.1.1-13.el7.x86_64 qemu-kvm-1.5.3-19.el7.x86_64 kernel-3.10.0-33.el7.x86_64 Created attachment 828554 [details]
libvirtd log
The following additional commits are needed to fix this bug completely: commit ee414b5d6d1601bde8440a9de050c02447bbd3bf Author: Cole Robinson <crobinso> Date: Thu Dec 5 14:54:41 2013 -0500 qemu: hotplug: Only label hostdev after checking device conflicts Similar to what Jiri did for cgroup setup/teardown in 05e149f94, push it all into the device handler functions so we can do the necessary prep work before claiming the device. This also fixes hotplugging USB devices by product/vendor (virt-manager's default behavior): https://bugzilla.redhat.com/show_bug.cgi?id=1016511 commit 5953a73787b50da56e2ee820a8095ccb09c7a79b Author: Cole Robinson <crobinso> Date: Thu Dec 5 15:03:00 2013 -0500 qemu: hotplug: Fix double free on USB collision If we hit a collision, we free the USB device while it is still part of our temporary USBDeviceList. When the list is unref'd, the device is free'd again. Make the initial device freeing dependent on whether it is present in the temporary list or not. commit 586b0ed81828a443717b018989f2bced1bcfac01 Author: Cole Robinson <crobinso> Date: Thu Dec 5 14:59:05 2013 -0500 qemu: hotplug: Fix adding USB devices to the driver list We were unconditionally removing the device from the host list, when it should only be done on error. This fixes USB collision detection when hotplugging the same device to two guests. Test with the latest libvirt build libvirt-1.1.1-15.el7.x86_64, this bug is fixed, change the status to "VERIFIED". Steps: 1. prepare the usb devices. # lsusb Bus 006 Device 002: ID 0951:1646 Kingston Technology ...... 2. prepare the usb xml for hot-plug, note only specify the vendor id and product id in the xml. # cat usb.xml <hostdev mode='subsystem' type='usb' managed='yes'> <source> <vendor id='0x0951'/> <product id='0x1646'/> </source> </hostdev> 3. hot-plug the usb device to one running guest # virsh attach-device a usb.xml Device attached successfully # virsh dumpxml a |grep host -A 5 <hostdev mode='subsystem' type='usb' managed='yes'> <source> <vendor id='0x0951'/> <product id='0x1646'/> <address bus='6' device='2'/> </source> <alias name='hostdev0'/> </hostdev> 4. detach the usb with the same xml, the usb is hot-unpluged successfully. # virsh detach-device a usb.xml Device detached successfully [root@xuzhangtest2 xuzhang]# virsh dumpxml a |grep host -A 5 This request was resolved in Red Hat Enterprise Linux 7.0. Contact your manager or support representative in case you have further questions about the request. |