diff --git a/docs/speculation/TEARDOWN-HOST.md b/docs/speculation/TEARDOWN-HOST.md index 531ba2cb..4a2c2554 100644 --- a/docs/speculation/TEARDOWN-HOST.md +++ b/docs/speculation/TEARDOWN-HOST.md @@ -21,6 +21,12 @@ cleanup latches `nvfault`; successful cleanup does not make the context reusable Descriptor numbers are retired after their first close attempt, including an error, so a subsequent call cannot close a newly reused descriptor number. +The same ownership rule applies before `nvcpumap` publishes a mapping to its +caller. If descriptor close fails and its immediate unmap is refused, +`nvunpub` retains that mapping for `nvmapfinish`. A faulted or inactive +context refuses another `nvcpumap`, so the retained handle cannot be overwritten. +Failed `mapbind` is different: the pinned compiler contract retires that handle. + ## Fixture and isolation The handwritten `tests/speculation/teardown-host-test.om` runs the actual @@ -32,6 +38,9 @@ The disclosed shell composer replaces only these OS effects: - Device opens become an immediate test assertion failure. - Unmap and close become stateful fakes that count calls, reject double release, and can refuse an otherwise valid synthetic mapping. +- The unpublished-mapping case allows one synthetic descriptor open and replaces + `mapnew` with a fake that returns a fourth owned mapping; no real mapping or + device open is performed. The composer refuses an unbound device/open/close/unmap verb. It never changes the tracked runtime file. The fixture does not open `/dev/nvidia*`, allocate GPU @@ -47,6 +56,10 @@ Retries must make no extra descriptor closes or driver calls. The context fault must remain set, and `nvstart` must still refuse reuse. A direct `nvmforce` call while driver resources are live must refuse without changing ownership flags, handles, addresses or lengths and without making an OS effect. +The additional close-error/unmap-refusal case checks that the unpublished +mapping survives two shutdown attempts, is released on a later successful +retry, and is never double-unmapped. It also checks refusal of another mapping +attempt while that context is faulted. ## Reproduction @@ -62,13 +75,23 @@ sh tests/speculation/run-teardown-host.sh /absolute/path/to/pinned-omc The script retains a private temporary directory with exact source units, ELF files, compiler logs, stdout/stderr, exit statuses, and hashes. It compiles the -original `5e037c7e3d0226abadaa10af9d44bc6339109b3f` context with the same fixture +original `f9cd649c1dca92ad81009bcd05a959f34c25c76e` context with the same fixture first: it must fail by a test assertion (exit 1), not compilation error, trap or timeout. The repaired source must then compile and exit 0 with the PASS marker. An unsupported host returns 77 and `NOT_RUN`; it is not a test pass. ## Current qualification limit +The source-compatibility review uses the exact pinned `seed/omc/omc.om`, not +a different compiler profile. Its `topname` and `s_fn` readers limit globals, +texts and parameter names to eight bytes; function names may be 63 bytes. +The initial source review missed overlong names in both this repair and the +inherited fixture. They are now shortened without changing cleanup behavior. +The fixture's custom calls use scalar arguments only; the compiler's prohibition +on passing globals to ordinary `view`/`edit` parameters does not apply to them. +The `tmapnew` fake preserves the native word's five scalar types and long result. +This is source inspection, not evidence that either unit compiles or executes. + Native compilation and execution are **NOT_RUN** in the merge-review workspace, which is x86_64 and has no runnable AArch64 compiler or emulator. The fixture and repair remain candidates for source review and supported-host qualification. diff --git a/native/nvrm/context.om b/native/nvrm/context.om index 8127efde..5280fea0 100644 --- a/native/nvrm/context.om +++ b/native/nvrm/context.om @@ -27,6 +27,8 @@ global nvbar long 1 global nvfifo long 1 global nvnotify long 1 global nvchva long 1 +note A mapping not yet published to its caller remains owned after failed cleanup. +global nvunpub long 1 global nvtoken uint 1 global nvchreg uchar 1 global nvsched uchar 1 @@ -249,6 +251,15 @@ put nverr 0 neg long 16 ret false end ok = true +if gt get nvunpub 0 0 +r = mapdrop get nvunpub 0 +if ne r 0 +put nverr 0 r +ok = false +else +put nvunpub 0 0 +end +end if gt get nvbar 0 0 r = mapdrop get nvbar 0 if ne r 0 @@ -434,6 +445,10 @@ end note Low GPU command addresses are reserved without replacement before an owned bind. note BAR mappings may use Linux-selected addresses; GPU buffers stay below 40 bits. fn nvcpumap obj uint size ulong system bool flags uint to long +if or ne get nvfault 0 0 ne get nvstate 0 1 +put nverr 0 neg long 5 +ret neg long 1 +end fd = neg long 1 if system fd = fopen nvctl 0 len nvctl 524290 0 @@ -489,6 +504,9 @@ put nverr 0 r put nvfault 0 1 if gt m 0 r = mapdrop m +if ne r 0 +put nvunpub 0 m +end end ret neg long 1 end diff --git a/tests/speculation/run-teardown-host.sh b/tests/speculation/run-teardown-host.sh index 382647c8..305ab30d 100755 --- a/tests/speculation/run-teardown-host.sh +++ b/tests/speculation/run-teardown-host.sh @@ -21,7 +21,7 @@ fi root=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd) || exit 74 out=$(mktemp -d "${TMPDIR:-/tmp}/cudapp-teardown-host.XXXXXX") || exit 74 echo "Native-host test outputs: $out" -base=5e037c7e3d0226abadaa10af9d44bc6339109b3f +base=f9cd649c1dca92ad81009bcd05a959f34c25c76e git -C "$root" show "$base:native/nvrm/context.om" > "$out/before.om" || exit 74 cp "$root/native/nvrm/context.om" "$out/after.om" || exit 74 for arm in before after; do @@ -29,11 +29,11 @@ for arm in before after; do awk ' $2 == "=" && ($3 == "devcall" || $3 == "devctl" || $3 == "uvmctl") { print $1 " = tdriver"; next } $2 == "=" && $3 == "fopen" { print $1 " = tunexpected"; next } - { for (i=1; i<=NF; i++) { if ($i == "mapdrop") $i="tdrop"; if ($i == "fclose") $i="tclose" }; print } + { for (i=1; i<=NF; i++) { if ($i == "mapdrop") $i="tdrop"; if ($i == "fclose") $i="tclose"; if ($i == "mapnew") $i="tmapnew" }; print } ' "$out/$arm.om" > "$out/$arm-unit.om" || exit 74 cat "$root/tests/speculation/teardown-host-test.om" >> "$out/$arm-unit.om" || exit 74 # A new or differently shaped device effect must not silently escape the shim. - awk '$1 != "note" { for (i=1; i<=NF; i++) if ($i == "devcall" || $i == "devctl" || $i == "uvmctl" || $i == "fopen" || $i == "fclose" || $i == "mapdrop") exit 1 }' "$out/$arm-unit.om" || { + awk '$1 != "note" { for (i=1; i<=NF; i++) if ($i == "devcall" || $i == "devctl" || $i == "uvmctl" || $i == "fopen" || $i == "fclose" || $i == "mapdrop" || $i == "mapnew") exit 1 }' "$out/$arm-unit.om" || { echo 'REFUSED: unbound OS effect in teardown fixture' >&2 exit 69 } diff --git a/tests/speculation/teardown-host-test.om b/tests/speculation/teardown-host-test.om index 455a1bdc..7e228796 100644 --- a/tests/speculation/teardown-host-test.om +++ b/tests/speculation/teardown-host-test.om @@ -2,13 +2,16 @@ note SPDX-License-Identifier: AGPL-3.0-only note Synthetic host refusal fixture. The private unit replaces device calls, close and mapdrop. note No GPU file is opened and no kernel, model, or hardware result is claimed. global tchecks ulong 1 -global tblocked uchar 3 -global tlive uchar 3 -global tdrops ulong 3 +global tblocked uchar 4 +global tlive uchar 4 +global tdrops ulong 4 +global tmapmode uchar 1 +global tmclose ulong 1 +global tmopen ulong 1 global tcloses ulong 2 -global tdrivercalls ulong 1 -global tdriverfail uchar 1 -global tclosefail uchar 1 +global tdcalls ulong 1 +global tdfail uchar 1 +global tcfail uchar 1 text tok "NATIVE_TEARDOWN_HOST_PASS\n" text tbad "NATIVE_TEARDOWN_HOST_FAIL\n" fn tcheck yes bool to void @@ -19,21 +22,35 @@ exit int 1 end end fn tunexpected to long +if ne get tmapmode 0 0 +put tmopen 0 add get tmopen 0 1 +ret 42 +end tcheck false ret neg long 5 end +fn tmapnew fd int offset ulong size ulong access int mode int to long +tcheck eq get tmapmode 0 1 +tcheck eq fd 42 +tcheck eq offset 0 +tcheck eq size 4096 +tcheck eq access 3 +tcheck eq mode 1 +put tlive 3 1 +ret 14 +end fn tdriver to long note A retry after descriptor closure must never issue another RM or UVM call. tcheck eq get nvstate 0 1 -put tdrivercalls 0 add get tdrivercalls 0 1 -if ne get tdriverfail 0 0 -put tdriverfail 0 0 +put tdcalls 0 add get tdcalls 0 1 +if ne get tdfail 0 0 +put tdfail 0 0 ret neg long 11 end ret 0 end fn tdrop m long to long -tcheck and ge m 11 le m 13 +tcheck and ge m 11 le m 14 i = ulong sub m 11 tcheck eq get tlive i 1 put tdrops i add get tdrops i 1 @@ -44,12 +61,17 @@ put tlive i 0 ret 0 end fn tclose fd int to long +if eq fd 42 +put tmclose 0 add get tmclose 0 1 +tcheck eq get tmclose 0 1 +ret neg long 5 +end tcheck and ge fd 40 le fd 41 i = ulong sub fd 40 put tcloses i add get tcloses i 1 note A descriptor number could be reused after the first close, even if close reports an error. tcheck eq get tcloses i 1 -if and eq i 0 ne get tclosefail 0 0 +if and eq i 0 ne get tcfail 0 0 ret neg long 5 end ret 0 @@ -81,9 +103,9 @@ end for i ulong 2 put tcloses i 0 end -put tdrivercalls 0 0 -put tdriverfail 0 0 -put tclosefail 0 0 +put tdcalls 0 0 +put tdfail 0 0 +put tcfail 0 0 put nverr 0 0 put nvfault 0 0 put nvstate 0 1 @@ -146,29 +168,29 @@ for i ulong len nvfd tcheck eq get nvfd i neg int 1 end end -fn tretry which ulong driver_refusal bool to void +fn tretry which ulong drvfail bool to void tprepare put tblocked which 1 -if driver_refusal +if drvfail note Refuse channel destruction before its handles retire; retry must not free them through closed fds. put nvobj 6 101 put nvobj 8 102 put nvobj 9 103 -put tdriverfail 0 1 +put tdfail 0 1 end tcheck not nvstop tretained which -before = get tdrivercalls 0 +before = get tdcalls 0 tcheck not nvstop tretained which -tcheck eq get tdrivercalls 0 before +tcheck eq get tdcalls 0 before for i ulong 2 tcheck eq get tcloses i 1 end put tblocked which 0 tcheck nvstop tclosed -tcheck eq get tdrivercalls 0 before +tcheck eq get tdcalls 0 before tcheck eq get nvfault 0 1 tcheck not nvstart tcheck eq get nverr 0 neg long 5 @@ -198,10 +220,46 @@ end for i ulong 2 tcheck eq get tcloses i 0 end -tcheck eq get tdrivercalls 0 0 +tcheck eq get tdcalls 0 0 tcheck nvstop tclosed end +fn tunpublished to void +note Close fails after mapping succeeds; a refused unmap must remain reachable. +tprepare +put tmapmode 0 1 +put tmopen 0 0 +put tmclose 0 0 +put tblocked 3 1 +put tdrops 3 0 +put tlive 3 0 +tcheck eq nvcpumap 201 4096 false 0 neg long 1 +tcheck eq get tmopen 0 1 +tcheck eq get tmclose 0 1 +tcheck eq get tlive 3 1 +tcheck eq get tdrops 3 1 +tcheck eq get nvfault 0 1 +tcheck not nvstop +tcheck eq get nvstate 0 2 +tcheck eq get tlive 3 1 +note A faulted caller cannot overwrite the quarantined handle or reopen a descriptor. +tcheck eq nvcpumap 202 4096 false 0 neg long 1 +tcheck eq get tmopen 0 1 +before = get tdcalls 0 +tcheck not nvstop +tcheck eq get tdcalls 0 before +tcheck eq get tmclose 0 1 +put tblocked 3 0 +tcheck nvstop +tclosed +tcheck eq get tlive 3 0 +tcheck eq get nvfault 0 1 +count = get tdrops 3 +tcheck nvstop +tcheck eq get tdrops 3 count +tcheck not nvstart +put tmapmode 0 0 +end fn main to int note Closed contexts stay idempotent without touching descriptors or mappings. tcheck nvstop @@ -221,13 +279,14 @@ tretry 1 true tphaseguard note An error from the descriptor close must latch the fault without retrying that descriptor. tprepare -put tclosefail 0 1 +put tcfail 0 1 tcheck not nvstop tclosed tcheck eq get nvfault 0 1 tcheck nvstop tclosed tcheck not nvstart +tunpublished tcheck eq write 1 tok 0 len tok long len tok ret 0 end