2 Commits

Author SHA1 Message Date
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
0e877c71c2 gsp_bringup, gsp_pointer_controls: do not forward NvP64 controls flat to GSP-RM (620 and 580 lists)
gsp_bringup::forward_escape would forward an NV_ESC_RM_CONTROL of a
caller's own client to GSP-RM as a flat parameter block
(GspRpcEngine::rm_control) once Node::escape_target_gpu_id finds the
object in Node::classes. Since #361 a forwarded ALLOC that GSP-RM
accepts is recorded there (rmapi_node::on_gsp_legacy_object_alloc), so
a control on a forwarded subdevice gets that far. On the R620 ABI that
would include controls whose parameter struct holds an NvP64 user
address, for example

- NV2080_CTRL_CMD_GPU_EXEC_REG_OPS 0x20800122, NvP64 regOps (620.73.04
  ctrl2080gpu.h:729). Stock copies the ops in (embeddedParamCopyIn,
  embedded_param_copy.c:478-488), and a GSP client sends them inline
  in NV_RM_RPC_GPU_EXEC_REG_OPS (subdevice_ctrl_gpu_regops.c:205-231).
- NV2080_CTRL_CMD_FB_GET_BAR1_OFFSET 0x20801310, NvP64 cpuVirtAddress,
  which stock CPU-RM answers from its own CPU mappings
  (subdeviceCtrlCmdFbGetBar1Offset_IMPL, mem_mgr_ctrl.c:299-322).

Stock almost never hands GSP-RM such a block: CPU-RM FINN-serializes
the control (rpcRmApiControl_GSP, rpc.c:11503-11512), sends a dedicated
RPC or answers it alone, and converts the deprecated v1 controls to V2
first (rmDeprecatedControlTable, rmapi_deprecated_control.c:78-88,
called from entry_points.c:498). The exceptions are three exported
ROUTE_TO_PHYSICAL controls FINN does not serialize: DEFERRED_API
0x50800101, DEFERRED_API_INTERNAL 0x50800104 and
MIGRATE_ENGINE_CTX_DATA 0xb06f010d. serverSerializeCtrlDown returns them
unchanged (rmapi_finn.c:85-87) and rmresControl_Prologue_IMPL sends them
flat (resource.c:254, NV_RM_RPC_CONTROL at :289). This guard refuses
them too, which is stricter than stock.

nv_rs_core::gpu::gsp_pointer_controls (new) holds two lists:
NVP64_CONTROLS_620, every control the 620.73.04 RM exports (NVOC method
tables, generated/g_*_nvoc.c) whose parameter struct holds an NvP64
directly or nested: 56 commands, the same in 620.70.06; and
POINTER_CONTROLS, the rest of the FINN serializer's list
(g_finn_rm_api.c) and the 8 commands of the deprecated converter table:
13 commands. forwards_flat(abi, cmd) is false on R620 for both lists.
escape_forwards_flat(abi, escape, top) is the check forward_escape now
makes first: for an NV_ESC_RM_CONTROL with a full NVOS54_PARAMETERS
block it reads the command at +8 and asks forwards_flat. When the answer
is no, forward_escape returns None and rmapi_node falls through to
nvdriver's own server.

tools/check_pointer_controls_620.py recomputes the lists from the 620
tree (an argument, $NV_RS_OGKM_620, $OPEN_GPU_ROOT or target/ref/ogkm)
and fails on a missing or extra NvP64 control, on a FINN-serialized or
deprecated command on neither list, and on a POINTER_CONTROLS entry
that is neither. As a cross-check, every case of embeddedParamCopyIn
(embedded_param_copy.c:185-781, 39 cases) must be on a list unless 620
does not export it (BIOS_GET_NBSI 0x20800803, FB_GET_AMAP_CONF
0x20801336) or define it (NV0000_CTRL_CMD_OS_GET_CAPS). It passes on
620.73.04 and 620.70.06. Plain T * members are not scanned.

Unit tests: the lists are sorted and disjoint, forwards_flat refuses
every entry on R620, escape_forwards_flat reads the command of a control
block and leaves other escapes and short blocks alone, and every control
rmapi::node::Node::nested_plan copies a nested buffer for (15 on master)
is on a list. docs/REPLAY_TESTING.md says how to run both.

Scope: only gsp_bringup's forwarder with gsp_abi=620, which master
takes with ga10x_gsp=0 at bringup level >= 9 (boot_gsp_rm). Its R580
ABI gets its own list, from the 580.178.04 tree, in the next commit;
gsp_route is unchanged.

EXEC_REG_OPS through its dedicated RPC and BAR1_OFFSET answered
CPU-side are not implemented: both get nvdriver's own answer.

Ported from night2-int f6d588c8 and 2470ff4f (the deprecated-table
entries), where the lists lived in gsp_objects.rs of our R620 runtime.

The 580.178.04 list for gsp_abi=580:

The previous commit left gsp_bringup's R580 forwarder unchanged. Stock
580.178.04 handles these controls the same way as 620.73.04, so the
R580 ABI now gets its own list, computed from the 580.178.04
open-gpu-kernel-modules tree:

- embeddedParamCopyIn copies the embedded buffers in
  (embedded_param_copy.c:214-767, GPU_EXEC_REG_OPS at :507-517).
- rpcRmApiControl_GSP FINN-serializes the control (rpc.c:10853,
  serverSerializeCtrlDown at :10929-10938).
- A GSP client sends GPU_EXEC_REG_OPS as NV_RM_RPC_GPU_EXEC_REG_OPS with
  the ops inline (subdevice_ctrl_gpu_regops.c:205-231), regOps being an
  NvP64 (ctrl2080gpu.h:743).
- subdeviceCtrlCmdFbGetBar1Offset_IMPL answers FB_GET_BAR1_OFFSET from
  CPU-RM's own mappings (mem_mgr_ctrl.c:310-333).
- rmDeprecatedControlTable converts the v1 controls to V2
  (rmapi_deprecated_control.c:78-88, called from entry_points.c:500).

NVP64_CONTROLS_580 holds the 53 controls the 580.178.04 RM exports
whose parameter struct holds an NvP64. That is the 620 list without
three commands: NV0000_CTRL_CMD_SYSTEM_NVPCF_GET_POWER_MODE_INFO is
exported but its 580 struct has no inOutData (ctrl0000system.h:2136),
and NV2080_CTRL_CMD_GSP_CRYPTO_CONTROL and
NVA083_CTRL_CMD_VIRTUAL_DISPLAY_GET_DEFAULT_EDID are neither exported
nor defined in 580. POINTER_CONTROLS stays the same 13 commands: every
command of the 580 FINN list (25 messages) and of the 580 deprecated
table (the same 8 commands) is on NVP64_CONTROLS_580 or
POINTER_CONTROLS, and every POINTER_CONTROLS entry is FINN-serialized
or deprecated in 580 too.

holds_user_pointer(abi, cmd) replaces holds_user_pointer_620 and picks
the list by ABI; forwards_flat refuses it on both ABIs.

tools/check_pointer_controls_620.py becomes tools/check_pointer_controls.py.
It takes one or more trees, reads NVIDIA_VERSION from each version.mk
and checks NVP64_CONTROLS_620 or NVP64_CONTROLS_580 against it. It
passes on 620.73.04, 620.70.06 and 580.178.04. The 580 tree is the
NVIDIA open-gpu-kernel-modules 580.178.04 tarball; its kernel-open/nvidia
matches the 580.178.04 .run's kernel-open/nvidia file for file, apart
from the prebuilt nv-kernel.o_binary.

The unit tests now run for both ABIs, and one more checks that the 580
list is the 620 list without those three commands.

gsp_route is unchanged: the GA10x runtime has its own handling of
controls with user pointers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 10:51:24 +01:00