interplane.Get Omega
Read in your language

omega-gpu-driver

aien-dev/omega-gpu-driver

Brought by drakestapleton

Comparing de238b57895ce9551e602e79d3427e1b29100e61 ... 81b579e4c371cc6e5c1eba3c57bc93ef20040800

20 files changed, +775 -79

GB20B.md+21-6
README.md+8-4
fwprep.om+74-5
gsp/arena.om+89-11
gsp/fw.om+2-2
gsp/owned.om+38-2
tests/arena_bytes.lean+28-0
tests/arena_large.om+131-0
tests/arena_large.py+93-0
tests/arena_large.sh+34-0
tests/boot_dma.sh+1-1
tests/fw_diff.sh+81-23
tests/window_sim.sh+57-2
window/README.md+7-1
window/aien-owndriver-window.service+3-3
window/common.sh+6-1
window/d2-boot.sh+2-1
window/d2-pre.sh+52-9
window/d2-restore.sh+29-3
window/d2-run.sh+19-5

GB20B.md

@@ -47,10 +47,12 @@ sizes are not applied to GB20B. Common WPR/FMC-args layout follows the generated
4747 WPR HAL. The selected FMC and its 48-byte hash, 384-byte key and 384-byte signature
4848 are copied to the bounded aligned arena. COT v2 leaves every FRTS field zero.
4949 These profile assertions describe the caller's checked extraction, NOT cryptographic
50-verification. Existing `fwprep` still extracts GB10B only; it is NOT a GB20B package
51-loader. A composed caller must extract and validate the distinct GB20B archives and
52-select gb20y before setting these fields. Passing GB10B bytes and lying about their
53-provenance is not supported or authenticated by this library.
50+verification. `fwprep FWFILE OGKMSRC OUTDIR gb20b` prepares this profile offline.
51+It selects the gb20y signature and both GB20B production archives, checks the SHA-256 of
52+all three complete inputs against the vendor pins, then creates a fresh output directory and publishes the boot image and FMC
53+inputs. It writes `fw.gb20b.manifest` last. An existing output directory is refused. The default
54+three-argument invocation prepares the historical GB10B profile. The board identity
55+and the physical launch still require hardware qualification.
5456
5557 `gsp/sec2.om:s2boot` takes actual BOOT_42 plus explicit profile/package and refuses a
5658 mismatch before register access. It requires silicon, SEC2 present and FMC enabled;
@@ -69,10 +71,23 @@ policy with its own monotonic clock and approved pause. No production timing or
6971 policy is asserted by a synthetic check-count simulation. Warm/resume, confidential
7072 compute and firmware debug variants are not implemented by this cold-production path.
7173
74+## Full-size host image
75+
76+`tests/arena_large.sh FIRMWARE VERIFIED_GB20B_PACKAGE` compiles the native composer and reads the real
77+inputs from the signed-firmware package. The test stages 76,496,896 bytes in an anonymous host mapping.
78+It checks all 74,969,088 firmware bytes, 18,303 leaf pages and their parent pointers, the bootloader,
79+both signatures, the FMC and its key and digest. The test fixture supplies model addresses and system
80+parameters. The finite byte model in `tests/arena_bytes.lean` proves the upper bank fits, a byte write
81+round-trips and the other bytes in its word are preserved.
82+
83+The host composer admits 80 MiB. The existing owned device-window policy in `chan/gmmu.om` admits
84+8 MiB. Physical transport, real device addresses, cache visibility and firmware launch still need
85+hardware qualification.
86+
7287 ## Composed launcher and native effect seam
7388
74-`build.sh` builds ONLY `build/w0` and `build/fwprep`. There is no `build/ogd`, no composed
75-`boot`, `hello` or `exec`, and no end-to-end native GPU startup. Host units cover
89+`build.sh` builds `build/w0`, `build/fwprep` and the model-only `build/ogd`. The latter
90+accepts `model` and `model-trace` and refuses a physical launch with exit 95. Host units cover
7691 protocol building, modeled boot/RPC, resource records and queue/completion ownership;
7792 their passing tests do not create a launcher. `gsp/dispatch.om` still refuses hardware.
7893 `chan/dma.om` and `gsp/mmio.om` target Linux VFIO/map handles, NOT native Aienux capabilities.

README.md

@@ -23,7 +23,7 @@ The 2026-10-28 candidate corrects the common-mode GB10B MCTP-header oracle defec
2323 and adds a separate source-selected GB20B COTv2 arena and SEC2 response path.
2424 See [GB20B.md](GB20B.md) for exact vendor/reference pins, mismatch refusals,
2525 host-only scope, composed-launcher/native-effect gaps and the **unexecuted**
26-minimal W0 authorization procedure. `fwprep` remains GB10B-only; `gpchip` does
26+minimal W0 authorization procedure. `fwprep` accepts an explicit `gb20b` profile for offline firmware preparation. `gpchip` does
2727 not admit GB20B to the existing GB10B transport. No physical boot/RPC/compute ran.
2828
2929 ## W0: bind, read identity, release
@@ -341,7 +341,10 @@ Nothing installs `/dev/nvidia-uvm`, replaces a module, or closes the ROADMAP row
341341
342342 `fwprep FWFILE OGKMSRC OUTDIR` reads the signed `gsp_ga10x.bin` (unchanged) and the NVIDIA open-source
343343 bindata tables, and writes `fmc.img`, `fmc.hash`, `fmc.pubkey`, `fmc.sig`, `bl.img` and, last,
344-`fw.manifest`. Channel ops other than the simulator (mode 0) trap; on the GB10 they go through GSP RPC.
344+`fw.manifest`. Add `gb20b` as the fourth argument to prepare the pinned GB20B production
345+inputs in a fresh directory. Its commit marker is `fw.gb20b.manifest`.
346+`sh tests/fw_diff.sh` compares both profiles against the independent extractors.
347+Channel ops other than the simulator (mode 0) trap; on the GB10 they go through GSP RPC.
345348
346349 The hardware backing assumption is now explicit: `mmwinit` keeps the simulator array; `mmwalloc` owns
347350 shared anonymous `mapnew` memory and CPU accesses use the live handle plus offset. The IOVA, CPU base
@@ -432,8 +435,9 @@ replies populate `pareply`. Header success and the RM body status are separate c
432435 leave the consumer reply buffer unchanged. Hardware `chan/chan.om` bind/disable/idle still trap.
433436
434437 `arbuild` composes the full WPR/libos/log page tables/cached args/shared queue/radix3/bootloader/
435-signature/FMC/FMC-args/COT image into `arbuf`, bounded by `arcap <= 16777216`; input staging `arin`
436-has the same fixed bound. `arsrc/arslen[0..7)` select ELF, RM signature, bootloader, FMC, FMC hash,
438+signature/FMC/FMC-args/COT image up to `arcap <= 83886080` bytes. Use `arinput` and `aroutput`
439+for offsets in this range. The first 16 MiB retains the existing `arin` and `arbuf` byte spans. The
440+upper 64 MiB uses little-endian words. The physical provider has its own admission limits. `arsrc/arslen[0..7)` select ELF, RM signature, bootloader, FMC, FMC hash,
437441 FMC key and FMC signature. `arcfg[0..10)` carries explicit profile, DMA width, heap IOVA/size, GPU
438442 instance, regkeys, bootloader code/data/manifest offsets and serialized registry length. `aroff/arsize`
439443 describe all regions; `arcmd/arstat` are queue offsets, `araddr 15` the FMC-args IOVA, `arcot/arclen`

fwprep.om

@@ -1,9 +1,10 @@
11 note fwprep.om: the GB10 firmware inputs for the bring-up chain, from files only (OM-1 seeded omc).
2-note Usage: fwprep FWFILE OGKMSRC OUTDIR
2+note Usage: fwprep FWFILE OGKMSRC OUTDIR [gb20b]
33 note FWFILE gsp_ga10x.bin (580.173.02), inspected as ck_gsp_fw_inspect inspect does
4-note OGKMSRC open-gpu-kernel-modules-580.173.02 tree; its two GB10B bindata files are read as
4+note OGKMSRC open-gpu-kernel-modules-580.173.02 tree; its two profile-specific bindata files are read as
55 note ck_gsp_bindata_extract extract does (src/nvidia/generated/g_bindata_kgspGetBinArchive*)
6-note OUTDIR gets fmc.img fmc.hash fmc.pubkey fmc.sig bl.img, then fw.manifest (written to
6+note OUTDIR must be new for gb20b (commit marker fw.gb20b.manifest). The default directory
7+note gets fmc.img fmc.hash fmc.pubkey fmc.sig bl.img, then fw.manifest (written to
78 note fw.manifest.tmp and renamed; fw.manifest is unlinked first, so a refused or failed run
89 note never leaves a manifest behind; consumers read the outputs only through it)
910 note stdout: the inspect report, the FMC extract report, the boot extract report (the C tools' exact
@@ -12,6 +13,14 @@ note (stderr), 2 refused, 3 output write failure.
1213 note Build: cat gsp/sha2.om gsp/inflate.om gsp/fw.om gsp/bindata.om fwprep.om | build/omc > fwprep
1314 note Prefix fwp. Host only: reads files, writes OUTDIR; no device.
1415 global fwpok ulong 1
16+global fwp20 ulong 1
17+global fwparg uchar 32
18+text FWPGB20 "gb20b"
19+note sha256 of the installed 580.173.02 firmware and the exact GB20B vendor archives,
20+note in FMC then boot order, from open-gpu-kernel-modules 20e4e6e19cc26ba47b5cbe23130a396be100c427.
21+text FWPGSP "32cb7cf3e77f97e92f6e92135939ccb3ba382748144569c0dfccf3338d43d963"
22+text FWPARCH "035179cfd878d6bed7308842b0d95612fbb0390149ebee7532b23f375727d8b671e3c512eaa78c60518f6c907826df36bed8e9cbbe8ea8257ca0b1c45d131dec"
23+text FWPERR20 "fwprep REFUSED GB20B input digest"
1524 global fwpsgb ulong 80
1625 global fwpsgl ulong 80
1726 global fwpst uchar 128
@@ -31,7 +40,7 @@ global fwpsh uchar 128
3140 note FWPTXT segments: 1 "fwprep ", 2 usage, 3..5 bindata paths, 6..7 functions, 8..13 labels,
3241 note 14..20 output names, 21.. messages, 33.. manifest pieces, 43..63 the 21 RM_RISCV_UCODE_DESC
3342 note words in struct order (C riscv_desc), 64.. more pieces
34-text FWPTXT "|fwprep |usage: fwprep FWFILE OGKMSRC OUTDIR|/src/nvidia/generated/|g_bindata_kgspGetBinArchiveGspRmFmcGfwProdSigned_GB10B.c|g_bindata_kgspGetBinArchiveGspRmBoot_GB10B.c|kgspGetBinArchiveGspRmFmcGfwProdSigned_GB10B|kgspGetBinArchiveGspRmBoot_GB10B|UCODE_IMAGE|UCODE_HASH|UCODE_PKEY|UCODE_SIG|UCODE_IMAGE_PROD|UCODE_DESC_PROD|fmc.img|fmc.hash|fmc.pubkey|fmc.sig|bl.img|fw.manifest|fw.manifest.tmp|REFUSED unexpected function | in |REFUSED missing label |wrote | bytes=| sha256=|RESULT OK|FAILED |makedir |write |rename |: |fwmanifest 1|fwversion |build_id |fw_file bytes=|fwimage offset=| size=|fwsignature .fwsignature_gb10y offset=|fmc_src |boot_src |bl_desc UCODE_DESC_PROD| version=| bootloader_off=| bootloader_size=| bl_param_off=| bl_param_size=| elf_off=| elf_size=| app_version=| manifest_off=| manifest_size=| mdata_off=| mdata_size=| mcode_off=| mcode_size=| monitor_enabled=| swbrom_code_off=| swbrom_code_size=| swbrom_data_off=| swbrom_data_size=| fb_reserved=| signed_as_code=|out |end|open |short read|REFUSED firmware|REFUSED bindata |"
43+text FWPTXT "|fwprep |usage: fwprep FWFILE OGKMSRC OUTDIR [gb20b]|/src/nvidia/generated/|g_bindata_kgspGetBinArchiveGspRmFmcGfwProdSigned_GB10B.c|g_bindata_kgspGetBinArchiveGspRmBoot_GB10B.c|kgspGetBinArchiveGspRmFmcGfwProdSigned_GB10B|kgspGetBinArchiveGspRmBoot_GB10B|UCODE_IMAGE|UCODE_HASH|UCODE_PKEY|UCODE_SIG|UCODE_IMAGE_PROD|UCODE_DESC_PROD|fmc.img|fmc.hash|fmc.pubkey|fmc.sig|bl.img|fw.manifest|fw.manifest.tmp|REFUSED unexpected function | in |REFUSED missing label |wrote | bytes=| sha256=|RESULT OK|FAILED |makedir |write |rename |: |fwmanifest 1|fwversion |build_id |fw_file bytes=|fwimage offset=| size=|fwsignature .fwsignature_gb10y offset=|fmc_src |boot_src |bl_desc UCODE_DESC_PROD| version=| bootloader_off=| bootloader_size=| bl_param_off=| bl_param_size=| elf_off=| elf_size=| app_version=| manifest_off=| manifest_size=| mdata_off=| mdata_size=| mcode_off=| mcode_size=| monitor_enabled=| swbrom_code_off=| swbrom_code_size=| swbrom_data_off=| swbrom_data_size=| fb_reserved=| signed_as_code=|out |end|open |short read|REFUSED firmware|REFUSED bindata |g_bindata_kgspGetBinArchiveGspRmFmcGfwProdSigned_GB20B.c|g_bindata_kgspGetBinArchiveGspRmBoot_GB20B.c|kgspGetBinArchiveGspRmFmcGfwProdSigned_GB20B|kgspGetBinArchiveGspRmBoot_GB20B|fwsignature .fwsignature_gb20y offset=|fw.gb20b.manifest|fw.gb20b.manifest.tmp|"
3544 fn fwpsetup to void
3645 if eq get fwpok 0 1
3746 ret
@@ -110,11 +119,46 @@ fwoc 10
110119 z = fwoflush
111120 put fwofd 0 1
112121 end
122+note Select the production archives, commit marker, manifest signature and ELF family together.
123+note The same slots drive matching and reporting. The default table remains GB10B.
124+fn fwpprof to ulong
125+n = argread 4 fwparg 0 32
126+if ne n long len FWPGB20
127+ret 1
128+end
129+for i ulong len FWPGB20
130+if ne get fwparg i get FWPGB20 i
131+ret 1
132+end
133+end
134+for i ulong 4
135+put fwpsgb add 4 i get fwpsgb add 70 i
136+put fwpsgl add 4 i get fwpsgl add 70 i
137+end
138+for i ulong 2
139+put fwpsgb add 19 i get fwpsgb add 75 i
140+put fwpsgl add 19 i get fwpsgl add 75 i
141+end
142+put fwpsgb 39 get fwpsgb 74
143+put fwpsgl 39 get fwpsgl 74
144+put fwsgb 50 get fwsgb 71
145+put fwsgl 50 get fwsgl 71
146+put fwsgb 52 get fwsgb 72
147+put fwsgl 52 get fwsgl 72
148+put fwp20 0 1
149+ret 0
150+end
113151 note arguments into fwpath (FWFILE), fwpsrc, fwpout: 0, or 1 on a usage error
114152 fn fwpargs to ulong
153+if eq argcnt 5
154+if ne fwpprof 0
155+ret 1
156+end
157+else
115158 if ne argcnt 4
116159 ret 1
117160 end
161+end
118162 a = argread 1 fwpath 0 4096
119163 if lt a 1
120164 ret 1
@@ -483,7 +527,7 @@ note make OUTDIR (an existing one is fine) and write every output, the manifest
483527 fn fwpwrite to ulong
484528 r = makedir fwpout 0 get fwpoutn 0 493
485529 if lt r 0
486-if ne r -17
530+if or ne r -17 eq get fwp20 0 1
487531 for i ulong get fwpoutn 0
488532 put fwpp i get fwpout i
489533 end
@@ -499,6 +543,20 @@ end
499543 end
500544 ret fwpman
501545 end
546+note Bind the selected section and archive payloads to the complete pinned inputs before output.
547+fn fwppins to ulong
548+for i ulong 64
549+if ne get fwhxf i get FWPGSP i
550+ret 0
551+end
552+end
553+for i ulong 128
554+if ne get fwpsh i get FWPARCH i
555+ret 0
556+end
557+end
558+ret 1
559+end
502560 fn fwprun to ulong
503561 e = fwpfw
504562 if eq e 2
@@ -517,6 +575,15 @@ e = fwpboot
517575 if ne e 0
518576 ret e
519577 end
578+if eq get fwp20 0 1
579+if eq fwppins 0
580+for i ulong len FWPERR20
581+fwoc get FWPERR20 i
582+end
583+fwoc 10
584+ret 2
585+end
586+end
520587 e = fwpwrite
521588 if ne e 0
522589 ret e
@@ -534,8 +601,10 @@ if ne fwpargs 0
534601 fwperr 2 0 0
535602 ret 1
536603 end
604+if eq get fwp20 0 0
537605 fwpmk 19
538606 u = unlink fwpp 0 get fwppn 0
607+end
539608 e = fwprun
540609 z = fwoflush
541610 if and eq e 0 eq get fwoerr 0 1

gsp/arena.om

@@ -2,17 +2,22 @@ note Host-only physical image composer, never DMA/MMIO. Oracle a108b114 gb10_gsp
22 note Profile 1 means explicit UNVERIFIED GB10B 580.173.02 layout, NOT detected hardware identity.
33 note Vendor 20e4e6e kernel_sec2_gb10b.c:507-508: gspFmcSysmemOffset = memdescGetPhysAddr; frtsSysmemSize = pGspImageSize.
44 note WolframLanguageEvaluator FromDigits[dc3aae21371a60b3,16] -> 15869187694674993331; FromDigits[1410de7e,16] -> 336649854.
5-note Caller supplies arin bytes and arsrc/arslen spans: ELF,RMsignature,bootloader,FMC,hash,key,FMCsignature.
5+note Caller supplies input bytes with arinput (or arin below ARLOW) and arsrc/arslen spans: ELF,RMsignature,bootloader,FMC,hash,key,FMCsignature.
66 note No firmware parsing/authentication: signed-byte fixtures test composition only, not signature validity.
77 note arcfg: profile,dmaBits,heapPA,heapBytes,gpuInstance,regkeys,BLcode,BLdata,BLmanifest,registryBytes.
8-note arbase is caller supplied IOVA. arcap <=16MiB; arused must be zero on entry. Partial output invalid on failure.
8+note arbase is caller supplied IOVA. arcap <=80MiB; arused must be zero on entry. Partial output invalid on failure.
99 note aroff/arsize: WPR,libos,7 logs,args,shared,radix,BL,signature,FMC,FMCargs,ELFdata.
1010 note arcmd/arstat are queue byte offsets. arcot[0..arclen) is SEC2 packet; artail is EMEM queue tail.
1111 note Raw registry must be canonical PACKED_REGISTRY_TABLE: 1..32 entries, exact contiguous name/value order,
1212 note nonempty terminated names, type1 DWORD length4 or type2/3 nonempty bytes, reserved padding zero.
1313 note Strings preserve opaque bytes like C oracle; their termination is not reinterpreted. Zero bytes omits RPC73.
1414 note Refusals: -1 profile/config, -2 source spans, -3 capacity, -4 registry, -5 DMA, -6 queue.
15-const ARMAX ulong 16777216
15+const ARLOW ulong 16777216
16+const ARMAX ulong 83886080
17+note The seed allows 2^24 elements per array. Eight bytes per word give 64 MiB beyond the legacy byte span.
18+note The upper extent is BSS. Unused pages cost no resident memory on demand-paged hosts.
19+global aroword ulong 8388608
20+global ariword ulong 8388608
1621 global arbuf uchar 16777216
1722 global arin uchar 16777216
1823 global arreg uchar 65456
@@ -35,9 +40,50 @@ global artail ulong 1
3540 global arnp ulong 4
3641 global arlvl ulong 4
3742 text arnames "LOGINIT|LOGINTR|LOGRM|LOGMNOC|LOGDBG|LOGROOT|LOGKRNL|RMARGS|"
43+fn arword o ulong to ulong
44+ret shr sub o ARLOW 3
45+end
46+fn arshift o ulong to ulong
47+ret shl and o 7 3
48+end
49+fn arbyte word ulong o ulong to uchar
50+ret uchar and shr word arshift o 255
51+end
52+fn arputb word ulong o ulong v uchar to ulong
53+s = arshift o
54+ret or and word not shl ulong 255 s shl ulong v s
55+end
56+fn arinput o ulong v uchar to void
57+if lt o ARLOW
58+put arin o v
59+ret
60+end
61+w = arword o
62+put ariword w arputb get ariword w o v
63+end
64+fn arsource o ulong to uchar
65+if lt o ARLOW
66+ret get arin o
67+end
68+ret arbyte get ariword arword o o
69+end
70+fn aroutput o ulong to uchar
71+if lt o ARLOW
72+ret get arbuf o
73+end
74+ret arbyte get aroword arword o o
75+end
76+fn arstore o ulong v uchar to void
77+if lt o ARLOW
78+put arbuf o v
79+ret
80+end
81+w = arword o
82+put aroword w arputb get aroword w o v
83+end
3884 fn arput o ulong v ulong n ulong to void
3985 for i ulong n
40-put arbuf add o i uchar and shr v mul i 8 255
86+arstore add o i uchar and shr v mul i 8 255
4187 end
4288 end
4389 fn arcput o ulong v ulong n ulong to void
@@ -118,22 +164,54 @@ end
118164 end
119165 ret eq pos n
120166 end
121-note Dynamic for loops have compiler fuel1000000; page chunks cover the full declared16MiB bound.
167+note artake supplies page-aligned offsets and sizes. Keep each inner loop below seed fuel.
122168 fn arzero o ulong n ulong to void
169+lead = and sub ulong 0 o 4095
170+if gt lead n
171+lead = n
172+end
173+for i ulong lead
174+arstore add o i 0
175+end
176+o = add o lead
177+n = sub n lead
123178 for p ulong div n 4096
179+if lt o ARLOW
124180 for i ulong 4096
125181 put arbuf add o i 0
126182 end
183+else
184+w = arword o
185+for i ulong 512
186+put aroword add w i 0
187+end
188+end
127189 o = add o 4096
128190 end
129191 for i ulong rem n 4096
130-put arbuf add o i 0
192+arstore add o i 0
131193 end
132194 end
133195 fn arcspan d ulong s ulong n ulong to void
196+if and le add d n ARLOW le add s n ARLOW
197+for i ulong n
198+put arbuf add d i get arin add s i
199+end
200+ret
201+end
202+if and and ge d ARLOW ge s ARLOW eq and or d s 7 0
203+dw = arword d
204+sw = arword s
205+for i ulong div n 8
206+put aroword add dw i get ariword add sw i
207+end
208+moved = and n not ulong 7
209+d = add d moved
210+s = add s moved
211+n = sub n moved
212+end
134213 for i ulong n
135-v = get arin add s i
136-put arbuf add d i v
214+arstore add d i arsource add s i
137215 end
138216 end
139217 fn artake k ulong n ulong to bool
@@ -292,11 +370,11 @@ if eq get arcfg 0 1
292370 arcput 28 get arslen 3 4
293371 end
294372 for i ulong 48
295-put arcot add 44 i get arin add get arsrc 4 i
373+put arcot add 44 i arsource add get arsrc 4 i
296374 end
297375 for i ulong 384
298-put arcot add 92 i get arin add get arsrc 5 i
299-put arcot add 476 i get arin add get arsrc 6 i
376+put arcot add 92 i arsource add get arsrc 5 i
377+put arcot add 476 i arsource add get arsrc 6 i
300378 end
301379 arcput 860 araddr 15 8
302380 put arclen 0 868

gsp/fw.om

@@ -1,6 +1,6 @@
11 note gsp/fw.om: GSP firmware container inspection in seeded Omega (OM-1). Ports the inspect path of
22 note aienux PR #441 native/kernel/tools/ck_gsp_fw_inspect.c (in_bounds, inspect_buf, print_report,
3-note cmd_inspect) for the fixed pins family gb10y and version 580.173.02. Library unit: no main.
3+note cmd_inspect) for firmware version 580.173.02 (default family gb10y). Library unit: no main.
44 note Prefix fw. Needs gsp/sha2.om concatenated first. The file is read with pread from an open fd,
55 note never mapped and never a device. Also holds the shared stdout writer (fwo*) that gsp/bindata.om
66 note and fwprep.om print through, and the strerror texts the C prints.
@@ -46,7 +46,7 @@ global fwhxs uchar 64
4646 note segment k of FWTXT is the text between the k-th and (k+1)-th '|' (segment 0 is empty).
4747 note 1..28 are the C refusal reasons in check order, 29 the deviation reason, 30.. report pieces,
4848 note 54.. strerror texts (glibc wording); 68..70 more strerror texts for fwprep's write paths.
49-text FWTXT "|short header: file smaller than an ELF64 header|ELF magic missing|not ELF64 (EI_CLASS)|not little-endian (EI_DATA)|EI_VERSION is not 1|e_type is not ET_REL (the pinned container is a relocatable object)|e_machine is not RISC-V (243)|e_shentsize is not 64|e_shnum is 0: no section header table|e_shnum above this tool's limit (256)|e_shstrndx out of range|section header table outside the file|section string table outside the file or empty|section string table not NUL-terminated|section name index outside the string table|section bounds: offset+size outside the file|missing section .fwimage|.fwimage empty|missing section .fwversion|missing section .note.gnu.build-id|missing section: no signature section for this chip family|signature section empty|version section size not in 1..63|version string not NUL-terminated|version mismatch against the pinned driver version|build-id note too short|build-id note is not an NT_GNU_BUILD_ID note|build-id note descriptor size out of range|section string table above this port's 16 MiB buffer|file | bytes=| family=| expect_version=|section | type=| offset=| size=|(null)|fwversion |build_id |signature_section |sha256_file |sha256_fwimage |sha256_signature |RESULT OK|RESULT REFUSED |.fwimage|.fwversion|.note.gnu.build-id|.fwsignature_gb10y|580.173.02|gb10y|GNU|No such file or directory|Permission denied|Is a directory|File too large|Input/output error|Not a directory|Too many levels of symbolic links|File name too long|Unknown error |open |: |short read|Too many open files|Cannot allocate memory|File exists|No space left on device|Read-only file system|"
49+text FWTXT "|short header: file smaller than an ELF64 header|ELF magic missing|not ELF64 (EI_CLASS)|not little-endian (EI_DATA)|EI_VERSION is not 1|e_type is not ET_REL (the pinned container is a relocatable object)|e_machine is not RISC-V (243)|e_shentsize is not 64|e_shnum is 0: no section header table|e_shnum above this tool's limit (256)|e_shstrndx out of range|section header table outside the file|section string table outside the file or empty|section string table not NUL-terminated|section name index outside the string table|section bounds: offset+size outside the file|missing section .fwimage|.fwimage empty|missing section .fwversion|missing section .note.gnu.build-id|missing section: no signature section for this chip family|signature section empty|version section size not in 1..63|version string not NUL-terminated|version mismatch against the pinned driver version|build-id note too short|build-id note is not an NT_GNU_BUILD_ID note|build-id note descriptor size out of range|section string table above this port's 16 MiB buffer|file | bytes=| family=| expect_version=|section | type=| offset=| size=|(null)|fwversion |build_id |signature_section |sha256_file |sha256_fwimage |sha256_signature |RESULT OK|RESULT REFUSED |.fwimage|.fwversion|.note.gnu.build-id|.fwsignature_gb10y|580.173.02|gb10y|GNU|No such file or directory|Permission denied|Is a directory|File too large|Input/output error|Not a directory|Too many levels of symbolic links|File name too long|Unknown error |open |: |short read|Too many open files|Cannot allocate memory|File exists|No space left on device|Read-only file system|.fwsignature_gb20y|gb20y|"
5050 text FWHEXD "0123456789abcdef"
5151 note build the segment table once
5252 fn fwsetup to void

gsp/owned.om

@@ -3,6 +3,38 @@ note Compose after chan/dma+gmmu and gsp/arena+boot. No device opens, barriers o
33 note Real publication still requires reviewed coherency/release/acquire and an authorized endpoint.
44 global arsepoch ulong 1
55 global arsboot ulong 1
6+note All staged bytes target the same checked owned mapping. Publish the receipt after the last copy.
7+fn arstdata h long n ulong to bool
8+if or eq n 0 gt n ARMAX
9+ret false
10+end
11+low = n
12+if gt low ARLOW
13+low = ARLOW
14+end
15+if ne mapwrite h 0 arbuf 0 low long low
16+ret false
17+end
18+if eq low n
19+ret true
20+end
21+page = new uchar 4096 0
22+o = low
23+while lt o n bound 16384
24+size = sub n o
25+if gt size 4096
26+size = ulong 4096
27+end
28+for i ulong size
29+put page i aroutput add o i
30+end
31+if ne mapwrite h o page 0 size long size
32+ret false
33+end
34+o = add o size
35+end
36+ret eq o n
37+end
638 fn arstage gen ulong to long
739 if not mmwepoch gen
840 ret MMEGEN
@@ -19,8 +51,12 @@ end
1951 if or eq get arused 0 0 gt get arused 0 get mmws 0
2052 ret MMEINVAL
2153 end
22-r = mapwrite get mmwh 0 0 arbuf 0 get arused 0
23-if ne r long get arused 0
54+if gt get arused 0 ARMAX
55+ret MMEINVAL
56+end
57+put arsepoch 0 0
58+put arsboot 0 0
59+if not arstdata get mmwh 0 get arused 0
2460 ret MMEIO
2561 end
2662 put arsepoch 0 gen

tests/arena_bytes.lean

new file mode 100644
@@ -0,0 +1,28 @@
1+import Std.Tactic.BVDecide
2+
3+namespace ArenaBytes
4+
5+-- The upper byte offsets and word indices used by arword and arshift.
6+theorem bounds (o : Nat) (lo : 16777216 ≤ o) (hi : o < 83886080) :
7+ (o - 16777216) / 8 < 8388608 ∧
8+ 16777216 + 8 * ((o - 16777216) / 8) + o % 8 = o := by omega
9+
10+def shift (lane : BitVec 3) : BitVec 64 := lane.zeroExtend 64 <<< 3
11+
12+def getByte (w : BitVec 64) (lane : BitVec 3) : BitVec 8 :=
13+ (w >>> shift lane).truncate 8
14+
15+def setByte (w : BitVec 64) (lane : BitVec 3) (v : BitVec 8) : BitVec 64 :=
16+ (w &&& ~~~((255 : BitVec 64) <<< shift lane)) ||| (v.zeroExtend 64 <<< shift lane)
17+
18+theorem readWrite (w : BitVec 64) (lane : BitVec 3) (v : BitVec 8) :
19+ getByte (setByte w lane v) lane = v := by
20+ unfold getByte setByte shift
21+ bv_decide
22+
23+theorem otherLanes (w : BitVec 64) (a b : BitVec 3) (v : BitVec 8) (h : a ≠ b) :
24+ getByte (setByte w a v) b = getByte w b := by
25+ unfold getByte setByte shift
26+ bv_decide
27+
28+end ArenaBytes

tests/arena_large.om

new file mode 100644
@@ -0,0 +1,131 @@
1+note Device-free caller. Read the seven verified firmware spans; emit the anonymous staged bytes and COT.
2+note The first byte selects a normal cap (0), a 16 MiB cap (1), or dirty high output bytes (2).
3+global alchunk uchar 65536
4+fn alread n ulong to bool
5+p = ulong 0
6+while lt p n bound 65536
7+r = read 0 alchunk p sub n p
8+if lt r 1
9+ret false
10+end
11+p = add p ulong r
12+end
13+ret true
14+end
15+fn alwrite n ulong to bool
16+p = ulong 0
17+while lt p n bound 65536
18+r = write 1 alchunk p sub n p
19+if lt r 1
20+ret false
21+end
22+p = add p ulong r
23+end
24+ret true
25+end
26+fn alspan pos ulong n ulong to bool
27+while gt n 0 bound 2048
28+k = n
29+if gt k 65536
30+k = ulong 65536
31+end
32+if not alread k
33+ret false
34+end
35+for i ulong k
36+arinput add pos i get alchunk i
37+end
38+pos = add pos k
39+n = sub n k
40+end
41+ret true
42+end
43+fn main to int
44+if not alread 1
45+ret 1
46+end
47+mode = get alchunk 0
48+if gt mode 3
49+ret 1
50+end
51+put arcfg 0 2
52+put arcfg 1 40
53+put arcfg 2 268435456
54+put arcfg 3 8192
55+put arcfg 6 61440
56+put arcfg 7 2560
57+for i ulong 3
58+put arpkg i 2
59+end
60+put arbase 0 1048576
61+put arcap 0 ARMAX
62+if eq mode 1
63+put arcap 0 ARLOW
64+end
65+put arslen 0 74969088
66+put arslen 1 4096
67+put arslen 2 212992
68+put arslen 3 212296
69+put arslen 4 48
70+put arslen 5 384
71+put arslen 6 384
72+note Skew the input three bytes so the packed word boundary differs from the output.
73+pos = ulong 3
74+if eq mode 3
75+pos = ulong 0
76+end
77+for i ulong 7
78+put arsrc i pos
79+if not alspan pos get arslen i
80+ret 2
81+end
82+pos = add pos get arslen i
83+end
84+if ne read 0 alchunk 0 1 0
85+ret 2
86+end
87+if eq mode 2
88+for page ulong 16384
89+put aroword mul page 512 not ulong 0
90+end
91+end
92+rc = arbuild
93+if ne rc 0
94+if eq rc -3
95+ret 3
96+end
97+ret 4
98+end
99+used = get arused 0
100+h = mapnew -1 0 used 3 33
101+if lt h 0
102+ret 5
103+end
104+if not arstdata h used
105+ret 6
106+end
107+o = ulong 0
108+while lt o used bound 2048
109+k = sub used o
110+if gt k 65536
111+k = ulong 65536
112+end
113+if ne mapread h o alchunk 0 k long k
114+ret 7
115+end
116+if not alwrite k
117+ret 8
118+end
119+o = add o k
120+end
121+if ne mapdrop h 0
122+ret 9
123+end
124+for i ulong get arclen 0
125+put alchunk i get arcot i
126+end
127+if not alwrite get arclen 0
128+ret 8
129+end
130+ret 0
131+end

tests/arena_large.py

new file mode 100644
@@ -0,0 +1,93 @@
1+"""Check offline GB20B composition against the pinned vendor bytes and radix layout."""
2+import argparse
3+import hashlib
4+import struct
5+import subprocess
6+from pathlib import Path
7+
8+PAGE = 4096
9+BASE = 1048576
10+FW = "32cb7cf3e77f97e92f6e92135939ccb3ba382748144569c0dfccf3338d43d963"
11+PARTS = {
12+ "bl.img": "6da8510c912ccd5a8b73f9a5cce9e0f4ea657aa430431d2f8e4874834aeadb94",
13+ "fmc.img": "b92f83c1250019af11162d9ee471b8fb74081ea598cf6added0bee7a3663e2be",
14+ "fmc.hash": "4a5854c785fa7a9ea4aaabb52f6c9838242f81506659ff413da0f4b8ac1f40bf",
15+ "fmc.pubkey": "54076b108ad3da65e09f675d88efd553340a0c0653cf13372f4e30dd6ab17e7c",
16+ "fmc.sig": "6c5fbbf096efff9d0f47d4cc70096898f059579154464e6c3b972d2e606f1334",
17+}
18+
19+
20+def sha(data):
21+ return hashlib.sha256(data).hexdigest()
22+
23+
24+def span(path, digest):
25+ body = path.read_bytes()
26+ if sha(body) != digest:
27+ raise ValueError(f"wrong firmware input {path.name}")
28+ return body
29+
30+
31+def check(exe, fw, inputs):
32+ firmware = span(fw, FW)
33+ image = firmware[64:64 + 74969088]
34+ signature = firmware[74969199:74969199 + 4096]
35+ boot, fmc, fmc_hash, pubkey, signed = [span(inputs / k, v) for k, v in PARTS.items()]
36+ source = b"".join([image, signature, boot, fmc, fmc_hash, pubkey, signed])
37+ def run(mode, data):
38+ return subprocess.run([exe], input=bytes([mode]) + data, capture_output=True, timeout=120)
39+ small = run(1, source)
40+ assert (small.returncode, small.stdout) == (3, b""), "old capacity must refuse before output"
41+ for bad in (source[:-1], source + b"x"):
42+ refused = run(0, bad)
43+ assert (refused.returncode, refused.stdout) == (2, b""), "incomplete or surplus input admitted"
44+ regular = run(0, source)
45+ assert regular.returncode == 0, regular.returncode
46+ dirty = run(2, source)
47+ assert dirty.returncode == 0 and regular.stdout == dirty.stdout, "uncleared reused arena"
48+ aligned = run(3, source)
49+ assert aligned.returncode == 0 and regular.stdout == aligned.stdout, "aligned and unaligned inputs differ"
50+ out = memoryview(regular.stdout)
51+ arena, cot = out[:-868], out[-868:]
52+ def word(data, offset):
53+ return struct.unpack_from("<Q", data, offset)[0]
54+ def at(data, offset):
55+ address = word(data, offset)
56+ assert BASE <= address < BASE + len(arena)
57+ return address - BASE
58+ radix = at(arena, 16)
59+ assert word(arena, 24) == len(image)
60+ # Three levels; check every intermediate and leaf pointer, including the final partial page.
61+ pages = (len(image) + PAGE - 1) // PAGE
62+ levels = [(pages + 512**i - 1) // 512**i for i in (3, 2, 1, 0)]
63+ current = radix
64+ for count, children in zip(levels, levels[1:]):
65+ child = current + PAGE * count
66+ for i in range(children):
67+ assert at(arena, current + i * 8) == child + i * PAGE, (current, i)
68+ assert not any(arena[current + children * 8:child]), "nonzero radix padding"
69+ current = child
70+ assert arena[current:current + len(image)] == image, "firmware bytes changed"
71+ assert not any(arena[current + len(image):current + pages * PAGE])
72+ for data, ref, offset in [(arena, boot, 32), (arena, signature, 72), (cot, fmc, 12)]:
73+ start = at(data, offset)
74+ assert arena[start:start + len(ref)] == ref
75+ assert word(arena, 40) == len(boot) and word(arena, 80) == len(signature)
76+ assert (word(arena, 48), word(arena, 56), word(arena, 64)) == (61440, 2560, 0)
77+ assert struct.unpack_from("<I", cot)[0] == (3 << 30)
78+ assert struct.unpack_from("<HH", cot, 8) == (2, 860)
79+ assert cot[44:92] == fmc_hash and cot[92:476] == pubkey and cot[476:860] == signed
80+ assert at(arena, at(cot, 860) + 16) == 0
81+ print(f"PASS {len(arena)} staged bytes, {len(image)} firmware bytes, {pages} data pages, {len(cot)} COT bytes")
82+ print(f"arena_sha256 {sha(arena)}\ncot_sha256 {sha(cot)}")
83+ print("PASS undersized arena, short/trailing input, dirty high pages and aligned/unaligned copies")
84+
85+
86+if __name__ == "__main__":
87+ if not __debug__:
88+ raise SystemExit("assertions required")
89+ ap = argparse.ArgumentParser(description=__doc__)
90+ for name in ("exe", "firmware", "package"):
91+ ap.add_argument(name, type=Path)
92+ args = ap.parse_args()
93+ check(args.exe.resolve(), args.firmware, args.package)

tests/arena_large.sh

new file mode 100755
@@ -0,0 +1,34 @@
1+#!/bin/sh
2+# Host-only on AArch64. The simulator uses an anonymous CPU mapping.
3+set -eu
4+r=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
5+fw=${1:?usage: arena_large.sh FIRMWARE VERIFIED_GB20B_PACKAGE}
6+package=${2:?missing GB20B package from fwprep}
7+compiler=${OMC:-$r/build/irq-omc}
8+pin=$(sed -n 's/^OMC_SHA256=//p' "$r/tools/irq-omc.pin")
9+printf '%s %s\n' "$pin" "$compiler" | sha256sum -c -
10+tmp=$(mktemp -d)
11+trap 'rm -rf "$tmp"' EXIT HUP INT TERM
12+(
13+ cd "$r"
14+ test "$(tail -1 tools/ogd.units)" = ogd.om
15+ sed '$d' tools/ogd.units | xargs cat
16+ cat tests/arena_large.om
17+) > "$tmp/large.om"
18+"$compiler" < "$tmp/large.om" > "$tmp/large"
19+chmod +x "$tmp/large"
20+python3 "$r/tests/arena_large.py" "$tmp/large" "$fw" "$package"
21+sha256sum "$tmp/large.om" "$tmp/large"
22+orig='ret arbyte get aroword arword o o'
23+test "$(grep -Fxc "$orig" "$tmp/large.om")" -eq 1
24+sed "s/^$orig\$/ret uchar xor arbyte get aroword arword o o 1/" "$tmp/large.om" > "$tmp/mut.om"
25+"$compiler" < "$tmp/mut.om" > "$tmp/mut"
26+chmod +x "$tmp/mut"
27+if python3 "$r/tests/arena_large.py" "$tmp/mut" "$fw" "$package" > "$tmp/mut.log" 2>&1; then
28+ echo 'FAIL high-byte copy mutant survived'; exit 1
29+else
30+ rc=$?
31+fi
32+test "$rc" = 1
33+grep -Fxq 'AssertionError: firmware bytes changed' "$tmp/mut.log"
34+echo 'PASS compiled high-byte copy mutant ran and changed the firmware bytes'

tests/boot_dma.sh

@@ -18,7 +18,7 @@ build "$R/gsp/owned.om"
1818 "$t/replay"
1919 echo 'boot_dma: PASS exact owned staging, generations, publication refusal and timeout quarantine; hardware NOT_RUN'
2020 sha256sum "$t/all.om" "$t/replay"
21-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"
21+sed 's/if not arstdata get mmwh 0 get arused 0/if false/' "$R/gsp/owned.om" > "$t/nocopy.om"
2222 build "$t/nocopy.om"
2323 if "$t/replay"; then echo 'boot_dma: SURVIVED staging'; exit 1; else rc=$?; fi
2424 [ "$rc" = 1 ] || { echo 'boot_dma: INVALID staging mutant'; exit 2; }

tests/fw_diff.sh

@@ -32,16 +32,34 @@ run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; }
3232 fail() { echo "fw_diff: FAIL $2"; exit "$1"; }
3333
3434 FW_SHA=32cb7cf3e77f97e92f6e92135939ccb3ba382748144569c0dfccf3338d43d963
35-FMC_C=g_bindata_kgspGetBinArchiveGspRmFmcGfwProdSigned_GB10B.c
36-BOOT_C=g_bindata_kgspGetBinArchiveGspRmBoot_GB10B.c
37-FMC_F=kgspGetBinArchiveGspRmFmcGfwProdSigned_GB10B
38-BOOT_F=kgspGetBinArchiveGspRmBoot_GB10B
39-FMC_C_SHA=2861be1864befa21e4fe4a5d088dae816de8cd8f03359de9f7d35cff910c8957
40-BOOT_C_SHA=c9c0c0073837b8e38ef6fc94c3c531d6f03b22003fe084b0f9066631f4a0397b
41-FMC_IMG_SHA=b13ead4b9a6b8a0d268f3094cc4f4521d6be8a9a525edbc9a8f3f397c86f1f2e
42-BL_IMG_SHA=427a691d8453f02548d395f40ac900eb0d5b8ea864e8f14f958eef890ba400a2
43-# 0xa00 = 2560, 0xa600 = 42496, 0xb000 = 45056, 0x24d00 = 150784
44-DESC_PIN='version=5 bootloader_off=0 bootloader_size=0 bl_param_off=0 bl_param_size=0 elf_off=0 elf_size=0 app_version=0 manifest_off=0 manifest_size=2560 mdata_off=2560 mdata_size=42496 mcode_off=45056 mcode_size=150784 monitor_enabled=1'
35+case "${1:-gb10b}" in
36+gb10b)
37+ family=gb10y
38+ chip=GB10B
39+ manifest=fw.manifest
40+ FMC_C_SHA=2861be1864befa21e4fe4a5d088dae816de8cd8f03359de9f7d35cff910c8957
41+ BOOT_C_SHA=c9c0c0073837b8e38ef6fc94c3c531d6f03b22003fe084b0f9066631f4a0397b
42+ FMC_IMG_SHA=b13ead4b9a6b8a0d268f3094cc4f4521d6be8a9a525edbc9a8f3f397c86f1f2e
43+ BL_IMG_SHA=427a691d8453f02548d395f40ac900eb0d5b8ea864e8f14f958eef890ba400a2
44+ fmc_size=195912; boot_size=196608; mdata_size=42496; mcode_off=45056
45+ ;;
46+gb20b)
47+ family=gb20y
48+ chip=GB20B
49+ manifest=fw.gb20b.manifest
50+ FMC_C_SHA=035179cfd878d6bed7308842b0d95612fbb0390149ebee7532b23f375727d8b6
51+ BOOT_C_SHA=71e3c512eaa78c60518f6c907826df36bed8e9cbbe8ea8257ca0b1c45d131dec
52+ FMC_IMG_SHA=b92f83c1250019af11162d9ee471b8fb74081ea598cf6added0bee7a3663e2be
53+ BL_IMG_SHA=6da8510c912ccd5a8b73f9a5cce9e0f4ea657aa430431d2f8e4874834aeadb94
54+ fmc_size=212296; boot_size=212992; mdata_size=58880; mcode_off=61440
55+ ;;
56+*) fail 2 "unknown test profile" ;;
57+esac
58+FMC_F=kgspGetBinArchiveGspRmFmcGfwProdSigned_$chip
59+BOOT_F=kgspGetBinArchiveGspRmBoot_$chip
60+FMC_C=g_bindata_$FMC_F.c
61+BOOT_C=g_bindata_$BOOT_F.c
62+DESC_PIN="version=5 bootloader_off=0 bootloader_size=0 bl_param_off=0 bl_param_size=0 elf_off=0 elf_size=0 app_version=0 manifest_off=0 manifest_size=2560 mdata_off=2560 mdata_size=$mdata_size mcode_off=$mcode_off mcode_size=150784 monitor_enabled=1"
4563 G=$OGKM/src/nvidia/generated
4664
4765 got=$(sha256sum "$OMC" | cut -d' ' -f1)
@@ -64,7 +82,7 @@ cat "$SHA2_OM" "$INFL_OM" "$FW_OM" "$BD_OM" "$FWPREP_OM" | run "$OMC" > "$t/fwpr
6482 chmod +x "$t/fwprep"
6583
6684 # ---- positive run on the real inputs ----
67-run "$t/ck_gsp_fw_inspect" inspect "$FW" > "$t/insp.txt" || fail 2 "C inspect refused the real firmware"
85+run "$t/ck_gsp_fw_inspect" inspect "$FW" --family "$family" > "$t/insp.txt" || fail 2 "C inspect refused the real firmware"
6886 run "$t/ck_gsp_bindata_extract" extract "$G/$FMC_C" > "$t/fmc.txt" || fail 2 "C extract refused FMC"
6987 run "$t/ck_gsp_bindata_extract" extract "$G/$BOOT_C" > "$t/boot.txt" || fail 2 "C extract refused boot"
7088 mkdir "$t/cfmc" "$t/cboot"
@@ -83,7 +101,7 @@ while [ $# -ge 2 ]; do
83101 outs="$outs $1:$2"
84102 shift 2
85103 done
86-printf 'fwprep wrote fw.manifest\nfwprep RESULT OK\n' >> "$t/want.txt"
104+printf 'fwprep wrote %s\nfwprep RESULT OK\n' "$manifest" >> "$t/want.txt"
87105
88106 sec() { sed -n "s/^section [0-9]* $1 type=[0-9]* offset=\([0-9]*\) size=\([0-9]*\)\$/offset=\1 size=\2/p" "$t/insp.txt"; }
89107 names='version bootloader_off bootloader_size bl_param_off bl_param_size elf_off elf_size app_version manifest_off manifest_size mdata_off mdata_size mcode_off mcode_size monitor_enabled swbrom_code_off swbrom_code_size swbrom_data_off swbrom_data_size fb_reserved signed_as_code'
@@ -96,7 +114,7 @@ desc=$(set -- $words; for n in $names; do printf ' %s=%s' "$n" "$1"; shift; done
96114 echo "build_id $(sed -n 's/^build_id //p' "$t/insp.txt")"
97115 echo "fw_file bytes=$(wc -c < "$FW") sha256=$(sed -n 's/^sha256_file //p' "$t/insp.txt")"
98116 echo "fwimage $(sec '\.fwimage') sha256=$(sed -n 's/^sha256_fwimage \([0-9a-f]*\) .*/\1/p' "$t/insp.txt")"
99- echo "fwsignature .fwsignature_gb10y $(sec '\.fwsignature_gb10y') sha256=$(sed -n 's/^sha256_signature //p' "$t/insp.txt")"
117+ echo "fwsignature .fwsignature_$family $(sec "\.fwsignature_$family") sha256=$(sed -n 's/^sha256_signature //p' "$t/insp.txt")"
100118 echo "fmc_src $FMC_C bytes=$(wc -c < "$G/$FMC_C") sha256=$FMC_C_SHA"
101119 echo "boot_src $BOOT_C bytes=$(wc -c < "$G/$BOOT_C") sha256=$BOOT_C_SHA"
102120 echo "bl_desc UCODE_DESC_PROD$desc"
@@ -105,9 +123,18 @@ desc=$(set -- $words; for n in $names; do printf ' %s=%s' "$n" "$1"; shift; done
105123 } > "$t/manifest.want"
106124
107125 o=$t/out
108-mkdir "$o"
109-echo stale > "$o/fw.manifest"
110-run "$t/fwprep" "$FW" "$OGKM" "$o" > "$t/om.txt" 2> "$t/om.err"
126+if [ "$chip" = GB10B ]; then
127+ mkdir "$o"
128+ echo stale > "$o/$manifest"
129+fi
130+run_profile() {
131+ if [ "$chip" = GB20B ]; then
132+ run "$t/fwprep" "$@" gb20b
133+ else
134+ run "$t/fwprep" "$@"
135+ fi
136+}
137+run_profile "$FW" "$OGKM" "$o" > "$t/om.txt" 2> "$t/om.err"
111138 rc=$?
112139 [ "$rc" -eq 0 ] || { cat "$t/om.err"; tail -n 3 "$t/om.txt"; fail 1 "fwprep exit $rc on the real inputs"; }
113140 [ -s "$t/om.err" ] && fail 1 "fwprep wrote to stderr on success"
@@ -119,17 +146,17 @@ fi
119146 for p in $outs; do
120147 cmp -s "${p#*:}" "$o/${p%%:*}" || fail 1 "${p%%:*} differs from the C output"
121148 done
122-if ! cmp -s "$t/manifest.want" "$o/fw.manifest"; then
123- diff "$t/manifest.want" "$o/fw.manifest" | head -n 6
149+if ! cmp -s "$t/manifest.want" "$o/$manifest"; then
150+ diff "$t/manifest.want" "$o/$manifest" | head -n 6
124151 fail 1 "fw.manifest differs from the one rebuilt from the C outputs"
125152 fi
126153 [ "$(ls "$o" | wc -l)" -eq 6 ] || fail 1 "OUTDIR holds other files: $(ls "$o" | tr '\n' ' ')"
127154 [ "$(sha256sum < "$o/fmc.img" | cut -d' ' -f1)" = "$FMC_IMG_SHA" ] || fail 1 "fmc.img sha256 pin"
128-[ "$(wc -c < "$o/fmc.img")" -eq 195912 ] || fail 1 "fmc.img size pin"
155+[ "$(wc -c < "$o/fmc.img")" -eq "$fmc_size" ] || fail 1 "fmc.img size pin"
129156 [ "$(sha256sum < "$o/bl.img" | cut -d' ' -f1)" = "$BL_IMG_SHA" ] || fail 1 "bl.img sha256 pin"
130-[ "$(wc -c < "$o/bl.img")" -eq 196608 ] || fail 1 "bl.img size pin"
131-grep -qF "bl_desc UCODE_DESC_PROD $DESC_PIN " "$o/fw.manifest" || fail 1 "descriptor pin"
132-echo "fw_diff: positive PASS ($n stdout lines, 5 outputs and fw.manifest identical to the C referees)"
157+[ "$(wc -c < "$o/bl.img")" -eq "$boot_size" ] || fail 1 "bl.img size pin"
158+grep -qF "bl_desc UCODE_DESC_PROD $DESC_PIN " "$o/$manifest" || fail 1 "descriptor pin"
159+echo "fw_diff: $chip positive PASS ($n stdout lines, 5 outputs and $manifest identical to the C referees)"
133160
134161 # ---- negative controls ----
135162 # edit_line SRC LINE OLD NEW DST: replace line LINE (which must read OLD) with NEW; exactly once
@@ -167,6 +194,36 @@ cref() {
167194 [ "$r" -eq 2 ] || fail 1 "control $nm: C referee exit $r, want 2"
168195 }
169196
197+if [ "$chip" = GB20B ]; then
198+ # Keep the container parseable and keep the archives' extracted bytes valid.
199+ # Only the selected input's digest changes. Each failure must precede publication.
200+ expect_refusal() {
201+ run_profile "$1" "$2" "$t/red-out" > "$t/red.log"
202+ status=$?
203+ [ "$status" = 2 ] && [ ! -e "$t/red-out" ] &&
204+ tail -n1 "$t/red.log" | grep -Fxq "$3" || fail 1 "control $4: exit $status or wrong refusal"
205+ echo "fw_diff: $chip refused $4"
206+ }
207+ cp "$FW" "$t/appended.bin" && printf x >> "$t/appended.bin" || fail 2 "copy firmware"
208+ expect_refusal "$t/appended.bin" "$OGKM" "fwprep REFUSED GB20B input digest" firmware-digest
209+ for archive in "$FMC_C" "$BOOT_C"; do
210+ tree altered "$G/$FMC_C" "$G/$BOOT_C" || fail 2 "copy archives"
211+ printf '\n' >> "$t/altered/src/nvidia/generated/$archive" || fail 2 "edit archive"
212+ expect_refusal "$FW" "$t/altered" "fwprep REFUSED GB20B input digest" "$archive"
213+ done
214+ tree wrong "$G/g_bindata_kgspGetBinArchiveGspRmFmcGfwProdSigned_GB10B.c" "$G/$BOOT_C" || fail 2 "copy wrong family"
215+ expect_refusal "$FW" "$t/wrong" "fwprep REFUSED unexpected function kgspGetBinArchiveGspRmFmcGfwProdSigned_GB10B in $FMC_C" cross-family
216+ # The GB20B run claims a new directory before writing anything. A second run cannot alter it.
217+ (cd "$o" && sha256sum ./*) > "$t/sealed"
218+ run_profile "$FW" "$OGKM" "$o" > "$t/reuse.log"
219+ [ "$?" = 3 ] && tail -n1 "$t/reuse.log" | grep -Fxq "fwprep FAILED makedir $o: File exists" || fail 1 "existing directory accepted"
220+ (cd "$o" && sha256sum -c "$t/sealed") >/dev/null || fail 1 "existing package modified"
221+ run "$t/fwprep" "$FW" "$OGKM" "$o" gb20b-extra > "$t/bad-profile.log" 2>&1
222+ [ "$?" = 1 ] && grep -Fxq 'usage: fwprep FWFILE OGKMSRC OUTDIR [gb20b]' "$t/bad-profile.log" || fail 1 "unknown profile accepted"
223+ echo "fw_diff: GB20B PASS (all five output files and manifest match, six negative controls)"
224+ exit 0
225+fi
226+
170227 # 1 truncated firmware (ends inside .fwsignature_gb10y)
171228 head -c 74985600 "$FW" > "$t/trunc.bin"
172229 cref trunc "$t/ck_gsp_fw_inspect" inspect "$t/trunc.bin"
@@ -229,6 +286,7 @@ neg=$((neg + 1))
229286 run "$t/fwprep" "$FW" "$OGKM" > /dev/null 2> "$t/usage.err"
230287 r=$?
231288 [ "$r" -eq 1 ] || fail 1 "control usage: fwprep exit $r, want 1"
232-grep -qx 'usage: fwprep FWFILE OGKMSRC OUTDIR' "$t/usage.err" || fail 1 "control usage: stderr"
289+grep -Fxq 'usage: fwprep FWFILE OGKMSRC OUTDIR [gb20b]' "$t/usage.err" || fail 1 "control usage: stderr"
233290 neg=$((neg + 1))
234291 echo "fw_diff: PASS ($n stdout lines and 6 files identical to the C referees; $neg/9 negative controls refused)"
292+sh "$0" gb20b || exit $?

tests/window_sim.sh

@@ -40,6 +40,7 @@ mkroot() {
4040 echo 0 > "$S/st/sysctl.kernel.panic"; echo 0 > "$S/st/sysctl.kernel.panic_on_oops"
4141 echo 0 > "$S/st/boots"; : > "$S/st/events"
4242 printf 'window: sim\nreset: approved\nreboot: approved\n' > "$S/home/handoffs/OwnDriver/window/APPROVED"
43+ case $1 in identity_*) echo "stage: W0" >> "$S/home/handoffs/OwnDriver/window/APPROVED" ;; esac
4344 shims "$S"
4445 cat > "$S/q36/start-35b-batch.sh" <<'EOF'
4546 #!/bin/sh
@@ -118,6 +119,13 @@ boot_power_on() {
118119 bind_nvidia "$S"; touch "$S/st/persistenced"
119120 fi
120121 if [ "$2" = 1 ] && [ -e "$S/st/unit-enabled" ] && [ -e "$S/etc/systemd/system/aien-owndriver-window.service" ]; then
122+ u=$S/etc/systemd/system/aien-owndriver-window.service
123+ if ! grep -Fxq "WorkingDirectory=$S/repo" "$u" || ! grep -Fxq 'ExecStart=/bin/sh ./window/d2-boot.sh' "$u"; then
124+ echo "invalid unit target" >> "$S/st/events"
125+ return 1
126+ fi
127+ [ ! -e "$S/st/add_ogd_after_boot" ] || touch "$S/build/ogd"
128+ [ ! -e "$S/st/alter_w0_after_boot" ] || echo '# changed' >> "$S/build/w0"
121129 echo "unit runs" >> "$S/st/events"
122130 (cd "$S/repo" && OWNDRIVER_WINDOW_ROOT=$S PATH="$S/bin:$PATH" sh "$S/repo/window/d2-boot.sh") > "$S/st/unit-$n.out" 2>&1 ||
123131 echo "unit exit $?" >> "$S/st/events"
@@ -139,6 +147,9 @@ run_window() {
139147 shims() {
140148 S=$1; B=$S/bin
141149 w() { printf '#!/bin/sh\nS=%s\nD=$S/sys/bus/pci/devices/%s\n%s\n' "$S" "$BDF" "$2" > "$B/$1"; chmod +x "$B/$1"; }
150+ w ss '[ ! -e "$S/st/ss_fail" ] || exit 1
151+[ ! -e "$S/st/unrecognized" ] || echo "LISTEN 0 1 127.0.0.1:18091"
152+exit 0'
142153 w sudo '[ "$1" = -n ] && shift
143154 exec "$@"'
144155 w systemctl 'echo "systemctl $*" >> $S/st/events
@@ -206,7 +217,8 @@ case $f in $S/dev/vfio/*) cat $S/st/modes/$(basename $f) ;; *) exec /usr/bin/sta
206217 nvgrace-gpu-vfio-pci) for a in 31C2 2941 2348 2345 2342; do echo "alias: pci:v000010DEd0000${a}sv*sd*bc*sc*i*"; done ;;
207218 *) exit 1 ;;
208219 esac'
209- w lsinitramfs 'echo usr/lib/modules/sim/kernel/drivers/vfio/pci/vfio-pci.ko'
220+ w lsinitramfs '[ ! -e "$S/st/initramfs_fail" ] || exit 1
221+echo usr/lib/modules/sim/kernel/drivers/vfio/pci/vfio-pci.ko'
210222 w spark-window 'echo free'
211223 }
212224
@@ -273,6 +285,49 @@ check "w0 ran on the device" "grep -q '^w0 000f:01:00.0 20' $S/st/events"
273285 check "W4/W5 logged NOT_RUN (no build/ogd)" "grep -q \"W-boot NOT_RUN\" $(L)/*-run.log && grep -q \"W-hello NOT_RUN\" $(L)/*-run.log"
274286 check "panic sysctls were 10/1 during W2" "grep -q 'sysctl kernel.panic=10 kernel.panic_on_oops=1' $S/st/events"
275287
288+CASE=identity_up; echo "case $CASE"; mkroot "$CASE"
289+run_window "$S" sh window/d2-pre.sh --go W0
290+boots 2; restored
291+check "identity ran exactly once" "test \$(grep -c '^w0 ' $S/st/events) = 1"
292+check "cleared identity receipts" "[ ! -e $(L)/identity-service ] && [ ! -e $(L)/identity-executable.sha256 ]"
293+
294+stop_sim_service() { kill "$(cat "$S/st/35b")"; rm -f "$S/st/35b"; }
295+CASE=identity_down; echo "case $CASE"; mkroot "$CASE"; stop_sim_service
296+run_window "$S" sh window/d2-pre.sh --go W0
297+boots 2
298+check "previously idle port kept idle" "! alive35b && test \$(grep -c '^start35b ' $S/st/events) = 1 && grep -q 'WINDOW CLOSED' $S/home/handoffs/BOARD.md"
299+
300+CASE=identity_foreign_service; echo "case $CASE"; mkroot "$CASE"
301+printf '%s\0' test-foreign-argument >> "$S/proc/$(cat "$S/st/35b")/cmdline"
302+run_window "$S" sh window/d2-pre.sh --go W0
303+boots 0; untouched
304+check "foreign command line kept out of logs" "! grep -rqs test-foreign-argument $(L) && grep -q 'another launch recipe' $(L)/*-pre.log"
305+
306+CASE=identity_downgrade; echo "case $CASE"; mkroot "$CASE"
307+run_window "$S" sh window/d2-pre.sh --go D2
308+boots 0; untouched
309+check "identity authorization refuses broader stage" "grep -q 'approval does not name this stage' $(L)/*-pre.log"
310+
311+for refusal in initramfs_fail ss_fail unrecognized ogd; do
312+ CASE=identity_$refusal; echo "case $CASE"; mkroot "$CASE"; stop_sim_service
313+ if [ "$refusal" = ogd ]; then touch "$S/build/ogd"; else touch "$S/st/$refusal"; fi
314+ run_window "$S" sh window/d2-pre.sh --go W0
315+ boots 0
316+ check "failed before arming the window" "grep -q 'cmd exit 1' $S/st/events && [ ! -e $(L)/state ] && [ ! -e $S/st/unit-enabled ]"
317+done
318+
319+for mutation in add_ogd_after_boot alter_w0_after_boot; do
320+ CASE=identity_$mutation; echo "case $CASE"; mkroot "$CASE"; touch "$S/st/$mutation"
321+ run_window "$S" sh window/d2-pre.sh --go W0
322+ boots 2; restored
323+ check "post-boot mutation refused before binding" "! grep -q '^bind vfio-pci' $S/st/events && ! grep -q '^w0 ' $S/st/events"
324+done
325+
326+CASE=identity_restore_failure; echo "case $CASE"; mkroot "$CASE"; echo 1 > "$S/st/nvidia_bad_boots"
327+run_window "$S" sh window/d2-pre.sh --go W0
328+boots 2
329+check "failed restore requests attended recovery" "grep -q 'Attended recovery required' $(L)/*-restore.log && test \"\$(cat $(L)/state)\" = 'restore W0'"
330+
276331 CASE=rebind; echo "case $CASE: D2 window, RESTORE_PATH=rebind"; mkroot $CASE
277332 run_window "$S" env RESTORE_PATH=rebind sh window/d2-pre.sh --go D2
278333 boots 1; restored
@@ -392,7 +447,7 @@ check "D3 exec ran in isolated simulator" "grep -q '^ogd exec$' $S/st/events"
392447 boots 2; restored
393448
394449 CASE=stale; echo "case $CASE: boot unit left over with no state"; mkroot $CASE
395-cp "$R/window/aien-owndriver-window.service" "$S/etc/systemd/system/"; touch "$S/st/unit-enabled"
450+sed "s|@CHECKOUT@|$S/repo|g" "$R/window/aien-owndriver-window.service" > "$S/etc/systemd/system/aien-owndriver-window.service"; touch "$S/st/unit-enabled"
396451 boot_power_on "$S" 1
397452 check "unit removed itself" "[ ! -e $S/etc/systemd/system/aien-owndriver-window.service ] && [ ! -e $S/st/unit-enabled ]"
398453 check "no driver change" "! grep -q 'bind vfio-pci' $S/st/events"

window/README.md

@@ -1,4 +1,4 @@
1-# OwnDriver window procedure (D2, D3)
1+# OwnDriver window procedure (W0 identity, D2, D3)
22
33 Status: **NOT_RUN** on the GB10. W0 has run read-only beside the live 35B (EXERCISED, host). Nothing in W1..W7
44 or R has touched the GB10. The unchanged scripts have run end to end against a simulated machine under /tmp
@@ -6,6 +6,12 @@ or R has touched the GB10. The unchanged scripts have run end to end against a s
66 the simulator must catch it). Every step below stops the resident 35B on 127.0.0.1:18091, resets the GPU and
77 reboots the Spark twice. It runs only in an exclusive window that Drake opens for this job.
88
9+## Identity-only window
10+
11+Use `sh window/d2-pre.sh --check W0` for the read-only preflight. The physical test uses `sh window/d2-pre.sh --go W0` and requires the existing approval record to include `stage: W0`. Keep the tested checkout in place through both reboots. It must contain the pinned `build/omc`, the matching `build/w0`, and no `build/ogd`. The temporary boot unit uses this checkout. A changed identity executable aborts the test before device binding.
12+
13+The identity step reads the PCI identity and three documented registers, then releases the device and requests a normal reboot. It records whether port 18091 was idle or held the recognized service. Restoration preserves that state. If the normal boot fails to restore the GPU, the script records the failure and leaves recovery to the operator. This mode budgets two reboots. A PASS in the simulator covers control flow only.
14+
915 ## What the window does to the machine
1016
1117 - **Two reboots.** nvidia.ko is held back for one boot so the GPU comes up without a driver. A live unload of

window/aien-owndriver-window.service

@@ -4,15 +4,15 @@
44 # which does nothing (and removes this unit) unless window/state says a step is pending. Status: NOT_RUN.
55 [Unit]
66 Description=aien OwnDriver window step after reboot (one-shot, removed at window close)
7-After=multi-user.target network-online.target
7+After=network-online.target
88 Wants=network-online.target
99
1010 [Service]
1111 Type=oneshot
1212 User=drakestapleton
1313 Environment=HOME=/home/drakestapleton
14-WorkingDirectory=/home/drakestapleton/work/OwnDriver/omega-gpu-driver
15-ExecStart=/bin/sh /home/drakestapleton/work/OwnDriver/omega-gpu-driver/window/d2-boot.sh
14+WorkingDirectory=@CHECKOUT@
15+ExecStart=/bin/sh ./window/d2-boot.sh
1616 # R starts the 35B from inside this unit: only the main process is stopped when the unit ends.
1717 KillMode=process
1818 TimeoutStartSec=3600

window/common.sh

@@ -13,7 +13,7 @@ ROOT=${OWNDRIVER_WINDOW_ROOT:-}
1313 if [ -n "$ROOT" ]; then
1414 case $ROOT in /tmp/*) ;; *) echo "OWNDRIVER_WINDOW_ROOT must be under /tmp" >&2; exit 2 ;; esac
1515 [ -e "$ROOT/.owndriver-window-sim" ] || { echo "$ROOT is not a window simulator root" >&2; exit 2; }
16- for c in sudo systemctl modprobe sysctl lsmod nvidia-smi pgrep curl tee stat fuser modinfo lsinitramfs spark-window; do
16+ for c in sudo systemctl modprobe sysctl lsmod nvidia-smi pgrep curl tee stat fuser modinfo lsinitramfs spark-window ss; do
1717 [ "$(command -v "$c")" = "$ROOT/bin/$c" ] || { echo "simulator: $c is not $ROOT/bin/$c" >&2; exit 2; }
1818 done
1919 HOMEDIR=$ROOT/home
@@ -46,6 +46,8 @@ APPROVAL=$LOGDIR/APPROVED
4646 # sysctl values W2 changes; SNAP is the live 35B launch record W0 checks the restore recipe against;
4747 # RPATH holds "rebind" if W1 was asked for RESTORE_PATH=rebind; PRIVBASE is the privilege baseline (W0).
4848 STATE=$LOGDIR/state
49+IDENTITY=$LOGDIR/identity-service
50+W0SUM=$LOGDIR/identity-executable.sha256
4951 SAVED=$LOGDIR/saved-sysctl
5052 SNAP=$LOGDIR/live-35b.snapshot
5153 RPATH=$LOGDIR/restore-path
@@ -68,6 +70,9 @@ need_approval() {
6870 grep -q '^window: ..*' "$APPROVAL" || die "$APPROVAL lacks a 'window: <Drake's words>' line"
6971 grep -qx 'reset: approved' "$APPROVAL" || die "$APPROVAL lacks 'reset: approved' (VFIO bind/release resets the GPU)"
7072 grep -qx 'reboot: approved' "$APPROVAL" || die "$APPROVAL lacks 'reboot: approved' (the window reboots the Spark twice)"
73+ if [ "$STAGE" = W0 ] || grep -q '^stage:' "$APPROVAL"; then
74+ [ "$(sed -n 's/^stage: //p' "$APPROVAL")" = "$STAGE" ] || die "approval does not name this stage"
75+ fi
7176 log "approval: $(grep '^window: ' "$APPROVAL" | head -1)"
7277 }
7378

window/d2-boot.sh

@@ -10,7 +10,8 @@ LOG=$LOGDIR/d2-$(date -u +%Y%m%dT%H%M%SZ)-boot.log
1010 s=$(cat "$STATE" 2>/dev/null || true)
1111 log "boot unit: state '$s'"
1212 case $s in
13-"run D2" | "run D3") exec sh "$R/window/d2-run.sh" --go "${s#run }" ;;
13+"run W0" | "run D2" | "run D3") exec sh "$R/window/d2-run.sh" --go "${s#run }" ;;
14+"restore W0") exec sh "$R/window/d2-restore.sh" --go W0 ;;
1415 restore) exec sh "$R/window/d2-restore.sh" --go ;;
1516 *)
1617 sudo -n systemctl disable aien-owndriver-window.service >/dev/null 2>&1 || true

window/d2-pre.sh

@@ -1,6 +1,7 @@
11 #!/bin/sh
22 # window/d2-pre.sh -- W0 and W1 of the OwnDriver window. Status: W0 EXERCISED read-only on the host; W1 NOT_RUN.
33 # no argument: W0, read-only checks, safe while the 35B runs. Changes nothing except its own log.
4+# --go W0: identity only, previously running service restored, two reboots at most.
45 # --go [D2|D3]: W1, needs $APPROVAL. Stops the 35B on 18091, writes the one-boot nvidia hold-back file and the
56 # boot unit, sets state "run D2" (default) or "run D3", reboots. The unit then runs W2.. by itself
67 # (window/d2-run.sh), and after the second reboot R (window/d2-restore.sh).
@@ -11,6 +12,11 @@ R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
1112 LOG=$LOGDIR/d2-$(date -u +%Y%m%dT%H%M%SZ)-pre.log
1213 GO=${1:-}
1314 STAGE=${2:-D2}
15+case $STAGE in W0 | D2 | D3) ;; *) die "stage must be W0, D2 or D3" ;; esac
16+if [ "$STAGE" = W0 ]; then
17+ [ ! -e "$BUILD/ogd" ] && [ ! -L "$BUILD/ogd" ] || die "identity-only checkout contains build/ogd"
18+ [ "${RESTORE_PATH:-reboot}" = reboot ] || die "identity-only window requires reboot restore"
19+fi
1420
1521 log "W0 checks (repo $(git -C "$R" rev-parse HEAD 2>/dev/null || echo no-git), dirty files: $(git -C "$R" status --porcelain 2>/dev/null | wc -l))"
1622 echo "$FW_SHA $FW" | sha256sum -c --quiet || die "firmware sha256 mismatch"
@@ -44,7 +50,7 @@ log "device $(cat "$DEV/vendor"):$(cat "$DEV/device") driver=$(drv) reset_method
4450 log "modules: $(lsmod | awk '/^nvidia/{printf "%s(%s) ", $1, $3}')"
4551 log "cmdline: $(cat /proc/cmdline)"
4652 log "sysctl: kernel.panic=$(sysctl -n kernel.panic) kernel.panic_on_oops=$(sysctl -n kernel.panic_on_oops)"
47-for f in "$HOLD" "$UNIT" "$STATE"; do
53+for f in "$HOLD" "$UNIT" "$STATE" "$IDENTITY" "$W0SUM"; do
4854 [ ! -e "$f" ] || die "$f already exists (an earlier window did not finish): run window/d2-restore.sh --go"
4955 done
5056 # No window is open (checked above), so the current privilege state is the baseline R4 must return to.
@@ -60,13 +66,25 @@ if modinfo nvgrace-gpu-vfio-pci 2>/dev/null | grep -qi 'd00002E12'; then
6066 die "nvgrace-gpu-vfio-pci now lists 2E12: re-decide variant vs plain vfio-pci before binding"
6167 fi
6268 log "nvgrace-gpu-vfio-pci aliases ($(modinfo nvgrace-gpu-vfio-pci 2>/dev/null | grep -c '^alias')) do not list 10de:2e12: plain vfio-pci"
63-if lsinitramfs "/boot/initrd.img-$(uname -r)" | grep -Eq '/nvidia(_uvm|_modeset|_drm)?\.ko'; then
69+listing=$(mktemp "$LOGDIR/initramfs.XXXXXX")
70+if ! lsinitramfs "/boot/initrd.img-$(uname -r)" > "$listing" || [ ! -s "$listing" ]; then
71+ rm -f "$listing"
72+ die "could not inspect initramfs"
73+fi
74+if grep -Eq '/nvidia(_uvm|_modeset|_drm)?\.ko' "$listing"; then
75+ rm -f "$listing"
6476 die "initramfs carries nvidia.ko: a modprobe.d hold-back would not be enough"
6577 fi
78+rm -f "$listing"
6679 log "initramfs has no nvidia/nvidia_uvm/nvidia_modeset/nvidia_drm"
6780 modinfo -n vfio-pci >/dev/null 2>&1 || die "vfio-pci module not available"
6881 p=$(live_pid)
69-if [ -n "$p" ]; then
82+if [ -n "$p" ] && [ "$STAGE" = W0 ]; then
83+ # An unrelated service can have sensitive command-line options. Compare in memory.
84+ [ "$(snap35b "$p")" = "$(snap_expected)" ] || die "port 18091 belongs to another launch recipe. Wait for its owner"
85+ snap_expected > "$SNAP"
86+ log "35B pid $p matches the restore recipe"
87+elif [ -n "$p" ]; then
7088 snap35b "$p" > "$SNAP.now"
7189 snap_expected > "$SNAP.want"
7290 if cmp -s "$SNAP.now" "$SNAP.want"; then
@@ -77,7 +95,7 @@ if [ -n "$p" ]; then
7795 die "the live 35B was not started the way d2-restore.sh restarts it: update snap_expected and R3 first"
7896 fi
7997 else
80- log "35B not running (restore will start it from the recipe)"
98+ log "35B not running"
8199 fi
82100 log "GPU device users: $(sudo -n fuser "$ROOT"/dev/nvidia* 2>/dev/null | tr -s ' ' | tr ' ' '\n' | sort -u | while read -r q; do [ -n "$q" ] && printf '%s(%s) ' "$q" "$(cat "$PROC/$q/comm" 2>/dev/null)"; done)"
83101 log "chip lock (read from the kernel lock table, not taken): $(spark-window locks gb10 2>&1 | head -2 | tr '\n' ' ')"
@@ -88,10 +106,16 @@ if [ "$GO" != --go ]; then
88106 fi
89107
90108 # W1 --------------------------------------------------------------------------
91-case $STAGE in D2 | D3) ;; *) die "stage must be D2 or D3" ;; esac
109+# Only substitute checkout paths that are literal in both sed and systemd.
110+case $R in *[!a-zA-Z0-9/._-]* | /) die "unsupported checkout path in temporary boot unit" ;; esac
111+[ -r "$R/window/d2-boot.sh" ] || die "boot helper is missing"
112+rendered=$(sed "s|^WorkingDirectory=@CHECKOUT@$|WorkingDirectory=$R|" "$R/window/aien-owndriver-window.service")
113+printf '%s\n' "$rendered" | grep -Fxq "WorkingDirectory=$R" || die "could not render boot unit"
92114 need_approval
93115 # build/ogd is optional: without it the window runs W2, W3 (build/w0), W7 and R, and logs the driver steps NOT_RUN.
116+if [ "$STAGE" != W0 ]; then
94117 [ "$STAGE" = D2 ] || has_mode exec || die "D3 needs build/ogd with a successful exact 'exec' mode"
118+fi
95119 case ${RESTORE_PATH:-reboot} in
96120 reboot) rm -f "$RPATH" ;;
97121 rebind) echo rebind > "$RPATH" ;;
@@ -106,6 +130,21 @@ fi
106130 # The chip lock: no other GPU job may be running; it is held until the reboot ends this process.
107131 exec 9>>"$GB10_LOCK"
108132 flock -n 9 || die "$GB10_LOCK is held by another GPU job: wait for it"
133+if [ "$STAGE" = W0 ]; then
134+ p=$(live_pid)
135+ if [ -n "$p" ]; then
136+ [ "$(snap35b "$p")" = "$(snap_expected)" ] || die "service changed before the identity window"
137+ before=up
138+ else
139+ listeners=$(ss -Hltn 'sport = :18091') || die "could not inspect port 18091"
140+ [ -z "$listeners" ] || die "unrecognized listener on port 18091"
141+ before=down
142+ fi
143+ apps=$(nvidia-smi --query-compute-apps=pid --format=csv,noheader) || die "could not inspect GPU clients"
144+ [ -z "$apps" ] || [ "$apps" = "$p" ] || die "another GPU client is active"
145+ sha256sum "$BUILD/w0" > "$W0SUM" || die "could not seal identity executable"
146+ echo "$before" > "$IDENTITY"
147+fi
109148 abort_w1() {
110149 rc=$?
111150 trap - EXIT
@@ -113,7 +152,7 @@ abort_w1() {
113152 sudo -n systemctl disable aien-owndriver-window.service >/dev/null 2>&1 || true
114153 sudo -n rm -f "$HOLD" "$UNIT"
115154 sudo -n systemctl daemon-reload || true
116- echo restore > "$STATE"
155+ if [ "$STAGE" = W0 ]; then echo "restore W0" > "$STATE"; else echo restore > "$STATE"; fi
117156 log "W1 aborted before reboot (rc=$rc); window files removed; restoring the 35B"
118157 sh "$R/window/d2-restore.sh" --go || true
119158 }
@@ -121,7 +160,11 @@ trap 'abort_w1' EXIT
121160
122161 touch "$LIVE_MARKER"
123162 board "WINDOW OPEN $STAGE (own driver): stopping 18091, reboot with nvidia held back; every agent session on the Spark ends at the reboot. Log $LOG"
124-p=$(live_pid)
163+if [ "$STAGE" = W0 ]; then
164+ [ "$(live_pid)" = "$p" ] || die "service changed while arming the identity window"
165+else
166+ p=$(live_pid)
167+fi
125168 if [ -n "$p" ]; then
126169 log "TERM 35B pid $p"
127170 kill -TERM "$p"
@@ -145,14 +188,14 @@ install nvidia_uvm /bin/false
145188 install nvidia_modeset /bin/false
146189 install nvidia_drm /bin/false
147190 EOF
148-sudo -n cp "$R/window/aien-owndriver-window.service" "$UNIT"
191+printf '%s\n' "$rendered" | sudo -n tee "$UNIT" >/dev/null
149192 sudo -n chmod 0644 "$UNIT"
150193 sudo -n systemctl daemon-reload
151194 sudo -n systemctl enable aien-owndriver-window.service
152195 echo "run $STAGE" > "$STATE"
153196 log "wrote $HOLD, installed and enabled $UNIT, state 'run $STAGE'"
154-trap - EXIT
155197 board "$STAGE W1: rebooting with nvidia held back; the boot unit runs window/d2-run.sh, then R after the next reboot"
156198 sync
157199 log "reboot"
158200 sudo -n systemctl reboot
201+trap - EXIT

window/d2-restore.sh

@@ -15,13 +15,27 @@ R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
1515 . "$R/window/common.sh"
1616 LOG=$LOGDIR/d2-$(date -u +%Y%m%dT%H%M%SZ)-restore.log
1717 [ "${1:-}" = --go ] || { echo "usage: $0 --go"; exit 2; }
18-echo restore > "$STATE"
18+was=$(cat "$STATE" 2>/dev/null || true)
19+is_identity=false
20+if [ "${2:-}" = W0 ] || [ "$was" = "restore W0" ] || [ "$was" = "run W0" ] || [ -e "$IDENTITY" ] || [ -e "$W0SUM" ]; then
21+ is_identity=true
22+ echo "restore W0" > "$STATE"
23+else
24+ echo restore > "$STATE"
25+fi
1926 # Any refusal leaves state "restore" and the unit in place (the next boot tries R again) and says so on BOARD.
2027 trap 'rc=$?; [ "$rc" -eq 0 ] || board "restore STOPPED rc=$rc, 18091 may be down, log $LOG (page Main; next boot retries R)"' EXIT
2128
2229 # R0 -------------------------------------------------------------------------
30+# Identity windows have a two-reboot budget. A failed restore leaves evidence for attended recovery.
31+identity_state=
32+if "$is_identity"; then
33+ identity_state=$(cat "$IDENTITY") || die "identity service record unavailable"
34+ case $identity_state in up | down) ;; *) die "invalid identity service record" ;; esac
35+fi
2336 if [ -e "$HOLD" ]; then
2437 sudo -n rm -f "$HOLD"
38+ [ -z "$identity_state" ] || die "removed remaining hold-back. Attended recovery required"
2539 log "R0 hold-back file was still present: removed; rebooting; the boot unit runs R again"
2640 board "restore: hold-back file was still present, removed, rebooting"
2741 sync
@@ -32,6 +46,7 @@ fi
3246 # R1 -------------------------------------------------------------------------
3347 FALLBACK=$LOGDIR/reboot-fallback-used
3448 fallback() {
49+ [ -z "$identity_state" ] || die "identity restore failed: $*. Attended recovery required"
3550 if [ -e "$FALLBACK" ]; then
3651 board "restore FAILED after the reboot fallback: $* (page Main and Drake; GPU state unknown; log $LOG)"
3752 die "$* after the reboot fallback already ran"
@@ -66,6 +81,12 @@ fi
6681 log "R2 persistenced $(systemctl is-active nvidia-persistenced); kernel.panic=$(sysctl -n kernel.panic) panic_on_oops=$(sysctl -n kernel.panic_on_oops)"
6782
6883 # R3 -------------------------------------------------------------------------
84+if [ "$identity_state" = down ]; then
85+ listeners=$(ss -Hltn 'sport = :18091') || die "could not inspect restored port"
86+ [ -z "$listeners" ] && [ -z "$(live_pid)" ] || die "unexpected service on port 18091"
87+ apps="port 18091 was and remains idle"
88+ log "R3 $apps"
89+else
6990 if [ -z "$(live_pid)" ]; then
7091 K=$(cat "$Q36_KEY")
7192 Q36_BATCH_BIN=$Q36_BIN AIEN_Q36_STROKE=1 AIEN_SERVE_GPU_LOCK=/tmp/aien-serve-18091.lock AIEN_COORD_KEY="$K" \
@@ -83,16 +104,21 @@ out=$(curl -fsS --max-time 120 http://127.0.0.1:18091/v1/chat/completions -H 'Co
83104 log "R3 greedy chat: $out"
84105 p=$(live_pid)
85106 snap35b "$p" > "$SNAP.restored"
86-snap_expected | cmp -s - "$SNAP.restored" || log "R3 WARNING: restarted 35B launch record differs from the recipe (see $SNAP.restored)"
107+if ! snap_expected | cmp -s - "$SNAP.restored"; then
108+ [ "$identity_state" != up ] || die "running service differs from its pre-window snapshot"
109+ log "R3 WARNING: restarted 35B launch record differs from the recipe (see $SNAP.restored)"
110+fi
87111 apps=$(nvidia-smi --query-compute-apps=process_name,used_memory --format=csv,noheader)
88112 log "R3 compute apps: $apps"
89113 [ "$(printf '%s\n' "$apps" | grep -c aien-serve-http)" -eq 1 ] || die "expected exactly one aien-serve-http on the GPU"
90114
115+fi
116+
91117 # R4 -------------------------------------------------------------------------
92118 sudo -n systemctl disable aien-owndriver-window.service >/dev/null 2>&1 || true
93119 sudo -n rm -f "$UNIT"
94120 sudo -n systemctl daemon-reload
95121 privcheck || { board "PRIVILEGE PERSISTED after the window, see $LOG (page Main)"; die "privilege state not clean"; }
96-rm -f "$LIVE_MARKER" "$APPROVAL" "$FALLBACK" "$SAVED" "$RPATH" "$LOGDIR/d3-cmd" "$STATE"
122+rm -f "$LIVE_MARKER" "$APPROVAL" "$FALLBACK" "$SAVED" "$IDENTITY" "$W0SUM" "$RPATH" "$LOGDIR/d3-cmd" "$STATE"
97123 board "WINDOW CLOSED (own driver), 18091 restored ($(printf '%s' "$apps" | tr '\n' ' ')). Log $LOG"
98124 log "R PASS"

window/d2-run.sh

@@ -1,5 +1,5 @@
11 #!/bin/sh
2-# window/d2-run.sh --go D2|D3 -- W2..W7, run by the boot unit after the reboot that d2-pre.sh --go started.
2+# window/d2-run.sh --go W0|D2|D3 -- W2..W7, run by the boot unit after the reboot that d2-pre.sh --go started.
33 # Status: NOT_RUN.
44 # W2 state "restore" and remove the hold-back file FIRST (any later reboot is a normal one that ends in R),
55 # check no nvidia module, kernel.panic=10 + panic_on_oops=1 (an oops reboots into R), bind vfio-pci
@@ -18,9 +18,9 @@ set -eu
1818 R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
1919 . "$R/window/common.sh"
2020 LOG=$LOGDIR/d2-$(date -u +%Y%m%dT%H%M%SZ)-run.log
21-[ "${1:-}" = --go ] || { echo "usage: $0 --go D2|D3 (window only)"; exit 2; }
21+[ "${1:-}" = --go ] || { echo "usage: $0 --go W0|D2|D3 (window only)"; exit 2; }
2222 STAGE=${2:-}
23-case $STAGE in D2 | D3) ;; *) echo "usage: $0 --go D2|D3"; exit 2 ;; esac
23+case $STAGE in W0 | D2 | D3) ;; *) echo "usage: $0 --go W0|D2|D3"; exit 2 ;; esac
2424
2525 # W2 -------------------------------------------------------------------------
2626 release() {
@@ -31,7 +31,7 @@ release() {
3131 echo | sudo -n tee "$DEV/driver_override" >/dev/null || true
3232 pm_auto
3333 log "W7 driver=$(drv) override='$(cat "$DEV/driver_override")' power=$(cat "$DEV/power/control")"
34- if [ "$(cat "$RPATH" 2>/dev/null || true)" = rebind ]; then
34+ if [ "$STAGE" != W0 ] && [ "$(cat "$RPATH" 2>/dev/null || true)" = rebind ]; then
3535 board "$STAGE run ended rc=$rc, log $LOG; restoring by rebind (reboot fallback inside d2-restore)"
3636 exec sh "$R/window/d2-restore.sh" --go
3737 fi
@@ -40,7 +40,11 @@ release() {
4040 sudo -n systemctl reboot
4141 }
4242 # From here on every exit, including a refusal below, goes through W7 and ends in R.
43+if [ "$STAGE" = W0 ]; then
44+ echo "restore W0" > "$STATE"
45+else
4346 echo restore > "$STATE"
47+fi
4448 trap release EXIT
4549 sudo -n rm -f "$HOLD"
4650 [ ! -e "$HOLD" ] && log "W2 ($STAGE) state 'restore'; hold-back removed: the next boot loads nvidia again and runs R" ||
@@ -50,7 +54,13 @@ exec 9>>"$GB10_LOCK"
5054 flock -n 9 || die "$GB10_LOCK is held: something started a GPU job after the reboot"
5155 if [ "$(nv_modules)" -ne 0 ]; then die "nvidia is loaded: the hold-back did not take"; fi
5256 # Recheck after reboot, but only after recovery is armed and before any VFIO binding.
53-[ "$STAGE" = D2 ] || has_mode exec || die "D3 needs build/ogd with a successful exact 'exec' mode"
57+if [ "$STAGE" = W0 ]; then
58+ case $(cat "$IDENTITY") in up | down) ;; *) die "missing identity service state" ;; esac
59+ [ ! -e "$BUILD/ogd" ] && [ ! -L "$BUILD/ogd" ] || die "identity-only checkout contains build/ogd"
60+ sha256sum -c --quiet "$W0SUM" || die "identity executable changed"
61+else
62+ [ "$STAGE" = D2 ] || has_mode exec || die "D3 needs build/ogd with a successful exact 'exec' mode"
63+fi
5464
5565
5666 sudo -n sysctl -q kernel.panic=10 kernel.panic_on_oops=1
@@ -75,6 +85,10 @@ log "W2 PASS: $BDF on vfio-pci, /dev/vfio/$GRP root:root:600 (programs run as ro
7585 # W3 -------------------------------------------------------------------------
7686 pm_on
7787 run_logged sudo -n "$BUILD/w0" "$BDF" "$GRP"
88+if [ "$STAGE" = W0 ]; then
89+ log "W3 PASS: identity read; closing the identity-only window"
90+ exit 0
91+fi
7892 if has_mode ident; then
7993 pm_on
8094 run_logged sudo -n "$BUILD/ogd" ident "$BDF" "$GRP" "$FW" "$BUILD/fw"