Xen: passing USB devices through into an HVM virtual machine (Windows), or USB passthrough

Practice



USB passthrough into a Xen virtual machine is possible in two main ways, which differ fundamentally in their approach (here I will only cover "static" USB passthrough, i.e. for example some hardware security dongle that gets attached at system startup).


Method 1: legacy

This method is available in any version of Xen, including subversions 3.x and 4.x.

To pass a USB device through into an HVM domain (for example, into Windows) from Xen, you need to add the following lines to the virtual machine's configuration file:

usb = 1
usbdevice = 'host:0a89:0003'

The first line enables a virtual USB hub inside our HVM virtual machine.

The second line tells Xen which specific device needs to be passed through. Here:
  • host : write it exactly as "host", it does not change
  • 0a89 : VendorID
  • 0003 : DeviceID

You can find the VendorID and DeviceID of the device you need using the command:
$ lsusb
run on Xen's Dom0.

In the resulting list you will see all the USB devices connected to this server. Among them will be USB hubs, as well as other devices, if any are connected.


How do you connect several devices? Unfortunately, I have not found any information on this in Xen, and everything I have tried myself does not help. Without PV, you cannot pass through several USB devices into an HVM machine.



Method 2: Xen 3.4+, Xen 4.0+ and paravirtualized machines

This method only worked on relatively recent versions of Xen, and its most notable application is in Xen 4. For it to work, the HVM machine needs to have paravirtualized drivers on board (for example, GPLPV).



With this method, a virtual USB controller is created on the HVM domain's side, and the specified devices are passed through directly into this controller.


For this to work, you need to add the following line to the virtual machine's configuration file:

vusb = [ 'usbver=2, numports=8, port_1=1-1, port_2=1-2' ]

here:
  • usbver=2 : USB version. usbver=2 is USB 2.0, usbver=1 is USB 1.1
  • numports=8 : The number of ports on this virtual controller. From 1 to 16.
  • port_1=1-1 : This is the description of port 1 of the virtual controller. That is, this specifies which USB device to pass through to port 1 of the virtual machine.
  • port_2=1-2 : The same, but for the second port.

As we can see, there are settings here called port_X, after the "=" sign of which some index of the USB device to be passed through is specified.

This index is the ID of the device plugged into the physical machine (whether it is a flash drive or a hardware security dongle). You can find out which ID you need with the following command:

$ sudo xm usb-list-assignable-devices

This command will output a list of all the USB devices that can be "passed through" into a virtual machine, along with their IDs. It is exactly these IDs that we can use to specify the devices being passed through in port_X.

At the same time, as we can see, up to 16 USB devices can now be passed through into a single virtual machine, which is certainly welcome.


You can view the devices currently passed through into a particular machine with the command:
$ sudo xm usb-list <domain_name>

Where instead of <domain_name> specify the name of the domain for which you want to display the listing.


PS. Personal observation - a hardware security dongle did not get passed through using this method (the second one). Using the first method it did get passed through, but not with the second one; at the same time, with the second method Xen reported that the device was present and bound to the correct virtual machine, but inside the machine itself the dongle was not visible.

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Operating Systems and System Programming"

Terms: Operating Systems and System Programming