1.. SPDX-License-Identifier: BSD-3-Clause 2 Copyright(c) 2010-2015 Intel Corporation. 3 Copyright 2017 Mellanox Technologies, Ltd 4 All rights reserved. 5 6.. _linux_gsg_linux_drivers: 7 8Linux Drivers 9============= 10 11Different PMDs may require different kernel drivers in order to work properly. 12Depending on the PMD being used, a corresponding kernel driver should be loaded, 13and network ports should be bound to that driver. 14 15VFIO 16---- 17 18VFIO is a robust and secure driver that relies on IOMMU protection. 19To make use of VFIO, the ``vfio-pci`` module must be loaded: 20 21.. code-block:: console 22 23 sudo modprobe vfio-pci 24 25VFIO kernel is usually present by default in all distributions, 26however please consult your distributions documentation to make sure that is the case. 27 28For DMA mapping of either external memory or hugepages, VFIO interface is used. 29VFIO does not support partial unmap of once mapped memory. Hence DPDK's memory is 30mapped in hugepage granularity or system page granularity. Number of DMA 31mappings is limited by kernel with user locked memory limit of a process (rlimit) 32for system/hugepage memory. Another per-container overall limit applicable both 33for external memory and system memory was added in kernel 5.1 defined by 34VFIO module parameter ``dma_entry_limit`` with a default value of 64K. 35When application is out of DMA entries, these limits need to be adjusted to 36increase the allowed limit. 37 38Since Linux version 5.7, 39the ``vfio-pci`` module supports the creation of virtual functions. 40After the PF is bound to ``vfio-pci`` module, 41the user can create the VFs using the ``sysfs`` interface, 42and these VFs will be bound to ``vfio-pci`` module automatically. 43 44When the PF is bound to ``vfio-pci``, 45by default it will have a randomly generated VF token. 46For security reasons, this token is write only, 47so the user cannot read it from the kernel directly. 48To access the VFs, the user needs to create a new token, 49and use it to initialize both VF and PF devices. 50The tokens are in UUID format, 51so any UUID generation tool can be used to create a new token. 52 53This VF token can be passed to DPDK by using EAL parameter ``--vfio-vf-token``. 54The token will be used for all PF and VF ports within the application. 55 56#. Generate the VF token by uuid command 57 58 .. code-block:: console 59 60 14d63f20-8445-11ea-8900-1f9ce7d5650d 61 62#. Load the ``vfio-pci`` module with ``enable_sriov`` parameter set 63 64 .. code-block:: console 65 66 sudo modprobe vfio-pci enable_sriov=1 67 68 Alternatively, pass the ``enable_sriov`` parameter through the ``sysfs`` if the module is already loaded or is built-in: 69 70 .. code-block:: console 71 72 echo 1 | sudo tee /sys/module/vfio_pci/parameters/enable_sriov 73 74#. Bind the PCI devices to ``vfio-pci`` driver 75 76 .. code-block:: console 77 78 ./usertools/dpdk-devbind.py -b vfio-pci 0000:86:00.0 79 80#. Create the desired number of VF devices 81 82 .. code-block:: console 83 84 echo 2 > /sys/bus/pci/devices/0000:86:00.0/sriov_numvfs 85 86#. Start the DPDK application that will manage the PF device 87 88 .. code-block:: console 89 90 <build_dir>/app/dpdk-testpmd -l 22-25 -n 4 -a 86:00.0 \ 91 --vfio-vf-token=14d63f20-8445-11ea-8900-1f9ce7d5650d --file-prefix=pf -- -i 92 93#. Start the DPDK application that will manage the VF device 94 95 .. code-block:: console 96 97 <build_dir>/app/dpdk-testpmd -l 26-29 -n 4 -a 86:02.0 \ 98 --vfio-vf-token=14d63f20-8445-11ea-8900-1f9ce7d5650d --file-prefix=vf0 -- -i 99 100To make use of full VFIO functionality, 101both kernel and BIOS must support and be configured 102to use IO virtualization (such as Intel® VT-d). 103 104.. note:: 105 106 Linux versions earlier than version 3.6 do not support VFIO. 107 108.. note:: 109 110 Linux versions earlier than version 5.7 do not support the creation of 111 virtual functions within the VFIO framework. 112 113.. note:: 114 115 In most cases, specifying "iommu=on" as kernel parameter should be enough to 116 configure the Linux kernel to use IOMMU. 117 118For proper operation of VFIO when running DPDK applications as a non-privileged user, correct permissions should also be set up. 119For more information, please refer to :ref:`Running_Without_Root_Privileges`. 120 121VFIO no-IOMMU mode 122------------------ 123 124If there is no IOMMU available on the system, VFIO can still be used, 125but it has to be loaded with an additional module parameter: 126 127.. code-block:: console 128 129 modprobe vfio enable_unsafe_noiommu_mode=1 130 131Alternatively, one can also enable this option in an already loaded kernel module: 132 133.. code-block:: console 134 135 echo 1 > /sys/module/vfio/parameters/enable_unsafe_noiommu_mode 136 137After that, VFIO can be used with hardware devices as usual. 138 139.. note:: 140 141 It may be required to unload all VFIO related-modules before probing 142 the module again with ``enable_unsafe_noiommu_mode=1`` parameter. 143 144.. warning:: 145 146 Since no-IOMMU mode forgoes IOMMU protection, it is inherently unsafe. 147 That said, it does make it possible for the user 148 to keep the degree of device access and programming that VFIO has, 149 in situations where IOMMU is not available. 150 151UIO 152--- 153 154In situations where using VFIO is not an option, there are alternative drivers one can use. 155In many cases, the standard ``uio_pci_generic`` module included in the Linux kernel 156can be used as a substitute for VFIO. This module can be loaded using the command: 157 158.. code-block:: console 159 160 sudo modprobe uio_pci_generic 161 162.. note:: 163 164 ``uio_pci_generic`` module doesn't support the creation of virtual functions. 165 166As an alternative to the ``uio_pci_generic``, there is the ``igb_uio`` module 167which can be found in the repository `dpdk-kmods <http://git.dpdk.org/dpdk-kmods>`_. 168It can be loaded as shown below: 169 170.. code-block:: console 171 172 sudo modprobe uio 173 sudo insmod igb_uio.ko 174 175.. note:: 176 177 If UEFI secure boot is enabled, 178 the Linux kernel may disallow the use of UIO on the system. 179 Therefore, devices for use by DPDK should be bound to the ``vfio-pci`` kernel module 180 rather than any UIO-based module. 181 For more details see :ref:`linux_gsg_binding_kernel` below. 182 183.. note:: 184 185 If the devices used for DPDK are bound to the ``uio_pci_generic`` kernel module, 186 please make sure that the IOMMU is disabled or is in passthrough mode. 187 One can add ``intel_iommu=off`` or ``amd_iommu=off`` or ``intel_iommu=on iommu=pt`` 188 in GRUB command line on x86_64 systems, 189 or add ``iommu.passthrough=1`` on aarch64 systems. 190 191.. note:: 192 193 Using UIO drivers is inherently unsafe due to this method lacking IOMMU protection, 194 and can only be done by root user. 195 196.. _bifurcated_driver: 197 198Bifurcated Driver 199----------------- 200 201PMDs which use the bifurcated driver co-exists with the device kernel driver. 202On such model the NIC is controlled by the kernel, while the data 203path is performed by the PMD directly on top of the device. 204 205Such model has the following benefits: 206 207 - It is secure and robust, as the memory management and isolation 208 is done by the kernel. 209 - It enables the user to use legacy linux tools such as ``ethtool`` or 210 ``ifconfig`` while running DPDK application on the same network ports. 211 - It enables the DPDK application to filter only part of the traffic, 212 while the rest will be directed and handled by the kernel driver. 213 The flow bifurcation is performed by the NIC hardware. 214 As an example, using :ref:`flow_isolated_mode` allows to choose 215 strictly what is received in DPDK. 216 217More about the bifurcated driver can be found in 218`Mellanox Bifurcated DPDK PMD 219<https://www.dpdk.org/wp-content/uploads/sites/35/2016/10/Day02-Session04-RonyEfraim-Userspace2016.pdf>`__. 220 221.. _linux_gsg_binding_kernel: 222 223Binding and Unbinding Network Ports to/from the Kernel Modules 224-------------------------------------------------------------- 225 226.. note:: 227 228 PMDs which use the bifurcated driver should not be unbound from their kernel drivers. 229 This section is for PMDs which use the UIO or VFIO drivers. 230 231As of release 1.4, DPDK applications no longer automatically unbind all supported network ports from the kernel driver in use. 232Instead, in case the PMD being used use the VFIO or UIO drivers, 233all ports that are to be used by a DPDK application must be bound to 234the ``vfio-pci``, ``uio_pci_generic``, or ``igb_uio`` module 235before the application is run. 236For such PMDs, any network ports under Linux* control will be ignored and cannot be used by the application. 237 238To bind ports to the ``vfio-pci``, ``uio_pci_generic`` or ``igb_uio`` module 239for DPDK use, or to return ports to Linux control, 240a utility script called ``dpdk-devbind.py`` is provided in the ``usertools`` subdirectory. 241This utility can be used to provide a view of the current state of the network ports on the system, 242and to bind and unbind those ports from the different kernel modules, 243including the VFIO and UIO modules. 244The following are some examples of how the script can be used. 245A full description of the script and its parameters can be obtained 246by calling the script with the ``--help`` or ``--usage`` options. 247Note that the UIO or VFIO kernel modules to be used, 248should be loaded into the kernel before running the ``dpdk-devbind.py`` script. 249 250.. warning:: 251 252 Due to the way VFIO works, there are certain limitations 253 to which devices can be used with VFIO. 254 Mainly it comes down to how IOMMU groups work. 255 Any Virtual Function device can usually be used with VFIO on its own, 256 but physical devices may require either all ports bound to VFIO, 257 or some of them bound to VFIO while others not being bound to anything at all. 258 259 If your device is behind a PCI-to-PCI bridge, 260 the bridge will then be part of the IOMMU group in which your device is in. 261 Therefore, the bridge driver should also be unbound from the bridge PCI device 262 for VFIO to work with devices behind the bridge. 263 264.. warning:: 265 266 While any user can run the ``dpdk-devbind.py`` script 267 to view the status of the network ports, 268 binding or unbinding network ports requires root privileges. 269 270To see the status of all network ports on the system: 271 272.. code-block:: console 273 274 ./usertools/dpdk-devbind.py --status 275 276 Network devices using DPDK-compatible driver 277 ============================================ 278 0000:82:00.0 '82599EB 10-GbE NIC' drv=uio_pci_generic unused=ixgbe 279 0000:82:00.1 '82599EB 10-GbE NIC' drv=uio_pci_generic unused=ixgbe 280 281 Network devices using kernel driver 282 =================================== 283 0000:04:00.0 'I350 1-GbE NIC' if=em0 drv=igb unused=uio_pci_generic *Active* 284 0000:04:00.1 'I350 1-GbE NIC' if=eth1 drv=igb unused=uio_pci_generic 285 0000:04:00.2 'I350 1-GbE NIC' if=eth2 drv=igb unused=uio_pci_generic 286 0000:04:00.3 'I350 1-GbE NIC' if=eth3 drv=igb unused=uio_pci_generic 287 288 Other network devices 289 ===================== 290 <none> 291 292To bind device ``eth1``,``04:00.1``, to the ``uio_pci_generic`` driver: 293 294.. code-block:: console 295 296 ./usertools/dpdk-devbind.py --bind=uio_pci_generic 04:00.1 297 298or, alternatively, 299 300.. code-block:: console 301 302 ./usertools/dpdk-devbind.py --bind=uio_pci_generic eth1 303 304To restore device ``82:00.0`` to its original kernel binding: 305 306.. code-block:: console 307 308 ./usertools/dpdk-devbind.py --bind=ixgbe 82:00.0 309 310Troubleshooting VFIO 311-------------------- 312 313In certain situations, using ``dpdk-devbind.py`` script 314to bind a device to VFIO driver may fail. 315The first place to check is the kernel messages: 316 317.. code-block:: console 318 319 dmesg | tail 320 ... 321 [ 1297.875090] vfio-pci: probe of 0000:31:00.0 failed with error -22 322 ... 323 324In most cases, the ``error -22`` indicates that the VFIO subsystem 325could not be enabled because there is no IOMMU support. 326 327To check whether the kernel has been booted with correct parameters, 328one can check the kernel command-line: 329 330.. code-block:: console 331 332 cat /proc/cmdline 333 334Please refer to earlier sections on how to configure kernel parameters 335correctly for your system. 336 337If the kernel is configured correctly, one also has to make sure that 338the BIOS configuration has virtualization features (such as Intel® VT-d). 339There is no standard way to check if the platform is configured correctly, 340so please check with your platform documentation to see if it has such features, 341and how to enable them. 342 343In certain distributions, default kernel configuration is such that 344the no-IOMMU mode is disabled altogether at compile time. 345This can be checked in the boot configuration of your system: 346 347.. code-block:: console 348 349 cat /boot/config-$(uname -r) | grep NOIOMMU 350 # CONFIG_VFIO_NOIOMMU is not set 351 352If ``CONFIG_VFIO_NOIOMMU`` is not enabled in the kernel configuration, 353VFIO driver will not support the no-IOMMU mode, 354and other alternatives (such as UIO drivers) will have to be used. 355