mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
src/nvidia/src/gpu/fake_gsp.rs (#[cfg(test)]) adds LegacyGsp, a host
model of GSP-RM's side of master's page-ring transport
(gpu::gsp_transport: send_rpc, recv_rpc, send_rpc_fragmented,
recv_rpc_reassembled, wait_for_rm_init_done). It owns the queue-0
registers the transport polls and rings (NV_PGSP_QUEUE_HEAD 0x110c00,
CMDQ_TAIL 0x110c04, QUEUE_TAIL 0x110c80, MSGQ_TAIL 0x110c84, the
constants in gsp_rpc.rs:27-33), decodes every element the driver
publishes with gsp_rpc::unpack_message (XOR checksum, element count at
+0x28, sequence) and writes replies with gsp_rpc::pack_message, split
into CONTINUATION_RECORDs where asked. Five tests in fake_gsp/tests.rs:
- 40 RPCs of 1 and 2 pages through an 8-page ring wrap and come back in
sequence with no violation;
- a status element with its first payload byte flipped (element and RPC
headers still valid) fails unpack_message with BadChecksum, recv_rpc
refuses it (0x2f) and the driver's MSGQ_TAIL does not move;
- a full command ring refuses the RPC with 0x1a and next_seq stays;
- a 9000-byte request goes out as a primary plus two
CONTINUATION_RECORDs; a split reply is reassembled; a continuation
record whose RPC header sequence is skipped (the elements' own seq_num
stay in order) is refused (0x25); a reply cut short times out;
- wait_for_rm_init_done times out without GSP_INIT_DONE, returns OK on
it and returns the rpc_result it carries (0x57).
The replies and faults are the test's choice, not observed GSP-RM
behaviour; the model checks how the driver handles them. The element is
the 580.178.04 GSP_MSG_QUEUE_ELEMENT (open-gpu-kernel-modules 580.178.04
src/nvidia/inc/kernel/gpu/gsp/message_queue_priv.h:43-51: checksum
+0x20, seqNum +0x24, elemCount +0x28, RPC header +0x30). 620's
GspMsgQueueReceiveStatus (620.73.04 message_queue_cpu.c:634) checks
MCTP/NVDM headers instead and has no checksum.
The asserted statuses are master's. Three of them differ from stock
580.178.04 CPU-RM; the tests, fake_gsp.rs and docs/OFFLINE_TESTING.md
say so. Stock lines are in src/nvidia/src/kernel/gpu/gsp/ and
src/nvidia/src/kernel/vgpu/rpc.c of the 580.178.04 sources:
- bad checksum: master returns 0x2f (gsp_transport.rs:243) and leaves
the element in the ring. Stock GspMsgQueueReceiveStatus reads it
up to three times, returns NV_ERR_INVALID_DATA (0x25) and marks it
consumed (message_queue_cpu.c:615, :685-688, :772-782);
- full command ring: master returns 0x1a at once (gsp_transport.rs:178).
Stock GspMsgQueueSendCommand waits up to 1 s per element, then
returns NV_ERR_BUSY_RETRY (0x03, message_queue_cpu.c:522-556), which
_issueRpcAndWait passes on as NV_ERR_GENERIC (rpc.c:1884);
- skipped RPC sequence in a continuation record: master returns 0x25
(ContinuationAssembler::push, gsp_rpc.rs:1544-1545, mapped at
gsp_transport.rs:443-444). Stock _issueRpcLarge waits for
CONTINUATION_RECORD at the next sequence (rpc.c:2164-2171);
_kgspRpcDrainOneEvent does not match a record with another RPC
sequence (kernel_gsp.c:1814-1820), _kgspProcessRpcEvent logs it as
an unexpected event and drops it (:1648-1658), and the wait ends in
NV_ERR_TIMEOUT (:2473-2477).
The timeout (0x65) and the GSP_INIT_DONE rpc_result match stock
(kernel_gsp.c:2473-2477, :5266-5273). The tests keep asserting master's
values so that a change to them is seen; changing the transport is not
part of this commit.
Ported from night2-int (b21d4992, LIghtJUNction). Changed against it:
the bad-checksum test flipped frame[0x34], the low byte of the RPC
header's signature, so RpcHeader::decode refused the element
(BadSignature, gsp_rpc.rs:337) before the checksum was computed
(gsp_rpc.rs:434), and the test passed with the checksum check removed.
It now flips the first payload byte (+0x50), which only the checksum
covers, and asserts BadChecksum; with the check removed it fails.
The fork's skipped-continuation case also skipped the element's own
seq_num (106 where 101 is next). For that input stock fails earlier:
GspMsgQueueReceiveStatus's seqNum check (message_queue_cpu.c:693-717)
fails three reads, returns NV_ERR_INVALID_DATA (0x25) and consumes the
element (:772-782), and that status reaches the caller (kernel_gsp.c
:2454-2455, rpc.c:2171-2187), the same as master's. Now only the RPC
header sequence is skipped, the input the stock comparison above
describes; with ContinuationAssembler's sequence check disabled the
case fails (run once, reverted). The stock comparison was added to the
tests and the doc.
Left out: FakeGsp and its 20 tests, which drive the R620 linked queues
(R620LinkedQueues, R620BootQueues, R620QueueMemory, rm_rpc) of our R620
runtime; master's 620 ABI runs over the same page rings (send_rpc_620 /
recv_rpc_620) and has none of those types. docs/OFFLINE_TESTING.md
describes what is and is not modelled.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: ChrisMythos <63128214+ChrisMythos@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5.6 KiB
5.6 KiB
Offline testing
Host-only tests that need no GPU and no loaded module. They run as part of cargo test --workspace.
Fake GSP (page-ring transport)
cd src/nvidia && cargo test -p nv-rs-core --lib fake_gsp
Code: src/nvidia/src/gpu/fake_gsp.rs (model) and fake_gsp/tests.rs (tests), #[cfg(test)] only.
What is modelled
LegacyGspplays GSP-RM's side of the page-ring transport ingpu::gsp_transport(send_rpc,recv_rpc,send_rpc_fragmented,recv_rpc_reassembled,wait_for_rm_init_done): theNV_PGSP_QUEUE_HEAD/CMDQ_TAIL/QUEUE_TAIL/MSGQ_TAILregisters of queue 0, a small wrapping ring, multi-page elements. It decodes every element the driver publishes (XOR checksum, element count, sequence) and records violations, and it writes replies, including ones split intoCONTINUATION_RECORDs, into the status ring.- Faults: a reply with a bad checksum, a full command ring, a continuation record with a
skipped RPC sequence, a reply cut short after its primary packet, a
GSP_INIT_DONEthat never comes or carries anrpc_result.
What the tests pin
The tests pin what master's transport does today. Three of the statuses are master's own and
differ from stock 580.178.04 CPU-RM; they are pinned so that a change is noticed, not because
they match stock. Stock references are to the open-gpu-kernel-modules 580.178.04 sources:
message_queue_cpu.c and kernel_gsp.c in src/nvidia/src/kernel/gpu/gsp/, rpc.c in
src/nvidia/src/kernel/vgpu/, nvstatuscodes.h in src/common/sdk/nvidia/inc/.
- A status element with one payload byte flipped (headers still valid) fails the XOR checksum,
is refused with
0x2f, and the driver's tail does not move. Differs from stock: master returns0x2f(NV_ERR_INVALID_LOCK_STATE,nvstatuscodes.h:76) without consuming the element. StockGspMsgQueueReceiveStatusreads it up to three times, returnsNV_ERR_INVALID_DATA(0x25) and marks it consumed (message_queue_cpu.c:615,:685-688,:772-782). - A full command ring refuses the RPC with
NV_ERR_INSUFFICIENT_RESOURCES(0x1a) and the sequence counter does not advance. Differs from stock: stockGspMsgQueueSendCommandwaits up to 1 s per element for space, then returnsNV_ERR_BUSY_RETRY(0x03,message_queue_cpu.c:522-556), which the RPC layer turns intoNV_ERR_GENERICfor its caller (rpc.c:1884). Stock's queue counter stays (:588), but its RPC header sequence has already advanced (kernel_gsp.c:405); master uses one counter for both. - A large request goes out as a primary packet plus
CONTINUATION_RECORDs; a split reply is reassembled; a continuation record whose RPC header sequence is skipped (the element's ownseq_numstays in order) is refused (0x25); a reply cut short times out (0x65). The0x25differs from stock: stock logs a continuation record with the wrong RPC sequence as an unexpected event, drops it and keeps waiting untilNV_ERR_TIMEOUT(rpc.c:2171,kernel_gsp.c:1814-1820,:1648-1658). The timeout status (0x65) is the same as stock's. wait_for_rm_init_donetimes out withoutGSP_INIT_DONEand returns therpc_resultthatGSP_INIT_DONEcarries. Same as stockkgspWaitForRmInitDone_IMPL(kernel_gsp.c:5266-5273).
What is NOT modelled
- Real GSP-RM behaviour. Statuses, reply sizes and ordering are chosen by the test; they only exist on hardware. A passing test means the driver handles that wire behaviour, not that GSP-RM produces it.
- Stock's receive-side element sequence check (
seqNumagainst its receive counter,message_queue_cpu.c:693-717). Master'srecv_rpchas no such check, so the model does not exercise one. - The 620 MCTP+NVDM element on the same rings (
send_rpc_620,recv_rpc_620,send_rpc_fragmented_620), whichgsp_bringupuses whengsp_abiis 620. The element has no checksum (unpack_message_620). - The kernel crate:
gsp_bringup::GspRpcEngine, DMA allocation and coherency, session teardown, interrupts, timing, the CPU sequencer and boot (execute_gsp_boot), and the GA10x runtime's own queues (ga10x*.rs).
Fuzz / property tests
src/nvidia/src/rmapi/fuzz_tests.rs (seeded xorshift, no extra dependencies):
cd src/nvidia && cargo test -p nv-rs-core --lib fuzz_
NV_RS_FUZZ_ITERS=30 cargo test -p nv-rs-core --lib fuzz_ # random payloads per case (default 2); scales the codec rounds too
- Control sweep: every exported method of
control_table::METHODS(plus unknown, null and deprecated-converter commands) goes throughControlNode::prepare+executeasNV_ESC_RM_CONTROL, on a client, device, subdevice and BinaryApi object of a modelled GV100. Sizes: declared, 0, declared±1,MAX_PARAMS+1; payloads zero / 0xff / random; random flags. Asserts: no panic, status defined (< 0x80, aNV_WARN_*in0x1xxxx, or0xffff), copy plan<= MAX_PARAMS, and an identical transcript hash for the same seed. - Other tests:
executewith a block of the wrong length is refused (no panic, a defined status other than OK), repeated calls do not regain OK after a refusal, oversized plans are capped. - Codec properties: PTE encode/decode round trip and canonical decode (all architectures
and page sizes), PDE/leaf-plan never panic, GSP message pack/unpack round trip plus
single-bit corruption detection, RM control/alloc header round trips, and random-byte
decoders that must not panic (CrashCat packets, the GA10x
GspStaticConfigInfoparserga10x_gsp::parse_static_info, the GMCAPI NVKV walkergmcapi::decodeandgmcapi::decode_static_info).