#!/usr/bin/env python3 """Run the original GV100 OBJACR Unload after the original Load and write an oracle. The environment is the one tools/check_gpu_acr_load_binary.py builds: that file is executed unchanged up to the end of its traced V100 case, so every unload case starts from the emulated state the original Load leaves (OBJACR InitLocked, OBJLSFM Load, OBJACR Load with the transcript's register values). On a GV100 the unload image does not run on SEC2. OBJACR+38b is clear, so OBJACR+130 _nv016972rm passes the image to the PMU function at +2e0 (_nv052043rm), which resets the PMU Falcon and runs the image there from a system-memory allocation through DMA index 4. The status check OBJACR+158 (_nv016730rm) then reads the mailboxes of the SEC2 Falcon, because OBJACR+37f is set. Executed original code (chip HAL 0x23, RM HAL 2): OBJACR Unload _nv016962rm; +130 _nv016972rm with the gate _nv016925rm (+150 _nv016745rm), the signature placement _nv016965rm (+370 _nv016945rm, PMU+3d8 _nv052308rm), the status check +158 _nv016730rm. The image is prepared as the constructor _nv016731rm does it: _nv016905rm(gpu, acr, 6, OBJACR+3c0) with the bundle of +2d0 _nv016853rm. PMU +2e0 _nv052043rm; +2d0 _nv052261rm; the vtable function at +60 of the PMU+b08 object (_nv004583rm, _nv051835rm); of the embedded object at +a00 (bound by _nv006032rm, properties _nv005854rm): +60 _nv052224rm, the reset +58 _nv052192rm with +68 _nv052223rm, +88 _nv052197rm, +70 _nv052194rm, +80 _nv052248rm, +78 _nv052252rm, +a8 _nv052188rm, +48 _nv052213rm, the start +d8 _nv052256rm, the wait +d0 _nv052260rm and +c0 _nv052215rm; +278 _nv051924rm and +280 _nv051927rm; +70 _nv052291rm of the embedded object at +c20 (bound by _nv006033rm); the wait wrapper _nv052647rm; the boot loader records of the bundle of +370 (_nv052066rm) as the constructor part _nv051982rm unpacks them. Falcon the halt _nv028516rm with +2a8 _nv028520rm, the interface functions _nv028817rm and _nv028831rm, +370 _nv028766rm, +378, +1a0 _nv028785rm, the DMEM writer _nv028452rm, the IMEM writer _nv028523rm, _nv028552rm. OBJMC +198 _nv043581rm. GPU +7c0 _nv030971rm, +5c8 _nv030977rm and _nv030976rm with the clock-gating functions they reach. Fixture-supplied, beyond the load harness: the function at +160 of the GPU+1ec8 object (called by _nv041589rm), the interrupt service _nv031481rm and _nv031415rm, the PMU class function at vtable +508 (called after a timeout), MemorySystem+f10, the GPU+20c8 object's function at +1b8, and the system-memory descriptor (creation, allocation with the bus address as a case input, mapping backed by emulator memory). Stored by the harness as the creators store them (the creators themselves need the object tree and are not executed): the two vtable pointers and self pointers of the PMU+a00 object (_nv006737rm), of the PMU+c20 object (_nv006738rm; +80 = 0 and +84 = 3 as _nv003401rm and _nv052273rm give for a GV100 with GPU+914 clear), and of the PMU+b08 object (_nv006726rm), whose state word at +80 is a case input. No hardware is involved. The physical transcript does not contain an unload: this harness is instruction-emulation evidence only. """ import hashlib import json from pathlib import Path import struct import sys HERE = Path(__file__).resolve() SOURCE = HERE.with_name("check_gpu_acr_load_binary.py") MARKER = "# ------------------------------------------------------------------ InitLocked" source = SOURCE.read_text() assert MARKER in source and "--traced" not in sys.argv exec(compile(source[:source.index(MARKER)], str(SOURCE), "exec"), globals()) # noqa: S102 LOAD_IMAGE_SHA256 = hashlib.sha256(HS_IMAGE).hexdigest() BUNDLE_UNLOAD, BUNDLE_PMU_LOADER = 0x1141350, 0x11432e0 A00, C20, IMPL, OBJ_1EC8 = PMU + 0xa00, PMU + 0xc20, MEMMGR2 + 0x800, MEMMGR2 + 0xa00 DMA = 0x1_2345_6000 # bus address of the system-memory allocation in most cases # ------------------------------------------------------------ additional setup hooks[text("_nv028817rm")] = ("_nv028817rm", lambda a, low: { SEC2 + 0xe8: F_SEC2, PMU + 0xe8: F_PMU}[a[1]]) @service("GPU+1ec8 object +160") def object_1ec8_160(a, low): emit(f"pg:{state['pg']:x}") return state["pg"] @hook("_nv031481rm") def interrupt_service(a, low): emit(f"is:{low[2]:x}") return 0 @hook("_nv031415rm") def gpu_mask(a, low): assert a[0] == GPU return 1 @service("PMU class vtable +508") def pmu_508(a, low): assert (a[0], a[1], low[2]) == (GPU, PMU, 1), a emit("pd") return 0 @service("MemorySystem+f10") def memory_f10(a, low): assert a[0] == GPU emit("mf") return 0 @service("GPU+20c8 object +1b8") def vbios_1b8(a, low): assert (a[0], a[1]) == (GPU, VBIOS) emit("vb") return 0 # The PMU+a00 object as _nv006737rm leaves it. q(A00 + 0x40, A00) q(A00 + 0x38, A00 + 8) q(A00, rodata(0x5ee72c0)) q(A00 + 8, rodata(0x5ee72d8)) call("_nv005854rm", A00, CHIP) q(A00 + 0x100, F_PMU) assert (byte(A00 + 0xf8), byte(A00 + 0xf9)) == (1, 0) # The object _nv006726rm creates for the class _nv003201rm; PMU+b08 is its # base at +8 (_nv051986rm casts it to _nv003215rm). cpu.mem_write(IMPL, bytes(0x88)) for index, table in enumerate((0x5ee7500, 0x5ee7518, 0x5ee7530)): q(IMPL + 8 * index, rodata(table)) q(IMPL + 0x68, IMPL + 0x10) q(IMPL + 0x70, IMPL + 8) q(IMPL + 0x78, IMPL) q(IMPL + 8 + 0x50, F_PMU) assert pointer(address_of(by_name["_nv003201rm"]) + 0x10) == text("_nv006348rm") assert call("_nv005245rm", IMPL, address_of(by_name["_nv003215rm"])) == (IMPL + 8) & 0xffffffff q(PMU + 0xb08, IMPL + 8) assert slot(pointer(IMPL + 8), 0x60) == "_nv004583rm" assert slot(pointer(IMPL), 0xd0) == "_nv051835rm" # The PMU+c20 object as _nv006738rm leaves it. cpu.mem_write(C20, bytes(0x98)) q(C20 + 0x40, C20) q(C20 + 0x38, C20 + 8) q(C20, rodata(0x5ee7360)) q(C20 + 8, rodata(0x5ee7378)) call("_nv006033rm", C20, CHIP, RM) b(C20 + 0x80, 0) d(C20 + 0x84, 3) # The PMU class vtable the creator stored: only its function at +508 is # replaced, in a copy. PMU_VTABLE = MEMMGR2 + 0xc00 cpu.mem_write(PMU_VTABLE, bytes(cpu.mem_read(pointer(PMU), 0x600))) q(PMU_VTABLE + 0x508, pmu_508) q(PMU, PMU_VTABLE) q(GPU + 0x1ec8, OBJ_1EC8) q(OBJ_1EC8 + 0x160, object_1ec8_160) q(MEMSYS + 0xf10, memory_f10) q(VBIOS + 0x1b8, vbios_1b8) # The boot loader records, as the PMU constructor part _nv051982rm unpacks them. call(slot(PMU, 0x370), PMU) LOADER_BUNDLE = cpu.reg_read(UC_X86_REG_RAX) assert analysis(LOADER_BUNDLE) == BUNDLE_PMU_LOADER for tag, field in ((0x12, 0x17d0), (0x23, 0x17d8)): call("_nv017872rm", LOADER_BUNDLE, tag) assert call("_nv017879rm", cpu.reg_read(UC_X86_REG_RAX), PMU + field) == 0 call(slot(ACR, 0x2d0), ACR) assert analysis(cpu.reg_read(UC_X86_REG_RAX)) == BUNDLE_UNLOAD BOUND_UNLOAD = { "OBJACR": (ACR, {0x130: "_nv016972rm", 0x150: "_nv016745rm", 0x158: "_nv016730rm", 0x2d0: "_nv016853rm", 0x370: "_nv016945rm", 0x1d0: "_nv016927rm"}), "PMU": (PMU, {0x278: "_nv051924rm", 0x280: "_nv051927rm", 0x2d0: "_nv052261rm", 0x2e0: "_nv052043rm", 0x370: "_nv052066rm", 0x3d8: "_nv052308rm"}), "PMU+a00": (A00, {0x48: "_nv052213rm", 0x58: "_nv052192rm", 0x60: "_nv052224rm", 0x68: "_nv052223rm", 0x70: "_nv052194rm", 0x78: "_nv052252rm", 0x80: "_nv052248rm", 0x88: "_nv052197rm", 0xa8: "_nv052188rm", 0xc0: "_nv052215rm", 0xd0: "_nv052260rm", 0xd8: "_nv052256rm"}), "PMU+c20": (C20, {0x70: "_nv052291rm"}), "PMU Falcon": (F_PMU, {0x1a0: "_nv028785rm", 0x2a8: "_nv028520rm", 0x370: "_nv028766rm"}), "GPU": (GPU, {0x5c8: "_nv030977rm", 0x7c0: "_nv030971rm"}), } bound_unload = {} for label, (base, slots) in BOUND_UNLOAD.items(): for offset, function in slots.items(): assert slot(base, offset) == function, (label, hex(offset), slot(base, offset)) bound_unload[f"{label}+{offset:#x}"] = function assert slot(pointer(pointer(F_PMU + 0x5d8)), 0xd0) == "_nv028831rm" # The image, prepared as the constructor _nv016731rm does for a GV100 # (OBJACR+38b and +37b clear: type 6 into OBJACR+3c0). assert (byte(ACR + 0x38b), byte(ACR + 0x37b), byte(ACR + 0x391), byte(ACR + 0x390)) == (0, 0, 0, 0) UNLOADABLE = {} for fuse in (0, 0x100000): state["reads"] = {0x10ac08: [fuse]} saved_acr = bytes(cpu.mem_read(ACR + 0x3c0, 0x70)) del trace[:] assert call("_nv016905rm", GPU, ACR, 6, ACR + 0x3c0) == 0 PREPARE_EVENTS = list(trace) UNLOADABLE[fuse] = loaded_state() cpu.mem_write(ACR + 0x3c0, saved_acr) U_SETTINGS = dict(g91d=0, g69e4=0, o1eb=0, a391=0, a37b=0, a37f=1, a390=0, p9a2=0, ps=0, g914=0, g252c=0, g915=1, g917=0, g918=0, g926=0, g97c=0, g4de4=0, ge00=0, f3a7=0, f3af=0, f3b6=0, f3bb=0, f3be=0, pg=0, k108=0, k1=0, lp234=0, m8ccf=0, mc=1, v2d8=0, g6=0, dma=DMA, fuse=0, fail="") # Register values of a default run: the regions as the traced Load left them, # the PMU halted with the LS image placed (CPUCTL 0x50 at transcript line # 147279), everything else as a case input. U_READS = {0x100cd4: [0x7fde802, 0x7fdf403, 0x80000c0, 0x80000c1], 0x10ac08: [0], 0x10a040: [0], 0x80: [0x8f], 0x20c: [0x21ecdedc], 0x10a3c0: [0, 1], 0x10a0a4: [0x200], 0x10a3c4: [0x10], 0x1221fc: [0], 0x1241fc: [0], 0x1281fc: [0], 0x10a10c: [1], 0x10ae24: [0x10], 0x10a108: [0x400e0100], 0x10a100: [0x10], 0x10a130: [0], 0x87040: [0], 0x87044: [0], 0x10a044: [0], 0x10a268: [0x100], 0x10a04c: [0], 0: [0x140000a1], 0x10a12c: [0xca0e1136], 0x10a048: [0], 0x10a430: [0], 0x10a1c0: [0]} def unload_begin(reads, checks, settings): restore_loaded(UNLOADABLE[settings["fuse"]]) del trace[:] diagnostics[0] = 0 fail = {} for item in filter(None, settings["fail"].split(",")): kind, number, status = item.split(":") fail[kind] = (int(number), int(status, 16)) state.update(reads={offset: list(values) for offset, values in reads.items()}, checks=list(checks), addresses=[settings["dma"]], fail=fail, counts={}, k1=settings["k1"], g6=settings["g6"], pg=settings["pg"], no_buffer=None) for offset, name in ((0x391, "a391"), (0x37b, "a37b"), (0x37f, "a37f"), (0x390, "a390")): b(ACR + offset, settings[name]) for offset, name in ((0x91d, "g91d"), (0x914, "g914"), (0x915, "g915"), (0x917, "g917"), (0x918, "g918"), (0x926, "g926"), (0x97c, "g97c"), (0x4de4, "g4de4")): b(GPU + offset, settings[name]) d(GPU + 0x69e4, settings["g69e4"]) d(GPU + 0x252c, settings["g252c"]) cpu.mem_write(GPU + 0xe00, struct.pack(" _nv016961rm) calls the same OBJACR+130 # when +100 (_nv016960rm) leaves OBJACR+37b clear. That needs the PMU feature # bytes of PMU+330 (_nv052503rm on a GV100, called by the PMU constructor # _nv051986rm), which no unload case reads; they are applied here only. assert slot(PMU, 0x330) == "_nv052503rm" and slot(ACR, 0x100) == "_nv016960rm" for fuse in list(UNLOADABLE): restore_loaded(UNLOADABLE[fuse]) call("_nv052503rm", GPU, PMU) assert byte(PMU + 0x43c) == 1 UNLOADABLE[fuse] = loaded_state() oracle_rows, urows = urows, [] TRACED_REGION = transcript_reads(37715, 37722)[0x100cd4] status, PREINIT_EMPTY = unload_case(reads={0x100cd4: TRACED_REGION}, entry="_nv016961rm") assert status == 0 and byte(ACR + 0x37b) == 0 assert [token for token in PREINIT_EMPTY if token[:2] in ("r:", "w:")] == transcript_tokens( 37715, 37722), PREINIT_EMPTY status, PREINIT_SET = unload_case(entry="_nv016961rm") assert status == 0 and PREINIT_SET == DEFAULT_EVENTS status, PREINIT_FAILED = unload_case(reads={0x10a100: [0x10, 0]}, checks=(0x65,), entry="_nv016961rm") assert status == 0x65 PREINIT = { "body": "_nv016961rm (OBJACR PreInitLocked, stage thunk _nv004038rm): OBJACR+108 " "_nv016733rm and +118 _nv016735rm (constant zero), +100 _nv016960rm, then " "OBJACR+130 _nv016972rm when OBJACR+37b and +391 are clear", "region_1_as_traced": { "transcript_lines": [37715, 37722], "events": PREINIT_EMPTY, "result": "the eight accesses of the transcript lines and nothing else; status 0"}, "region_1_set": { "events": len(PREINIT_SET), "result": "the event list equals the default Unload case: the unlock image runs on " "the PMU during PreInit; status 0"}, "region_1_set_and_the_pmu_never_halts": { "status": hex(status), "result": "the body returns the status of OBJACR+130 (0x65)"}, } urows = oracle_rows oracle = "\n".join(urows) + "\n" (out / "original-acr-unload.txt").write_text(oracle) report = { "original_sha256": DIGEST, "chip_hal": "0x23", "rm_hal": 2, "environment": "tools/check_gpu_acr_load_binary.py executed unchanged up to the end of its " "traced V100 case (OBJACR InitLocked, OBJLSFM Load, OBJACR Load)", "load_hs_image_sha256": LOAD_IMAGE_SHA256, "executed_on_the_default_case": UNLOAD_EXECUTED, "bindings": bound_unload, "pmu_b08_object": {"class": "_nv003201rm (creator _nv006348rm -> _nv006726rm)", "vtable +0x60": "_nv004583rm -> _nv051835rm (state word +0x80 above 1)"}, "bundles": {"unload image (OBJACR+2d0)": hex(BUNDLE_UNLOAD), "PMU boot loader (PMU+370)": hex(BUNDLE_PMU_LOADER)}, "image_preparation_events": PREPARE_EVENTS, "cases": len(urows), "cases_by_kind": {"Unload _nv016962rm (U)": len(urows)}, "oracle": "target/gpu-stage/original-acr-unload.txt", "oracle_sha256": hashlib.sha256(oracle.encode()).hexdigest(), "unload_image": {"file": "target/gpu-stage/original-acr-unload-image-gv100.bin", "bytes": len(UNLOAD_IMAGE), "sha256": hashlib.sha256(UNLOAD_IMAGE).hexdigest()}, "default_case": {"boot_descriptor_words": DESCRIPTOR_WORDS, "boot_loader_words_sha256": hashlib.sha256( " ".join(LOADER_WORDS).encode()).hexdigest(), "register_accesses": sum(1 for token in DEFAULT_EVENTS if token[:2] in ("r:", "w:"))}, "physical_transcript": "none: the capture ended before any unload", "first_open_with_a_region_already_set": PREINIT, "scope": "Original GV100 OBJACR Unload after the original Load in one emulated state. " "Register values, time, the system-memory descriptor and the listed cross-object " "services are fixture-supplied; no hardware executed."} (ROOT / "reports/gpu-acr-unload-original.json").write_text(json.dumps(report, indent=2) + "\n") print(f"{len(urows)} original ACR unload cases; PreInit with region 1 set runs the same " f"unlock ({len(PREINIT_SET)} events); image sha256 " f"{report['unload_image']['sha256']}; oracle sha256 {report['oracle_sha256']}")