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