Files
nvdriver/docs/GPU_BRINGUP_GUIDE.md

21 KiB
Raw Permalink Blame History

GPU Bring-Up & Hardware Testing Guide

This guide explains how contributors can safely test nvdriver on new NVIDIA GPU families (Maxwell through Blackwell), capture actionable diagnostic reports, and follow the REA-first parity workflow.


1. Bricking Risk & Hardware Safety

  • No permanent bricking risk: nvdriver never flashes VBIOS, InfoROM, SPI ROM, or fuses. All register writes are volatile and cleared on power cycle.
  • Worst-case failure mode: On untested silicon, a bug in engine bring-up or GSP-RM boot can cause a GPU hang, a host kernel oops, or leave the card in a state where stock nvidia.ko requires a reboot / power cycle to re-initialize.
  • Golden rules for safe testing:
    1. Prefer a disposable VFIO QEMU/KVM VM (tools/vm/run_vfio_guest.py) whenever your host has IOMMU enabled. A guest panic exits cleanly without tainting or rebooting your host kernel, and a guest hang is bounded by the runner's default 90-second wall-clock timeout (configurable with --timeout <seconds>).
    2. Never reset a GPU via sysfs (.../reset, .../remove + rescan, or setpci bridge resets) on a host where stock nvidia.ko may be reloaded — many boards cannot recover without a full power cycle.
    3. Stop all GPU services before unbinding stock nvidia.ko: Ensure no display manager, nvidia-persistenced, container, or compute process holds /dev/nvidia* open before unbinding. On a live swap where stock nvidia.ko remains installed on disk, run sudo udevadm settle --timeout=10 && sudo udevadm control --stop-exec-queue before rmmod nvidia (draining any in-flight workers before freezing the queue) (and sudo udevadm control --start-exec-queue after reverting — and also after any failed or aborted swap step, since the queue is system-wide and events for unrelated devices stay queued until it restarts) so udev's PCI modalias rule does not immediately re-load stock nvidia before insmod nvidia_rs.ko (nvidia_rs intentionally ships no PCI modalias).
    4. Use short timeouts on every /dev/nvidia* command and treat a hang as a stop signal: Run timeout 15 nvidia-smi / timeout 15 ./probe to bound userspace stalls. Warning: a process blocked in kernel uninterruptible sleep (D state) cannot respond to timeout signals until the kernel wait wakes, so timeout does not protect against a wedged driver open; if a command hangs, stop immediately and do not open /dev/nvidia* again.
    5. Keep an SSH / root console open and pass pci_target=<bdf> to bind only the single GPU under test.

2. Driver Versions, ABI & Firmware

Branch / Component Status in nvdriver Notes
580.178.04 Primary parity baseline Default target for Pre-GSP (GM10x–GV100), GSP-RM (TU10x–GB20x), nvidia-uvm bridge, and nvidia-modeset bridge.
Other 580.x (e.g. 580.196.07) Supported via driver_version=<ver> Pass driver_version=580.196.07 so userspace libcuda.so / libnvidia-ml.so version checks match. Bridge CRCs require matching stock .ko modules on the host.
620.73.04 / 620.70.06 GSP / STOCK_ABI support Makefile auto-detects STOCK_ABI from modinfo -F version nvidia; see docs/KERNEL_COMPAT.md.

Extracting Firmware Blobs

  • Pre-GSP (Maxwell / Pascal / Volta): Extract the signed firmware pack from your installed 580.178.04 package into /lib/firmware/nvidia-rs/580.178.04/ (or run ./install.sh, which handles extraction automatically):
    python3 tools/extract_gv100_firmware.py --help
    # Example (Volta GV100; use --family gm20x|gp100|gp10x|all for Maxwell/Pascal):
    sudo python3 tools/extract_gv100_firmware.py --family gv100 --out /lib/firmware/nvidia-rs/580.178.04/gv100.fw
    
  • GSP-RM (Turing / Ampere / Hopper / Ada / Blackwell): Stage the matching 580.178.04 gsp_*.bin under /lib/firmware/nvidia/580.178.04/ (and extract RISC-V boot ucode if needed via python3 tools/extract_gsp_boot_ucode.py --help), then boot with gsp_abi=580.

3. Step 1 — Run Offline Validation First

Before touching any physical GPU or loading any kernel module on the host, verify that the tree builds cleanly and passes all offline checks and software QEMU EDU guest tests:

# Strictly offline checks (no host module load, no physical GPU access):
cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
python3 tests/kernel-module-gate/test_gate_cases.py
python3 tests/kernel-module-gate/test_kernel_archive.py
make modules
make -C src/nvidia audit-codegen
python3 tools/check_native_codegen.py

# Build and run the software QEMU EDU guest checks (no GPU passthrough):
sh tools/vm/build_guest_test.sh
sh tools/vm/build_initramfs.sh
python3 tools/vm/run_guest.py
python3 tools/vm/run_guest.py --iommu
python3 tests/vm/test_result_gate.py

Important

Before any hardware run (Step 2 or Step 3), run the full 36/36 validation gate on a quiet tree (sh tools/validate_all.sh, which runs all offline checks, component suites, software QEMU EDU guests, and the empty-pci_target live control check via sudo -n python3 tools/run_live_control.py). Use the strictly offline commands above only while iterating locally before you are ready to run the full gate.

Key kernel-module hygiene invariants enforced automatically by tools/check_kernel_module.py:

  • 0 unsupported GOT relocations (R_X86_64_GOTPCREL)
  • 0 calls to memcpy / memset / memmove in Rust objects
  • 0 SIMD / x87 / FPU register usage
  • Fixed function stack frames <= 1,024 bytes
  • Full kernel hardening compatibility (retpoline, rethunk, SLS, IBT, CONFIG_CALL_PADDING)

Prerequisites

  1. Enable IOMMU in kernel cmdline (intel_iommu=on iommu=pt on Intel, amd_iommu=on iommu=pt on AMD) and reboot.
  2. Verify your GPU's PCI BDF and IOMMU group:
    lspci -nnD | grep -i nvidia
    ls -la /sys/bus/pci/devices/0000:01:00.0/iommu_group/devices/
    
    Single-function server cards (V100/P100/P40) have only .0; consumer cards (Turing–Blackwell) typically share the group with sibling functions on the same slot (.1 HDA audio, .2 USB-C, .3 UCSI).
  3. Stop any process holding /dev/nvidia* open (lsof /dev/nvidia* or fuser -v /dev/nvidia*).

Run Inside a Disposable VM

Important

tools/vm/run_vfio_guest.py's ensure_vfio_bound() accepts single-device IOMMU groups (typical for server cards such as V100/P100/P40) and also consumer multi-function GPU groups (.0 GPU + .1 HDA audio + .2 USB-C + .3 UCSI), provided every member of the group sits on the same PCI slot (domain:bus:slot). It binds all same-slot members to vfio-pci itself; only a group containing an unrelated PCI device (a different slot) is refused — in that case move the unrelated devices to their own group or use a manual QEMU invocation instead.

# Example: Volta / Pascal headless card (single-device IOMMU group)
python3 tools/vm/run_vfio_guest.py \
  --bdf 0000:b3:00.0 \
  --cmd 'timeout 15 nvidia-smi -q > /tmp/smi.txt; s=$?; head -n 60 /tmp/smi.txt; [ "$s" -eq 0 ]'

# Example: Turing card in an isolated single-device IOMMU group (sm_70 cubin is valid on Volta/Turing;
# for Ampere/Ada/Blackwell, compile and pass a cubin targeting your GPU's compute capability, e.g. sm_86/sm_89)
python3 tools/vm/run_vfio_guest.py \
  --bdf 0000:01:00.0 \
  --modparams 'gsp_abi=580' \
  --cmd 'timeout 15 nvidia-smi && timeout 15 /repo/target/hardware-hello/cuda-parity-suite /repo/target/hardware-hello/native_hello.sm70.cubin "$GPU_BDF"'

Logs and structured JSON results are saved automatically under reports/vfio-guest-<bdf_underscored>-rust.{log,json} (with : and . replaced by _, e.g. reports/vfio-guest-0000_b3_00_0-rust.{log,json}).


5. Step 3 — Bare-Metal Staged Bring-Up (BRINGUP=0..9)

When testing directly on bare metal (or inside a VM to isolate which boot stage fails), start conservatively and increase one stage at a time:

Parameter Behavior
bringup=0 runtime_engines=0 Software-only gate — zero hardware register writes.
bringup=1..3 MC engine enable, PTIMER init, pre-stage engine reset.
bringup=4 BAR2 page-table & instance-block setup.
bringup=5 NVDEC HS Falcon run + reset.
bringup=6 PFIFO host load + unload.
bringup=7 PGRAPH InitLocked / StateLoad / StateUnload with BAR2 bound.
bringup=8 OBJACR Load / Unload on SEC2 / PMU.
bringup=9 Full LS PMU / SEC2 / FECS / GPCCS + golden GR context + reverse-order unload.
runtime_engines=1 Full bring-up + persistent runtime engines for nvidia-smi / CUDA / UVM.

Stage 3a — Staged Bring-Up (bringup=0..9, one stage at a time)

If the GPU was previously bound to vfio-pci (for example after running Step 2), release vfio-pci and clear its driver_override first so nvidia_rs can claim the device:

BDF=0000:01:00.0
if [ -e "/sys/bus/pci/drivers/vfio-pci/$BDF" ]; then
  echo "$BDF" | sudo tee /sys/bus/pci/drivers/vfio-pci/unbind >/dev/null
fi
echo "" | sudo tee "/sys/bus/pci/devices/$BDF/driver_override" >/dev/null

Then run each stage one at a time, starting at bringup=0 (software-only gate, zero hardware register writes) and advancing through bringup=9.

Note

On the GV100/pre-GSP path with runtime_engines=0, finish_result intentionally returns -95 (EOPNOTSUPP) after tearing down a clean diagnostic stage (GSP-RM returns earlier from boot_gsp_rm). However, errno 95 alone does not prove success because stage errors can also map to -95. Always treat any timeout or any errno other than 95 as an immediate failure, and verify the stage-specific dmesg diagnostics (nvidia_rs / NVRM / bringup note, confirming expected milestones and clean teardown with zero error statuses) before advancing to the next stage or loading runtime_engines=1.

set -eu
BDF=0000:01:00.0
STAGE=0  # advance 0 -> 1 -> ... -> 9 only after confirming stage diagnostics in dmesg

# Record the latest timestamped dmesg boundary before loading (scan backward so multiline
# messages cannot reset the boundary; abort if no timestamped kernel line is found)
DMESG_START_TS=$(sudo dmesg | python3 -c "
import re, sys
pat = re.compile(r'^\[\s*([0-9]+\.[0-9]+)\]')
for line in reversed(sys.stdin.read().splitlines()):
    m = pat.match(line)
    if m:
        print(m.group(1))
        sys.exit(0)
print('STOP: could not determine dmesg timestamp boundary', file=sys.stderr)
sys.exit(1)
")

# Show ALL kernel messages logged after DMESG_START_TS (including IOMMU/DMAR/AMD-Vi faults,
# kernel warnings/oopses, and driver milestones — not just filtered driver lines)
dmesg_since_start() {
  sudo dmesg | python3 -c "
import re, sys
start = float(sys.argv[1])
pat = re.compile(r'^\[\s*([0-9]+\.[0-9]+)\]')
emit = False
for line in sys.stdin:
    m = pat.match(line)
    if m:
        emit = float(m.group(1)) > start
    if emit:
        sys.stdout.write(line)
" "$DMESG_START_TS"
}

sudo insmod kernel-open/nvidia_rs.ko \
  "pci_target=$BDF" \
  driver_version=580.178.04 \
  "bringup=$STAGE" runtime_engines=0

# Trigger nv_rs_gpu_first_open() with a short timeout (with runtime_engines=0,
# insmod only registers the GPU; stages execute on first open of the device node).
# On GV100/pre-GSP with runtime_engines=0, errno 95 (EOPNOTSUPP) is returned on
# clean teardown, so accept errno 95 here ONLY to proceed to dmesg verification;
# treat timeouts and any other errno as an immediate STOP.
if ! sudo timeout 15 python3 -c "
import errno, os, sys
try:
    fd = os.open('/dev/nvidia-rs-$BDF', os.O_RDWR)
    os.close(fd)
    print('open returned 0')
except OSError as exc:
    if exc.errno == errno.EOPNOTSUPP:
        print('open returned EOPNOTSUPP (95): verify stage milestones in dmesg below before advancing')
    else:
        print(f'unexpected open error: errno={exc.errno} ({exc})', file=sys.stderr)
        sys.exit(1)
"; then
  echo "STOP: bringup=$STAGE first-open failed unexpectedly or timed out; inspect dmesg and report." >&2
  dmesg_since_start
  exit 1
fi

# Required: confirm bringup=$STAGE completed cleanly in THIS run's dmesg (no error status / fault)
# before advancing to STAGE+1 or Stage 3b.
dmesg_since_start

# Clean unload before advancing to the next stage
echo "$BDF" | sudo tee /sys/bus/pci/drivers/nvidia_rs/unbind >/dev/null
sudo rmmod nvidia_rs

Stage 3b — Persistent Runtime Engines (Only After bringup=0..9 All Succeed)

Run this stage in a root shell — sudo bash, which keeps your working directory (sudo -i also works but drops you in /root, and every path below is relative to the repo): the module operations need root. The block keeps the fd that starts the runtime worker open in the same process that runs the checks, so the session cannot be closed out from under them. That fd is the RMAPI GPU session node (/dev/nvidia-rs-rmapi-gpu<minor>), not the direct GPU node: the direct node's open runs the first-open path under misc_mtx with no runtime worker, and its park wait returns immediately (kernel-open/nvidia/gpu_owner.c:550, nv_rs_runtime_park_wait), so it tears the engines down again before the open returns. The block below resolves this GPU's minor from its own proc page (created at probe, rmapi_node.c:4395) and opens the session node first; that open starts the runtime worker, which parks with the engines live.

# Strict mode: a failed insmod, a missing node, or a failed unbind must stop
# the stage here - without this the block falls through to the unbind/rmmod
# and can exit 0 without any check having passed.
set -euo pipefail
BDF=0000:01:00.0

# Every exit after a successful insmod leaves the module loaded and this GPU bound,
# and closing an fd is not a stop request — so a retry would fail at insmod. Print
# the cleanup for every failure path, not only the one at the end.
stage3b_fail() {
  echo "$1" >&2
  echo "  echo $BDF | tee /sys/bus/pci/drivers/nvidia_rs/unbind >/dev/null; rmmod nvidia_rs" >&2
  exit 1
}

insmod kernel-open/nvidia_rs.ko \
  "pci_target=$BDF" \
  driver_version=580.178.04 \
  runtime_engines=1

# PASS CONDITIONS for Stage 3b — all four must hold before advancing.
# Do NOT verify with `nvidia-smi` or `cuInit(0)`: this driver publishes no
# stock `/dev/nvidiactl`/`/dev/nvidia0` ABI (its device nodes are
# nvidia-rs-<bdf> / nvidia-rs-rmapi-ctl / -gpu<N> / -uvm, plus an
# nvidia-caps region and a 0600 diagnostic node nvidia-rsctl), so both
# tools fail on a healthy bring-up and their exit status carries no signal.

INFO="/proc/driver/nvidia/gpus/$BDF/information"
[ -r "$INFO" ] || stage3b_fail "cannot read $INFO"
# Resolve the target minor before any open; the proc page is created at probe
# (`rmapi_node.c:4395`). Do NOT open the direct GPU node here: its first-open
# path has no runtime worker and tears the engines down before the open returns.
MINOR=$(sed -n 's/^Device Minor:[[:space:]]*\([0-9]\+\)$/\1/p' "$INFO")
[ -n "$MINOR" ] || stage3b_fail "no readable Device Minor in $INFO"
SESSION="/dev/nvidia-rs-rmapi-gpu$MINOR"
[ -e "$SESSION" ] || { ls -l /dev/nvidia-rs-* >&2 || true; stage3b_fail "missing $SESSION for this GPU"; }

# The session open and checks 1-4 run in ONE timed helper. The fd must live in the
# process that runs the checks, and a stalled first open must not leave a root
# shell sitting in it. `timeout` bounds interruptible stalls only: a process
# blocked in an uninterruptible kernel wait (D state) is not woken by a signal,
# so a timeout here is a stop signal, not a rescue. Closing the fd later does
# not stop the runtime worker; a stop request does (see the note below).
if ! timeout 15 bash -euo pipefail -c '
  SESSION=$1; INFO=$2
  exec 9<"$SESSION"                        # 1) session open: the runtime worker starts and parks

  grep -q . "$INFO"                        # 2) the GPU proc page is populated
  cat "$INFO"

  # 3) the node held on fd 9 belongs to this GPU: the minor the proc page
  #    names now must match the one resolved before the open. A wildcard would
  #    pass when no session node exists at all (nullglob removes the pattern) or
  #    when the node belongs to another GPU.
  MINOR=$(sed -n "s/^Device Minor:[[:space:]]*\([0-9]\+\)$/\1/p" "$INFO")
  [ -n "$MINOR" ] || { echo "no readable Device Minor in $INFO" >&2; exit 1; }
  [ "$SESSION" = "/dev/nvidia-rs-rmapi-gpu$MINOR" ] || { echo "held $SESSION but proc page names minor $MINOR" >&2; exit 1; }

  # 4) the control and UVM nodes open WHILE the session fd is held
  for node in /dev/nvidia-rs-rmapi-ctl /dev/nvidia-rs-uvm; do
    true <"$node"
  done
' _ "$SESSION" "$INFO"; then
  stage3b_fail "STOP: Stage 3b checks failed or did not complete within the timeout; inspect dmesg and report."
fi

# The helper has exited and fd 9 is closed. Closing the session fd does not stop
# the runtime worker: it stays parked with the engines live until a stop request.
# The unbind below is that stop request (`nv_rs_rmapi_node_gpu_remove` ->
# `nv_rs_gpu_owner_runtime_stop`, `rmapi_node.c:4573`), and it is what makes the
# unload clean.

# Clean unload — keep this: it was already correct
echo "$BDF" | tee /sys/bus/pci/drivers/nvidia_rs/unbind >/dev/null
rmmod nvidia_rs

Do not add a stage number to this invocation. With an explicit bringup=N where N > 0, resolve_bringup_mode() (src/nvidia/kernel/adapter_start.rs) silently forces runtime engines OFF regardless of the runtime_engines=1 parameter — diagnostic staging always takes precedence over runtime mode. Stage 3b is passed with no bringup= at all; a well-meant bringup=9 here turns this check into a staging run with no runtime to verify.

Decoding Common bringup note & RM Control Logs

  • 4c470001..4c470004: Legacy Maxwell/Pascal pre-GSP bring-up stage milestones (firmware pack, ACR, FECS golden context size, runtime active).
  • 47520001..4752001a: Volta GV100 GR/engine milestones (4752001a 00000000 confirms clean teardown).
  • 47530001..47530003: GSP-RM boot milestones.
  • fb_size=0x... in bring-up logs: BAR1 aperture size, not total VRAM (mapped from gpu.bar1_size in rmapi_node.rs); total VRAM is reported on the FB length line in the same dmesg output.
  • RM_CONTROL 0x2080xxxx status 0x56 (NV_ERR_NOT_SUPPORTED), 0x57 (NV_ERR_OBJECT_NOT_FOUND), or 0x1f (NV_ERR_INVALID_ARGUMENT): Identifies the exact RM control command that nvidia-smi or libcuda.so expected for your architecture. 0x56 has two distinct causes: the command can be genuinely unimplemented for the addressed class on this chip generation, or the command can simply have been sent to an object whose class does not own it — see below before diagnosing an architecture gap.

To tell the two 0x56 cases apart, resolve who owns the command before blaming silicon. Dispatch looks up the command id against the addressed object's class and then its ancestor classes (the resControlLookup walk in src/nvidia/src/rmapi/server.rs; legacy v1 converter commands are synthesized separately) and returns NOT_SUPPORTED when neither owns it, before any handler executes — leaving the parameter buffer exactly as the caller passed it. Each exported method's owning class is the first field of its row in src/nvidia/src/rmapi/control_table.rs; the target object's client-facing class and the internal class those rows key on are both in src/nvidia/src/resources.rs (for example: client 0x0080 → internal 0xe0ac20 device, 0x2080 → 0x4b01b3 subdevice, 0x2081 → 0xb7a47c binary API). Compare through the internal class — including ancestors — and a mismatch localizes the 0x56 to addressing, not to missing hardware support.


6. Step 4 — Filing a GPU Bring-Up Report

When opening a GPU Bring-Up Report issue on GitHub, please include:

  1. Hardware & environment: lspci -nnD | grep -i nvidia, uname -r, distro, and installed NVIDIA userspace version (modinfo -F version nvidia or nvidia-smi --version).
  2. Exact commit & build command: git rev-parse --short HEAD and whether you ran in VFIO or bare metal.
  3. dmesg excerpt: dmesg | grep -E 'nvidia_rs|NVRM|BUG|Oops|Call Trace' covering load, workload, and unload.
  4. Userspace results: Output of nvidia-smi, cuInit, and the first failing RM/UVM control hex code (if any).
  5. Stock baseline comparison (optional): Output of the same command under stock nvidia.ko for side-by-side parity reference.

7. Step 5 — Exact-Logic REA Workflow (Fixing Divergences)

nvdriver follows a strict REA-first discipline — never guess register offsets, bitmasks, or RM status codes:

  1. Locate the failing RM control code (e.g. 0x20802a0a) in src/nvidia/src/rmapi/control_table.rs to find its 580.178.04 handler index (_nv<N>rm).
  2. Disassemble / decompile _nv<N>rm and its HAL callees in NVIDIA 580.178.04's nv-kernel.o_binary (using Ghidra / objdump -dr) to recover exact struct layouts, field offsets, per-architecture HAL tables, and error ordering.
  3. Implement the clean-room Rust algorithm in #![no_std], add unit tests covering every architecture branch and error code, and verify tools/validate_all.sh + make modules before re-testing on hardware.

See docs/PARITY_AND_UNLOCKS.md and docs/REPLAY_TESTING.md for current architecture parity status and offline replay testing details.