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