[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH V9 0/7] xen pvusb toolstack work
On Wed, 2015-11-25 at 02:19 -0700, Chun Yan Liu wrote: > According to current active discussion: > libxl: Introduce a template for devices with a controller > https://www.mail-archive.com/xen-devel@xxxxxxxxxxxxx/msg46720.html > > Will update naming and RESEND. Maybe give it a day or two to allow for review of that proposal, in case something changes? Ian. > > - Chunyan > > > > > On 11/24/2015 at 04:35 PM, in message > <1448354134-21644-1-git-send-email-cyliu@xxxxxxxx>, Chunyan Liu > <cyliu@xxxxxxxx> wrote: > > This patch series is to add pvusb toolstack work, supporting hot > > add|remove > > USB device to|from guest and specify USB device in domain > > configurationÂÂ > > file. > > Â > > Changes to V8: > > * lots of changes in libxl pvusb API (patch 3/7) > > * update 2/7 to write separate read_sysfs_file function > > * address all other comments > > Â > > V8: > > http://lists.xen.org/archives/html/xen-devel/2015-10/msg02178.html > > Â > > V7: > > http://lists.xen.org/archives/html/xen-devel/2015-09/msg03115.html > > Â > > V6: > > http://lists.xen.org/archives/html/xen-devel/2015-08/msg00750.html > > Â > > V5: > > http://lists.xen.org/archives/html/xen-devel/2015-06/msg04052.html > > Â > > V4: > > http://lists.xenproject.org/archives/html/xen-devel/2015-06/msg01327.ht > > ml > > Â > > Related Discussion Threads: > > http://www.redhat.com/archives/libvir-list/2014-June/msg00038.html > > http://lists.xen.org/archives/html/xen-devel/2014-06/msg00086.html > > Â > > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ<<< pvusb work introduction >>> > > Â > > 1. Overview > > Â > > There are two general methods for passing through individual host > > devices to a guest. The first is via an emulated USB device > > controller; the second is PVUSB. > > Â > > Additionally, there are two ways to add USB devices to a guest: via > > the config file at domain creation time, and via hot-plug while the VM > > is running. > > Â > > * Emulated USB > > Â > > In emulated USB, the device model (qemu) presents an emulated USB > > controller to the guest. The device model process then grabs control > > of the device from domain 0 and and passes the USB commands between > > the guest OS and the host USB device. > > Â > > This method is only available to HVM domains, and is not available for > > domains running with device model stubdomains. > > Â > > * PVUSB > > Â > > PVUSB uses a paravirtialized front-end/back-end interface, similar to > > the traditional Xen PV network and disk protocols. In order to use > > PVUSB, you need usbfront in your guest OS, and usbback in dom0 (or > > your USB driver domain). > > Â > > 2. Specifying a host USB device > > Â > > QEMU qmp commands allows USB devices to be specified either by their > > bus address (in the form bus.device) or their device tag (in the form > > vendorid:deviceid). > > Â > > Each way of specifying has its advantages: > > Â > > ÂÂÂÂSpecifying by device tag will always get the same device, > > regardless of where the device ends up in the USB bus topology. > > However, if there are two identical devices, it will not allow you to > > specify which one. > > Â > > ÂÂÂÂSpecifying by bus address will always allow you to choose a > > specific device, even if you have duplicates. However, the bus address > > may change depending on which port you plugged the device into, and > > possibly also after a reboot. > > Â > > To avoid duplication of vendorid:deviceid, we'll use bus address to > > specify host USB device in xl toolstack. > > Â > > You can use lsusb to list the USB devices on the system: > > Â > > Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 > > Hub > > Bus 003 Device 002: ID f617:0905 > > Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub > > Bus 001 Device 004: ID 0424:2640 Standard Microsystems Corp. USB 2.0 > > Hub > > Bus 001 Device 005: ID 0424:4060 Standard Microsystems Corp. Ultra > > Fast Media Reader > > Bus 001 Device 006: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse > > Â > > To pass through the Logitec mouse, for instance, you could specify > > 1.6 (remove leading zeroes). > > Â > > Note: USB hubs can not be assigned to guest. > > Â > > 3. PVUSB toolstack > > Â > > * Specify USB device in xl config file > > Â > > You can just specify usb devices, like: > > usbdev=['1.6'] > > Â > > Then it will create a USB controller automatically and attach the USB > > device to the first available USB controller:port. > > Â > > or, you can explicitly specify usb controllers and usb devices, like: > > usbctrl=['verison=1, ports=4', 'version=2, ports=8', ] > > usbdev=['1.6, controller=0, port=1'] > > Â > > Then it will create two USB controllers as you specified. > > And if controller and port are specified in usb config, then it will > > attach the USB device to that controller:port. About the controller > > and port value: > > Each USB controller has a index (or called devid) based on 0. The 1st > > controller has index 0, the 2nd controller has index 1, ... > > Under controller, each port has a port number based on 1. In above > > configuration, the 1st controller will have port 1,2,3,4. > > Â > > * Hot-Plug USB device > > Â > > To attach a USB device, you should first create a USB controller. > > e.g. > > xl usb-ctrl-attach domain [version=1|2] [ports=value] > > By default, it will create a USB2.0 controller with 8 ports. > > Â > > Then you could attach a USB device. > > e.g. > > xl usb-attach domain 1.6 [controller=index port=number] > > By default, it will find the 1st available controller:port to attach > > the USB device. > > Â > > You could view USB device status of the domain by usb-list. > > e.g. > > xl usb-list domain > > It will list USB controllers and USB devices under each controller. > > Â > > You could detach a USB device with usb-detach command. > > e.g. > > xl usb-detach domain 1.6 > > Â > > You can also remove the whole USB controller by usb-ctrl-detach > > command. > > e.g. > > xl usb-ctrl-detach domain 0 > > It will remove the USB controller with index 0 and all USB devices > > under it. > > Â > > 4. PVUSB Libxl implementation > > Â > > * usb-ctrl-attach > > To create a usb controller, we need: > > 1) generate usb controler related information > > 2) write usb controller frontend/backend info to xenstore > > PVUSB frontend and backend driver will probe xenstore paths and build > > connection between frontend and backend. > > Â > > * usb-ctrl-detach > > To remove a usb controller, we need: > > 1) check if the usb controller exists or not > > 2) remove all usb devices under controller > > 3) remove usb controller info from xenstore > > Â > > * usb-attach > > To attach a usb device, we need: > > 1) check if the usb device type is assignable > > 2) check if the usb device is already assigned to a domain > > 3) add 'busid' of the usb device to xenstore contoller/port/. > > ÂÂÂPVUSB driver watches the xenstore changes and detects that, > > ÂÂÂand needs to use 'busid' to do following work. > > 4) unbind usb device from original driver and bind to usbback. > > ÂÂÂIf usb device has many interfaces, then: > > ÂÂÂ- unbind each interface from its original driver and bind to > > usbback. > > ÂÂÂ- store the original driver to xenstore for later rebinding when > > ÂÂÂÂÂdetaching the device. > > Â > > * usb-detach > > To detach a usb device, we need: > > 1) check if the usb device is assigned to the domain > > 2) remove the usb device from xenstore controller/port. > > 3) unbind usb device from usbback and rebind to its original driver. > > ÂÂÂIf usb device has many interfaces, do it to each interface. > > Â > > * usb-list > > List all USB controllers and USB devices under each controller. > > Â > > 5. PVUSB xenstore information > > Â > > PVUSB xenstore information includes three parts: frontend, backend > > and /libxl part. > > Â > > A USB controller is corresponding to a "vusb" device in xenstore. > > Adding a USB controller will add a new "vusb" device, removing a > > USB controller will delete the related "vusb" device. > > Â > > Following is an example xenstore values of a USB controller. > > Backend: > > ÂÂÂbackend = "" > > ÂÂÂÂvusb = "" > > ÂÂÂÂÂ1 = "" > > ÂÂÂÂÂÂ0 = "" > > ÂÂÂÂÂÂÂfrontend = "/local/domain/1/device/vusb/0" > > ÂÂÂÂÂÂÂfrontend-id = "1" > > ÂÂÂÂÂÂÂonline = "1" > > ÂÂÂÂÂÂÂstate = "4" > > ÂÂÂÂÂÂÂtype = "pv" > > ÂÂÂÂÂÂÂusb-ver = "1" > > ÂÂÂÂÂÂÂnum-ports = "4" > > ÂÂÂÂÂÂÂport = "" > > ÂÂÂÂÂÂÂÂ1 = "" > > ÂÂÂÂÂÂÂÂ2 = "" > > ÂÂÂÂÂÂÂÂ3 = "" > > ÂÂÂÂÂÂÂÂ4 = "" > > Â > > Frontend: > > ÂÂÂdevice = "" > > ÂÂÂÂvusb = "" > > ÂÂÂÂÂ0 = "" > > ÂÂÂÂÂÂbackend = "/local/domain/0/backend/vusb/1/0" > > ÂÂÂÂÂÂbackend-id = "0" > > ÂÂÂÂÂÂstate = "4" > > ÂÂÂÂÂÂurb-ring-ref = "348" > > ÂÂÂÂÂÂconn-ring-ref = "346" > > ÂÂÂÂÂÂevent-channel = "20" > > Â > > Adding a USB device won't create a new "vusb" device, but only write > > the USB device busid to one port of USB controller. > > For example, attaching a USB device (busid is 2-1.6) to above USB > > controller port 1, it only need write 2-1.6 to port 1 of this USB > > controller: > > Backend: > > ÂÂÂbackend = "" > > ÂÂÂÂvusb = "" > > ÂÂÂÂÂ1 = "" > > ÂÂÂÂÂÂ0 = "" > > ÂÂÂÂÂÂÂfrontend = "/local/domain/1/device/vusb/0" > > ÂÂÂÂÂÂÂfrontend-id = "1" > > ÂÂÂÂÂÂÂonline = "1" > > ÂÂÂÂÂÂÂstate = "4" > > ÂÂÂÂÂÂÂtype = "pv" > > ÂÂÂÂÂÂÂusb-ver = "1" > > ÂÂÂÂÂÂÂnum-ports = "4" > > ÂÂÂÂÂÂÂport = "" > > ÂÂÂÂÂÂÂÂ1 = "2-1.6" > > ÂÂÂÂÂÂÂÂ2 = "" > > ÂÂÂÂÂÂÂÂ3 = "" > > ÂÂÂÂÂÂÂÂ4 = "" > > Frontend doesn't change. > > Â > > Since assign a host USB device to guest, we'll unbind USB interfaces > > from their original drivers and bind them to usbback. After detaching > > this USB device from guest, one would hope the USB interfaces could > > be rebind to their original drivers, so there should some place to > > get the original driver info. To support that, when attaching a USB > > device to guest, we'll save the original driver info in xenstore too, > > the place is /libxl/usbback, for example: > > libxl = "" > > Â1 = "" > > Â dm-version = "qemu_xen" > > Âusbback = "" > > Â 3-11 = "" > > ÂÂÂ3-11@1_0 = "" > > ÂÂÂÂdriver_path = "/sys/bus/usb/drivers/btusb" > > Â > > In this example, USB device (busid is 3-11, /sys/bus/usb/devices/3-11). > > It has interface 3-11:1.0, whose original dirver is btusb. > > Since xenstore doesn't allow ':' and '.' in a key, so we encode the > > interface by changing ':' to '@' and changing '.' to '_'. > > Â > > When detaching the USB device from guest, we can rebind 3-11:1.0 to > > btusb driver. > > Â > > Chunyan Liu (7): > > Â libxl: export some functions for pvusb use > > Â libxl_utils: add internal function to read sysfs file contents > > Â libxl: add pvusb API > > Â libxl: add libxl_device_usb_assignable_list API > > Â xl: add pvusb commands > > Â xl: add usb-assignable-list command > > Â domcreate: support pvusb in configuration file > > Â > > Âdocs/man/xl.cfg.pod.5ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ84 ++ > > Âdocs/man/xl.pod.1ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ41 + > > Âtools/libxl/MakefileÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂÂ2 +- > > Âtools/libxl/libxl.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ55 +- > > Âtools/libxl/libxl.hÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ77 ++ > > Âtools/libxl/libxl_create.cÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ73 +- > > Âtools/libxl/libxl_device.cÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂÂ9 +- > > Âtools/libxl/libxl_internal.hÂÂÂÂÂÂÂÂÂ|ÂÂÂ34 + > > Âtools/libxl/libxl_osdeps.hÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ13 + > > Âtools/libxl/libxl_pvusb.cÂÂÂÂÂÂÂÂÂÂÂÂ| 1584ÂÂ > > ++++++++++++++++++++++++++++++++++ > > Âtools/libxl/libxl_types.idlÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ46 + > > Âtools/libxl/libxl_types_internal.idl |ÂÂÂÂ1 + > > Âtools/libxl/libxl_utils.cÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ95 ++ > > Âtools/libxl/libxl_utils.hÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂÂ5 + > > Âtools/libxl/xl.hÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂÂ6 + > > Âtools/libxl/xl_cmdimpl.cÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ322 ++++++- > > Âtools/libxl/xl_cmdtable.cÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ29 + > > Â17 files changed, 2466 insertions(+), 10 deletions(-) > > Âcreate mode 100644 tools/libxl/libxl_pvusb.c > Â > _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |