diff --git a/reports/citation-audit-580-gsp.md b/reports/citation-audit-580-gsp.md index e09a8c59..da4930d8 100644 --- a/reports/citation-audit-580-gsp.md +++ b/reports/citation-audit-580-gsp.md @@ -26,6 +26,8 @@ Issue #60 confirmed 12 of the 23 `_nvrm` citations in `src/nvidia/src/gpu/gsp ## Reproducibility +### 1. Automated symbol existence check and `--inspect` summary + ```sh python3 tools/verify_580_citations.py --self-check python3 tools/verify_580_citations.py \ @@ -33,3 +35,25 @@ python3 tools/verify_580_citations.py \ --inspect _nv041332rm _nv041222rm _nv041223rm _nv041407rm _nv041396rm \ _nv041397rm _nv041253rm _nv041420rm _nv041260rm _nv041429rm _nv034199rm ``` + +### 2. Reproducing exact symbol addresses and full disassembly evidence + +`--inspect` prints instruction counts, direct `_nv*rm` callees, and BAR0 MMIO immediates. To reproduce the symbol offsets, struct field displacements, and full function roles recorded in the table above directly from the canonical `580.178.04` `nv-kernel.o_binary` (set `NV_BIN` to its path): + +```sh +NV_BIN="${NV_RS_580_BINARY:-/usr/src/nvidia-580.178.04/nvidia/nv-kernel.o_binary}" +sha256sum "$NV_BIN" # must equal 5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b + +# Reproduce the Address column (section-relative offsets in .text): +nm --defined-only "$NV_BIN" | grep -E ' (_nv041332rm|_nv041222rm|_nv041223rm|_nv041407rm|_nv041396rm|_nv041397rm|_nv041253rm|_nv041420rm|_nv041260rm|_nv041429rm|_nv034199rm)$' + +# Reproduce the Insns, Key Register / Offset / Callee Evidence, and Function Role columns: +for sym in _nv041332rm _nv041222rm _nv041223rm _nv041407rm _nv041396rm \ + _nv041397rm _nv041253rm _nv041420rm _nv041260rm _nv041429rm _nv034199rm; do + objdump -dr --no-show-raw-insn --disassemble="$sym" "$NV_BIN" +done +``` + +Manual verification steps on each disassembled function: +1. Match BAR0 register immediates (`0x110040`/`0x110044`, `0x1103c0`, `0x110804`, `0x110c00`, `0x118128`, `0x1fa824`/`0x1fa828`, etc.) against the open-gpu-kernel-modules `580.178.04` hardware headers (`dev_gsp.h`, `dev_bus.h`, `dev_fb.h`) and calls to `_nv053907rm` (BAR0 read) / `_nv053912rm` (BAR0 write). +2. Match `KernelGsp` / `OBJGPU` struct field offsets (`+0x908`, `+0x910`, `+0xa14`, `+0xa48`, `+0xe00`/`+0xe01`, `+0x1f98`, `+0x23b0`) and HAL vtable slot offsets (`+0x4e0`, `+0x878`, `+0x8b8`, `+0x8c8`, `+0x960`) against the `580.178.04` `g_kernel_gsp_nvoc.h` / `g_gpu_nvoc.h` layouts. diff --git a/tools/verify_580_citations.py b/tools/verify_580_citations.py index 048f2d0d..e37fbd09 100755 --- a/tools/verify_580_citations.py +++ b/tools/verify_580_citations.py @@ -26,9 +26,13 @@ ROOT = Path(__file__).resolve().parents[1] CANONICAL_580_SHA256 = "5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b" SYM_RE = re.compile(r"\b(_nv\d{6}rm)\b") GHIDRA_MARKER_RE = re.compile(r"====\s+(_nv\d{6}rm)\s+@\s+([0-9a-fA-F]+)") -CALL_RE = re.compile(r"R_X86_64_PC32\s+(_nv\d{6}rm)") -INSN_RE = re.compile(r"^\s+[0-9a-f]+:\s+[a-zA-Z]") -MMIO_IMM_RE = re.compile(r"\$(0x(?:1[01][0-9a-f]{4}|1fa[0-9a-f]{3}|9[08a][0-9a-f]{4}|8[0-9a-f]{5}|c[0-9a-f]{5}))") +CALL_RELOC_RE = re.compile(r"^\s+[0-9a-f]+:\s+R_X86_64_(?:PLT32|PC32)\s+(_nv\d{6}rm)\b") +RELOC_LINE_RE = re.compile(r"^\s+[0-9a-f]+:\s+R_[A-Z0-9_]+\b") +CALL_INSN_RE = re.compile(r"^\s+[0-9a-f]+:\s+call[qlw]?\b") +INSN_RE = re.compile(r"^\s+[0-9a-f]+:\s+(?!R_[A-Z0-9_]+\b)[a-zA-Z]") +MMIO_IMM_RE = re.compile( + r"\$(0x(?:1[01][0-9a-f]{4}|1fa[0-9a-f]{3}|9[08a][0-9a-f]{4}|8[0-9a-f]{5}|c[0-9a-f]{5}))(?![0-9a-fA-F])" +) DEFAULT_BINARY_CANDIDATES = ( "/usr/src/nvidia-580.178.04/nvidia/nv-kernel.o_binary", @@ -96,21 +100,38 @@ def load_defined_symbols(binary: Path) -> set[str]: return set(SYM_RE.findall(out)) +def parse_objdump_inspect(sym: str, out: str) -> dict[str, object]: + insns: list[str] = [] + callees_set: set[str] = set() + prev_is_call = False + for ln in out.splitlines(): + if RELOC_LINE_RE.match(ln): + if prev_is_call: + m = CALL_RELOC_RE.match(ln) + if m: + callees_set.add(m.group(1)) + continue + if INSN_RE.match(ln): + insns.append(ln) + prev_is_call = bool(CALL_INSN_RE.match(ln)) + else: + prev_is_call = False + mmio = sorted(set(MMIO_IMM_RE.findall(out))) + return { + "symbol": sym, + "instructions": len(insns), + "callees": sorted(callees_set), + "mmio_immediates": mmio, + } + + def inspect_symbol(binary: Path, sym: str) -> dict[str, object]: out = subprocess.check_output( ["objdump", "-dr", "--no-show-raw-insn", f"--disassemble={sym}", str(binary)], text=True, env=dict(os.environ, LC_ALL="C"), ) - insns = [ln for ln in out.splitlines() if INSN_RE.match(ln)] - callees = sorted(set(CALL_RE.findall(out))) - mmio = sorted(set(MMIO_IMM_RE.findall(out))) - return { - "symbol": sym, - "instructions": len(insns), - "callees": callees, - "mmio_immediates": mmio, - } + return parse_objdump_inspect(sym, out) def sha256_file(path: Path) -> str: @@ -158,9 +179,36 @@ def run_self_check() -> int: except ValueError: pass - # 3. Verify INSN_RE matches real instructions and ignores wrapped byte continuation lines. + # 3. Verify instruction counting, callee extraction, and MMIO immediate boundaries. _check(INSN_RE.match(" 0:\tmov $0x1,%eax") is not None, "instruction line must match") _check(INSN_RE.match(" 7:\t00 00") is None, "wrapped raw bytes must not match") + _check( + INSN_RE.match(" 1:\tR_X86_64_PC32\t_nv041332rm-0x4") is None, + "relocation record must not count as an instruction", + ) + sample_disasm = "\n".join([ + "0000000000000000 <_nv041407rm>:", + " 0:\tmov $0x110040,%esi", + " 5:\tmov $0x100000,%edx", + " a:\tmov $0x10000000,%ecx", + " f:\tlea 0x0(%rip),%rax", + " 12:\tR_X86_64_PC32\t_nv099999rm-0x4", + " 16:\tcall 1b <_nv041407rm+0x1b>", + " 17:\tR_X86_64_PLT32\t_nv043721rm-0x4", + " 1b:\tcallq 20 <_nv041407rm+0x20>", + " 1c:\tR_X86_64_PC32\t_nv053912rm-0x4", + " 20:\tret", + ]) + parsed = parse_objdump_inspect("_nv041407rm", sample_disasm) + _check(parsed["instructions"] == 7, f"expected 7 instructions (excluding relocs), got {parsed}") + _check( + parsed["callees"] == ["_nv043721rm", "_nv053912rm"], + f"expected only call targets (PLT32+PC32, no lea), got {parsed['callees']}", + ) + _check( + parsed["mmio_immediates"] == ["0x100000", "0x110040"], + f"expected complete hex boundary excluding $0x10000000, got {parsed['mmio_immediates']}", + ) # 4. Verify a noncanonical ELF defining every cited symbol is still rejected and # --paths with a missing file exits nonzero.