Skip to content

Commit

Permalink
doc: add more instructions for running as non-root
Browse files Browse the repository at this point in the history
The guide to run DPDK applications as non-root in Linux
did not provide specific instructions to configure the required access
and did not explain why each bit is needed.
The latter is important because running as non-root
is one of the ways to tighten security and grant minimal permissions.

Cc: [email protected]

Signed-off-by: Dmitry Kozlyuk <[email protected]>
Acked-by: Bruce Richardson <[email protected]>
  • Loading branch information
dkozlyuk authored and tmonjalo committed Jun 27, 2022
1 parent 8d73de6 commit 979bb5d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 27 deletions.
90 changes: 63 additions & 27 deletions doc/guides/linux_gsg/enable_func.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,64 @@ Enabling Additional Functionality
Running DPDK Applications Without Root Privileges
-------------------------------------------------

In order to run DPDK as non-root, the following Linux filesystem objects'
permissions should be adjusted to ensure that the Linux account being used to
run the DPDK application has access to them:
The following sections describe generic requirements and configuration
for running DPDK applications as non-root.
There may be additional requirements documented for some drivers.

* All directories which serve as hugepage mount points, for example, ``/dev/hugepages``
Hugepages
~~~~~~~~~

* If the HPET is to be used, ``/dev/hpet``
Hugepages must be reserved as root before running the application as non-root,
for example::

sudo dpdk-hugepages.py --reserve 1G

If multi-process is not required, running with ``--in-memory``
bypasses the need to access hugepage mount point and files within it.
Otherwise, hugepage directory must be made accessible
for writing to the unprivileged user.
A good way for managing multiple applications using hugepages
is to mount the filesystem with group permissions
and add a supplementary group to each application or container.

One option is to use the script provided by this project::

export HUGEDIR=$HOME/huge-1G
mkdir -p $HUGEDIR
sudo dpdk-hugepages.py --mount --directory $HUGEDIR --user `id -u` --group `id -g`

In production environment, the OS can manage mount points
(`systemd example <https://github.com/systemd/systemd/blob/main/units/dev-hugepages.mount>`_).

The ``hugetlb`` filesystem has additional options to guarantee or limit
the amount of memory that is possible to allocate using the mount point.
Refer to the `documentation <https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt>`_.

.. note::

Using ``vfio-pci`` kernel driver, if applicable, can eliminate the need
for physical addresses and therefore eliminate the permission requirements
described below.

If the driver requires using physical addresses (PA),
the executable file must be granted additional capabilities:

* ``SYS_ADMIN`` to read ``/proc/self/pagemaps``
* ``IPC_LOCK`` to lock hugepages in memory

.. code-block:: console
setcap cap_ipc_lock,cap_sys_admin+ep <executable>
If physical addresses are not accessible,
the following message will appear during EAL initialization::

EAL: rte_mem_virt2phy(): cannot open /proc/self/pagemap: Permission denied

It is harmless in case PA are not needed.

Resource Limits
~~~~~~~~~~~~~~~

When running as non-root user, there may be some additional resource limits
that are imposed by the system. Specifically, the following resource limits may
Expand All @@ -34,8 +85,13 @@ need to be adjusted in order to ensure normal DPDK operation:
The above limits can usually be adjusted by editing
``/etc/security/limits.conf`` file, and rebooting.

Additionally, depending on which kernel driver is in use, the relevant
resources also should be accessible by the user running the DPDK application.
See `Hugepage Mapping <hugepage_mapping>`_
section to learn how these limits affect EAL.

Device Control
~~~~~~~~~~~~~~

If the HPET is to be used, ``/dev/hpet`` permissions must be adjusted.

For ``vfio-pci`` kernel driver, the following Linux file system objects'
permissions should be adjusted:
Expand All @@ -45,26 +101,6 @@ permissions should be adjusted:
* The directories under ``/dev/vfio`` that correspond to IOMMU group numbers of
devices intended to be used by DPDK, for example, ``/dev/vfio/50``

.. note::

The instructions below will allow running DPDK with ``igb_uio`` or
``uio_pci_generic`` drivers as non-root with older Linux kernel versions.
However, since version 4.0, the kernel does not allow unprivileged processes
to read the physical address information from the pagemaps file, making it
impossible for those processes to be used by non-privileged users. In such
cases, using the VFIO driver is recommended.

For ``igb_uio`` or ``uio_pci_generic`` kernel drivers, the following Linux file
system objects' permissions should be adjusted:

* The userspace-io device files in ``/dev``, for example, ``/dev/uio0``, ``/dev/uio1``, and so on

* The userspace-io sysfs config and resource files, for example for ``uio0``::

/sys/class/uio/uio0/device/config
/sys/class/uio/uio0/device/resource*


Power Management and Power Saving Functionality
-----------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions doc/guides/prog_guide/env_abstraction_layer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ Normally, these options do not need to be changed.
can later be mapped into that preallocated VA space (if dynamic memory mode
is enabled), and can optionally be mapped into it at startup.

.. _hugepage_mapping:

Hugepage Mapping
^^^^^^^^^^^^^^^^

Expand Down

0 comments on commit 979bb5d

Please sign in to comment.