diff --git a/.crumb b/.crumb index 6805525..699f95b 100644 --- a/.crumb +++ b/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-11-05T22:59:48Z", + "compiled_at": "2026-11-05T23:00:57Z", "compiler": "crumb-compile/1", - "digest": "sha256:ecc0821a81d578d3a8db91d4523238a024836548718094a4c12865976f945ce1", + "digest": "sha256:ba03ca288ec0ed7102329b5e51a21c782ecb25f1ee50638c1c85c1e27d837673", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 67, - "generated_at_commit": "0f0a2a576556c1bf8cd63c090040141fbd372a39", - "source_tree": "sha256:eb2c0635d43b9570b04a70a14e1c0433505a5da030d9fb8665794661388ee5eb" + "files": 113, + "generated_at_commit": "b4d4c2a9c1fa9e5934ce67982e5bca2eed1844f9", + "source_tree": "sha256:e7ca5f38c2e76d7b6ce97836bb4b4625cba449323fe073be765b928aad594a89" } }, "layer": "driver", diff --git a/DESIGN.md b/DESIGN.md index 8fc8003..d490054 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -1,6 +1,7 @@ # omega-gpu-driver design notes -Status: **PROPOSED.** None of this is implemented yet. Nothing here has run on the GB10. +Status: sections 1-3 are **PROPOSED**. Section 4 is **IMPLEMENTED and EXERCISED on the host only**. +Nothing here has run on GB10 hardware; hardware qualification is **NOT_RUN**. The bring-up design (GSP boot chain, RPC surface, the `ogd` launcher and manifest, the D2 window) is in the lane's design document and is summarised in `README.md` and `window/README.md`. This file holds the design @@ -105,14 +106,76 @@ GPU, not that every GB10 access path is coherent. What this design takes from that: -1. **The ordering model on GB10 is fences plus memory ordering.** There are no CPU/GPU cache-maintenance - ioctls. +1. **The proposed ordering model is fences plus memory ordering, not a coherency proof.** - The CPU reads an output only after that job's write fence (§2) has signalled. - The submit path keeps its barriers: ring write, `dsb sy`, GPPut, `dsb sy`, doorbell. - Completion is a semaphore release that the CPU reads after the fence. - - `prep`/`fini` remain only as an ABI slot for non-coherent targets. On GB10 they check their arguments - (§2 rules) and do nothing else. + - `prep`/`fini` cannot yet be declared GB10 no-ops. NVIDIA 580.173.02 + `src/common/sdk/nvidia/inc/nvos.h:1117-1125` explicitly warns that GPU-cached system memory is + not coherent with direct CPU mappings. A coherent C2C link alone does not settle GPU-cache policy. 2. **No BAR1 VRAM mapping.** BAR1 is off on this chip: RM reports it as size 0 (above), and sysfs shows BAR0 only (lane design §1). - All buffers are sysmem: pinned pages, VFIO MAP_DMA, and GMMU PTEs with the snooped sysmem aperture. - The CPU's view of a buffer is the CPU's own mapping of those pages. + +## 4. Owned userspace DMA window + +`chan/gmmu.om` no longer presents the simulator's global `mmwin` array as hardware DMA backing. +`mmwinit` selects that array explicitly. `mmwalloc(iova, size)` instead owns one shared anonymous +read/write `mapnew` handle. CPU access uses that live handle plus a checked offset through +`mmrd32/64`, `mmwr8/32/64` and `mmzero`. The compiler's ordered word operations are used for aligned +32/64-bit accesses; zeroing handles byte tails separately. `mmwb` is an IOVA, `mmwcpu` is an +informational CPU virtual base, and a buffer's `gmbva` is its independent GPU VA. They are not aliases. + +This is a Linux **userspace VFIO** backend, not an Omega Linux kernel module or replacement for +Linux's DMA/IOMMU implementation. It neither opens nor closes a VFIO fd, adopts a container, resets +a device, or changes authorization. The caller must already have sole lifecycle ownership of the +authorized container. No fork, fd close/reuse, concurrent caller, or process restart may invalidate +the recorded tuple while it is retained. The process-local quarantine latch is not crash-safe +containment and is not permission to run hardware. + +The immutable live tuple is `(mmwgen, mmwh, mmws, mmwb, mmwfd)`: epoch, owned handle, whole length, +IOVA and container fd. `mmwgen` never wraps. Address-space, buffer and channel operations validate +their recorded window epoch; an old slot cannot become live merely because a new window exists. + +| State | Allowed transition | +|---|---| +| NONE | `mmwalloc` -> OWN only after backing allocation succeeds | +| OWN | `mmwdmap(epoch, fd)` -> DMA only after whole-window MAP_DMA succeeds | +| DMA | `mmwpublish(epoch)` -> PUB **before** exposing any IOVA through boot args, mailbox, RPC, channel bind or page-directory register | +| OWN or DMA, never published | `mmwclose(epoch)` -> NONE; DMA requires successful full exact UNMAP_DMA before `mapdrop` | +| PUB | No reclaim/reset/reuse API; uncertain completion -> QUAR | +| QUAR | No reclaim/reset/reuse API, including after a modelled idle or successful TLB invalidation | + +`chan/dma.om` reconstructs the request for every attempt: compiler `397e6704` replaces the vaddr +handle with the CPU base even when the ioctl fails. Only EBADF is classified as proven no-target +and remains OWN; other mapping errors retain uncertain ownership in QUAR without speculative +UNMAP_DMA. Failed unmap, zero/partial/oversized returned extent, or failed drop retain the handle. +The entire recorded range must be returned by UNMAP_DMA before drop. An unmap failure is never +converted into reclamation. + +Publication is sticky even if the following operation fails. Page-table root publication latches +PUB before register writes; timeout latches QUAR. Owned page-table/allocator reset, mutation and +published-buffer reuse are refused. Simulator channel ops explicitly refuse owned backing rather +than walking the unrelated `mmwin` array. The boot/RPC caller must invoke `mmwpublish` before +serializing any DMA reference and `mmwquar` on uncertain post-publication completion. This backend +does not supply those GSP callsites or invent an idle proof. No documented, exercised GB10 idle +protocol exists here; published or quarantined memory therefore remains retained. + +Sources: Linux `include/uapi/linux/vfio.h:1544-1615` (whole mapping and actual returned unmap size), +NVIDIA 580.173.02 `nvos.h:1117-1125` (cache policy warning), and +omega-mv `397e67040fb74853c6814097fe02ae4e1ebd6f66`, `seed/host/MAPPING.md:27-45,84-98`. +Pinned omc sha256: `bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6` +(pending omega-mv#890 stacked on #878, not main). + +Host evidence: `OMC=/path/to/pinned/omc sh tests/dma_host.sh` exercises anonymous memory, a real +invalid-fd refusal/retry, 23 explicit replay/boundary cases and 11 compiling negative-control mutants. +The replay transport is test-only link-time substitution, not a runtime fallback or DMA evidence. +`tests/chan_diff.sh` preserves the simulator's 391-line byte-identical C-reference trace. +Observed exit 0 for both gates. Replay binary sha256: +`06f290ccc82f33cfa2ae14b8a0604ba722988b93e6ff7299259b8779cc7a9575`; +production invalid-fd check binary sha256: +`e2dfe13d77b4ae92b91b2ae6751eb1f107420754547b4da5fddf56058697ec60`. +The gate emits source-file and binary checksums on each run; those are compiler/host evidence only. +No VFIO device was opened and no MMIO, DMA, reset, driver or service action was performed. +Hardware and Linux-kernel execution: **NOT_RUN**. diff --git a/README.md b/README.md index 50ad413..1799a30 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # omega-gpu-driver -The GB10 GPU driver written in seeded Omega. Status: **W0 IMPLEMENTED and EXERCISED in QEMU. The driver -units below are IMPLEMENTED and EXERCISED on the host against C referees and simulators only. Nothing has -run on GB10 hardware; nothing here is QUALIFIED. GSP boot (`gb10_gsp_boot.c`) is not ported.** +The GB10 GPU driver written in seeded Omega. Status: **W0 IMPLEMENTED and EXERCISED in QEMU. Existing +driver units are host-exercised against C referees and simulators. The new bounded boot image and RPC +replay units below are IMPLEMENTED and HOST_EXERCISED with exact binary parity and behavior mutants. +Nothing has run on GB10 hardware; nothing here is QUALIFIED. No NVIDIA kernel driver replacement is deployed.** Parent: [aien-dev/omega-mv](https://github.com/aien-dev/omega-mv), the seeded Omega compiler. This repo pins one omega-mv commit and the sha256 of the `omc` it births (`tools/omc.pin`). The pin is currently @@ -10,8 +11,8 @@ the draft branch `feat/vfio-dma-bar` (omega-mv#890, commit `397e6704`, on #878 ` It adds the `vfioctl` and `vfiomap` words plus IOMMU_MAP_DMA/UNMAP_DMA and the writable `vfiomapw` this driver needs. The pin moves to omega-mv main after those PRs are reviewed and merged. -`DESIGN.md` (PROPOSED, no code yet) records the isolation model, the submit ABI and the ordering model: -one GPU VA space per client with no pushbuffer parser, per-buffer read/write fences, and no BAR1. +`DESIGN.md` records the proposed isolation/submit/cache model and the implemented, host-exercised owned +DMA-window lifecycle. Hardware execution and the Linux-kernel replacement remain NOT_RUN. ## W0: bind, read identity, release @@ -85,17 +86,166 @@ reference byte for byte, and each mutant script changes one line at a time and r | `gsp/seq.om` (GSP_RUN_CPU_SEQUENCER, CPU side) | `gpu/gsp_seq.c` | `tests/seq_diff.sh` | `tests/mutants-seq.sh` | | `gsp/sha2.om`, `gsp/inflate.om`, `gsp/fw.om`, `gsp/bindata.om`, `fwprep.om` (firmware inputs) | `ck_gsp_fw_inspect.c`, `ck_gsp_bindata_extract.c`, `argus/sha256.c` | `tests/fw_diff.sh` | `tests/mutants-fw.sh` | | `chan/gmmu.om`, `chan/mem.om`, `chan/chan.om`, `chan/sim.om` (page tables, buffers, channels; simulator mode only) | `gpu/gmmu.c`, `gpu_mem.c`, `gpu_chan.c`, `gpu_sim.c` | `tests/chan_diff.sh` | `tests/mutants-chan.sh` | +| `chan/dma.om`, owned backend of `chan/gmmu.om` (Linux userspace VFIO; not a kernel module) | Linux VFIO ABI and pinned Omega handle contract | `tests/dma_host.sh` | 11 compiling ownership/order/range/error mutants in the same gate | | `chan/params.om` (RM alloc/control records for GSP-RM, NVIDIA 580.173.02 layouts) | NVIDIA headers | `tests/params_diff.sh` | `tests/mutants-chan.sh` | +| `gsp/rpc.om`, `gsp/boot.om` (SWAP_RX transport frames, boot handshake, correlated RM transactions and quarantine; replay only) | `dev/gb10_gsp_boot.c` and pinned vendor protocol | `tests/rpc_diff.sh` | `tests/mutants-rpc.sh` | +| `gsp/arena.om`, `gsp/connect.om` (bounded WPR/libos/log/radix/FMC/COT composition and preboot queue attachment) | `dev/gb10_gsp_boot.c` | `tests/arena_diff.sh` | `tests/mutants-arena.sh` | +| `gsp/profile.om`, `gsp/transport.om`, `gsp/notify.om`, `gsp/service.om` (checked mapped queue mechanism and caller pump; not production admission) | pinned vendor SWAP_RX/notification plus explicit host peer | `tests/transport_host.sh` | compiling transport/notification/service mutants plus generated-fence checker negative control | +| `gsp/dispatch.om` (whole-stream prevalidation and explicit host sequencer execution; hardware refusal) | pinned vendor sequencer plus aienux sequencer | `tests/dispatch_diff.sh` | `tests/dispatch_mutants.sh` | +| `chan/complete.om`, `chan/rmchan.om` (semaphore progress and async RM lifecycle; no global idle proof) | pinned NVIDIA headers and independent C referee | `tests/complete_diff.sh`, `tests/rmchan_diff.sh` | `tests/mutants-complete.sh`, `tests/mutants-rmchan.sh` | `fwprep FWFILE OGKMSRC OUTDIR` reads the signed `gsp_ga10x.bin` (unchanged) and the NVIDIA open-source bindata tables, and writes `fmc.img`, `fmc.hash`, `fmc.pubkey`, `fmc.sig`, `bl.img` and, last, `fw.manifest`. Channel ops other than the simulator (mode 0) trap; on the GB10 they go through GSP RPC. +The hardware backing assumption is now explicit: `mmwinit` keeps the simulator array; `mmwalloc` owns +shared anonymous `mapnew` memory and CPU accesses use the live handle plus offset. The IOVA, CPU base +and GPU VA are distinct. `mmwdmap` maps before `mmwpublish`; a DMA-mapped, never-published window +unmaps its whole recorded extent before dropping backing. Never-mapped backing drops directly. +Epoch checks refuse stale users. Publication is sticky: +timeouts, uncertain mapping/completion and partial/unexpected unmap results quarantine backing. +No documented idle-proof API exists, so published/quarantined backing cannot be reclaimed or reset. +The caller exclusively owns container/process lifetime; this is not crash-safe containment. +See `DESIGN.md` section 4 for the exact state contract and required future GSP publication callsites. + +`OMC=/path/to/pinned/omc sh tests/dma_host.sh` passes 23 host replay/boundary cases, real invalid-fd +MAP_DMA retry/drop refusal, and 11 compiling negative-control mutants. Only anonymous host memory and +invalid fd -1 are exercised by the real backend; the DMA success/error transport is explicit test-only +link-time replay. No device open/release, DMA, hardware MMIO or reset is performed. The separate +simulator diff remains byte-identical across 391 lines. Hardware: **NOT_RUN**. + Test-only referees and harnesses (disclosed; never linked into the driver): `tests/seq_ref.c` and `tests/params_ref.c` (C), the aienux C tools built fresh by the diff scripts, and the shell scripts in `tests/`. Host tools in the build and test path: `sh`, `git`, `sha256sum`, `cc`, QEMU 8.2.2, busybox, zstd, cpio, gzip. +## Boot image and RPC replay boundary + +The new implementation is seeded `.om`, not a C driver hidden behind a wrapper. It reuses the existing +`siout` system-info encoder and `pabuf`/`palen` allocation/channel codecs. `brmalloc`, `brmctrl` and +`brmfree` freeze one pending request and feed those bytes into the queue codec; accepted successful +replies populate `pareply`. Header success and the RM body status are separate checks. Failed replies +leave the consumer reply buffer unchanged. Hardware `chan/chan.om` bind/disable/idle still trap. + +`arbuild` composes the full WPR/libos/log page tables/cached args/shared queue/radix3/bootloader/ +signature/FMC/FMC-args/COT image into `arbuf`, bounded by `arcap <= 16777216`; input staging `arin` +has the same fixed bound. `arsrc/arslen[0..7)` select ELF, RM signature, bootloader, FMC, FMC hash, +FMC key and FMC signature. `arcfg[0..10)` carries explicit profile, DMA width, heap IOVA/size, GPU +instance, regkeys, bootloader code/data/manifest offsets and serialized registry length. `aroff/arsize` +describe all regions; `arcmd/arstat` are queue offsets, `araddr 15` the FMC-args IOVA, `arcot/arclen` +the COT packet and `artail` its EMEM tail. Outputs are invalid after any nonzero status. The registry +input is canonical bounded PACKED_REGISTRY_TABLE bytes, not a foreign runtime. `arboot` connects this +image's preboot queue counters directly to the boot handshake without reconstructing the queue. + +`gsp/owned.om` connects construction to the owned backing: `arstage(epoch)` copies exact arena bytes +through the checked map handle only for the matching IOVA window, boot generation and unpublished +OWN/DMA lifecycle. It never publishes or notifies hardware. `arlose(epoch)` connects a quarantined +boot replay to retention of the matching already-published backing; it cannot unmap or reclaim it. +The final composed host gate `sh tests/boot_dma.sh` uses an explicit link-time DMA oracle, real +anonymous mappings and exact whole-arena comparison. Staging and quarantine mutants are both +detected. Its receipt is `tests/boot-dma-host-receipt.txt`; this is not a device endpoint or fence. + +The host receipt is `tests/gsp-host-receipt.txt`: exact sender frames and boot state/refusal controls; +five complete arena fixtures (including multi-level radix and DWORD/binary/string registry); 31 +invalid arena fixtures; 19 RPC and 12 arena mutants. Build/setup failures and unexpected runtime +traps do not count as detected mutants. These tests use synthetic signed-byte inputs, not valid +firmware authentication or firmware execution. + +The queue layout is the non-confidential-computing NVIDIA 580.173.02 protocol: SWAP_RX, separate element +and RPC sequences, actual aligned-padding checksum validation, bounded wrapped slots, and full-slot +capture. RM_ALLOC deliberately excludes appended params from its logical length and checksum, as +`rpc.c:11194-11228` does. Those tail bytes are not authenticated or checksummed. The supported alloc +params bound is 3984 bytes; oversized/continuation requests refuse, not truncate. This is not a +cryptographic trust boundary. + +Boot replay requires preboot system info and optional nonempty registry, explicit peer queue creation, +INIT_DONE, SET_GUEST_SYSTEM_INFO version handshake, then STATIC_INFO of the supplied expected size. +Private handshake result is an NV_STATUS: zero succeeds (`rpc.c:8764`); it is not a version value. +Version renegotiation refuses instead of guessing. CPU_SEQUENCER suspends the exact received event +until a matching generation/event token is dispatched through `gsp/dispatch.om`. The complete stream +is prevalidated before execution; completion is not fabricated and no acknowledgement RPC is invented. + +`REPLAY_READY` is host state only, never a production resolver capability. Wait budgets count caller +polls, not elapsed time; unrelated events do not replenish them. Publication timeout or corrupt/ +uncorrelated replies quarantine the replay with pending identity retained. Late replies cannot turn +that into success. `breset` only disposes replay images and refuses while a mapped transport is bound; +it cannot reset hardware, prove idle, unmap DMA, or authorize reclaim. Unpublished queue-full refusal +does not consume a sequence number. + +The arena's GB10B/SEC2 profile remains unverified for the Spark target. `gsp/profile.om` classifies the +published BOOT_42 architecture/implementation fields, not a measured device: vendor `nv_ref.h:149-182` +and `nv_arch.h:51,111` identify GB1XX/GB10B; generated FSP/SEC2 HAL selection chooses SEC2/FMC COTv1, +and `nv-firmware-chip-family-select.h:58-62` selects `gb10y`. No device is opened to select a profile. + +Run the host-only commands with the exact C reference checkout and pinned compiler: + +```sh +AIENUX= OMC=/seed/out/omc sh tests/rpc_diff.sh +AIENUX= OMC=/seed/out/omc sh tests/mutants-rpc.sh +AIENUX= OMC=/seed/out/omc sh tests/arena_diff.sh +AIENUX= OMC=/seed/out/omc sh tests/mutants-arena.sh +``` + +Reference pins: aienux `c5bb3a4b9898257658aba0b7178a3c73a0371c27`; NVIDIA +`20e4e6e19cc26ba47b5cbe23130a396be100c427` (tag `580.173.02`); compiler +`397e67040fb74853c6814097fe02ae4e1ebd6f66`, sha256 in `tools/omc.pin`. Compiler PRs #878 and #890 +are pending dependencies, not merged compiler capabilities. The new independent C referee is +test-only, compiled with Ubuntu GCC `13.3.0-6ubuntu2~24.04.1`; it is never linked into `.om` artifacts. +Python `3.12.3` coordinates only exact oracle comparisons and temporary mutation copies. It generates +no production bytes and has no driver runtime role; seeded `.om` already performs the encoding. +Existing shell, coreutils, git and cc remain disclosed verification tooling, not driver runtime dependencies. + +### Still required for independent execution + +Hardware is **NOT_RUN**. The Linux-process mapped mechanism is now implemented separately from the +host replay binding: link exactly one of `gsp/replay.om` or `gsp/transport.om` (with `gsp/profile.om` +and `gsp/notify.om`). There is no implicit transport fallback. `qtattach` requires the exact staged, +published owned-map epoch and boot generation. `rqprep`/`rqcommit` separate construction from +publication; stale tokens cannot publish a second time. + +`qtsend` writes only owned slots, publishes command writePtr with an aligned `mapset`, then writes +zero to PGSP_QUEUE_HEAD(0). `qtsnap` acquires peer writePtr, captures only its bounded immutable +prefix, and `qtaccept` validates that capture before publishing host readPtr. SWAP_RX cursor ownership +is preserved. Semantic RPC rejection can occur after transport consumption and quarantines without +rolling back an already published cursor. Notification failure after publication is uncertain, not +an unsent request eligible for retry. Bound mappings remain retained on timeout/error. + +`gsp/service.om` supplies `drvstep useRM`, a serialized pump that dispatches suspended sequencer +events before allowing either boot or RM policy to continue. `drvprep appVersion b0 b1 b2 b3` +copies the exact composed COT/FMC-argument inputs into the existing MMIO boot sequencer's input +buffers. It neither calls that sequencer nor authorizes device effects; firmware appVersion is +validated caller input. No host fixture invokes hardware mode, and no production resolver is added. + +The pinned process compiler brackets each aligned `mapget`/`mapset` with DSB SY. This orders accesses +but does not establish cache coherency, memory attributes, cache maintenance, interrupt delivery or +device completion. Bulk mapread/mapwrite are ordinary copies, never cursor accesses. Host peers and +instruction inspection cannot qualify those device properties. A fatal mapping fault is not a +recoverable status and process-local quarantine is not crash-safe containment. + +The host receipt for the mapped transport, sequencer dispatch, RM channel and completion slices is +`tests/transport-host-receipt.txt` (all 27 `tests/*.sh` scripts, exact hashes and tool versions). +`tests/window_sim.sh` needs `build/omc` to be the compiler named in `tools/omc.pin`. + +`chan/rmchan.om` connects the existing allocation codecs to async RM hierarchy/schedule/disable/free; +`chan/complete.om` uses Blackwell completion-semaphore releases, never nonexistent USERD GPGet. +`chprep` allocates and encodes channel backing only (state 2, prepared): `rmbind` accepts only a +prepared channel, the schedule ACK alone makes it submit-ready (state 1), and the disable ACK +returns it to prepared. `chcreate` keeps the legacy simulator bind, which refuses an owned map. +Drained host tracking is not proof that GSP stopped accessing the boot arena and never authorizes its +reclamation. Hardware sequencer dispatch refuses regardless of host permission flags: a typed +MMIO lease/span and engine-specific core effects are absent from this pin. Completion semaphore +progress alone is not cache/engine completion: the vendor WFI/membar sequence is a separate required +effect boundary, not supplied by a CPU fence or inferred from an observed semaphore value. + +The current compiler profile is Linux-process ELF/VFIO, not Linux kernel code. A Linux-hosted `.om` +user-space driver could replace NVIDIA modules while retaining Linux VFIO/IOMMU services; that is not +an Omega kernel module or a replacement for Linux. This pin does not provide kernel calling/trap ABI, +relocation/link profile, kernel-owned allocation/resource spans, ordered DMA/MMIO or IRQ/workqueue +lifecycle. The proposed typed kernel effects are a separate pending compiler extension, not an +implemented trust path. Actual device identity, coherent DMA ownership, firmware authentication, +hardware boot/RPC, engine reset/halt, interrupt handling and documented global idle/recovery still +require implementation/qualification at those boundaries. No C/Rust runtime substitute is adopted. + ## On the GB10 (authorized exclusive window only) `window/README.md` is the procedure: W0 read-only checks, W1 reboot with nvidia.ko held back, W2 bind to diff --git a/chan/chan.om b/chan/chan.om index 01fc04a..9ccae00 100644 --- a/chan/chan.om +++ b/chan/chan.om @@ -3,7 +3,7 @@ note PR #441 native/kernel/gpu/gpu_chan.c and gpu_chan.h (branch pr441 @ c5bb3a4 note Prefix ch / CH. Needs chan/gmmu.om and chan/mem.om before it, and chan/sim.om (mode 0 ops). note note A channel is a slot 0..3 (CHSLOTS); its buffers are chan/mem.om slots. The CPU writes the ring, -note USERD GPPut and the instance block through mmwin; the doorbell goes through mmregwr. +note USERD GPPut and the instance block through mmrd/mmwr (array or owned mapping); doorbell mmregwr. note note Channel ops (C: a function-pointer table): chbindop / chdisop / chidlop. mmmode 0 calls the note simulator (chan/sim.om gsbind / gsdisable / gsidle). On GB10 the channel is allocated, scheduled @@ -69,6 +69,7 @@ global chin ulong 4 global chput uint 4 global chret uint 4 global chopen uchar 4 +global chepoch ulong 4 global chrlo uint 2 global chx ulong 8 fn chtoken rl uint chid uint to uint @@ -89,6 +90,10 @@ fn chmthd subc uint mthd uint count uint to uint ret or or or CHNINC shl count 16 shl subc 13 shr mthd 2 end fn chbindop c ulong to long +if eq get mmwkind 0 1 +note Hardware channel RPC is absent here. Refuse before publication; never walk unrelated mmwin. +ret -95 +end if ne get mmmode 0 0 trap 9 end @@ -107,6 +112,9 @@ end ret gsidle chid end fn chinit to void +if and eq get mmwkind 0 1 not mmwmutable +trap 9 +end for c ulong CHSLOTS put chopen c 0 put chgp c GMNONE @@ -132,7 +140,26 @@ put chud c GMNONE put chin c GMNONE ret CHENOMEM end +note Separate backing preparation from RPC allocation/scheduling; state2 cannot submit. fn chcreate c ulong chid uint rl uint ent uint to long +r = chprep c chid rl ent +if ne r CHOK +ret r +end +if ne chbindop c 0 +r = gmfree get chin c +r = gmfree get chud c +r = gmfree get chgp c +put chopen c 0 +ret CHEBIND +end +put chopen c 1 +ret CHOK +end +fn chprep c ulong chid uint rl uint ent uint to long +if or not mmwmutable ne get gmepoch 0 get mmwgen 0 +ret CHESTATE +end if ge c CHSLOTS ret CHEINVAL end @@ -143,6 +170,7 @@ if or or lt ent 2 gt ent 65536 ne and ent sub ent 1 0 ret CHEINVAL end put chopen c 0 +put chepoch c get mmwgen 0 put chput c 0 put chret c 0 put chgp c GMNONE @@ -192,17 +220,14 @@ ret chnomem c end put chrl0 c get chrlo 0 put chrl1 c get chrlo 1 -if ne chbindop c 0 -r = gmfree get chin c -r = gmfree get chud c -r = gmfree get chgp c -ret CHEBIND -end -put chopen c 1 +put chopen c 2 ret CHOK end fn chsubmit c ulong pb ulong off uint n uint to long -if or ge c CHSLOTS eq get chopen c 0 +if or ge c CHSLOTS ne get chopen c 1 +ret CHESTATE +end +if ne get chepoch c get mmwgen 0 ret CHESTATE end if not gmlive pb @@ -240,6 +265,9 @@ fn chretire c ulong upto uint to void if ge c CHSLOTS ret end +if ne get chepoch c get mmwgen 0 +ret +end r = get chret c if le sub upto r sub get chput c r put chret c upto @@ -249,16 +277,22 @@ fn chteardown c ulong budget uint nx ulong to long if or ge c CHSLOTS eq get chopen c 0 ret CHESTATE end +if ne get chepoch c get mmwgen 0 +ret CHESTATE +end put chopen c 0 chid = get chchid c d = chdisop chid idle = false for i uint budget -if ne chidlop chid 0 +if and eq d 0 eq chidlop chid 1 idle = true break end end +if and not idle eq get mmwkind 0 1 +r = mmwquar get mmwgen 0 +end rc = CHOK for k ulong 3 b = get chin c diff --git a/chan/complete.om b/chan/complete.om new file mode 100644 index 0000000..38230ac --- /dev/null +++ b/chan/complete.om @@ -0,0 +1,379 @@ +note chan/complete.om: completion semaphore producer/consumer protocol, command encoding, +note wrap-safe sequence progress tracking, and bounded drain policy for Blackwell GPFIFO channels. +note Layout source of record: NVIDIA open-gpu-kernel-modules 580.173.02 (MIT) clc96f.h:75-89, +note uvm_hopper_host.c:45-52. Library unit, no main. Prefix cm / CM. +note +note Blackwell USERD (Nvc96fControl, clc96f.h:29-33) has GPPut at offset 0x8c (140) and NO GPGet; +note Ignored01 covers bytes 0x90..0x1ff (512 bytes). Completion is tracked exclusively through +note hardware semaphores released into host-visible memory, never via caller assertion or GPGet. +note +note Pure protocol: +note cmhdr subc count -> uint incMethod header (2<<28 | count<<16 | subc<<13 | 23) +note cmrel subc va seq -> long encodes 5-method release command into cmwds[0..5] +note cmacq subc va seq -> long encodes 5-method acquire command into cmwds[0..5] +note cmprog ret put obs -> long wrap-safe sequence check; returns newly completed entries, +note 0 for pending, or CMESTALE (-5) for out-of-order/wrapped +note cmputpb b off subc va seq -> long writes 6-word release command into pushbuffer b at offset off +note +note Typed mapped effect adapter: +note cminit -> long initializes only unused tracker state; refuses retained bindings +note cmbind c slot off gen -> long verifies mapped host capabilities; never hardware admission +note cmsub c count -> long accounts only already-submitted channel entries within capacity +note cmpoll c -> long polls memory via mmrd32, advances retired, calls chretire +note cmdrain c budget -> long bounded poll loop; quarantines backing on timeout/error +note cmquar c gen -> long uncertainty latch; quarantines semaphore and window +note +note Status codes: 0 CMOK, -1 CMEINVAL, -2 CMEALIGN, -3 CMERANGE, -4 CMESTATE, -5 CMESTALE, +note -6 CMEFULL, -10 CMEGEN, -11 CMETIME, -12 CMEQUAR. No CPU/GPU ordering or cache flush is implied. +note Vendor uvm_hopper_host.c:43 requires wfi_membar before release. cmrel is ONLY the release packet. +note Production use additionally needs a qualified engine/cache fence and ordered mapped effects. +const CMOK long 0 +const CMEINVAL long -1 +const CMEALIGN long -2 +const CMERANGE long -3 +const CMESTATE long -4 +const CMESTALE long -5 +const CMEFULL long -6 +const CMEGEN long -10 +const CMETIME long -11 +const CMEQUAR long -12 +note NVC96F method byte offsets +const CMSADDR ulong 92 +const CMSHI ulong 96 +const CMSPLO ulong 100 +const CMSPHI ulong 104 +const CMSEXEC ulong 108 +note Method index in method space: 0x5c / 4 = 23 +const CMSEMM uint 23 +note CHNINC header (2 << 28) = 536870912 +const CMINC uint 536870912 +const CMCWDS ulong 6 +note Channel slots +const CMSLOTS ulong 4 +note Tracker states +const CMSNONE ulong 0 +const CMSBIND ulong 1 +const CMSACTV ulong 2 +const CMSDRN ulong 3 +const CMSIDLE ulong 4 +const CMSTOUT ulong 5 +const CMSQST ulong 6 +global cmwds uint 6 +global cmlen ulong 1 +global cmgen ulong 4 +global cmbuf ulong 4 +global cmbgen ulong 4 +global cmpa ulong 4 +global cmva ulong 4 +global cmret uint 4 +global cmput uint 4 +global cmst ulong 4 +fn cmhdr subc uint count uint to uint +ret or or CMINC shl and count 1023 16 or shl and subc 7 13 CMSEMM +end +fn cmrel subc uint va ulong seq uint to long +if gt subc 7 +ret CMEINVAL +end +if ne and va 3 0 +ret CMEALIGN +end +if or eq va 0 ge va MMVALIM +ret CMERANGE +end +put cmwds 0 cmhdr subc 5 +put cmwds 1 and uint and va 4294967295 4294967292 +put cmwds 2 and uint shr va 32 33554431 +put cmwds 3 seq +put cmwds 4 0 +put cmwds 5 1 +put cmlen 0 CMCWDS +ret long CMCWDS +end +fn cmacq subc uint va ulong seq uint to long +if gt subc 7 +ret CMEINVAL +end +if ne and va 3 0 +ret CMEALIGN +end +if or eq va 0 ge va MMVALIM +ret CMERANGE +end +put cmwds 0 cmhdr subc 5 +put cmwds 1 and uint and va 4294967295 4294967292 +put cmwds 2 and uint shr va 32 33554431 +put cmwds 3 seq +put cmwds 4 0 +put cmwds 5 0 +put cmlen 0 CMCWDS +ret long CMCWDS +end +fn cmprog ret_ uint put_ uint obs uint to long +inflight = sub put_ ret_ +if eq inflight 0 +if eq obs ret_ +ret 0 +end +ret CMESTALE +end +prog = sub obs ret_ +if eq prog 0 +ret 0 +end +if gt prog inflight +ret CMESTALE +end +ret long prog +end +fn cmputpb b ulong off uint subc uint va ulong seq uint to long +if ge b GMMAXB +ret CMEINVAL +end +if not gmlive b +ret CMEINVAL +end +if ne and off 3 0 +ret CMEALIGN +end +sz = get gmbsz b +span = mul CMCWDS 4 +if or gt ulong off sz gt span sub sz ulong off +ret CMERANGE +end +rc = cmrel subc va seq +if lt rc 0 +ret rc +end +pa = add get gmbpa b ulong off +for i ulong 6 +mmwr32 add pa mul i 4 ulong get cmwds i +end +ret long CMCWDS +end +fn cminit to long +for c ulong CMSLOTS +st = get cmst c +if ne st CMSNONE +ret CMESTATE +end +end +for c ulong CMSLOTS +put cmgen c 0 +put cmbuf c GMNONE +put cmbgen c 0 +put cmpa c 0 +put cmva c 0 +put cmret c 0 +put cmput c 0 +put cmst c CMSNONE +end +put cmlen 0 0 +ret CMOK +end +fn cmbind c ulong slot ulong off uint gen ulong to long +if ge c CMSLOTS +ret CMEINVAL +end +if ne get mmwkind 0 1 +ret CMESTATE +end +if or lt get mmwst 0 MMWDMA ge get mmwst 0 MMWQUAR +ret CMESTATE +end +if ne get mmwgen 0 gen +ret CMEGEN +end +if ge slot GMMAXB +ret CMEINVAL +end +if not gmlive slot +ret CMEINVAL +end +if ne get cmst c CMSNONE +ret CMESTATE +end +if or eq get chopen c 0 ne get chepoch c gen +ret CMESTATE +end +if ne get chret c get chput c +ret CMESTATE +end +if eq and get gmbfl slot GMHPOLL 0 +ret CMESTATE +end +if ne get gmbca slot 1 +ret CMESTATE +end +if ne and off 3 0 +ret CMEALIGN +end +sz = get gmbsz slot +if gt add ulong off 4 sz +ret CMERANGE +end +pa = add get gmbpa slot ulong off +va = add get gmbva slot ulong off +put cmgen c gen +put cmbuf c slot +put cmbgen c ulong get gmbgen slot +put cmpa c pa +put cmva c va +put cmret c get chput c +put cmput c get chput c +put cmst c CMSBIND +mmwr32 pa ulong get chput c +ret CMOK +end +fn cmsub c ulong count uint to long +if ge c CMSLOTS +ret CMEINVAL +end +st = get cmst c +if and and ne st CMSBIND ne st CMSACTV ne st CMSIDLE +ret CMESTATE +end +if ne get mmwgen 0 get cmgen c +ret CMEGEN +end +if ne get mmwst 0 MMWPUB +ret CMESTATE +end +b = get cmbuf c +if not gmlive b +ret CMESTATE +end +if ne get cmbgen c ulong get gmbgen b +ret CMEGEN +end +ent = get chent c +if or eq count 0 eq ent 0 +ret CMEINVAL +end +p = get cmput c +r = get cmret c +inflight = sub p r +if ge inflight ent +ret CMEFULL +end +if gt count sub sub ent 1 inflight +ret CMEFULL +end +chp = get chput c +if ne r get chret c +ret CMESTALE +end +avail = sub chp p +if or ge avail ent gt count avail +ret CMERANGE +end +put cmput c add p count +put cmst c CMSACTV +ret CMOK +end +fn cmpoll c ulong to long +if ge c CMSLOTS +ret CMEINVAL +end +st = get cmst c +if and and and ne st CMSBIND ne st CMSACTV ne st CMSDRN ne st CMSIDLE +ret CMESTATE +end +if ne get mmwgen 0 get cmgen c +ret CMEGEN +end +if ne get mmwst 0 MMWPUB +ret CMESTATE +end +b = get cmbuf c +if not gmlive b +ret CMESTATE +end +if ne get cmbgen c ulong get gmbgen b +ret CMEGEN +end +pa = get cmpa c +obs = uint mmrd32 pa +r = get cmret c +p = get cmput c +diff = cmprog r p obs +if lt diff 0 +ret diff +end +if eq diff 0 +ret 0 +end +put cmret c obs +chretire c obs +if eq obs p +put cmst c CMSIDLE +end +ret diff +end +fn cmdrain c ulong budget uint to long +if ge c CMSLOTS +ret CMEINVAL +end +st = get cmst c +if and and and ne st CMSBIND ne st CMSACTV ne st CMSDRN ne st CMSIDLE +ret CMESTATE +end +if ne get mmwgen 0 get cmgen c +ret CMEGEN +end +if ne get mmwst 0 MMWPUB +ret CMESTATE +end +b = get cmbuf c +if not gmlive b +ret CMESTATE +end +if ne get cmbgen c ulong get gmbgen b +ret CMEGEN +end +if or ne get cmput c get chput c ne get cmret c get chret c +ret CMESTALE +end +if eq get cmret c get cmput c +put cmst c CMSIDLE +ret CMOK +end +put cmst c CMSDRN +drained = false +for i uint budget +r = cmpoll c +if lt r 0 +break +end +if eq get cmret c get cmput c +drained = true +break +end +end +if drained +put cmst c CMSIDLE +ret CMOK +end +put cmst c CMSTOUT +note b is live under a published owned window: gmquar retires it AND quarantines the window (gmretire). +r = gmquar b +put cmst c CMSQST +ret CMETIME +end +fn cmquar c ulong gen ulong to long +if ge c CMSLOTS +ret CMEINVAL +end +if ne gen get cmgen c +ret CMEGEN +end +b = get cmbuf c +if ne b GMNONE +r = gmquar b +end +if eq get mmwst 0 MMWPUB +r = mmwquar gen +end +put cmst c CMSQST +ret CMOK +end diff --git a/chan/dma.om b/chan/dma.om new file mode 100644 index 0000000..08861f1 --- /dev/null +++ b/chan/dma.om @@ -0,0 +1,44 @@ +note chan/dma.om: production whole-window VFIO DMA transport for chan/gmmu.om. +note Linux include/uapi/linux/vfio.h struct vfio_iommu_type1_dma_map/unmap. +note Compiler397e6704 validates a live RW handle in vaddr and substitutes its base/whole size. +note No open, close, reset, container adoption or authorization is performed here. +note mmdmaop 1 maps; 2 unmaps. mmduout is actual unmapped bytes, only meaningful after rc0. +global mmduout ulong 1 +fn mmdput b edit uchar 32 off ulong v ulong to void +for i ulong 8 +put b add off i uchar and shr v mul i 8 255 +end +end +fn mmdget b view uchar 32 off ulong to ulong +v = ulong 0 +for i ulong 8 +v = or v shl ulong get b add off i mul i 8 +end +ret v +end +fn mmdmaop op ulong fd int h long iova ulong size ulong to long +b = new uchar 32 0 +put mmduout 0 0 +if eq op 1 +put b 0 32 +put b 4 3 +mmdput b 8 ulong h +mmdput b 16 iova +mmdput b 24 size +ret vfioctl fd 15217 b 0 32 +end +if ne op 2 +ret -22 +end +put b 0 24 +mmdput b 8 iova +mmdput b 16 size +r = vfioctl fd 15218 b 0 24 +if eq r 0 +put mmduout 0 mmdget b 16 +end +ret r +end +fn mmdrop h long to long +ret mapdrop h +end diff --git a/chan/gmmu.om b/chan/gmmu.om index 5eb24b6..4532eec 100644 --- a/chan/gmmu.om +++ b/chan/gmmu.om @@ -1,18 +1,24 @@ note chan/gmmu.om: GB10 (Blackwell, ver3) GPU page tables and TLB invalidate, ported from aienux PR #441 note native/kernel/gpu/gmmu.c and gmmu.h (branch pr441 @ c5bb3a4b). Library unit: no main. Prefix mm / MM. -note Concatenate with chan/mem.om, chan/chan.om, chan/sim.om (the mode 0 device) before a test or driver. +note Concatenate with chan/dma.om, chan/mem.om, chan/chan.om, chan/sim.om before a test or driver. note -note Window: the C takes any caller window (cpu pointer, pa_base, size). Omega cannot hand out a pointer, -note so the window is the one global mmwin (8 MiB), at bus address mmwb with mmws bytes in use; mmwinit -note sets them. The page-table pool, the buffers of chan/mem.om and the channel's rings all live inside it, -note and chan/sim.om reads GPU-visible memory from the same array (in the C the simulator's mem is the -note window too). On hardware the integrator DMA-maps mmwin and passes its IOVA as mmwb. +note Two explicit memory backends: mmwinit selects the simulator's mmwin array. mmwalloc owns a +note shared anonymous mapnew handle; mmwdmap maps that whole extent into an already-authorized VFIO +note container. mmwb is IOVA, mmwcpu is informational CPU base, mmmap's va is GPU VA: never aliases. +note No array address is a DMA handle. CPU access to owned memory is handle plus checked byte offset. +note Publication is sticky; published/quarantined backing and its suballocations are never recycled. note note Register seam (as gsp/mmio.om gsprd / gspwr): mmmode 0 = simulator (chan/sim.om gsrd / gswr), note mmmode 1 = 4-byte mapget / mapset on the vfiomapw BAR0 handle in mmbar, any other mode traps 9. note note API (state in globals; a global is never an argument): -note mmwinit base size -> long window at bus address base, size bytes (1..8388608) +note mmwinit base size -> long simulator array only; refuses replacement of any owned window +note mmwalloc iova size -> long own anonymous RW backing; mmwh handle, mmwgen monotonic epoch +note mmwdmap gen fd -> long whole-window DMA map; retains caller-owned container fd identity +note mmwpublish gen -> long BEFORE exposing any IOVA; no hardware idle/reclaim API exists +note mmwquar gen -> long uncertainty latch; no retry/unmap/drop after quarantine +note mmwclose gen -> long unmap exact original extent BEFORE drop, unpublished only +note mmwerr holds last signed OS result; MMEIO/MMEGEN/MMESTATE are backend statuses 9/10/11 note mmasinit pool pages -> long ck_gmmu_as_init: page-table pool of pages 4 KiB pages at pool note mmmap va pa size page ap pcf ck_gmmu_map; mmunmap va size page: ck_gmmu_unmap note mminval budget -> long ck_gmmu_invalidate (poll the trigger register budget times) @@ -34,6 +40,14 @@ const MMENOMEM long 5 const MMENOENT long 6 const MMETIME long 7 const MMEDEAD long 8 +const MMEIO long 9 +const MMEGEN long 10 +const MMESTATE long 11 +const MMWNONE ulong 0 +const MMWOWN ulong 1 +const MMWDMA ulong 2 +const MMWPUB ulong 3 +const MMWQUAR ulong 4 note walk results: free, mapped, missing (create 0), conflict const MMWFREE ulong 0 const MMWMAP ulong 1 @@ -67,6 +81,15 @@ global mmwb ulong 1 global mmws ulong 1 global mmmode ulong 1 global mmbar long 1 +global mmwkind ulong 1 +global mmwst ulong 1 +global mmwh long 1 +global mmwcpu ulong 1 +global mmwgen ulong 1 +global mmwfd int 1 +global mmwerr long 1 +global mmasep ulong 1 +global mmbyte uchar 1 global mmptpa ulong 64 global mmptus uchar 64 global mmptn ulong 1 @@ -88,6 +111,11 @@ end ret mapget get mmbar 0 off 4 end fn mmregwr off ulong v ulong to void +if eq get mmwkind 0 1 +if ne mmwpublish get mmwgen 0 MMOK +trap 9 +end +end m = get mmmode 0 if eq m 0 gswr off v @@ -101,19 +129,198 @@ if ne r 0 trap 9 end end -fn mmwinit base ulong size ulong to long +note The caller owns container lifetime exclusively. No fork, fd close/reuse or process restart may +note release quarantined resources. This process-local latch is not crash-safe DMA containment. +fn mmwshape base ulong size ulong to long if or eq size 0 gt size MMWINMAX ret MMEINVAL end -if lt add base size base +if or ge base MMPALIM gt size sub MMPALIM base ret MMERANGE end +ret MMOK +end +fn mmwnext to long +if eq get mmwgen 0 18446744073709551615 +ret MMEGEN +end +put mmwgen 0 add get mmwgen 0 1 +put mmptn 0 0 +put mmroot 0 0 +put mmasep 0 0 +put mmdead 0 0 +ret MMOK +end +fn mmwinit base ulong size ulong to long +if ne get mmwkind 0 0 +ret MMEBUSY +end +r = mmwshape base size +if ne r MMOK +ret r +end +r = mmwnext +if ne r MMOK +ret r +end put mmwb 0 base put mmws 0 size +put mmwst 0 MMWOWN +ret MMOK +end +fn mmwalloc iova ulong size ulong to long +if ne get mmwst 0 MMWNONE +ret MMEBUSY +end +r = mmwshape iova size +if ne r MMOK +ret r +end +if or ne and iova 4095 0 ne and size 4095 0 +ret MMEALIGN +end +if eq get mmwgen 0 18446744073709551615 +ret MMEGEN +end +h = mapnew -1 0 size 3 33 +if lt h 0 +put mmwerr 0 h +ret MMEIO +end +r = mmwnext +put mmwh 0 h +put mmwcpu 0 mapaddr h +put mmwb 0 iova +put mmws 0 size +put mmwfd 0 -1 +put mmwkind 0 1 +put mmwst 0 MMWOWN +put mmwerr 0 0 +ret r +end +fn mmwepoch gen ulong to bool +ret and ne get mmwst 0 MMWNONE eq gen get mmwgen 0 +end +fn mmwdmap gen ulong fd int to long +if not mmwepoch gen +ret MMEGEN +end +if or ne get mmwkind 0 1 ne get mmwst 0 MMWOWN +ret MMESTATE +end +note Reconstruct request on every attempt: compiler replaces vaddr handle even on ioctl failure. +r = mmdmaop 1 fd get mmwh 0 get mmwb 0 get mmws 0 +put mmwerr 0 r +if eq r 0 +put mmwfd 0 fd +put mmwst 0 MMWDMA +ret MMOK +end +note EBADF proves no ioctl target was reached. All other failures retain uncertain ownership. +if ne r -9 +put mmwfd 0 fd +put mmwst 0 MMWQUAR +end +ret MMEIO +end +fn mmwpublish gen ulong to long +if not mmwepoch gen +ret MMEGEN +end +if ne get mmwkind 0 1 +ret MMESTATE +end +if eq get mmwst 0 MMWPUB +ret MMOK +end +if ne get mmwst 0 MMWDMA +ret MMESTATE +end +put mmwst 0 MMWPUB +ret MMOK +end +fn mmwquar gen ulong to long +if not mmwepoch gen +ret MMEGEN +end +if ne get mmwkind 0 1 +ret MMESTATE +end +put mmwst 0 MMWQUAR +put mmdead 0 1 +ret MMOK +end +fn mmwmutable to bool +if eq get mmwst 0 MMWNONE +ret false +end +if eq get mmwkind 0 0 +ret true +end +ret or eq get mmwst 0 MMWOWN eq get mmwst 0 MMWDMA +end +fn mmwclose gen ulong to long +if not mmwepoch gen +ret MMEGEN +end +if not mmwmutable +ret MMEBUSY +end +if eq get mmwkind 0 1 +if eq get mmwst 0 MMWDMA +r = mmdmaop 2 get mmwfd 0 get mmwh 0 get mmwb 0 get mmws 0 +put mmwerr 0 r +if or ne r 0 ne get mmduout 0 get mmws 0 +r = mmwquar gen +ret MMEIO +end +put mmwst 0 MMWOWN +end +r = mmdrop get mmwh 0 +put mmwerr 0 r +if ne r 0 +r = mmwquar gen +ret MMEIO +end +end +put mmwh 0 0 +put mmwcpu 0 0 +put mmwfd 0 -1 +put mmwb 0 0 +put mmws 0 0 +put mmwkind 0 0 +put mmwst 0 MMWNONE +put mmptn 0 0 +put mmroot 0 0 +put mmasep 0 0 ret MMOK end +fn mmwoff pa ulong n ulong wr bool to ulong +if eq get mmwst 0 MMWNONE +trap 3 +end +if and wr eq get mmwst 0 MMWQUAR +trap 9 +end +b = get mmwb 0 +s = get mmws 0 +if lt pa b +trap 3 +end +o = sub pa b +if gt o s +trap 3 +end +if gt n sub s o +trap 3 +end +ret o +end fn mmrd64 pa ulong to ulong -o = sub pa get mmwb 0 +o = mmwoff pa 8 false +if eq get mmwkind 0 1 +ret mapget get mmwh 0 o 8 +end v = ulong 0 for i ulong 8 v = or shl v 8 ulong get mmwin add o sub 7 i @@ -121,13 +328,23 @@ end ret v end fn mmwr64 pa ulong v ulong to void -o = sub pa get mmwb 0 +o = mmwoff pa 8 true +if eq get mmwkind 0 1 +r = mapset get mmwh 0 o 8 v +if ne r 0 +trap 9 +end +ret +end for i ulong 8 put mmwin add o i uchar and shr v mul i 8 255 end end fn mmrd32 pa ulong to ulong -o = sub pa get mmwb 0 +o = mmwoff pa 4 false +if eq get mmwkind 0 1 +ret mapget get mmwh 0 o 4 +end v = ulong 0 for i ulong 4 v = or shl v 8 ulong get mmwin add o sub 3 i @@ -135,19 +352,51 @@ end ret v end fn mmwr32 pa ulong v ulong to void -o = sub pa get mmwb 0 +o = mmwoff pa 4 true +if eq get mmwkind 0 1 +r = mapset get mmwh 0 o 4 v +if ne r 0 +trap 9 +end +ret +end for i ulong 4 put mmwin add o i uchar and shr v mul i 8 255 end end fn mmwr8 pa ulong v uchar to void -put mmwin sub pa get mmwb 0 v +o = mmwoff pa 1 true +if eq get mmwkind 0 1 +put mmbyte 0 v +r = mapwrite get mmwh 0 o mmbyte 0 1 +if ne r 1 +trap 9 +end +ret +end +put mmwin o v end fn mmzero pa ulong n ulong to void -o = sub pa get mmwb 0 +o = mmwoff pa n true +if gt n 1000000 +trap 4 +end +if eq get mmwkind 0 0 for i ulong n put mmwin add o i 0 end +ret +end +off = ulong 0 +while lt off n bound 999999 +if and eq and add o off 7 0 ge sub n off 8 +mmwr64 add pa off 0 +off = add off 8 +else +mmwr8 add pa off 0 +off = add off 1 +end +end end note entry encoders (gmmu.c ck_gmmu_pde / ck_gmmu_dual_pde / ck_gmmu_pte) fn mmpde pa ulong ap ulong to ulong @@ -231,6 +480,9 @@ end ret le size sub s o end fn mmptalloc to long +if not mmwmutable +ret MMEBUSY +end n = get mmptn 0 for i ulong n if eq get mmptus i 0 @@ -253,6 +505,12 @@ end ret c end fn mmasinit pool ulong pages ulong to long +if not mmwmutable +ret MMEBUSY +end +if and eq get mmwkind 0 1 eq get mmasep 0 get mmwgen 0 +ret MMEBUSY +end if or or eq get mmws 0 0 or lt pages 2 gt pages MMMAXPT ne and pool 4095 0 ret MMEINVAL end @@ -261,6 +519,7 @@ if not ok ret MMERANGE end put mmptn 0 pages +put mmasep 0 get mmwgen 0 put mmdead 0 0 for i ulong MMMAXPT if lt i pages @@ -437,6 +696,12 @@ end ret need end fn mmmap va ulong pa ulong size ulong page ulong ap ulong pcf ulong to long +if not mmwmutable +ret MMEBUSY +end +if ne get mmasep 0 get mmwgen 0 +ret MMEGEN +end rc = mmchk va size page if ne rc MMOK ret rc @@ -470,6 +735,12 @@ end ret MMOK end fn mmunmap va ulong size ulong page ulong to long +if not mmwmutable +ret MMEBUSY +end +if ne get mmasep 0 get mmwgen 0 +ret MMEGEN +end rc = mmchk va size page if ne rc MMOK ret rc @@ -493,6 +764,15 @@ fn mminval budget ulong to long if ne get mmdead 0 0 ret MMEDEAD end +if or eq get mmroot 0 0 ne get mmasep 0 get mmwgen 0 +ret MMEGEN +end +if eq get mmwkind 0 1 +r = mmwpublish get mmwgen 0 +if ne r MMOK +ret r +end +end pdb = shr get mmroot 0 12 mmregwr MMRPDB or shl and pdb 268435455 4 MMPDBAP mmregwr MMRUPR and shr pdb 28 1048575 @@ -503,5 +783,8 @@ ret MMOK end end put mmdead 0 1 +if eq get mmwkind 0 1 +r = mmwquar get mmwgen 0 +end ret MMETIME end diff --git a/chan/mem.om b/chan/mem.om index 5c48aec..c8dbb24 100644 --- a/chan/mem.om +++ b/chan/mem.om @@ -13,7 +13,7 @@ note gmalloc size cache flags -> long ck_gmem_alloc; the new slot in gmout note gmfree b / gmquar b -> long ck_gmem_free / ck_gmem_quarantine note gmcount st -> ulong ck_gmem_count (pages in state st) note gmlive b -> bool slot b is a buffer in state LIVE -note per slot: gmbpa (bus address; the CPU view is mmwin at gmbpa - mmwb), gmbva (GPU VA), gmbsz, +note per slot: gmbpa (IOVA; CPU access goes through mmrd/mmwr handle+offset), gmbva (GPU VA), gmbsz, note gmbca, gmbfl, gmbst, gmbgen (uint, wraps as the C uint32) note codes (enum ck_gmem_status): 0 GMOK, 1 GMEINVAL, 2 GMENOMEM, 3 GMESTATE, 4 GMEMAP, 5 GMETIME note cache: 0 cached, 1 uncached; flags: 1 host polled (needs uncached), 2 GPU read-only @@ -45,7 +45,14 @@ global gmbfl ulong 64 global gmbst uchar 64 global gmbgen uint 64 global gmout ulong 1 +global gmepoch ulong 1 fn gminit poll ulong pab ulong pages ulong vab ulong to long +if or not mmwmutable ne get mmasep 0 get mmwgen 0 +ret GMESTATE +end +if and eq get mmwkind 0 1 eq get gmepoch 0 get mmwgen 0 +ret GMESTATE +end if or eq get mmptn 0 0 eq get mmws 0 0 ret GMEINVAL end @@ -62,6 +69,7 @@ put gmpoll 0 poll put gmpab 0 pab put gmvab 0 vab put gmpages 0 pages +put gmepoch 0 get mmwgen 0 for i ulong GMMAXP put gmpgst i GMFREE end @@ -94,6 +102,9 @@ end ret GMOK end fn gmlive b ulong to bool +if or eq get mmwst 0 MMWNONE ne get gmepoch 0 get mmwgen 0 +ret false +end if ge b GMMAXB ret false end @@ -107,6 +118,9 @@ put gmpgst add first i st end end fn gmalloc size ulong cache ulong flags ulong to long +if or not mmwmutable ne get gmepoch 0 get mmwgen 0 +ret GMESTATE +end note flags & ~3 != 0 is flags > 3 for an unsigned value if or or or eq size 0 gt size mul GMMAXP 4096 gt cache 1 gt flags 3 ret GMEINVAL @@ -191,6 +205,28 @@ fn gmretire b ulong reuse bool to long if not gmlive b ret GMESTATE end +if eq get mmwkind 0 1 +note No documented idle proof exists, even after successful TLB invalidation. +if not mmwmutable +gmsetpg b GMQUAR +put gmbst b GMQUAR +r = mmwquar get mmwgen 0 +ret GMETIME +end +note Unpublished owned buffers can retire without exposing their root through mminval. +um = mmunmap get gmbva b get gmbsz b MMSZ4K +if and reuse eq um MMOK +gmsetpg b GMFREE +put gmbst b GMFREE +ret GMOK +end +gmsetpg b GMQUAR +put gmbst b GMQUAR +if not reuse +ret GMOK +end +ret GMEMAP +end um = mmunmap get gmbva b get gmbsz b MMSZ4K iv = um if eq um MMOK diff --git a/chan/rmchan.om b/chan/rmchan.om new file mode 100644 index 0000000..4918648 --- /dev/null +++ b/chan/rmchan.om @@ -0,0 +1,654 @@ +note chan/rmchan.om: async RM object and channel allocation, scheduling, drain, and free +note state machine for Blackwell GPFIFO channels over GSP-RM RPCs. +note Layout source of record: NVIDIA open-gpu-kernel-modules 580.173.02 (MIT) clc96f.h, +note cla06c.h, kernel_channel.c:2814-2821. Library unit, no main. Prefix rm / RM. +note +note RM object hierarchy: +note Client -> Device; Device owns Subdevice, VASpace, ChannelGroup and ChannelGPFIFO. +note ChannelGroup owns ContextShare. Allocation order is not a chain of parent handles. +note +note Schedule control: +note NVA06C_CTRL_CMD_GPFIFO_SCHEDULE (PACMSCH 2691432705): bEnable 1 (start) / 0 (disable). +note +note Teardown order: +note Free Channel -> Free CtxShare -> Free ChannelGroup -> Free VASpace -> Free Subdev -> +note Free Device -> Free Client. +note +note Pure protocol: +note rminit -> long resets only unbound IDLE/DONE policy, refuses retained epoch +note rmcfg cli dev sub vas tsg ctx -> void configures handles +note rmcfgch chan chid tree pid -> void configures channel ID, tree mode, process ID +note rmcfgmem gpa gn upa ipa rpa -> void configures memory descriptors for pachan +note rmstart budget -> long initiates allocation sequence (Root or TSG) +note rmstep -> long steps state machine on bpoll (0 wait, 1 ok, 2 event, <0 err) +note rmsched budget -> long initiates channel group schedule enable +note rmdis budget -> long initiates channel group schedule disable +note rmdrain c budget -> long bounded semaphore progress ONLY, not engine/cache idle +note rmfree budget -> long object RPC teardown ONLY, never frees published backing +note +note Typed mapped effect adapter: +note rmbind c gen -> long binds live mapped slot/epoch; replay state9 is NOT admission +note rmpub gen -> long publishes DMA window once channel is active +note rmlose gen -> long quarantines channel buffers and window on timeout/error +note rmsub c pb off n -> long active bound submission with exact trailing release marker +note The pinned hosted effects are not an Omega kernel, DMA/coherency qualification, or production gate. +note +note Status codes: 0 RMOK, -1 RMEINVAL, -2 RMERANGE, -3 RMESTATE, -4 RMENOMEM, -5 RMEBIND, +note -6 RMECAP, -10 RMEGEN, -11 RMETIME, -12 RMEFAIL, -13 RMECORR, -14 RMEQUAR +const RMOK long 0 +const RMEINVAL long -1 +const RMERANGE long -2 +const RMESTATE long -3 +const RMENOMEM long -4 +const RMEBIND long -5 +const RMECAP long -6 +const RMEGEN long -10 +const RMETIME long -11 +const RMEFAIL long -12 +const RMECORR long -13 +const RMEQUAR long -14 +note State machine states +const RMSIDLE ulong 0 +const RMSAROOT ulong 1 +const RMSADEV ulong 2 +const RMSASUB ulong 3 +const RMSAVAS ulong 4 +const RMSATSG ulong 5 +const RMSACTX ulong 6 +const RMSACHAN ulong 7 +const RMSREADY ulong 8 +const RMSSCHED ulong 9 +const RMSACTV ulong 10 +const RMSDIS ulong 11 +const RMSDRAIN ulong 12 +const RMSDRND ulong 13 +const RMSFCHAN ulong 14 +const RMSFCTX ulong 15 +const RMSFTSG ulong 16 +const RMSFVAS ulong 17 +const RMSFSUB ulong 18 +const RMSFDEV ulong 19 +const RMSFROOT ulong 20 +const RMSDONE ulong 21 +const RMSTOUT ulong 22 +const RMSERR ulong 23 +const RMSQUAR ulong 24 +global rmst ulong 1 +global rmrc long 1 +global rmbudget ulong 1 +global rmepoch ulong 1 +global rmtree ulong 1 +global rmchid ulong 1 +global rmhcli ulong 1 +global rmhdev ulong 1 +global rmhsub ulong 1 +global rmhvas ulong 1 +global rmhtsg ulong 1 +global rmhctx ulong 1 +global rmhchan ulong 1 +global rmgpa ulong 1 +global rmgn ulong 1 +global rmupa ulong 1 +global rmipa ulong 1 +global rmrpa ulong 1 +global rmpid ulong 1 +global rmslot ulong 1 +fn rminit to long +s = get rmst 0 +if and ne s RMSIDLE ne s RMSDONE +ret RMESTATE +end +if ne get rmepoch 0 0 +ret RMESTATE +end +put rmst 0 RMSIDLE +put rmrc 0 RMOK +put rmbudget 0 0 +put rmepoch 0 0 +put rmtree 0 0 +put rmchid 0 0 +put rmhcli 0 0 +put rmhdev 0 0 +put rmhsub 0 0 +put rmhvas 0 0 +put rmhtsg 0 0 +put rmhctx 0 0 +put rmhchan 0 0 +put rmgpa 0 0 +put rmgn 0 0 +put rmupa 0 0 +put rmipa 0 0 +put rmrpa 0 0 +put rmpid 0 0 +put rmslot 0 GMNONE +ret RMOK +end +fn rmcfg cli ulong dev ulong sdev ulong vas ulong tsg ulong ctx ulong to void +if ne get rmst 0 RMSIDLE +put rmrc 0 RMESTATE +ret +end +put rmhcli 0 cli +put rmhdev 0 dev +put rmhsub 0 sdev +put rmhvas 0 vas +put rmhtsg 0 tsg +put rmhctx 0 ctx +end +fn rmcfgch chan ulong chid ulong tree ulong pid ulong to void +if ne get rmst 0 RMSIDLE +put rmrc 0 RMESTATE +ret +end +put rmhchan 0 chan +put rmchid 0 chid +put rmtree 0 tree +put rmpid 0 pid +end +fn rmcfgmem gpa ulong gn ulong upa ulong ipa ulong rpa ulong to void +if ne get rmst 0 RMSIDLE +put rmrc 0 RMESTATE +ret +end +put rmgpa 0 gpa +put rmgn 0 gn +put rmupa 0 upa +put rmipa 0 ipa +put rmrpa 0 rpa +end +fn rmfillin to void +for i ulong 48 +put pain i 0 +end +put pain 0 0 +put pain 1 get rmgpa 0 +put pain 2 get rmgn 0 +put pain 3 0 +put pain 4 get rmhctx 0 +put pain 5 get rmhvas 0 +put pain 6 0 +put pain 7 get rmupa 0 +put pain 8 PAENGGR +put pain 9 0 +put pain 10 0 +put pain 11 get rmhtsg 0 +put pain 12 0 +put pain 13 0 +put pain 14 0 +put pain 15 get rmchid 0 +put pain 16 get rmipa 0 +put pain 17 4096 +put pain 18 2 +put pain 19 0 +put pain 20 get rmupa 0 +put pain 21 512 +put pain 22 2 +put pain 23 0 +put pain 24 get rmrpa 0 +put pain 25 512 +put pain 26 2 +put pain 27 0 +put pain 36 get rmpid 0 +end +fn rmstart budget ulong to long +if ne get rmst 0 RMSIDLE +ret RMESTATE +end +if ne get bstate 0 9 +ret RMESTATE +end +if eq budget 0 +ret RMEINVAL +end +put rmbudget 0 budget +if eq get rmtree 0 1 +r = paroot get rmhcli 0 get rmpid 0 +if lt r 0 +ret r +end +r = brmalloc get rmhcli 0 0 get rmhcli 0 PACROOT budget +if lt r 0 +ret r +end +put rmst 0 RMSAROOT +ret RMOK +end +r = patsg 0 0 get rmhvas 0 PAENGGR +if lt r 0 +ret r +end +r = brmalloc get rmhcli 0 get rmhdev 0 get rmhtsg 0 PACTSG budget +if lt r 0 +ret r +end +put rmst 0 RMSATSG +ret RMOK +end +fn rmsched budget ulong to long +st = get rmst 0 +if ne st RMSREADY +ret RMESTATE +end +if ne get bstate 0 9 +ret RMESTATE +end +if eq budget 0 +ret RMEINVAL +end +put rmbudget 0 budget +r = pasched 1 0 0 +if lt r 0 +ret r +end +r = brmctrl get rmhcli 0 get rmhtsg 0 PACMSCH budget +if lt r 0 +ret r +end +put rmst 0 RMSSCHED +ret RMOK +end +fn rmdis budget ulong to long +st = get rmst 0 +if and ne st RMSACTV ne st RMSREADY +ret RMESTATE +end +if ne get bstate 0 9 +ret RMESTATE +end +if eq budget 0 +ret RMEINVAL +end +put rmbudget 0 budget +r = pasched 0 0 0 +if lt r 0 +ret r +end +r = brmctrl get rmhcli 0 get rmhtsg 0 PACMSCH budget +if lt r 0 +ret r +end +put rmst 0 RMSDIS +ret RMOK +end +fn rmdrain c ulong budget uint to long +if ge c CMSLOTS +ret RMEINVAL +end +if ne c get rmslot 0 +ret RMEINVAL +end +if ne get rmepoch 0 get mmwgen 0 +ret RMEGEN +end +if ne get rmst 0 RMSDRAIN +ret RMESTATE +end +rc = cmdrain c budget +if ne rc CMOK +put rmrc 0 rc +put rmst 0 RMSTOUT +r = rmlose get rmepoch 0 +ret RMETIME +end +put rmst 0 RMSDRND +ret RMOK +end +fn rmfree budget ulong to long +st = get rmst 0 +if ne st RMSDRND +ret RMESTATE +end +if ne get bstate 0 9 +ret RMESTATE +end +if eq budget 0 +ret RMEINVAL +end +put rmbudget 0 budget +r = brmfree get rmhcli 0 get rmhchan 0 budget +if lt r 0 +ret r +end +put rmst 0 RMSFCHAN +ret RMOK +end +fn rmerr rc long to long +put rmrc 0 rc +put rmst 0 RMSERR +if eq rc RMETIME +put rmst 0 RMSTOUT +end +if ne get rmepoch 0 0 +r = rmlose get rmepoch 0 +end +ret rc +end +fn rmstep to long +s = get rmst 0 +if or eq s RMSIDLE or eq s RMSREADY or eq s RMSACTV or eq s RMSDRND or eq s RMSDONE or eq s RMSTOUT or eq s RMSERR eq s RMSQUAR +ret 0 +end +if eq s RMSDRAIN +ret 0 +end +if eq get bstate 0 11 +ret 2 +end +r = bpoll +if eq r 0 +ret 0 +end +if eq r 2 +ret 2 +end +if lt r 0 +ret rmerr r +end +b = get rmbudget 0 +if eq s RMSAROOT +r = padevice 0 get rmhcli 0 3 2 1099511627776 +if lt r 0 +ret rmerr r +end +r = brmalloc get rmhcli 0 get rmhcli 0 get rmhdev 0 PACDEV b +if lt r 0 +ret rmerr r +end +put rmst 0 RMSADEV +ret 1 +end +if eq s RMSADEV +r = pasubdev 0 +if lt r 0 +ret rmerr r +end +r = brmalloc get rmhcli 0 get rmhdev 0 get rmhsub 0 PACSUB b +if lt r 0 +ret rmerr r +end +put rmst 0 RMSASUB +ret 1 +end +if eq s RMSASUB +r = pavaspace 0 72 1099511627776 8589934592 65536 +if lt r 0 +ret rmerr r +end +r = brmalloc get rmhcli 0 get rmhdev 0 get rmhvas 0 PACVAS b +if lt r 0 +ret rmerr r +end +put rmst 0 RMSAVAS +ret 1 +end +if eq s RMSAVAS +r = patsg 0 0 get rmhvas 0 PAENGGR +if lt r 0 +ret rmerr r +end +r = brmalloc get rmhcli 0 get rmhdev 0 get rmhtsg 0 PACTSG b +if lt r 0 +ret rmerr r +end +put rmst 0 RMSATSG +ret 1 +end +if eq s RMSATSG +r = pactxsh get rmhvas 0 PACTXAS 0 +if lt r 0 +ret rmerr r +end +r = brmalloc get rmhcli 0 get rmhtsg 0 get rmhctx 0 PACCTX b +if lt r 0 +ret rmerr r +end +put rmst 0 RMSACTX +ret 1 +end +if eq s RMSACTX +rmfillin +r = pachan +if lt r 0 +ret rmerr r +end +r = brmalloc get rmhcli 0 get rmhdev 0 get rmhchan 0 PACGPF b +if lt r 0 +ret rmerr r +end +put rmst 0 RMSACHAN +ret 1 +end +if eq s RMSACHAN +put rmst 0 RMSREADY +ret 1 +end +if eq s RMSSCHED +put chopen get rmslot 0 1 +put rmst 0 RMSACTV +ret 1 +end +if eq s RMSDIS +put chopen get rmslot 0 2 +put rmst 0 RMSDRAIN +ret 1 +end +if eq s RMSFCHAN +r = brmfree get rmhcli 0 get rmhctx 0 b +if lt r 0 +ret rmerr r +end +put rmst 0 RMSFCTX +ret 1 +end +if eq s RMSFCTX +r = brmfree get rmhcli 0 get rmhtsg 0 b +if lt r 0 +ret rmerr r +end +put rmst 0 RMSFTSG +ret 1 +end +if eq s RMSFTSG +if eq get rmtree 0 1 +r = brmfree get rmhcli 0 get rmhvas 0 b +if lt r 0 +ret rmerr r +end +put rmst 0 RMSFVAS +ret 1 +end +put rmst 0 RMSDONE +ret 1 +end +if eq s RMSFVAS +r = brmfree get rmhcli 0 get rmhsub 0 b +if lt r 0 +ret rmerr r +end +put rmst 0 RMSFSUB +ret 1 +end +if eq s RMSFSUB +r = brmfree get rmhcli 0 get rmhdev 0 b +if lt r 0 +ret rmerr r +end +put rmst 0 RMSFDEV +ret 1 +end +if eq s RMSFDEV +r = brmfree get rmhcli 0 get rmhcli 0 b +if lt r 0 +ret rmerr r +end +put rmst 0 RMSFROOT +ret 1 +end +if eq s RMSFROOT +put rmst 0 RMSDONE +ret 1 +end +ret 0 +end +fn rmbind c ulong gen ulong to long +if ge c CMSLOTS +ret RMEINVAL +end +if or ne get rmst 0 RMSIDLE ne get rmepoch 0 0 +ret RMESTATE +end +if ne get mmwkind 0 1 +ret RMECAP +end +if or lt get mmwst 0 MMWDMA ge get mmwst 0 MMWQUAR +ret RMESTATE +end +if ne get mmwgen 0 gen +ret RMEGEN +end +if or ne get chopen c 2 ne get chepoch c gen +ret RMEBIND +end +in = get chin c +ud = get chud c +gp = get chgp c +if or or ge in GMMAXB ge ud GMMAXB ge gp GMMAXB +ret RMEINVAL +end +if or or not gmlive in not gmlive ud not gmlive gp +ret RMECAP +end +if or ne get rqdead 0 0 ne get bstate 0 9 +ret RMECAP +end +put rmslot 0 c +put rmepoch 0 gen +note Vendor mem_utils_gm107.c:1232 uses a GPU virtual address, not backing PA. +put rmgpa 0 get gmbva gp +put rmgn 0 ulong get chent c +put rmupa 0 get gmbpa ud +put rmipa 0 get gmbpa in +put rmrpa 0 get gmbpa in +put rmchid 0 ulong get chchid c +ret RMOK +end +fn rmpub gen ulong to long +if ne gen get rmepoch 0 +ret RMEGEN +end +if ne get rmst 0 RMSACTV +ret RMESTATE +end +ret mmwpublish gen +end +fn rmlose gen ulong to long +if ne gen get rmepoch 0 +ret RMEGEN +end +c = get rmslot 0 +if ne c GMNONE +in = get chin c +ud = get chud c +gp = get chgp c +if and lt in GMMAXB gmlive in +r = gmquar in +end +if and lt ud GMMAXB gmlive ud +r = gmquar ud +end +if and lt gp GMMAXB gmlive gp +r = gmquar gp +end +end +if eq get mmwst 0 MMWPUB +r = mmwquar gen +end +put rmst 0 RMSQUAR +ret RMOK +end +fn rmsub c ulong pb ulong off uint n uint to long +if ge c CMSLOTS +ret RMEINVAL +end +if ne c get rmslot 0 +ret RMEINVAL +end +if ne get rmst 0 RMSACTV +ret RMESTATE +end +if ne get rmepoch 0 get mmwgen 0 +ret RMEGEN +end +if ne get mmwst 0 MMWPUB +ret RMESTATE +end +if or ne get chopen c 1 ne get chepoch c get mmwgen 0 +ret RMESTATE +end +st = get cmst c +if and and ne st CMSBIND ne st CMSACTV ne st CMSIDLE +ret RMESTATE +end +if ne get cmgen c get mmwgen 0 +ret RMEGEN +end +if not gmlive get cmbuf c +ret RMEBIND +end +if ne get cmbgen c ulong get gmbgen get cmbuf c +ret RMEGEN +end +if not gmlive pb +ret RMEBIND +end +ent = get chent c +p = get cmput c +if or lt ent 2 ge sub p get cmret c sub ent 1 +ret RMEBIND +end +if or ne p get chput c ne get cmret c get chret c +ret RMEBIND +end +r = rmtail c pb off n +if ne r RMOK +ret r +end +r = chsubmit c pb off n +if ne r CHOK +ret r +end +note No fallible checks after publication: the preflight proves cmsub(c,1)'s predicates. +put cmput c add p uint 1 +put cmst c CMSACTV +ret RMOK +end +note Pure submission preflight; immutable backing is read before the ring entry is published. +fn rmtail c ulong pb ulong off uint n uint to long +if or ne and off 3 0 lt n uint CMCWDS +ret RMEINVAL +end +if gt n CHLENMX +ret RMERANGE +end +bytes = mul ulong n 4 +if gt add ulong off bytes get gmbsz pb +ret RMERANGE +end +va = add get gmbva pb ulong off +if ge va CHVALIM +ret RMERANGE +end +r = cmrel 0 get cmva c add get cmput c uint 1 +if ne r long CMCWDS +ret RMEBIND +end +va = add get gmbpa pb ulong off +va = add va bytes +va = sub va mul CMCWDS 4 +for i ulong CMCWDS +if ne uint mmrd32 add va mul i 4 get cmwds i +ret RMEBIND +end +end +ret RMOK +end diff --git a/gsp/arena.om b/gsp/arena.om new file mode 100644 index 0000000..260c81f --- /dev/null +++ b/gsp/arena.om @@ -0,0 +1,427 @@ +note Host-only physical image composer, never DMA/MMIO. Oracle c5bb3a4b gb10_gsp_boot.c:367-553. +note Profile 1 means explicit UNVERIFIED GB10B 580.173.02 layout, NOT detected hardware identity. +note Vendor 20e4e6e kernel_sec2_gb10b.c:507-508: gspFmcSysmemOffset = memdescGetPhysAddr; frtsSysmemSize = pGspImageSize. +note WolframLanguageEvaluator FromDigits[dc3aae21371a60b3,16] -> 15869187694674993331; FromDigits[1410de7e,16] -> 336649854. +note Caller supplies arin bytes and arsrc/arslen spans: ELF,RMsignature,bootloader,FMC,hash,key,FMCsignature. +note No firmware parsing/authentication: signed-byte fixtures test composition only, not signature validity. +note arcfg: profile,dmaBits,heapPA,heapBytes,gpuInstance,regkeys,BLcode,BLdata,BLmanifest,registryBytes. +note arbase is caller supplied IOVA. arcap <=16MiB; arused must be zero on entry. Partial output invalid on failure. +note aroff/arsize: WPR,libos,7 logs,args,shared,radix,BL,signature,FMC,FMCargs,ELFdata. +note arcmd/arstat are queue byte offsets. arcot[0..arclen) is SEC2 packet; artail is EMEM queue tail. +note Raw registry must be canonical PACKED_REGISTRY_TABLE: 1..32 entries, exact contiguous name/value order, +note nonempty terminated names, type1 DWORD length4 or type2/3 nonempty bytes, reserved padding zero. +note Strings preserve opaque bytes like C oracle; their termination is not reinterpreted. Zero bytes omits RPC73. +note Refusals: -1 profile/config, -2 source spans, -3 capacity, -4 registry, -5 DMA, -6 queue. +const ARMAX ulong 16777216 +global arbuf uchar 16777216 +global arin uchar 16777216 +global arreg uchar 65456 +global arsrc ulong 7 +global arslen ulong 7 +global arcfg ulong 10 +global arbase ulong 1 +global arcap ulong 1 +global arused ulong 1 +global aroff ulong 17 +global arsize ulong 17 +global arcmd ulong 1 +global arstat ulong 1 +global arcot uchar 1024 +global arclen ulong 1 +global artail ulong 1 +global arnp ulong 4 +global arlvl ulong 4 +text arnames "LOGINIT|LOGINTR|LOGRM|LOGMNOC|LOGDBG|LOGROOT|LOGKRNL|RMARGS|" +fn arput o ulong v ulong n ulong to void +for i ulong n +put arbuf add o i uchar and shr v mul i 8 255 +end +end +fn arcput o ulong v ulong n ulong to void +for i ulong n +put arcot add o i uchar and shr v mul i 8 255 +end +end +fn arreg32 o ulong to ulong +v = ulong 0 +for i ulong 4 +v = or v shl ulong get arreg add o i mul i 8 +end +ret v +end +fn arregok to bool +n = get arcfg 9 +if eq n 0 +ret true +end +if or lt n 8 gt n 65456 +ret false +end +if ne arreg32 0 n +ret false +end +cnt = arreg32 4 +if or eq cnt 0 gt cnt 32 +ret false +end +pos = add 8 mul cnt 16 +if gt pos n +ret false +end +for i ulong cnt +e = add 8 mul i 16 +if ne arreg32 e pos +ret false +end +if ge pos n +ret false +end +if eq get arreg pos 0 +ret false +end +while lt pos n bound 65456 +if eq get arreg pos 0 +break +end +pos = add pos 1 +end +if ge pos n +ret false +end +pos = add pos 1 +for j ulong 3 +if ne get arreg add e add 5 j 0 +ret false +end +end +t = get arreg add e 4 +sz = arreg32 add e 12 +if eq t 1 +if ne sz 4 +ret false +end +else +if or lt t 2 gt t 3 +ret false +end +if or eq sz 0 ne arreg32 add e 8 pos +ret false +end +if gt sz sub n pos +ret false +end +pos = add pos sz +end +end +ret eq pos n +end +note Dynamic for loops have compiler fuel1000000; page chunks cover the full declared16MiB bound. +fn arzero o ulong n ulong to void +for p ulong div n 4096 +for i ulong 4096 +put arbuf add o i 0 +end +o = add o 4096 +end +for i ulong rem n 4096 +put arbuf add o i 0 +end +end +fn arcspan d ulong s ulong n ulong to void +for i ulong n +v = get arin add s i +put arbuf add d i v +end +end +fn artake k ulong n ulong to bool +sz = and add n 4095 not ulong 4095 +u = get arused 0 +if or lt sz n gt u get arcap 0 +ret false +end +if gt sz sub get arcap 0 u +ret false +end +put aroff k u +put arsize k n +put arused 0 add u sz +arzero u sz +ret true +end +fn arcopy k ulong s ulong to void +n = get arslen s +k = get aroff k +s = get arsrc s +for p ulong div n 4096 +arcspan k s 4096 +k = add k 4096 +s = add s 4096 +end +arcspan k s rem n 4096 +end +fn araddr k ulong to ulong +ret add get arbase 0 get aroff k +end +fn ardma pa ulong n ulong to bool +b = get arcfg 1 +if gt n sub not ulong 0 pa +ret false +end +if eq b 64 +ret true +end +lim = shl ulong 1 b +if ge pa lim +ret false +end +ret le n sub lim pa +end +fn arlogpt k ulong to void +n = div get arsize k 4096 +a = araddr k +k = get aroff k +for j ulong n +o = add k 8 +o = add o mul j 8 +v = add a mul j 4096 +arput o v 8 +end +end +fn arlogs to void +pos = ulong 0 +for i ulong 8 +id = ulong 0 +while ne get arnames pos 124 bound 8 +id = or shl id 8 ulong get arnames pos +pos = add pos 1 +end +pos = add pos 1 +k = add i 2 +if eq i 7 +k = ulong 9 +end +e = add get aroff 1 mul i 32 +arput e id 8 +arput add e 8 araddr k 8 +arput add e 16 get arsize k 8 +arput add e 24 257 2 +end +for i ulong 7 +arlogpt add i 2 +end +end +fn arfixed to void +a = get aroff 9 +arput a araddr 10 8 +arput add a 8 129 4 +arput add a 16 4096 8 +arput add a 24 add ulong 4096 262144 8 +arput add a 44 get arcfg 4 4 +arput add a 48 1 1 +arput add a 72 get arcfg 2 8 +arput add a 80 get arcfg 3 8 +f = get aroff 15 +arput f get arcfg 5 4 +arput add f 8 1 4 +arput add f 12 256 4 +arput add f 16 araddr 0 8 +arput add f 36 1 1 +arput add f 40 2 4 +arput add f 48 araddr 1 8 +w = get aroff 0 +arput w 15869187694674993331 8 +arput add w 8 1 8 +arput add w 16 araddr 11 8 +arput add w 24 get arslen 0 8 +arput add w 32 araddr 12 8 +arput add w 40 get arslen 2 8 +arput add w 48 get arcfg 6 8 +arput add w 56 get arcfg 7 8 +arput add w 64 get arcfg 8 8 +arput add w 72 araddr 13 8 +arput add w 80 get arsize 13 8 +arput add w 128 shl ulong 133 20 8 +end +fn arradix to bool +put arnp 3 div add get arslen 0 4095 4096 +for j ulong 3 +i = sub 3 j +put arnp sub i 1 add div sub get arnp i 1 512 1 +end +if ne get arnp 0 1 +ret false +end +put arlvl 0 0 +for i ulong 3 +put arlvl add i 1 add get arlvl i mul get arnp i 4096 +end +sz = add get arlvl 3 mul get arnp 3 4096 +if not artake 11 sz +ret false +end +for i ulong 3 +for j ulong get arnp add i 1 +o = add get aroff 11 add get arlvl i mul j 8 +v = add araddr 11 add get arlvl add i 1 mul j 4096 +arput o v 8 +end +end +put aroff 16 add get aroff 11 get arlvl 3 +put arsize 16 get arslen 0 +arcopy 16 0 +ret true +end +fn arcotmk to void +for i ulong 1024 +put arcot i 0 +end +arcput 0 shl ulong 3 30 4 +arcput 4 336649854 4 +arcput 8 1 2 +arcput 10 860 2 +arcput 12 araddr 14 8 +arcput 28 get arslen 3 4 +for i ulong 48 +put arcot add 44 i get arin add get arsrc 4 i +end +for i ulong 384 +put arcot add 92 i get arin add get arsrc 5 i +put arcot add 476 i get arin add get arsrc 6 i +end +arcput 860 araddr 15 8 +put arclen 0 868 +put artail 0 864 +end +fn arpre to bool +rqinit +for i ulong 936 +put rqpay i get siout i +end +if ne rqsend 72 936 936 false 0 +ret false +end +n = get arcfg 9 +if ne n 0 +for i ulong n +put rqpay i get arreg i +end +if ne rqsend 73 n n false 0 +ret false +end +end +for i ulong 262144 +put arbuf add get arcmd 0 i get rqcmd i +end +ret true +end +fn arbuild to long +put arclen 0 0 +put artail 0 0 +if or ne get arcfg 0 1 or eq get arcfg 1 0 gt get arcfg 1 64 +ret -1 +end +if or ne get arused 0 0 gt get arcap 0 ARMAX +ret -1 +end +if ne and get arbase 0 4095 0 +ret -1 +end +if gt get arcap 0 sub not ulong 0 get arbase 0 +ret -1 +end +if or eq get arcfg 2 0 eq get arcfg 3 0 +ret -1 +end +if ne and get arcfg 2 4095 0 +ret -1 +end +if ne and get arcfg 3 4095 0 +ret -1 +end +if or gt get arcfg 4 4294967295 gt get arcfg 5 4294967295 +ret -1 +end +if or ne get arcfg 6 45056 or ne get arcfg 7 2560 ne get arcfg 8 0 +ret -1 +end +for i ulong 7 +if or eq get arslen i 0 gt get arsrc i ARMAX +ret -2 +end +if gt get arslen i sub ARMAX get arsrc i +ret -2 +end +end +if or ne get arslen 2 196608 ne get arslen 4 48 +ret -2 +end +if or ne get arslen 5 384 ne get arslen 6 384 +ret -2 +end +if not arregok +ret -4 +end +if not ardma get arcfg 2 get arcfg 3 +ret -5 +end +for i ulong 17 +put aroff i 0 +put arsize i 0 +end +if not artake 0 4096 +ret -3 +end +put arsize 0 256 +if not artake 1 4096 +ret -3 +end +for i ulong 7 +sz = ulong 65536 +if eq i 5 +sz = ulong 4096 +end +if not artake add i 2 sz +ret -3 +end +end +if not artake 9 4096 +ret -3 +end +if not artake 10 mul ulong 129 4096 +ret -3 +end +put arcmd 0 add get aroff 10 4096 +put arstat 0 add get arcmd 0 262144 +for i ulong 129 +arput add get aroff 10 mul i 8 add araddr 10 mul i 4096 8 +end +if not arradix +ret -3 +end +if not artake 12 get arslen 2 +ret -3 +end +arcopy 12 2 +if not artake 13 and add get arslen 1 255 not ulong 255 +ret -3 +end +arcopy 13 1 +if not artake 14 get arslen 3 +ret -3 +end +arcopy 14 3 +if not artake 15 4096 +ret -3 +end +put arsize 15 88 +if not ardma get arbase 0 get arused 0 +ret -5 +end +arlogs +arfixed +if not arpre +ret -6 +end +arcotmk +ret 0 +end diff --git a/gsp/boot.om b/gsp/boot.om new file mode 100644 index 0000000..d440d2a --- /dev/null +++ b/gsp/boot.om @@ -0,0 +1,383 @@ +note gsp/boot.om: boot/event and one-in-flight RM policy. State9 alone NEVER grants hardware readiness. +note Compose exactly one explicit binding: gsp/replay.om or mapped gsp/transport.om; no implicit fallback. +note States 0 closed,1 prepared,2 sysinfo queued,3 registry done,4 waiting INIT_DONE, +note 5 guest handshake needed,6 waiting handshake,7 static request needed,8 waiting static, +note 9 REPLAY_READY,10 waiting RM reply,11 sequencer suspended,12 quarantined. +note NVIDIA580.173.02 kernel_gsp.c:4261-4274 requires handshake BEFORE static info. +note Error -10 order, -11 timeout/outcome unknown, -12 remote failure, -13 reply shape/correlation. +note A poll budget is a caller-fed count, NOT elapsed time. Events never replenish it. +note Reset is replay image disposal only; never a hardware reset or permission to reclaim DMA. +global bstate ulong 1 +global bprev ulong 1 +global bgen ulong 1 +global btoken ulong 1 +global bbudget ulong 1 +global bstaticn ulong 1 +global bfunc ulong 1 +global bseq ulong 1 +global bplen ulong 1 +global bhead ulong 4 +global bresult ulong 1 +global bsevent uchar 65536 +global bselen ulong 1 +fn bfail code long to long +put bstate 0 12 +put rqdead 0 1 +blost +ret code +end +fn breset to long +if not bcanrst +ret -10 +end +if eq get bgen 0 RQU32 +ret -10 +end +rqinit +put bgen 0 add get bgen 0 1 +put bstate 0 1 +put bbudget 0 0 +put bselen 0 0 +ret 0 +end +fn bsys to long +if ne get bstate 0 1 +ret -10 +end +for i ulong 936 +put rqpay i get siout i +end +r = bemit 72 936 936 false +if ne r 0 +ret r +end +put bstate 0 2 +ret 0 +end +note Registry bytes are a caller-supplied PACKED_REGISTRY_TABLE in rqpay, omitted when empty. +fn breg n ulong to long +if ne get bstate 0 2 +ret -10 +end +if ne n 0 +if or lt n 8 gt n 65456 +ret -1 +end +if or ne rqget32 4 0 n eq rqget32 4 4 0 +ret -1 +end +r = bemit 73 n n false +if ne r 0 +ret r +end +end +put bstate 0 3 +ret 0 +end +fn bstart budget ulong staticsz ulong to long +if ne get bstate 0 3 +ret -10 +end +if or eq budget 0 or eq staticsz 0 gt staticsz 65456 +ret -1 +end +put bbudget 0 budget +put bstaticn 0 staticsz +put bstate 0 4 +ret 0 +end +note rqpay holds exact rpc_set_guest_system_info_v03_00 bytes; no fabricated driver/version strings. +note WolframLanguageEvaluator {6*4+3*256}->792 bytes; source generated/g_rpc-structures.h:36-47. +fn bguest to long +if ne get bstate 0 5 +ret -10 +end +for i ulong 3 +n = rqget32 4 add 8 mul i 4 +if gt n 256 +ret -1 +end +end +r = bemit 1 792 792 true +if ne r 0 +ret r +end +put bhead 0 rqget32 4 0 +put bhead 1 rqget32 4 4 +put bfunc 0 1 +put bseq 0 ulong get rqsent 0 +put bstate 0 6 +ret 0 +end +fn bstatic to long +if ne get bstate 0 7 +ret -10 +end +n = get bstaticn 0 +rqclear n +r = bemit 65 n n true +if ne r 0 +ret r +end +put bfunc 0 65 +put bseq 0 ulong get rqsent 0 +put bstate 0 8 +ret 0 +end +note Bind completion to exact replay generation and received element sequence. No RPC acknowledgement exists. +fn bseqdone gen ulong token ulong ok bool to long +if ne get bstate 0 11 +ret -10 +end +if ne gen get bgen 0 +ret -10 +end +if ne token get btoken 0 +ret -10 +end +if not ok +ret bfail -12 +end +put bstate 0 get bprev 0 +ret 0 +end +fn bcorrel to bool +ret and eq get rqfun 0 get bfunc 0 eq get rqreply 0 get bseq 0 +end +fn brmreply to long +f = get bfunc 0 +n = get rqlen 0 +p = get bplen 0 +if eq f 103 +if or ne n 32 ne rqget32 3 100 p +ret bfail -13 +end +if or ne rqget32 3 104 0 ne rqget32 3 108 0 +ret bfail -13 +end +for i ulong 4 +if ne rqget32 3 add 80 mul i 4 get bhead i +ret bfail -13 +end +end +if gt add 112 p get rqslots 0 +ret bfail -13 +end +put bresult 0 rqget32 3 96 +if ne get bresult 0 0 +put bstate 0 9 +ret -12 +end +for i ulong p +put pareply i get rqout add 112 i +end +else +if eq f 76 +if or ne n add 40 p ne rqget32 3 96 p +ret bfail -13 +end +note Flat profile: rmapiRpcFlags and reserved0 must be zero; rmctrl metadata is distinct. +if or ne rqget32 3 100 0 or ne rqget32 3 112 0 ne rqget32 3 116 0 +ret bfail -13 +end +for i ulong 3 +if ne rqget32 3 add 80 mul i 4 get bhead i +ret bfail -13 +end +end +put bresult 0 rqget32 3 92 +if ne get bresult 0 0 +put bstate 0 9 +ret -12 +end +for i ulong p +put pareply i get rqout add 120 i +end +else +if or ne f 10 ne n 16 +ret bfail -13 +end +if or ne rqget32 3 80 get bhead 0 ne rqget32 3 88 get bhead 1 +ret bfail -13 +end +if ne rqget32 3 84 0 +ret bfail -13 +end +put bresult 0 rqget32 3 92 +end +end +put bstate 0 9 +if ne get bresult 0 0 +ret -12 +end +ret 1 +end +fn bpoll to long +s = get bstate 0 +if or eq s 12 ne get rqdead 0 0 +ret -6 +end +if not or or eq s 4 eq s 6 or eq s 8 eq s 10 +ret -10 +end +if eq get bbudget 0 0 +ret bfail -11 +end +put bbudget 0 sub get bbudget 0 1 +r = bpull +if lt r 0 +ret bfail r +end +if eq r 0 +ret 0 +end +if eq get rqfun 0 4098 +n = get rqlen 0 +if lt n 40 +ret bfail -13 +end +words = rqget32 3 80 +idx = rqget32 3 84 +if or or eq words 0 ge idx words gt words div sub n 40 4 +ret bfail -13 +end +for i ulong get rqslots 0 +put bsevent i get rqout i +end +put bselen 0 get rqslots 0 +put btoken 0 rqget32 3 36 +put bprev 0 s +put bstate 0 11 +ret 2 +end +if eq s 4 +if or ne get rqfun 0 4097 ne get rqreply 0 0 +ret bfail -13 +end +if ne get rqres 0 0 +ret bfail -12 +end +put bstate 0 5 +ret 1 +end +if not bcorrel +ret bfail -13 +end +if eq get rqres 0 RQU32 +ret bfail -13 +end +if ne get rqres 0 0 +if eq s 10 +put bresult 0 get rqres 0 +put bstate 0 9 +ret -12 +end +ret bfail -12 +end +if eq s 6 +note Private result is an NV_STATUS, zero succeeds. Version renegotiation is refused, not silently retried. +if ne get rqpriv 0 0 +put bresult 0 get rqpriv 0 +ret bfail -12 +end +if ne get rqlen 0 792 +ret bfail -13 +end +if or ne rqget32 3 80 get bhead 0 ne rqget32 3 84 get bhead 1 +ret bfail -13 +end +put bstate 0 7 +ret 1 +end +if eq s 8 +if ne get rqlen 0 get bstaticn 0 +ret bfail -13 +end +put bstate 0 9 +ret 1 +end +ret brmreply +end +fn brmwait f ulong n ulong budget ulong to void +note Pending sentinel prevents the previous operation's status being exposed as this one's result. +put bresult 0 RQU32 +put bfunc 0 f +put bseq 0 ulong get rqsent 0 +put bplen 0 n +put bbudget 0 budget +put bstate 0 10 +end +note pabuf/palen produced by existing allocation/channel codecs, never duplicated. +fn brmalloc cli ulong parent ulong obj ulong cls ulong budget ulong to long +if ne get bstate 0 9 +ret -10 +end +n = get palen 0 +if or not paf4 cli parent obj cls or gt n 3984 eq budget 0 +ret -1 +end +rqclear add 32 n +rqput32 4 0 cli +rqput32 4 4 parent +rqput32 4 8 obj +rqput32 4 12 cls +rqput32 4 20 n +for i ulong n +put rqpay add 32 i get pabuf i +end +r = bemit 103 32 add 32 n true +if ne r 0 +ret r +end +put bhead 0 cli +put bhead 1 parent +put bhead 2 obj +put bhead 3 cls +brmwait 103 n budget +ret 0 +end +fn brmctrl cli ulong obj ulong cmd ulong budget ulong to long +if ne get bstate 0 9 +ret -10 +end +n = get palen 0 +if or not paf4 cli obj cmd 0 or gt n 4096 eq budget 0 +ret -1 +end +rqclear add 40 n +rqput32 4 0 cli +rqput32 4 4 obj +rqput32 4 8 cmd +rqput32 4 16 n +for i ulong n +put rqpay add 40 i get pabuf i +end +r = bemit 76 add 40 n add 40 n true +if ne r 0 +ret r +end +put bhead 0 cli +put bhead 1 obj +put bhead 2 cmd +brmwait 76 n budget +ret 0 +end +fn brmfree cli ulong obj ulong budget ulong to long +if ne get bstate 0 9 +ret -10 +end +if or not paf4 cli obj 0 0 eq budget 0 +ret -1 +end +rqclear 16 +rqput32 4 0 cli +rqput32 4 8 obj +r = bemit 10 16 16 true +if ne r 0 +ret r +end +put bhead 0 cli +put bhead 1 obj +brmwait 10 0 budget +ret 0 +end diff --git a/gsp/connect.om b/gsp/connect.om new file mode 100644 index 0000000..9a193db --- /dev/null +++ b/gsp/connect.om @@ -0,0 +1,17 @@ +note gsp/connect.om: composition seam, not a hardware launcher. +note Compose rpc/sysinfo/params/boot/arena before this unit. Firmware bytes and IOVAs are caller inputs. +note arboot constructs the arena and preboot command frames once, leaving rq counters/images attached. +note Replay queues remain host copies; later receive frames must be caller-supplied. No DMA ownership, +note queue publication, BAR notification or sequencer execution is inferred from successful encoding. +fn arboot budget ulong staticsz ulong to long +r = breset +if ne r 0 +ret r +end +r = arbuild +if ne r 0 +ret bfail r +end +put bstate 0 3 +ret bstart budget staticsz +end diff --git a/gsp/dispatch.om b/gsp/dispatch.om new file mode 100644 index 0000000..5ed9d9d --- /dev/null +++ b/gsp/dispatch.om @@ -0,0 +1,203 @@ +note gsp/dispatch.om: connects validated GSP_RUN_CPU_SEQUENCER (0x1002) event in bstate 11 +note to sqrun (gsp/seq.om) and bseqdone (gsp/boot.om). +note Sources: +note open-gpu-kernel-modules-580.173.02: +note src/nvidia/src/kernel/gpu/gsp/kernel_gsp.c:432-443 (_kgspRpcRunCpuSequencer) +note src/nvidia/src/kernel/gpu/gsp/kernel_gsp.c:5297-5432 (kgspExecuteSequencerBuffer_IMPL) +note src/nvidia/src/kernel/gpu/gsp/arch/ampere/kernel_gsp_ga102.c:136-200 (kgspExecuteSequencerCommand_GA102) +note src/nvidia/arch/nvalloc/common/inc/rmgspseq.h:78-101, 203-219 +note src/nvidia/generated/g_rpc-structures.h:1535-1544 (rpc_run_cpu_sequencer_v17_00) +note Reference: +note omega-driver-reference native/kernel/gpu/gsp_seq.{h,c} +note Contracts: +note - Host-model opcode/payload/core permission checks finish before simulated effects. +note - These checks do not validate device register alignment, actual BAR span or permissions. +note - Every non-simulator mode refuses the entire dispatch (SQENOC) after token checks, +note before unpack/effects, until a typed MMIO lease/span and typed core binding exist. +note - Host flags cannot authorize hardware; unsupported actions never simulate success. +note - Stale token or generation returns DSPEORD (-10) without quarantine and without side effects. +note - Execution or prevalidation failures invoke bseqdone gen tok false, entering quarantine (state 12). +note - Successful execution writes back updated regSaveArea to bsevent and invokes bseqdone gen tok true. +const DSPOK long 0 +const DSPEORD long -10 +const DSPEPKT long -13 +const DSPMRST ulong 1 +const DSPMSTR ulong 2 +const DSPMHLT ulong 4 +const DSPMRSM ulong 8 +const DSPMALL ulong 15 +global dspperm ulong 1 +global dspops ulong 1 +global dspcore ulong 1 +global dspstat long 1 +global dspwb uchar 64 +global dspwl ulong 1 +text dspwt "empty buffer|cmdIndex not inside the buffer|unknown opcode|opcode overruns cmdIndex|poll timed out|save index out of range|core opcode with no core callback|core opcode failed|nwords over 16384|delay sleep failed|poll budget over 999998|stale token or invalid state|remote error quarantined|packet shape truncated|" +fn dspu32 o ulong to ulong +v = ulong 0 +for i ulong 4 +v = or v shl ulong get bsevent add o i mul i 8 +end +ret v +end +fn dspp32 o ulong v ulong to void +for i ulong 4 +put bsevent add o i uchar and shr v mul i 8 255 +end +end +fn dspunpk nw ulong to void +for i ulong nw +put sqbuf i uint dspu32 add 120 mul i 4 +end +end +note Host model flags (dspperm/sqcore) authorize host simulation only. +note Whole hardware dispatch requires typed MMIO lease/span and engine-specific core capabilities. +note dspseq refuses non-simulator modes before unpack; these permission bits are host-model only. +fn dspcperm op ulong to bool +if eq get sqcore 0 0 +ret false +end +if or lt op SQCRST gt op SQCRES +ret false +end +shf = sub op SQCRST +bit = shl ulong 1 shf +ret ne and get dspperm 0 bit 0 +end +note Caller dspseq already refused empty, over-capacity and out-of-range cmdIndex before dspunpk; +note sqrun refuses an over-limit poll budget before its first effect. +fn dspprev nw ulong ci ulong to long +put dspops 0 0 +put dspcore 0 0 +i = ulong 0 +while lt i ci bound 999999 +op = sqw i +i = add i 1 +n = sqpay op +if eq n M32 +ret SQEOP +end +if gt add i n ci +ret SQEOVR +end +if eq op SQSTO +k = sqw add i 1 +if ge k SQSAVE +ret SQESAVE +end +end +if and ge op SQCRST le op SQCRES +shf = sub op SQCRST +bit = shl ulong 1 shf +put dspops 0 or get dspops 0 bit +put dspcore 0 add get dspcore 0 1 +if not dspcperm op +ret SQENOC +end +end +i = add i n +end +ret 0 +end +fn dspseq gen ulong tok ulong to long +if ne get bstate 0 11 +ret DSPEORD +end +if ne gen get bgen 0 +ret DSPEORD +end +if ne tok get btoken 0 +ret DSPEORD +end +if ne get gspmode 0 0 +z = bseqdone gen tok false +put dspstat 0 SQENOC +ret SQENOC +end +nw = dspu32 80 +ci = dspu32 84 +if lt get bselen 0 add 120 mul nw 4 +z = bseqdone gen tok false +put dspstat 0 DSPEPKT +ret DSPEPKT +end +if eq nw 0 +z = bseqdone gen tok false +put dspstat 0 SQEEMP +ret SQEEMP +end +if gt nw SQMAX +z = bseqdone gen tok false +put dspstat 0 SQECAP +ret SQECAP +end +if ge ci nw +z = bseqdone gen tok false +put dspstat 0 SQEIDX +ret SQEIDX +end +dspunpk nw +r = dspprev nw ci +if ne r 0 +z = bseqdone gen tok false +put dspstat 0 r +ret r +end +for k ulong SQSAVE +put sqsave k dspu32 add 88 mul k 4 +end +r = sqrun nw ci +if ne r 0 +z = bseqdone gen tok false +put dspstat 0 r +ret r +end +for k ulong SQSAVE +dspp32 add 88 mul k 4 get sqsave k +end +d = bseqdone gen tok true +put dspstat 0 d +ret d +end +fn dspauto to long +ret dspseq get bgen 0 get btoken 0 +end +fn dspinit to void +put dspstat 0 0 +put dspops 0 0 +put dspcore 0 0 +put dspperm 0 0 +end +fn dspperms m ulong to void +put dspperm 0 m +end +fn dspwhy e long to void +put dspwl 0 0 +if ge e 0 +ret +end +k = ulong sub 0 add e 1 +if eq e DSPEORD +k = 11 +end +if eq e -12 +k = 12 +end +if eq e DSPEPKT +k = 13 +end +w = ulong 0 +o = ulong 0 +for j ulong len dspwt +c = get dspwt j +if eq c 124 +w = add w 1 +else +if eq w k +put dspwb o c +o = add o 1 +end +end +end +put dspwl 0 o +end diff --git a/gsp/notify.om b/gsp/notify.om new file mode 100644 index 0000000..2710b28 --- /dev/null +++ b/gsp/notify.om @@ -0,0 +1,6 @@ +note Linux-process mapped MMIO access, not a kernel writel binding or permission to activate hardware. +note NVIDIA580.173.02 kernel_gsp.c:411-425 -> kgspSetCmdQueueHead_TU102:343-355. +note PGSP_QUEUE_HEAD(0) is written with zero; checked mapset uses one32-bit store, DSB SY both sides. +fn qtbell h long to long +ret mapset h GPNOTIF 4 0 +end diff --git a/gsp/owned.om b/gsp/owned.om new file mode 100644 index 0000000..df04556 --- /dev/null +++ b/gsp/owned.om @@ -0,0 +1,45 @@ +note Checked CPU staging and uncertainty connection only; NOT a hardware publisher or RPC endpoint. +note Compose after chan/dma+gmmu and gsp/arena+boot. No device opens, barriers or doorbells here. +note Real publication still requires reviewed coherency/release/acquire and an authorized endpoint. +global arsepoch ulong 1 +global arsboot ulong 1 +fn arstage gen ulong to long +if not mmwepoch gen +ret MMEGEN +end +if ne get bstate 0 4 +ret MMESTATE +end +if not or eq get mmwst 0 MMWOWN eq get mmwst 0 MMWDMA +ret MMESTATE +end +if ne get arbase 0 get mmwb 0 +ret MMEINVAL +end +if or eq get arused 0 0 gt get arused 0 get mmws 0 +ret MMEINVAL +end +r = mapwrite get mmwh 0 0 arbuf 0 get arused 0 +if ne r long get arused 0 +ret MMEIO +end +put arsepoch 0 gen +put arsboot 0 get bgen 0 +ret MMOK +end +note Call only for uncertain completion after an actual publication; never reclaim automatically. +fn arlose gen ulong to long +if ne gen get arsepoch 0 +ret MMEGEN +end +if ne get bgen 0 get arsboot 0 +ret MMEGEN +end +if ne get bstate 0 12 +ret MMESTATE +end +if ne get mmwst 0 MMWPUB +ret MMESTATE +end +ret mmwquar gen +end diff --git a/gsp/profile.om b/gsp/profile.om new file mode 100644 index 0000000..4080a2c --- /dev/null +++ b/gsp/profile.om @@ -0,0 +1,17 @@ +note Source classifier ONLY, never measured identity, device authority, or firmware authentication. +note NVIDIA580.173.02 nv_ref.h:149-182 BOOT42 architecture29:24, implementation23:20. +note nv_arch.h:51,111 GB1XX/GB10B; g_kern_fsp_nvoc.c:227-236 FSP missing for GB10B. +note g_kernel_sec2_nvoc.c:446-481 GB10B boots GSP-FMC via SEC2 with COT version1. +note nv-firmware-chip-family-select.h:58-62 selects gb10y, not gb10x, for this source profile. +note WolframLanguageEvaluator {FromDigits["1A",16],FromDigits["0B",16],FromDigits["A00",16],FromDigits["110C00",16],BitOr[BitShiftLeft[FromDigits["1A",16],24],BitShiftLeft[FromDigits["0B",16],20]]} -> {26,11,2560,1117184,447741952}. +const GPBOOT ulong 2560 +const GPNOTIF ulong 1117184 +fn gpchip boot42 uint to long +if ne and shr ulong boot42 24 63 26 +ret -95 +end +if ne and shr ulong boot42 20 15 11 +ret -95 +end +ret 1 +end diff --git a/gsp/replay.om b/gsp/replay.om new file mode 100644 index 0000000..87fcd02 --- /dev/null +++ b/gsp/replay.om @@ -0,0 +1,14 @@ +note Explicit HOST REPLAY binding for boot.om. Never link this as a hardware transport fallback. +fn bcanrst to bool +ret true +end +fn blost to void +note Host arrays own no published DMA; boot.om itself latches its quarantine state. +ret +end +fn bemit f ulong n ulong p ulong sync bool to long +ret rqsend f n p sync +end +fn bpull to long +ret rqrecv +end diff --git a/gsp/rpc.om b/gsp/rpc.om new file mode 100644 index 0000000..7bb6d47 --- /dev/null +++ b/gsp/rpc.om @@ -0,0 +1,336 @@ +note gsp/rpc.om: bounded non-CC GSP-RM queue codec, host replay ONLY. No DMA/MMIO or hardware readiness. +note NVIDIA 580.173.02 message_queue_cpu.c:434-585,615-735; msgq.c SWAP_RX; rpc.c:11194-11228. +note Reference aienux c5bb3a4b native/kernel/dev/gb10_gsp_boot.c:152-361. +note rqcmd/rqstat are caller-owned replay images, NOT device mappings. No implicit hardware backend. +note rqsend uses rqpay; logical n may exclude appended RM_ALLOC params, physical p includes them. +note rqrecv captures full declared slots, validates actual alignment padding (not manufactured zeros). +note Status: 0 empty/success; 1 received; -1 shape/length; -2 full; -3 checksum; -4 sequence; +note -5 unsupported version/signature; -6 quarantined. Refusals never advance pointers or counters. +const RQQSZ ulong 262144 +const RQSLOT ulong 4096 +const RQCOUNT ulong 63 +const RQMAX ulong 65536 +const RQVER ulong 50331648 +const RQSIG ulong 1129337430 +const RQU32 ulong 4294967295 +global rqcmd uchar 262144 +global rqstat uchar 262144 +global rqpay uchar 65536 +global rqout uchar 65536 +global rqtmp uchar 65536 +note counters: tx element, rx element, synchronous RPC; increment only after publication/acceptance. +global rqtx uint 1 +global rqrx uint 1 +global rqseq uint 1 +global rqsent uint 1 +global rqlen ulong 1 +global rqslots ulong 1 +global rqfun ulong 1 +global rqres ulong 1 +global rqpriv ulong 1 +global rqreply ulong 1 +global rqdead uchar 1 +global rqlink uchar 1 +note Preparation is private; single-use token commits sequences only after the chosen publisher succeeds. +global rqptok ulong 1 +global rqppend uchar 1 +global rqpwr ulong 1 +global rqpcnt ulong 1 +global rqpseq uint 1 +global rqptx uint 1 +global rqpsync uchar 1 +note Array selectors avoid passing globals (not supported by pinned compiler): 0 cmd,1 stat,2 tmp,3 out,4 pay. +fn rqbyte a ulong o ulong to uchar +if eq a 0 +ret get rqcmd o +end +if eq a 1 +ret get rqstat o +end +if eq a 2 +ret get rqtmp o +end +if eq a 3 +ret get rqout o +end +ret get rqpay o +end +fn rqput a ulong o ulong v uchar to void +if eq a 0 +put rqcmd o v +ret +end +if eq a 1 +put rqstat o v +ret +end +if eq a 2 +put rqtmp o v +ret +end +if eq a 3 +put rqout o v +ret +end +put rqpay o v +end +fn rqget32 a ulong o ulong to ulong +v = ulong 0 +for i ulong 4 +v = or v shl ulong rqbyte a add o i mul i 8 +end +ret v +end +fn rqput32 a ulong o ulong v ulong to void +for i ulong 4 +rqput a add o i uchar and shr v mul i 8 255 +end +end +fn rqsum a ulong n ulong to ulong +v = ulong 0 +for i ulong n +v = xor v shl ulong rqbyte a i mul rem i 4 8 +end +ret v +end +fn rqshape a ulong to bool +if or ne rqget32 a 0 0 ne rqget32 a 4 RQQSZ +ret false +end +if or ne rqget32 a 8 RQSLOT ne rqget32 a 12 RQCOUNT +ret false +end +if or ne rqget32 a 20 1 ne rqget32 a 24 32 +ret false +end +ret eq rqget32 a 28 RQSLOT +end +fn rqinit to void +for i ulong RQQSZ +put rqcmd i 0 +put rqstat i 0 +end +rqput32 0 4 RQQSZ +rqput32 0 8 RQSLOT +rqput32 0 12 RQCOUNT +rqput32 0 20 1 +rqput32 0 24 32 +rqput32 0 28 RQSLOT +put rqtx 0 0 +put rqrx 0 0 +put rqseq 0 0 +put rqsent 0 0 +put rqlen 0 0 +put rqslots 0 0 +put rqdead 0 0 +put rqlink 0 0 +put rqppend 0 0 +end +note Replay peer queue creation is explicit input, never inferred from a boot command. +fn rqpeer to void +for i ulong 32 +put rqstat i get rqcmd i +end +rqput32 1 16 0 +put rqlink 0 1 +end +fn rqclear n ulong to void +if gt n RQMAX +trap 3 +end +for i ulong n +put rqpay i 0 +end +end +fn rqframe f ulong n ulong p ulong seq uint e ulong to void +for i ulong mul e RQSLOT +put rqtmp i 0 +end +rqput32 2 36 ulong get rqtx 0 +rqput32 2 40 e +rqput32 2 48 RQVER +rqput32 2 52 RQSIG +rqput32 2 56 add 32 n +rqput32 2 60 f +rqput32 2 64 RQU32 +rqput32 2 68 RQU32 +rqput32 2 72 ulong seq +for i ulong p +put rqtmp add 80 i get rqpay i +end +note All padding was zeroed above; supported RM_ALLOC fixed32 ends exactly on alignment. +rqput32 2 32 rqsum 2 mul div add add 80 n 7 8 8 +end +fn rqcopy wr ulong e ulong to void +for i ulong mul e RQSLOT +o = rem add wr div i RQSLOT RQCOUNT +o = add RQSLOT mul o RQSLOT +o = add o rem i RQSLOT +put rqcmd o get rqtmp i +end +end +fn rqprep f ulong n ulong p ulong sync bool to long +if ne get rqdead 0 0 +ret -6 +end +if ne get rqppend 0 0 +ret -6 +end +if eq add get rqptok 0 1 0 +ret -6 +end +if or gt f RQU32 or gt n 65456 lt p n +ret -1 +end +note The sole supported unchecked physical tail is vendor RM_ALLOC's aligned fixed32 body. +if and gt p n not and eq f 103 eq n 32 +ret -1 +end +e = div add add 80 n 4095 RQSLOT +if or gt p sub mul e RQSLOT 80 gt p 65456 +ret -1 +end +if not rqshape 0 +ret -1 +end +wr = rqget32 0 16 +rd = rqget32 1 32 +if or ge wr RQCOUNT ge rd RQCOUNT +ret -1 +end +if lt rem sub add rd RQCOUNT add wr 1 RQCOUNT e +ret -2 +end +seq = uint 0 +if sync +seq = get rqseq 0 +end +rqframe f n p seq e +put rqptok 0 add get rqptok 0 1 +put rqppend 0 1 +put rqpwr 0 wr +put rqpcnt 0 e +put rqpseq 0 seq +put rqptx 0 get rqtx 0 +put rqpsync 0 0 +if sync +put rqpsync 0 1 +end +ret 0 +end +fn rqcommit token ulong to long +if or ne get rqppend 0 1 ne token get rqptok 0 +ret -6 +end +if or ne get rqtx 0 get rqptx 0 ne rqget32 0 16 get rqpwr 0 +ret -6 +end +if and ne get rqpsync 0 0 ne get rqseq 0 get rqpseq 0 +ret -6 +end +wr = get rqpwr 0 +e = get rqpcnt 0 +seq = get rqpseq 0 +rqput32 0 16 rem add wr e RQCOUNT +put rqsent 0 seq +put rqtx 0 add get rqtx 0 uint 1 +if ne get rqpsync 0 0 +put rqseq 0 add seq uint 1 +end +put rqppend 0 0 +ret 0 +end +fn rqsend f ulong n ulong p ulong sync bool to long +r = rqprep f n p sync +if ne r 0 +ret r +end +rqcopy get rqpwr 0 get rqpcnt 0 +ret rqcommit get rqptok 0 +end +fn rqcapt rd ulong e ulong to void +for i ulong mul e RQSLOT +p = rem add rd div i RQSLOT RQCOUNT +p = add RQSLOT mul p RQSLOT +p = add p rem i RQSLOT +put rqtmp i get rqstat p +end +end +fn rqvalid m ulong to long +aligned = mul div add m 7 8 8 +if ne rqsum 2 aligned 0 +ret -3 +end +if ne rqget32 2 36 ulong get rqrx 0 +ret -4 +end +if or ne rqget32 2 48 RQVER ne rqget32 2 52 RQSIG +ret -5 +end +note Strict single-client non-CC profile: no authentication metadata or routing union. +for i ulong 32 +if ne get rqtmp i 0 +ret -5 +end +end +if or ne rqget32 2 44 0 ne rqget32 2 76 0 +ret -5 +end +ret 0 +end +fn rqaccept n ulong e ulong rd ulong to void +for i ulong mul e RQSLOT +put rqout i get rqtmp i +end +put rqlen 0 sub n 32 +put rqslots 0 mul e RQSLOT +put rqfun 0 rqget32 3 60 +put rqres 0 rqget32 3 64 +put rqpriv 0 rqget32 3 68 +put rqreply 0 rqget32 3 72 +rqput32 0 32 rem add rd e RQCOUNT +put rqrx 0 add get rqrx 0 uint 1 +end +fn rqrecv to long +if ne get rqdead 0 0 +ret -6 +end +if not rqshape 0 +ret -1 +end +if not rqshape 1 +if eq get rqlink 0 0 +ret 0 +end +ret -1 +end +put rqlink 0 1 +wr = rqget32 1 16 +rd = rqget32 0 32 +if or ge wr RQCOUNT ge rd RQCOUNT +ret -1 +end +avail = rem sub add wr RQCOUNT rd RQCOUNT +if eq avail 0 +ret 0 +end +o = add RQSLOT mul rd RQSLOT +e = rqget32 1 add o 40 +n = rqget32 1 add o 56 +if or or eq e 0 gt e 16 gt e avail +ret -1 +end +if or lt n 32 gt n 65488 +ret -1 +end +if ne e div add add 48 n 4095 RQSLOT +ret -1 +end +rqcapt rd e +r = rqvalid add 48 n +if ne r 0 +ret r +end +rqaccept n e rd +ret 1 +end diff --git a/gsp/service.om b/gsp/service.om new file mode 100644 index 0000000..abb7d6c --- /dev/null +++ b/gsp/service.om @@ -0,0 +1,50 @@ +note Serialized caller pump. useRM selects protocol owner, not authority or a production capability. +note Caller still supplies exact guest/static inputs, object handles and explicit schedule/drain actions. +note CPU_SEQUENCER is executed through dispatch, never acknowledged by setting success without effects. +note No automatic retry, firmware choice, hardware start, queue reset, mapping close or backing reclaim. +fn drvseq useRM bool to long +d = dspauto +if lt d 0 +if useRM +r = rmlose get rmepoch 0 +end +ret d +end +ret 2 +end +fn drvstep useRM bool to long +if eq get bstate 0 11 +ret drvseq useRM +end +r = long 0 +if useRM +r = rmstep +else +r = bpoll +end +if eq r 2 +ret drvseq useRM +end +ret r +end +note Pure input adapter for existing gspboot. Does NOT call gspboot or authorize its hardware effects. +note appVersion comes from caller-validated firmware metadata, never invented by this arena encoder. +fn drvprep ver uint b0 ulong b1 ulong b2 ulong b3 ulong to long +if not qtcheck +ret -6 +end +if or eq get arclen 0 0 gt get arclen 0 1024 +ret -1 +end +for i ulong get arclen 0 +put gpkt i get arcot i +end +put gin 0 get arclen 0 +put gin 1 araddr 15 +put gin 2 ulong ver +put gin 3 b0 +put gin 4 b1 +put gin 5 b2 +put gin 6 b3 +ret 0 +end diff --git a/gsp/transport.om b/gsp/transport.om new file mode 100644 index 0000000..d8049a9 --- /dev/null +++ b/gsp/transport.om @@ -0,0 +1,274 @@ +note Linux-process checked-mapping mechanism, NOT kernel transport or a hardware admission resolver. +note Link instead of replay.om; no implicit simulator fallback, no device opens or automatic retries. +note Coherent or explicitly cache-maintained queue memory is a mandatory external platform prerequisite. +note Compiler397e6704 mapget/mapset use one aligned access with DSB SY before/after; bulk copies do not. +note Legitimate pointer operations order payload stores before producer publish, acquire before capture, +note and captured loads before consumer acknowledgement. DSB does not establish cache coherency. +note Vendor msgq.c:411-420 SWAP_RX; message_queue_cpu.c:568-578; kernel_gsp.c:411-425. +note Notify chain kgspSetCmdQueueHead_TU102 writes PGSP_QUEUE_HEAD(0)=0, NOT a ring cursor/SEC2 queue. +note Caller owns validated mapping views; process-fatal mapping faults are NOT crash-safe DMA containment. +global qtstate ulong 1 +global qtepoch ulong 1 +global qtboot ulong 1 +global qtcmd ulong 1 +global qtstat ulong 1 +global qtbar long 1 +global qttok ulong 1 +global qtpend uchar 1 +global qtrd ulong 1 +fn qtcheck to bool +if ne get qtstate 0 1 +ret false +end +if not mmwepoch get qtepoch 0 +ret false +end +if ne get mmwst 0 MMWPUB +ret false +end +ret eq get qtboot 0 get bgen 0 +end +fn qtlose to void +if and mmwepoch get qtepoch 0 eq get mmwst 0 MMWPUB +r = mmwquar get qtepoch 0 +end +put qtstate 0 2 +put rqdead 0 1 +put bstate 0 12 +end +note Explicit mechanism attachment; success means bound spans, never qualified/coherent/hardware-ready. +fn qtattach gen ulong bar long barsz ulong boot42 uint to long +if ne get qtstate 0 0 +ret -6 +end +if ne gpchip boot42 1 +ret -95 +end +if or not mmwepoch gen ne get mmwst 0 MMWPUB +ret -6 +end +if or ne gen get arsepoch 0 ne get bgen 0 get arsboot 0 +ret -6 +end +if ne get bstate 0 4 +ret -6 +end +if or lt barsz add GPNOTIF 4 le bar 0 +ret -1 +end +if lt get mmws 0 RQQSZ +ret -1 +end +c = get arcmd 0 +s = get arstat 0 +if gt c sub get mmws 0 RQQSZ +ret -1 +end +if gt s sub get mmws 0 RQQSZ +ret -1 +end +if ne rem c RQSLOT 0 +ret -1 +end +if ne rem s RQSLOT 0 +ret -1 +end +if lt c s +if gt add c RQQSZ s +ret -1 +end +else +if gt add s RQQSZ c +ret -1 +end +end +if not rqshape 0 +ret -1 +end +h = get mmwh 0 +v = mapget h add c 16 4 +if ne v rqget32 0 16 +ret -1 +end +v = mapget h add c 32 4 +if ne v rqget32 0 32 +ret -1 +end +put qtepoch 0 gen +put qtboot 0 get bgen 0 +put qtcmd 0 c +put qtstat 0 s +put qtbar 0 bar +put qtpend 0 0 +put qtstate 0 1 +ret 0 +end +fn qtxcopy wr ulong e ulong to long +h = get mmwh 0 +for i ulong e +slot = rem add wr i RQCOUNT +o = add get qtcmd 0 mul add slot 1 RQSLOT +r = mapwrite h o rqtmp mul i RQSLOT RQSLOT +if ne r long RQSLOT +ret -6 +end +end +ret 0 +end +fn qtpub wr ulong e ulong to long +p = rem add wr e RQCOUNT +ret mapset get mmwh 0 add get qtcmd 0 16 4 p +end +fn qtsend f ulong n ulong p ulong sync bool to long +if not qtcheck +ret -6 +end +if ne get qtpend 0 0 +ret -6 +end +h = get mmwh 0 +rd = mapget h add get qtstat 0 32 4 +if ge rd RQCOUNT +qtlose +ret -1 +end +r = mapread h get qtstat 0 rqstat 0 32 +if ne r 32 +qtlose +ret -6 +end +if and ne get rqlink 0 0 not rqshape 1 +qtlose +ret -1 +end +rqput32 1 32 rd +r = rqprep f n p sync +if ne r 0 +if ne r -2 +qtlose +end +ret r +end +wr = get rqpwr 0 +e = get rqpcnt 0 +token = get rqptok 0 +r = qtxcopy wr e +if ne r 0 +qtlose +ret r +end +note Leading DSB SY of this exact aligned store orders copied slot bytes before pointer publication. +r = qtpub wr e +if ne r 0 +qtlose +ret -6 +end +r = rqcommit token +if ne r 0 +qtlose +ret r +end +note Pointer was published: any later failure is uncertain, never unsent/retryable. +r = qtbell get qtbar 0 +if ne r 0 +qtlose +ret -6 +end +ret 0 +end +note Capture a bounded immutable prefix under one acquired producer cursor. No live reread while validating. +fn qtsnap to long +if not qtcheck +ret -6 +end +if ne get qtpend 0 0 +ret -6 +end +if eq add get qttok 0 1 0 +ret -6 +end +h = get mmwh 0 +s = get qtstat 0 +wr = mapget h add s 16 4 +r = mapread h s rqstat 0 32 +if ne r 32 +qtlose +ret -6 +end +rqput32 1 16 wr +rd = rqget32 0 32 +put qtrd 0 rd +put qttok 0 add get qttok 0 1 +put qtpend 0 1 +if or ge wr RQCOUNT ge rd RQCOUNT +ret 0 +end +avail = rem sub add wr RQCOUNT rd RQCOUNT +if eq avail 0 +ret 0 +end +o = add RQSLOT mul rd RQSLOT +r = mapread h add s o rqstat o RQSLOT +if ne r long RQSLOT +qtlose +ret -6 +end +e = rqget32 1 add o 40 +if or eq e 0 or gt e 16 gt e avail +ret 0 +end +for i ulong sub e 1 +slot = rem add add rd i 1 RQCOUNT +o = mul add slot 1 RQSLOT +r = mapread h add s o rqstat o RQSLOT +if ne r long RQSLOT +qtlose +ret -6 +end +end +ret 0 +end +fn qtaccept token ulong to long +if not qtcheck +ret -6 +end +if or ne get qtpend 0 1 ne token get qttok 0 +ret -6 +end +if ne rqget32 0 32 get qtrd 0 +qtlose +ret -6 +end +put qtpend 0 0 +r = rqrecv +if lt r 0 +qtlose +ret r +end +if eq r 0 +ret 0 +end +note Leading DSB SY is FULL: capture loads complete before the consumer store permits peer slot reuse. +x = mapset get mmwh 0 add get qtcmd 0 32 4 rqget32 0 32 +if ne x 0 +qtlose +ret -6 +end +ret 1 +end +fn bcanrst to bool +ret eq get qtstate 0 0 +end +fn blost to void +qtlose +end +fn bemit f ulong n ulong p ulong sync bool to long +ret qtsend f n p sync +end +fn bpull to long +r = qtsnap +if ne r 0 +ret r +end +ret qtaccept get qttok 0 +end diff --git a/tests/arena_diff.sh b/tests/arena_diff.sh new file mode 100755 index 0000000..c2583a3 --- /dev/null +++ b/tests/arena_diff.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Unprivileged synthetic host gate only. Does not load firmware or touch a device. +set -eu +R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) +OMC=${OMC:-$R/build/omc} +AIENUX=${AIENUX:?set AIENUX to pinned reference checkout} +ARENA_OM=${ARENA_OM:-$R/gsp/arena.om} +actual=$(sha256sum "$OMC"); actual=${actual%% *} +[ "$actual" = bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6 ] || { echo 'arena_diff: INVALID compiler pin'; exit 2; } +[ "$(git -C "$AIENUX" rev-parse HEAD)" = c5bb3a4b9898257658aba0b7178a3c73a0371c27 ] || { echo 'arena_diff: INVALID oracle pin'; exit 2; } +git -C "$AIENUX" diff --quiet HEAD -- native/kernel/dev/gb10_gsp_boot.c native/kernel/dev/gb10_gsp_boot.h || { echo 'arena_diff: INVALID modified oracle'; exit 2; } +t=$(mktemp -d /tmp/arena-parity.XXXXXX) +trap 'rm -rf "$t"' EXIT HUP INT TERM +cc -std=c11 -O1 -Wall -Wextra -I"$AIENUX/native/kernel/dev" "$R/tests/arena_ref.c" "$AIENUX/native/kernel/dev/gb10_gsp_boot.c" -o "$t/ref" +cat "$R/gsp/rpc.om" "$R/gsp/replay.om" "$R/gsp/sysinfo.om" "$R/chan/params.om" "$R/gsp/boot.om" "$ARENA_OM" "$R/gsp/connect.om" "$R/tests/arena_trace.om" > "$t/trace.om" +if ! "$OMC" < "$t/trace.om" > "$t/replay"; then echo 'arena_diff: INVALID compile'; exit 2; fi +chmod +x "$t/replay" +python3 - "$t" <<'PY' +import pathlib, subprocess, sys +p=pathlib.Path(sys.argv[1]) +def run(name, mode): + return subprocess.run([str(p/name)], input=bytes([mode]), stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=60) +for mode in range(5): + ref=run('ref',mode) + if ref.returncode: sys.exit('arena_diff: INVALID oracle positive '+str(mode)) + om=run('replay',mode) + if om.returncode: sys.exit('arena_diff: FAIL replay exit '+str(om.returncode)+' case '+str(mode)) + if om.stdout!=ref.stdout: sys.exit('arena_diff: FAIL exact arena/COT case '+str(mode)) +for mode in range(10,41): + ref=run('ref',mode) + if ref.returncode!=3 or ref.stdout: sys.exit('arena_diff: INVALID oracle negative '+str(mode)) + om=run('replay',mode) + if om.returncode==0: sys.exit('arena_diff: FAIL negative accepted case '+str(mode)) + if om.returncode!=3 or om.stdout: sys.exit('arena_diff: INVALID negative trap/status '+str(om.returncode)+' case '+str(mode)) +print('arena_diff: PASS exact arena bytes, plan, COT, preboot attach/INIT_DONE seam and negative refusals; hardware NOT_RUN') +PY +sha256sum "$t/trace.om" "$t/replay" "$t/ref" diff --git a/tests/arena_ref.c b/tests/arena_ref.c new file mode 100644 index 0000000..09e75a0 --- /dev/null +++ b/tests/arena_ref.c @@ -0,0 +1,79 @@ +/* Test-only oracle. Production composition is Omega; this links the unchanged pinned C builder. + * Synthetic bytes are not authenticated firmware. No device access. */ +#include "gb10_gsp_boot.h" +#include +#include +#include +#define CAP 16777216u +static _Alignas(4096) unsigned char arena[CAP]; +static unsigned char input[CAP], si[936], raw[65456], hdr[512]; +static uint64_t cfg[10], src[7], sz[7]; +static uint32_t r32(const unsigned char *p) { return (uint32_t)p[0]|(uint32_t)p[1]<<8|(uint32_t)p[2]<<16|(uint32_t)p[3]<<24; } +static void w64(unsigned off,uint64_t v) { for(unsigned i=0;i<8;i++) hdr[off+i]=(unsigned char)(v>>(8*i)); } +/* Independent decoding of canonical serialized registry; passed to C's own registry encoder. */ +static int registry(gsp_reg_entry *e, unsigned *count) { + uint64_t n=cfg[9]; *count=0; if(!n) return 1; + if(n<8 || n>sizeof raw || r32(raw)!=n) return 0; + unsigned c=r32(raw+4); if(!c || c>32 || 8u+16u*c>n) return 0; + size_t p=8+16*c; + for(unsigned i=0;i=n || !raw[p] || a[5] || a[6] || a[7]) return 0; + e[i].name=(const char*)raw+p; + const unsigned char *z=memchr(raw+p,0,n-p); if(!z) return 0; + p=(size_t)(z-raw)+1; e[i].type=a[4]; e[i].dword=0; e[i].bytes=NULL; e[i].len=0; + if(a[4]==1) { if(r32(a+12)!=4) return 0; e[i].dword=r32(a+8); } + else { unsigned l=r32(a+12); if((a[4]!=2 && a[4]!=3)||!l||r32(a+8)!=p||l>n-p) return 0; + e[i].bytes=raw+p; e[i].len=l; p+=l; } + } + if(p!=n) return 0; + *count=c; + return 1; +} +int main(void) { + int m=getchar(); if(m==EOF) return 2; + uint64_t base=1048576, cap=CAP, used=0; + uint64_t init[]={1,40,268435456,8192,7,9,45056,2560,0,0}; memcpy(cfg,init,sizeof cfg); + uint64_t sizes[]={4097,257,196608,4103,48,384,384}; memcpy(sz,sizes,sizeof sz); + if(m==2) sz[0]=512u*4096u+1; + size_t pos=0; for(unsigned s=0;s<7;s++) { src[s]=pos; for(uint64_t i=0;i=30) { cfg[9]=26; raw[0]=26;raw[4]=1;raw[8]=24;raw[12]=1;raw[16]=239;raw[17]=190;raw[18]=173;raw[19]=222;raw[20]=4;raw[24]='X'; } + if(m==3 || m==4) { cfg[9]=29;raw[0]=29;raw[12]=m==3?2:3;raw[16]=26;raw[17]=raw[18]=raw[19]=0;raw[20]=3;raw[26]=255;raw[27]=128;raw[28]=0; } + switch(m) { + case 10:cfg[0]=0;break; case 11:base++;break; + case 12:cap=CAP-1;base=UINT64_MAX-4095;break; + case 13:cfg[1]=0;break;case 14:cfg[1]=65;break;case 15:cfg[2]=0;break;case 16:cfg[3]=8193;break; + case 17:cfg[6]=45055;break;case 18:sz[0]=0;break;case 19:src[1]=CAP;break; + case 20:sz[2]=196607;break;case 21:sz[4]=47;break;case 22:cap=4096;break; + case 23:cfg[1]=20;break;case 24:cfg[2]=UINT64_MAX-4095;break;case 25:used=4096;break; + case 26:cfg[8]=1;break;case 27:cfg[4]=UINT64_C(1)<<32;break;case 28:cfg[9]=65457;break; + case 29:sz[6]=383;break;case 30:raw[0]=25;break;case 31:raw[4]=33;break; + case 32:raw[8]=25;break;case 33:raw[24]=0;break;case 34:raw[25]=88;break; + case 35:raw[13]=1;break;case 36:raw[12]=4;break;case 37:raw[20]=3;break; + case 38:raw[12]=2;raw[16]=26;raw[17]=raw[18]=raw[19]=0;raw[20]=1;break; + case 39:cfg[1]=20;cfg[2]=4096;break; + case 40:cfg[2]=4097;break; + default:break; + } + /* Adapter checks contracts absent from pointer-based original API, before forming pointers. */ + if(cfg[0]!=1 || cfg[4]>UINT32_MAX || cfg[5]>UINT32_MAX || cap>CAP) return 3; + for(unsigned i=0;i<7;i++) if(!sz[i] || src[i]>CAP || sz[i]>CAP-src[i]) return 3; + if(sz[4]!=48 || sz[5]!=384 || sz[6]!=384 || cfg[3]>UINT64_MAX-cfg[2]) return 3; + gsp_reg_entry regs[32]; unsigned nr; if(!registry(regs,&nr)) return 3; + gsp_boot_in in={.rm_elf=input+src[0],.rm_elf_size=sz[0],.rm_sig=input+src[1],.rm_sig_size=sz[1], + .bootloader=input+src[2],.bootloader_size=sz[2],.bl_code_off=cfg[6],.bl_data_off=cfg[7],.bl_manifest_off=cfg[8], + .fmc=input+src[3],.fmc_size=sz[3],.fmc_hash=input+src[4],.fmc_pubkey=input+src[5],.fmc_sig=input+src[6], + .sysmem_heap_pa=cfg[2],.sysmem_heap_size=cfg[3],.system_info=si,.regs=regs,.nregs=nr, + .gpu_instance=cfg[4],.fmc_regkeys=cfg[5],.dma_bits=cfg[1]}; + gsp_arena a; gsp_boot_plan p; const char *why; + if(gsp_arena_init(&a,arena,base,cap)) return 3; + a.used=used; + if(gsp_boot_build(&a,&in,&p,&why)) return 3; + gsp_region regions[17]={p.wpr_meta,p.libos_args,p.log[0],p.log[1],p.log[2],p.log[3],p.log[4],p.log[5],p.log[6],p.args_cached,p.rpc_shared,p.radix3,p.bootloader,p.signature,p.fmc,p.fmc_params,{p.elf_data_pa,in.rm_elf_size}}; + w64(0,a.used);w64(8,p.cmdq_pa-base);w64(16,p.statq_pa-base);w64(24,p.tx_seq);w64(32,p.cot_packet_len);w64(40,p.emem_queue_tail); + for(unsigned i=0;i<17;i++) { w64(48+i*8,regions[i].pa-base);w64(184+i*8,regions[i].size); } + for(unsigned i=0;i<4;i++) w64(320+i*8,p.radix3_level_pages[i]); + if(fwrite(hdr,1,sizeof hdr,stdout)!=sizeof hdr || fwrite(arena,1,a.used,stdout)!=a.used || fwrite(p.cot_packet,1,1024,stdout)!=1024) return 4; + return 0; +} diff --git a/tests/arena_trace.om b/tests/arena_trace.om new file mode 100644 index 0000000..95d3b07 --- /dev/null +++ b/tests/arena_trace.om @@ -0,0 +1,280 @@ +fn tpage s ulong pos ulong off ulong n ulong to void +for i ulong n +v = mul add off i 37 +v = and add v s 255 +put arin add pos i uchar v +end +end +fn tfill s ulong pos ulong to void +n = get arslen s +s = mul add s 1 19 +off = ulong 0 +for p ulong div n 4096 +tpage s pos off 4096 +pos = add pos 4096 +off = add off 4096 +end +tpage s pos off rem n 4096 +end +note Independent synthetic caller-owned fixture, never reads actual firmware or a device. +global athdr uchar 512 +fn athput o ulong v ulong to void +for i ulong 8 +put athdr add o i uchar and shr v mul i 8 255 +end +end +fn atsetup mode uchar to void +put arbase 0 1048576 +put arcap 0 ARMAX +put arused 0 0 +put arcfg 0 1 +put arcfg 1 40 +put arcfg 2 268435456 +put arcfg 3 8192 +put arcfg 4 7 +put arcfg 5 9 +put arcfg 6 45056 +put arcfg 7 2560 +put arcfg 8 0 +put arcfg 9 0 +put arslen 0 4097 +if eq mode 2 +put arslen 0 add mul ulong 512 4096 1 +end +put arslen 1 257 +put arslen 2 196608 +put arslen 3 4103 +put arslen 4 48 +put arslen 5 384 +put arslen 6 384 +pos = ulong 0 +for s ulong 7 +put arsrc s pos +tfill s pos +pos = add pos get arslen s +end +for i ulong 936 +put siout i uchar and add mul i 13 129 255 +end +if or or eq mode 1 eq mode 3 or eq mode 4 ge mode 30 +put arcfg 9 26 +put arreg 0 26 +put arreg 4 1 +put arreg 8 24 +put arreg 12 1 +put arreg 16 239 +put arreg 17 190 +put arreg 18 173 +put arreg 19 222 +put arreg 20 4 +put arreg 24 88 +end +if or eq mode 3 eq mode 4 +put arreg 12 2 +put arreg 16 26 +put arreg 17 0 +put arreg 18 0 +put arreg 19 0 +put arreg 20 3 +put arcfg 9 29 +put arreg 0 29 +put arreg 26 255 +put arreg 27 128 +put arreg 28 0 +if eq mode 4 +put arreg 12 3 +end +end +if eq mode 10 +put arcfg 0 0 +end +if eq mode 11 +put arbase 0 1048577 +end +if eq mode 12 +put arcap 0 sub ARMAX 1 +put arbase 0 sub not ulong 0 4095 +end +if eq mode 13 +put arcfg 1 0 +end +if eq mode 14 +put arcfg 1 65 +end +if eq mode 15 +put arcfg 2 0 +end +if eq mode 16 +put arcfg 3 8193 +end +if eq mode 17 +put arcfg 6 45055 +end +if eq mode 18 +put arslen 0 0 +end +if eq mode 19 +put arsrc 1 ARMAX +end +if eq mode 20 +put arslen 2 196607 +end +if eq mode 21 +put arslen 4 47 +end +if eq mode 22 +put arcap 0 4096 +end +if eq mode 23 +put arcfg 1 20 +end +if eq mode 24 +put arcfg 2 sub not ulong 0 4095 +end +if eq mode 25 +put arused 0 4096 +end +if eq mode 26 +put arcfg 8 1 +end +if eq mode 27 +put arcfg 4 shl ulong 1 32 +end +if eq mode 28 +put arcfg 9 65457 +end +if eq mode 29 +put arslen 6 383 +end +if eq mode 30 +put arreg 0 25 +end +if eq mode 31 +put arreg 4 33 +end +if eq mode 32 +put arreg 8 25 +end +if eq mode 33 +put arreg 24 0 +end +if eq mode 34 +put arreg 25 88 +end +if eq mode 35 +put arreg 13 1 +end +if eq mode 36 +put arreg 12 4 +end +if eq mode 37 +put arreg 20 3 +end +if eq mode 38 +put arreg 12 2 +put arreg 16 26 +put arreg 17 0 +put arreg 18 0 +put arreg 19 0 +put arreg 20 1 +end +if eq mode 39 +put arcfg 1 20 +put arcfg 2 4096 +end +if eq mode 40 +put arcfg 2 4097 +end +end +fn atqueue to bool +c = get arcmd 0 +s = get arstat 0 +for i ulong 262144 +v = get arbuf add c i +if ne v get rqcmd i +ret false +end +v = get arbuf add s i +if ne v get rqstat i +ret false +end +end +ret true +end +fn main to int +b = new uchar 1 0 +n = read 0 b 0 1 +if ne n 1 +ret 2 +end +m = get b 0 +atsetup m +r = arboot 40 128 +if lt r 0 +ret 3 +end +if ne get bstate 0 4 +ret 5 +end +if ne get rqrx 0 0 +ret 5 +end +if ne get rqseq 0 0 +ret 5 +end +if not atqueue +ret 5 +end +rqpeer +for i ulong 4096 +put rqtmp i 0 +end +rqput32 2 40 1 +rqput32 2 48 RQVER +rqput32 2 52 RQSIG +rqput32 2 56 32 +rqput32 2 60 4097 +rqput32 2 32 rqsum 2 80 +for i ulong 4096 +put rqstat add 4096 i get rqtmp i +end +rqput32 1 16 1 +if ne bpoll 1 +ret 5 +end +if ne get bstate 0 5 +ret 5 +end +if ne get rqrx 0 1 +ret 5 +end +if ne get rqseq 0 0 +ret 5 +end +athput 0 get arused 0 +athput 8 get arcmd 0 +athput 16 get arstat 0 +athput 24 ulong get rqtx 0 +athput 32 get arclen 0 +athput 40 get artail 0 +for i ulong 17 +athput add 48 mul i 8 get aroff i +athput add 184 mul i 8 get arsize i +end +for i ulong 4 +athput add 320 mul i 8 get arnp i +end +n = write 1 athdr 0 512 +if ne n 512 +ret 4 +end +n = write 1 arbuf 0 get arused 0 +if ne n long get arused 0 +ret 4 +end +n = write 1 arcot 0 1024 +if ne n 1024 +ret 4 +end +ret 0 +end diff --git a/tests/boot-dma-host-receipt.txt b/tests/boot-dma-host-receipt.txt new file mode 100644 index 0000000..59d54d4 --- /dev/null +++ b/tests/boot-dma-host-receipt.txt @@ -0,0 +1,28 @@ +Composed GSP arena + owned DMA host receipt. Hardware and kernel execution NOT_RUN. +Source contains c69470f5fac6fe603a45b2c4af0c79eea3409ec6 and1c7e6f0aacce5550ebb5951f8e6727357c16b5b1 DMA changes, cherry-picked preserving boot work. +Compiler omega-mv397e67040fb74853c6814097fe02ae4e1ebd6f66, omc SHA256 bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6. +Platform Linux7.0.0-1019-nvidia aarch64 GNU/Linux. +Commands with exact pinned OMC: +OMC=$OMC sh tests/boot_dma.sh +OMC=$OMC AIENUX=$AIENUX sh tests/dma_host.sh +Both exited0. + +Observed: +boot_dma: PASS exact owned staging, generations, publication refusal and timeout quarantine; hardware NOT_RUN +Composed source SHA256 f8f8e3372e2cd6704b582469aed9f6f36baf73d725a6f195227d7495c6234eee +Omega executable SHA256 3631c2bb44e69b7650c87b96728d3206429c23d7015ad9f90a9481805d6191a5 +boot_dma: PASS both behavior mutants detected; hardware NOT_RUN + +The link-time DMA oracle is explicitly tests/dma_replay.om plus checked tuple/order helpers from tests/dma_check.om. Real shared-anonymous mapnew/mapwrite/mapread/mapdrop semantics remain active. No device fd is opened, no DMA ioctl executes, and no hardware publication is inferred. Complete arbuf bytes equal the owned CPU mapping. Stale epoch, different IOVA window and postpublication staging refuse; pending timeout plus explicit arlose quarantines backing; unmap/drop remain uncalled and the map remains retained. Mutant omitting staging copy and mutant omitting quarantine both compiled and returned1 on behavior checks, not unexpected traps. + +dma_host: 23 replay/boundary cases and real invalid-fd retry/drop PASS +dma_host: 11 compiled ownership/order/range/error mutants killed; hardware NOT_RUN +DMA source SHA256s: +chan/dma.om 87134205838435ec050646d30c99966b4381ea5821a0460ac30938b4911a8caf +chan/gmmu.om 0c2033b69241a9aff2e067d0a61597fcff63292473c9627f9c33bf6e308526bf +chan/mem.om 9adcf31f5b50fb7869d705908b6efd4a6da7ef67073c7e4cc24fd796e76b7a44 +chan/chan.om 900a40639724827d5afa17eb762663120c31a4410cb79040345b9706f682a127 +DMA replay executable SHA256 06f290ccc82f33cfa2ae14b8a0604ba722988b93e6ff7299259b8779cc7a9575 +Production invalid-fd executable SHA256 e2dfe13d77b4ae92b91b2ae6751eb1f107420754547b4da5fddf56058697ec60 + +No release/acquire live queue publisher, completion detector, real sequencer dispatch, kernel transport, or authorization path is installed. CPU staging is not firmware execution. Published/quarantined backing is never reclaimed without a future documented idle proof. diff --git a/tests/boot_dma.om b/tests/boot_dma.om new file mode 100644 index 0000000..6c90eaf --- /dev/null +++ b/tests/boot_dma.om @@ -0,0 +1,43 @@ +note HOST ONLY: explicit link-time DMA oracle plus real checked anonymous mapping. No device fd. +global ascheck uchar 16777216 +fn asbytes to void +n = get arused 0 +r = mapread get mmwh 0 0 ascheck 0 n +drcheck eq r long n +for p ulong div n 4096 +for i ulong 4096 +o = add mul p 4096 i +v = get ascheck o +drcheck eq v get arbuf o +end +end +end +fn main to int +atsetup 0 +drcheck eq arboot 1 128 0 +drcheck eq mmwalloc get arbase 0 get arused 0 MMOK +g = get mmwgen 0 +drcheck eq mmwpublish g MMESTATE +drcheck eq arstage add g 1 MMEGEN +put arbase 0 add get arbase 0 4096 +drcheck eq arstage g MMEINVAL +put arbase 0 sub get arbase 0 4096 +drcheck eq arstage g MMOK +asbytes +drcheck eq mmwdmap g 17 MMOK +drcheck eq arstage g MMOK +asbytes +drcheck eq mmwpublish g MMOK +drcheck eq arstage g MMESTATE +drcheck eq arlose g MMESTATE +drcheck eq bpoll 0 +drcheck eq bpoll -11 +drcheck eq arlose add g 1 MMEGEN +drcheck eq arlose g MMOK +drcheck eq get mmwst 0 MMWQUAR +drcheck eq mmwclose g MMEBUSY +drcheck ne get mmwh 0 0 +drcheck eq get drunmaps 0 0 +drcheck eq get drdrops 0 0 +ret 0 +end diff --git a/tests/boot_dma.sh b/tests/boot_dma.sh new file mode 100755 index 0000000..2fa5044 --- /dev/null +++ b/tests/boot_dma.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# Host only. Explicit DMA oracle replaces chan/dma.om at link time; no actual VFIO calls. +set -eu +R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) +OMC=${OMC:-$R/build/omc} +a=$(sha256sum "$OMC"); a=${a%% *} +[ "$a" = bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6 ] || exit 2 +t=$(mktemp -d /tmp/boot-dma.XXXXXX) +trap 'rm -rf "$t"' EXIT HUP INT TERM +sed 's/fn main to int/fn dmatests to int/' "$R/tests/dma_check.om" > "$t/dma.om" +sed 's/fn main to int/fn artests to int/' "$R/tests/arena_trace.om" > "$t/arena.om" +build() { + cat "$R/tests/dma_replay.om" "$R/chan/gmmu.om" "$R/chan/mem.om" "$R/chan/chan.om" "$R/chan/sim.om" "$t/dma.om" "$R/gsp/rpc.om" "$R/gsp/replay.om" "$R/gsp/sysinfo.om" "$R/chan/params.om" "$R/gsp/boot.om" "$R/gsp/arena.om" "$R/gsp/connect.om" "$t/arena.om" "$1" "$R/tests/boot_dma.om" > "$t/all.om" + if ! "$OMC" < "$t/all.om" > "$t/replay"; then echo 'boot_dma: INVALID compile'; exit 2; fi + chmod +x "$t/replay" +} +build "$R/gsp/owned.om" +"$t/replay" +echo 'boot_dma: PASS exact owned staging, generations, publication refusal and timeout quarantine; hardware NOT_RUN' +sha256sum "$t/all.om" "$t/replay" +sed 's/r = mapwrite get mmwh 0 0 arbuf 0 get arused 0/r = long get arused 0/' "$R/gsp/owned.om" > "$t/nocopy.om" +build "$t/nocopy.om" +if "$t/replay"; then echo 'boot_dma: SURVIVED staging'; exit 1; else rc=$?; fi +[ "$rc" = 1 ] || { echo 'boot_dma: INVALID staging mutant'; exit 2; } +sed 's/ret mmwquar gen/ret MMOK/' "$R/gsp/owned.om" > "$t/noquar.om" +build "$t/noquar.om" +if "$t/replay"; then echo 'boot_dma: SURVIVED quarantine'; exit 1; else rc=$?; fi +[ "$rc" = 1 ] || { echo 'boot_dma: INVALID quarantine mutant'; exit 2; } +echo 'boot_dma: PASS both behavior mutants detected; hardware NOT_RUN' diff --git a/tests/chan_diff.sh b/tests/chan_diff.sh index b4ef7a6..cf650f2 100755 --- a/tests/chan_diff.sh +++ b/tests/chan_diff.sh @@ -46,7 +46,7 @@ else fi run "$t/ctrace" > "$t/c.txt" || { echo "chan_diff: FAIL C reference run"; exit 2; } fi -if ! cat "$GMMU_OM" "$MEM_OM" "$CHAN_OM" "$GSIM_OM" "$here/tests/chan_trace.om" | run "$OMC" > "$t/omtrace"; then +if ! cat "$here/chan/dma.om" "$GMMU_OM" "$MEM_OM" "$CHAN_OM" "$GSIM_OM" "$here/tests/chan_trace.om" | run "$OMC" > "$t/omtrace"; then echo "chan_diff: FAIL omc build"; exit 3 fi chmod +x "$t/omtrace" diff --git a/tests/chan_trace.om b/tests/chan_trace.om index a5270e5..8b045a1 100644 --- a/tests/chan_trace.om +++ b/tests/chan_trace.om @@ -2,7 +2,7 @@ note tests/chan_trace.om: the differential trace driver for the channel port. It note native/kernel/tests/gpu_chan_trace.c (branch pr441 @ c5bb3a4b) line for line on chan/sim.om and note prints the same text: after every operation its rc, every register access the simulator logged note since the last line, the doorbell count and FNV-1a 64 of the whole 8 MiB simulated memory. -note Build: cat chan/gmmu.om chan/mem.om chan/chan.om chan/sim.om tests/chan_trace.om | omc > prog. +note Build: cat chan/dma.om chan/gmmu.om chan/mem.om chan/chan.om chan/sim.om tests/chan_trace.om | omc > prog. note Prefix ct. Host only: mmmode is 0 (the simulator) for the whole run. note memory: 8 MiB at bus address 0x80000000, page-table pool there (64 pages), data at 0x80040000 note (128 pages), GPU VA base 0x200000000 diff --git a/tests/complete_diff.sh b/tests/complete_diff.sh new file mode 100755 index 0000000..e6342f5 --- /dev/null +++ b/tests/complete_diff.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# tests/complete_diff.sh: builds the .om completion trace (chan/dma.om + chan/gmmu.om + chan/mem.om + +# chan/chan.om + chan/sim.om + chan/complete.om + tests/complete_trace.om) and the C reference trace +# tests/complete_ref.c (compiled fresh into a temp dir against NVIDIA open-gpu-kernel-modules 580.173.02 +# clc96f.h headers) and requires byte-identical stdout. Host only. +set -u +here=$(cd "$(dirname "$0")/.." && pwd) +OMC=${OMC:-$here/build/omc} +COMPLETE_OM=${COMPLETE_OM:-$here/chan/complete.om} +OGKM_SRC=${OGKM_SRC:-/home/drakestapleton/workspace/_ext/open-gpu-kernel-modules-580.173.02/src} +COMPLETE_REF=${COMPLETE_REF:-} +OMC_SHA=$(sed -n 's/^OMC_SHA256=//p' "$here/tools/omc.pin") +run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; } + +got=$(sha256sum "$OMC" | cut -d' ' -f1) +if [ "$got" != "$OMC_SHA" ]; then + echo "complete_diff: FAIL omc sha256 $got, pinned $OMC_SHA"; exit 2 +fi + +t=$(mktemp -d /tmp/complete_diff.XXXXXX) || exit 2 +trap 'rm -rf "$t"' EXIT + +if [ -n "$COMPLETE_REF" ]; then + [ -s "$COMPLETE_REF" ] || { echo "complete_diff: FAIL COMPLETE_REF $COMPLETE_REF missing or empty"; exit 2; } + cp "$COMPLETE_REF" "$t/c.txt" || exit 2 +else + S=$OGKM_SRC + if ! run cc -std=c11 -O1 -Wall -Werror \ + -I"$S/common/sdk/nvidia/inc" -I"$S/nvidia/arch/nvalloc/common/inc" -I"$S/common/uproc/os/common/include" \ + -I"$S/nvidia/inc/kernel" -I"$S/nvidia/inc" -I"$S/nvidia/generated" -I"$S/common/shared/msgq/inc" \ + -I"$S/nvidia/interface" -I"$S/common/inc" -o "$t/cref" "$here/tests/complete_ref.c"; then + echo "complete_diff: FAIL C reference build"; exit 2 + fi + run "$t/cref" > "$t/c.txt" || { echo "complete_diff: FAIL C reference run"; exit 2; } +fi + +if ! cat "$here/chan/dma.om" "$here/chan/gmmu.om" "$here/chan/mem.om" "$here/chan/chan.om" "$here/chan/sim.om" "$COMPLETE_OM" "$here/tests/complete_trace.om" | run "$OMC" > "$t/omtrace"; then + echo "complete_diff: FAIL omc build"; exit 3 +fi +chmod +x "$t/omtrace" +run "$t/omtrace" > "$t/om.txt" +rc=$? +if [ "$rc" -ne 0 ]; then + echo "complete_diff: FAIL om trace exit $rc"; exit 1 +fi +n=$(wc -l < "$t/c.txt") +if [ "$n" -eq 0 ]; then + echo "complete_diff: FAIL empty C trace"; exit 2 +fi +if ! cmp -s "$t/c.txt" "$t/om.txt"; then + echo "complete_diff: FAIL traces differ ($(diff "$t/c.txt" "$t/om.txt" | grep -c '^[<>]') differing lines; C $n lines, om $(wc -l < "$t/om.txt"))" + exit 1 +fi +echo "complete_diff: PASS ($n lines identical, .om vs C reference)" diff --git a/tests/complete_ref.c b/tests/complete_ref.c new file mode 100644 index 0000000..2668d00 --- /dev/null +++ b/tests/complete_ref.c @@ -0,0 +1,182 @@ +/* tests/complete_ref.c: TEST-ONLY C referee for chan/complete.om. Never linked into driver. + * Builds against NVIDIA open-gpu-kernel-modules 580.173.02 headers (MIT). + * Compares exact command encodings, wrap-safe progress math, capability refusals, + * and timeout quarantine latch with tests/complete_trace.om. */ +#include +#include +#include +#include +#include + +#include "nvtypes.h" +#include "nvmisc.h" +#include "class/clc96f.h" + +#define CMOK 0 +#define CMEINVAL (-1) +#define CMEALIGN (-2) +#define CMERANGE (-3) +#define CMESTATE (-4) +#define CMESTALE (-5) +#define CMEFULL (-6) +#define CMEGEN (-10) +#define CMETIME (-11) +#define CMEQUAR (-12) + +#define CHNINC 0x20000000u +#define CMSEMM (NVC96F_SEM_ADDR_LO >> 2) /* 23 */ +#define MMVALIM (1ULL << 57) + +static uint32_t cmhdr(uint32_t subc, uint32_t count) +{ + return CHNINC | ((count & 0x3ff) << 16) | ((subc & 7) << 13) | CMSEMM; +} + +static int cmrel(uint32_t subc, uint64_t va, uint32_t seq, uint32_t *wds) +{ + if (subc > 7) return CMEINVAL; + if ((va & 3) != 0) return CMEALIGN; + if (va == 0 || va >= MMVALIM) return CMERANGE; + wds[0] = cmhdr(subc, 5); + wds[1] = (uint32_t)(va & 0xFFFFFFFCULL); + wds[2] = (uint32_t)((va >> 32) & 0x1FFFFFFULL); + wds[3] = seq; + wds[4] = 0; + wds[5] = DRF_DEF(C96F, _SEM_EXECUTE, _OPERATION, _RELEASE) | + DRF_DEF(C96F, _SEM_EXECUTE, _PAYLOAD_SIZE, _32BIT) | + DRF_DEF(C96F, _SEM_EXECUTE, _RELEASE_WFI, _DIS); + return 6; +} + +static int cmacq(uint32_t subc, uint64_t va, uint32_t seq, uint32_t *wds) +{ + if (subc > 7) return CMEINVAL; + if ((va & 3) != 0) return CMEALIGN; + if (va == 0 || va >= MMVALIM) return CMERANGE; + wds[0] = cmhdr(subc, 5); + wds[1] = (uint32_t)(va & 0xFFFFFFFCULL); + wds[2] = (uint32_t)((va >> 32) & 0x1FFFFFFULL); + wds[3] = seq; + wds[4] = 0; + wds[5] = DRF_DEF(C96F, _SEM_EXECUTE, _OPERATION, _ACQUIRE); + return 6; +} + +static long cmprog(uint32_t ret, uint32_t put, uint32_t obs) +{ + uint32_t inflight = put - ret; + if (inflight == 0) { + if (obs == ret) return 0; + return CMESTALE; + } + uint32_t prog = obs - ret; + if (prog == 0) return 0; + if (prog > inflight) return CMESTALE; + return (long)prog; +} + +static void show_cmd(int id, int rc, const uint32_t *wds) +{ + if (rc > 0) { + printf("cmd %d rc=%d %08x %08x %08x %08x %08x %08x\n", + id, rc, wds[0], wds[1], wds[2], wds[3], wds[4], wds[5]); + } else { + printf("cmd %d rc=%d\n", id, rc); + } +} + +static void show_prog(int id, long rc) +{ + printf("prog %d rc=%ld\n", id, rc); +} + +static void show_cap(int id, int rc) +{ + printf("cap %d rc=%d\n", id, rc); +} + +static void show_drain(int id, int rc, int st, int bst, int wst) +{ + printf("drain %d rc=%d st=%d bst=%d wst=%d\n", id, rc, st, bst, wst); +} + +int main(void) +{ + uint32_t wds[6]; + int rc; + + /* 1. Command encoding */ + memset(wds, 0, sizeof wds); + rc = cmrel(0, 0x20000000ULL, 1, wds); + show_cmd(1, rc, wds); + + memset(wds, 0, sizeof wds); + rc = cmrel(3, 0x100000004ULL, 42, wds); + show_cmd(2, rc, wds); + + memset(wds, 0, sizeof wds); + rc = cmrel(7, 0x800000000ULL, 0xFFFFFFFFU, wds); + show_cmd(3, rc, wds); + + rc = cmrel(8, 0x20000000ULL, 1, wds); + show_cmd(4, rc, wds); + + rc = cmrel(0, 0x1001ULL, 1, wds); + show_cmd(5, rc, wds); + + rc = cmrel(0, 0ULL, 1, wds); + show_cmd(6, rc, wds); + + rc = cmrel(0, MMVALIM + 4, 1, wds); + show_cmd(7, rc, wds); + + memset(wds, 0, sizeof wds); + rc = cmacq(1, 0x40000000ULL, 10, wds); + show_cmd(8, rc, wds); + + /* 2. Sequence progress (wrap-safe) */ + show_prog(10, cmprog(0, 10, 0)); + show_prog(11, cmprog(0, 10, 5)); + show_prog(12, cmprog(0, 10, 10)); + show_prog(13, cmprog(0, 10, 11)); + show_prog(14, cmprog(5, 10, 4)); + show_prog(15, cmprog(0xFFFFFFFEU, 3, 1)); + show_prog(16, cmprog(0xFFFFFFFEU, 3, 0xFFFFFFFEU)); + show_prog(17, cmprog(0xFFFFFFFEU, 3, 4)); + show_prog(18, cmprog(0xFFFFFFFEU, 3, 0xFFFFFFFDU)); + show_prog(19, cmprog(100, 100, 100)); + show_prog(20, cmprog(100, 100, 101)); + + /* 3. Capability refusals */ + /* id 30: simulator window mmwkind=0 */ + show_cap(30, CMESTATE); + /* id 31: unmapped window mmwst=MMWOWN */ + show_cap(31, CMESTATE); + /* id 32: epoch mismatch */ + show_cap(32, CMEGEN); + /* id 33: cached buffer */ + show_cap(33, CMESTATE); + /* id 34: non-polled buffer */ + show_cap(34, CMESTATE); + /* id 35: misaligned offset */ + show_cap(35, CMEALIGN); + /* id 36: valid bind */ + show_cap(36, CMOK); + /* id 38: unbound slot rejects cmdrain */ + show_cap(38, CMESTATE); + /* id 42: cmsub over ring capacity rejects */ + show_cap(42, CMEFULL); + /* id 43: cmsub exceeding channel submitted entries rejects */ + show_cap(43, CMERANGE); + + /* 4. Drain & timeout quarantine */ + /* id 40: successful drain: rc=CMOK st=CMSIDLE(4) bst=GMLIVE(1) wst=MMWPUB(3) */ + show_drain(40, CMOK, 4, 1, 3); + /* id 41: timeout drain: rc=CMETIME st=CMSQST(6) bst=GMQUAR(2) wst=MMWQUAR(4) */ + show_drain(41, CMETIME, 6, 2, 4); + /* Terminal quarantines are never resurrected by the fixture. */ + show_cap(37, CMESTATE); + show_cap(39, CMESTATE); + + return 0; +} diff --git a/tests/complete_trace.om b/tests/complete_trace.om new file mode 100644 index 0000000..bbbb695 --- /dev/null +++ b/tests/complete_trace.om @@ -0,0 +1,172 @@ +note tests/complete_trace.om: test trace runner for chan/complete.om. +note Matches tests/complete_ref.c byte for byte on stdout. +text ctfrag "cmd | rc=|prog |cap |drain | st=| bst=| wst=" +text cthex "0123456789abcdef" +global outbuf uchar 256 +global digs uchar 24 +fn prch c uchar to void +put outbuf 0 c +r = write 1 outbuf 0 1 +end +fn prstr k ulong to void +w = ulong 0 +for i ulong len ctfrag +c = get ctfrag i +if eq c 124 +w = add w 1 +else +if eq w k +prch c +end +end +end +end +fn prdec v long to void +if lt v 0 +prch 45 +v = sub 0 v +end +if eq v 0 +prch 48 +ret +end +cnt = ulong 0 +x = ulong v +while gt x 0 bound 24 +put digs cnt uchar add rem x 10 48 +cnt = add cnt 1 +x = div x 10 +end +for i ulong cnt +prch get digs sub sub cnt 1 i +end +end +fn prhex8 v uint to void +for i ulong 8 +shift = mul sub 7 i 4 +idx = and shr v shift 15 +prch get cthex ulong idx +end +end +fn prcmd id long rc long to void +prstr 0 +prdec id +prstr 1 +prdec rc +if gt rc 0 +for i ulong 6 +prch 32 +prhex8 get cmwds i +end +end +prch 10 +end +fn prprog id long rc long to void +prstr 2 +prdec id +prstr 1 +prdec rc +prch 10 +end +fn prcap id long rc long to void +prstr 3 +prdec id +prstr 1 +prdec rc +prch 10 +end +fn prdrain id long rc long st ulong bst uchar wst ulong to void +prstr 4 +prdec id +prstr 1 +prdec rc +prstr 5 +prdec long st +prstr 6 +prdec long bst +prstr 7 +prdec long wst +prch 10 +end +fn setupmem to void +r = mmwalloc 2147483648 1048576 +put mmwgen 0 42 +note HOSTMODEL: real anonymous handle, no VFIO mapping or device publication. +r = mmasinit get mmwb 0 64 +r = gminit 4 add get mmwb 0 262144 128 8589934592 +r = gmalloc 4096 1 GMHPOLL +put chent 0 1024 +put chopen 0 1 +put chepoch 0 get mmwgen 0 +put mmwst 0 MMWDMA +end +fn main to int +r = cminit +if ne r CMOK +exit 1 +end +r = cmrel 0 536870912 1 +prcmd 1 r +r = cmrel 3 4294967300 42 +prcmd 2 r +r = cmrel 7 34359738368 4294967295 +prcmd 3 r +r = cmrel 8 536870912 1 +prcmd 4 r +r = cmrel 0 4097 1 +prcmd 5 r +r = cmrel 0 0 1 +prcmd 6 r +r = cmrel 0 add MMVALIM 4 1 +prcmd 7 r +r = cmacq 1 1073741824 10 +prcmd 8 r +prprog 10 cmprog 0 10 0 +prprog 11 cmprog 0 10 5 +prprog 12 cmprog 0 10 10 +prprog 13 cmprog 0 10 11 +prprog 14 cmprog 5 10 4 +prprog 15 cmprog 4294967294 3 1 +prprog 16 cmprog 4294967294 3 4294967294 +prprog 17 cmprog 4294967294 3 4 +prprog 18 cmprog 4294967294 3 4294967293 +prprog 19 cmprog 100 100 100 +prprog 20 cmprog 100 100 101 +setupmem +slot = ulong 0 +gen = ulong 42 +put mmwkind 0 0 +prcap 30 cmbind 0 slot 0 gen +put mmwkind 0 1 +put mmwst 0 MMWOWN +prcap 31 cmbind 0 slot 0 gen +put mmwst 0 MMWDMA +prcap 32 cmbind 0 slot 0 add gen 1 +put gmbca slot 0 +prcap 33 cmbind 0 slot 0 gen +put gmbca slot 1 +put gmbfl slot 0 +prcap 34 cmbind 0 slot 0 gen +put gmbfl slot GMHPOLL +prcap 35 cmbind 0 slot 1 gen +prcap 36 cmbind 0 slot 0 gen +put mmwst 0 MMWPUB +put chput 0 10 +prcap 38 cmdrain 1 10 +prcap 42 cmsub 0 2000 +prcap 43 cmsub 0 15 +rcsub = cmsub 0 10 +if ne rcsub CMOK +exit 1 +end +mmwr32 get cmpa 0 10 +rcdr1 = cmdrain 0 10 +prdrain 40 rcdr1 get cmst 0 get gmbst slot get mmwst 0 +put chput 0 15 +rcsub2 = cmsub 0 5 +rcdr2 = cmdrain 0 3 +prdrain 41 rcdr2 get cmst 0 get gmbst slot get mmwst 0 +prcap 37 cmbind 0 slot 0 gen +prcap 39 cmsub 0 5 +ret 0 +end diff --git a/tests/dispatch_cases.txt b/tests/dispatch_cases.txt new file mode 100644 index 0000000..2186522 --- /dev/null +++ b/tests/dispatch_cases.txt @@ -0,0 +1,63 @@ +# tests/dispatch_cases.txt: test cases for tests/dispatch_diff.sh +# Fields: name busy budget core corefail perms gen_off tok_off bstate pkt_trunc mode nwords end m w0 .. w(m-1) +# Opcodes: 0 WRITE a v, 1 MODIFY a mask v, 2 POLL a mask v tmo err, 3 DELAY us, 4 STORE a idx, 5..8 core +# Registers: 8653504 SEC2 EMEMC (plain), 8653824 SEC2 QUEUE_HEAD (busy), 1114356 GSP HWCFG2 (read-only) + +# 1. Valid dispatch cases (perms=15 = all core allowed, gen_off=0, tok_off=0, bstate=11, pkt_trunc=0, mode=0) +valid-empty 0 4 0 0 15 0 0 11 0 0 4 0 0 +valid-write 0 4 0 0 15 0 0 11 0 0 4 3 3 0 8653504 2748 +valid-modify 0 4 0 0 15 0 0 11 0 0 8 7 7 0 8653504 255 1 8653504 15 160 +valid-poll 0 4 0 0 15 0 0 11 0 0 10 9 9 0 8653504 4615 2 8653504 255 7 0 0 +valid-delay 0 4 0 0 15 0 0 11 0 0 3 2 2 3 50 +valid-store 0 4 0 0 15 0 0 11 0 0 7 6 6 0 8653504 4660 4 8653504 3 +valid-allcore 0 4 1 0 15 0 0 11 0 0 5 4 4 5 6 7 8 +valid-mixed 0 4 1 0 15 0 0 11 0 0 20 19 19 0 8653504 255 1 8653504 15 160 3 5 4 8653504 2 5 2 8653504 255 240 0 0 + +# 2. Malformed late opcode with ZERO side effects (full prevalidation proof) +late-unkop 0 4 1 0 15 0 0 11 0 0 8 7 7 0 8653504 100 4 8653504 1 99 +late-badstore 0 4 1 0 15 0 0 11 0 0 7 6 6 0 8653504 100 4 8653504 8 +late-overrun 0 4 1 0 15 0 0 11 0 0 6 5 5 0 8653504 100 1 8653504 +late-corenoc 0 4 0 0 15 0 0 11 0 0 8 7 7 0 8653504 100 4 8653504 1 5 +late-noperm 0 4 1 0 7 0 0 11 0 0 8 7 7 0 8653504 100 4 8653504 1 8 + +# 3. Token / generation stale or invalid bstate (zero side effects, no quarantine) +stale-gen 0 4 0 0 15 1 0 11 0 0 4 3 3 0 8653504 2748 +stale-tok 0 4 0 0 15 0 1 11 0 0 4 3 3 0 8653504 2748 +stale-both 0 4 0 0 15 1 1 11 0 0 4 3 3 0 8653504 2748 +bad-bstate 0 4 0 0 15 0 0 9 0 0 4 3 3 0 8653504 2748 + +# 4. Poll failure and poll budget +poll-fail 4 2 0 0 15 0 0 11 0 0 10 9 9 0 8653504 100 2 8653824 4294967295 16 0 0 +poll-budget-exceed 0 999999 0 0 15 0 0 11 0 0 4 3 3 0 8653504 2748 + +# 5. Core opcode matrix: 4 opcodes (5..8) x (no callback, no permission, fail, ok) +core5-nocall 0 4 0 0 15 0 0 11 0 0 2 1 1 5 +core5-noperm 0 4 1 0 14 0 0 11 0 0 2 1 1 5 +core5-fail 0 4 1 5 15 0 0 11 0 0 2 1 1 5 +core5-ok 0 4 1 0 15 0 0 11 0 0 2 1 1 5 + +core6-nocall 0 4 0 0 15 0 0 11 0 0 2 1 1 6 +core6-noperm 0 4 1 0 13 0 0 11 0 0 2 1 1 6 +core6-fail 0 4 1 6 15 0 0 11 0 0 2 1 1 6 +core6-ok 0 4 1 0 15 0 0 11 0 0 2 1 1 6 + +core7-nocall 0 4 0 0 15 0 0 11 0 0 2 1 1 7 +core7-noperm 0 4 1 0 11 0 0 11 0 0 2 1 1 7 +core7-fail 0 4 1 7 15 0 0 11 0 0 2 1 1 7 +core7-ok 0 4 1 0 15 0 0 11 0 0 2 1 1 7 + +core8-nocall 0 4 0 0 15 0 0 11 0 0 2 1 1 8 +core8-noperm 0 4 1 0 7 0 0 11 0 0 2 1 1 8 +core8-fail 0 4 1 8 15 0 0 11 0 0 2 1 1 8 +core8-ok 0 4 1 0 15 0 0 11 0 0 2 1 1 8 + +# 6. Non-sim mode: whole dispatch refuses without typed MMIO span, including register-only streams. +core-nonsim 0 4 1 0 15 0 0 11 0 1 5 4 4 0 8653504 100 5 +# A valid write precedes a misaligned register write: neither may reach MMIO. +late-invalidreg 0 4 1 0 15 0 0 11 0 1 7 6 6 0 8653504 100 0 1 7 + +# 7. Packet shape, capacity, and index bounds +shape-trunc 0 4 0 0 15 0 0 11 1 0 4 3 3 0 8653504 2748 +cap-zero 0 4 0 0 15 0 0 11 0 0 0 0 0 +cap-over 0 4 0 0 15 0 0 11 0 0 16385 0 0 +idx-over 0 4 0 0 15 0 0 11 0 0 4 4 3 0 8653504 2748 diff --git a/tests/dispatch_diff.sh b/tests/dispatch_diff.sh new file mode 100755 index 0000000..5237d9a --- /dev/null +++ b/tests/dispatch_diff.sh @@ -0,0 +1,133 @@ +#!/bin/sh +# tests/dispatch_diff.sh: builds the .om GSP sequencer dispatcher (gsp/dispatch.om) +# and the C referee (tests/dispatch_ref.c against gsp_seq.c and gsp_sim.c), +# runs every case in tests/dispatch_cases.txt through both, and requires +# byte-identical traces (rc, state, dead, why, delays, core calls, save[8], register log, violations). +# Host verification only. Never invokes VFIO, device opens, or kernel module actions. +set -u +here=$(cd "$(dirname "$0")/.." && pwd) +AIENUX=${AIENUX:-/tmp/omega-driver-reference} +[ -d "$AIENUX/native/kernel" ] || AIENUX=/home/drakestapleton/work/OwnDriver/omega-driver-reference +OMC=${OMC:-$here/build/omc} +[ -f "$OMC" ] || OMC=/home/drakestapleton/work/OwnDriver/omega-mv-vfio/seed/out/omc +SEQ_OM=${SEQ_OM:-$here/gsp/seq.om} +RPC_OM=${RPC_OM:-$here/gsp/rpc.om} +BOOT_OM=${BOOT_OM:-$here/gsp/boot.om} +DISPATCH_OM=${DISPATCH_OM:-$here/gsp/dispatch.om} +OMC_PIN=$here/tools/omc.pin +[ -f "$OMC_PIN" ] || OMC_PIN=/home/drakestapleton/work/OwnDriver/omega-mv-vfio/tools/omc.pin +OMC_SHA=$(sed -n 's/^OMC_SHA256=//p' "$OMC_PIN" 2>/dev/null || echo "bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6") +run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; } + +got=$(sha256sum "$OMC" 2>/dev/null | cut -d' ' -f1) +if [ "$got" != "$OMC_SHA" ]; then + echo "dispatch_diff: FAIL omc sha256 $got, pinned $OMC_SHA"; exit 2 +fi + +# Hard device-safety check: neither dispatch nor test harness may reference device paths or IOCTLs +if grep -n 'put gspmode [0-9]* [1-9]\|gspbar\|vfio\|mapnew\|/dev/\|/sys/' "$here/tests/dispatch_trace.om" "$DISPATCH_OM"; then + echo "dispatch_diff: FAIL dispatch or test driver names a device"; exit 2 +fi + +t=$(mktemp -d /tmp/dispatch_diff.XXXXXX) || exit 2 +trap 'rm -rf "$t"' EXIT + +k=$AIENUX/native/kernel +if ! run cc -std=c11 -O1 -Wall -Werror -I"$k/gpu" -o "$t/ref" "$here/tests/dispatch_ref.c" "$k/gpu/gsp_seq.c" "$k/gpu/gsp_sim.c"; then + echo "dispatch_diff: FAIL C referee build"; exit 2 +fi + +REPLAY_OM="" +if [ -f "$here/gsp/replay.om" ]; then + REPLAY_OM="$here/gsp/replay.om" +fi + +if ! cat "$here/gsp/mmio.om" "$here/gsp/sim.om" "$SEQ_OM" "$RPC_OM" $REPLAY_OM "$here/gsp/sysinfo.om" "$here/chan/params.om" "$BOOT_OM" "$DISPATCH_OM" "$here/tests/dispatch_trace.om" | run "$OMC" > "$t/om"; then + echo "dispatch_diff: FAIL omc build"; exit 3 +fi +chmod +x "$t/om" + +fail=0 +cases=$here/tests/dispatch_cases.txt + +run "$t/ref" < "$cases" > "$t/c.cases"; echo "exit $?" >> "$t/c.cases" +run "$t/om" < "$cases" > "$t/o.cases"; echo "exit $?" >> "$t/o.cases" + +if ! cmp -s "$t/c.cases" "$t/o.cases"; then + echo "dispatch_diff: cases output differs (C left, .om right)"; diff -u "$t/c.cases" "$t/o.cases" | head -20; fail=1 +fi + +want=$(grep -Evc '^(#|[[:space:]]*$)' "$cases") +n=$(grep -c '^== ' "$t/o.cases") +if [ "$n" -ne "$want" ] || [ "$(tail -n 1 "$t/o.cases")" != "exit 0" ]; then + echo "dispatch_diff: ran $n of $want cases"; tail -n 1 "$t/o.cases"; fail=1 +fi + +# Verification of negative controls and behavioral constraints: +# 1. Zero writes on malformed late op (proves full prevalidation prevented any partial effects) +late_unk=$(grep '^== late-unkop ' "$t/o.cases") +case "$late_unk" in + *"rc=-3"*"state=12"*"dead=1"*"nlog=0"*) ;; + *) echo "dispatch_diff: FAIL late-unkop side-effect control: $late_unk"; fail=1 ;; +esac + +late_badstore=$(grep '^== late-badstore ' "$t/o.cases") +case "$late_badstore" in + *"rc=-6"*"state=12"*"dead=1"*"nlog=0"*) ;; + *) echo "dispatch_diff: FAIL late-badstore side-effect control: $late_badstore"; fail=1 ;; +esac + +# 2. Stale token / generation returns -10 without entering quarantine (state remains 11, dead=0) +stale_gen=$(grep '^== stale-gen ' "$t/o.cases") +case "$stale_gen" in + *"rc=-10"*"state=11"*"dead=0"*"nlog=0"*) ;; + *) echo "dispatch_diff: FAIL stale-gen state control: $stale_gen"; fail=1 ;; +esac + +stale_tok=$(grep '^== stale-tok ' "$t/o.cases") +case "$stale_tok" in + *"rc=-10"*"state=11"*"dead=0"*"nlog=0"*) ;; + *) echo "dispatch_diff: FAIL stale-tok state control: $stale_tok"; fail=1 ;; +esac + +# 3. Poll timeout enters quarantine +poll_fail=$(grep '^== poll-fail ' "$t/o.cases") +case "$poll_fail" in + *"rc=-5"*"state=12"*"dead=1"*) ;; + *) echo "dispatch_diff: FAIL poll-fail quarantine control: $poll_fail"; fail=1 ;; +esac + +# 4. Core matrix: all 4 core opcodes refuse without callback or without permission +for op in 5 6 7 8; do + nocall=$(grep "^== core${op}-nocall " "$t/o.cases") + case "$nocall" in + *"rc=-7"*"state=12"*"dead=1"*"core=0"*) ;; + *) echo "dispatch_diff: FAIL core${op}-nocall refusal: $nocall"; fail=1 ;; + esac + noperm=$(grep "^== core${op}-noperm " "$t/o.cases") + case "$noperm" in + *"rc=-7"*"state=12"*"dead=1"*"core=0"*) ;; + *) echo "dispatch_diff: FAIL core${op}-noperm refusal: $noperm"; fail=1 ;; + esac +done +# 5. Non-sim mode: allpermissions+sqcore cannot activate core in non-sim mode (refuses before effect) +core_nonsim=$(grep '^== core-nonsim ' "$t/o.cases") +case "$core_nonsim" in + *"rc=-7"*"state=12"*"dead=1"*"core=0"*"nlog=0"*) ;; + *) echo "dispatch_diff: FAIL core-nonsim side-effect control: $core_nonsim"; fail=1 ;; +esac + +# No typed MMIO span: reject even register-only hardware sequences before the first write. +late_reg=$(grep '^== late-invalidreg ' "$t/o.cases") +case "$late_reg" in + *"rc=-7"*"state=12"*"dead=1"*"delays=0/0"*"core=0"*"nlog=0"*"violations=0"*) ;; + *) echo "dispatch_diff: FAIL late-invalidreg whole-dispatch refusal: $late_reg"; fail=1 ;; +esac + +if [ "$fail" -eq 0 ]; then + echo "dispatch_diff: PASS host-model trace parity, payload prevalidation, hardware-dispatch refusal, and quarantine controls; hardware NOT_RUN" + sha256sum "$here/gsp/dispatch.om" "$cases" "$here/tests/dispatch_ref.c" "$here/tests/dispatch_trace.om" + exit 0 +else + exit 1 +fi diff --git a/tests/dispatch_mutants.sh b/tests/dispatch_mutants.sh new file mode 100755 index 0000000..d6b6459 --- /dev/null +++ b/tests/dispatch_mutants.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# tests/dispatch_mutants.sh: behavioral mutation testing of gsp/dispatch.om. +# Single-line mutants targeting each security, prevalidation, and state transition contract. +# Every mutant must compile and be killed (detected) by tests/dispatch_diff.sh. +# Host verification only. Never invokes VFIO or device operations. +set -u +here=$(cd "$(dirname "$0")/.." && pwd) +src=$here/gsp/dispatch.om +diff_sh=$here/tests/dispatch_diff.sh +t=$(mktemp -d /tmp/mutants-dispatch.XXXXXX) || exit 2 +trap 'rm -rf "$t"' EXIT + +cat > "$t/list" <<'EOF' +prevalidation bypassed|r = dspprev nw ci|r = long 0 +stale generation check disabled|if ne gen get bgen 0|if false +stale token check disabled|if ne tok get btoken 0|if false +suspended state check disabled|if ne get bstate 0 11|if false +packet truncation check disabled|if lt get bselen 0 add 120 mul nw 4|if false +buffer capacity check disabled|if gt nw SQMAX|if false +cmdIndex bound check disabled|if ge ci nw|if false +core permission check disabled in prevalidation|if not dspcperm op|if false +store save index check disabled in prevalidation|if ge k SQSAVE|if false +bseqdone ok=false on success|d = bseqdone gen tok true|d = bseqdone gen tok false +save register writeback dropped|dspp32 add 88 mul k 4 get sqsave k|note no writeback +non-sim whole-dispatch refusal disabled|if ne get gspmode 0 0|if false +EOF + +killed=0 +survived=0 +invalid=0 + +while IFS='|' read -r desc old new; do + [ -z "$desc" ] && continue + m="$t/mutant.om" + awk -v o="$old" -v n="$new" ' + $0 == o { c++; print n; next } + { print } + END { if (c != 1) exit 1 }' "$src" > "$m" + if [ $? -ne 0 ] || cmp -s "$src" "$m"; then + echo "mutant INVALID (pattern not matched exactly once): $desc"; invalid=$((invalid + 1)); continue + fi + DISPATCH_OM=$m sh "$diff_sh" > "$t/m.log" 2>&1 + rc=$? + case $rc in + 0) echo "mutant SURVIVED: $desc"; survived=$((survived + 1)) ;; + 1) echo "mutant killed: $desc"; killed=$((killed + 1)) ;; + *) echo "mutant INVALID (exit $rc: $(cat "$t/m.log")): $desc"; invalid=$((invalid + 1)) ;; + esac +done < "$t/list" + +echo "mutants-dispatch: $killed killed, $survived survived, $invalid invalid" +[ "$survived" -eq 0 ] && [ "$invalid" -eq 0 ] && [ "$killed" -ge 10 ] diff --git a/tests/dispatch_ref.c b/tests/dispatch_ref.c new file mode 100644 index 0000000..eae5883 --- /dev/null +++ b/tests/dispatch_ref.c @@ -0,0 +1,224 @@ +/* tests/dispatch_ref.c -- TEST-ONLY C referee for tests/dispatch_diff.sh. + * Never linked into the product. + * Runs reference prevalidation and gsp_seq_run against gsp_sim for every case in tests/dispatch_cases.txt. + * Opcodes and payload sizes from rmgspseq.h and kernel_gsp.c:5297-5432. + * Input format (decimal): + * name busy budget core corefail perms gen_off tok_off bstate pkt_trunc mode nwords end m w0 .. w(m-1) + */ +#include +#include +#include +#include +#include "gsp_seq.h" +#include "gsp_sim.h" + +struct ctx { + struct ck_gpu_regs r; + uint32_t fail, ncalls, ops[16], ndelay, us; +}; + +static uint32_t rd(void *c, uint32_t a) { struct ctx *x = c; return x->r.rd(x->r.ctx, a); } +static void wr(void *c, uint32_t a, uint32_t v) { struct ctx *x = c; x->r.wr(x->r.ctx, a, v); } + +static int c_core(void *c, uint32_t op) +{ + struct ctx *x = c; + if (x->ncalls < 16) x->ops[x->ncalls] = op; + x->ncalls++; + return op == x->fail ? -1 : 0; +} + +static void delay_us(void *c, uint32_t us) +{ + struct ctx *x = c; + x->ndelay++; + x->us += us; +} + +static uint32_t payload_dwords(uint32_t op) +{ + switch (op) { + case GSP_SEQ_REG_WRITE: return 2; + case GSP_SEQ_REG_MODIFY: return 3; + case GSP_SEQ_REG_POLL: return 5; + case GSP_SEQ_DELAY_US: return 1; + case GSP_SEQ_REG_STORE: return 2; + case GSP_SEQ_CORE_RESET: + case GSP_SEQ_CORE_START: + case GSP_SEQ_CORE_WAIT: + case GSP_SEQ_CORE_RESUME: return 0; + default: return 0xffffffffu; + } +} + +static const char *why_text(int rc) +{ + switch (rc) { + case -1: return "empty buffer"; + case -2: return "cmdIndex not inside the buffer"; + case -3: return "unknown opcode"; + case -4: return "opcode overruns cmdIndex"; + case -5: return "poll timed out"; + case -6: return "save index out of range"; + case -7: return "core opcode with no core callback"; + case -8: return "core opcode failed"; + case -9: return "nwords over 16384"; + case -10: return "stale token or invalid state"; + case -11: return "poll budget over 999998"; + case -12: return "remote error quarantined"; + case -13: return "packet shape truncated"; + default: return "-"; + } +} + +static int map_why_to_code(const char *why) +{ + if (!why) return 0; + if (!strcmp(why, "empty buffer")) return -1; + if (!strcmp(why, "cmdIndex not inside the buffer")) return -2; + if (!strcmp(why, "unknown opcode")) return -3; + if (!strcmp(why, "opcode overruns cmdIndex")) return -4; + if (!strcmp(why, "poll timed out")) return -5; + if (!strcmp(why, "save index out of range")) return -6; + if (!strcmp(why, "core opcode with no core callback")) return -7; + if (!strcmp(why, "core opcode failed")) return -8; + if (!strcmp(why, "nwords over 16384")) return -9; + if (!strcmp(why, "delay sleep failed")) return -10; + if (!strcmp(why, "poll budget over 999998")) return -11; + return -1; +} + +static int prevalidate(const uint32_t *buf, uint32_t nw, uint32_t end, uint32_t perms, int has_core, uint32_t bud, uint32_t mode) +{ + if (nw == 0) return -1; + if (end >= nw) return -2; + if (nw > 16384) return -9; + if (bud > 999998) return -11; + uint32_t i = 0; + while (i < end) { + uint32_t op = buf[i++]; + uint32_t n = payload_dwords(op); + if (n == 0xffffffffu) return -3; + if (i + n > end) return -4; + if (op == GSP_SEQ_REG_STORE) { + if (buf[i + 1] >= 8) return -6; + } + if (op >= GSP_SEQ_CORE_RESET && op <= GSP_SEQ_CORE_RESUME) { + uint32_t bit = 1u << (op - GSP_SEQ_CORE_RESET); + /* Host model flags (perms/has_core) authorize host simulation only (mode == 0). + * Hardware core operations require typed engine capabilities; non-sim mode (mode != 0) + * unconditionally refuses core operations. */ + if (mode != 0 || !has_core || !(perms & bit)) return -7; + } + i += n; + } + return 0; +} + +int main(void) +{ + char line[65536]; + while (fgets(line, sizeof line, stdin)) { + char *p = line; + while (*p == ' ' || *p == '\t') p++; + if (*p == '#' || *p == '\n' || *p == '\0') continue; + char name[64]; + long long busy, bud, core, fail, perms, gen_off, tok_off, bstate, pkt_trunc, mode, nw, end, m; + int off = 0; + if (sscanf(p, "%63s %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld%n", + name, &busy, &bud, &core, &fail, &perms, &gen_off, &tok_off, &bstate, &pkt_trunc, &mode, &nw, &end, &m, &off) != 14) { + fprintf(stderr, "dispatch_ref: malformed line: %s\n", line); + return 2; + } + p += off; + uint32_t alloc_nw = (nw > 0) ? (uint32_t)nw : 1; + uint32_t *buf = calloc(alloc_nw, sizeof(uint32_t)); + for (long long i = 0; i < m && i < nw; i++) { + long long w = 0; + if (sscanf(p, "%lld%n", &w, &off) != 1) { + fprintf(stderr, "dispatch_ref: short words in: %s\n", line); + free(buf); + return 2; + } + buf[i] = (uint32_t)w; + p += off; + } + while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n') p++; + if (*p != '\0') { + fprintf(stderr, "dispatch_ref: trailing words (m does not cover the line): %s\n", line); + free(buf); + return 2; + } + + struct ck_gspsim_cfg cfg; + memset(&cfg, 0, sizeof cfg); + cfg.busy_reads = (uint32_t)busy; + struct ck_gspsim sim; + ck_gspsim_init(&sim, &cfg); + + struct ctx x; + memset(&x, 0, sizeof x); + x.r = ck_gspsim_regs(&sim); + x.fail = (uint32_t)fail; + + uint32_t state = (uint32_t)bstate; + uint32_t bprev = 9; + uint32_t dead = 0; + uint32_t bselen = pkt_trunc ? 100 : (120 + (uint32_t)nw * 4); + uint32_t save[8] = {0}; + int rc = 0; + + if (state != 11 || gen_off != 0 || tok_off != 0) { + rc = -10; + } else if (mode != 0) { + /* No typed MMIO lease/span: refuse the WHOLE dispatch before unpack/effects. + * This is the explicit unavailable-effect gate, not vendor register validation. */ + dead = 1; state = 12; rc = -7; + } else if (bselen < 120 + (uint32_t)nw * 4) { + dead = 1; state = 12; rc = -13; + } else if (nw == 0) { + dead = 1; state = 12; rc = -1; + } else if (nw > 16384) { + dead = 1; state = 12; rc = -9; + } else if ((uint32_t)end >= (uint32_t)nw) { + dead = 1; state = 12; rc = -2; + } else { + int pr = prevalidate(buf, (uint32_t)nw, (uint32_t)end, (uint32_t)perms, (int)core, (uint32_t)bud, (uint32_t)mode); + if (pr != 0) { + dead = 1; state = 12; rc = pr; + } else { + struct gsp_seq_io io; + memset(&io, 0, sizeof io); + io.rd = rd; + io.wr = wr; + io.core = core ? c_core : NULL; + io.delay_us = delay_us; + io.ctx = &x; + io.poll_budget = (uint32_t)bud; + const char *why = NULL; + int s_rc = gsp_seq_run(buf, (uint32_t)nw, (uint32_t)end, &io, &why); + if (s_rc != 0) { + dead = 1; state = 12; + rc = map_why_to_code(why); + } else { + state = bprev; + dead = 0; + rc = 0; + for (int k = 0; k < 8; k++) save[k] = io.save[k]; + } + } + } + + printf("== %s rc=%d state=%u dead=%u why=%s delays=%u/%u core=%u ops=", + name, rc, state, dead, why_text(rc), x.ndelay, x.us, x.ncalls); + for (uint32_t i = 0; i < x.ncalls && i < 16; i++) printf("%u,", x.ops[i]); + printf(" save="); + for (int i = 0; i < 8; i++) printf("%#x,", save[i]); + printf(" nlog=%u violations=%u\n", sim.nlog, sim.violations); + for (uint32_t i = 0; i < sim.nlog && i < CK_GSPSIM_LOG_MAX; i++) + printf("%c %06x %08x\n", sim.log[i].write ? 'W' : 'R', sim.log[i].off, sim.log[i].val); + + free(buf); + } + return 0; +} diff --git a/tests/dispatch_trace.om b/tests/dispatch_trace.om new file mode 100644 index 0000000..19cc8b0 --- /dev/null +++ b/tests/dispatch_trace.om @@ -0,0 +1,329 @@ +note tests/dispatch_trace.om: host trace of gsp/dispatch.om on the in-.om simulator. +note Reads cases on stdin, decimal: +note name busy budget core corefail perms gen_off tok_off bstate pkt_trunc nwords end m w0 .. w(m-1) +note Prints, per case, what tests/dispatch_ref.c prints for the C reference on the C simulator: +note == name rc=RC state=S dead=D why=WHY delays=CALLS/US core=CALLS ops=OP,.. save=%#x,..(8) nlog=N violations=N +note then the register log, one "W|R %06x %08x" line per access. +note Host only, mode 0 only. Never touches real hardware. +text zqtx "== | rc=| state=| dead=| why=| delays=| core=| ops=| save=| nlog=| violations=|" +global zqin uchar 262144 +global zqn ulong 1 +global zqp ulong 1 +global zqt uchar 64 +global zqtl ulong 1 +global zqnm uchar 64 +global zqnml ulong 1 +global zqob uchar 65536 +global zqo ulong 1 +global zqops ulong 16 +global zqnop ulong 1 +global zqfail ulong 1 +global zqbusy ulong 1 +global zqbud ulong 1 +global zqcon ulong 1 +global zqperm ulong 1 +global zqgenoff ulong 1 +global zqtokoff ulong 1 +global zqistat ulong 1 +global zqtrunc ulong 1 +global zqmode ulong 1 +global zqnw ulong 1 +global zqci ulong 1 +fn sqcorefn op ulong to long +k = get zqnop 0 +if lt k 16 +put zqops k op +end +put zqnop 0 add k 1 +if eq op get zqfail 0 +ret -1 +end +ret 0 +end +fn zqflush to void +n = get zqo 0 +if eq n 0 +ret +end +p = ulong 0 +while lt p n bound 100000 +w = write 1 zqob p sub n p +if le w 0 +exit 1 +end +p = add p ulong w +end +put zqo 0 0 +end +fn zqbad to void +zqflush +exit 2 +end +fn zqch c uchar to void +p = get zqo 0 +put zqob p c +put zqo 0 add p 1 +if ge add p 1 65000 +zqflush +end +end +fn zqfr k ulong to void +w = ulong 0 +for i ulong len zqtx +c = get zqtx i +if eq c 124 +w = add w 1 +else +if eq w k +zqch c +end +end +end +end +fn zqdec v ulong to void +d = ulong 1 +while le d div v 10 bound 20 +d = mul d 10 +end +while ne d 0 bound 20 +zqch uchar add rem div v d 10 48 +d = div d 10 +end +end +fn zqsdec v long to void +if lt v 0 +zqch 45 +zqdec ulong sub 0 v +else +zqdec ulong v +end +end +fn zqdig v ulong to void +if lt v 10 +zqch uchar add v 48 +else +zqch uchar add sub v 10 97 +end +end +fn zqhexw v ulong w ulong to void +t = v +nd = ulong 0 +while ne t 0 bound 17 +nd = add nd 1 +t = shr t 4 +end +if lt nd w +nd = w +end +for i ulong nd +zqdig and shr v mul sub sub nd i 1 4 15 +end +end +fn zqhex v ulong to void +if eq v 0 +zqch 48 +ret +end +zqch 48 +zqch 120 +zqhexw v 1 +end +fn zqsp c uchar to bool +ret or eq c 32 and ge c 9 le c 13 +end +fn zqtok to ulong +p = get zqp 0 +n = get zqn 0 +while and lt p n zqsp get zqin p bound 300000 +p = add p 1 +end +l = ulong 0 +while and lt p n not zqsp get zqin p bound 300000 +if ge l 63 +zqbad +end +put zqt l get zqin p +l = add l 1 +p = add p 1 +end +put zqp 0 p +put zqtl 0 l +ret l +end +fn zqskipl to void +p = get zqp 0 +n = get zqn 0 +while and lt p n ne get zqin p 10 bound 300000 +p = add p 1 +end +put zqp 0 p +end +fn zqnum to ulong +l = zqtok +if eq l 0 +zqbad +end +v = ulong 0 +for i ulong l +c = get zqt i +if or lt c 48 gt c 57 +zqbad +end +v = add mul v 10 ulong sub c 48 +if gt v 4294967295 +zqbad +end +end +ret v +end +fn zqexec to void +busy = get zqbusy 0 +for i ulong 10 +put scfg i 0 +end +put scfg 0 busy +siminit +put spm 0 0 +put gspmode 0 get zqmode 0 +for j ulong SQSAVE +put sqsave j 0 +end +put sqdly 0 0 +put sqdly 1 0 +put zqnop 0 0 +put sqbud 0 get zqbud 0 +put sqcore 0 get zqcon 0 +dspinit +dspperms get zqperm 0 +put bgen 0 42 +put btoken 0 1001 +put bprev 0 9 +put bstate 0 get zqistat 0 +put rqdead 0 0 +nw = get zqnw 0 +ci = get zqci 0 +trunc = get zqtrunc 0 +if eq trunc 1 +put bselen 0 100 +else +put bselen 0 add 120 mul nw 4 +end +dspp32 80 nw +dspp32 84 ci +for k ulong SQSAVE +dspp32 add 88 mul k 4 0 +end +gen = add 42 get zqgenoff 0 +tok = add 1001 get zqtokoff 0 +rc = dspseq gen tok +dspwhy rc +zqfr 0 +for k ulong get zqnml 0 +zqch get zqnm k +end +zqfr 1 +zqsdec rc +zqfr 2 +zqdec get bstate 0 +zqfr 3 +zqdec ulong get rqdead 0 +zqfr 4 +if eq get dspwl 0 0 +zqch 45 +else +for k ulong get dspwl 0 +zqch get dspwb k +end +end +zqfr 5 +zqdec get sqdly 0 +zqch 47 +zqdec and get sqdly 1 M32 +zqfr 6 +zqdec get zqnop 0 +zqfr 7 +for k ulong get zqnop 0 +if lt k 16 +zqdec get zqops k +zqch 44 +end +end +zqfr 8 +for k ulong SQSAVE +zqhex dspu32 add 88 mul k 4 +zqch 44 +end +zqfr 9 +zqdec sg SNLOG +zqfr 10 +zqdec sg SVIOL +zqch 10 +for k ulong sg SNLOG +if lt k LOGMAX +if eq get slogw k 1 +zqch 87 +else +zqch 82 +end +zqch 32 +zqhexw get slogo k 6 +zqch 32 +zqhexw get slogv k 8 +zqch 10 +end +end +end +fn main to int +p = ulong 0 +while lt p 262144 bound 300000 +r = read int 0 zqin p sub 262144 p +if lt r 0 +zqbad +end +if eq r 0 +break +end +p = add p ulong r +end +put zqn 0 p +put zqp 0 0 +while true bound 100000 +l = zqtok +if eq l 0 +break +end +if eq get zqt 0 35 +zqskipl +continue +end +for i ulong l +put zqnm i get zqt i +end +put zqnml 0 l +put zqbusy 0 zqnum +put zqbud 0 zqnum +put zqcon 0 zqnum +put zqfail 0 zqnum +put zqperm 0 zqnum +put zqgenoff 0 zqnum +put zqtokoff 0 zqnum +put zqistat 0 zqnum +put zqtrunc 0 zqnum +put zqmode 0 zqnum +put zqnw 0 zqnum +put zqci 0 zqnum +m = zqnum +for i ulong 65536 +put bsevent i 0 +end +for i ulong m +w = zqnum +if lt i get zqnw 0 +dspp32 add 120 mul i 4 w +end +end +zqexec +end +zqflush +ret 0 +end diff --git a/tests/dma_badfd.om b/tests/dma_badfd.om new file mode 100644 index 0000000..088ec2c --- /dev/null +++ b/tests/dma_badfd.om @@ -0,0 +1,26 @@ +note Production chan/dma.om transport: anonymous CPU memory and invalid fd -1 only. +note The compiler mutates vaddr during MAP_DMA validation even when the ioctl returns EBADF. +note A second identical attempt must still reach EBADF rather than treating a CPU address as a handle. +fn dbcheck ok bool to void +if not ok +exit 1 +end +end +fn main to int +dbcheck eq mmwalloc 2147483648 4096 MMOK +g = get mmwgen 0 +h = get mmwh 0 +dbcheck eq mmwpublish g MMESTATE +dbcheck eq mmwdmap g -1 MMEIO +dbcheck eq get mmwerr 0 -9 +dbcheck eq get mmwst 0 MMWOWN +dbcheck eq mmwdmap g -1 MMEIO +dbcheck eq get mmwerr 0 -9 +dbcheck eq get mmwst 0 MMWOWN +mmwr64 2147483648 42 +dbcheck eq mapget h 0 8 42 +dbcheck eq mmwclose g MMOK +dbcheck eq get mmwh 0 0 +dbcheck eq mmwdmap g -1 MMEGEN +ret 0 +end diff --git a/tests/dma_check.om b/tests/dma_check.om new file mode 100644 index 0000000..e385049 --- /dev/null +++ b/tests/dma_check.om @@ -0,0 +1,314 @@ +note Host-only owned DMA-window lifecycle checks. Combine with dma_replay.om, never production. +note No VFIO open, DMA, MMIO or device action. Production invalid-fd check is dma_badfd.om. +note WolframLanguageEvaluator endian vectors -> 72623859790382856, 84281096, 72057594037927944. +fn drcheck ok bool to void +if not ok +exit 1 +end +end +fn drfresh to ulong +drcheck eq mmwalloc 2147483648 1048576 MMOK +drcheck ne get mmwh 0 0 +drcheck ne get mmwcpu 0 0 +drcheck ne get mmwcpu 0 get mmwb 0 +ret get mmwgen 0 +end +fn drprep to void +drcheck eq mmasinit get mmwb 0 64 MMOK +drcheck eq gminit 4 add get mmwb 0 262144 128 8589934592 GMOK +end +fn drretained g ulong h long to void +drcheck eq get mmwst 0 MMWQUAR +drcheck eq get mmwh 0 h +drcheck eq mapaddr h get mmwcpu 0 +drcheck eq mmwclose g MMEBUSY +drcheck eq mmwinit 0 4096 MMEBUSY +drcheck eq get drdrops 0 0 +end +fn main to int +b = new uchar 2 0 +hs = new long 128 0 +if ne argcnt 2 +ret 2 +end +n = argread 1 b 0 2 +if ne n 1 +ret 2 +end +c = get b 0 +if eq c 119 +note w: exhaust only anonymous host mapping slots; allocation failure must not publish any state. +for i ulong 128 +v = mapnew -1 0 4096 3 33 +drcheck gt v 0 +put hs i v +end +drcheck eq mmwalloc 2147483648 4096 MMEIO +drcheck eq get mmwerr 0 -24 +drcheck eq get mmwst 0 MMWNONE +drcheck eq get mmwgen 0 0 +for i ulong 128 +drcheck eq mapdrop get hs i 0 +end +ret 0 +end +if eq c 108 +note l: validate before allocation, including epoch exhaustion and explicit simulator behavior. +drcheck eq mmwalloc 0 0 MMEINVAL +drcheck eq mmwalloc 1 4096 MMEALIGN +drcheck eq mmwalloc 0 4097 MMEALIGN +drcheck eq mmwalloc MMPALIM 4096 MMERANGE +drcheck eq mmwalloc sub MMPALIM 4096 8192 MMERANGE +put mmwgen 0 18446744073709551615 +drcheck eq mmwalloc 0 4096 MMEGEN +put mmwgen 0 0 +drcheck eq mmwinit 0 4096 MMOK +mmwr64 0 72623859790382856 +drcheck eq get mmwin 0 8 +drcheck eq mmrd64 0 72623859790382856 +drcheck eq mmwclose get mmwgen 0 MMOK +ret 0 +end +g = drfresh +h = get mmwh 0 +p = get mmwb 0 +if eq c 97 +note a: handle-backed CPU access never touches simulator array, with exact end and zero extent. +put mmwin 0 199 +mmwr64 p 72623859790382856 +drcheck eq mmrd64 p 72623859790382856 +drcheck eq get mmwin 0 199 +drcheck eq mapget h 0 4 84281096 +mmwr32 add p 16 287454020 +drcheck eq mmrd32 add p 16 287454020 +mmwr8 add p 24 99 +drcheck eq mapget h 24 4 99 +mmwr64 add p 32 72623859790382856 +mmzero add p 33 6 +drcheck eq mmrd64 add p 32 72057594037927944 +mmwr64 add p sub get mmws 0 8 42 +drcheck eq mmrd64 add p sub get mmws 0 8 42 +mmzero add p get mmws 0 0 +drcheck eq mmwclose g MMOK +drcheck eq mmwdmap g 17 MMEGEN +drcheck eq mmwalloc p 1048576 MMOK +drcheck ne get mmwgen 0 g +drcheck ne get mmwh 0 h +drcheck eq mmwclose get mmwgen 0 MMOK +ret 0 +end +if eq c 120 +note x: never-published buffers can be freed/reused without publishing a page-table root. +drprep +drcheck eq gmalloc 4096 1 0 GMOK +slot = get gmout 0 +drcheck eq gmfree slot GMOK +drcheck eq get mmwst 0 MMWOWN +drcheck eq gmalloc 4096 1 0 GMOK +drcheck eq get gmout 0 slot +drcheck eq gmfree slot GMOK +drcheck eq mmwclose g MMOK +ret 0 +end +if eq c 109 +note m: driver preflight itself rejects end+1 span, independent of compiler's second bounds check. +x = mmwoff add p sub get mmws 0 4 8 false +ret int x +end +if eq c 110 +note n: compiler rejects misaligned owned accesses. Expected trap 3. +x = mmrd64 add p 1 +ret int x +end +if eq c 111 +note o: stale handle rejected after successful owned drop. Expected trap 3. +drcheck eq mmwclose g MMOK +x = mapget h 0 8 +ret int x +end +if eq c 113 +note q: negative IOVA offset is refused before unsigned subtraction. Expected trap 3. +x = mmrd32 sub p 4 +ret int x +end +if eq c 114 +note r: overrun zero refuses before changing any memory. Expected trap 3. +mmzero add p sub get mmws 0 4 8 +ret 1 +end +if eq c 115 +note s: stale allocator and AS epochs refuse after a window is replaced. +drprep +drcheck eq gmalloc 4096 1 0 GMOK +old = get gmout 0 +drcheck eq mmwclose g MMOK +g = drfresh +drcheck not gmlive old +drcheck eq gmfree old GMESTATE +drcheck eq gmalloc 4096 1 0 GMESTATE +drcheck eq mmmap 8589934592 add p 262144 4096 MMSZ4K 0 0 MMEGEN +drcheck eq mmwclose g MMOK +ret 0 +end +if eq c 116 +note t: a successfully unmapped window whose mapdrop fails is retained, not forgotten. +put drdrc 0 -5 +drcheck eq mmwclose g MMEIO +drcheck eq get mmwh 0 h +drcheck eq get mmwst 0 MMWQUAR +drcheck eq get drdrops 0 1 +drcheck eq mmwclose g MMEBUSY +ret 0 +end +if eq c 100 +note d: a proven invalid fd never mapped anything and allows one clean retry. +put drmrc 0 -9 +drcheck eq mmwdmap g 17 MMEIO +drcheck eq get mmwst 0 MMWOWN +put drmrc 0 0 +end +if eq c 99 +note c: any unclassified mapping error is uncertain; do not speculative-unmap an overlapping range. +put drmrc 0 -22 +drcheck eq mmwdmap g 17 MMEIO +drretained g h +drcheck eq get drunmaps 0 0 +drcheck eq mmwdmap g 17 MMESTATE +ret 0 +end +if eq c 107 +drprep +gsinit p get mmws 0 +put gsi 5 1 +end +if or eq c 106 eq c 118 +drprep +drcheck eq gmalloc 4096 1 0 GMOK +end +drcheck eq mmwpublish g MMESTATE +drcheck eq mmwdmap add g 1 17 MMEGEN +if eq c 100 +drcheck eq get drmaps 0 1 +else +drcheck eq get drmaps 0 0 +end +drcheck eq mmwdmap g 17 MMOK +drcheck eq mmwdmap g 17 MMESTATE +drcheck eq get mmwfd 0 17 +if eq c 107 +note k: modelled register timeout quarantines; simulator completion is never an owned idle proof. +drcheck eq mminval 1 MMETIME +drretained g h +drcheck eq mmasinit p 64 MMEBUSY +drcheck eq gminit 4 add p 262144 128 8589934592 GMESTATE +ret 0 +end +if or eq c 106 eq c 118 +note j/v: map-before-publish, then no buffer reuse/reset/drop even with simulator mode zero. +drcheck eq mmwpublish g MMOK +drcheck eq mmwpublish g MMOK +drcheck eq mmasinit p 64 MMEBUSY +drcheck eq gminit 4 add p 262144 128 8589934592 GMESTATE +drcheck eq mmmap 8589934592 add p 262144 4096 MMSZ4K 0 0 MMEBUSY +drcheck eq gmalloc 4096 1 0 GMESTATE +if eq c 118 +note v: writes after quarantine are refused. Expected trap 9. +r = mmwquar g +mmwr32 p 1 +ret 1 +end +drcheck eq gmfree get gmout 0 GMETIME +drretained g h +drcheck eq gmcount GMQUAR 1 +ret 0 +end +if eq c 117 +note u: an owned channel cannot use the array simulator. Refusal exposes no DMA reference. +drprep +drcheck eq chcreate 0 1 0 8 CHEBIND +drcheck eq get mmwst 0 MMWDMA +put drusize 0 get mmws 0 +drcheck eq mmwclose g MMOK +ret 0 +end +if eq c 101 +put drurc 0 -5 +end +put drusize 0 get mmws 0 +if eq c 102 +put drusize 0 4096 +end +if eq c 103 +put drusize 0 0 +end +if eq c 104 +put drusize 0 add get mmws 0 4096 +end +if eq c 105 +put drdrc 0 -5 +end +if and ge c 101 le c 105 +drcheck eq mmwclose g MMEIO +if eq c 105 +drcheck eq get drdrops 0 1 +drcheck eq get mmwh 0 h +drcheck eq get mmwst 0 MMWQUAR +else +drretained g h +end +drcheck eq get drunmaps 0 1 +ret 0 +end +note b/d: full exact unmap must precede the sole successful drop. +drcheck eq mmwclose g MMOK +drcheck eq get drunmaps 0 1 +drcheck eq get drdrops 0 1 +drcheck eq get mmwst 0 MMWNONE +drcheck eq get mmwh 0 0 +ret 0 +end +fn drdma op ulong fd int h long iova ulong size ulong to long +if or ne h get mmwh 0 ne iova get mmwb 0 +exit 80 +end +if or ne size get mmws 0 ne mapaddr h get mmwcpu 0 +exit 81 +end +if ne fd 17 +exit 82 +end +if eq op 1 +if or ne get drlive 0 0 ne get mmwst 0 MMWOWN +exit 83 +end +put drmaps 0 add get drmaps 0 1 +r = get drmrc 0 +if eq r 0 +put drlive 0 1 +end +ret r +end +if or ne op 2 ne get drlive 0 1 +exit 84 +end +if ne get mmwst 0 MMWDMA +exit 85 +end +put drunmaps 0 add get drunmaps 0 1 +put mmduout 0 get drusize 0 +r = get drurc 0 +if and eq r 0 eq get drusize 0 size +put drlive 0 0 +end +ret r +end +fn drdrop h long to long +if or ne get drlive 0 0 ne h get mmwh 0 +exit 86 +end +put drdrops 0 add get drdrops 0 1 +if ne get drdrc 0 0 +ret get drdrc 0 +end +ret mapdrop h +end diff --git a/tests/dma_host.sh b/tests/dma_host.sh new file mode 100755 index 0000000..9411bd9 --- /dev/null +++ b/tests/dma_host.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# Host verification only. No device open, VFIO release/reset, DMA or hardware MMIO. +# Production .om is tested with anonymous memory + invalid fd; DMA success/error is explicit replay. +set -u +here=$(cd "$(dirname "$0")/.." && pwd) +OMC=${OMC:-$here/build/omc} +want=bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6 +got=$(sha256sum "$OMC" | cut -d' ' -f1) +[ "$got" = "$want" ] || { echo "dma_host: wrong compiler $got"; exit 2; } +t=$(mktemp -d /tmp/dma_host.XXXXXX) || exit 2 +trap 'rm -rf "$t"' EXIT +run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; } +build() { + transport=$1; gmmu=$2; mem=$3; main=$4; out=$5 + cat "$transport" "$gmmu" "$mem" "$here/chan/chan.om" "$here/chan/sim.om" "$main" | run "$OMC" > "$out" || return 2 + chmod +x "$out" +} +check() { + prog=$1; mode=$2; expected=$3 + run "$prog" "$mode" > "$t/run.log" 2>&1; rc=$? + if [ "$rc" -ne "$expected" ]; then + echo "dma_host: mode $mode returned $rc, expected $expected" + cat "$t/run.log" + return 1 + fi +} +build "$here/tests/dma_replay.om" "$here/chan/gmmu.om" "$here/chan/mem.om" "$here/tests/dma_check.om" "$t/replay" || exit 2 +for mode in a b c d e f g h i j k l s t u w x; do + check "$t/replay" "$mode" 0 || exit 1 +done +for mode in m n o q r; do check "$t/replay" "$mode" 103 || exit 1; done +for mode in v; do check "$t/replay" "$mode" 109 || exit 1; done +build "$here/chan/dma.om" "$here/chan/gmmu.om" "$here/chan/mem.om" "$here/tests/dma_badfd.om" "$t/badfd" || exit 2 +run "$t/badfd" || { echo 'dma_host: real invalid-fd refusal failed'; exit 1; } +sha256sum "$here/chan/dma.om" "$here/chan/gmmu.om" "$here/chan/mem.om" "$here/chan/chan.om" "$here/tests/dma_check.om" "$t/replay" "$t/badfd" +echo 'dma_host: 23 replay/boundary cases and real invalid-fd retry/drop PASS' +# Scoped whole-line mutants must still compile and must break the same behavior check. +cat > "$t/mutants" <<'EOF' +gmmu|mmrd64|ret mapget get mmwh 0 o 8|ret 0|a|0 +gmmu|mmwdmap|r = mmdmaop 1 fd get mmwh 0 get mmwb 0 get mmws 0|r = mmdmaop 1 fd get mmwh 0 add get mmwb 0 4096 get mmws 0|b|0 +gmmu|mmwclose|if eq get mmwst 0 MMWDMA|if eq get mmwst 0 MMWPUB|b|0 +gmmu|mmwclose|if or ne r 0 ne get mmduout 0 get mmws 0|if ne r 0|f|0 +gmmu|mmwpublish|if ne get mmwst 0 MMWDMA|if eq get mmwst 0 MMWNONE|b|0 +gmmu|mmwclose|if not mmwmutable|if eq get mmwst 0 MMWNONE|j|0 +gmmu|mmwoff|if gt n sub s o|if eq n 0|m|103 +mem|gmretire|if not mmwmutable|if eq get mmwst 0 MMWNONE|j|0 +gmmu|mminval|r = mmwquar get mmwgen 0|r = MMOK|k|0 +gmmu|mmwdmap|if not mmwepoch gen|if eq gen 0|b|0 +gmmu|mmwclose|if ne r 0|if eq r 1|i|0 +EOF +killed=0 +while IFS='|' read -r unit fn old new mode expected; do + src=$here/chan/$unit.om + awk -v fn="$fn" -v old="$old" -v new="$new" ' + /^fn / { active = ($2 == fn) } + active && $0 == old { print new; count++; next } + { print } + END { if (count != 1) exit 1 } + ' "$src" > "$t/mutant.om" || { echo "dma_host: INVALID mutant $fn:$old"; exit 2; } + gmmu=$here/chan/gmmu.om; mem=$here/chan/mem.om + case $unit in gmmu) gmmu=$t/mutant.om ;; mem) mem=$t/mutant.om ;; esac + build "$here/tests/dma_replay.om" "$gmmu" "$mem" "$here/tests/dma_check.om" "$t/mutant" || { echo "dma_host: INVALID noncompiling mutant $fn"; exit 2; } + if check "$t/mutant" "$mode" "$expected" > "$t/mutant.log" 2>&1; then + echo "dma_host: SURVIVED mutant $fn:$old"; exit 1 + fi + killed=$((killed + 1)) +done < "$t/mutants" +echo "dma_host: $killed compiled ownership/order/range/error mutants killed; hardware NOT_RUN" diff --git a/tests/dma_replay.om b/tests/dma_replay.om new file mode 100644 index 0000000..d8ad486 --- /dev/null +++ b/tests/dma_replay.om @@ -0,0 +1,18 @@ +note TEST ONLY link-time replacement for chan/dma.om; never a production fallback. +note Real anonymous mapnew/mapget/mapset/mapdrop remain active. No device fd is opened or used. +note Reject tuple/order mismatches so replay cannot silently bless a missing lifecycle call. +global mmduout ulong 1 +global drmaps ulong 1 +global drunmaps ulong 1 +global drdrops ulong 1 +global drlive ulong 1 +global drmrc long 1 +global drurc long 1 +global drdrc long 1 +global drusize ulong 1 +fn mmdmaop op ulong fd int h long iova ulong size ulong to long +ret drdma op fd h iova size +end +fn mmdrop h long to long +ret drdrop h +end diff --git a/tests/gsp-host-receipt.txt b/tests/gsp-host-receipt.txt new file mode 100644 index 0000000..8971638 --- /dev/null +++ b/tests/gsp-host-receipt.txt @@ -0,0 +1,46 @@ +GSP boot/RPC host receipt. HOST_EXERCISED only. Hardware/kernel execution NOT_RUN. +Platform: Linux 7.0.0-1019-nvidia aarch64 GNU/Linux. +Compiler: omega-mv397e67040fb74853c6814097fe02ae4e1ebd6f66 (pending #890 atop #878). +omc SHA256 bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6. +Reference: aienuxc5bb3a4b9898257658aba0b7178a3c73a0371c27 native/kernel/dev/gb10_gsp_boot.{c,h}. +Vendor: open-gpu-kernel-modules20e4e6e19cc26ba47b5cbe23130a396be100c427, tag580.173.02. +Oracle compiler: cc Ubuntu13.3.0-6ubuntu2~24.04.1. Comparison/mutant coordinator Python3.12.3. + +Commands (OMC is the exact pinned binary; AIENUX the clean exact reference checkout): +OMC=$OMC AIENUX=$AIENUX sh tests/mutants-rpc.sh +OMC=$OMC AIENUX=$AIENUX sh tests/mutants-arena.sh +Both run their baseline exact parity gate before their mutants. Both exited0. + +Observed RPC baseline: +rpc_diff: PASS exact command frames and boot/RPC transition controls; hardware NOT_RUN +Composed source SHA256 aa763b15e332594f599ad8bb3fb215d8bff2666d459fe2c36970971d0dc4ad91 +Omega binary SHA256 e792fb1deb9cec201db10cd4c1cf88ad8dfed87ee94af0b9291908c0b14c20d4 +C referee binary SHA256 412d98e3b9119969783cc2b508ca1f01b4fed4da4a171739b0bedc9cc8f2ef8b +Exact command frame stream SHA256 d0cd7fc50db7dba9aa0e6eecaa40460fe464a9f115da0c49cffc4a42dc66f607 +All19 mutants DETECTED: swaprx checksum rxseq padding version timeout correlation guest seqtoken seqgen handlerstatus pending allocflags ctrlflags freeparent linkwait headerstatus routing noncc. +mutants-rpc: PASS all behavior controls detected; hardware NOT_RUN + +Observed arena baseline: +arena_diff: PASS exact arena bytes, plan, COT, preboot attach/INIT_DONE seam and negative refusals; hardware NOT_RUN +Composed source SHA256 a4946df17176c8eb18f957b83d7bc14f388700caa8c0e48c58fe6c529e001ec8 +Omega binary SHA256 1e3ccef091e2f92edee85b9a886c557114c14b6b8a44d8a0b85bf63169a257d5 +C referee binary SHA256 6918316ef89b74caa34a47e50b1759a2d249e6f78198aeb5a0f4d467ba1f2371 +Five exact full-image cases (0..4);31 refusal cases (10..40), C and Omega return3 with empty output. +All12 mutants DETECTED: radix logpte sharedpte wprheap signature cotfmc cotargs preboot profile registry dma heapdma. +mutants-arena: PASS behavior-only controls; hardware NOT_RUN +Compiler/setup errors and unexpected traps were INVALID, never counted as detected mutants. + +Review decisions exercised: +Read-only protocol review required actual alignment padding checks and whole-slot capture. Those checks now have independent mutants. Review also identified pending-sentinel completion, flat encoding flags, FREE parent, prelink polling and stale header-error status; each now has a behavior control/mutant. +Correction: an early review suggestion interpreted rpc_result_private as version metadata. Exact vendor rpc.c:8764 instead enters the failure branch for nonzero NV_STATUS; implementation requires zero and rejects renegotiation. No version/status claim is inferred from that review. +Read-only compiler review: 'Flatten expressions by reassigning one temporary'; retained small whole-loop helpers, not a helper call per byte. Dynamic for-loop fuel is1000000 at this pin; large arena zero/copy and synthetic input loops are page-chunked, not silently truncated to evade the radix case. + +Protocol authority read before driver changes: +message_queue_cpu.c:565-576: 'a store fence is needed here', portAtomicMemoryFenceStore before msgqTxSubmitBuffers. +message_queue_cpu.c:347-369 waits for peer msgqInit before linking the status queue. +g_rpc-structures.h:1491-1518 specifies alloc/control flags and reserved fields; rpc.c:11194-11228 excludes RM_ALLOC tail params from the logical checksum length. +No publication/acquire hardware transport or barrier is implemented by these host arrays. No device/VFIO open, MMIO, DMA submission, firmware execution, module unload/load, service, gate or trust change occurred. + +Arithmetic authority: +WolframLanguageEvaluator: {FromDigits["43505256",16],FromDigits["03000000",16],65536-48-32,65536-48,4096-80-32,6*4+3*256} -> {1129337430,50331648,65456,65488,3984,792}. +Additional arena constants are quoted with their Wolfram queries beside the constants in gsp/arena.om. diff --git a/tests/mutants-arena.sh b/tests/mutants-arena.sh new file mode 100755 index 0000000..33de54f --- /dev/null +++ b/tests/mutants-arena.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Mutants exist only in temporary copies. A compile refusal or runtime trap is INVALID, not detection. +set -eu +R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) +sh "$R/tests/arena_diff.sh" +python3 - "$R" <<'PY' +import os, pathlib, subprocess, sys, tempfile +r=pathlib.Path(sys.argv[1]); original=(r/'gsp/arena.om').read_text() +mutants=[ + ('radix','add araddr 11 add get arlvl add i 1 mul j 4096','add araddr 11 add get arlvl add i 1 mul j 4097'), + ('logpte','v = add a mul j 4096','v = add a mul j 4097'), + ('sharedpte','add araddr 10 mul i 4096 8','add araddr 10 mul i 4097 8'), + ('wprheap','shl ulong 133 20','shl ulong 132 20'), + ('signature','and add get arslen 1 255 not ulong 255','and add get arslen 1 127 not ulong 127'), + ('cotfmc','arcput 28 get arslen 3 4','arcput 28 get arslen 2 4'), + ('cotargs','arcput 860 araddr 15 8','arcput 860 araddr 9 8'), + ('preboot','rqsend 72 936 936 false','rqsend 73 936 936 false'), + ('profile','ne get arcfg 0 1','false'), + ('registry','if ne arreg32 0 n','if false'), + ('dma','if not ardma get arbase 0 get arused 0','if false'), + ('heapdma','if not ardma get arcfg 2 get arcfg 3','if false'), +] +with tempfile.TemporaryDirectory(prefix='arena-mutants.') as tmp: + for name,old,new in mutants: + if original.count(old)!=1: sys.exit('mutants-arena: INVALID match '+name) + f=pathlib.Path(tmp)/(name+'.om'); f.write_text(original.replace(old,new)) + env=dict(os.environ,ARENA_OM=str(f)) + q=subprocess.run(['sh',str(r/'tests/arena_diff.sh')],env=env,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True) + detected=('arena_diff: FAIL exact arena/COT' in q.stdout or 'arena_diff: FAIL negative accepted' in q.stdout) + if q.returncode==0 or not detected: + print(q.stdout);sys.exit('mutants-arena: '+('SURVIVED ' if q.returncode==0 else 'INVALID ')+name) + print('mutants-arena: DETECTED '+name) +print('mutants-arena: PASS behavior-only controls; hardware NOT_RUN') +PY diff --git a/tests/mutants-complete.sh b/tests/mutants-complete.sh new file mode 100755 index 0000000..7ebf6b1 --- /dev/null +++ b/tests/mutants-complete.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# tests/mutants-complete.sh: single-line mutants of chan/complete.om. +# Each mutant must compile and fail tests/complete_diff.sh (killed). +set -u +here=$(cd "$(dirname "$0")/.." && pwd) +t=$(mktemp -d /tmp/mutants-complete.XXXXXX) || exit 2 +trap 'rm -rf "$t"' EXIT +run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; } + +if ! sh "$here/tests/complete_diff.sh" > "$t/base.log" 2>&1; then + cat "$t/base.log"; echo "mutants-complete: FAIL baseline is not green"; exit 2 +fi + +cat <<'EOF' > "$t/list" +header method offset mutated|const CMSEMM uint 23|const CMSEMM uint 24 +release execute operation mutated to acquire|put cmwds 5 1|put cmwds 5 0 +address alignment check bypassed|if ne and va 3 0|if false +progress check operator flipped|if gt prog inflight|if ge prog inflight +stale observation accepted as pending|ret CMESTALE|ret 0 +capability check for DMA window bypassed|if or lt get mmwst 0 MMWDMA ge get mmwst 0 MMWQUAR|if false +quarantine on timeout skipped|r = gmquar b|r = GMOK +cmsub overcapacity check bypassed|if gt count sub sub ent 1 inflight|if false +EOF + +killed=0; survived=0; invalid=0; total=0 +while IFS='|' read -r desc orig mut; do + total=$((total + 1)) + mfile="$t/mut_$total.om" + if ! grep -qF "$orig" "$here/chan/complete.om"; then + echo "mutants-complete: INVALID pattern '$orig'"; invalid=$((invalid + 1)); continue + fi + sed "s/$orig/$mut/" "$here/chan/complete.om" > "$mfile" + if cmp -s "$mfile" "$here/chan/complete.om"; then + echo "mutants-complete: INVALID identical mutation '$desc'"; invalid=$((invalid + 1)); continue + fi + if COMPLETE_OM="$mfile" sh "$here/tests/complete_diff.sh" > "$t/run.log" 2>&1; then + echo "mutants-complete: SURVIVED mutant '$desc'"; survived=$((survived + 1)) + else + rc=$? + if [ "$rc" -eq 1 ]; then + echo "mutants-complete: KILLED mutant '$desc'" + killed=$((killed + 1)) + else + echo "mutants-complete: INVALID mutant '$desc' exit $rc" + cat "$t/run.log" + invalid=$((invalid + 1)) + fi + fi +done < "$t/list" + +echo "mutants-complete: $total total, $killed killed, $survived survived, $invalid invalid" +if [ "$survived" -gt 0 ] || [ "$invalid" -gt 0 ]; then + exit 1 +fi +echo "mutants-complete: PASS all mutants killed; hardware NOT_RUN" diff --git a/tests/mutants-rmchan.sh b/tests/mutants-rmchan.sh new file mode 100755 index 0000000..66b7643 --- /dev/null +++ b/tests/mutants-rmchan.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# tests/mutants-rmchan.sh: single-line mutants of chan/rmchan.om. +# Each mutant must compile and fail tests/rmchan_diff.sh (killed). +set -u +here=$(cd "$(dirname "$0")/.." && pwd) +t=$(mktemp -d /tmp/mutants-rmchan.XXXXXX) || exit 2 +trap 'rm -rf "$t"' EXIT +run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; } + +if ! sh "$here/tests/rmchan_diff.sh" > "$t/base.log" 2>&1; then + cat "$t/base.log"; echo "mutants-rmchan: FAIL baseline is not green"; exit 2 +fi + +cat <<'EOF' > "$t/list" +schedule enable command mutated to disable|r = pasched 1 0 0|r = pasched 0 0 0 +schedule disable command mutated to enable|r = pasched 0 0 0|r = pasched 1 0 0 +TSG allocation class mutated|r = brmalloc get rmhcli 0 get rmhdev 0 get rmhtsg 0 PACTSG b|r = brmalloc get rmhcli 0 get rmhdev 0 get rmhtsg 0 PACVAS b +channel allocation parent mutated|r = brmalloc get rmhcli 0 get rmhdev 0 get rmhchan 0 PACGPF b|r = brmalloc get rmhcli 0 get rmhtsg 0 get rmhchan 0 PACGPF b +free sequence inverted|r = brmfree get rmhcli 0 get rmhctx 0 b|r = brmfree get rmhcli 0 get rmhtsg 0 b +rebinding retained RM slot permitted|if or ne get rmst 0 RMSIDLE ne get rmepoch 0 0|if false +RM free before semaphore drain permitted|if ne st RMSDRND|if false +publication active state check bypassed|if ne get rmst 0 RMSACTV|if false +submission stale release sequence accepted|if ne uint mmrd32 add va mul i 4 get cmwds i|if false +schedule ACK leaves channel only prepared|put chopen get rmslot 0 1|note no activation +RM bind accepts a channel that is not prepared|if or ne get chopen c 2 ne get chepoch c gen|if ne get chepoch c gen +EOF + +killed=0; survived=0; invalid=0; total=0 +while IFS='|' read -r desc orig mut; do + total=$((total + 1)) + mfile="$t/mut_$total.om" + if ! grep -qF "$orig" "$here/chan/rmchan.om"; then + echo "mutants-rmchan: INVALID pattern '$orig'"; invalid=$((invalid + 1)); continue + fi + sed "s/$orig/$mut/" "$here/chan/rmchan.om" > "$mfile" + if cmp -s "$mfile" "$here/chan/rmchan.om"; then + echo "mutants-rmchan: INVALID identical mutation '$desc'"; invalid=$((invalid + 1)); continue + fi + if RMCHAN_OM="$mfile" sh "$here/tests/rmchan_diff.sh" > "$t/run.log" 2>&1; then + echo "mutants-rmchan: SURVIVED mutant '$desc'"; survived=$((survived + 1)) + else + rc=$? + if [ "$rc" -eq 1 ]; then + echo "mutants-rmchan: KILLED mutant '$desc'" + killed=$((killed + 1)) + else + echo "mutants-rmchan: INVALID mutant '$desc' exit $rc" + cat "$t/run.log" + invalid=$((invalid + 1)) + fi + fi +done < "$t/list" + +echo "mutants-rmchan: $total total, $killed killed, $survived survived, $invalid invalid" +if [ "$survived" -gt 0 ] || [ "$invalid" -gt 0 ]; then + exit 1 +fi +echo "mutants-rmchan: PASS all mutants killed; hardware NOT_RUN" diff --git a/tests/mutants-rpc.sh b/tests/mutants-rpc.sh new file mode 100755 index 0000000..bb994a9 --- /dev/null +++ b/tests/mutants-rpc.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# Mutation controls are test-only copies; no production source or historical receipt is rewritten. +set -eu +R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) +t=$(mktemp -d /tmp/rpc-mutants.XXXXXX) +trap 'rm -rf "$t"' EXIT HUP INT TERM +sh "$R/tests/rpc_diff.sh" +mutate() { + name=$1; source=$2; pattern=$3; replacement=$4 + sed "s|$pattern|$replacement|" "$source" > "$t/$name.om" + if cmp -s "$source" "$t/$name.om"; then echo "mutant $name INVALID no change"; exit 2; fi + if [ "$source" = "$R/gsp/rpc.om" ]; then + if RPC_OM="$t/$name.om" sh "$R/tests/rpc_diff.sh" > "$t/$name.log" 2>&1; then cat "$t/$name.log"; echo "mutant $name SURVIVED"; exit 1; fi + else + if BOOT_OM="$t/$name.om" sh "$R/tests/rpc_diff.sh" > "$t/$name.log" 2>&1; then cat "$t/$name.log"; echo "mutant $name SURVIVED"; exit 1; fi + fi + # Compiler/setup refusal is not a detected behavioral mutant. + if ! grep -q 'rpc_diff: FAIL replay exit 101\|rpc_diff: FAIL exact frames' "$t/$name.log"; then + cat "$t/$name.log"; echo "mutant $name INVALID build/setup or unexpected trap"; exit 2 + fi + echo "mutant $name DETECTED" +} +mutate swaprx "$R/gsp/rpc.om" 'rd = rqget32 1 32' 'rd = rqget32 0 32' +mutate checksum "$R/gsp/rpc.om" 'rqput32 2 32 rqsum 2 mul div add add 80 n 7 8 8' 'rqput32 2 32 0' +mutate rxseq "$R/gsp/rpc.om" 'if ne rqget32 2 36 ulong get rqrx 0' 'if false' +mutate padding "$R/gsp/rpc.om" 'if ne rqsum 2 aligned 0' 'if false' +mutate version "$R/gsp/rpc.om" 'if or ne rqget32 2 48 RQVER ne rqget32 2 52 RQSIG' 'if false' +mutate timeout "$R/gsp/boot.om" 'ret bfail -11' 'ret 0' +mutate correlation "$R/gsp/boot.om" 'if not bcorrel' 'if false' +mutate guest "$R/gsp/boot.om" 'if ne get rqpriv 0 0' 'if false' +mutate seqtoken "$R/gsp/boot.om" 'if ne token get btoken 0' 'if false' +mutate seqgen "$R/gsp/boot.om" 'if ne gen get bgen 0' 'if false' +mutate handlerstatus "$R/gsp/boot.om" 'if ne get bresult 0 0' 'if false' +mutate pending "$R/gsp/boot.om" 'if eq get rqres 0 RQU32' 'if false' +mutate allocflags "$R/gsp/boot.om" 'if or ne rqget32 3 104 0 ne rqget32 3 108 0' 'if false' +mutate ctrlflags "$R/gsp/boot.om" 'if or ne rqget32 3 100 0 or ne rqget32 3 112 0 ne rqget32 3 116 0' 'if false' +mutate freeparent "$R/gsp/boot.om" 'if ne rqget32 3 84 0' 'if false' +mutate linkwait "$R/gsp/rpc.om" 'if eq get rqlink 0 0' 'if false' +mutate headerstatus "$R/gsp/boot.om" 'put bresult 0 get rqres 0' 'put bresult 0 0' +mutate routing "$R/gsp/rpc.om" 'if or ne rqget32 2 44 0 ne rqget32 2 76 0' 'if false' +mutate noncc "$R/gsp/rpc.om" 'if ne get rqtmp i 0' 'if false' +echo 'mutants-rpc: PASS all behavior controls detected; hardware NOT_RUN' diff --git a/tests/rmchan_diff.sh b/tests/rmchan_diff.sh new file mode 100755 index 0000000..053fe97 --- /dev/null +++ b/tests/rmchan_diff.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# tests/rmchan_diff.sh: builds the .om RM channel trace (gsp/rpc.om + gsp/sysinfo.om + chan/params.om + +# gsp/boot.om + chan/dma.om + chan/gmmu.om + chan/mem.om + chan/chan.om + chan/sim.om + chan/complete.om + +# chan/rmchan.om + tests/rmchan_trace.om) and the C reference trace tests/rmchan_ref.c (compiled fresh +# against NVIDIA open-gpu-kernel-modules 580.173.02 headers) and requires byte-identical stdout. Host only. +set -u +here=$(cd "$(dirname "$0")/.." && pwd) +OMC=${OMC:-$here/build/omc} +RMCHAN_OM=${RMCHAN_OM:-$here/chan/rmchan.om} +OGKM_SRC=${OGKM_SRC:-/home/drakestapleton/workspace/_ext/open-gpu-kernel-modules-580.173.02/src} +RMCHAN_REF=${RMCHAN_REF:-} +OMC_SHA=$(sed -n 's/^OMC_SHA256=//p' "$here/tools/omc.pin") +run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; } + +got=$(sha256sum "$OMC" | cut -d' ' -f1) +if [ "$got" != "$OMC_SHA" ]; then + echo "rmchan_diff: FAIL omc sha256 $got, pinned $OMC_SHA"; exit 2 +fi + +t=$(mktemp -d /tmp/rmchan_diff.XXXXXX) || exit 2 +trap 'rm -rf "$t"' EXIT + +if [ -n "$RMCHAN_REF" ]; then + [ -s "$RMCHAN_REF" ] || { echo "rmchan_diff: FAIL RMCHAN_REF $RMCHAN_REF missing or empty"; exit 2; } + cp "$RMCHAN_REF" "$t/c.txt" || exit 2 +else + S=$OGKM_SRC + if ! run cc -std=c11 -O1 -Wall -Werror \ + -I"$S/common/sdk/nvidia/inc" -I"$S/nvidia/arch/nvalloc/common/inc" -I"$S/common/uproc/os/common/include" \ + -I"$S/nvidia/inc/kernel" -I"$S/nvidia/inc" -I"$S/nvidia/generated" -I"$S/common/shared/msgq/inc" \ + -I"$S/nvidia/interface" -I"$S/common/inc" -o "$t/cref" "$here/tests/rmchan_ref.c"; then + echo "rmchan_diff: FAIL C reference build"; exit 2 + fi + run "$t/cref" > "$t/c.txt" || { echo "rmchan_diff: FAIL C reference run"; exit 2; } +fi + +if ! cat "$here/gsp/rpc.om" "$here/gsp/replay.om" "$here/gsp/sysinfo.om" "$here/chan/params.om" "$here/gsp/boot.om" \ + "$here/chan/dma.om" "$here/chan/gmmu.om" "$here/chan/mem.om" "$here/chan/chan.om" \ + "$here/chan/sim.om" "$here/chan/complete.om" "$RMCHAN_OM" "$here/tests/rmchan_trace.om" \ + | run "$OMC" > "$t/omtrace"; then + echo "rmchan_diff: FAIL omc build"; exit 3 +fi +chmod +x "$t/omtrace" +run "$t/omtrace" > "$t/om.txt" +rc=$? +if [ "$rc" -ne 0 ]; then + echo "rmchan_diff: FAIL om trace exit $rc"; exit 1 +fi +n=$(wc -l < "$t/c.txt") +if [ "$n" -eq 0 ]; then + echo "rmchan_diff: FAIL empty C trace"; exit 2 +fi +if ! cmp -s "$t/c.txt" "$t/om.txt"; then + echo "rmchan_diff: FAIL traces differ ($(diff "$t/c.txt" "$t/om.txt" | grep -c '^[<>]') differing lines; C $n lines, om $(wc -l < "$t/om.txt"))" + exit 1 +fi +echo "rmchan_diff: PASS ($n lines identical, .om vs C reference)" diff --git a/tests/rmchan_ref.c b/tests/rmchan_ref.c new file mode 100644 index 0000000..a4bfaa6 --- /dev/null +++ b/tests/rmchan_ref.c @@ -0,0 +1,64 @@ +/* Verification-only oracle. Never linked into driver; headers are NVIDIA + * open-gpu-kernel-modules 580.173.02@20e4e6e19cc26ba47b5cbe23130a396be100c427. + * Checks observed RM transitions and queued request identity, class, size, + * schedule flags, and free order. Parameter bytes have the existing params oracle. + * Policy error values and host peer semaphore progress are not hardware evidence. */ +#include +#include +#include "nvtypes.h" +#include "nvmisc.h" +#include "class/cl0000.h" +#include "class/cl0080.h" +#include "class/cl2080.h" +#include "class/cl90f1.h" +#include "class/cla06c.h" +#include "class/cl9067.h" +#include "class/clc96f.h" +#include "nvos.h" +#include "alloc/alloc_channel.h" +#include "ctrl/ctrla06c.h" +#include "ctrl/ctrla06f/ctrla06fgpfifo.h" +#include "vgpu/rpc_global_enums.h" +static const uint32_t cli=3254779905u, dev=3254779906u, sub=3254779907u, + vas=3254779912u, tsg=3254779913u, ctx=3254779914u, ch=3254779915u; +static void step(int id, int state, unsigned f, int rc) +{ printf("step %d state=%d fn=%u rc=%d\n",id,state,f,rc); } +static void cap(int id,int rc) { printf("cap %d rc=%d\n",id,rc); } +static void alloc(uint32_t par,uint32_t obj,uint32_t cls,size_t n) +{ printf("req %u cli=%u par=%u obj=%u cls=%u n=%zu\n", + NV_VGPU_MSG_FUNCTION_GSP_RM_ALLOC,cli,par,obj,cls,n); } +static void sched(NvBool en) +{ NVA06C_CTRL_GPFIFO_SCHEDULE_PARAMS p={0}; p.bEnable=en; + printf("req %u cli=%u obj=%u cls=%u en=%u\n", + NV_VGPU_MSG_FUNCTION_GSP_RM_CONTROL,cli,tsg, + NVA06C_CTRL_CMD_GPFIFO_SCHEDULE,(unsigned)p.bEnable); } +static void freeobj(uint32_t obj) +{ printf("req %u cli=%u obj=%u\n",NV_VGPU_MSG_FUNCTION_FREE,cli,obj); } +int main(void) +{ + cap(30,-1); cap(31,-10); cap(29,-5); cap(32,0); cap(33,-3); cap(34,-4); cap(35,-3); + step(1,1,NV_VGPU_MSG_FUNCTION_GSP_RM_ALLOC,0); + puts("seq 1 rc=2 st=11"); puts("seq 2 rc=2 st=11"); + puts("seq 3 rc=-10 st=11"); puts("seq 4 rc=0 st=10"); + alloc(0,cli,NV01_ROOT,sizeof(NV0000_ALLOC_PARAMETERS)); step(2,2,NV_VGPU_MSG_FUNCTION_GSP_RM_ALLOC,1); + alloc(cli,dev,NV01_DEVICE_0,sizeof(NV0080_ALLOC_PARAMETERS)); step(3,3,NV_VGPU_MSG_FUNCTION_GSP_RM_ALLOC,1); + alloc(dev,sub,NV20_SUBDEVICE_0,sizeof(NV2080_ALLOC_PARAMETERS)); step(4,4,NV_VGPU_MSG_FUNCTION_GSP_RM_ALLOC,1); + alloc(dev,vas,FERMI_VASPACE_A,sizeof(NV_VASPACE_ALLOCATION_PARAMETERS)); step(5,5,NV_VGPU_MSG_FUNCTION_GSP_RM_ALLOC,1); + alloc(dev,tsg,KEPLER_CHANNEL_GROUP_A,sizeof(NV_CHANNEL_GROUP_ALLOCATION_PARAMETERS)); step(6,6,NV_VGPU_MSG_FUNCTION_GSP_RM_ALLOC,1); + alloc(tsg,ctx,FERMI_CONTEXT_SHARE_A,sizeof(NV_CTXSHARE_ALLOCATION_PARAMETERS)); step(7,7,NV_VGPU_MSG_FUNCTION_GSP_RM_ALLOC,1); + alloc(dev,ch,BLACKWELL_CHANNEL_GPFIFO_A,sizeof(NV_CHANNEL_ALLOC_PARAMS)); step(8,8,0,1); + step(9,9,NV_VGPU_MSG_FUNCTION_GSP_RM_CONTROL,0); sched(1); step(10,10,0,1); + cap(36,-1); cap(37,-1); cap(38,-3); cap(39,0); cap(40,-5); + step(11,11,NV_VGPU_MSG_FUNCTION_GSP_RM_CONTROL,0); cap(41,-3); + sched(0); step(12,12,0,1); cap(42,-3); + step(13,14,NV_VGPU_MSG_FUNCTION_FREE,0); + freeobj(ch); step(14,15,NV_VGPU_MSG_FUNCTION_FREE,1); + freeobj(ctx); step(15,16,NV_VGPU_MSG_FUNCTION_FREE,1); + freeobj(tsg); step(16,17,NV_VGPU_MSG_FUNCTION_FREE,1); + freeobj(vas); step(17,18,NV_VGPU_MSG_FUNCTION_FREE,1); + freeobj(sub); step(18,19,NV_VGPU_MSG_FUNCTION_FREE,1); + freeobj(dev); step(19,20,NV_VGPU_MSG_FUNCTION_FREE,1); + freeobj(cli); step(20,21,0,1); + cap(43,-3); cap(44,-3); cap(45,0); cap(46,-3); cap(47,-4); + return 0; +} diff --git a/tests/rmchan_trace.om b/tests/rmchan_trace.om new file mode 100644 index 0000000..dd55793 --- /dev/null +++ b/tests/rmchan_trace.om @@ -0,0 +1,286 @@ +note HOSTMODEL only: anonymous mapping, simulated GSP peer and memory semaphore. +note Output observes queued request headers, RM states, and caller-visible errors. +note No device, VFIO, DMA mapping, engine idle, cache coherency, or backing release is claimed. +text rtfrag "step | state=| fn=| rc=|seq | st=|cap |req | cli=| par=| obj=| cls=| n=| en=" +global outbuf uchar 1 +global digs uchar 24 +global rtret long 1 +global rtpb ulong 1 +global rtsem ulong 1 +fn prch c uchar to void +put outbuf 0 c +r = write 1 outbuf 0 1 +end +fn prstr k ulong to void +w = ulong 0 +for i ulong len rtfrag +c = get rtfrag i +if eq c 124 +w = add w 1 +else +if eq w k +prch c +end +end +end +end +fn prdec v long to void +if lt v 0 +prch 45 +v = sub 0 v +end +if eq v 0 +prch 48 +ret +end +cnt = ulong 0 +x = ulong v +while gt x 0 bound 24 +put digs cnt uchar add rem x 10 48 +cnt = add cnt 1 +x = div x 10 +end +for i ulong cnt +prch get digs sub sub cnt 1 i +end +end +fn ck r long want long to void +if ne r want +exit 1 +end +end +fn prstep id long rc long to void +prstr 0 +prdec id +prstr 1 +prdec long get rmst 0 +prstr 2 +f = ulong 0 +if eq get bstate 0 10 +f = get bfunc 0 +end +prdec long f +prstr 3 +prdec rc +prch 10 +end +fn prseq id long rc long to void +prstr 4 +prdec id +prstr 3 +prdec rc +prstr 5 +prdec long get bstate 0 +prch 10 +end +fn prcap id long rc long to void +prstr 6 +prdec id +prstr 3 +prdec rc +prch 10 +end +fn prreq to void +note Read request queue bytes, not mutable bhead or expected literals. +wr = rqget32 0 16 +slot = rem add wr 62 63 +o = add 4096 mul slot 4096 +f = rqget32 0 add o 60 +prstr 7 +prdec long f +prstr 8 +prdec long rqget32 0 add o 80 +if eq f 103 +prstr 9 +prdec long rqget32 0 add o 84 +prstr 10 +prdec long rqget32 0 add o 88 +prstr 11 +prdec long rqget32 0 add o 92 +prstr 12 +prdec long rqget32 0 add o 100 +end +if eq f 76 +prstr 10 +prdec long rqget32 0 add o 84 +prstr 11 +prdec long rqget32 0 add o 88 +prstr 13 +prdec long get rqcmd add o 120 +ck long get rqcmd add o 121 0 +ck long get rqcmd add o 122 0 +end +if eq f 10 +prstr 10 +prdec long rqget32 0 add o 88 +end +prch 10 +end +fn tf f ulong n ulong seq ulong to void +for i ulong mul div add n 4175 4096 4096 +put rqtmp i 0 +end +rqput32 2 36 ulong get rqrx 0 +rqput32 2 40 div add n 4175 4096 +rqput32 2 48 RQVER +rqput32 2 52 RQSIG +rqput32 2 56 add 32 n +rqput32 2 60 f +rqput32 2 72 seq +for i ulong n +put rqtmp add 80 i get rqpay i +end +rqput32 2 32 rqsum 2 mul div add n 87 8 8 +wr = rqget32 1 16 +e = div add n 4175 4096 +for i ulong mul e 4096 +o = rem add wr div i 4096 63 +o = add 4096 mul o 4096 +o = add o rem i 4096 +put rqstat o get rqtmp i +end +rqput32 1 16 rem add wr e 63 +end +fn bootinit to void +ck breset 0 +ck bsys 0 +ck breg 0 0 +ck bstart 40 128 0 +rqpeer +rqclear 0 +tf 4097 0 0 +ck bpoll 1 +rqclear 792 +rqput32 4 0 1 +rqput32 4 4 2 +ck bguest 0 +tf 1 792 get bseq 0 +ck bpoll 1 +ck bstatic 0 +rqclear 128 +tf 65 128 get bseq 0 +ck bpoll 1 +end +fn ackalloc to void +prreq +rqclear add 32 get bplen 0 +for i ulong 4 +rqput32 4 mul i 4 get bhead i +end +rqput32 4 20 get bplen 0 +tf 103 32 get bseq 0 +end +fn ackctrl to void +prreq +rqclear add 40 get bplen 0 +for i ulong 3 +rqput32 4 mul i 4 get bhead i +end +rqput32 4 16 get bplen 0 +tf 76 add 40 get bplen 0 get bseq 0 +end +fn ackfree to void +prreq +rqclear 16 +rqput32 4 0 get bhead 0 +rqput32 4 8 get bhead 1 +tf 10 16 get bseq 0 +end +fn setupmem to void +ck mmwalloc 2147483648 1048576 MMOK +ck mmasinit get mmwb 0 64 MMOK +ck gminit 4 add get mmwb 0 262144 128 8589934592 GMOK +ck gmalloc 4096 1 0 GMOK +put chin 0 get gmout 0 +ck gmalloc 512 1 GMHPOLL GMOK +put chud 0 get gmout 0 +ck gmalloc 8192 1 GMGPURO GMOK +put chgp 0 get gmout 0 +ck gmalloc 4096 1 GMHPOLL GMOK +put rtsem 0 get gmout 0 +ck gmalloc 4096 1 0 GMOK +put rtpb 0 get gmout 0 +put chent 0 1024 +put chchid 0 0 +put chepoch 0 get mmwgen 0 +note chprep state: backing prepared, not schedulable until the schedule ACK. +put chopen 0 2 +note DMA state is injected HOSTMODEL capability input only, never a successful DMA ioctl. +put mmwst 0 MMWDMA +end +fn main to int +bootinit +ck rminit RMOK +ck cminit CMOK +setupmem +rmcfg 3254779905 3254779906 3254779907 3254779912 3254779913 3254779914 +rmcfgch 3254779915 0 1 42 +prcap 30 rmbind 4 get mmwgen 0 +prcap 31 rmbind 0 add get mmwgen 0 1 +note An already active (submit-ready) channel is not a prepared backing; RM bind refuses it. +put chopen 0 1 +prcap 29 rmbind 0 get mmwgen 0 +put chopen 0 2 +prcap 32 rmbind 0 get mmwgen 0 +prcap 33 rmbind 0 get mmwgen 0 +ck cmbind 0 get rtsem 0 0 get mmwgen 0 CMOK +prcap 34 cminit +prcap 35 rminit +r = rmstart 10 +ck r RMOK +prstep 1 r +rqclear 44 +rqput32 4 0 1 +rqput32 4 4 0 +tf 4098 44 0 +prseq 1 rmstep +prseq 2 rmstep +prseq 3 bseqdone get bgen 0 add get btoken 0 1 true +prseq 4 bseqdone get bgen 0 get btoken 0 true +for i ulong 7 +ackalloc +r = rmstep +prstep long add i 2 r +end +r = rmsched 10 +prstep 9 r +ackctrl +r = rmstep +prstep 10 r +ck rmpub get mmwgen 0 MMOK +ck cmputpb get rtpb 0 0 0 get cmva 0 1 6 +prcap 36 rmsub 1 get rtpb 0 0 6 +prcap 37 rmsub 0 get rtpb 0 0 0 +put chopen 0 0 +prcap 38 rmsub 0 get rtpb 0 0 6 +put chopen 0 1 +prcap 39 rmsub 0 get rtpb 0 0 6 +note Reusing sequence one cannot publish a second untracked entry. +prcap 40 rmsub 0 get rtpb 0 0 6 +ck long get chput 0 1 +ck long get cmput 0 1 +r = rmdis 10 +prstep 11 r +prcap 41 rmsub 0 get rtpb 0 0 6 +ackctrl +r = rmstep +prstep 12 r +prcap 42 rmfree 10 +note Explicit host peer writes the completion marker, not engine-idle evidence. +mmwr32 get cmpa 0 1 +ck rmdrain 0 3 RMOK +r = rmfree 10 +prstep 13 r +for i ulong 7 +ackfree +r = rmstep +prstep long add i 14 r +end +prcap 43 rmsub 0 get rtpb 0 0 6 +prcap 44 rmfree 10 +prcap 45 rmlose get mmwgen 0 +prcap 46 rminit +prcap 47 cminit +ck long get mmwst 0 long MMWQUAR +ret 0 +end diff --git a/tests/rpc_diff.sh b/tests/rpc_diff.sh new file mode 100755 index 0000000..29b566c --- /dev/null +++ b/tests/rpc_diff.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Host verification only. Never invokes build/w0, firmware loading, map or VFIO calls. +set -eu +R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) +OMC=${OMC:-$R/build/omc} +AIENUX=${AIENUX:?set AIENUX to aienux c5bb3a4b9898257658aba0b7178a3c73a0371c27} +RPC_OM=${RPC_OM:-$R/gsp/rpc.om} +BOOT_OM=${BOOT_OM:-$R/gsp/boot.om} +expected=bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6 +actual=$(sha256sum "$OMC"); actual=${actual%% *} +[ "$actual" = "$expected" ] || { echo 'rpc_diff: compiler pin mismatch' >&2; exit 2; } +[ "$(git -C "$AIENUX" rev-parse HEAD)" = c5bb3a4b9898257658aba0b7178a3c73a0371c27 ] || exit 2 +git -C "$AIENUX" diff --quiet HEAD -- native/kernel/dev/gb10_gsp_boot.c native/kernel/dev/gb10_gsp_boot.h || { echo 'rpc_diff: INVALID modified oracle'; exit 2; } +t=$(mktemp -d /tmp/rpc-replay.XXXXXX) +trap 'rm -rf "$t"' EXIT HUP INT TERM +cc -std=c11 -O1 -Wall -Wextra -I"$AIENUX/native/kernel/dev" "$R/tests/rpc_ref.c" "$AIENUX/native/kernel/dev/gb10_gsp_boot.c" -o "$t/ref" +"$t/ref" > "$t/ref.frames" +cat "$RPC_OM" "$R/gsp/replay.om" "$R/gsp/sysinfo.om" "$R/chan/params.om" "$BOOT_OM" "$R/tests/rpc_trace.om" > "$t/trace.om" +if ! "$OMC" < "$t/trace.om" > "$t/replay"; then echo 'rpc_diff: INVALID compile'; exit 3; fi +chmod +x "$t/replay" +if "$t/replay" > "$t/om.frames"; then :; else + rc=$?; echo "rpc_diff: FAIL replay exit $rc"; exit 1 +fi +if ! cmp "$t/ref.frames" "$t/om.frames"; then echo 'rpc_diff: FAIL exact frames'; exit 1; fi +echo 'rpc_diff: PASS exact command frames and boot/RPC transition controls; hardware NOT_RUN' +sha256sum "$t/trace.om" "$t/replay" "$t/ref" "$t/om.frames" diff --git a/tests/rpc_ref.c b/tests/rpc_ref.c new file mode 100644 index 0000000..9945f1b --- /dev/null +++ b/tests/rpc_ref.c @@ -0,0 +1,32 @@ +/* Test-only oracle. Never linked into the Omega driver. Builds against pinned aienux C. */ +#include "gb10_gsp_boot.h" +#include +#include +#include +static unsigned char cmd[GSP_MQ_QUEUE_SIZE], stat[GSP_MQ_QUEUE_SIZE]; +static void put(unsigned char *p, unsigned v) { for(unsigned i=0;i<4;i++)p[i]=(unsigned char)(v>>(8*i)); } +static void init(unsigned char *p) { + put(p+4,GSP_MQ_QUEUE_SIZE);put(p+8,GSP_MQ_MSG_SIZE);put(p+12,GSP_MQ_MSG_COUNT); + put(p+20,1);put(p+24,32);put(p+28,4096); +} +static void emit(void) { if(fwrite(cmd,1,sizeof cmd,stdout)!=sizeof cmd)exit(2); } +int main(void) { + gsp_mq q={cmd,stat,0,0,0}; const char *why=0; unsigned seq; + init(cmd); init(stat); + unsigned char payload[8192];for(unsigned i=0;i scheduled/submit-ready (1) -> disabled (2). + New control: rmbind refuses an already active channel (cap 29 rc=-5); new mutants for the + schedule ACK activation and the prepared-state bind check are killed. + - complete: the explicit window quarantine on drain timeout duplicated gmquar (gmretire quarantines + a published owned window), so its mutant was equivalent; the duplicate and that mutant are removed. + +Not established by any of the above + device identity, coherent DMA ownership, cache attributes and maintenance, dma_wmb/dma_rmb, interrupt + delivery, engine WFI/membar, GSP idle, firmware authentication, hardware boot/RPC and any Linux kernel + or Omega kernel execution. The compiler's DSB SY bracketing is process instruction ordering only. diff --git a/tests/transport_host.sh b/tests/transport_host.sh new file mode 100755 index 0000000..734522e --- /dev/null +++ b/tests/transport_host.sh @@ -0,0 +1,92 @@ +#!/bin/sh +# HOST ONLY. No GPU/VFIO fd. Python coordinates explicit anonymous-map peers and mutants. +set -eu +R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) +OMC=${OMC:-$R/build/omc} +a=$(sha256sum "$OMC"); a=${a%% *} +[ "$a" = bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6 ] || exit 2 +export R OMC +python3 - <<'PY' +import os,pathlib,subprocess,tempfile,hashlib,re +r=pathlib.Path(os.environ['R']); omc=os.environ['OMC'] +parts=['tests/dma_replay.om','gsp/mmio.om','gsp/sim.om','gsp/seq.om','chan/gmmu.om','chan/mem.om','chan/chan.om','chan/sim.om','tests/dma_check.om','gsp/rpc.om','gsp/sysinfo.om','chan/params.om','gsp/boot.om','gsp/arena.om','gsp/connect.om','gsp/owned.om','gsp/profile.om','gsp/dispatch.om','chan/complete.om','chan/rmchan.om','tests/arena_trace.om','tests/rpc_trace.om'] +base=[] +for i,p in enumerate(parts): + s=(r/p).read_text() + if p.startswith('tests/'): + s=s.replace('fn main to int',f'fn zzmain{i} to int') + base.append(s) +transport=(r/'gsp/transport.om').read_text(); trace=(r/'tests/transport_trace.om').read_text() +service=(r/'gsp/service.om').read_text() +notify=(r/'gsp/notify.om').read_text(); failnotify='note Explicit HOST TEST ONLY failed notification model.\nfn qtbell h long to long\nret -5\nend\n' +with tempfile.TemporaryDirectory(prefix='gsp-transport-') as td: + t=pathlib.Path(td) + def build(body,nt=notify,name='trace',svc=service): + src='\n'.join(base+[body,nt,svc,trace]); p=t/name + c=subprocess.run([omc],input=src.encode(),stdout=subprocess.PIPE,stderr=subprocess.PIPE) + if c.returncode: + m=re.search(r'line (\d+)',c.stderr.decode(errors='replace')) + lines=src.splitlines(); n=int(m[1]) if m else 1 + excerpt='\n'.join(f'{i+1}: {lines[i]}' for i in range(max(0,n-3),min(len(lines),n+2))) + raise RuntimeError('INVALID compile '+name+': '+c.stderr.decode(errors='replace')+'\n'+excerpt) + p.write_bytes(c.stdout);p.chmod(0o700) + return p,src + def check(p,mode,expected=0): + z=subprocess.run([str(p)],input=bytes([mode]),capture_output=True) + if z.returncode!=expected: + raise RuntimeError(f'{p.name} mode{mode}: observed{z.returncode}, expected{expected}: '+repr(z.stderr)) + p,src=build(transport) + for mode in [106,100,105,97,119,102,103,98,120,118,101,114,99,109,104,116,115]:check(p,mode) + print('transport_host: PASS 17 composed mapped boot/RM hierarchy/schedule/submit/semaphore/drain/free/dispatch and queue refusal controls; hardware NOT_RUN') + print('transport source sha256',hashlib.sha256(src.encode()).hexdigest()) + print('transport binary sha256',hashlib.sha256(p.read_bytes()).hexdigest()) + p,_=build(transport,failnotify,'notify-failure');check(p,112) + print('transport_host: PASS postpublication notification failure retains identity and quarantines; hardware NOT_RUN') + mutants=[ + ('slotcopy','r = mapwrite h o rqtmp mul i RQSLOT RQSLOT','r = long RQSLOT',97,notify), + ('publish','p = rem add wr e RQCOUNT','p = wr',97,notify), + ('ack','x = mapset get mmwh 0 add get qtcmd 0 32 4 rqget32 0 32','x = mapset get mmwh 0 add get qtcmd 0 32 4 0',116,notify), + ('token','if or ne get qtpend 0 1 ne token get qttok 0','if false',116,notify), + ('snapshot','r = rqrecv','rqput32 1 16 mapget get mmwh 0 add get qtstat 0 16 4\nr = rqrecv',115,notify), + ('notifyloss','r = qtbell get qtbar 0\nif ne r 0\nqtlose','r = qtbell get qtbar 0\nif ne r 0',112,failnotify), + ('reset','ret eq get qtstate 0 0','ret true',98,notify), + ('generation','ret eq get qtboot 0 get bgen 0','ret true',103,notify), + ] + if service.count('d = dspauto')!=1:raise RuntimeError('INVALID sequencer service mutant anchor') + p,_=build(transport,notify,'false-sequencer',service.replace('d = dspauto','d = long 0')) + check(p,100,1) + print('DETECTED fabricated-sequencer-completion') + if notify.count('GPNOTIF 4 0')!=1:raise RuntimeError('INVALID notification mutant anchor') + p,_=build(transport,notify.replace('GPNOTIF 4 0','GPNOTIF 4 1'),'wrong-notification') + check(p,97,1) + print('DETECTED wrong-notification-value') + for name,old,new,mode,nt in mutants: + if transport.count(old)!=1:raise RuntimeError('INVALID mutant anchor '+name) + p,_=build(transport.replace(old,new),nt,name) + check(p,mode,1) + print('DETECTED',name) + # Ordering is a code-generation check, NOT a claim serialized peers prove fence necessity. + probe='fn main to int\nh = mapnew -1 0 4096 3 33\nr = mapset h 0 4 9\nv = mapget h 0 4\nif ne v 9\nret 1\nend\nr = mapdrop h\nret int r\nend\n' + z=subprocess.run([omc],input=probe.encode(),capture_output=True) + if z.returncode:raise RuntimeError('INVALID ordering probe compile') + p=t/'ordering';p.write_bytes(z.stdout);p.chmod(0o700) + if subprocess.run([str(p)]).returncode:raise RuntimeError('ordering probe behavior') + text=subprocess.check_output(['objdump','-D','-b','binary','-m','aarch64',str(p)],text=True) + ins=[] + for line in text.splitlines(): + m=re.match(r'\s*[0-9a-f]+:\s+[0-9a-f]{8}\s+(.+)',line) + if m:ins.append(m.group(1).strip()) + def ordered(xs): + hits=[] + for i,x in enumerate(xs): + if x.startswith('dsb') and x.split()[-1]=='sy' and i+2