USB split driver
I've updated this patch to compile against current unstable and implemented a new protocol which I think fixes the data integrity issue present in all previous versions where URBs were not correctly stalled on error.
In this version of the driver, an error in the BE causes the BE URB queue to stall and all URBs present and subsequently arriving in the BE to be unlinked and failed back to the FE.
The FE catches the unlinking URBs and hangs onto them until the callbacks of any failing URBs and any URBs explicitly unlinked by the FE driver as a result have completed.
After the FE error and unlink completions are quiesced, the FE retries any URBs that remain back to the BE, sending the first with a flag that clears the stall in the BE.
This was fairly ugly, and the locking is a bit of a nightmare. The main problem is that the USB stack has the semantics that it guarantees that the URB queue will be stalled only until the URB completion returns which means that there is a requirement to to URB unlinking nested in the BE completion.
I have seen a couple of URB errors handled without the kernel crashing but I would expect there to be some bugs in this code somewhere.
Also the xenbus stuff has been stirred around a few times since I wrote it correctly and I have lost interest in proving to myself that the current hooks into xenbus are correct. The state machines in ub_xb_channel and uf_xb_channel which coordinate with xenbus were derived by trial and error and unlike the rest of the code are not intended to be correct by design.
Someone has messed around with the usb stuff in the python code since the last version too, possibly to implement usb support for the HVM guests. I changed this code to use "usbport" rather than usb and hopefully it won't conflict. This is untested.
The driver used to be modular and an older version did correctly handle module load and unload in both the FE and BE including quiescing ongoing I/O. I was told to simplify the driver and remove this functionality. The current version is therefore not modular.
I had some correspondence with the author of the USB over IP patch and we came to the conclusion that USB/IP does not address the stalling requirement above. We were not 100% sure whether this is a problem but I think it probably is. This driver might perhaps be a useful example of how to solve the problem for the USB/IP code.
I had put this work on hold waiting for an upstream merge of the other drivers in the hope that it would force a cleanup of some of the xenbus design. Recently I discovered that I'll be leaving the IBM Xen team in the near future and I'm not sure how much more time I can spend on this so this is an attempt to get the driver in the best possible shape for someone else to pick up.
The xen core team should decide whether they really want a USB split driver at all or if they want to go with USB/IP or some common code approach.
As for this driver, the basic structure of the code is OK. I think the locking is probably OK. Lots more testing is required as well as regression tests for xm-test. Some formatting issues probably remain too. It's probably a bit too abstract for some of you---if so, you can always read the .ko files ;-)
Sniff tested against f426f6e646eb.
linux-2.6-xen-sparse/drivers/xen/Kconfig +47 -0
@@ -145,6 +145,29 @@ depends on XEN_PCIDEV_BACKEND default n +config XEN_USBDEV_BACKEND + bool "USB-device backend driver" + depends on XEN_BACKEND + select USB + default y + help + The USB-device backend driver allows the kernel to export USB + devices to USB-device frontend drivers running in other domains. + This is not required for USB device access in domain 0 or any domain + given exclusive control over a USB host controller device at the PCI + level. + Say Y if you want to use this kernel to export a USB device to + another domain running a USB-device frontend driver. + +config XEN_USBDEV_BACKEND_TRACE + bool "USB-device backend driver tracing" + depends on XEN_USBDEV_BACKEND + default n + help + This option causes the driver to output a continual trace of its + activity. + Say N here unless you are trying to debug the driver. + config XEN_TPMDEV_BACKEND tristate "TPM-device backend driver" depends on XEN_BACKEND
@@ -171,6 +194,30 @@ network interfaces within another guest OS. Unless you are building a dedicated device-driver domain, or your master control domain (domain 0), then you almost certainly want to say Y here. + +config XEN_USBDEV_FRONTEND + bool "USB-device frontend driver" + depends on XEN + default y + select USB + help + The USB-device frontend driver allows the kernel to access USB + devices exported by a USB-device backend driver running in another + domain. + This is not required for USB device access in domain 0 or any domain + given exclusive control over a USB host controller device at the PCI + level. + Say Y if you want to use a USB-device backend driver to export a USB + device from another domain to the domain which will run this kernel. + +config XEN_USBDEV_FRONTEND_TRACE + bool "USB-device frontend driver tracing" + depends on XEN_USBDEV_FRONTEND + default n + help + This option causes the driver to output a continual trace of its + activity. + Say N here unless you are trying to debug the driver. config XEN_SCRUB_PAGES bool "Scrub memory before freeing it to Xen"
linux-2.6-xen-sparse/drivers/xen/Makefile +2 -0
@@ -11,7 +11,9 @@ obj-$(CONFIG_XEN_BLKDEV_TAP) += blktap/ obj-$(CONFIG_XEN_NETDEV_BACKEND) += netback/ obj-$(CONFIG_XEN_TPMDEV_BACKEND) += tpmback/ +obj-$(CONFIG_XEN_USBDEV_BACKEND) += usbback/ obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += blkfront/ obj-$(CONFIG_XEN_NETDEV_FRONTEND) += netfront/ obj-$(CONFIG_XEN_PCIDEV_BACKEND) += pciback/ obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += pcifront/ +obj-$(CONFIG_XEN_USBDEV_FRONTEND) += usbfront/
tools/examples/Makefile +1 -0
@@ -29,6 +29,7 @@ XEN_SCRIPTS += block XEN_SCRIPTS += block-enbd block-nbd XEN_SCRIPTS += blktap +XEN_SCRIPTS += usb XEN_SCRIPTS += vtpm vtpm-delete XEN_SCRIPTS += xen-hotplug-cleanup XEN_SCRIPTS += external-device-migrate
tools/examples/xen-backend.agent +3 -0
@@ -9,6 +9,9 @@ case "$XENBUS_TYPE" in tap) /etc/xen/scripts/blktap "$ACTION" + ;; + usb) + /etc/xen/scripts/usb "$ACTION" ;; vbd) /etc/xen/scripts/block "$ACTION"
tools/examples/xen-backend.rules +1 -0
@@ -1,4 +1,5 @@ SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACTION}" +SUBSYSTEM=="xen-backend", KERNEL=="usb*", RUN+="/etc/xen/scripts/usb $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} online"
tools/examples/xmexample1 +7 -0
@@ -64,6 +64,13 @@ # and MODE is r for read-only, w for read-write. disk = [ 'phy:hda1,hda1,w' ] + +#---------------------------------------------------------------------------- +# Define USB devices. +# +# Specify the USB device path as it appears in /sys/bus/usb/devices in the +# backend. This example exports device 3 on bus 1 and device 4 on bus 2. +#usbport = ['path=1-3','path=2-4'] #---------------------------------------------------------------------------- # Define to which TPM instance the user domain should communicate.
tools/python/xen/xend/XendDomainInfo.py +1 -1
@@ -1794,5 +1794,5 @@ addControllerClass('pci', pciif.PciController) addControllerClass('ioports', iopif.IOPortsController) addControllerClass('irq', irqif.IRQController) -addControllerClass('usb', usbif.UsbifController) +addControllerClass('usbport', usbif.UsbifController) addControllerClass('tap', BlktapController)
tools/python/xen/xend/server/usbif.py +25 -2
@@ -22,6 +22,8 @@ """Support for virtual USB hubs. """ +from xen.xend import sxp + from xen.xend.server.DevController import DevController
@@ -36,7 +38,28 @@ DevController.__init__(self, vm) - def getDeviceDetails(self, _): + def getDeviceDetails(self, config): """@see DevController.getDeviceDetails""" - return (self.allocateDeviceID(), {}, {}) + path = sxp.child_value(config, 'path') + + devid = self.allocateDeviceID() + + back = { 'path' : path, + 'handle' : "%i" % devid } + + front = { 'handle' : "%i" % devid } + + return (devid, back, front) + + def configuration(self, devid): + """@see DevController.configuration""" + + result = DevController.configuration(self, devid) + + path = self.readBackend(devid,'path') + + if path: + result.append(['path', path]) + + return result
tools/python/xen/xm/create.py +37 -7
82 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/Makefile new file +12 -0
@@ -0,0 +1,12 @@ +obj-y = \ +ub_buffer_rsrc_provider.o \ +ub_callback.o \ +ub_device.o \ +ub_ep.o \ +ub_gw.o \ +ub_gw_rsrc.o \ +ub_rbr_mapper.o \ +ub_rsrc.o \ +ub_ring_channel.o \ +ub_work.o \ +ub_xb_channel.o
linux-2.6-xen-sparse/drivers/xen/usbback/ub_buffer_rsrc_provider.c new file +196 -0
196 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_buffer_rsrc_provider.h new file +77 -0
77 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_callback.c new file +41 -0
41 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_callback.h new file +146 -0
146 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_channel.h new file +159 -0
159 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_device.c new file +766 -0
766 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_device.h new file +28 -0
@@ -0,0 +1,28 @@ +/*****************************************************************************/ +/* Copyright (c) 2005 Harry Butterworth IBM Corporation */ +/* */ +/* This program is free software; you can redistribute it and/or modify it */ +/* under the terms of the GNU General Public License as published by the */ +/* Free Software Foundation; either version 2 of the License, or (at your */ +/* option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, but */ +/* WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */ +/* Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License along */ +/* with this program; if not, write to the Free Software Foundation, Inc., */ +/* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* */ +/*****************************************************************************/ + +#ifndef UB_DEVICE_H +#define UB_DEVICE_H + +struct ub_device ; + +domid_t ub_device_query_remote_domain (struct ub_device *device); +struct usb_device *ub_device_query_usbdev (struct ub_device *device); + +#endif
linux-2.6-xen-sparse/drivers/xen/usbback/ub_ep.c new file +416 -0
416 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_ep.h new file +57 -0
57 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_gw.c new file +466 -0
466 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_gw.h new file +163 -0
163 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_gw_rsrc.c new file +75 -0
75 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_rbr_mapper.c new file +347 -0
170 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_rbr_mapper.h new file +145 -0
145 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_ring_channel.c new file +755 -0
755 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_ring_channel.h new file +111 -0
111 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_rsrc.c new file +529 -0
529 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_rsrc.h new file +61 -0
61 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_trace.h new file +36 -0
Lines of this file are not shown. View the raw message.
linux-2.6-xen-sparse/drivers/xen/usbback/ub_work.c new file +72 -0
72 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_work.h new file +104 -0
104 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_xb_channel.c new file +372 -0
372 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbback/ub_xb_channel.h new file +77 -0
77 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/Makefile new file +16 -0
Lines of this file are not shown. View the raw message.
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_buffer_rsrc_provider.c new file +173 -0
173 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_buffer_rsrc_provider.h new file +78 -0
78 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_callback.c new file +39 -0
Lines of this file are not shown. View the raw message.
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_callback.h new file +150 -0
150 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_channel.h new file +159 -0
159 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_device.c new file +795 -0
795 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_device.h new file +48 -0
48 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_driver.c new file +429 -0
429 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_driver.h new file +30 -0
Lines of this file are not shown. View the raw message.
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_ep.c new file +452 -0
452 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_ep.h new file +63 -0
63 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_gw.c new file +503 -0
503 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_gw.h new file +123 -0
123 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_gw_rsrc.c new file +211 -0
211 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_gw_rsrc.h new file +84 -0
84 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_module.c new file +65 -0
65 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_rbr_provider_pool.c new file +339 -0
339 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_rbr_provider_pool.h new file +169 -0
169 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_ring_channel.c new file +744 -0
744 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_ring_channel.h new file +114 -0
114 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_rsrc.c new file +597 -0
597 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_rsrc.h new file +81 -0
81 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_sll.h new file +97 -0
97 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_trace.h new file +36 -0
Lines of this file are not shown. View the raw message.
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_work.c new file +73 -0
73 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_work.h new file +105 -0
105 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_xb_channel.c new file +399 -0
399 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/usbfront/uf_xb_channel.h new file +77 -0
77 lines not on this page · raw message
xen/include/public/io/usbif.h new file +213 -0
213 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Part of the diff is not shown here. View the raw message.
Thanks, Harry. I know you've put a lot of work into this.
Peace.
Andrew
Quoted 73 lines · Harry Butterworth
I've updated this patch to compile against current unstable and implemented a new protocol which I think fixes the data integrity issue present in all previous versions where URBs were not correctly stalled on error.
In this version of the driver, an error in the BE causes the BE URB queue to stall and all URBs present and subsequently arriving in the BE to be unlinked and failed back to the FE.
The FE catches the unlinking URBs and hangs onto them until the callbacks of any failing URBs and any URBs explicitly unlinked by the FE driver as a result have completed.
After the FE error and unlink completions are quiesced, the FE retries any URBs that remain back to the BE, sending the first with a flag that clears the stall in the BE.
This was fairly ugly, and the locking is a bit of a nightmare. The main problem is that the USB stack has the semantics that it guarantees that the URB queue will be stalled only until the URB completion returns which means that there is a requirement to to URB unlinking nested in the BE completion.
I have seen a couple of URB errors handled without the kernel crashing but I would expect there to be some bugs in this code somewhere.
Also the xenbus stuff has been stirred around a few times since I wrote it correctly and I have lost interest in proving to myself that the current hooks into xenbus are correct. The state machines in
ub_xb_channelanduf_xb_channelwhich coordinate with xenbus were derived by trial and error and unlike the rest of the code are not intended to be correct by design.Someone has messed around with the usb stuff in the python code since the last version too, possibly to implement usb support for the HVM guests. I changed this code to use "usbport" rather than usb and hopefully it won't conflict. This is untested.
The driver used to be modular and an older version did correctly handle module load and unload in both the FE and BE including quiescing ongoing I/O. I was told to simplify the driver and remove this functionality. The current version is therefore not modular.
I had some correspondence with the author of the USB over IP patch and we came to the conclusion that USB/IP does not address the stalling requirement above. We were not 100% sure whether this is a problem but I think it probably is. This driver might perhaps be a useful example of how to solve the problem for the USB/IP code.
I had put this work on hold waiting for an upstream merge of the other drivers in the hope that it would force a cleanup of some of the xenbus design. Recently I discovered that I'll be leaving the IBM Xen team in the near future and I'm not sure how much more time I can spend on this so this is an attempt to get the driver in the best possible shape for someone else to pick up.
The xen core team should decide whether they really want a USB split driver at all or if they want to go with USB/IP or some common code approach.
As for this driver, the basic structure of the code is OK. I think the locking is probably OK. Lots more testing is required as well as regression tests for xm-test. Some formatting issues probably remain too. It's probably a bit too abstract for some of you---if so, you can always read the .ko files ;-)
Sniff tested against
f426f6e646eb.Signed-off-by Harry Butterworth <[email protected]>_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel