Files
nvdriver/docs/REPLAY_TESTING.md
LIghtJUNction ac4c31c12d tools: ioctl capture/replay workflow with normalized 620.73.04 golden transcripts (#120)
LD_PRELOAD ioctl recorder, replay_diff.py, capture_stock.sh, replay_live.sh,
golden stock 620.73.04 transcript + known-gaps, and an offline control test.
Stock swap is opt-in via NV_RS_CAPTURE_BDF. No HANDOFF.md/AGENTS.md changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-12-01 13:06:44 -05:00

3.4 KiB

Replay testing against the stock driver

Real ioctl transcripts of the stock NVIDIA 620.73.04 open modules, recorded on the RTX 4060 Laptop (AD107), compared with what nvidia_rs does for the same workloads. Three layers:

Layer Needs hardware Command Catches
Offline table check no cd src/nvidia && cargo test --test stock_capture_controls a control the stock driver serves that our tables lack or size differently
Live replay gate yes (nvidia_rs loaded) sh tools/ioctl_capture/replay_live.sh any new divergence from the stock transcript: status, missing or extra steps
Re-record yes, swaps drivers tools/ioctl_capture/capture_stock.sh swap / run / restore refreshes captures/stock/ and the golden after a driver or firmware bump

Files

  • tools/ioctl_capture/nv_ioctl_capture.c: LD_PRELOAD shim; records each /dev/nvidia* ioctl (top struct before/after, and the RM_CONTROL/RM_ALLOC parameter buffer) as JSONL. It only reads memory. Nested pointers inside parameter buffers are not followed.
  • tools/ioctl_capture/capture_stock.sh: swap (nvidia_rs → stock modules), run NAME -- CMD (record into captures/NAME.jsonl), restore (stock → nvidia_rs through dev_reload.sh). CAPTURE_SUDO=sudo is needed against nvidia_rs when dev mode makes the nodes root-only.
  • tools/ioctl_capture/replay_diff.py: golden reduces raw captures to a handle-free transcript; diff aligns a candidate with it step by step and gates on a baseline.
  • captures/stock/*.jsonl: raw stock recordings (evidence, category [O]). Not committed: they embed the GPU UUID. Re-record locally with capture_stock.sh.
  • captures/golden/stock-620.73.04.json, controls.tsv: normalised transcript and the control set.
  • captures/golden/known-gaps.tsv: controls the stock driver served that our 580-derived table does not match. The offline test fails on a new entry and on a stale one.
  • captures/baseline/*.json: divergences of the candidate driver you accept, written locally by replay_live.sh --update (not committed; the live gate fails on a new divergence and reports fixed ones, so a baseline only shrinks).
  • Workloads: nvidia-smi -L, nvidia-smi, tools/ioctl_capture/cuda_basic.py (cuInit, context, alloc, H2D, D2H, free, destroy). Add a workload by recording it with run and listing it in replay_live.sh and replay_diff.py golden.

Re-recording (needs the user's explicit yes)

The swap unloads nvidia_rs and loads the stock modules built for the running kernel (STOCK_SRC, default ../nvidia-open-620.73.04/kernel-open, from the NVIDIA tag 620.73.04, make modules SYSSRC=/usr/lib/modules/$(uname -r)/build). It is opt-in: set NV_RS_CAPTURE_BDF=<bdf> to the one GPU it may unbind; it refuses if nvidia_rs is bound to any other device, so it cannot touch a multi-GPU host by accident. Never reset the GPU or reboot from the script. After swap, run sudo nvidia-modprobe -c0 -u -m if the nodes are missing. restore drops caches and compacts memory first: after the stock driver ran, DMA32 order-7 allocations fail with runtime initialization failed: -12 otherwise.

What the golden transcript shows (stock 620.73.04)

  • nvidia-smi and a CUDA round trip (cuInit … cuCtxDestroy) succeed; the CUDA workload is 551 ioctls over 65 distinct controls and 18 allocation classes.
  • Not covered: nested pointers inside parameter buffers, mmap contents, GPU-side effects.