This document is relevant for: Inf2, Trn1, Trn2, Trn3
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:
Step |
Owner |
Control |
Effect |
|---|---|---|---|
|
Linux kernel (boot time) |
|
Host allocations come from a reserved region |
|
Neuron Runtime ( |
|
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_memsupport. Check the running kernel withuname -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 example16G.<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:
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:
sudo grubby --update-kernel=ALL --args="reserve_mem=16G:4096:neuron"
sudo reboot
After the instance reboots, confirm that the parameter was applied:
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:
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:
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.
This document is relevant for: Inf2, Trn1, Trn2, Trn3