Files
nvdriver/docs/REPLAY_TESTING.md
ChrisMythos 5c244c7487 gsp_pointer_controls: forward the three ROUTE_TO_PHYSICAL controls flat, as stock does
The guard refused every exported control whose parameter struct holds
an NvP64, including three that stock CPU-RM forwards to GSP-RM flat.
Refusing them left NVB06F_CTRL_CMD_MIGRATE_ENGINE_CTX_DATA on a channel
GSP-RM created to nvdriver's own server, which does not hold that
channel and answers OBJECT_NOT_FOUND (CodeRabbit review of #392).

Stock, in 620.73.04 and 580.178.04 alike:

- rmresControlSerialization_Prologue_IMPL calls serverSerializeCtrlDown
  for a control whose method entry is flagged
  RMCTRL_FLAGS_ROUTE_TO_PHYSICAL (0x40, control.h:230 in 620, :233 in
  580; resource.c:209-222; ctrlFlags is the method entry's flags,
  resource.c:172).
- serverSerializeCtrlDown returns NV_OK with the block unchanged when
  FINN does not serialize the control (rmapi_finn.c:85-87 in 620,
  :86-88 in 580).
- rmresControl_Prologue_IMPL then sends the block to GSP-RM as it is
  (resource.c:254, NV_RM_RPC_CONTROL at :289).

The exported NvP64 controls flagged ROUTE_TO_PHYSICAL that FINN does
not serialize are the same three in both releases:

- NV5080_CTRL_CMD_DEFERRED_API 0x50800101 (flags 0x50048)
- NV5080_CTRL_CMD_DEFERRED_API_INTERNAL 0x50800104 (flags 0x500c8)
- NVB06F_CTRL_CMD_MIGRATE_ENGINE_CTX_DATA 0xb06f010d (flags 0x14044)

The method table of the closed 580.178.04 binary
(rmapi::control_table::METHODS) has the same flags for all three.

tools/check_pointer_controls.py now derives this from each tree: it
reads every method entry's flags from the NVOC tables, the value of
RMCTRL_FLAGS_ROUTE_TO_PHYSICAL from control.h, and leaves out of the
expected list every exported NvP64 control whose entries all carry it
and that the FINN serializer list does not hold. It fails when such a
control is on a list. In the embeddedParamCopyIn cross-check, a control
stock forwards flat is accounted for: MIGRATE_ENGINE_CTX_DATA, whose
pEngineCtxBuff stock copies in first (embedded_param_copy.c:661-672 in
620, :673-684 in 580).

Regenerated with it, NVP64_CONTROLS_620 goes from 56 to 53 commands
(620.73.04 and 620.70.06) and NVP64_CONTROLS_580 from 53 to 50
(580.178.04). POINTER_CONTROLS is unchanged at 13. The check passes on
all three trees.

The guard still refuses every other NvP64 control, on both ABIs. A new
unit test checks that the three are on no list, go flat through
forwards_flat and escape_forwards_flat on both ABIs, and are flagged
ROUTE_TO_PHYSICAL in control_table::METHODS. The module doc, the
gsp_bringup::forward_escape comment and docs/REPLAY_TESTING.md drop
the "stricter than stock" wording. They also record the difference that
remains for MIGRATE_ENGINE_CTX_DATA: stock sends GSP-RM the address of
CPU-RM's kernel copy of pEngineCtxBuff, while gsp_bringup passes the
caller's block unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 11:39:53 +01:00

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

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:

cargo test -p nv-rs-core --lib gsp_pointer_controls
python3 tools/check_pointer_controls.py <open-gpu-kernel-modules 620 tree> <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.