libvirt/docs/drvnodedev.html.in

315 lines
12 KiB
HTML
Raw Normal View History

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<h1>Host device management</h1>
<p>
Libvirt provides management of both physical and virtual host devices
(historically also referred to as node devices) like USB, PCI, SCSI, and
network devices. This also includes various virtualization capabilities
which the aforementioned devices provide for utilization, for example
SR-IOV, NPIV, MDEV, DRM, etc.
</p>
<p>
The node device driver provides means to list and show details about host
devices (<code>virsh nodedev-list</code>, <code>virsh nodedev-info</code>,
and <code>virsh nodedev-dumpxml</code>), which are generic and can be used
with all devices. It also provides the means to manage virtual devices.
Persistently-defined virtual devices are only supported for mediated
devices, while transient devices are supported by both mediated devices
and NPIV (<a href="https://wiki.libvirt.org/page/NPIV_in_libvirt">more
info about NPIV)</a>).
</p>
<p>
Persistent virtual devices are managed with
<code>virsh nodedev-define</code> and <code>virsh nodedev-undefine</code>.
Persistent devices can be configured to start manually or automatically
using <code>virsh nodedev-autostart</code>. Inactive devices can be made
active with <code>virsh nodedev-start</code>.
</p>
<p>
Transient virtual devices are started and stopped with the commands
<code>virsh nodedev-create</code> and <code>virsh nodedev-destroy</code>.
</p>
<p>
Devices on the host system are arranged in a tree-like hierarchy, with
the root node being called <code>computer</code>. The node device driver
remove HAL node device driver There was one attempt a year ago done by me to drop HAL [1] but it was never resolved. There was another time when Dan suggested to drop HAL driver [2] but it was decided to keep it around in case device assignment will be implemented for FreeBSD and the fact that virt-manager uses node device driver [3]. I checked git history and code and it doesn't look like bhyve supports device assignment so from that POV it should not block removing HAL. The argument about virt-manager is not strong as well because libvirt installed from FreeBSD packages doesn't have HAL support so it will not affect these users as well [4]. The only users affected by this change would be the ones compiling libvirt from GIT on FreeBSD. I looked into alternatives and there is libudev-devd package on FreeBSD but unfortunately it doesn't work as it doesn't list any devices when used with libvirt. It provides libudev APIs using devd. I also looked into devd directly and it provides some APIs but there are no APIs for device monitoring and events so that would have to be somehow done by libvirt. Main motivation for dropping HAL support is to replace libdbus with GLib dbus implementation and it cannot be done with HAL driver present in libvirt because HAL APIs heavily depends on symbols provided by libdbus. [1] <https://www.redhat.com/archives/libvir-list/2019-May/msg00203.html> [2] <https://www.redhat.com/archives/libvir-list/2016-April/msg00992.html> [3] <https://www.redhat.com/archives/libvir-list/2016-April/msg00994.html> [4] <https://svnweb.freebsd.org/ports/head/devel/libvirt/Makefile?view=markup> Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-09-03 12:20:43 +00:00
supports udev backend (HAL backend was removed in <code>6.8.0</code>).
</p>
<p>
Details of the XML format of a host device can be found <a
href="formatnode.html">here</a>. Of particular interest is the
<code>capability</code> element, which describes features supported by
the device. Some specific device types are addressed in more detail
below.
</p>
<h2>Basic structure of a node device</h2>
<pre>
&lt;device&gt;
&lt;name&gt;pci_0000_00_17_0&lt;/name&gt;
&lt;path&gt;/sys/devices/pci0000:00/0000:00:17.0&lt;/path&gt;
&lt;parent&gt;computer&lt;/parent&gt;
&lt;driver&gt;
&lt;name&gt;ahci&lt;/name&gt;
&lt;/driver&gt;
&lt;capability type='pci'&gt;
...
&lt;/capability&gt;
&lt;/device&gt;</pre>
<ul id="toc"/>
<h2><a id="PCI">PCI host devices</a></h2>
<dl>
<dt><code>capability</code></dt>
<dd>
When used as top level element, the supported values for the
<code>type</code> attribute are <code>pci</code> and
<code>phys_function</code> (see <a href="#SRIOVCap">SR-IOV below</a>).
</dd>
</dl>
<pre>
&lt;device&gt;
&lt;name&gt;pci_0000_04_00_1&lt;/name&gt;
&lt;path&gt;/sys/devices/pci0000:00/0000:00:06.0/0000:04:00.1&lt;/path&gt;
&lt;parent&gt;pci_0000_00_06_0&lt;/parent&gt;
&lt;driver&gt;
&lt;name&gt;igb&lt;/name&gt;
&lt;/driver&gt;
&lt;capability type='pci'&gt;
&lt;domain&gt;0&lt;/domain&gt;
&lt;bus&gt;4&lt;/bus&gt;
&lt;slot&gt;0&lt;/slot&gt;
&lt;function&gt;1&lt;/function&gt;
&lt;product id='0x10c9'&gt;82576 Gigabit Network Connection&lt;/product&gt;
&lt;vendor id='0x8086'&gt;Intel Corporation&lt;/vendor&gt;
&lt;iommuGroup number='15'&gt;
&lt;address domain='0x0000' bus='0x04' slot='0x00' function='0x1'/&gt;
&lt;/iommuGroup&gt;
&lt;numa node='0'/&gt;
&lt;pci-express&gt;
&lt;link validity='cap' port='1' speed='2.5' width='2'/&gt;
&lt;link validity='sta' speed='2.5' width='2'/&gt;
&lt;/pci-express&gt;
&lt;/capability&gt;
&lt;/device&gt;</pre>
<p>
The XML format for a PCI device stays the same for any further
capabilities it supports, a single nested <code>&lt;capability&gt;</code>
element will be included for each capability the device supports.
</p>
<h3><a id="SRIOVCap">SR-IOV capability</a></h3>
<p>
Single root input/output virtualization (SR-IOV) allows sharing of the
PCIe resources by multiple virtual environments. That is achieved by
slicing up a single full-featured physical resource called physical
function (PF) into multiple devices called virtual functions (VFs) sharing
their configuration with the underlying PF. Despite the SR-IOV
specification, the amount of VFs that can be created on a PF varies among
manufacturers.
</p>
<p>
Suppose the NIC <a href="#PCI">above</a> was also SR-IOV capable, it would
also include a nested
<code>&lt;capability&gt;</code> element enumerating all virtual
functions available on the physical device (physical port) like in the
example below.
</p>
<pre>
&lt;capability type='pci'&gt;
...
&lt;capability type='virt_functions' maxCount='7'&gt;
&lt;address domain='0x0000' bus='0x04' slot='0x10' function='0x1'/&gt;
&lt;address domain='0x0000' bus='0x04' slot='0x10' function='0x3'/&gt;
&lt;address domain='0x0000' bus='0x04' slot='0x10' function='0x5'/&gt;
&lt;address domain='0x0000' bus='0x04' slot='0x10' function='0x7'/&gt;
&lt;address domain='0x0000' bus='0x04' slot='0x11' function='0x1'/&gt;
&lt;address domain='0x0000' bus='0x04' slot='0x11' function='0x3'/&gt;
&lt;address domain='0x0000' bus='0x04' slot='0x11' function='0x5'/&gt;
&lt;/capability&gt;
...
&lt;/capability&gt;</pre>
<p>
A SR-IOV child device on the other hand, would then report its top level
capability type as a <code>phys_function</code> instead:
</p>
<pre>
&lt;device&gt;
...
&lt;capability type='phys_function'&gt;
&lt;address domain='0x0000' bus='0x04' slot='0x00' function='0x0'/&gt;
&lt;/capability&gt;
...
&lt;/device&gt;</pre>
<h3><a id="MDEVCap">MDEV capability</a></h3>
<p>
A device capable of creating mediated devices will include a nested
capability <code>mdev_types</code> which enumerates all supported mdev
types on the physical device, along with the type attributes available
through sysfs. A detailed description of the XML format for the
<code>mdev_types</code> capability can be found
<a href="formatnode.html#MDEVTypesCap">here</a>.
</p>
<p>
The following example shows how we might represent an NVIDIA GPU device
that supports mediated devices. See below for <a href="#MDEV">more
information about mediated devices</a>.
</p>
<pre>
&lt;device&gt;
...
&lt;driver&gt;
&lt;name&gt;nvidia&lt;/name&gt;
&lt;/driver&gt;
&lt;capability type='pci'&gt;
...
&lt;capability type='mdev_types'&gt;
&lt;type id='nvidia-11'&gt;
&lt;name&gt;GRID M60-0B&lt;/name&gt;
&lt;deviceAPI&gt;vfio-pci&lt;/deviceAPI&gt;
&lt;availableInstances&gt;16&lt;/availableInstances&gt;
&lt;/type&gt;
&lt;!-- Here would come the rest of the available mdev types --&gt;
&lt;/capability&gt;
...
&lt;/capability&gt;
&lt;/device&gt;</pre>
<h2><a id="MDEV">Mediated devices (MDEVs)</a></h2>
<p>
Mediated devices (<span class="since">Since 3.2.0</span>) are software
devices defining resource allocation on the backing physical device which
in turn allows the parent physical device's resources to be divided into
several mediated devices, thus sharing the physical device's performance
among multiple guests. Unlike SR-IOV however, where a PCIe device appears
as multiple separate PCIe devices on the host's PCI bus, mediated devices
only appear on the mdev virtual bus. Therefore, no detach/reattach
procedure from/to the host driver procedure is involved even though
mediated devices are used in a direct device assignment manner. A
detailed description of the XML format for the <code>mdev</code>
capability can be found <a href="formatnode.html#mdev">here</a>.
</p>
<h3>Example of a mediated device</h3>
<pre>
&lt;device&gt;
&lt;name&gt;mdev_4b20d080_1b54_4048_85b3_a6a62d165c01&lt;/name&gt;
&lt;path&gt;/sys/devices/pci0000:00/0000:00:02.0/4b20d080-1b54-4048-85b3-a6a62d165c01&lt;/path&gt;
&lt;parent&gt;pci_0000_06_00_0&lt;/parent&gt;
&lt;driver&gt;
&lt;name&gt;vfio_mdev&lt;/name&gt;
&lt;/driver&gt;
&lt;capability type='mdev'&gt;
&lt;type id='nvidia-11'/&gt;
&lt;uuid&gt;4b20d080-1b54-4048-85b3-a6a62d165c01&lt;/uuid&gt;
&lt;iommuGroup number='12'/&gt;
&lt;/capability&gt;
&lt;/device&gt;</pre>
<p>
The support of mediated device's framework in libvirt's node device driver
covers the following features:
</p>
<ul>
<li>
list available mediated devices on the host
(<span class="since">Since 3.4.0</span>)
</li>
<li>
display device details
(<span class="since">Since 3.4.0</span>)
</li>
<li>
create transient mediated devices
(<span class="since">Since 6.5.0</span>)
</li>
<li>
define persistent mediated devices
(<span class="since">Since 7.3.0</span>)
</li>
</ul>
<p>
Because mediated devices are instantiated from vendor specific templates,
simply called 'types', information describing these types is contained
within the parent device's capabilities (see the example in <a
href="#PCI">PCI host devices</a>). To list all devices capable of
creating mediated devices, the following command can be used.
</p>
<pre>$ virsh nodedev-list --cap mdev_types</pre>
<p>
To see the supported mediated device types on a specific physical device
use the following:
</p>
<pre>$ virsh nodedev-dumpxml &lt;device&gt;</pre>
<p>
Before creating a mediated device, unbind the device from the respective
device driver, eg. subchannel I/O driver for a CCW device. Then bind the
device to the respective VFIO driver. For a CCW device, also unbind the
corresponding subchannel of the CCW device from the subchannel I/O driver
and then bind the subchannel (instead of the CCW device) to the vfio_ccw
driver. The below example shows the unbinding and binding steps for a CCW
device.
</p>
<pre>
device="0.0.1234"
subchannel="0.0.0123"
echo $device &gt; /sys/bus/ccw/devices/$device/driver/unbind
echo $subchannel &gt; /sys/bus/css/devices/$subchannel/driver/unbind
echo $subchannel &gt; /sys/bus/css/drivers/vfio_ccw/bind
</pre>
<p>
To instantiate a transient mediated device, create an XML file representing the
device. See above for information about the mediated device xml format.
</p>
<pre>$ virsh nodedev-create &lt;xml-file&gt;
Node device '&lt;device-name&gt;' created from '&lt;xml-file&gt;'</pre>
<p>
If you would like to persistently define the device so that it will be
maintained across host reboots, use <code>virsh nodedev-define</code>
instead of <code>nodedev-create</code>:
</p>
<pre>$ virsh nodedev-define &lt;xml-file&gt;
Node device '&lt;device-name&gt;' defined from '&lt;xml-file&gt;'</pre>
<p>
To start an instance of this device definition, use the following command:
</p>
<pre>$ virsh nodedev-start &lt;device-name&gt;</pre>
<p>
Active mediated device instances can be stopped using <code>virsh
nodedev-destroy</code>, and persistent device definitions can be removed
using <code>virsh nodedev-undefine</code>.
</p>
<p>
If a mediated device is defined persistently, it can also be set to be
automatically started whenever the host reboots or when the parent device
becomes available. In order to autostart a mediated device, use the
following command:
</p>
<pre>$ virsh nodedev-autostart &lt;device-name&gt;</pre>
</body>
</html>