Files
nvdriver/tools/check_gpu_acr_load_binary.py
morebrackets faa96bbccf Preserve executed harness assertions with optimize=0 and gate HS_IMAGE write on sys.argv[0]
- Pass optimize=0 to every exec(compile(..., 'exec', optimize=0)) harness slice
  across all five ACR/Falcon binary oracles so python3 -O never drops required
  descriptor/setup calls in executed base harnesses (e.g. check_gpu_bar2_setup_binary.py).
- Gate original-acr-hs-image-gv100.bin output in check_gpu_acr_load_binary.py
  on direct entry via Path(sys.argv[0]).name == 'check_gpu_acr_load_binary.py'
  and not _PMU_ORIGINAL_ENV (instead of __file__, which pmu_original_environment.py
  impersonates).
2026-12-02 16:26:42 -08:00

1182 lines
49 KiB
Python

#!/usr/bin/env python3
"""Run the original GV100 OBJACR InitLocked and Load (ACR bootstrap on SEC2) and write an oracle.
The environment is the one tools/check_gpu_wpr_blob_binary.py builds (the
whole object relocated; GPU chip identification; OBJBSP, OBJSEC2, the PMU
class, FECS and GPCCS objects from their creators; OBJLSFM and OBJACR bound
and their properties initialised; five Falcons bound, attached and
configured). That file's setup part, up to its first case, is executed here
unchanged, so both harnesses share one description of the objects.
Executed original code (chip HAL 0x23, RM HAL 2):
OBJLSFM InitLocked _nv043236rm and Load _nv043238rm (as in the image
harness), then the writer _nv043215rm from inside the bootstrap.
OBJACR InitLocked _nv016955rm with _nv016940rm, +120 _nv016953rm,
_nv016937rm and _nv016725rm; Load _nv016956rm; +180 _nv016923rm;
the bootstrap +128 _nv016931rm with _nv016747rm, the HS runner
_nv016741rm, the image preparation _nv016905rm (bundle getter
+1f0 _nv016889rm, descriptors unpacked by the original unpacker),
the signature placement _nv016965rm, the region descriptor and
shadow copy +110 _nv016753rm (CPU branch) with +368 _nv016963rm
and _nv016932rm, the status check +158 _nv016730rm, the cleanup
_nv016748rm, the region check _nv016974rm with +150 _nv016745rm,
and _nv016973rm with +190 _nv016911rm and +198.
Falcon +248 _nv028470rm with +250 _nv028502rm (boot loader records),
the reset _nv028467rm (three times) and what it reaches in the
OBJSEC2 interface and OBJMC, _nv028746rm, +260 _nv028420rm, +98
_nv028536rm, +270 _nv028379rm, +a8 _nv028759rm with _nv013358rm,
the DMEM writer _nv028452rm, the IMEM writer _nv028523rm, +1c8
_nv028764rm, +268 _nv028781rm with _nv028782rm, +278 _nv028770rm
and +a0 _nv028537rm.
OBJMC +198 _nv043581rm, +158, +150, +188, +190 as bound by _nv006001rm.
PMU class +2f8 _nv052412rm, +3d8 _nv052308rm.
Fixture-supplied (recorded as events where they are observable):
register read _nv053907rm and write _nv053912rm; the delay _nv049598rm and
the time functions _nv059509rm, _nv059505rm, _nv059492rm; diagnostics; the
allocator, fill and copy; the registry lookup _nv049786rm; the memory
services: descriptor creation _nv043694rm, allocation _nv043691rm (the
address is a case input), _nv043704rm, _nv043699rm, _nv043721rm, _nv043696rm,
_nv043717rm, the placement override _nv043742rm, the CPU mappings
_nv043739rm/_nv043773rm and _nv044028rm/_nv044029rm (backed by a framebuffer
model; every byte the original stores is captured), the fill _nv044030rm; the
address-space services: _nv060601rm and _nv060602rm (create and destroy), the
address space's functions at +e0 and +e8, the instance block writer
_nv040832rm, MemoryManager+358, the mapping _nv026096rm and its release
_nv026107rm; KernelBus+4c8; the FIFO lookup at +1b8; the multi-GPU section
_nv031478rm; the clock-gating feature services; the functions of the GPU+1e70
object (+100), of the GPU+22c8 object's child (+178), of the GPU+20c8 object
(+238, +270) and the GPU check _nv031156rm. MemorySystem+1058, +ec8 and +ed0
run as bound by _nv005936rm. No hardware is involved.
`--traced` stops after the traced V100 case (the transcript comparison and
target/gpu-stage/original-acr-hs-image-gv100.bin) without writing the oracle.
"""
import hashlib
import itertools
import json
from pathlib import Path
import struct
import sys
if str(Path(__file__).resolve().parent) not in sys.path:
sys.path.insert(0, str(Path(__file__).resolve().parent))
from _gpu_acr_falcon_oracle_check import ( # noqa: E402
require,
write_or_check_bytes,
write_or_check_json,
write_or_check_text,
)
HERE = Path(__file__).resolve()
SOURCE = HERE.with_name("check_gpu_wpr_blob_binary.py")
MARKER = "# ------------------------------------------------- the traced V100 case"
source = SOURCE.read_text()
require(MARKER in source)
exec(compile(source[:source.index(MARKER)], str(SOURCE), "exec", optimize=0), globals()) # noqa: S102
from unicorn import UC_HOOK_MEM_WRITE as MEM_WRITE # noqa: E402
from unicorn.x86_const import UC_X86_REG_RSP as RSP # noqa: E402
TRANSCRIPT_LINES = TRANSCRIPT.read_text().split("\n")
FBMEM, FBMEM_BYTES = 0x70000000, 0x400000
DESCRIPTORS, DESCRIPTOR_BYTES = 0x68000000, 0x10000
cpu.mem_map(FBMEM, FBMEM_BYTES)
cpu.mem_map(DESCRIPTORS, DESCRIPTOR_BYTES)
# Objects this harness adds, in the spare part of the image harness's MEMORY block.
(MC, MEMSYS, LPWR, LPWR_CHILD, OBJ_1E70, OBJ_22C0, OBJ_23C8, FIFO, KBUS, KGMMU, DMA, VASPACE,
VASPACE_VTABLE, MEMMGR2) = (MEMORY + 0x8000 + 0x1800 * index for index in range(14))
require(MEMMGR2 + 0x1800 <= MEMORY + 0x20000)
trace = []
descriptors = {}
state = {"reads": {}, "checks": [], "addresses": [], "fail": {}, "counts": {}, "fb": 0}
def emit(token):
trace.append(token)
def failing(kind):
"""Status injected at the n-th call of a service (1-based), else 0."""
state["counts"][kind] = state["counts"].get(kind, 0) + 1
wanted = state["fail"].get(kind)
return wanted[1] if wanted and wanted[0] == state["counts"][kind] else 0
def unhook(*names):
for name in names:
address = text(name)
hooks.pop(address, None)
if address in installed:
cpu.hook_del(installed.pop(address))
def stack_argument(index):
return pointer(cpu.reg_read(RSP) + 8 + 8 * index)
@hook("_nv053907rm")
def register_read(a, low):
require((a[0], low[1], low[2]) == (GPU + 0x4120, 0, 0), a)
values = state["reads"].get(low[3])
require(values, f"unexpected read {low[3]:#x}")
value = values.pop(0) if len(values) > 1 else values[0]
emit(f"r:{low[3]:x}:{value:x}")
return value
@hook("_nv053912rm")
def register_write(a, low):
require((a[0], low[1], low[2]) == (GPU + 0x4120, 0, 0), a)
emit(f"w:{low[3]:x}:{low[4]:x}")
return 0
@hook("_nv049598rm")
def delay(a, low):
emit(f"t:{low[0]:x}")
return 0
@hook("_nv059509rm")
def timeout_start(a, low):
require(a[0] == GPU + 0x1e08)
emit(f"ts:{low[2]:x}:{low[3]:x}")
return 0
@hook("_nv059505rm")
def timeout_check(a, low):
require(a[0] == GPU + 0x1e08)
status = state["checks"].pop(0) if state["checks"] else 0
# A wait whose register never changes and whose time checks are used up
# would run forever: the case is wrong, not the original.
state["idle_checks"] = 0 if state["checks"] else state.get("idle_checks", 0) + 1
if state["idle_checks"] > 50000:
raise RuntimeError("the case does not terminate")
emit(f"tc:{low[2]:x}:{status:x}")
return status
@hook("_nv059492rm")
def timeout_reset(a, low):
emit("tr")
return 0
@hook("_nv031478rm")
def gpu_section(a, low):
require((a[0], low[1], low[2]) == (GPU, 0, 0), a)
emit(f"gs:{low[3]:x}")
return 0
@hook("_nv031034rm")
def feature_state(a, low):
emit(f"fs:{low[1]:x}:{low[2]:x}:0")
return 0
@hook("_nv031133rm")
def record_feature(a, low):
emit(f"rf:{low[1]:x}:{low[2]:x}:{low[3] & 0xff:x}")
return 0
@hook("_nv030608rm")
def fifo_object(a, low):
return FIFO
@hook("_nv049786rm")
def registry(a, low):
return 0x56
def new_descriptor(size, alignment, contiguous, space, cache, flags, parent=None, offset=0):
handle = DESCRIPTORS + 0x200 * (len(descriptors) + 1)
require(handle + 0x200 <= DESCRIPTORS + DESCRIPTOR_BYTES)
cpu.mem_write(handle, bytes(0x200))
q(handle + 0x30, size)
descriptors[handle] = dict(size=size, alignment=alignment, contiguous=contiguous, space=space,
cache=cache, flags=flags, address=None, backing=None, parent=parent,
offset=offset, number=len(descriptors))
return handle
def address_of_descriptor(handle):
entry = descriptors[handle]
if entry["parent"] is not None:
return address_of_descriptor(entry["parent"]) + entry["offset"]
require(entry["address"] is not None, "descriptor used before allocation")
return entry["address"]
def backing_of(handle):
entry = descriptors[handle]
if entry["parent"] is not None:
return backing_of(entry["parent"]) + entry["offset"]
return entry["backing"]
@hook("_nv043694rm")
def descriptor_create(a, low):
require(a[1] == GPU)
cache, flags = stack_argument(0) & 0xffffffff, stack_argument(1)
status = failing("create")
emit(f"dc:{low[2]:x}:{low[3]:x}:{low[4]:x}:{low[5]:x}:{cache:x}:{flags:x}:{status:x}")
if status:
q(a[0], 0)
return status
q(a[0], new_descriptor(a[2], low[3], low[4], low[5], cache, flags))
return 0
@hook("_nv043691rm")
def descriptor_allocate(a, low):
entry = descriptors[a[0]]
status = failing("allocate")
tag = word(a[0] + 0xa0)
if status:
emit(f"da:{tag:x}:{entry['size']:x}:{status:x}")
return status
entry["address"] = state["addresses"].pop(0)
entry["tag"] = tag
size = (entry["size"] + 0xfff) & ~0xfff
if state["fb"] + size + 0x1000 <= FBMEM_BYTES:
entry["backing"] = FBMEM + state["fb"]
state["fb"] += size + 0x1000
state["ranges"].append((entry["backing"], size, entry["address"]))
emit(f"da:{tag:x}:{entry['size']:x}:0:{entry['address']:x}")
return 0
@hook("_nv043704rm")
def descriptor_free(a, low):
if not a[0]:
return 0 # a null descriptor: the release functions are entered and do nothing
entry = descriptors[a[0]]
emit("df:-" if entry["parent"] is None and entry["address"] is None
else f"df:{address_of_descriptor(a[0]):x}")
return 0
@hook("_nv043699rm")
def descriptor_destroy(a, low):
if not a[0]:
return 0
entry = descriptors[a[0]]
if entry["parent"] is None:
emit("dd:-" if entry["address"] is None else f"dd:{entry['address']:x}")
return 0
@hook("_nv043721rm")
def descriptor_address(a, low):
require(low[1] == 1, a)
return address_of_descriptor(a[0]) + a[2]
@hook("_nv043696rm")
def sub_descriptor(a, low):
require(a[2] == GPU, a)
q(a[0], new_descriptor(a[4], 0, 1, 2, 0, 0, parent=a[1], offset=a[3]))
return 0
@hook("_nv043742rm")
def placement_override(a, low):
"""_nv043742rm(location, name, &address space, &cache): the case chooses the space."""
d(a[2], state["instance_space"])
return 0
def mapping(kind, handle, flags):
if failing(kind):
emit(f"{kind}:{address_of_descriptor(handle):x}:{descriptors[handle]['size']:x}:{flags:x}:"
"fail")
return 0
emit(f"{kind}:{address_of_descriptor(handle):x}:{descriptors[handle]['size']:x}:{flags:x}")
return backing_of(handle)
@hook("_nv043739rm")
def map_descriptor(a, low):
require(a[0] == GPU)
return mapping("m", a[1], low[2])
@hook("_nv043773rm")
def unmap_descriptor(a, low):
require(a[0] == GPU)
emit(f"u:{address_of_descriptor(a[1]):x}:{low[2]:x}")
return 0
@hook("_nv044028rm")
def map_region(a, low):
return mapping("M", a[1], low[2])
@hook("_nv044029rm")
def unmap_region(a, low):
emit(f"U:{address_of_descriptor(a[1]):x}:{low[2]:x}")
return 0
@hook("_nv044030rm")
def fill_descriptor(a, low):
"""_nv044030rm(memory manager, descriptor, value, bytes; zero means all)."""
entry = descriptors[a[1]]
size = a[3] or entry["size"]
cpu.mem_write(backing_of(a[1]), bytes([low[2] & 0xff]) * size)
emit(f"z:{address_of_descriptor(a[1]):x}:{size:x}:{low[2]:x}")
return 0
def framebuffer(address):
"""Framebuffer address of an emulator address inside a mapped allocation."""
for backing, size, base in state["ranges"]:
if backing <= address < backing + size:
return base + address - backing
return None
def copy(a, low):
data = bytes(cpu.mem_read(a[1], low[2]))
source, destination = framebuffer(a[1]), framebuffer(a[0])
if source is not None:
emit(f"l:{source:x}+{low[2]:x}")
if destination is not None:
emit(f"c:{destination:x}+{low[2]:x}:{hashlib.sha256(data).hexdigest()[:16]}")
cpu.mem_write(a[0], data)
return a[0]
hooks[address_of(by_name["os_mem_copy"])] = ("os_mem_copy", copy)
def framebuffer_store(emu, access, address, size, value, unused):
target = framebuffer(address)
require(target is not None, hex(address))
if trace and trace[-1].startswith("s:"):
start, length = (int(part, 16) for part in trace[-1][2:].split("+"))
if start + length == target:
trace[-1] = f"s:{start:x}+{length + size:x}"
return
emit(f"s:{target:x}+{size:x}")
cpu.hook_add(MEM_WRITE, framebuffer_store, begin=FBMEM, end=FBMEM + FBMEM_BYTES - 1)
@hook("_nv060601rm")
def address_space_create(a, low):
status = failing("vas")
emit(f"vc:{low[1]:x}:{low[3]:x}:{a[4]:x}:{a[5]:x}:{stack_argument(3):x}:{status:x}")
target = stack_argument(4)
q(target, 0 if status else VASPACE)
return status
@hook("_nv060602rm")
def address_space_destroy(a, low):
require(a[1] == VASPACE)
emit("vd")
return 0
@hook("_nv040832rm")
def instance_block_init(a, low):
require((a[0], a[2]) == (KGMMU, VASPACE), a)
status = failing("instance")
emit(f"vi:{address_of_descriptor(a[1]):x}:{low[3]:x}:{status:x}")
return status
@hook("_nv026096rm")
def address_space_map(a, low):
require((a[0], a[1], a[2]) == (GPU, DMA, VASPACE), a)
status = failing("vmap")
emit(f"vm:{address_of_descriptor(a[3]):x}:{descriptors[a[3]]['size']:x}:{a[5]:x}:"
f"{stack_argument(0):x}:{stack_argument(1):x}:{stack_argument(2):x}:{status:x}")
if not status:
q(a[4], state["virtual"].pop(0))
return status
@hook("_nv026107rm")
def address_space_unmap(a, low):
require((a[0], a[1], a[2]) == (GPU, DMA, VASPACE), a)
emit(f"vu:{a[3]:x}:{address_of_descriptor(a[4]):x}:{a[5]:x}")
return 0
@hook("_nv028817rm")
def falcon_on_gpu(a, low):
require(a[0] == GPU and a[1] == SEC2 + 0xe8, a)
return F_SEC2
@hook("_nv031156rm")
def gpu_check(a, low):
require((a[0], low[1], low[2]) == (GPU, 0, 0), a)
emit(f"g6:{state['g6']:x}")
return state["g6"]
@service("address space +e0")
def address_space_pin(a, low):
require((a[0], a[1]) == (VASPACE, GPU))
status = failing("pin")
emit(f"vp:{status:x}")
return status
@service("address space +e8")
def address_space_unpin(a, low):
require((a[0], a[1]) == (VASPACE, GPU))
emit("vq")
return 0
@service("MemoryManager+358")
def memory_page_size(a, low):
require((a[0], a[1]) == (GPU, MEMMGR), a)
status = failing("pagesize")
emit(f"ps:{address_of_descriptor(a[2]):x}:{a[3]:x}:{low[4]:x}:{status:x}")
return status
@service("KernelBus+4c8")
def bus_flush(a, low):
require(a[0] == GPU)
emit("bf")
return 0
@service("FIFO+1b8")
def fifo_lookup(a, low):
require((a[0], a[1]) == (GPU, FIFO))
status, value = (state["fifo"][0] if (low[2], low[4]) == (0, 8) else state["fifo"][1])
require((low[2], low[4]) in ((0, 8), (8, 6)), low)
if status == 0:
d(a[5], value)
emit(f"fi:{low[2]:x}:{low[3]:x}:{low[4]:x}:{status:x}:{value if not status else 0:x}")
return status
@service("GPU+1e70 object +100")
def object_1e70_100(a, low):
require((a[0], a[1], low[2], low[3]) == (GPU, OBJ_1E70, 0, 0), a)
emit(f"k1:{state['k1']:x}")
return state["k1"]
@service("GPU+22c8 child +178")
def lpwr_child_178(a, low):
require(a[0] == GPU)
emit("lp")
return 0
@service("GPU+20c8 object +238")
def vbios_238(a, low):
require((a[0], a[1], low[2]) == (GPU, VBIOS, 6), a)
emit(f"v8:{state['v238']:x}")
return state["v238"]
image_allocate = hooks[text("_nv052687rm")][1]
@hook("_nv052687rm")
def allocate_or_fail(a, low):
if state.get("no_buffer") == low[0]:
emit(f"al:{low[0]:x}:fail")
return 0
return image_allocate(a, low)
@hook("_nv049632rm")
def os_flush(a, low):
emit(f"of:{framebuffer(a[1]):x}:{a[2]:x}")
return 0
def slot(base, offset):
return entries.get(pointer(base + offset) - TEXT, hex(pointer(base + offset)))
# ----------------------------------------------------------- additional setup
# The image harness resolves the rax thunk only; the failure path of
# InitLocked calls through rdx.
from unicorn.x86_const import UC_X86_REG_RDX as RDX # noqa: E402
THUNK_RDX = address_of(by_name["__x86_indirect_thunk_rdx"])
hooks[THUNK_RDX] = ("__x86_indirect_thunk_rdx", None)
installed[THUNK_RDX] = cpu.hook_add(UC_HOOK_CODE, lambda emu, address, size, unused: emu.reg_write(
UC_X86_REG_RIP, emu.reg_read(RDX)), begin=THUNK_RDX, end=THUNK_RDX)
unhook("_nv017883rm", "_nv017897rm")
call("_nv006001rm", MC, CHIP, RM)
for binder in ("_nv005936rm",):
call(binder, MEMSYS, CHIP, RM)
q(VASPACE, VASPACE_VTABLE)
q(VASPACE_VTABLE + 0xe0, address_space_pin)
q(VASPACE_VTABLE + 0xe8, address_space_unpin)
for offset, target in ((0x1ea0, MC), (0x1ec0, MEMSYS), (0x22c8, LPWR), (0x1e70, OBJ_1E70),
(0x22c0, OBJ_22C0), (0x23c8, 0), (0x1f80, KBUS), (0x1f90, KGMMU),
(0x1fb0, DMA), (0x1f78, 0)):
q(GPU + offset, target)
q(LPWR + 0x11b8, LPWR_CHILD)
q(LPWR_CHILD + 0x178, lpwr_child_178)
q(OBJ_1E70 + 0x100, object_1e70_100)
q(KBUS + 0x4c8, bus_flush)
q(FIFO + 0x1b8, fifo_lookup)
q(MEMMGR + 0x358, memory_page_size)
q(VBIOS + 0x238, vbios_238)
q(BSS + by_name["_nv029075rm"]["st_value"], SYSTEM)
BOUND = {
"OBJACR": (ACR, {0x110: "_nv016753rm", 0x120: "_nv016953rm", 0x128: "_nv016931rm",
0x148: "_nv016916rm", 0x150: "_nv016745rm", 0x158: "_nv016730rm",
0x180: "_nv016923rm", 0x190: "_nv016911rm", 0x198: "_nv016948rm",
0x1c0: "_nv016919rm", 0x1c8: "_nv016950rm", 0x1d0: "_nv016927rm",
0x1f0: "_nv016889rm", 0x368: "_nv016963rm"}),
"Falcon": (F_SEC2, {0x98: "_nv028536rm", 0xa0: "_nv028537rm", 0xa8: "_nv028759rm",
0x128: "_nv028679rm", 0x1a0: "_nv028785rm", 0x1c8: "_nv028764rm",
0x248: "_nv028470rm", 0x250: "_nv028502rm", 0x258: "_nv028390rm",
0x260: "_nv028420rm", 0x268: "_nv028781rm", 0x270: "_nv028379rm",
0x278: "_nv028770rm", 0x2e8: "_nv028579rm"}),
"OBJMC": (MC, {0x150: "_nv043634rm", 0x158: "_nv043619rm", 0x188: "_nv043603rm",
0x190: "_nv043639rm", 0x198: "_nv043581rm", 0x1a8: "_nv043589rm"}),
"MemorySystem": (MEMSYS, {0x1058: "_nv046002rm", 0xf00: "_nv044278rm", 0xf08: "_nv044306rm",
0xec8: "_nv044823rm", 0xed0: "_nv044821rm"}),
"OBJSEC2": (SEC2, {0x3a0: "_nv055663rm"}),
"PMU class": (PMU, {0x2f0: "_nv052403rm", 0x2f8: "_nv052412rm", 0x3d8: "_nv052308rm"}),
}
bound = {}
for label, (base, slots) in BOUND.items():
for offset, function in slots.items():
require(slot(base, offset) == function, (label, hex(offset), slot(base, offset)))
bound[f"{label}+{offset:#x}"] = function
SEC2_INTERFACE = pointer(F_SEC2 + 0x5d8)
require(SEC2_INTERFACE == SEC2 + 0xe8 and pointer(SEC2 + 0x1b8) == SEC2_INTERFACE)
INTERFACE = {f"+{offset:#x}": slot(pointer(SEC2_INTERFACE), offset)
for offset in (0x58, 0x68, 0xc8, 0xd0)}
# What the OBJACR constructor _nv016731rm leaves for a GV100 without registry
# values: the region count of +148 at +394 and a zeroed array of count + 1
# records of 0x38 bytes at +3a0; +3a8 (requests) and +3b0 empty.
REGION_COUNT = call("_nv016916rm", GPU, ACR)
require(REGION_COUNT == 2)
d(ACR + 0x394, REGION_COUNT)
REGION_RECORDS = MEMMGR2
cpu.mem_write(REGION_RECORDS, bytes(0x38 * (REGION_COUNT + 1)))
q(ACR + 0x3a0, REGION_RECORDS)
# InitLocked undoes a failure through the object's vtable slot e0, the
# StateDestroy body _nv016954rm of the class.
q(ACR, MEMMGR2 + 0x400)
q(MEMMGR2 + 0x400 + 0xe0, text("_nv016954rm"))
PREPARED = snapshot()
SERVICE_REGISTERS = (0x100c80, 0x100cb8, 0x100cec, 0x100cbc, 0x70000, 0x1373a0)
V100 = dict(primary=0x7fde80000, shadow=0x7fdda0000, image=0x7fdf79000, instance=0x7fdf78000)
TRACED_READS = {0x10ac08: [0], 0x21644: [1], 0x10a108: [0x400e0100], 0x87108: [0x20420100],
0x10a100: [0x10]}
rows, counts = [], {}
FALCON_STATE = (("3a5", 0x3a5), ("3a7", 0x3a7), ("3aa", 0x3aa), ("3b1", 0x3b1), ("582", 0x582),
("628", 0x628), ("638", 0x638))
SETTINGS = dict(a385=0, a386=1, a392=0, a529=0, a37f=1, a382=1, a510=1, k108=0, k1=0, lp234=0,
g91c=0, g917=0, g918=0, g926=0, g4de4=0, g4de5=0, g90e=0, f582=0, f3b4=0, f3b5=0,
f3a6=0, mc=1, space=2, va=0x1000, ix=0x2f, bx=14, ia=0, ba=0, g6=0, v238=0,
m8cef=0, m8ccf=0, store=0, buffer=1, fail="")
def transcript_reads(first, last):
reads = {}
for line in TRANSCRIPT_LINES[first - 1:last]:
kind, offset, value, unused = line.split()
if kind == "R":
reads.setdefault(int(offset, 16), []).append(int(value, 16))
return reads
def transcript_tokens(first, last):
tokens = []
for line in TRANSCRIPT_LINES[first - 1:last]:
kind, offset, value, unused = line.split()
if int(offset, 16) not in SERVICE_REGISTERS:
tokens.append(f"{kind.lower()}:{int(offset, 16):x}:{int(value, 16):x}")
return tokens
def begin(reads, addresses, checks, settings):
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(idle_checks=0, reads={offset: list(values) for offset, values in reads.items()},
checks=list(checks), addresses=list(addresses), fail=fail, counts={},
instance_space=settings["space"], virtual=[settings["va"]],
fifo=((settings["ia"], settings["ix"]), (settings["ba"], settings["bx"])),
k1=settings["k1"], v238=settings["v238"], g6=settings["g6"],
no_buffer=None if settings["buffer"] else 0xe0000)
for offset, name in ((0x385, "a385"), (0x386, "a386"), (0x392, "a392"), (0x529, "a529"),
(0x37f, "a37f"), (0x382, "a382")):
b(ACR + offset, settings[name])
b(OBJ_1E70 + 0x108, settings["k108"])
b(LPWR + 0x234, settings["lp234"])
for offset, name in ((0x91c, "g91c"), (0x917, "g917"), (0x918, "g918"), (0x926, "g926"),
(0x4de4, "g4de4"), (0x4de5, "g4de5"), (0x90e, "g90e")):
b(GPU + offset, settings[name])
for offset, name in ((0x582, "f582"), (0x3b4, "f3b4"), (0x3b5, "f3b5"), (0x3a6, "f3a6")):
b(F_SEC2 + offset, settings[name])
q(GPU + 0x1ea0, MC if settings["mc"] else 0)
b(MEMSYS + 0x8cef, settings["m8cef"])
b(MEMSYS + 0x8ccf, settings["m8ccf"])
if settings["store"]:
handle = new_descriptor(0x2000000, 0x20000, 1, 2, 0, 0)
descriptors[handle]["address"] = settings["store"]
q(MEMSYS + 0x13c8, handle)
def fresh():
prepare(dict(DEFAULT, pre=1))
state.update(fb=0, ranges=[])
descriptors.clear()
cpu.mem_write(FBMEM, bytes(FBMEM_BYTES))
cpu.mem_write(DESCRIPTORS, bytes(DESCRIPTOR_BYTES))
def text_of(settings):
return " ".join(f"{key}={value}" if isinstance(value, str) else f"{key}={value:x}"
for key, value in settings.items())
def reads_of(reads):
return " ".join(f"{offset:x}=" + ",".join(f"{value:x}" for value in values)
for offset, values in reads.items())
def used(reads):
"""The read values a case consumed; lists whose last value repeats are kept whole."""
return {offset: values[:max(1, len(values) - len(state["reads"][offset]) + 1)]
for offset, values in reads.items()
if len(values) != len(state["reads"][offset]) or any(
token.startswith(f"r:{offset:x}:") for token in trace)}
def region_records():
out = []
for index in range(1, REGION_COUNT + 1):
base = REGION_RECORDS + 0x38 * index
fields = struct.unpack("<5I4x4Q", cpu.mem_read(base, 0x38))
out.append(":".join(f"{value:x}" for value in fields[:5]) + ":" + ":".join(
f"{descriptors[handle]['address']:x}" if handle in descriptors and
descriptors[handle]["address"] is not None else ("-" if not handle else "?")
for handle in fields[5:8]))
return ",".join(out)
def requests():
out, node = [], pointer(ACR + 0x3a8)
while node:
identity, size, alignment, attribute, mask, flag = struct.unpack(
"<IIIIIB", cpu.mem_read(node + 8, 21))
region, handle, phase = word(node + 0x20), pointer(node + 0x28), word(node + 0x30)
where = "-"
if handle in descriptors:
where = f"{descriptors[handle]['offset']:x}+{descriptors[handle]['size']:x}"
out.append(f"{identity:x}:{size:x}:{alignment:x}:{attribute:x}:{mask:x}:{region:x}:"
f"{phase:x}:{where}")
node = pointer(node)
return ",".join(out)
def init_case(registered=None, addresses=(V100["primary"], V100["shadow"], 0x7fdcc0000),
**changes):
"""OBJACR InitLocked. `registered` replaces the manager's request by direct
calls of the registration function _nv016949rm."""
settings = dict(SETTINGS, **changes)
fresh()
if registered is None:
begin(TRACED_READS, addresses, (), settings)
require(call("_nv043236rm", GPU, LSFM) == 0)
label = "lsfm"
else:
begin(TRACED_READS, addresses, (), settings)
for index, request in enumerate(registered):
cpu.mem_write(SCRATCH + 0x100, struct.pack("<6I", *request))
require(call("_nv016949rm", GPU, ACR, SCRATCH + 0x100, 0) == 0)
label = ";".join(":".join(f"{value:x}" for value in request) for request in registered)
del trace[:]
state["counts"] = {}
try:
status = call("_nv016955rm", GPU, ACR)
except Exception:
print("FAILED", label, changes, trace, function_at(cpu.reg_read(UC_X86_REG_RIP)))
raise
counts["I"] = counts.get("I", 0) + 1
rows.append("|".join(("I", text_of({key: settings[key] for key in (
"a386", "a392", "a529", "fail")}), label, ",".join(f"{value:x}" for value in addresses),
f"{status:x}", f"{word(ACR + 0x398):x}:{word(ACR + 0x3b8):x}:{byte(ACR + 0x510):x}",
region_records(), requests(), f"{diagnostics[0]:x}", " ".join(trace))))
return status
def loaded_state():
return (snapshot(), dict((key, dict(value)) for key, value in descriptors.items()),
state["fb"], list(state["ranges"]), bytes(cpu.mem_read(FBMEM, state["fb"] + 0x1000)),
bytes(cpu.mem_read(DESCRIPTORS, DESCRIPTOR_BYTES)))
def restore_loaded(saved):
cpu.mem_write(DATA, saved[0][0])
cpu.mem_write(HEAP, saved[0][2])
heap[0] = saved[0][1]
descriptors.clear()
descriptors.update((key, dict(value)) for key, value in saved[1].items())
state.update(fb=saved[2], ranges=list(saved[3]))
cpu.mem_write(FBMEM, bytes(FBMEM_BYTES))
cpu.mem_write(FBMEM, saved[4])
cpu.mem_write(DESCRIPTORS, saved[5])
def content(address, size):
for backing, length, base in state["ranges"]:
if base == address:
return hashlib.sha256(bytes(cpu.mem_read(backing, size))).hexdigest()
return "-"
def finish(kind, settings, reads, checks, status, extra=""):
consumed = used(reads)
left = len(state["checks"])
falcon = " ".join(f"{name}={byte(F_SEC2 + offset):x}" for name, offset in FALCON_STATE)
events = list(trace)
counts[kind] = counts.get(kind, 0) + 1
rows.append("|".join((kind, text_of(settings), reads_of(consumed),
",".join(f"{value:x}" for value in checks[:len(checks) - left]),
f"{status:x}", falcon + extra, f"{diagnostics[0]:x}",
" ".join(events))))
return events
# InitLocked of the traced configuration, then the manager's Load: the state
# every Load case starts from.
require(init_case() == 0)
require(word(ACR + 0x398) == 1)
PRIMARY, SHADOW = (pointer(REGION_RECORDS + 0x38 + offset) for offset in (0x18, 0x20))
require(call("_nv043238rm", GPU, LSFM) == 0)
LOADED = loaded_state()
HS_ADDRESSES = [V100["image"], V100["instance"]]
RUN_READS = {0x10ac08: [0], 0x80: [0x8f], 0x20c: [0x21ecdedc], 0x200: [0x1fecdff1],
0x873c0: [0, 1], 0x87040: [0], 0x87044: [0], 0x8710c: [1], 0x8712c: [0xca0e1136],
0x87048: [4], 0x87004: [0], 0x87604: [0x110], 0x87090: [0x40], 0x870a4: [0],
0x87008: [8], 0x870dc: [0x8ed03d, 0x8e003f], 0x87058: [0], 0x87268: [0x100],
0x87108: [0x20420100], 0x87100: [0x10, 0, 0, 0x10]}
CHECK_READS = {0x100cd4: [0x7fde802, 0x7fdf403, 0x80000c0, 0x80000c1, 0x1ffffe04, 5, 0x80000c0,
0x80000c1]}
AFTER_READS = {0x12006c: [0x10], 0x100cd4: [0x7fde802, 0x7fdf403, 0x1ffffe04, 5]}
def merged(*parts):
"""Default read lists in sequence: a register read in several phases gets each
phase's values one after the other."""
out = {}
for part in parts:
for offset, values in part.items():
out[offset] = out.get(offset, []) + list(values) if offset in out else list(values)
return out
def overridden(defaults, case):
"""A case's read values replace the default list of that register. (Until
2026-11-19 they were appended to it, so a register read once never took a
case's value: reports/gpu-acr-load-validation.json, correction_2026_11_19.)"""
out = {offset: list(values) for offset, values in defaults.items()}
out.update((offset, list(values)) for offset, values in case.items())
return out
def after_default(case):
"""The default values of a run first, then the case's: for waits that must see the
default before the value under test."""
return {offset: RUN_READS.get(offset, []) + list(values) for offset, values in case.items()}
def load_case(reads=None, checks=(), addresses=None, **changes):
"""OBJACR Load _nv016956rm."""
settings = dict(SETTINGS, **changes)
reads = overridden(merged(TRACED_READS, RUN_READS), reads or {})
if 0x100cd4 not in (reads or {}) or reads[0x100cd4] == RUN_READS.get(0x100cd4):
reads[0x100cd4] = CHECK_READS[0x100cd4] + AFTER_READS[0x100cd4]
reads.setdefault(0x12006c, [0x10])
restore_loaded(LOADED)
begin(reads, addresses or HS_ADDRESSES, checks, settings)
status = call("_nv016956rm", GPU, ACR, 0)
extra = f" p={content(V100['primary'], 0xe0000)} q={content(V100['shadow'], 0xe0000)}"
return status, finish("L", settings, reads, list(checks), status, extra)
def hs_case(reads=None, checks=(), addresses=None, kind=1, **changes):
"""The HS runner _nv016741rm(gpu, acr, type, 0)."""
settings = dict(SETTINGS, **changes)
reads = overridden(RUN_READS, reads or {})
restore_loaded(LOADED)
begin(reads, addresses or HS_ADDRESSES, checks, settings)
try:
status = call("_nv016741rm", GPU, ACR, kind, 0)
except Exception:
print("FAILED", changes, reads, checks, function_at(cpu.reg_read(UC_X86_REG_RIP)),
[t for t in trace if t[:2] not in ("r:", "w:", "tc")][-12:])
raise
extra = f" q={content(V100['shadow'], 0xe0000)}"
return status, finish("H", dict(settings, kind=kind), reads, list(checks), status, extra)
def check_case(reads, **changes):
"""The region check _nv016974rm."""
settings = dict(SETTINGS, **changes)
restore_loaded(LOADED)
begin(reads, [], (), settings)
b(ACR + 0x510, settings["a510"])
status = call("_nv016974rm", GPU, ACR)
return status, finish("C", settings, reads, [], status)
def after_case(reads, **changes):
"""_nv016973rm, called by Load after the bootstrap."""
settings = dict(SETTINGS, **changes)
restore_loaded(LOADED)
begin(reads, [], (), settings)
status = call("_nv016973rm", GPU, ACR)
return status, finish("R", settings, reads, [], status)
# ------------------------------------------------------------ the traced V100
traced = merged(TRACED_READS, transcript_reads(141023, 147277))
traced[0x87108] = [0x20420100, 0x20420100]
traced[0x10ac08] = [0]
restore_loaded(LOADED)
settings = dict(SETTINGS, k108=1)
begin(traced, HS_ADDRESSES, (), settings)
status = call("_nv016956rm", GPU, ACR, 0)
physical = finish("L", settings, traced, [], status,
f" p={content(V100['primary'], 0xe0000)} q={content(V100['shadow'], 0xe0000)}")
require(status == 0)
registers = [token for token in physical if token[:2] in ("r:", "w:")]
split = registers.index("r:80:8f")
write_expected = transcript_tokens(140591, 140620)
require(registers[:split] == write_expected, (registers[:split], write_expected))
run_expected = transcript_tokens(141024, 147277)
# Words 1 to 3 of the boot descriptor are stack bytes the original never sets.
stale = [index for index, token in enumerate(run_expected) if token.startswith("w:871c4:")][1:4]
mismatch = [(index, a, e) for index, (a, e) in enumerate(itertools.zip_longest(
registers[split:], run_expected)) if a != e and index not in stale]
require(not mismatch, mismatch[:5])
PHYSICAL = {"write_lines": [140591, 140620], "run_lines": [141024, 147277],
"register_accesses": len(registers),
"service_lines_not_compared": len(TRANSCRIPT_LINES[141023:147277]) - len(run_expected),
"stale_descriptor_words": [run_expected[index] for index in stale],
"sha256_of_normalised_lines": hashlib.sha256("\n".join(
write_expected + run_expected).encode()).hexdigest()}
PHYSICAL_EXECUTED = sorted(executed - set(SETUP))
# The image the original uploaded for the traced values, as it left the copy.
HS_IMAGE = next(bytes(cpu.mem_read(backing, 0x4700)) for backing, size, base in state["ranges"]
if base == V100["image"])
if (
not globals().get("_PMU_ORIGINAL_ENV")
and sys.argv
and Path(sys.argv[0]).name == "check_gpu_acr_load_binary.py"
):
write_or_check_bytes(
ROOT / "target/gpu-stage/original-acr-hs-image-gv100.bin",
HS_IMAGE,
check="--check" in sys.argv,
)
if "--traced" in sys.argv:
print("traced case only; image sha256", hashlib.sha256(HS_IMAGE).hexdigest())
sys.exit(0)
track(False)
# ------------------------------------------------------------------ InitLocked
for changes in (dict(a386=0), dict(a529=1), dict(a529=1, a386=0), dict(a392=1),
dict(fail="create:1:51"), dict(fail="create:2:51"), dict(fail="allocate:1:1a"),
dict(fail="allocate:2:1a"), dict(a529=1, fail="create:3:51"),
dict(a529=1, fail="allocate:3:1a"), dict(a386=0, fail="allocate:1:57")):
init_case(**changes)
for size, alignment, first, second in itertools.product(
(1, 0x1000, 0x20000, 0x20001, 0xc1000, 0x123456, 0xfffe0000),
(0x20000, 0x1000, 0x40000), ((0xc, 0xc), (5, 9), (0, 0xf)), (0, 1)):
for a392 in (0, 1):
if alignment != 0x20000 and not a392 and second:
continue
init_case(registered=[(1, size, alignment, first[0], first[1], second)], a392=a392)
init_case(registered=[])
init_case(registered=[(7, 0x3000, 0x20000, 3, 4, 0)])
# ------------------------------------------------------------------ the HS run
# Not run: a failed creation or allocation of the instance block descriptor.
# _nv028536rm does not test either result and stores through the null pointer.
hs_case()
for changes in (dict(k108=1), dict(k108=1, k1=1), dict(lp234=1), dict(a386=0), dict(buffer=0),
dict(fail="m:1:1"), dict(fail="m:2:1"), dict(fail="m:3:1"),
dict(fail="create:1:51"), dict(fail="allocate:1:1a"), dict(mc=0), dict(f582=1),
dict(fail="vas:1:51"),
dict(fail="pin:1:1a"), dict(fail="instance:1:40"), dict(fail="pagesize:1:1f"),
dict(fail="vmap:1:1a"), dict(space=1), dict(space=3), dict(space=0),
dict(va=0), dict(va=0x12345000), dict(va=0x1ffff000), dict(f3b5=1),
dict(f3b4=1), dict(f3a6=1), dict(ia=0x56), dict(ba=0x56), dict(ix=0x10, bx=3),
dict(ix=4), dict(ix=0xb7), dict(g917=1), dict(g918=1), dict(g926=1),
dict(a37f=1, g91c=1)):
hs_case(**changes)
for fuse in (0x100000, 0xffefffff, 0xffffffff):
hs_case(reads={0x10ac08: [fuse]})
# Reset: enable word, reset register, memory scrub wait and its timeout.
for enable in (0x1fec9ff1, 0, 0xffffffff, 0x4000):
hs_case(reads={0x200: [enable]})
hs_case(reads={0x200: [enable]}, f3b4=1)
for itfen in (0, 1, 2, 3, 7, 0xffffffff):
hs_case(reads={0x87048: [itfen]})
hs_case(reads={0x87048: [itfen]}, f3a6=1)
for reset in ([0, 1], [0xfffffffe, 0xffffffff], [1, 0], [0x10, 0x11]):
hs_case(reads={0x873c0: reset})
for dmactl, checks in (([6, 0], (0,)), ([7, 7, 1], (0, 0)), ([6, 6, 1], (0, 0x65)),
([6, 6, 6, 1], (0x65,)), ([2, 2, 0], (0x56,)), ([0xfffffff9], ())):
hs_case(reads={0x8710c: dmactl}, checks=checks)
for hwcfg1 in (0, 0x30, 0x10, 0x40000000, 0xffffffff, 0xc1):
hs_case(reads={0x8712c: [hwcfg1, hwcfg1 ^ 0xff]})
# Bind: register values and the two waits.
for values in ({0x87604: [0xffffffff]}, {0x87090: [0]}, {0x870a4: [0xfffffff7]},
{0x87058: [0xfffffffd]}, {0x87004: [0, 0xfffffff7, 0]},
{0x87008: [0, 8], 0x870dc: [0x5000, 0x5000, 0]},
{0x87008: [8], 0x870dc: [0x4000, 0x5000, 0x1000, 0]},
{0x87008: [0xfffffff7, 8], 0x870dc: [0xffffdfff, 0xffffdfff, 0xffff8fff]}):
hs_case(reads=values)
# The time checks of a default run: three scrub waits without a check, then
# the two bind waits (one check each), then the halt wait.
for checks in ((0x65,), (0, 0x65), (0x65, 0x65), (0x56, 0), (0, 0x56)):
hs_case(checks=checks, reads=after_default({0x87008: [0], 0x870dc: [0x1000]}))
# The DMEM boundary: _nv028457rm reads the control word back after every data
# word at or above it and stops on bit 31 or bits 30:29.
for boundary in (0, 1, 0x100, 0xffffff, 0xffffffff):
for control in ([0], [0x80000000], [0, 0x20000000], [0, 0, 0x40000000], [0x60000000],
[0x1fffffff]):
hs_case(reads={0x87268: [boundary], 0x871c0: control})
for hwcfg in (0x20420100, 0x1ff, 2, 0x202, 0x3fe, 0xffffffff):
hs_case(reads={0x87108: [hwcfg]})
# Start through CPUCTL or its alias; halt at once, late, never.
for cpuctl, checks in (([0x10, 0x10], ()), ([0x50, 0x10], ()), ([0x40, 0x10], ()),
([0, 0, 0x10], (0, 0, 0)), ([0x10] + [0] * 6 + [0xffffffff], (0,) * 8),
([0x10, 0], (0, 0, 0, 0x65)), ([0x10, 0], (0, 0, 0x65)),
([0x10, 0, 0, 0x10], (0, 0, 0x56, 0)),
([0x10, 0, 0, 0, 0x10], (0, 0, 0x56, 0x57, 0))):
hs_case(reads={0x87100: cpuctl}, checks=checks)
# Mailboxes after the run: the five scrub waits read MAILBOX0 first.
for mailbox in itertools.chain(range(1, 0x70), (0x80, 0xff, 0x100, 0xdeadbeef)):
hs_case(reads={0x87040: [0, 0, 0, 0, 0, mailbox], 0x87044: [mailbox ^ 0x55]})
# ------------------------------------------------------------ the region check
GOOD = [0x7fde802, 0x7fdf403, 0x80000c0, 0x80000c1, 0x1ffffe04, 5, 0x80000c0, 0x80000c1]
check_case({0x100cd4: GOOD})
for position, value in ((0, 0x7fde812), (0, 2), (1, 0x7fdf413), (1, 0x7fdf203), (1, 3),
(2, 0x80000d0), (3, 0x80000d1), (3, 0x8000001), (3, 0xffffffc1),
(4, 4), (4, 0x14), (5, 0x15), (5, 0x1ffffe05), (7, 0x8000c01),
(6, 0x80005c0)):
changed = list(GOOD)
changed[position] = value
check_case({0x100cd4: changed})
check_case({0x100cd4: changed}, a392=1)
for changes in (dict(g6=0xf), dict(a510=0), dict(a392=1)):
check_case({0x100cd4: GOOD}, **changes)
# The index field reads back late.
check_case({0x100cd4: [0, 0x7fde802, 1, 2, 0x7fdf403] + GOOD[2:]})
# ------------------------------------------------------ the check after the run
for changes in (dict(), dict(m8cef=1), dict(a382=0), dict(store=0x7fdfa0000),
dict(store=0x7fde00000), dict(store=0x7fdf00000), dict(store=0x7fdf60000),
dict(store=0x5fdfa0000), dict(store=0x7fbe80000), dict(store=0x7fbe90000)):
for values in ([0x7fde802, 0x7fdf403, 0x1ffffe04, 5], [2, 0x7fdf403, 4, 5],
[0x7fde802, 0x7fdf403, 0x7fdc004, 0x7fdc805], [0x7fdf402, 0x7fde803, 4, 5],
[0xfffffff2, 0xfffffff3, 0x1004, 0x2005]):
after_case({0x12006c: [0x10], 0x100cd4: values}, **changes)
# ------------------------------------------------------------------------ Load
load_case()
for changes in (dict(fail="M:1:1"), dict(a385=0, buffer=0), dict(fail="vmap:1:1a"),
dict(g4de5=1), dict(g90e=1), dict(m8cef=1), dict(a382=0), dict(mc=0),
dict(store=0x7fdf00000), dict(g91c=1)):
load_case(**changes)
load_case(reads={0x100cd4: [0x7fde812] + GOOD[1:] + AFTER_READS[0x100cd4]})
load_case(reads={0x87040: [0, 0, 0, 0, 0, 5]})
load_case(reads={0x87100: [0x10, 0]}, checks=(0, 0, 0x65))
load_case(reads={0x10a100: [0]})
# ------------------------------------------- the PMU function Load calls first
# PMU+2f8 _nv052412rm and its branch into PMU+2f0 _nv052403rm, with the real
# scratch-register functions of the GPU+20c8 object (+238 _nv060173rm, +240
# _nv060210rm), the wait at +d0 of the PMU+a00 object (_nv052260rm) and the
# halted test _nv028552rm. The PMU class function at vtable +508, called when
# the wait ends by time, is a fixture ("pd"). The PMU+a00 object is stored as
# its creator _nv006737rm leaves it (as in tools/check_gpu_acr_unload_binary.py).
PMU_A00, PMU_VTABLE_COPY = PMU + 0xa00, MEMMGR2 + 0xc00
PMU_CLASS_VTABLE = pointer(PMU)
@service("PMU class vtable +508")
def pmu_capture(a, low):
require((a[0], a[1], low[2]) == (GPU, PMU, 1), a)
emit("pd")
return 0
def pmu_step_setup():
q(PMU_A00 + 0x40, PMU_A00)
q(PMU_A00 + 0x38, PMU_A00 + 8)
q(PMU_A00, rodata(0x5ee72c0))
q(PMU_A00 + 8, rodata(0x5ee72d8))
call("_nv005854rm", PMU_A00, CHIP)
q(PMU_A00 + 0x100, F_PMU)
cpu.mem_write(PMU_VTABLE_COPY, bytes(cpu.mem_read(PMU_CLASS_VTABLE, 0x600)))
q(PMU_VTABLE_COPY + 0x508, pmu_capture)
q(PMU, PMU_VTABLE_COPY)
q(VBIOS + 0x238, text("_nv060173rm"))
q(VBIOS + 0x240, text("_nv060210rm"))
require(pointer(GPU + 0x2120) == PMU and pointer(GPU + 0x20c8) == VBIOS)
require(pointer(pointer(PMU + 0x200) + 0x18) == F_PMU)
for base, offset, function in ((PMU, 0x2f0, "_nv052403rm"), (PMU, 0x2f8, "_nv052412rm"),
(PMU_A00, 0xd0, "_nv052260rm")):
require(slot(base, offset) == function, (hex(offset), slot(base, offset)))
def pmu_step_restore():
q(PMU, PMU_CLASS_VTABLE)
q(VBIOS + 0x238, vbios_238)
q(VBIOS + 0x240, VBIOS_240_BOUND)
VBIOS_240_BOUND = pointer(VBIOS + 0x240)
bound.update({"PMU class+0x2f0 (executed)": "_nv052403rm", "PMU+a00+0xd0": "_nv052260rm",
"OBJVBIOS+0x238 (P rows, vreal)": "_nv060173rm",
"OBJVBIOS+0x240 (P rows, vreal)": "_nv060210rm"})
def pmu_case(reads, checks=()):
"""PMU+2f8 _nv052412rm(gpu, pmu)."""
settings = dict(SETTINGS, vreal=1)
restore_loaded(LOADED)
begin(reads, [], checks, settings)
pmu_step_setup()
status = call("_nv052412rm", GPU, PMU)
pmu_step_restore()
return status, finish("P", settings, reads, list(checks), status)
def load_with_pmu_step(reads, checks=()):
"""OBJACR Load with the real scratch functions and the PMU+a00 wait."""
settings = dict(SETTINGS, vreal=1)
reads = overridden(merged(TRACED_READS, RUN_READS), reads)
reads[0x100cd4] = CHECK_READS[0x100cd4] + AFTER_READS[0x100cd4]
reads.setdefault(0x12006c, [0x10])
restore_loaded(LOADED)
begin(reads, HS_ADDRESSES, checks, settings)
pmu_step_setup()
status = call("_nv016956rm", GPU, ACR, 0)
pmu_step_restore()
extra = f" p={content(V100['primary'], 0xe0000)} q={content(V100['shadow'], 0xe0000)}"
return status, finish("L", settings, reads, list(checks), status, extra)
SCRATCH6, SCRATCH1, PMU_CPUCTL = 0x1598, 0x1584, 0x10a100
RUNNING = 0x22081045 # the traced state_word 0x22082045 with field 15:12 = 1
# Halted, or a field other_status than 1: no access beyond the two reads.
for state_word in (0, 0x22082045, RUNNING, 0x1000, 0x2000, 0xf000, 0xffffffff, 0xffff0fff, 0x11000):
for cpuctl_reads in (0x10, 0x50, 0xffffffff):
status, events = pmu_case({SCRATCH6: [state_word], PMU_CPUCTL: [cpuctl_reads]})
require(status == 0 and len(events) == 2, events)
for state_word in (0, 0x22082045, 0x2000, 0x3000, 0xf000, 0xffff0fff, 0x10000, 0x100):
for cpuctl_reads in (0, 0x20, 0x40, 0xffffffef):
status, events = pmu_case({SCRATCH6: [state_word], PMU_CPUCTL: [cpuctl_reads]})
require(status == 0 and len(events) == 2, events)
# Not halted with field 1: the request and the wait.
for state_word in (RUNNING, 0x1000, 0xffff1fff):
for request_word in (0, 0x200, 0xfffffdff, 0xffffffff, 0x8045):
for cpuctl_reads in ([0x20, 0x10], [0, 0x50], [0x20, 0x20, 0x10], [0x20, 0, 0, 0, 0x30],
[0x60] * 9 + [0x70]):
status, events = pmu_case({SCRATCH6: [state_word], SCRATCH1: [request_word],
PMU_CPUCTL: cpuctl_reads})
require(status == 0 and f"w:1584:{request_word | 0x200:x}" in events, events)
require("ts:2710:0" in events and "pd" not in events)
# The wait ends by time: the capture, status 0x65.
for cpuctl_reads in ([0x20], [0], [0xffffffef]):
for check_list in ((0x65,), (0, 0x65), (0, 0, 0, 0x65)):
status, events = pmu_case({SCRATCH6: [RUNNING], SCRATCH1: [0], PMU_CPUCTL: cpuctl_reads},
check_list)
require(status == 0x65 and events[-1] == "pd", (status, events))
# Halted at the reading after the time check that reports the timeout: no capture.
status, events = pmu_case({SCRATCH6: [RUNNING], SCRATCH1: [0], PMU_CPUCTL: [0x20, 0x20, 0x10]},
(0x65,))
require(status == 0x65 and "pd" not in events)
# A time check with another status does not end the wait.
for other_status in (0x1f, 0x40, 0xffff):
status, events = pmu_case({SCRATCH6: [RUNNING], SCRATCH1: [0],
PMU_CPUCTL: [0x20, 0x20, 0x20, 0x10]}, (other_status, 0))
require(status == 0 and "pd" not in events)
status, events = pmu_case({SCRATCH6: [RUNNING], SCRATCH1: [0],
PMU_CPUCTL: [0x20, 0x20, 0x10]}, (other_status,))
require(status == other_status and "pd" not in events)
status, events = pmu_case({SCRATCH6: [RUNNING], SCRATCH1: [0], PMU_CPUCTL: [0x20]},
(other_status, 0x65))
require(status == 0x65 and events[-1] == "pd")
# Load goes on whatever the step returned: the state of a GPU the original
# driver released (CPUCTL 0x20, field 1), halting after the request; never
# halting; and the traced state through the same real functions.
REFERENCE = load_case()[1]
status, events = load_with_pmu_step({SCRATCH6: [RUNNING], SCRATCH1: [0x8045],
PMU_CPUCTL: [0x20, 0x20, 0x10]})
require(status == 0 and events[-len(REFERENCE) + 2:] == REFERENCE[2:], status)
status, events = load_with_pmu_step({SCRATCH6: [RUNNING], SCRATCH1: [0], PMU_CPUCTL: [0x20]},
(0, 0x65))
require(status == 0 and "pd" in events and events[-len(REFERENCE) + 2:] == REFERENCE[2:])
status, events = load_with_pmu_step({SCRATCH6: [0x22082045], PMU_CPUCTL: [0x10]})
require(status == 0 and events[2:] == REFERENCE[2:] and events[0] == "r:1598:22082045")
CHECK_MODE = "--check" in sys.argv
out = ROOT / "target/gpu-stage"
oracle = "\n".join(rows) + "\n"
write_or_check_text(out / "original-acr-load.txt", oracle, check=CHECK_MODE)
report = {
"original_sha256": DIGEST, "chip_hal": "0x23", "rm_hal": 2,
"environment": "setup part of tools/check_gpu_wpr_blob_binary.py, executed unchanged",
"executed_on_the_traced_case": PHYSICAL_EXECUTED,
"bindings": bound, "sec2_interface_vtable": INTERFACE,
"sec2_slot_458_reached_through_interface_c8": slot(SEC2, 0x458),
"fixture_supplied": sorted(name for name, unused in hooks.values()
if not name.startswith("__x86")),
"stored_by_harness": {
"OBJACR+0x394": "2, the result of OBJACR+148 (_nv016916rm), as the constructor "
"_nv016731rm stores it",
"OBJACR+0x3a0": "zeroed array of three 0x38-byte records, as the constructor",
"OBJACR+0x385": "0 in every case: the constructor stores bit 0 of the registry value "
"RMAcrUseCeForShadowCopy there (GV100 default 1)",
"GPU children": "1ea0 OBJMC (binder _nv006001rm), 1ec0 MemorySystem (binder "
"_nv005936rm), 1e70, 22c0, 22c8, 1f80, 1f90, 1fb0 fixture objects"},
"cases": len(rows), "cases_by_kind": {
"InitLocked (I)": counts["I"], "HS run (H)": counts["H"], "region check (C)": counts["C"],
"check after the run (R)": counts["R"], "Load (L)": counts["L"],
"PMU function at +2f8 (P)": counts["P"]},
"oracle": "target/gpu-stage/original-acr-load.txt",
"oracle_sha256": hashlib.sha256(oracle.encode()).hexdigest(),
"hs_image": {"file": "target/gpu-stage/original-acr-hs-image-gv100.bin", "bytes": len(HS_IMAGE),
"sha256": hashlib.sha256(HS_IMAGE).hexdigest()},
"physical_transcript": dict(PHYSICAL, file="target/trace/b3-bar0.txt",
reproduced_by_original_instructions=True),
"scope": "Original GV100 OBJACR InitLocked and Load with creator- and binder-selected "
"function tables. Register values, time, memory and address-space services and "
"the other listed services are fixture-supplied; no hardware executed."}
write_or_check_json(ROOT / "reports/gpu-acr-load-original.json", report, check=CHECK_MODE)
print(f"{len(rows)} original ACR load cases " + str(counts) + f"; traced case: "
f"{len(registers)} register accesses equal transcript lines 140591-140620 and "
f"141024-147277; oracle sha256 {report['oracle_sha256']}")