# 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=` 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. ## Offline pointer-control check (620 and 580 trees) `gsp_bringup::forward_escape` does not forward a control to GSP-RM as a flat block when its parameter struct holds an `NvP64`, or when stock FINN-serializes it or converts it from a deprecated v1 control (`nv_rs_core::gpu::gsp_pointer_controls`); nvdriver's own server answers it. The exceptions mirror stock: an exported control flagged `RMCTRL_FLAGS_ROUTE_TO_PHYSICAL` that FINN does not serialize goes to GSP-RM flat in stock (`serverSerializeCtrlDown` leaves the block unchanged, `rmresControl_Prologue_IMPL` sends `NV_RM_RPC_CONTROL`), so it goes flat here too. Those are DEFERRED_API, DEFERRED_API_INTERNAL and MIGRATE_ENGINE_CTX_DATA in both releases. Each GSP-RM ABI has its own `NvP64` list: `NVP64_CONTROLS_620` for `gsp_abi=620` and `NVP64_CONTROLS_580` for `gsp_abi=580`. Two checks keep the lists right, neither needs hardware: ```sh cargo test -p nv-rs-core --lib gsp_pointer_controls python3 tools/check_pointer_controls.py <580 tree> ``` The script reads the release from each tree's `version.mk` and checks the matching list. Without an argument it checks only a 620 tree, found through `NV_RS_OGKM_620`, `OPEN_GPU_ROOT` or `target/ref/ogkm`. - The unit tests check that the lists are sorted and disjoint, that the 580 list is the 620 list without the three commands the trees differ in, that `forwards_flat` refuses every entry on its ABI, that the three ROUTE_TO_PHYSICAL controls stock forwards flat are on no list and go flat on both ABIs, that `escape_forwards_flat` (the check `forward_escape` makes) reads the command of an `NV_ESC_RM_CONTROL` block and leaves other escapes alone, and that every control `rmapi::node::Node::nested_plan` copies a nested buffer for is on the lists of both ABIs. - The script recomputes, from the tree, every exported control whose parameter struct holds an `NvP64` (the NVOC method tables and the SDK headers), and which of them stock forwards flat: those whose every method entry is flagged `RMCTRL_FLAGS_ROUTE_TO_PHYSICAL` (its value read from the tree's control.h) and that FINN's serializer list leaves out. It fails unless the release's list holds exactly the others, and unless every FINN-serialized control and every command of the deprecated converter table is on that list or on `POINTER_CONTROLS`. As a cross-check it requires every command `embeddedParamCopyIn` copies a buffer in for to be on a list too, unless stock forwards it flat (MIGRATE_ENGINE_CTX_DATA) or the release does not export or define it. It passes on 620.73.04 and 620.70.06 (56 exported `NvP64` controls in each, 3 forwarded flat, 53 listed) and on 580.178.04 (53, 3, 50). - Not covered: plain `T *` members (only `NvP64` is looked at), allocation parameters, and `gsp_route` (the GA10x runtime), which has its own handling of controls with user pointers.