3e5111
From 9a202d80f7b60fcf6caf059570bfd2d0b0cbe8a4 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <9a202d80f7b60fcf6caf059570bfd2d0b0cbe8a4@dist-git>
3e5111
From: Erik Skultety <eskultet@redhat.com>
3e5111
Date: Thu, 18 May 2017 14:02:55 +0200
3e5111
Subject: [PATCH] docs: Document the mediated devices within the nodedev driver
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1452072
3e5111
3e5111
Signed-off-by: Erik Skultety <eskultet@redhat.com>
3e5111
(cherry picked from commit a0a0b3cf71cbee1df40dd0fdebd7bb6a84682f09)
3e5111
Signed-off-by: Erik Skultety <eskultet@redhat.com>
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 docs/drvnodedev.html.in | 168 +++++++++++++++++++++++++++++++++++++++++++++++-
3e5111
 tools/virsh.pod         |   7 +-
3e5111
 2 files changed, 171 insertions(+), 4 deletions(-)
3e5111
3e5111
diff --git a/docs/drvnodedev.html.in b/docs/drvnodedev.html.in
3e5111
index 0a3870343..26c52dd0d 100644
3e5111
--- a/docs/drvnodedev.html.in
3e5111
+++ b/docs/drvnodedev.html.in
3e5111
@@ -9,7 +9,7 @@
3e5111
       (historically also referred to as node devices) like USB, PCI, SCSI, and
3e5111
       network devices. This also includes various virtualization capabilities
3e5111
       which the aforementioned devices provide for utilization, for example
3e5111
-      SR-IOV, NPIV, DRM, etc.
3e5111
+      SR-IOV, NPIV, MDEV, DRM, etc.
3e5111
     

3e5111
 
3e5111
     

3e5111
@@ -75,6 +75,7 @@
3e5111
           storage (Since 1.0.4),
3e5111
           scsi_generic (Since 1.0.7),
3e5111
           drm (Since 3.1.0), and
3e5111
+          mdev (Since 3.4.0).
3e5111
           This element can be nested in which case it further specifies a
3e5111
           device's capability. Refer to specific device types to see more values
3e5111
           for the type attribute which are exclusive.
3e5111
@@ -185,5 +186,170 @@
3e5111
 ...
3e5111
 <device>
3e5111
 
3e5111
+    

MDEV capability

3e5111
+    

3e5111
+      A PCI device capable of creating mediated devices will include a nested
3e5111
+      capability mdev_types which enumerates all supported mdev
3e5111
+      types on the physical device, along with the type attributes available
3e5111
+      through sysfs:
3e5111
+    

3e5111
+
3e5111
+    
3e5111
+      
type
3e5111
+      
3e5111
+        This element describes a mediated device type which acts as an
3e5111
+        abstract template defining a resource allocation for instances of this
3e5111
+        device type. The element has one attribute id which holds
3e5111
+        an official vendor-supplied identifier for the type.
3e5111
+        Since 3.4.0
3e5111
+      
3e5111
+
3e5111
+      
name
3e5111
+      
3e5111
+        The name element holds a vendor-supplied code name for
3e5111
+        the given mediated device type. This is an optional element.
3e5111
+        Since 3.4.0
3e5111
+      
3e5111
+
3e5111
+      
deviceAPI
3e5111
+      
3e5111
+        The value of this element describes how an instance of the given type
3e5111
+        will be presented to the guest by the VFIO framework.
3e5111
+        Since 3.4.0
3e5111
+      
3e5111
+
3e5111
+      
availableInstances
3e5111
+      
3e5111
+        This element reports the current state of resource allocation. In other
3e5111
+        words, how many instances of the given type can still be successfully
3e5111
+        created on the physical device.
3e5111
+        Since 3.4.0
3e5111
+      
3e5111
+    
3e5111
+
3e5111
+    

3e5111
+      For a more info about mediated devices, refer to the
3e5111
+      paragraph below.
3e5111
+    

3e5111
+
3e5111
+
3e5111
+<device>
3e5111
+...
3e5111
+  <driver>
3e5111
+    <name>nvidia</name>
3e5111
+  </driver>
3e5111
+  <capability type='pci'>
3e5111
+...
3e5111
+    <capability type='mdev_types'>
3e5111
+      <type id='nvidia-11'>
3e5111
+        <name>GRID M60-0B</name>
3e5111
+        <deviceAPI>vfio-pci</deviceAPI>
3e5111
+        <availableInstances>16</availableInstances>
3e5111
+      </type>
3e5111
+      <!-- Here would come the rest of the available mdev types -->
3e5111
+    </capability>
3e5111
+...
3e5111
+  </capability>
3e5111
+</device>
3e5111
+
3e5111
+    

Mediated devices (MDEVs)

3e5111
+    

3e5111
+      Mediated devices (Since 3.2.0) are software
3e5111
+      devices defining resource allocation on the backing physical device which
3e5111
+      in turn allows the parent physical device's resources to be divided into
3e5111
+      several mediated devices, thus sharing the physical device's performance
3e5111
+      among multiple guests. Unlike SR-IOV however, where a PCIe device appears
3e5111
+      as multiple separate PCIe devices on the host's PCI bus, mediated devices
3e5111
+      only appear on the mdev virtual bus. Therefore, no detach/reattach
3e5111
+      procedure from/to the host driver procedure is involved even though
3e5111
+      mediated devices are used in a direct device assignment manner.
3e5111
+    

3e5111
+
3e5111
+    

3e5111
+      The following sub-elements and attributes are exposed within the
3e5111
+      capability element:
3e5111
+    

3e5111
+
3e5111
+    
3e5111
+      
type
3e5111
+      
3e5111
+        This element describes a mediated device type which acts as an
3e5111
+        abstract template defining a resource allocation for instances of this
3e5111
+        device type. The element has one attribute id which holds
3e5111
+        an official vendor-supplied identifier for the type.
3e5111
+        Since 3.4.0
3e5111
+      
3e5111
+
3e5111
+      
iommuGroup
3e5111
+      
3e5111
+        This element supports a single attribute number which holds
3e5111
+        the IOMMU group number the mediated device belongs to.
3e5111
+        Since 3.4.0
3e5111
+      
3e5111
+    
3e5111
+
3e5111
+    

Example of a mediated device

3e5111
+    
3e5111
+<device>
3e5111
+  <name>mdev_4b20d080_1b54_4048_85b3_a6a62d165c01</name>
3e5111
+  <path>/sys/devices/pci0000:00/0000:00:02.0/4b20d080-1b54-4048-85b3-a6a62d165c01</path>
3e5111
+  <parent>pci_0000_06_00_0</parent>
3e5111
+  <driver>
3e5111
+    <name>vfio_mdev</name>
3e5111
+  </driver>
3e5111
+  <capability type='mdev'>
3e5111
+    <type id='nvidia-11'/>
3e5111
+    <iommuGroup number='12'/>
3e5111
+  <capability/>
3e5111
+<device/>
3e5111
+
3e5111
+    

3e5111
+      The support of mediated device's framework in libvirt's node device driver
3e5111
+      covers the following features:
3e5111
+    

3e5111
+
3e5111
+    
    3e5111
    +      
  • 3e5111
    +        list available mediated devices on the host
    3e5111
    +        (Since 3.4.0)
    3e5111
    +      
    3e5111
    +      
  • 3e5111
    +        display device details
    3e5111
    +        (Since 3.4.0)
    3e5111
    +      
    3e5111
    +    
    3e5111
    +
    3e5111
    +    

    3e5111
    +      Because mediated devices are instantiated from vendor specific templates,
    3e5111
    +      simply called 'types', information describing these types is contained
    3e5111
    +      within the parent device's capabilities
    3e5111
    +      (see the example in PCI host devices).
    3e5111
    +    

    3e5111
    +
    3e5111
    +    

    3e5111
    +      To see the supported mediated device types on a specific physical device
    3e5111
    +      use the following:
    3e5111
    +    

    3e5111
    +
    3e5111
    +    
    3e5111
    +$ ls /sys/class/mdev_bus/<device>/mdev_supported_types
    3e5111
    +
    3e5111
    +    

    3e5111
    +      To manually instantiate a mediated device, use one of the following as a
    3e5111
    +      reference:
    3e5111
    +    

    3e5111
    +
    3e5111
    +    
    3e5111
    +$ uuidgen > /sys/class/mdev_bus/<device>/mdev_supported_types/<type>/create
    3e5111
    +...
    3e5111
    +$ echo <UUID> > /sys/class/mdev_bus/<device>/mdev_supported_types/<type>/create
    3e5111
    +
    3e5111
    +    

    3e5111
    +      Manual removal of a mediated device is then performed as follows:
    3e5111
    +    

    3e5111
    +
    3e5111
    +    
    3e5111
    +$ echo 1 > /sys/bus/mdev/devices/<uuid>/remove
    3e5111
    +
    3e5111
       </body>
    3e5111
     </html>
    3e5111
    diff --git a/tools/virsh.pod b/tools/virsh.pod
    3e5111
    index 0dd1fc7b2..11bacefa9 100644
    3e5111
    --- a/tools/virsh.pod
    3e5111
    +++ b/tools/virsh.pod
    3e5111
    @@ -3155,10 +3155,11 @@ for HBA).
    3e5111
     
    3e5111
     List all of the devices available on the node that are known by libvirt.
    3e5111
     I<cap> is used to filter the list by capability types, the types must be
    3e5111
    -separated by comma, e.g. --cap pci,scsi, valid capability types include
    3e5111
    +separated by comma, e.g. --cap pci,scsi. Valid capability types include
    3e5111
     'system', 'pci', 'usb_device', 'usb', 'net', 'scsi_host', 'scsi_target',
    3e5111
    -'scsi', 'storage', 'fc_host', 'vports', 'scsi_generic', 'drm'.If I<--tree>
    3e5111
    -is used, the output is formatted in a tree representing parents of each
    3e5111
    +'scsi', 'storage', 'fc_host', 'vports', 'scsi_generic', 'drm', 'mdev',
    3e5111
    +'mdev_types'.
    3e5111
    +If I<--tree> is used, the output is formatted in a tree representing parents of each
    3e5111
     node.  I<cap> and I<--tree> are mutually exclusive.
    3e5111
     
    3e5111
     =item B<nodedev-reattach> I<nodedev>
    3e5111
    -- 
    3e5111
    2.13.0
    3e5111