Creating a mediated device for a DASD pass-through device

You need a VFIO mediated device to configure a pass-through DASD for a virtual server.

Procedure

  1. Obtain a UUID as an identifier for the mediated device. You can omit this step if you are using a node-device XML file and you want libvirt to generate a UUID for you.
    Example:
    # uuidgen
    18e124fb-b2fc-47f6-a407-f256b6c49767
  2. Create a node-device XML file for the mediated device.
    1. Start with the following template:
      <device>
          <parent>SUBCHANNELSPEC</parent>
          <capability type="mdev">
              <type id="vfio_ccw-io"/>
              <uuid>UUIDSPEC</uuid>
          </capability>
      </device>
    2. Replace SUBCHANNELSPEC with a specification for your subchannel. The specification must consist of a prefix css_ followed by a string that corresponds to the subchannel bus-ID with underscore characters (_) instead of dots (.). For example, for subchannel bus-ID 0.0.0004, specify css_0_0_0004.
    3. Replace UUIDSPEC with the UUID that you obtained in step 1. Remove the uuid element if you want libvirt to generate a UUID for you.
    Example:
    
    <device>
        <parent>css_0_0_0004</parent>
        <capability type="mdev">
            <type id="vfio_ccw-io"/>
            <uuid>18e124fb-b2fc-47f6-a407-f256b6c49767</uuid>
        </capability>
    </device>
  3. Create the mediated device.
    To create a persistent mediated device, use the virsh nodedev-define command. Persistent mediated devices for DASDs as VFIO pass-through build on CCW subchannels that are persistently controlled by the vfio_ccw device driver, see Assign the DASD's subchannel to the vfio_ccw device driver.

    For a transient mediated device, use the virsh nodedev-create command and a node-device XML file, or use general Linux® commands.

    • Follow these steps to create a persistent mediated device.
      1. Create the mediated device by issuing a virsh nodedev-define command with the node-device XML file as a command argument.

        In libvirt, the mediated device is represented with a prefix, mdev_, followed by a string that corresponds to the UUID with underscore characters (_) instead of hyphens (-), followed by a suffix that consists of an underscore character and the subchannel bus-ID with underscore characters (_) instead of dots (.).

      2. Add the device to the autostart configuration with the virsh nodedev-autostart command, so that the device is automatically activated after a host reboot.
      3. Activate the mediated device on the running KVM host with a virsh nodedev-start command.
      4. Optional: Confirm your settings for the mediated device with the virsh nodedev-info command.
      Example: This example uses a node-device XML file my_dasd_mdev.xml to create a mediated device. With a UUID 18e124fb-b2fc-47f6-a407-f256b6c49767, the resulting device in libvirt is mdev_18e124fb_b2fc_47f6_a407_f256b6c49767_0_0_0004.
      # virsh nodedev-define my_dasd_mdev.xml
      Node device 'mdev_18e124fb_b2fc_47f6_a407_f256b6c49767_0_0_0004' defined from my_dasd_mdev.xml
      # virsh nodedev-autostart mdev_18e124fb_b2fc_47f6_a407_f256b6c49767_0_0_0004
      # virsh nodedev-start mdev_18e124fb_b2fc_47f6_a407_f256b6c49767_0_0_0004
      Device mdev_18e124fb_b2fc_47f6_a407_f256b6c49767_0_0_0004 started
      # virsh nodedev-info mdev_18e124fb_b2fc_47f6_a407_f256b6c49767_0_0_0004
      Name:           mdev_18e124fb_b2fc_47f6_a407_f256b6c49767_0_0_0004
      Parent:         css_0_0_0004
      Active:         yes
      Persistent:     yes
      Autostart:      yes
      For more information about managing mediated devices with virsh commands and about creating a transient mediated device by using the virsh nodedev-create command, see Managing mediated devices with libvirt.
    • As an alternative to using virsh commands, create a transient mediated device by using a general Linux command.
      # echo <uuid> > /sys/bus/css/devices/<subchannel_bus_id>/mdev_supported_types/vfio_ccw-io/create
      In the command, <uuid> is the UUID you obtained in step 1.
      Example:
      # uuidgen
      18e124fb-b2fc-47f6-a407-f256b6c49767
      # echo 18e124fb-b2fc-47f6-a407-f256b6c49767 > \
      /sys/bus/css/devices/0.0.0004/mdev_supported_types/vfio_ccw-io/create
  4. Optional: Confirm that the mediated device maps to the intended DASD on the host.
    1. Confirm that the mediated device maps to the intended subchannel, by issuing a command of this form:
      virsh nodedev-dumpxml <mdev>
      where <mdev> is the representation of the mediated device in libvirt. In the command output, the parent element specifies the representation of the subchannel in libvirt.
      Example:
      # virsh nodedev-dumpxml mdev_18e124fb_b2fc_47f6_a407_f256b6c49767_0_0_0004
      <device>
        <name>mdev_18e124fb_b2fc_47f6_a407_f256b6c49767_0_0_0004</name>
        <path>/sys/devices/css0/0.0.0004/18e124fb_b2fc_47f6_a407_f256b6c49767</path>
        <parent>css_0_0_0004</parent>
        ...
      </device>
      
      The value css_0_0_0004 in the output resolves to subchannel ID 0.0.0004.
      As an alternative, you can use the lscss command to confirm this mapping.
      Example:
      # lscss --vfio
      MDEV                                  Subchan.  PIM PAM POM  CHPIDs
      ------------------------------------------------------------------------------
      18e124fb_b2fc_47f6_a407_f256b6c49767  0.0.0004  c0  c0  ff   34210000 00000000
      
    2. Confirm that the subchannel device maps to the device bus-ID of the intended DASD:
      virsh nodedev-dumpxml <subchannel>
      where <subchannel> is the representation of the subchannel in libvirt as shown in the previous command output. In the command output, the subelements of the channel_dev_addr element specify the device bus-ID of the DASD.
      Example:
      # virsh nodedev-dumpxml css_0_0_0004
      <device>
        <name>css_0_0_0004</name>
        <path>/sys/devices/css0/css_0_0_0004</path>
        ...
        <capability type='css'>
          <cssid>0x0</cssid>
          <ssid>0x0</ssid>
          <devno>0x0004</devno>
          <channel_dev_addr>
            <cssid>0x0</cssid>
            <ssid>0x0</ssid>
            <devno>0x3000</devno>
          </channel_dev_addr>
          ...
        </capability>
      </device>
      
      The values for the cssid, ssid, and devno elements resolve to a device bus-ID 0.0.3000 for the DASD.
      As an alternative, you can use the lscss command to confirm this mapping.
      Example:
      # lscss
      Device   Subchan.  DevType CU Type Use  PIM PAM POM  CHPIDs
      ----------------------------------------------------------------------
      ...
      0.0.1900 0.0.0002  1732/03 1731/03 yes  80  80  ff   1d000000 00000000
      0.0.3000 0.0.0004                       c0  c0  ff   34210000 00000000
      0.0.c60c 0.0.003c  3390/0c 3990/e9 yes  c0  c0  ff   34210000 00000000
      ...

What to do next

You can now use the mediated device to configure a virtual ECKD DASD as a pass-through device. See Configuring a pass-through DASD.