[libvirt] USB2 controllers & domain XML

Hi I have started looking at: https://bugzilla.redhat.com/show_bug.cgi?id=725670 My initial thought was to just add a new type of controller: <controller type='usb2' index='0'/> But it also needs the 3 companion UHCI controllers (see bug). We can either include them implicitely (not really elegant in libvirt, but doable), or with more flexibility list all the controllers in the XML: <controller type='ich9-usb-ehci1' index='0'/> <controller type='ich9-usb-uhci1' index='0' masterbus='0' firstport='0'> <controller type='ich9-usb-uhci2' index='0' masterbus='0' firstport='2'> <controller type='ich9-usb-uhci3' index='0' masterbus='0' firstport='4'> Any other idea? Daniel, have you also started working on USB2 & usb-redir support? regards -- Marc-André Lureau

On Thu, Aug 18, 2011 at 05:18:46PM +0200, Marc-André Lureau wrote:
Hi
I have started looking at: https://bugzilla.redhat.com/show_bug.cgi?id=725670
My initial thought was to just add a new type of controller:
<controller type='usb2' index='0'/>
But it also needs the 3 companion UHCI controllers (see bug). We can either include them implicitely (not really elegant in libvirt, but doable), or with more flexibility list all the controllers in the XML:
<controller type='ich9-usb-ehci1' index='0'/> <controller type='ich9-usb-uhci1' index='0' masterbus='0' firstport='0'> <controller type='ich9-usb-uhci2' index='0' masterbus='0' firstport='2'> <controller type='ich9-usb-uhci3' index='0' masterbus='0' firstport='4'>
Any other idea? Daniel, have you also started working on USB2 & usb-redir support?
I'm not actively doing any work on it, merely experimenting with QEMU to understand how everything fits together. There are some key observations I have - A guest can have multiple USB controllers, either USB1 or USB2. The USB1 controller may be a function on the PIIX, or it may be a dedicate card - Since the companion controllers have associated PCI addresses, we must represent them explicitly in the XML, so it is clear to apps what PCI slots/functions are used. - Historically QEMU would auto-create hubs. For migration stability we must not let it do this. We must create any neccessary hubs ourself. - QEMU does not currently have any USB2 hub, and when it does, it will likely be USB2 only, no USB1 support. This makes hubs less desirable than multiple controllers, since you'd need to choose between USB1 or USB2 when creating the hub, while a controller can dynamically switch between USB1 & 2 thanks to the companion controllers. - Since there can be multiple controllers, we need a way specify physical addressing for USB devices, to ensure stablility across migration and hotplug/unplug. This needs to include the controller index, and the port number. The control index needs to span across USB1 and USB2 controllers. What all this means.... 1. Add a new controller type 'usb' <controller type='usb' index='0' /> 2. Add a 'model' for the usb controller type, allowing things like piix3-uhci, uhci, ich9-ehci, etc. If none is specified, then we need to auto-fill the basic default (piix3-uchi). <controller type='usb' index='0' model='ich9-ehci'/> 3. A USB controller will have a PCI address child element. <controller type='usb' index='0' model='ich9-ehci'> <address type='pci' domain='0' bus='0' slot='4' function='7'/> </controller> 4. All USB devices will gain a new USB address child element. <input type='tablet' bus='usb'> <address type='usb' bus='0' port='4'/> </input> 5. USB companion controllers use type='usb' too, but with an extra 'master' attribute to associate them <controller type='usb' index='0' model='ich9-ehci'> <address type='pci' domain='0' bus='0' slot='4' function='7'/> </controller> <controller type='usb' index='0' model='ich9-ehci1'> <master startport='0'/> <address type='pci' domain='0' bus='0' slot='4' function='1'/> </controller> <controller type='usb' index='0' model='ich9-uhci2'> <master startport='2'/> <address type='pci' domain='0' bus='0' slot='4' function='2'/> </controller> <controller type='usb' index='0' model='ich9-uhci3'> <master startport='4'/> <address type='pci' domain='0' bus='0' slot='4' function='2'/> </controller> 6. A USB hub should appear as a normal device <hub type='usb'> <address type='usb' bus='0' port='1'/> </hub> 7. A USB device address port should include the hub path eg. Plug a hub into port 1 of the first USB bus <hub type='usb'> <address type='usb' bus='0' port='1'/> </hub> then put a device and another hub into that hub: <input type='mouse' type='usb'> <address type='usb' bus='0' port='1.1'/> </hub> <hub type='usb'> <address type='usb' bus='0' port='1.2'/> </hub> Finally add 2 more devices into the second hub <input type='mouse' type='usb'> <address type='usb' bus='0' port='1.2.1'/> </hub> <input type='mouse' type='usb'> <address type='usb' bus='0' port='1.2.2'/> </hub> 7. If no USB controller is in the XML, we need to prefill the default PIIX3 controller 8. If no USB addresses are specified, we should autoassign addrs starting against the first controller. A complex example. We create the default USB1 controllers, and two USB2 controllers. We put a USB tablet on the USB1 controller, and then create a USB smartcards on one of the USB2 controllers, and assign two host devices to the other USB2 controller: <controller type='usb' index='0' model='piix3-uhci'> <address type='pci' domain='0' bus='0' slot='1' function='3'/> </controller> <controller type='usb' index='1' model='ich9-ehci'> <address type='pci' domain='0' bus='0' slot='4' function='7'/> </controller> <controller type='usb' index='0' model='ich9-ehci1'> <master startport='0'/> <address type='pci' domain='0' bus='0' slot='4' function='1'/> </controller> <controller type='usb' index='0' model='ich9-uhci2'> <master startport='2'/> <address type='pci' domain='0' bus='0' slot='4' function='2'/> </controller> <controller type='usb' index='0' model='ich9-uhci3'> <master startport='4'/> <address type='pci' domain='0' bus='0' slot='4' function='3'/> </controller> <controller type='usb' index='2' model='ich9-ehci'> <address type='pci' domain='0' bus='0' slot='5' function='7'/> </controller> <controller type='usb' index='2' model='ich9-ehci1'> <master startport='0'/> <address type='pci' domain='0' bus='0' slot='5' function='1'/> </controller> <controller type='usb' index='2' model='ich9-uhci2'> <master startport='2'/> <address type='pci' domain='0' bus='0' slot='5' function='2'/> </controller> <controller type='usb' index='2' model='ich9-uhci3'> <master startport='4'/> <address type='pci' domain='0' bus='0' slot='5' function='3'/> </controller> <input type='tablet' bus='usb'> <address type='usb' bus='0' port='4'/> </input> <smartcard> <address type='usb' bus='1' port='1'/> </input> <hostdev mode=subsys type=usb> <source> <address bus='14' device='6'/> </source> <address type='usb' bus='2' port='1'/> </input> <hostdev mode=subsys type=usb> <source> <address bus='14' device='6'/> </source> <address type='usb' bus='2' port='2'/> </input> Regards, 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 :|

Hi On Thu, Aug 18, 2011 at 9:42 PM, Daniel P. Berrange <berrange@redhat.com> wrote:
5. USB companion controllers use type='usb' too, but with an extra 'master' attribute to associate them
<controller type='usb' index='0' model='ich9-ehci'> <address type='pci' domain='0' bus='0' slot='4' function='7'/> </controller> <controller type='usb' index='0' model='ich9-ehci1'> <master startport='0'/> <address type='pci' domain='0' bus='0' slot='4' function='1'/> </controller> <controller type='usb' index='0' model='ich9-uhci2'> <master startport='2'/> <address type='pci' domain='0' bus='0' slot='4' function='2'/> </controller> <controller type='usb' index='0' model='ich9-uhci3'> <master startport='4'/> <address type='pci' domain='0' bus='0' slot='4' function='2'/> </controller>
Does each companion controller has it's own bus? I guess the bus id is defined with the device id property in qemu. So if all controller have index='0', should the id be prefixed with echi-, uhci1-, uchi2- etc.. or should it use the same usb%d namespace. Having a prefix would mean that USB devices have to specify the correct bus name, which is probably not what we want. So using common "usb" prefix seems more convenient. And I think <master> is missing a 'bus' attribute. Would this XML be more suitable? <controller type='usb' index='0' model='ich9-ehci1'> <address type='pci' domain='0' bus='0' slot='4' function='7'/> </controller> <controller type='usb' index='1' model='ich9-uhci1'> <master bus='0' startport='0'/> <address type='pci' domain='0' bus='0' slot='4' function='0'/> </controller> <controller type='usb' index='2' model='ich9-uhci2'> <master bus='0' startport='2'/> <address type='pci' domain='0' bus='0' slot='4' function='1'/> </controller> <controller type='usb' index='3' model='ich9-uhci3'> <master bus='0' startport='4'/> <address type='pci' domain='0' bus='0' slot='4' function='2'/> </controller> regards -- Marc-André Lureau

Hi, On 08/19/2011 06:13 AM, Marc-André Lureau wrote:
Hi
On Thu, Aug 18, 2011 at 9:42 PM, Daniel P. Berrange<berrange@redhat.com> wrote:
5. USB companion controllers use type='usb' too, but with an extra 'master' attribute to associate them
<controller type='usb' index='0' model='ich9-ehci'> <address type='pci' domain='0' bus='0' slot='4' function='7'/> </controller> <controller type='usb' index='0' model='ich9-ehci1'> <master startport='0'/> <address type='pci' domain='0' bus='0' slot='4' function='1'/> </controller> <controller type='usb' index='0' model='ich9-uhci2'> <master startport='2'/> <address type='pci' domain='0' bus='0' slot='4' function='2'/> </controller> <controller type='usb' index='0' model='ich9-uhci3'> <master startport='4'/> <address type='pci' domain='0' bus='0' slot='4' function='2'/> </controller>
Does each companion controller has it's own bus?
No, this is why the companion controllers have the masterbus option. Each port on the ehci has a mux (in the real hardware which we emulate), it looks something like this: physical port | mux /\ / \ / \ ehci companion port And the uhci companion controller plugs into 2 of the companion ports, starting at the startport number, the ehci has 6 ports like the above diagram, hence 3 companions, to cover the 6 companion ports. These 6 ports together form a bus, ie the ehci.0 bus. So adding companion controllers does not add more physical busses (they will show up as logical busses in the guest, but that is of little concern to qemu). The bus sitation does not really change with / without companion controllers as soon as you've an ehci, you get a bus belonging to it with 6 ports. The companion controllers just add usb 1 compatiblity to the otherwise usb 2 only ports, so that you can plug in any usb device without needing to think about the speed of it (qemu has port_speed / device_speed masks for usb ports resp devices, and refuses to connect (*) a device if there is no overlap). *) This means in practice that if you do things wrong, like create an ehci without companions and plug in a usb-tablet, the usb-tablet will be there in qemu's device tree, but it will be in disconnected state. IOW it is lying next to the computer with its plug not inserted into the computer. Regards, Hans

Hi,
- Since the companion controllers have associated PCI addresses, we must represent them explicitly in the XML, so it is clear to apps what PCI slots/functions are used.
Hmm. Do we have to? Usually the individual pci functions of multifunction devices are not fully independent of each other. It is a single device with multiple interfaces. I would try to present the *device* in libvirt xml, not the *interfaces*. [ Yes, you can bundle multiple virtio devices as multifunction device into a single pci slot to overcome the slot number limit. That isn't how pci functions are usually used on real hardware though. ]
5. USB companion controllers use type='usb' too, but with an extra 'master' attribute to associate them
<controller type='usb' index='0' model='ich9-ehci'> <address type='pci' domain='0' bus='0' slot='4' function='7'/> </controller> <controller type='usb' index='0' model='ich9-ehci1'> <master startport='0'/> <address type='pci' domain='0' bus='0' slot='4' function='1'/> </controller> [ ... ]
<controller type='usb' index='0' model='ich9-ehci-with-companions'> <address type='pci' domain='0' bus='0' slot='4' /> </controller> ? cheers, Gerd

于 2011年08月18日 23:18, Marc-André Lureau 写道:
Hi
I have started looking at: https://bugzilla.redhat.com/show_bug.cgi?id=725670
My initial thought was to just add a new type of controller:
<controller type='usb2' index='0'/>
But it also needs the 3 companion UHCI controllers (see bug). We can either include them implicitely (not really elegant in libvirt, but doable), or with more flexibility list all the controllers in the XML:
<controller type='ich9-usb-ehci1' index='0'/> <controller type='ich9-usb-uhci1' index='0' masterbus='0' firstport='0'> <controller type='ich9-usb-uhci2' index='0' masterbus='0' firstport='2'> <controller type='ich9-usb-uhci3' index='0' masterbus='0' firstport='4'>
Any other idea? Daniel, have you also started working on USB2& usb-redir support?
I started to do the work, but then quited to do other work. And I just started to do the work again from yesterday.
regards

于 2011年08月19日 11:32, Osier Yang 写道:
于 2011年08月18日 23:18, Marc-André Lureau 写道:
Hi
I have started looking at: https://bugzilla.redhat.com/show_bug.cgi?id=725670
My initial thought was to just add a new type of controller:
<controller type='usb2' index='0'/>
But it also needs the 3 companion UHCI controllers (see bug). We can either include them implicitely (not really elegant in libvirt, but doable), or with more flexibility list all the controllers in the XML:
<controller type='ich9-usb-ehci1' index='0'/> <controller type='ich9-usb-uhci1' index='0' masterbus='0' firstport='0'> <controller type='ich9-usb-uhci2' index='0' masterbus='0' firstport='2'> <controller type='ich9-usb-uhci3' index='0' masterbus='0' firstport='4'>
Any other idea? Daniel, have you also started working on USB2& usb-redir support?
I started to do the work, but then quited to do other work. And I just started to do the work again from yesterday.
Marc-André, I just worked out the XML nodes, and a bit codes to parse the XML, I'm fine to quit if you went further than me. Regards Osier

Hi Osier, On Fri, Aug 19, 2011 at 8:31 AM, Osier Yang <jyang@redhat.com> wrote:
Marc-André,
I just worked out the XML nodes, and a bit codes to parse the XML, I'm fine to quit if you went further than me.
I am now more or less at 5 in Daniel plan. Did you go further? 22 files changed, 512 insertions(+), 23 deletions(-) -- Marc-André Lureau
participants (5)
-
Daniel P. Berrange
-
Gerd Hoffmann
-
Hans de Goede
-
Marc-André Lureau
-
Osier Yang