RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1025108 - hot-plug of USB device fails when only the vendor id and product id are specified
Summary: hot-plug of USB device fails when only the vendor id and product id are speci...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.0
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Jiri Denemark
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-10-31 03:04 UTC by Xuesong Zhang
Modified: 2014-06-18 00:58 UTC (History)
6 users (show)

Fixed In Version: libvirt-1.1.1-15.el7
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-06-13 10:13:28 UTC
Target Upstream Version:
Embargoed:


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

Description Xuesong Zhang 2013-10-31 03:04:48 UTC
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 14:47:51 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.

Comment 3 hongming 2013-11-25 08:24:05 UTC
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 08:24:52 UTC
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 08:27:55 UTC
Created attachment 828554 [details]
libvirtd log

Comment 6 Jiri Denemark 2013-12-09 19:01:06 UTC
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.

Comment 9 Xuesong Zhang 2013-12-16 05:36:40 UTC
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 10:13:28 UTC
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.