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