#!/usr/bin/env python3 """Create read-only original580 milestone/argument evidence map; no tracing.""" import argparse import hashlib import json import os from pathlib import Path ROOT = Path(__file__).resolve().parents[1] DEFAULT_ANALYSIS_ROOT = Path('/home/geodd/nvidia-driver/analysis-580.178.04') def find_export_dir(explicit: Path | None = None) -> Path: if explicit is not None: candidate = explicit else: analysis = Path(os.environ.get('NV_RS_ANALYSIS_ROOT', str(DEFAULT_ANALYSIS_ROOT))) candidate = analysis / 'decompiled/kernel-rm-all' if not (candidate / 'original-symbol-export-map.jsonl').is_file(): raise SystemExit( f'decompiled export map not found under {candidate}; ' 'pass --export-dir or set NV_RS_ANALYSIS_ROOT' ) return candidate def _fields(base, entries): return [{'owner': base, 'offset': hex(off), 'width_bits': width, 'meaning': name} for off, width, name in entries] def main(argv=None) -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--export-dir', type=Path, default=None) args = parser.parse_args(argv) export_dir = find_export_dir(args.export_dir) source = { r['name']: r for r in ( json.loads(line) for line in (export_dir / 'original-symbol-export-map.jsonl').read_text(encoding='utf-8').splitlines() if line.strip() ) } acr = _fields('arg2 ACR', [(0x37b, 8, 'alternate/disabled route gate'), (0x37f, 8, 'bootstrap owner policy input'), (0x381, 8, 'client route policy input'), (0x385, 8, 'WPR descriptor policy'), (0x386, 8, 'shadow allocation policy'), (0x387, 8, 'request attributes/shared-header policy'), (0x388, 8, 'bootstrap owner policy input'), (0x391, 8, 'WPR gather branch'), (0x392, 8, 'address-space/alignment policy'), (0x394, 32, 'WPR descriptor region policy'), (0x398, 32, 'region count/mode admission'), (0x3b8, 32, 'allocation stage marker'), (0x510, 8, 'region allocation stage flag')]) lsfm = _fields('arg2 LSFM', [(0x190, 8, 'normal(0)/alternate(1) protocol route'), (0x192, 16, 'constructed client count'), (0x194, 32, 'aggregate logical bytes'), (0x198, 32, 'excluded client mask'), (0x19c, 32, 'parent state reset field'), (0x1b0, 16, 'shared object count')]) falcon = _fields('arg2 Falcon', [(0x3a2, 8, 'lazy-bootstrap policy source'), (0x3a4, 8, 'image GPU-address source branch'), (0x3a5, 8, 'context policy saved/restored by028470'), (0x3a7, 8, 'client included flag; temporarily cleared by028470'), (0x3aa, 8, 'policy flag; temporarily cleared by028470'), (0x3b1, 8, 'wait/teardown route flag'), (0x560, 32, 'DMA context selector'), (0x581, 8, 'state prerequisite flag'), (0x582, 8, 'bootstrap busy admission flag'), (0x5ec, 32, 'engine type tag'), (0x608, 32, 'LSF client ID'), (0x628, 8, 'bootstrap temporary state flag'), (0x638, 8, 'bootstrap temporary state flag'), (0x648, 64, 'owned VM pointer; record identity only'), (0x650, 32, 'ISA route1=Falcon,2/3=RISC-V')]) rows = [] def add(n, stage, entry_args, status='NvStatus low32', state=(), proof=()): symbol = '_nv' + n + 'rm' s = source[symbol] path = export_dir / s['decompiler_output'] body = path.read_bytes() rows.append({ 'symbol': symbol, 'stage': stage, 'entry_arguments': entry_args, 'gpu_pointer': 'arg1/RDI (passed by verified RM caller; not self-validating)', 'return': status, 'direct_state_fields': list(state), 'evidence_reports': list(proof), 'ghidra_address_NOT_runtime': '0x' + s['mapped_entry'], 'elf_text_offset': hex(s['ELF_st_value']), 'elf_function_bytes': s['ELF_size'], 'decompiler_file': str(path), 'decompiler_sha256': hashlib.sha256(body).hexdigest(), }) add('043236', 'LSFM StateInit client enumeration/placement and request1 registration', {'RDI': 'GPU', 'RSI': 'LSFM'}, state=lsfm, proof=['gpu-lsf-image-rea', 'gpu-lsf-placement-oracle.json']) add('043182', 'per-client prepared firmware/header construction', {'RDI': 'GPU', 'RSI': 'LSFM', 'RDX': 'Falcon'}, state=lsfm + [{**f, 'owner': 'arg3 Falcon'} for f in falcon if int(f['offset'], 16) in [0x3a2, 0x3a7, 0x5ec, 0x608, 0x650]], proof=['gpu-lsf-image-rea', 'gpu-lsf-entry-oracle.json']) add('027605', 'selected FECS image/metadata/signature source', {'RDI': 'GPU', 'RSI': 'FECS provider', 'RDX': 'output138-byte descriptor'}, state=_fields('arg2 FECS provider', [(0x1c8, 32, 'selected netlist slot; not Falcon ID')]), proof=['gpu-lsf-image-rea', 'gpu-lsf-whole-image-oracle.json']) add('029864', 'selected GPCCS image/metadata/signature source', {'RDI': 'GPU', 'RSI': 'GPCCS provider', 'RDX': 'output138-byte descriptor'}, state=_fields('arg2 GPCCS provider', [(0x1f8, 32, 'selected netlist slot; not Falcon ID')]), proof=['gpu-lsf-image-rea', 'gpu-lsf-whole-image-oracle.json']) add('016949', 'register actual ACR request (id1 for LSFM aggregate)', {'RDI': 'GPU', 'RSI': 'ACR', 'RDX': '6-u32 request specification', 'RCX': 'optional output-owned-node handle'}, state=acr[:1] + [acr[8]], proof=['gpu-lsf-header-rea', 'gpu-lsf-placement-oracle.json']) add('016731', 'ACR region-table construction/policy', {'RDI': 'GPU', 'RSI': 'ACR'}, state=acr, proof=['gpu-wpr-policy-rea']) add('016953', 'actual ACR primary/shadow/backup region allocations', {'RDI': 'GPU', 'RSI': 'ACR'}, state=acr, proof=['gpu-acr-region-oracle.json']) add('043215', 'normal LSFM WPR population (headers, descriptors, client image copy)', {'RDI': 'GPU', 'RSI': 'LSFM', 'RDX': 'aggregate/region memory descriptor'}, state=lsfm, proof=['gpu-lsf-header-rea']) add('043231', 'resolve included client and invoke actual boot descriptor callback', {'RDI': 'GPU', 'RSI': 'LSFM', 'RDX': 'owned client node'}, state=lsfm[:1], proof=['gpu-lsf-header-rea']) add('028829', 'selected FECS/GPCCS interface70 descriptor forwarding', {'RDI': 'GPU', 'RSI': 'Ucode interface; Falcon at+18', 'RDX': 'prepared image descriptor', 'RCX': 'output boot descriptor', 'R8': 'output size pointer'}, 'void; RAX is not an NvStatus', proof=['gpu-lsf-boot-descriptor-rea', 'gpu-lsf-boot-descriptor-oracle.json']) add('028607', 'actual84-byte Falcon boot descriptor construction', {'RDI': 'GPU', 'RSI': 'Falcon', 'RDX': 'prepared image descriptor', 'RCX': 'output84-byte descriptor', 'R8': 'output size pointer'}, 'void; RAX is not an NvStatus', falcon, proof=['gpu-lsf-boot-descriptor-rea', 'gpu-lsf-boot-descriptor-oracle.json']) add('016741', 'HS firmware selection, patch/package, WPR gather and SEC2 launch parent', {'RDI': 'GPU', 'RSI': 'ACR', 'EDX': 'firmware operation/mode u32', 'RCX': 'optional source/argument preserved by parent; not assumed GPU'}, state=acr, proof=['gpu-acr-dma-rea', 'gpu-acr-parent-package-oracle.json']) add('016905', 'actual selected HS packed descriptor acquisition/unpack', {'RDI': 'GPU', 'RSI': 'ACR', 'EDX': 'operation/mode', 'RCX': 'output prepared HS descriptor'}, state=acr, proof=['gpu-acr-firmware-rea']) add('016965', 'patch HS signatures using actual selected assets', {'RDI': 'GPU', 'RSI': 'ACR', 'RDX': 'decoded image', 'RCX': 'production signature storage', 'R8': 'debug signature storage', 'R9': 'patch-location pointer', 'stack': '6 remaining scalar/pointer inputs; do not infer from register leftovers'}, state=acr[:1], proof=['gpu-acr-firmware-rea', 'gpu-acr-signature-oracle.json']) add('016753', 'WPR metadata gather and selected CPU/CE shadow copy', {'RDI': 'GPU', 'RSI': 'ACR', 'RDX': 'output descriptor buffer'}, state=acr, proof=['gpu-wpr-policy-rea', 'gpu-wpr-cpu-shadow-oracle.json']) add('028470', 'selected SEC2 HS parent reset/VM/DMEM/IMEM/start/wait', {'RDI': 'GPU', 'RSI': 'Falcon', 'RDX': 'mutable84-byte boot descriptor; not an image allocation', 'ECX': 'DMA index', 'R8D': 'scalar forwarded input5', 'R9D': 'scalar forwarded input6 to Falcon258 setup', 'stack_arg7_at_entry_RSP_plus8': 'nonzero forces virtual-DMA path; both branches still clock/reset', 'stack_arg8_at_entry_RSP_plus16': 'wait-completion input u32', 'stack_arg9_at_entry_RSP_plus24': 'primary image allocation/memdesc', 'stack_arg10_at_entry_RSP_plus32': 'optional second image allocation/memdesc'}, state=falcon, proof=['gpu-falcon-bootstrap-rea', 'gpu-falcon-boot-parent-oracle.json']) add('028467', 'Falcon reset hold/release operation', {'RDI': 'GPU', 'RSI': 'Falcon', 'EDX': 'hold/release scalar'}, 'void; RAX is not an NvStatus', falcon, proof=['gpu-falcon-bootstrap-rea']) add('028420', 'create owned90f1 Falcon VM and bind resource owners', {'RDI': 'GPU', 'RSI': 'Falcon'}, state=falcon[-2:], proof=['gpu-falcon-bootstrap-rea']) add('028379', 'map actual image allocation in owned Falcon VM', {'RDI': 'GPU', 'RSI': 'Falcon', 'RDX': 'bus owner', 'RCX': 'image allocation/memdesc', 'R8': 'output GPU VA pointer'}, state=falcon[-2:], proof=['gpu-falcon-bootstrap-rea']) add('028759', 'Falcon instance binding', {'RDI': 'GPU', 'RSI': 'Falcon', 'EDX': 'instance/address-space selector'}, 'void; RAX is not an NvStatus', falcon, proof=['gpu-falcon-bootstrap-rea']) add('028452', 'actual parent DMEM-copy virtual forwarder', {'RDI': 'GPU', 'RSI': 'Falcon', 'EDX': 'offset', 'RCX': 'source bytes', 'R8D': 'byte count', 'R9D': 'transfer flag', 'stack_arg7': 'port'}, 'forwarder decompiledvoid; only selected target execution defines RAX semantics', proof=['gpu-falcon-boot-parent-oracle.json']) add('028457', 'selected DMEM transfer body', {'RDI': 'GPU', 'RSI': 'Falcon', 'EDX': 'offset', 'RCX': 'source bytes', 'R8D': 'byte count', 'R9D': 'transfer flag', 'stack_arg7': 'port'}, 'NvStatus low32; selected028470 records but ignores executed DMEM failure', falcon, proof=['gpu-falcon-bootstrap-rea', 'gpu-falcon-boot-parent-oracle.json']) add('028523', 'selected IMEM code transfer', {'RDI': 'GPU', 'RSI': 'Falcon', 'RDX': 'IMEM offset', 'RCX': 'source bytes', 'R8D': 'byte count', 'R9D': 'port', 'stack': 'remaining tag/security inputs'}, 'void; RAX is not an NvStatus', proof=['gpu-falcon-imem-oracle.json']) add('028764', 'Falcon CPU start', {'RDI': 'GPU', 'RSI': 'Falcon'}, 'void; RAX is not an NvStatus', falcon, proof=['gpu-falcon-bootstrap-rea']) add('028781', 'HS completion wait plus teardown route', {'RDI': 'GPU', 'RSI': 'Falcon', 'RDX': 'image/mapping-related ownership input', 'RCX': 'optional second ownership input'}, state=falcon, proof=['gpu-falcon-bootstrap-rea', 'gpu-falcon-boot-parent-oracle.json']) report = { 'artifact_sha256': '5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b', 'purpose': 'read-only verified argument/state map for root-owned live original580 trace; creates no trace probes', 'architecture': 'x86-64 Linux SysV; register args at function entry', 'corrections': [ 'Earlier informal016953 map claiming Region arg1 was INVALID; actual GPU RDI,ACR RSI.', 'Earlier informal028470 fiveargument description was INVALID; actual10arguments with mutable boot descriptor RDX and image memdescs stackargs9/10.', ], 'symbols': rows, 'interpretation': [ 'Ghidra addresses and ELF offsets are static provenance, never loadedkernel addresses.', 'Entry argument type is not proof pointer belongs to target GPU; validate callsite/runtime module/artifact first.', 'kretprobe register args may be clobbered; retain entry arguments for return state snapshots.', 'Void functions RAX must not be interpreted as NvStatus.', 'CUDA may create worker TIDs; exactPID filtering may omit them.', 'An already initialized adapter may run CUDA context/launch without any cold LSFM/ACR/WPR/Falcon calls; zero such events is bounded negative evidence only.', 'Partialorder edges below follow selected static callsites and tested original software branches; actual trace determines exercised order, branches and nesting.', ], 'partialorder': [ ['043236', '043182', '027605 or029864 via028614'], ['043236', '016949'], ['043215', '043231', '028829', '028607'], ['016741', '016905', '016965 ifmode requires'], ['016741', '016753', '028470'], ['028470', '028467 x3 in both parent routes', '028420', '028379', '028759', '028452->028457', '028523', '028764', '028781'], ], 'no_physical_gpu_access': True, } out = ROOT / 'reports/gpu-firmware-live-trace-map.json' out.parent.mkdir(parents=True, exist_ok=True) out.write_text(json.dumps(report, indent=2) + '\n', encoding='utf-8') print(len(rows), 'verified milestone maps; no tracing changes') if __name__ == '__main__': main()