diff --git a/AGENTS.md b/AGENTS.md index ef15a74d..178eada4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -43,7 +43,7 @@ We are building a clean-room Rust driver that matches the **exact behavior** of - Keep evidence categories strictly separate in notes and reports (`[T]`/`[O]` observed original behavior, `[A]`/`[D]`/`[E]` static/emulated analysis, guest QEMU tests, replacement hardware execution). 4. **Validation gate.** - - Always pass 31/31 `tools/validate_all.sh` (including `check_kernel_module.py`: 0 GOT relocations, 0 `memcpy`/`memset`/`memmove`, stack <= 1,024 bytes, no SIMD, and `tests/kernel-module-gate/test_gate_cases.py`: while IBT is enforced, every data relocation that resolves to code must resolve to an instruction boundary and a target's entity is identified from the ELF tables rather than from a printed name (including the header-0 escape fields for extended section numbering, and a raw reserved `st_shndx` read as a special value rather than a section reference), so a printed form belonging to two entities, a shared truncation or a duplicate full name, is refused as unattributable, and the export set counts only defined symbol-table entries so a name that is only referenced is not an export, and the gate test sets `NV_RS_KERNEL_IBT=1` rather than reading the host's kernel config so a refusal expectation holds on a non-IBT host; a green check with IBT not enforced means the rule was skipped, not that the targets resolved) on a quiet tree before any hardware run. + - Always pass 36/36 `tools/validate_all.sh` (including `check_kernel_module.py`: 0 GOT relocations, 0 `memcpy`/`memset`/`memmove`, stack <= 1,024 bytes, no SIMD, and `tests/kernel-module-gate/test_gate_cases.py`: while IBT is enforced, every data relocation that resolves to code must resolve to an instruction boundary and a target's entity is identified from the ELF tables rather than from a printed name (including the header-0 escape fields for extended section numbering, and a raw reserved `st_shndx` read as a special value rather than a section reference), so a printed form belonging to two entities, a shared truncation or a duplicate full name, is refused as unattributable, and the export set counts only defined symbol-table entries so a name that is only referenced is not an export, and the gate test sets `NV_RS_KERNEL_IBT=1` rather than reading the host's kernel config so a refusal expectation holds on a non-IBT host; a green check with IBT not enforced means the rule was skipped, not that the targets resolved) on a quiet tree before any hardware run. --- diff --git a/CLAUDE.md b/CLAUDE.md index 19e04089..ba187379 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -21,7 +21,7 @@ The points most likely to be violated by accident: Run everything from the repository root so rustup picks the pinned toolchain (`rust-toolchain.toml`, 1.100.0, target `x86_64-unknown-none`). ```sh -sh tools/validate_all.sh # the 30-step gate; one PASS/FAIL line per step, logs in target/validate-logs/.log +sh tools/validate_all.sh # the 36-step gate; one PASS/FAIL/SKIP line per step, logs in target/validate-logs/.log make modules # Rust core -> nv-rust.o_binary, Kbuild -> kernel-open/*.ko, then tools/check_kernel_module.py make check # fmt + clippy -D warnings + `--check` of every generated table (needs REA_PYTHON) make test # cargo test --workspace diff --git a/README.md b/README.md index ac95a2f3..e556709b 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ For a step-by-step distro install guide (Ubuntu/Debian, Arch/CachyOS, Fedora, Ni ### Build & Validate ```sh -# Build nvidia_rs.ko and run the 34-step unit, oracle, QEMU guest & kernel-hygiene gate +# Build nvidia_rs.ko and run the 36-step unit, oracle, QEMU guest & kernel-hygiene gate sh tools/validate_all.sh # ARM64 / SBC PCIe build (RK3588, Ampere Altra, Apple Silicon Linux) diff --git a/docs/GPU_BRINGUP_GUIDE.md b/docs/GPU_BRINGUP_GUIDE.md index 00a3b57f..16072efa 100644 --- a/docs/GPU_BRINGUP_GUIDE.md +++ b/docs/GPU_BRINGUP_GUIDE.md @@ -61,7 +61,7 @@ python3 tests/vm/test_result_gate.py ``` > [!IMPORTANT] -> Before any hardware run (Step 2 or Step 3), run the full 31/31 validation gate on a quiet tree (`sh tools/validate_all.sh`, which runs all offline checks, component suites, software QEMU EDU guests, and the empty-`pci_target` live control check via `sudo -n python3 tools/run_live_control.py`). Use the strictly offline commands above only while iterating locally before you are ready to run the full gate. +> Before any hardware run (Step 2 or Step 3), run the full 36/36 validation gate on a quiet tree (`sh tools/validate_all.sh`, which runs all offline checks, component suites, software QEMU EDU guests, and the empty-`pci_target` live control check via `sudo -n python3 tools/run_live_control.py`). Use the strictly offline commands above only while iterating locally before you are ready to run the full gate. Key kernel-module hygiene invariants enforced automatically by `tools/check_kernel_module.py`: - **0** unsupported GOT relocations (`R_X86_64_GOTPCREL`) diff --git a/reports/gp106-core-validation.md b/reports/gp106-core-validation.md index 76f276cf..97fdf86b 100644 --- a/reports/gp106-core-validation.md +++ b/reports/gp106-core-validation.md @@ -19,12 +19,16 @@ Run a single area with `bash tools/gp106/check.sh `. Run the full GP106 offline set from the repository root with: ```sh -for area in memory legacy layout regions heap-inputs acr wpr sec2 hs-wpr upload \ - launch run unmap control inputs tlb pf-cpu bar2; do - bash tools/gp106/check.sh "$area" || exit -done +bash tools/gp106/check.sh all ``` +`all` runs the areas `memory legacy layout regions heap-inputs acr wpr sec2 +hs-wpr upload launch run unmap control inputs tlb pf-cpu pte-policy bar2` in +that order and stops at the first failure. It exits 2 without running anything +when the interpreter cannot import Unicorn and pyelftools or the original +object is not found. `tools/validate_all.sh` runs it as the `gp106_oracles` +step and reports that exit status as SKIP. + The checks generate fixtures and firmware-derived data under `target/`. JSON summaries from the original-instruction checks are under `target/gp106-reports/`. The PF CPU check compares generated metadata with diff --git a/tests/gp106/test_check_all.py b/tests/gp106/test_check_all.py new file mode 100644 index 00000000..49e4634c --- /dev/null +++ b/tests/gp106/test_check_all.py @@ -0,0 +1,61 @@ +"""Check how `tools/gp106/check.sh all` reports missing oracle prerequisites. + +Nothing here runs an oracle: the interpreters are stand-ins that only answer the +two prerequisite probes, so the test needs neither Unicorn nor the original object. +""" + +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[2] + +NO_MODULES = "#!/bin/sh\nexit 1\n" +NO_BINARY = """#!/bin/sh +case "$2" in + "import unicorn, elftools") exit 0 ;; + *) echo /nonexistent/nv-kernel.o_binary; exit 1 ;; +esac +""" + + +class CheckAllPrerequisiteTests(unittest.TestCase): + def run_all(self, interpreter_text): + work = tempfile.TemporaryDirectory() + self.addCleanup(work.cleanup) + interpreter = Path(work.name) / "python" + interpreter.write_text(interpreter_text, encoding="utf-8") + interpreter.chmod(0o755) + return subprocess.run( + ["bash", str(ROOT / "tools/gp106/check.sh"), "all"], + env=dict(os.environ, REA_PYTHON=str(interpreter)), + capture_output=True, + text=True, + ) + + def test_missing_python_modules_exit_2(self): + result = self.run_all(NO_MODULES) + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("SKIP: ", result.stderr) + self.assertIn("Unicorn and pyelftools", result.stderr) + self.assertNotIn("== gp106", result.stdout) + + def test_missing_original_object_exit_2(self): + result = self.run_all(NO_BINARY) + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("SKIP: reference 580.178.04 object not found at /nonexistent/nv-kernel.o_binary", result.stderr) + self.assertNotIn("== gp106", result.stdout) + + def test_usage_lists_all_and_every_area(self): + result = subprocess.run( + ["bash", str(ROOT / "tools/gp106/check.sh"), "no-such-area"], capture_output=True, text=True + ) + self.assertEqual(result.returncode, 2) + self.assertIn("{all|memory|legacy|", result.stderr) + self.assertIn("|pte-policy|bar2}", result.stderr) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/vm/test_validate_guest_steps.py b/tests/vm/test_validate_guest_steps.py index d344ab0c..b51072a5 100644 --- a/tests/vm/test_validate_guest_steps.py +++ b/tests/vm/test_validate_guest_steps.py @@ -19,7 +19,12 @@ sh() { *) return 0 ;; esac } -bash() { return 0; } +bash() { + case "$*" in + "tools/gp106/check.sh all") return "${GP106_STATUS:-0}" ;; + *) return 0 ;; + esac +} python3() { case "$*" in tools/vm/run_guest.py) [ "$FAILED_STEP" != guest ] ;; @@ -100,6 +105,21 @@ class GuestStepTests(unittest.TestCase): self.assertEqual(result.returncode, 0) self.assertIn("PASS live\n", result.stdout) + def test_gp106_oracles_pass(self): + result, _ = self.simulate("", extra_args=("--offline",)) + self.assertEqual(result.returncode, 0) + self.assertIn("PASS gp106_oracles\n", result.stdout) + + def test_gp106_oracles_without_prerequisites_skip(self): + result, _ = self.simulate("", extra_args=("--offline",), extra_env={"GP106_STATUS": "2"}) + self.assertEqual(result.returncode, 0) + self.assertIn("SKIP gp106_oracles ", result.stdout) + + def test_gp106_oracles_failure_fails_the_run(self): + result, _ = self.simulate("", extra_args=("--offline",), extra_env={"GP106_STATUS": "1"}) + self.assertEqual(result.returncode, 1) + self.assertIn("FAIL gp106_oracles ", result.stdout) + def test_unknown_option_fails_with_code_2(self): result, _ = self.simulate("", extra_args=("--bogus-option",)) self.assertEqual(result.returncode, 2) diff --git a/tools/gp106/check.sh b/tools/gp106/check.sh index ce73fb5b..5007faed 100644 --- a/tools/gp106/check.sh +++ b/tools/gp106/check.sh @@ -3,7 +3,33 @@ set -euo pipefail cd "$(dirname "$0")/../.." +AREAS="memory legacy layout regions heap-inputs acr wpr sec2 hs-wpr upload launch run unmap control inputs tlb pf-cpu pte-policy bar2" + case "${1:-}" in + all) + # Every area in turn, for tools/validate_all.sh. Exit 2 (SKIP there) when the + # oracle prerequisites are absent; any area that fails is exit 1. + # The interpreter default is the top-level Makefile's. + if [ -z "${REA_PYTHON:-}" ] && [ -x "$HOME/.local/opt/rea-python/bin/python" ]; then + REA_PYTHON="$HOME/.local/opt/rea-python/bin/python" + fi + export REA_PYTHON="${REA_PYTHON:-python3}" + if ! "$REA_PYTHON" -c 'import unicorn, elftools' >/dev/null 2>&1; then + echo "SKIP: $REA_PYTHON cannot import Unicorn and pyelftools (set REA_PYTHON to run)" >&2 + exit 2 + fi + if ! binary=$("$REA_PYTHON" -c 'import sys; sys.path.insert(0, "tools"); from _binary_path import resolve_580_binary; p = resolve_580_binary(); print(p); sys.exit(0 if p.is_file() else 1)'); then + echo "SKIP: reference 580.178.04 object not found at ${binary:-} (set NV_RS_580_BINARY to run)" >&2 + exit 2 + fi + for area in $AREAS; do + echo "== gp106 $area" + if ! bash tools/gp106/check.sh "$area"; then + echo "FAIL: gp106 $area" >&2 + exit 1 + fi + done + ;; memory) cargo test -p nv-rs-core --lib mmu::vram:: "${REA_PYTHON:-python3}" tools/check_vram_size_binary.py --check @@ -122,7 +148,7 @@ case "${1:-}" in cargo test -p nv-rs-core --lib original_gp106_pte_policy -- --include-ignored ;; *) - echo "Usage: bash tools/gp106/check.sh {memory|layout|regions|heap-inputs|acr|wpr|sec2|hs-wpr|upload|launch|run|unmap|control|inputs|tlb|pf-cpu|pte-policy|bar2|legacy}" >&2 + echo "Usage: bash tools/gp106/check.sh {all|${AREAS// /|}}" >&2 echo "Oracle checks require Unicorn, pyelftools and the extracted 580.178.04 object." >&2 exit 2 ;; diff --git a/tools/validate_all.sh b/tools/validate_all.sh index 1932b249..84a7ad02 100755 --- a/tools/validate_all.sh +++ b/tools/validate_all.sh @@ -56,6 +56,7 @@ step modules make modules step audit make -C src/nvidia audit-codegen step native_codegen python3 tools/check_native_codegen.py optional_step gsp_620_headers python3 tools/oracle_gsp_620.py +optional_step gp106_oracles bash tools/gp106/check.sh all guest_skip() { local name=$1 reason=$2 echo "$reason" >"$LOGS/$name.log"