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 1375410 - Hot-plugged USB redirect device cannot generate address
Summary: Hot-plugged USB redirect device cannot generate address
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.3
Hardware: x86_64
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Ján Tomko
QA Contact: yisun
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-09-13 03:31 UTC by Pei Zhang
Modified: 2017-08-02 01:27 UTC (History)
4 users (show)

Fixed In Version: libvirt-3.1.0-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-08-01 17:14:13 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2017:1846 0 normal SHIPPED_LIVE libvirt bug fix and enhancement update 2017-08-01 18:02:50 UTC

Description Pei Zhang 2016-09-13 03:31:16 UTC
Description of problem:
Now libvirt support hotplug a redirect USB device to guest, but it 
cannot generated USB address correctly. 

Version-Release number of selected component (if applicable):
libvirt-2.0.0-8.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. define and start a guest with USB controller

2. Prepare an USB hostdev, xml as following 
# cat hostdev1.xml 
<hostdev mode='subsystem' type='usb'>
  <source startupPolicy='optional'>
    <vendor id='0x1005'/>
    <product id='0xb113'/>
  </source>
</hostdev>

# virsh attach-device vm2 hostdev1.xml 
Device attached successfully

3. Prepare an USB redirect device, xml like following 
# cat redir-usb.xml 
<redirdev bus='usb' type='spicevmc'/>

# virsh attach-device vm2 redir-usb.xml 
Device attached successfully


# virsh dumpxml vm2 | grep usb 
  <hostdev mode='subsystem' type='usb' managed='no'>
      <source startupPolicy='optional'>
        <vendor id='0x1005'/>
        <product id='0xb113'/>
        <address bus='2' device='4'/>
      </source>
      <alias name='hostdev0'/>
      <address type='usb' bus='0' port='1'/>
    </hostdev>
    <redirdev bus='usb' type='spicevmc'>
      <alias name='redir0'/>
    </redirdev>
......

4. save and restore, it will fail to restore.
# virsh save vm2 vm2.save 

Domain vm2 saved to vm2.save

# virsh restore vm2.save 
error: Failed to restore domain from vm2.save
error: internal error: qemu unexpectedly closed the monitor: 2016-09-13T02:55:05.263225Z qemu-kvm: -device usb-host,hostbus=2,hostaddr=4,id=hostdev0,bus=usb.0,port=1: usb port 1 (bus usb.0) not found (in use?)

5. re-define and start a guest with usb controller 

6. attach redirect dev first. 

# virsh attach-device vm2 redir-usb.xml 
Device attached successfully

# virsh dumpxml vm2 
......
  <redirdev bus='usb' type='spicevmc'>
      <alias name='redir0'/>
    </redirdev>
......

7. then try to hotplug hostdev, it will fail to attach 

# virsh attach-device vm2 hostdev1.xml 
error: Failed to attach device from hostdev1.xml
error: internal error: unable to execute QEMU command 'device_add': usb port 1 (bus usb.0) not found (in use?)

Actual results:
As above, hot-plugged USB redirect device cannot generated address. 

Expected results:
It can generate USB address. 

Additional info:

Comment 1 Ján Tomko 2017-01-27 16:44:50 UTC
Upstream patch:
https://www.redhat.com/archives/libvir-list/2017-January/msg01107.html

Comment 2 Ján Tomko 2017-01-30 15:59:28 UTC
Pushed upstream:
commit de325472cc27f57c56d0a4049fc3c58f59e8c8b4
Author:     Ján Tomko <jtomko>
CommitDate: 2017-01-30 16:17:35 +0100

    qemu: assign USB addresses on redirdev hotplug too
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1375410

git describe: v3.0.0-83-gde32547

Comment 4 yisun 2017-03-22 10:43:23 UTC
Verified on: 
libvirt-3.1.0-2.el7.x86_64

Scenario 1: attach hostdev and then redirdev
1. prepare a vm without usb devices
## virsh dumpxml vm | grep usb -2
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </controller>
    <controller type='usb' index='0' model='piix3-uhci'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>


2. prepare a usb device on host
## lsusb | grep SanDisk
Bus 001 Device 005: ID 0781:5567 SanDisk Corp. Cruzer Blade


3. prepare one hostdev and one redir usb device xmls
## cat hostdev.usb 
<hostdev mode='subsystem' type='usb'>
  <source startupPolicy='optional'>
    <vendor id='0x0781'/>
    <product id='0x5567'/>
  </source>
</hostdev>


## cat redir.usb 
<redirdev bus='usb' type='spicevmc'/>


4. attach the hostdev usb device and check the usb addr
## virsh attach-device vm hostdev.usb 
Device attached successfully


## virsh dumpxml vm | grep usb -A6
...
    <hostdev mode='subsystem' type='usb' managed='no'>
      <source startupPolicy='optional'>
        <vendor id='0x0781'/>
        <product id='0x5567'/>
        <address bus='1' device='5'/>
      </source>
      <alias name='hostdev0'/>
      <address type='usb' bus='0' port='1'/>  <==== usb addr assigned
    </hostdev>
...


5. attach the redir usb device and check the usb addr
## virsh attach-device vm redir.usb 
Device attached successfully
## virsh dumpxml vm | grep usb -A6

--
    <hostdev mode='subsystem' type='usb' managed='no'>
      <source startupPolicy='optional'>
        <vendor id='0x0781'/>
        <product id='0x5567'/>
        <address bus='1' device='5'/>
      </source>
      <alias name='hostdev0'/>
      <address type='usb' bus='0' port='1'/>
    </hostdev>
    <redirdev bus='usb' type='spicevmc'>
      <alias name='redir0'/>
      <address type='usb' bus='0' port='2'/> <===== redirdev also has usb addr assigned
    </redirdev>


## virsh save vm vm.save 
Domain vm saved to vm.save <=== no more error

Scenario 2: attach redirdev and then hostdev
======================================
1. clean the vm's hotplugged usb devices
## virsh destroy vm; virsh start vm
Domain vm destroyed

Domain vm started

2. attach the redirdev first and check the usb addr
## virsh attach-device vm redir.usb 
Device attached successfully

## virsh dumpxml vm | grep usb -A6
--
    <redirdev bus='usb' type='spicevmc'>
      <alias name='redir0'/>
      <address type='usb' bus='0' port='1'/> <==== usb addr assigned
    </redirdev>


3. attach the hostdev and check the usb addr
## virsh attach-device vm hostdev.usb 
Device attached successfully


## virsh dumpxml vm | grep usb -A6
...
    <hostdev mode='subsystem' type='usb' managed='no'>
      <source startupPolicy='optional'>
        <vendor id='0x0781'/>
        <product id='0x5567'/>
        <address bus='1' device='5'/>
      </source>
      <alias name='hostdev0'/>
      <address type='usb' bus='0' port='2'/> <===== usb addr assigned without conflicts
    </hostdev>
    <redirdev bus='usb' type='spicevmc'>
      <alias name='redir0'/>
      <address type='usb' bus='0' port='1'/>
    </redirdev>

Comment 5 errata-xmlrpc 2017-08-01 17:14:13 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-2017:1846

Comment 6 errata-xmlrpc 2017-08-01 23:55:08 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-2017:1846

Comment 7 errata-xmlrpc 2017-08-02 01:27:35 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-2017:1846


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