.. meta::
   :description: Enable Neuron Secure Mode on Trn2 and Trn3 to restrict each Neuron device to a reserved region of host memory, using a reserve_mem kernel reservation and the NEURON_RT_SECURE_MODE environment variable.
   :date-modified: 2026-11-16
   :keywords: Neuron, Neuron Runtime, Neuron Driver, Secure Mode, NEURON_RT_SECURE_MODE, reserve_mem, host memory, DMA, bounce buffers

.. _nrt-secure-mode:

================================
How to enable Neuron Secure Mode
================================

Task overview
-------------

Secure Mode (also called Secure Neuron) limits which host addresses a Neuron device can reach over
the host PCIe link. At load time, the Neuron Driver takes one contiguous host region from a boot-time
memory reservation and serves every host allocation from it. The device firmware then programs the
device's host-side address translation regions so that the device can reach only that region.

When Secure Mode is on, every host-to-device DMA goes through bounce buffers inside the reserved
region instead of going directly to pinned user pages. This can reduce host-to-device transfer
throughput.

Enabling Secure Mode takes two steps, and both are required:

.. list-table::
   :header-rows: 1
   :widths: 25 20 25 30

   * - Step
     - Owner
     - Control
     - Effect
   * - 1. Reserve host memory
     - Linux kernel (boot time)
     - ``reserve_mem=`` on the kernel command line
     - Host allocations come from a reserved region
   * - 2. Apply Secure Mode
     - Neuron Runtime (``nrt_init()``)
     - ``NEURON_RT_SECURE_MODE=1``
     - Firmware restricts device access to the reserved region; host-to-device DMAs switch to bounce buffers

Prerequisites
-------------

- **Instance type:** Trn2 or Trn3.
- **Linux kernel:** 6.11 or later, for ``reserve_mem`` support. Check the running kernel with
  ``uname -r``.
- **Neuron Driver:** 2.32 or later.
- **Neuron Runtime Library:** 2.36 or later.

Instructions
------------

**1:** Reserve host memory for the Neuron Driver

Add a ``reserve_mem`` reservation to the kernel command line, then reboot. Reserve about 1 GiB per
Neuron device, for example 16 GiB on an instance with 16 devices.

The format is ``reserve_mem=<size>:<align>:neuron``:

- ``<size>`` is the total size of the reservation, for example ``16G``.
- ``<align>`` is the alignment of the reservation's base address. It must be a power of two and at
  least 4096 (4 KiB).
- The name must be ``neuron``.

On **Ubuntu**, add the reservation in a GRUB drop-in file, regenerate the GRUB configuration, and
reboot:

.. code-block:: bash

   echo 'GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX reserve_mem=16G:4096:neuron"' | \
     sudo tee /etc/default/grub.d/99-neuron-secure-mode.cfg
   sudo update-grub
   sudo reboot

On **Amazon Linux 2023, Rocky Linux, and RHEL**:

.. code-block:: bash

   sudo grubby --update-kernel=ALL --args="reserve_mem=16G:4096:neuron"
   sudo reboot

After the instance reboots, confirm that the parameter was applied:

.. code-block:: bash

   grep -o 'reserve_mem=[^ ]*' /proc/cmdline

The output shows the reservation, for example ``reserve_mem=16G:4096:neuron``. If there is no
output, the parameter wasn't applied.

**2:** Apply Secure Mode from the Neuron Runtime

Set ``NEURON_RT_SECURE_MODE`` in the environment of every process that uses the Neuron Runtime:

.. code-block:: bash

   export NEURON_RT_SECURE_MODE=1

``NEURON_RT_SECURE_MODE`` defaults to ``false``. When it is set, ``nrt_init()`` asks the Neuron
Driver to apply Secure Mode on each device before resetting the NeuronCores.

If Secure Mode can't be applied, ``nrt_init()`` fails with:

.. code-block:: text

   Failed to enable Secure Mode for nd <N>, error:<err>

Check ``dmesg`` for the reason reported by the Neuron Driver.

Disabling Secure Mode
---------------------

Once Secure Mode is applied to a device, it stays on. Setting ``NEURON_RT_SECURE_MODE=0``, or leaving
it unset, in later processes does **not** turn it off. To disable Secure Mode, reboot the instance.

Security considerations
-----------------------

The Neuron Driver interface that ``NEURON_RT_SECURE_MODE`` uses accepts up to 7 additional host
memory regions, on top of the region the driver reserves. The Neuron Runtime never passes additional
regions, but an application that calls the driver directly, without the Neuron Runtime, can. An
untrusted application could use this to give the device access to all of host memory.

Only the first request on each device takes effect. If an application has already applied Secure
Mode with additional regions, a later ``NEURON_RT_SECURE_MODE=1`` fails, because the requested
regions don't match the ones already programmed. ``nrt_init()`` returns an error, and the Neuron
Driver logs an error indicating that the regions differ. Treat this failure as a sign that the
device's Secure Mode configuration can't be trusted, and reboot the instance before running
workloads.

.. warning::

   Secure Mode does not isolate Neuron devices from each other, so it does not make it safe to share
   an instance between tenants. Devices can still access each other's device memory.
