OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

1.5.3. Device Passthrough / Hotplug


If instead of the here described hotplugging you want to always pass through a device add the xml content of the device to your static guest xml representation via e.g. virsh edit <guestname>. In that case you don't need to use attach/detach. There are different kinds of passthrough. Types available to you depend on your Hardware and software setup.

• USB hotplug/passthrough

• VF hotplug/Passthrough


image

2 http://libvirt.org/uri.html

3 https://libvirt.org/migration.html#offline

4 https://libvirt.org/migration.html

5 http://wiki.qemu.org/Features/PostCopyLiveMigration

6 https://wiki.ubuntu.com/QemuKVMMigration


But both kinds are handled in a very similar way and while there are various way to do it (e.g. also via qemu monitor) driving such a change via libvirt is recommended. That way libvirt can try to manage all sorts of special cases for you and also somewhat masks version differences.


In general when driving hotplug via libvirt you create a xml snippet that describes the device just as you would do in a static guest description.7 A usb device is usually identified by Vendor/Product id's:

<hostdev mode='subsystem' type='usb' managed='yes'>

<source>

<vendor id='0x0b6d'/>

<product id='0x3880'/>

</source>

</hostdev>


Virtual functions are usually assigned via their PCI-ID (domain, bus, slot, function).


<hostdev mode='subsystem' type='pci' managed='yes'>

<source>

<address domain='0x0000' bus='0x04' slot='0x10' function='0x0'/>

</source>

</hostdev>


image

To get the Virtual function in the first place is very device dependent and can therefore not be fully covered here. But in general it involves setting up an iommu, registering via VFIO8 and sometimes requesting a number of VFs. Here an example on ppc64el to get 4 VFs on a device:


$ sudo modprobe vfio-pci

# identify device

$ lspci -n -s 0005:01:01.3 0005:01:01.3 0200: 10df:e228 (rev 10)

# register and request VFs

$ echo 10df e228 | sudo tee /sys/bus/pci/drivers/vfio-pci/new_id

$ echo 4 | sudo tee /sys/bus/pci/devices/0005\:01\:00.0/sriov_numvfs


You then attach or detach the device via libvirt by relating the guest with the xml snippet.


virsh attach-device <guestname> <device-xml>

# Use the Device int the Guest

virsh detach-device <guestname> <device-xml>


image

There are several associated known issues in regard to apparmor proetction protecting "too much". You might need to tweak exceptions in the apparmor profiles until the bugs 15522419 (for USB) and https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1679704 (For VF assignment) are resolved. To check if you are affected watch dmesg while you use the USB/VF passthrough/hotplug feature and verify if you see apparmor denies10.


image

7 https://libvirt.org/formatdomain.html

8 https://www.kernel.org/doc/Documentation/vfio.txt

9 https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1552241

10 http://wiki.apparmor.net/index.php/AppArmor_Failures#Messages_in_the_Log_files


Top OS Cloud Computing at OnWorks: