[libvirt] Auto-assignment of USB devices and auto-creation of USB hubs

Hello, I've been helping a customer out this week with assigning specific devices to specific USB controllers inside his KVM VMs. He's got USB1 devices which need a UHCI controller (because of rubbishy Windows device drivers) and USB2 devices which need a EHCI controller ("speed mismatch" on a UHCI hub). I've suggested config similar to this: <controller type='usb' index='0' model='ehci'> </controller> <controller type='usb' index='1' model='piix3-uhci'> </controller> <input type='tablet' bus='usb'/> <hub type='usb'> <address type='usb' bus='1' port='2'/> </hub> <hostdev mode='subsystem' type='usb' managed='yes'> <source> <vendor id='0xAAAA'/> <product id='0xAAAA'/> </source> <address type='usb' bus='1' port='2.1'/> </hostdev> <hostdev mode='subsystem' type='usb' managed='yes'> <source> <vendor id='0xBBBB'/> <product id='0xBBBB'/> </source> <address type='usb' bus='1' port='2.2'/> </hostdev> and I explained the concept to him with diagrams like these: UHCI --+-- Tablet (port 1) +-- HUB (port 2) --. +-- Device (port 2.1) +-- Device (port 2.2) UHCI --+-- Tablet (port 1) +-- HUB (port 2) --. +-- HUB (port 2.1) --. | +-- Device (port 2.1.1) | +-- Device (port 2.1.2) | +-- HUB (port 2.2) --. +-- Device (port 2.2.1) (then imagine extending this example out to also include EHCI controller and devices) He's very happy so far and I've just been working it all out through trial and error and reading the libvirt domain specification. My observation is that you can either: a) let libvirt plug everything into the UHCI controller, regardless of what other controllers are there and what order they appear in or b) find out how many ports a controller/hub has through trial and error, manually create USB hubs, and map every single device and port out manually with no middle ground in between. I think it would be way better if users could just assign a USB hostdev to a controller, then let libvirt do all the heavy lifting in regards to hubs and ports. For example, : <controller type='usb' index='0' model='ehci'> </controller> <controller type='usb' index='1' model='piix3-uhci'> </controller> <hostdev mode='subsystem' type='usb' managed='yes'> <source> <vendor id='0x0529'/> <product id='0x0001'/> </source> <address type='usb' bus='1'/> </hostdev> <hostdev mode='subsystem' type='usb' managed='yes'> <source> <vendor id='0x3923'/> <product id='0x709b'/> </source> <address type='usb' bus='1'/> </hostdev> I can see it's already been discussed that we couldn't just implement "port=auto" because we need migration stability: http://www.redhat.com/archives/libvir-list/2011-August/msg00816.html but much like how you add: <controller type='usb' index='0' model='ehci'> </controller> then save the XML, and go "virsh edit" and the controller automagically has a PCI address assigned, we could enter this into the XML: <hostdev mode='subsystem' type='usb' managed='yes'> <source> whatever </source> <address type='usb' bus='1'/> </hostdev> then save the XML, and "virsh edit" again, and all the port/hub stuff would already be there pre-made as required. Any thoughts? Is this worth logging an RFE for? Cheers, Jamie

On Mi, 2013-09-18 at 07:33 -0400, Jamie Bainbridge wrote:
Hello,
I've been helping a customer out this week with assigning specific devices to specific USB controllers inside his KVM VMs. He's got USB1 devices which need a UHCI controller (because of rubbishy Windows device drivers) and USB2 devices which need a EHCI controller ("speed mismatch" on a UHCI hub).
I've suggested config similar to this:
<controller type='usb' index='0' model='ehci'> </controller> <controller type='usb' index='1' model='piix3-uhci'> </controller>
You can also do this: <controller type='usb' index='0' model='ich9-ehci1'> <address type='pci' domain='0x0000' bus='0x00' slot='0x1d' function='0x7' multifunction='on'/> </controller> <controller type='usb' index='0' model='ich9-uhci1'> <master startport='0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x1d' function='0x0' multifunction='on'/> </controller> <controller type='usb' index='0' model='ich9-uhci2'> <master startport='2'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x1d' function='0x1' multifunction='on'/> </controller> <controller type='usb' index='0' model='ich9-uhci3'> <master startport='4'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x1d' function='0x2' multifunction='on'/> </controller> Gives you a ehci controller with uhci companions. It's a single usb bus, with 6 ports, supporting both usb1 and usb2. Makes device attachment a bit easier as you don't have to worry about the device speed then.
<input type='tablet' bus='usb'/>
You can also do this here: <input type='tablet' bus='usb'> <address type='usb' bus='0' port='2.8'/> </input>
<hub type='usb'> <address type='usb' bus='1' port='2'/> </hub>
The qemu hub supports usb1.1 only, so any usb 2.0 devices must be plugged into a ehci root port. The hub has 8 downstream ports btw.
My observation is that you can either:
a) let libvirt plug everything into the UHCI controller, regardless of what other controllers are there and what order they appear in or b) find out how many ports a controller/hub has through trial and error, manually create USB hubs, and map every single device and port out manually
with no middle ground in between.
Correct. And if you hotplug usb devices you have to do (b) to make sure live migration works.
<address type='usb' bus='1'/>
then save the XML, and "virsh edit" again, and all the port/hub stuff would already be there pre-made as required.
Any thoughts? Is this worth logging an RFE for?
Sure. It's done for PCI, for good reasons. IMO libvirt should likewise create usb addresses. cheers, Gerd

On Wed, Sep 18, 2013 at 02:58:05PM +0200, Gerd Hoffmann wrote:
On Mi, 2013-09-18 at 07:33 -0400, Jamie Bainbridge wrote:
<address type='usb' bus='1'/>
then save the XML, and "virsh edit" again, and all the port/hub stuff would already be there pre-made as required.
Any thoughts? Is this worth logging an RFE for?
Sure. It's done for PCI, for good reasons. IMO libvirt should likewise create usb addresses.
I thought we already auto-added <address> lines for USB devices, but I guess not. We definitely should make that happen. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Daniel P. Berrange
-
Gerd Hoffmann
-
Jamie Bainbridge