This service will be undergoing maintenance at 00:00 UTC, 2017-10-23 It is expected to last about 30 minutes
Bug 1025108 - hot-plug of USB device fails when only the vendor id and product id are specified
hot-plug of USB device fails when only the vendor id and product id are speci...
Status: CLOSED CURRENTRELEASE
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt (Show other bugs)
7.0
Unspecified Unspecified
medium Severity medium
: rc
: ---
Assigned To: Jiri Denemark
Virtualization Bugs
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-30 23:04 EDT by Xuesong Zhang
Modified: 2014-06-17 20:58 EDT (History)
6 users (show)

See Also:
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 06:13:28 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
libvirtd log (123.74 KB, text/plain)
2013-11-25 03:27 EST, hongming
no flags Details

  None (edit)
Description Xuesong Zhang 2013-10-30 23:04:48 EDT
Description
On rhel7, hot-plug the usb device failed with vendor id and product id.

Version:
kernel-3.10.0-33.el7.x86_64
libvirt-1.1.1-10.el7.x86_64
qemu-kvm-1.5.3-10.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. prepare the usb devices.
# lsusb
Bus 002 Device 007: ID 0951:1625 Kingston Technology DataTraveler 101 II
Bus 003 Device 002: ID 046d:c077 Logitech, Inc. 
......

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='0x1625'/>
      </source>
    </hostdev>

3. hot-plug the usb device to one running guest
# virsh attach-device a usb.xml 
error: Failed to attach device from usb.xml
error: Path '/dev/bus/usb/000/000' is not accessible: No such file or directory


Actual results:
hot-plug usb device failed in step3

expect results:
hot-plug should be worked well in step3

Additional info: 
1. You can reference the following bug, hot-plug usb is working well at that time.
https://bugzilla.redhat.com/show_bug.cgi?id=916837

2. I checked on the latest rhel6.5, hot-plug usb is working well, so this issue is only on rhel7 now.

3. This issue is occurred while hot-plug usb only with vender id and product id. If using usb address, this issue didn't occurred.
Comment 1 Jiri Denemark 2013-11-15 09:47:51 EST
Fixed upstream by v1.1.4-90-g05e149f:

commit 05e149f94cbd34e4c3d4e9c7f6871e13cfe03d8c
Author: Jiri Denemark <jdenemar@redhat.com>
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.
Comment 3 hongming 2013-11-25 03:24:05 EST
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
Comment 4 hongming 2013-11-25 03:24:52 EST
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
Comment 5 hongming 2013-11-25 03:27:55 EST
Created attachment 828554 [details]
libvirtd log
Comment 6 Jiri Denemark 2013-12-09 14:01:06 EST
The following additional commits are needed to fix this bug completely:

commit ee414b5d6d1601bde8440a9de050c02447bbd3bf
Author: Cole Robinson <crobinso@redhat.com>
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@redhat.com>
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@redhat.com>
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.
Comment 9 Xuesong Zhang 2013-12-16 00:36:40 EST
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
Comment 10 Ludek Smid 2014-06-13 06:13:28 EDT
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.

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