Bug 814866 - libvirt does not allow usb redirection..
libvirt does not allow usb redirection..
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: libvirt (Show other bugs)
17
All Linux
unspecified Severity high
: ---
: ---
Assigned To: Libvirt Maintainers
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-04-20 17:21 EDT by Thomas Davis
Modified: 2012-05-02 16:55 EDT (History)
12 users (show)

See Also:
Fixed In Version: libvirt-0.9.11.3-1.fc17
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-05-02 16:55:43 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)
A variable is used before it's set; depends on compiler doing the right thing. (470 bytes, patch)
2012-04-20 18:21 EDT, Thomas Davis
no flags Details | Diff

  None (edit)
Description Thomas Davis 2012-04-20 17:21:44 EDT
Description of problem:

When you try to redirect a USB device to a VM, it refuses to do it, claiming
the device is already in another domain, and the domain name
is garbage.

Version-Release number of selected component (if applicable):

Fedora 17 Beta


How reproducible:


Steps to Reproduce:
1. Create VM.
2. Add usb host redir to VM.
3. try to start VM.
  
Actual results:

virt-manager complains.

Error starting domain: Requested operation is not valid: USB device 002:004 is in use by domain `

Traceback (most recent call last):
  File "/usr/share/virt-manager/virtManager/asyncjob.py", line 45, in cb_wrapper
    callback(asyncjob, *args, **kwargs)
  File "/usr/share/virt-manager/virtManager/asyncjob.py", line 66, in tmpcb
    callback(*args, **kwargs)
  File "/usr/share/virt-manager/virtManager/domain.py", line 1114, in startup
    self._backend.create()
  File "/usr/lib64/python2.7/site-packages/libvirt.py", line 554, in create
    if ret == -1: raise libvirtError ('virDomainCreate() failed', dom=self)
libvirtError: Requested operation is not valid: USB device 002:004 is in use by domain `


Expected results:

F15 does not have this problem.

Additional info:

device I'm trying to redirect is a HID device, but it's not a keyboard or a mouse.

[60601.454072] usb 3-2: USB disconnect, device number 3
[60604.033035] usb 3-2: new full-speed USB device number 4 using uhci_hcd
[60604.246075] usb 3-2: New USB device found, idVendor=6666, idProduct=5555
[60604.246082] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[60604.246087] usb 3-2: Product: Weather Direct Light Wireless Device
[60604.246091] usb 3-2: Manufacturer: LA CROSSE TECHNOLOGY
[60604.246094] usb 3-2: SerialNumber: 0123456
[60604.278442] generic-usb 0003:6666:5555.000A: hiddev0,hidraw3: USB HID v1.11 Device [LA CROSSE TECHNOLOGY Weather Direct Light Wireless Device] on usb-0000:00:1a.0-2/input0


Bus 003 Device 004: ID 6666:5555 Prototype product Vendor ID 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            3 Human Interface Device
  bDeviceSubClass         0 No Subclass
  bDeviceProtocol       255 
  bMaxPacketSize0        64
  idVendor           0x6666 Prototype product Vendor ID
  idProduct          0x5555 
  bcdDevice            1.00
  iManufacturer           1 LA CROSSE TECHNOLOGY
  iProduct                2 Weather Direct Light Wireless Device
  iSerial                 3 0123456
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower               30mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength     617
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval              32
Device Status:     0x0100
  (Bus Powered)

from /etc/libvirt/qemu/WindowsXP.xml:

   <hostdev mode='subsystem' type='usb' managed='yes'>
      <source>
        <vendor id='0x6666'/>
        <product id='0x5555'/>
      </source>
    </hostdev>
Comment 1 Thomas Davis 2012-04-20 18:21:11 EDT
Created attachment 579116 [details]
A variable is used before it's set; depends on compiler doing the right thing.

Sets the dev->used_by to NULL before it's used.
Comment 2 Thomas Davis 2012-04-20 18:23:13 EDT
I've tested and booted on a F17 KVM using a libvirt 0.9.11 patched RPM;

rpm -qa | grep libvirt
libvirt-daemon-0.9.11-1.fc17.x86_64
libvirt-python-0.9.11-1.fc17.x86_64
libvirt-client-0.9.11-1.fc17.x86_64
libvirt-daemon-kvm-0.9.11-1.fc17.x86_64
Comment 3 Laine Stump 2012-04-20 21:53:04 EDT
What you're adding is a NOP - VIR_ALLOC(dev) (in the lines just above where you set dev->used_by = NULL) ends up calling calloc(), so the memory is all initialized to 0 anyway.

The real fix is to apply the following three upstream patches, which unfortunately were pushed after 0.9.11 was released (but since it was so soon afterward, they should apply cleanly):

commit b2c7b9ee0e6f2203984035668c066be37f3a256a
Author: Michal Privoznik <mprivozn@redhat.com>
Date:   Mon Mar 26 16:33:58 2012 +0200

    qemu: Don't leak temporary list of USB devices
    
    and add debug message when adding USB device
    to the list of active devices.

commit e2f5dd6134ebeb6846450c7d7782273d3d274859
Author: Michal Privoznik <mprivozn@redhat.com>
Date:   Mon Mar 26 16:40:01 2012 +0200

    qemu: Delete USB devices used by domain on stop
    
    To prevent assigning one USB device to two domains,
    we keep a list of assigned USB devices. On domain
    startup - qemuProcessStart() - we insert devices
    used by domain into the list but remove them only
    on detach-device. Devices are, however, released
    on qemuProcessStop() as well.

commit ea3bc548aca7b4c448b48863120ad35a7337c127
Author: Michal Privoznik <mprivozn@redhat.com>
Date:   Mon Mar 26 16:44:19 2012 +0200

    qemu: Build activeUsbHostdevs list on process reconnect
    
    If the daemon is restarted it will lose list of active
    USB devices assigned to active domains. Therefore we need
    to rebuild this list on qemuProcessReconnect().

Setting to POST to catch the attention of the next person to do a build (Hi Cole!)
Comment 4 Thomas Davis 2012-04-21 00:09:12 EDT
Interesting.  Funny that's supposed to be zero'd out, but adding that NULL fixed the problem for the moment..

I'll wait for the next build, and see what it does.
Comment 5 Thomas Davis 2012-04-21 13:53:19 EDT
Ok, I found had some free moments..

those 3 patches do fix the problem, I reversed what I did and applied just those 3 patches.  Installed and it worked.
Comment 6 Michal Privoznik 2012-04-30 03:53:27 EDT
Thomas,

dev->used_by is there to protect a USB device 'dev' to be assigned to another domain. Basically, if it's NULL it is not used by any domain and vice versa: if it is NOT NULL, it points to a domain name that holds this device. Therefore, if forcibly set this to NULL, all subsequent checks would pass as 'dev' is thought to be free but it's not.
Comment 7 Fedora Update System 2012-04-30 10:47:50 EDT
libvirt-0.9.11.3-1.fc17 has been submitted as an update for Fedora 17.
https://admin.fedoraproject.org/updates/libvirt-0.9.11.3-1.fc17
Comment 8 Fedora Update System 2012-04-30 14:48:26 EDT
Package libvirt-0.9.11.3-1.fc17:
* should fix your issue,
* was pushed to the Fedora 17 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing libvirt-0.9.11.3-1.fc17'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2012-6964/libvirt-0.9.11.3-1.fc17
then log in and leave karma (feedback).
Comment 9 Thomas Davis 2012-04-30 22:59:13 EDT
(In reply to comment #6)
> Thomas,
> 
> dev->used_by is there to protect a USB device 'dev' to be assigned to another
> domain. Basically, if it's NULL it is not used by any domain and vice versa: if
> it is NOT NULL, it points to a domain name that holds this device. Therefore,
> if forcibly set this to NULL, all subsequent checks would pass as 'dev' is
> thought to be free but it's not.

Yes, I see that is what being attempted..

I'll give the updates a whirl.
Comment 10 Fedora Update System 2012-05-02 16:55:43 EDT
libvirt-0.9.11.3-1.fc17 has been pushed to the Fedora 17 stable repository.  If problems still persist, please make note of it in this bug report.

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