mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
gpu: fake GSP model of the page-ring transport, with fault injection
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>
This commit is contained in:
committed by
ChrisMythos
parent
1d3b4285a8
commit
f9c15d1a24
@ -2,6 +2,71 @@
|
||||
|
||||
Host-only tests that need no GPU and no loaded module. They run as part of `cargo test --workspace`.
|
||||
|
||||
## Fake GSP (page-ring transport)
|
||||
|
||||
```sh
|
||||
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
|
||||
|
||||
- `LegacyGsp` plays GSP-RM's side of the page-ring transport in `gpu::gsp_transport`
|
||||
(`send_rpc`, `recv_rpc`, `send_rpc_fragmented`, `recv_rpc_reassembled`,
|
||||
`wait_for_rm_init_done`): the `NV_PGSP_QUEUE_HEAD` / `CMDQ_TAIL` / `QUEUE_TAIL` / `MSGQ_TAIL`
|
||||
registers 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 into `CONTINUATION_RECORD`s, 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_DONE` that never
|
||||
comes or carries an `rpc_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
|
||||
returns `0x2f` (`NV_ERR_INVALID_LOCK_STATE`, `nvstatuscodes.h:76`) without consuming the
|
||||
element. 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`).
|
||||
- A full command ring refuses the RPC with `NV_ERR_INSUFFICIENT_RESOURCES` (`0x1a`) and the
|
||||
sequence counter does not advance. **Differs from stock:** stock `GspMsgQueueSendCommand`
|
||||
waits up to 1 s per element for space, then returns `NV_ERR_BUSY_RETRY` (`0x03`,
|
||||
`message_queue_cpu.c:522-556`), which the RPC layer turns into `NV_ERR_GENERIC` for 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_RECORD`s; a split reply is
|
||||
reassembled; a continuation record whose RPC header sequence is skipped (the element's own
|
||||
`seq_num` stays in order) is refused (`0x25`); a reply cut short times out (`0x65`).
|
||||
**The `0x25` differs from stock:** stock logs a continuation record with the wrong RPC
|
||||
sequence as an unexpected event, drops it and keeps waiting until `NV_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_done` times out without `GSP_INIT_DONE` and returns the `rpc_result` that
|
||||
`GSP_INIT_DONE` carries. Same as stock `kgspWaitForRmInitDone_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 (`seqNum` against its receive counter,
|
||||
`message_queue_cpu.c:693-717`). Master's `recv_rpc` has 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`), which `gsp_bringup` uses when `gsp_abi` is 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):
|
||||
|
||||
@ -54,6 +54,8 @@ pub mod engine_construct;
|
||||
mod engine_live_support;
|
||||
pub mod engine_set;
|
||||
pub mod engine_set_tables;
|
||||
#[cfg(test)]
|
||||
mod fake_gsp;
|
||||
pub mod falcon_boot;
|
||||
pub mod falcon_imem;
|
||||
pub mod falcon_ls_start;
|
||||
|
||||
161
src/nvidia/src/gpu/fake_gsp.rs
Normal file
161
src/nvidia/src/gpu/fake_gsp.rs
Normal file
@ -0,0 +1,161 @@
|
||||
//! Offline software model of GSP-RM's side of the page-ring transport, with fault injection
|
||||
//! (test only).
|
||||
//!
|
||||
//! `LegacyGsp` plays the firmware side of `send_rpc*` / `recv_rpc*` / `wait_for_rm_init_done`
|
||||
//! (0x30-byte element, XOR checksum): it consumes what the driver publishes in the command ring,
|
||||
//! checks each element's checksum and sequence, and writes scripted replies into the status ring
|
||||
//! behind its own head/tail registers. Real firmware behaviour is NOT modelled; see
|
||||
//! docs/OFFLINE_TESTING.md.
|
||||
//!
|
||||
//! The element is the 580.178.04 one (`GSP_MSG_QUEUE_ELEMENT`, message_queue_priv.h:43-51:
|
||||
//! checksum +0x20, seqNum +0x24, elemCount +0x28, RPC header +0x30), packed and checked with
|
||||
//! master's `gsp_rpc` codec. Stock's own checks are in `GspMsgQueueSendCommand` /
|
||||
//! `GspMsgQueueReceiveStatus` (580.178.04 message_queue_cpu.c:456, :608).
|
||||
extern crate std;
|
||||
|
||||
use super::gsp_rpc::{
|
||||
pack_message, RpcHeader, MSG_PAGE_BYTES, NV_PGSP_CMDQ_TAIL_0, NV_PGSP_MSGQ_TAIL_0,
|
||||
NV_PGSP_QUEUE_HEAD_0, NV_PGSP_QUEUE_TAIL_0,
|
||||
};
|
||||
use super::gsp_sequencer::SequencerHost;
|
||||
use super::gsp_transport::write_ring_pages;
|
||||
use super::registers::RegisterIo;
|
||||
use nv_rs_abi::NvStatus;
|
||||
use std::format;
|
||||
use std::string::String;
|
||||
use std::vec;
|
||||
use std::vec::Vec;
|
||||
|
||||
pub const NV_ERR_TIMEOUT: NvStatus = NvStatus(0x65);
|
||||
|
||||
/// One element the driver published, as the model decoded it.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Request {
|
||||
pub function: u32,
|
||||
pub sequence: u32,
|
||||
pub payload: Vec<u8>,
|
||||
pub pages: u32,
|
||||
}
|
||||
|
||||
fn rd32(b: &[u8], o: usize) -> u32 {
|
||||
u32::from_le_bytes(b[o..o + 4].try_into().unwrap())
|
||||
}
|
||||
|
||||
/// Firmware side of the legacy page-ring transport (`send_rpc`, 0x30-byte
|
||||
/// element, XOR checksum) with its own head/tail registers.
|
||||
pub struct LegacyGsp {
|
||||
pub ring_pages: u32,
|
||||
pub cmd_head: u32,
|
||||
pub cmd_tail: u32,
|
||||
pub msg_head: u32,
|
||||
pub msg_tail: u32,
|
||||
pub requests: Vec<Request>,
|
||||
pub violations: Vec<String>,
|
||||
expected_seq: Option<u32>,
|
||||
}
|
||||
|
||||
impl LegacyGsp {
|
||||
pub fn new(ring_pages: u32) -> Self {
|
||||
Self {
|
||||
ring_pages,
|
||||
cmd_head: 0,
|
||||
cmd_tail: 0,
|
||||
msg_head: 0,
|
||||
msg_tail: 0,
|
||||
requests: Vec::new(),
|
||||
violations: Vec::new(),
|
||||
expected_seq: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumes everything the driver published in `cmdq`, validating each element.
|
||||
pub fn process(&mut self, cmdq: &[u8]) {
|
||||
while self.cmd_tail != self.cmd_head {
|
||||
let mut first = vec![0u8; MSG_PAGE_BYTES];
|
||||
super::gsp_transport::read_ring_pages(
|
||||
cmdq,
|
||||
self.ring_pages,
|
||||
self.cmd_tail,
|
||||
1,
|
||||
&mut first,
|
||||
)
|
||||
.unwrap();
|
||||
let pages = rd32(&first, 0x28);
|
||||
if pages == 0 || pages > self.ring_pages {
|
||||
self.violations.push(format!("bad elem_count {pages}"));
|
||||
self.cmd_tail = self.cmd_head;
|
||||
return;
|
||||
}
|
||||
let mut frame = vec![0u8; pages as usize * MSG_PAGE_BYTES];
|
||||
super::gsp_transport::read_ring_pages(
|
||||
cmdq,
|
||||
self.ring_pages,
|
||||
self.cmd_tail,
|
||||
pages,
|
||||
&mut frame,
|
||||
)
|
||||
.unwrap();
|
||||
match super::gsp_rpc::unpack_message(&frame) {
|
||||
Ok((seq, rpc, payload)) => {
|
||||
if let Some(want) = self.expected_seq {
|
||||
if seq != want || rpc.sequence != want {
|
||||
self.violations
|
||||
.push(format!("sequence {seq}/{} want {want}", rpc.sequence));
|
||||
}
|
||||
}
|
||||
self.expected_seq = Some(seq.wrapping_add(1));
|
||||
self.requests.push(Request {
|
||||
function: rpc.function,
|
||||
sequence: rpc.sequence,
|
||||
payload: payload.to_vec(),
|
||||
pages,
|
||||
});
|
||||
}
|
||||
Err(e) => self.violations.push(format!("element rejected: {e:?}")),
|
||||
}
|
||||
self.cmd_tail = (self.cmd_tail + pages) % self.ring_pages;
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes one reply element (`seq_num` and RPC sequence given) into `msgq`.
|
||||
pub fn reply(&mut self, msgq: &mut [u8], seq: u32, rpc: &RpcHeader, payload: &[u8]) {
|
||||
let mut frame = vec![0u8; MSG_PAGE_BYTES * 4];
|
||||
let (total, _) = pack_message(&mut frame, seq, rpc, payload).unwrap();
|
||||
self.write_raw(msgq, &frame[..total]);
|
||||
}
|
||||
|
||||
pub fn write_raw(&mut self, msgq: &mut [u8], bytes: &[u8]) {
|
||||
self.msg_head = write_ring_pages(msgq, self.ring_pages, self.msg_head, bytes).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl RegisterIo for LegacyGsp {
|
||||
fn read32(&mut self, off: u32) -> Result<u32, NvStatus> {
|
||||
match off {
|
||||
NV_PGSP_CMDQ_TAIL_0 => Ok(self.cmd_tail),
|
||||
NV_PGSP_QUEUE_TAIL_0 => Ok(self.msg_head),
|
||||
_ => Err(NvStatus(0x51)),
|
||||
}
|
||||
}
|
||||
fn write32(&mut self, off: u32, value: u32) -> Result<(), NvStatus> {
|
||||
match off {
|
||||
NV_PGSP_QUEUE_HEAD_0 => self.cmd_head = value,
|
||||
NV_PGSP_MSGQ_TAIL_0 => self.msg_tail = value,
|
||||
_ => return Err(NvStatus(0x51)),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl SequencerHost for LegacyGsp {
|
||||
fn delay_us(&mut self, _us: u32) {}
|
||||
fn store_reg(&mut self, _index: u32, _value: u32) -> Result<(), NvStatus> {
|
||||
Ok(())
|
||||
}
|
||||
fn core_op(&mut self, _op: u32) -> Result<(), NvStatus> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
302
src/nvidia/src/gpu/fake_gsp/tests.rs
Normal file
302
src/nvidia/src/gpu/fake_gsp/tests.rs
Normal file
@ -0,0 +1,302 @@
|
||||
//! The statuses asserted here are what master's `gsp_transport` returns today. Three of them
|
||||
//! (`0x2f`, `0x1a`, `0x25`) are master's own choices and differ from stock 580.178.04 CPU-RM;
|
||||
//! each test says what stock does instead. The tests pin master's behaviour so a change to it is
|
||||
//! seen; they are not evidence that it matches stock. Stock lines cite the
|
||||
//! open-gpu-kernel-modules 580.178.04 sources (`src/nvidia/src/kernel/gpu/gsp/...`,
|
||||
//! `src/nvidia/src/kernel/vgpu/rpc.c`).
|
||||
|
||||
use super::*;
|
||||
use crate::gpu::gsp_rpc::{
|
||||
event, func, unpack_message, ContinuationSplitter, Error, MSG_ELEM_HEADER_BYTES,
|
||||
RPC_HEADER_BYTES,
|
||||
};
|
||||
use crate::gpu::gsp_transport::{
|
||||
recv_rpc, recv_rpc_reassembled, send_rpc, send_rpc_fragmented, wait_for_rm_init_done,
|
||||
RingIndices,
|
||||
};
|
||||
|
||||
fn legacy_rpc(function: u32, seq: u32, payload: &[u8]) -> RpcHeader {
|
||||
RpcHeader {
|
||||
rpc_result: 0,
|
||||
rpc_result_private: 0,
|
||||
..RpcHeader::request(function, payload.len() as u32, seq, 0)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_ring_send_recv_wraps_and_validates_checksum_and_sequence() {
|
||||
const PAGES: u32 = 8;
|
||||
let mut gsp = LegacyGsp::new(PAGES);
|
||||
let mut idx = RingIndices::new(PAGES);
|
||||
let mut cmdq = vec![0u8; PAGES as usize * MSG_PAGE_BYTES];
|
||||
let mut msgq = vec![0u8; PAGES as usize * MSG_PAGE_BYTES];
|
||||
let mut scratch = vec![0u8; 4 * MSG_PAGE_BYTES];
|
||||
for i in 0..40u32 {
|
||||
let payload = vec![i as u8; [16usize, 5000][(i % 2) as usize]];
|
||||
let seq = send_rpc(
|
||||
&mut gsp,
|
||||
&mut idx,
|
||||
0,
|
||||
&mut cmdq,
|
||||
&mut scratch,
|
||||
func::GSP_RM_CONTROL,
|
||||
&payload,
|
||||
0,
|
||||
)
|
||||
.unwrap();
|
||||
gsp.process(&cmdq);
|
||||
gsp.cmd_tail = gsp.cmd_head;
|
||||
gsp.reply(
|
||||
&mut msgq,
|
||||
seq,
|
||||
&legacy_rpc(func::GSP_RM_CONTROL, seq, &payload),
|
||||
&payload,
|
||||
);
|
||||
let (rseq, rpc, len) = recv_rpc(&mut gsp, &mut idx, 0, &mut msgq, &mut scratch)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!((rseq, rpc.sequence, len), (seq, seq, payload.len()));
|
||||
assert!(recv_rpc(&mut gsp, &mut idx, 0, &mut msgq, &mut scratch)
|
||||
.unwrap()
|
||||
.is_none());
|
||||
}
|
||||
assert!(gsp.violations.is_empty(), "{:?}", gsp.violations);
|
||||
assert_eq!(gsp.requests.len(), 40);
|
||||
assert_eq!(gsp.msg_tail, gsp.msg_head);
|
||||
}
|
||||
|
||||
/// One payload byte flipped: the element and RPC headers stay valid, so only the XOR checksum over
|
||||
/// +0x00..total catches it.
|
||||
///
|
||||
/// Master's status, not stock's: `recv_rpc` maps any `unpack_message` error to `0x2f`
|
||||
/// (gsp_transport.rs:243; `NV_ERR_INVALID_LOCK_STATE` in nvstatuscodes.h:76) and returns before
|
||||
/// it writes `MSGQ_TAIL` (:246). Stock `GspMsgQueueReceiveStatus` reads the element up to three
|
||||
/// times (message_queue_cpu.c:615), fails with `NV_ERR_INVALID_DATA` (`0x25`, :685-688), and on
|
||||
/// that failure still marks the element consumed and advances its receive counter (:734, :772-782);
|
||||
/// `_kgspRpcRecvPoll` returns that status (kernel_gsp.c:2437-2455).
|
||||
#[test]
|
||||
fn legacy_ring_bad_checksum_is_rejected_without_consuming() {
|
||||
const PAGES: u32 = 4;
|
||||
let mut gsp = LegacyGsp::new(PAGES);
|
||||
let mut idx = RingIndices::new(PAGES);
|
||||
let mut msgq = vec![0u8; PAGES as usize * MSG_PAGE_BYTES];
|
||||
let mut scratch = vec![0u8; 2 * MSG_PAGE_BYTES];
|
||||
let mut frame = vec![0u8; MSG_PAGE_BYTES];
|
||||
let rpc = legacy_rpc(func::GSP_RM_CONTROL, 0, &[1; 16]);
|
||||
let (total, _) = pack_message(&mut frame, 0, &rpc, &[1; 16]).unwrap();
|
||||
frame[MSG_ELEM_HEADER_BYTES + RPC_HEADER_BYTES] ^= 0x10; // first payload byte, +0x50
|
||||
assert_eq!(
|
||||
unpack_message(&frame[..total]).unwrap_err(),
|
||||
Error::BadChecksum
|
||||
);
|
||||
gsp.write_raw(&mut msgq, &frame[..total]);
|
||||
assert_eq!(
|
||||
recv_rpc(&mut gsp, &mut idx, 0, &mut msgq, &mut scratch).unwrap_err(),
|
||||
NvStatus(0x2f)
|
||||
);
|
||||
assert_eq!(gsp.msg_tail, 0);
|
||||
}
|
||||
|
||||
/// Master's status, not stock's: `send_rpc` refuses at once with `0x1a`
|
||||
/// (`NV_ERR_INSUFFICIENT_RESOURCES`, gsp_transport.rs:178). Stock `GspMsgQueueSendCommand` waits up
|
||||
/// to 1 s for each element's space (message_queue_cpu.c:522-547, timeout at :530), then returns
|
||||
/// `NV_ERR_BUSY_RETRY` (`0x03`, :549-556), and the RPC layer hands its caller `NV_ERR_GENERIC`
|
||||
/// instead (rpc.c:1884, :2081, :2118).
|
||||
///
|
||||
/// `next_seq` staying put matches stock's queue counter, which advances only on success
|
||||
/// (message_queue_cpu.c:588). Master uses `next_seq` for the RPC header's sequence too; stock takes
|
||||
/// that one before it tries the queue (kernel_gsp.c:405, :411), so it has already moved.
|
||||
#[test]
|
||||
fn legacy_ring_full_returns_insufficient_resources() {
|
||||
const PAGES: u32 = 4;
|
||||
let mut gsp = LegacyGsp::new(PAGES);
|
||||
let mut idx = RingIndices::new(PAGES);
|
||||
let mut cmdq = vec![0u8; PAGES as usize * MSG_PAGE_BYTES];
|
||||
let mut scratch = vec![0u8; 4 * MSG_PAGE_BYTES];
|
||||
for _ in 0..3 {
|
||||
send_rpc(
|
||||
&mut gsp,
|
||||
&mut idx,
|
||||
0,
|
||||
&mut cmdq,
|
||||
&mut scratch,
|
||||
func::NOP,
|
||||
&[0; 8],
|
||||
0,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
assert_eq!(
|
||||
send_rpc(
|
||||
&mut gsp,
|
||||
&mut idx,
|
||||
0,
|
||||
&mut cmdq,
|
||||
&mut scratch,
|
||||
func::NOP,
|
||||
&[0; 8],
|
||||
0
|
||||
)
|
||||
.unwrap_err(),
|
||||
NvStatus(0x1a)
|
||||
);
|
||||
assert_eq!(idx.next_seq, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_fragmented_send_and_reassembled_reply_with_faults() {
|
||||
const PAGES: u32 = 16;
|
||||
let mut gsp = LegacyGsp::new(PAGES);
|
||||
let mut idx = RingIndices::new(PAGES);
|
||||
let mut cmdq = vec![0u8; PAGES as usize * MSG_PAGE_BYTES];
|
||||
let mut msgq = vec![0u8; PAGES as usize * MSG_PAGE_BYTES];
|
||||
let mut scratch = vec![0u8; 4 * MSG_PAGE_BYTES];
|
||||
let payload: Vec<u8> = (0..9000u32).map(|i| i as u8).collect();
|
||||
let max_rpc = RPC_HEADER_BYTES + 3000;
|
||||
let (start, packets) = send_rpc_fragmented(
|
||||
&mut gsp,
|
||||
&mut idx,
|
||||
0,
|
||||
&mut cmdq,
|
||||
&mut scratch,
|
||||
func::GSP_RM_CONTROL,
|
||||
&payload,
|
||||
0,
|
||||
max_rpc,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!((start, packets), (0, 3));
|
||||
gsp.cmd_head = idx.tx_head;
|
||||
gsp.process(&cmdq);
|
||||
assert!(gsp.violations.is_empty(), "{:?}", gsp.violations);
|
||||
let seen: Vec<u32> = gsp.requests.iter().map(|r| r.function).collect();
|
||||
assert_eq!(
|
||||
seen,
|
||||
[
|
||||
func::GSP_RM_CONTROL,
|
||||
func::CONTINUATION_RECORD,
|
||||
func::CONTINUATION_RECORD
|
||||
]
|
||||
);
|
||||
|
||||
// Reply split into primary + continuation records, reassembled by the driver.
|
||||
let mut gsp = LegacyGsp::new(PAGES);
|
||||
let mut idx = RingIndices::new(PAGES);
|
||||
let mut splitter =
|
||||
ContinuationSplitter::new(func::GSP_RM_CONTROL, &payload, 100, 0, max_rpc).unwrap();
|
||||
let mut seq = 100;
|
||||
let mut reply_pages = Vec::new();
|
||||
while let Some((hdr, chunk)) = splitter.next_chunk() {
|
||||
let hdr = RpcHeader {
|
||||
rpc_result: 0,
|
||||
rpc_result_private: 0,
|
||||
..hdr
|
||||
};
|
||||
reply_pages.push((seq, hdr, chunk.to_vec()));
|
||||
seq += 1;
|
||||
}
|
||||
for (s, hdr, chunk) in &reply_pages {
|
||||
gsp.reply(&mut msgq, *s, hdr, chunk);
|
||||
}
|
||||
let mut out = vec![0u8; payload.len()];
|
||||
let (status, got) = recv_rpc_reassembled(
|
||||
&mut gsp,
|
||||
&mut idx,
|
||||
0,
|
||||
&mut msgq,
|
||||
&mut scratch,
|
||||
func::GSP_RM_CONTROL,
|
||||
100,
|
||||
&mut out,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!((status, got), (NvStatus(0), payload.len()));
|
||||
assert_eq!(out, payload);
|
||||
|
||||
// Skipped continuation sequence: the first CONTINUATION_RECORD's RPC header sequence is
|
||||
// skipped; the elements' own seq_num stay consecutive. Master refuses it with 0x25
|
||||
// (ContinuationAssembler::push, gsp_rpc.rs:1544-1545, mapped at gsp_transport.rs:443-444).
|
||||
// That is master's own check. For a bidirectional large RPC, stock _issueRpcLarge waits for
|
||||
// CONTINUATION_RECORD at the next sequence (rpc.c:2164-2171); a record with another RPC
|
||||
// sequence does not match (kernel_gsp.c:1814-1815), is logged as an unexpected event and
|
||||
// dropped (:1648-1658), and the wait ends in NV_ERR_TIMEOUT (0x65, :2473-2477).
|
||||
let mut gsp = LegacyGsp::new(PAGES);
|
||||
let mut idx = RingIndices::new(PAGES);
|
||||
for (i, (s, hdr, chunk)) in reply_pages.iter().enumerate() {
|
||||
let hdr = RpcHeader {
|
||||
sequence: if i == 1 { *s + 5 } else { *s },
|
||||
..*hdr
|
||||
};
|
||||
gsp.reply(&mut msgq, *s, &hdr, chunk);
|
||||
}
|
||||
assert_eq!(
|
||||
recv_rpc_reassembled(
|
||||
&mut gsp,
|
||||
&mut idx,
|
||||
0,
|
||||
&mut msgq,
|
||||
&mut scratch,
|
||||
func::GSP_RM_CONTROL,
|
||||
100,
|
||||
&mut out
|
||||
)
|
||||
.unwrap_err(),
|
||||
NvStatus(0x25)
|
||||
);
|
||||
|
||||
// Reply cut short after the primary: timeout. Same status as stock, whose wait for the next
|
||||
// CONTINUATION_RECORD times out with NV_ERR_TIMEOUT (rpc.c:2171-2187, kernel_gsp.c:2473-2477);
|
||||
// master's recv_rpc_reassembled returns it as soon as the ring is empty (gsp_transport.rs:440).
|
||||
let mut gsp = LegacyGsp::new(PAGES);
|
||||
let mut idx = RingIndices::new(PAGES);
|
||||
gsp.reply(&mut msgq, 100, &reply_pages[0].1, &reply_pages[0].2);
|
||||
assert_eq!(
|
||||
recv_rpc_reassembled(
|
||||
&mut gsp,
|
||||
&mut idx,
|
||||
0,
|
||||
&mut msgq,
|
||||
&mut scratch,
|
||||
func::GSP_RM_CONTROL,
|
||||
100,
|
||||
&mut out
|
||||
)
|
||||
.unwrap_err(),
|
||||
NV_ERR_TIMEOUT
|
||||
);
|
||||
}
|
||||
|
||||
/// Same statuses as stock: `kgspWaitForRmInitDone_IMPL` fails with `rpcRecvPoll`'s
|
||||
/// `NV_ERR_TIMEOUT` when `GSP_INIT_DONE` never comes, and otherwise returns the event's
|
||||
/// `rpc_result` (kernel_gsp.c:5266-5273). `0x57` is an arbitrary non-zero result.
|
||||
#[test]
|
||||
fn legacy_init_done_wait_times_out_and_reports_failure() {
|
||||
const PAGES: u32 = 4;
|
||||
let mut msgq = vec![0u8; PAGES as usize * MSG_PAGE_BYTES];
|
||||
let mut scratch = vec![0u8; 2 * MSG_PAGE_BYTES];
|
||||
|
||||
let mut gsp = LegacyGsp::new(PAGES);
|
||||
let mut idx = RingIndices::new(PAGES);
|
||||
assert_eq!(
|
||||
wait_for_rm_init_done(&mut gsp, &mut idx, 0, &mut msgq, &mut scratch, 8).unwrap_err(),
|
||||
NV_ERR_TIMEOUT
|
||||
);
|
||||
|
||||
let mut gsp = LegacyGsp::new(PAGES);
|
||||
let mut idx = RingIndices::new(PAGES);
|
||||
let hdr = legacy_rpc(event::GSP_INIT_DONE, 0, &[0; 8]);
|
||||
gsp.reply(&mut msgq, 0, &hdr, &[0; 8]);
|
||||
wait_for_rm_init_done(&mut gsp, &mut idx, 0, &mut msgq, &mut scratch, 8).unwrap();
|
||||
|
||||
let mut gsp = LegacyGsp::new(PAGES);
|
||||
let mut idx = RingIndices::new(PAGES);
|
||||
let hdr = RpcHeader {
|
||||
rpc_result: 0x57,
|
||||
..legacy_rpc(event::GSP_INIT_DONE, 0, &[0; 8])
|
||||
};
|
||||
gsp.reply(&mut msgq, 0, &hdr, &[0; 8]);
|
||||
assert_eq!(
|
||||
wait_for_rm_init_done(&mut gsp, &mut idx, 0, &mut msgq, &mut scratch, 8).unwrap_err(),
|
||||
NvStatus(0x57)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user