Files
nvdriver/docs/GPU_BRINGUP_GUIDE.md

15 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.
    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 31/31 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() currently requires a single-device IOMMU group containing only the supplied --bdf and refuses groups with sibling devices. Server cards (V100/P100/P40) typically satisfy this out of the box; consumer multi-function cards (.1 HDA audio, .2 USB-C, .3 UCSI) must either be isolated into a single-device IOMMU group or have all sibling functions in the group bound to vfio-pci and passed to 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)

set -eu
BDF=0000:01:00.0

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

# Test NVML and CUDA with short timeouts (treat any timeout or nonzero status as a stop signal)
timeout 15 nvidia-smi
timeout 15 python3 -c 'import ctypes, sys; cu=ctypes.CDLL("libcuda.so.1"); rc=cu.cuInit(0); print("cuInit:", rc); sys.exit(0 if rc == 0 else 1)'

# Clean unload
echo "$BDF" | sudo tee /sys/bus/pci/drivers/nvidia_rs/unbind >/dev/null
sudo rmmod nvidia_rs

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.
  • 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.

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.