Files
nvdriver/tools/check_gpu_fifo_load_binary.py
nvidia-driver-rs 4526e6a816 Baseline: validated 30/30 tree with passing Level 7 hardware regression
- Updated tools/post_reboot.sh to check kernel oops taint bit and stuck driver tasks instead of <86400s uptime
- Level 7 hardware regression passed on 0000:b3:00.0 (module 37e6fa430835eee2b426019db3ad70eeb7a9e9070c09c84bd9b973cf56cbe529, 107 inventory words, 0 static mismatches, CUDA baseline verified before and after)
- Updated .gitignore to exclude build archives (*.a, *.rlib), __pycache__, and raw trace dumps
2026-11-23 23:48:38 +00:00

944 lines
46 KiB
Python

#!/usr/bin/env python3
"""Run the original GV100 OBJFIFO StateLoad and write an oracle.
Executed original code. The whole object file is loaded and relocated, so no
callee is selected by hand; the KernelFifo, OBJFIFO, OBJMC and GPU-object
function tables come from running their original binders and property
initializers with chip HAL 0x23 and RM HAL 2.
preparation the engine table constructor behind KernelFifo+1a8
(_nv040242rm -> OBJFIFO+2f0 _nv027760rm) on the device-info
registers of a physical V100; the channel-id manager
_nv040227rm; the OBJFIFO constructor _nv027761rm (registry
keys are case inputs) with _nv028163rm; the scheduler manager
object (_nv006686rm) and the OBJFIFO InitLocked step
_nv028169rm -> _nv055508rm, which creates one owner object per
runlist (_nv055507rm, class selection _nv055499rm, object
creation _nv006057rm, owner initialization through vtable +30)
and allocates its two buffers (_nv015974rm -> _nv040400rm,
size and alignment _nv040339rm).
load OBJFIFO StateLoad _nv028309rm -> _nv028308rm: +710, the reset
_nv028145rm -> _nv028143rm -> _nv043611rm -> OBJMC+130
_nv043609rm (+138, OBJBIF+608/+610 through the configuration
accessors GPU+208/+210/+218), the channel-id manager loop
(_nv040234rm, +608), OBJBIF+318 _nv017752rm, the MIGManager
function at +168, _nv028025rm (+660 _nv027982rm with +630
_nv027874rm, +668, +1d8 _nv027979rm, +1d0, +128 _nv027662rm ->
_nv030171rm, +540, +118 _nv027681rm -> _nv030976rm and GPU+5c8
_nv030977rm with the table getters GPU+740/+748/+750/+768,
+150, +140), +160 _nv027753rm (_nv027770rm -> _nv027771rm per
engine: busy check _nv027871rm with +3e8 _nv027923rm and +400
_nv027859rm, restriction _nv040361rm, +2d8 _nv028277rm with
_nv027655rm, _nv028181rm with the owner lookup _nv055498rm,
the owner's submit _nv004422rm -> _nv055557rm -> _nv015976rm
and _nv015977rm -> +3b0 _nv028192rm -> _nv028190rm -> +3b8
_nv028203rm, and the preempt _nv028101rm with +1e8 _nv028063rm
and +1e0 _nv028344rm; then the 0x2a0c write and _nv027803rm
-> _nv027804rm), +640 _nv027660rm, +508 _nv027665rm, +518
_nv027667rm, +500, +510, +780.
after KernelFifo+208 _nv040417rm with the arguments (1, 0) the early
caller _nv028064rm passes; its own argument variations.
Fixture-supplied: register access (_nv053907rm, _nv053912rm), the delay
_nv049598rm, timeout start and check (_nv059509rm, _nv059505rm), diagnostics,
the allocator, fill and copy, locks, registry lookups, the multi-GPU helpers,
the object-model ancestor lookup, the framebuffer allocation _nv043691rm of
the runlist buffers (the address is a case input; the request is recorded),
and the cross-object services: the timer function at +180 of the GPU+1f60
object, the bus function at +220 of the GPU+1f78 object (it has its own oracle
in tools/check_gpu_bus_stage_binary.py), the clock-gating feature query and
record (_nv031034rm, _nv031133rm), the PMU mutex of the LPWR reference
(_nv031518rm, _nv031522rm) with the engine disable _nv042848rm, the recovery
service _nv037737rm of the preempt wait, the timer registrations of the
scheduler manager and the write-combine flush. No hardware is involved.
"""
import bisect
import hashlib
import json
from pathlib import Path
import struct
import sys
import warnings
warnings.filterwarnings("ignore", category=UserWarning)
from elftools.elf.elffile import ELFFile # noqa: E402
from unicorn import UC_ARCH_X86, UC_HOOK_CODE, UC_MODE_64, Uc, UcError # noqa: E402
from unicorn.x86_const import (UC_X86_REG_R8, UC_X86_REG_R9, UC_X86_REG_R10, # noqa: E402
UC_X86_REG_R11, UC_X86_REG_R12, UC_X86_REG_R13, UC_X86_REG_R14,
UC_X86_REG_R15, UC_X86_REG_RAX, UC_X86_REG_RBP, UC_X86_REG_RBX,
UC_X86_REG_RCX, UC_X86_REG_RDI, UC_X86_REG_RDX, UC_X86_REG_RIP,
UC_X86_REG_RSI, UC_X86_REG_RSP)
ROOT = Path(__file__).resolve().parents[1]
ORIGINAL = Path("/home/geodd/nvidia-driver/analysis-580.178.04/extracted/kernel/nvidia/nv-kernel.o_binary")
DIGEST = "5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b"
TRANSCRIPT = ROOT / "target/trace/b3-bar0.txt"
FIRST_LINE, LAST_LINE = 140621, 140934
BASES = {".text": 0x10000000, ".data": 0x20000000, ".rodata": 0x30000000, ".bss": 0x38000000}
EXT, HEAP, OBJ, STACK, STOP = 0x08000000, 0x40000000, 0x48000000, 0x4c000000, 0x4d000000
HEAP_SIZE, OBJ_SIZE = 0x400000, 0x120000
(GPU, KFIFO, OFIFO, MC, BIF, KBIF, OBUS, TMR, INTR, LPWR, CHIP, RM, MIG, PGCTRL, CHILD, TABLE,
MEMMGR) = (OBJ + 0x10000 * index for index in range(17))
CONTINUE, TIMER_SLOT, BUS_220, LOCK = STOP + 0x100, STOP + 0x200, STOP + 0x210, STOP + 0x800
ARGS = (UC_X86_REG_RDI, UC_X86_REG_RSI, UC_X86_REG_RDX, UC_X86_REG_RCX, UC_X86_REG_R8, UC_X86_REG_R9)
THUNKS = {"rax": UC_X86_REG_RAX, "rbx": UC_X86_REG_RBX, "rcx": UC_X86_REG_RCX,
"rdx": UC_X86_REG_RDX, "rsi": UC_X86_REG_RSI, "rdi": UC_X86_REG_RDI,
"r8": UC_X86_REG_R8, "r9": UC_X86_REG_R9, "r10": UC_X86_REG_R10,
"r11": UC_X86_REG_R11, "r12": UC_X86_REG_R12, "r13": UC_X86_REG_R13,
"r14": UC_X86_REG_R14, "r15": UC_X86_REG_R15}
BINDERS = (("_nv005912rm", KFIFO), ("_nv005792rm", KFIFO), ("_nv005970rm", OFIFO),
("_nv005971rm", OFIFO), ("_nv005972rm", OFIFO), ("_nv005820rm", OFIFO),
("_nv006001rm", MC))
GPU_BINDERS = ("_nv005978rm", "_nv005980rm", "_nv005982rm", "_nv005984rm")
# Slots the load dispatches through, checked against the bindings report.
EXPECTED = {
"OBJFIFO": {"0x118": "_nv027681rm", "0x128": "_nv027662rm", "0x140": "_nv028171rm",
"0x150": "_nv028320rm", "0x160": "_nv027753rm", "0x1d0": "_nv027977rm",
"0x1d8": "_nv027979rm", "0x1e0": "_nv028344rm", "0x1e8": "_nv028063rm",
"0x2d8": "_nv028277rm", "0x2f0": "_nv027760rm", "0x3a8": "_nv027888rm",
"0x3b0": "_nv028192rm", "0x3b8": "_nv028203rm", "0x3e8": "_nv027923rm",
"0x3f0": "_nv028082rm", "0x3f8": "_nv028084rm", "0x400": "_nv027859rm",
"0x500": "_nv027657rm", "0x508": "_nv027665rm", "0x510": "_nv028161rm",
"0x518": "_nv027667rm", "0x540": "_nv027981rm", "0x5c0": "_nv027678rm",
"0x5c8": "_nv027674rm", "0x5d0": "_nv027672rm", "0x5d8": "_nv027676rm",
"0x608": "_nv028104rm", "0x630": "_nv027874rm", "0x640": "_nv027660rm",
"0x660": "_nv027982rm", "0x668": "_nv027972rm", "0x710": "_nv028136rm",
"0x780": "_nv028288rm"},
"KernelFifo": {"0x100": "_nv040425rm", "0x118": "_nv040413rm", "0x1a8": "_nv040242rm",
"0x1b8": "_nv040256rm", "0x1f0": "_nv040410rm", "0x1f8": "_nv040407rm",
"0x200": "_nv040404rm", "0x208": "_nv040417rm", "0x288": "_nv040335rm"},
"OBJMC": {"0x130": "_nv043609rm", "0x138": "_nv043605rm"},
}
# Stored by the harness from the bindings report: only these functions of the objects are used.
FOREIGN = (("OBJBIF", BIF, 0x318, "_nv017752rm"), ("OBJBIF", BIF, 0x608, "_nv017686rm"),
("OBJBIF", BIF, 0x610, "_nv017682rm"), ("MIGManager", MIG, 0x168, "_nv046163rm"))
GPU_SLOTS = {0x208: "_nv031264rm", 0x210: "_nv031094rm", 0x218: "_nv031092rm",
0x5c8: "_nv030977rm", 0x740: "_nv030423rm", 0x748: "_nv030728rm",
0x750: "_nv030519rm", 0x768: "_nv030894rm"}
SERVICES = {"OBJTMR": ("0x180", "_nv059553rm"), "OBJBUS": ("0x220", "_nv018640rm")}
raw = ORIGINAL.read_bytes()
assert hashlib.sha256(raw).hexdigest() == DIGEST
bindings = json.loads((ROOT / "reports/gv100-engine-hal-bindings.json").read_text())
assert bindings["original_sha256"] == DIGEST
tables = {entry["class_label"]: entry["hal_slots"] for entry in bindings["classes"]}
for label, slots in EXPECTED.items():
for slot, function in slots.items():
assert tables[label][slot]["function"] == function, (label, slot)
for label, base, slot, function in FOREIGN:
assert tables[label][f"{slot:#x}"]["function"] == function, (label, slot)
for label, (slot, function) in SERVICES.items():
assert tables[label][slot]["function"] == function, (label, slot)
snapshot = json.loads((ROOT / "reports/hardware-inventory-original-b3.json").read_text())["inventory"]
DEVICE_INFO = {int(key, 16): int(value, 16) for key, value in snapshot.items()
if int(key, 16) == 0x2004 or 0x2390 <= int(key, 16) < 0x23d0
or 0x22700 <= int(key, 16) < 0x22800}
with ORIGINAL.open("rb") as stream:
elf = ELFFile(stream)
index = {section.name: number for number, section in enumerate(elf.iter_sections())}
sections = {name: bytearray(elf.get_section_by_name(name).data()) if name != ".bss"
else bytearray(elf.get_section_by_name(name)["sh_size"]) for name in BASES}
symbol_bytes = elf.get_section_by_name(".symtab").data()
strings = elf.get_section_by_name(".strtab").data()
relocations = {name: elf.get_section_by_name(".rela" + name).data()
for name in (".text", ".data", ".rodata")}
section_base = {index[name]: base for name, base in BASES.items()}
symbols, by_name, externals, functions = [], {}, {}, []
for name_offset, info, other, section, value, size in struct.iter_unpack("<IBBHQQ", symbol_bytes):
name = strings[name_offset:strings.index(b"\0", name_offset)].decode()
address = None
if section == 0 and name:
address = externals.setdefault(name, EXT + 0x100 + 16 * len(externals))
elif section in section_base:
address = section_base[section] + value
if name:
by_name[name] = address
if info & 15 == 2 and section == index[".text"]:
functions.append((address, size, name))
symbols.append(address)
functions.sort()
starts = [entry[0] for entry in functions]
for name, blob in relocations.items():
data, base = sections[name], BASES[name]
for offset, info, addend in struct.iter_unpack("<QQq", blob):
kind, target = info & 0xffffffff, symbols[info >> 32]
if target is None:
continue
if kind == 1:
struct.pack_into("<Q", data, offset, (target + addend) & (1 << 64) - 1)
elif kind in (2, 4):
struct.pack_into("<i", data, offset, target + addend - (base + offset))
elif kind == 10:
struct.pack_into("<I", data, offset, target + addend)
else:
assert kind == 11, kind
struct.pack_into("<i", data, offset, target + addend)
def function_at(address):
position = bisect.bisect_right(starts, address) - 1
if position >= 0:
start, size, name = functions[position]
if start <= address < start + max(size, 1):
return name
return None
cpu = Uc(UC_ARCH_X86, UC_MODE_64)
for name, base in BASES.items():
cpu.mem_map(base, (len(sections[name]) + 0xfff) & ~0xfff)
cpu.mem_write(base, bytes(sections[name]))
for base, size in ((EXT, 0x10000), (HEAP, HEAP_SIZE), (OBJ, OBJ_SIZE), (STACK, 0x100000),
(STOP, 0x1000)):
cpu.mem_map(base, size)
executed, calls = set(), []
state = {}
def q(address):
return struct.unpack("<Q", cpu.mem_read(address, 8))[0]
def d(address):
return struct.unpack("<I", cpu.mem_read(address, 4))[0]
def b(address):
return cpu.mem_read(address, 1)[0]
def wq(address, value):
cpu.mem_write(address, struct.pack("<Q", value & (1 << 64) - 1))
def wd(address, value):
cpu.mem_write(address, struct.pack("<I", value & 0xffffffff))
def wb(address, value):
cpu.mem_write(address, bytes([value & 0xff]))
def text(address):
return bytes(cpu.mem_read(address, 64)).split(b"\0")[0].decode()
def allocate(size, fill=0):
address = state["heap"]
state["heap"] += (size + 0x1f) & ~0xf
assert state["heap"] < HEAP + HEAP_SIZE
cpu.mem_write(address, bytes([fill]) * size)
return address
def leave(value=0):
rsp = cpu.reg_read(UC_X86_REG_RSP)
cpu.reg_write(UC_X86_REG_RSP, rsp + 8)
cpu.reg_write(UC_X86_REG_RAX, value & (1 << 64) - 1)
cpu.reg_write(UC_X86_REG_RIP, q(rsp))
def call(target, *arguments, stack=()):
for register, argument in zip(ARGS, arguments):
cpu.reg_write(register, argument & (1 << 64) - 1)
rsp = (STACK + 0xf0000 - 8 * len(stack)) & ~0xf
rsp -= 8
cpu.reg_write(UC_X86_REG_RSP, rsp)
# The object code keeps locals on a second stack addressed through RBP.
cpu.reg_write(UC_X86_REG_RBP, STACK + 0x80000)
wq(rsp, STOP)
for number, value in enumerate(stack):
wq(rsp + 8 + 8 * number, value)
try:
cpu.emu_start(target if isinstance(target, int) else by_name[target], STOP)
except UcError as error:
pc = cpu.reg_read(UC_X86_REG_RIP)
raise RuntimeError(f"{error} at {pc:#x} {function_at(pc)} after {calls[-12:]}") from error
assert cpu.reg_read(UC_X86_REG_RIP) == STOP, target
return cpu.reg_read(UC_X86_REG_RAX)
def nested(target, arguments, after):
"""Enter an original function from a fixture hook and resume the caller afterwards."""
rsp = cpu.reg_read(UC_X86_REG_RSP) - 8
cpu.reg_write(UC_X86_REG_RSP, rsp)
wq(rsp, CONTINUE)
for register, argument in zip(ARGS, arguments):
cpu.reg_write(register, argument)
cpu.reg_write(UC_X86_REG_RIP, target if isinstance(target, int) else by_name[target])
state["continuations"].append(after)
def emit(token):
state["events"].append(token)
def pop(name, default):
values = state["case"][name]
return values.pop(0) if values else default
def read_register(a):
assert (a[0], a[1] & 0xffffffff, a[2] & 0xffffffff) == (GPU + 0x4120, 0, 0)
offset = a[3] & 0xffffffff
if offset in DEVICE_INFO and state["phase"] == "table":
return DEVICE_INFO[offset]
values = state["case"]["reads"].get(offset)
if values:
value = values.pop(0) if len(values) > 1 else values[0]
else:
value = state["case"]["default_read"](offset)
if state["phase"] == "init" and offset != 0x2008 and "DEBUG" in sys.argv:
print("init read", hex(offset), calls[-10:])
emit(f"r:{offset:x}:{value:x}")
return value
def write_register(a):
assert (a[0], a[1] & 0xffffffff, a[2] & 0xffffffff) == (GPU + 0x4120, 0, 0)
emit(f"w:{a[3] & 0xffffffff:x}:{a[4] & 0xffffffff:x}")
return 0
def diagnostic(a):
emit(f"e:{a[0] & 0xffffffff:x}:{a[1] & 0xffffffff:x}")
return 0
def registry(a):
key = text(a[1])
state["keys"].append(key)
value = state["case"]["registry"].get(key)
if value is None:
return 0x57
wd(a[2], value)
return 0
def timeout_start(a):
assert a[0] == GPU + 0x1e08
emit(f"ts:{a[2] & 0xffffffff:x}:{a[3] & 0xffffffff:x}")
return 0
def timeout_check(a):
assert a[0] == GPU + 0x1e08
status = pop("check", 0)
state["checks"] = state.get("checks", 0) + 1
assert state["checks"] < 2000, "the case never ends its wait"
emit(f"tc:{a[2] & 0xffffffff:x}:{status:x}")
return status
def framebuffer_allocate(a):
"""The runlist buffers of OBJFIFO InitLocked: the request is recorded and the descriptor
is described at the case's address with the original _nv043698rm."""
descriptor = a[0]
request = (q(descriptor + 0x30), q(descriptor + 0x28), d(descriptor + 0x70),
d(descriptor + 0xa0), b(descriptor + 0x58) if False else 0)
state["requests"].append(request[:4])
address = state["case"]["buffers"].pop(0)
nested("_nv043698rm", [descriptor, 2, address, q(descriptor + 0x30)], lambda unused: 0)
def feature_state(a):
value = pop("feature", 0)
emit(f"F:{a[1] & 0xffffffff:x}:{a[2] & 0xffffffff:x}:{value:x}")
return value
def record_feature(a):
emit(f"G:{a[1] & 0xffffffff:x}:{a[2] & 0xffffffff:x}:{a[3] & 0xff:x}")
return 0
def mutex_acquire(a):
"""_nv031518rm(mutex manager, 6, &token, 0)."""
assert a[0] == q(GPU + 0x1f50) and a[1] & 0xffffffff == 6
status = pop("mutex", 0)
emit(f"ma:{d(a[2]):x}:{status:x}")
if status == 0:
wd(a[2], 0x55)
return status
def mutex_release(a):
assert a[0] == q(GPU + 0x1f50) and a[1] & 0xffffffff == 6
emit("mr")
return 0
def engine_disable(a):
emit(f"pd:{a[2] & 0xffffffff:x}")
return 0
HANDLERS = {
"_nv053907rm": read_register, "_nv053912rm": write_register,
"_nv047869rm": diagnostic, "_nv047868rm": diagnostic, "_nv047867rm": diagnostic,
"_nv046745rm": lambda a: emit(f"A:{a[0] & 0xffffffff:x}") or 0,
"_nv046747rm": lambda a: emit(f"S:{a[0] & 0xffffffff:x}:{a[1] & 0xffffffff:x}") or 0,
"_nv046744rm": lambda a: emit(f"A:{a[0] & 0xffffffff:x}") or 0,
"_nv052687rm": lambda a: allocate(a[0], 0xcc), "_nv052701rm": lambda a: 0,
"_nv052705rm": lambda a: cpu.mem_write(a[0], bytes([a[1] & 0xff]) * (a[2] & 0xffffffff)) or a[0],
"_nv052695rm": lambda a: cpu.mem_write(a[0], bytes(cpu.mem_read(a[2], a[3] & 0xffffffff))) or a[0],
"_nv052744rm": lambda a: LOCK, "_nv052743rm": lambda a: 0, "_nv052747rm": lambda a: 0,
"_nv049786rm": registry,
"_nv049086rm": lambda a: GPU,
"_nv005245rm": lambda a: a[0] if OBJ <= a[0] < OBJ + OBJ_SIZE else None,
"_nv031390rm": lambda a: 0, "_nv031395rm": lambda a: 1, "_nv031426rm": lambda a: GPU,
"_nv031478rm": lambda a: 0, "_nv031482rm": lambda a: 0,
"_nv049598rm": lambda a: emit(f"t:{a[0] & 0xffffffff:x}") or 0,
"_nv059509rm": timeout_start, "_nv059505rm": timeout_check,
"_nv037737rm": lambda a: emit("sv") or 0,
"_nv043691rm": framebuffer_allocate,
"_nv031034rm": feature_state, "_nv031133rm": record_feature,
"_nv031518rm": mutex_acquire, "_nv031522rm": mutex_release, "_nv042848rm": engine_disable,
"_nv059643rm": lambda a: 0,
"os_is_vgx_hyper": lambda a: 0,
"os_flush_cpu_write_combine_buffer": lambda a: emit("f") or 0,
}
def install(address, handler):
def run(emu, pc, size, unused):
value = handler([emu.reg_read(register) for register in ARGS])
if value is not None:
leave(value)
cpu.hook_add(UC_HOOK_CODE, run, begin=address, end=address)
for name, handler in HANDLERS.items():
install(externals[name] if name in externals else by_name[name], handler)
for name, address in externals.items():
if name.startswith("__x86_indirect_thunk_"):
register = THUNKS[name.rsplit("_", 1)[1]]
cpu.hook_add(UC_HOOK_CODE, lambda emu, pc, size, register: emu.reg_write(
UC_X86_REG_RIP, emu.reg_read(register)), register, begin=address, end=address)
def resume(emu, pc, size, unused):
value = state["continuations"].pop()(emu.reg_read(UC_X86_REG_RAX))
if value is not None:
leave(value)
cpu.hook_add(UC_HOOK_CODE, resume, begin=CONTINUE, end=CONTINUE)
install(TIMER_SLOT, lambda a: emit(f"d:{a[2] & 0xffffffff:x}") or 0)
install(BUS_220, lambda a: emit("b220") or 0)
TIMER_OTHER = STOP + 0x230
install(TIMER_OTHER, lambda a: 0)
def record_function(emu, address, size, unused):
name = function_at(address)
if name and address == by_name.get(name):
executed.add(name)
calls.append(name)
del calls[:-64]
def unexpected(emu, address, size, unused):
for name, target in externals.items():
if target == address and name not in HANDLERS and not name.startswith("__x86"):
raise AssertionError(f"unexpected external {name} after {calls[-8:]}")
cpu.hook_add(UC_HOOK_CODE, unexpected, begin=EXT, end=EXT + 0x10000)
PRISTINE = {name: bytes(sections[name]) for name in (".data", ".bss")}
TRACED_BUFFERS = [0x7fdb70000 - 0x20000 * number for number in range(26)]
# Register values of the traced V100 (transcript lines 140621-140934) where they matter.
TRACED_READS = {0x88004: [0x100506], 0x200: [0x1fecdff1], 0x88014: [0xc], 0x88018: [0x39a0],
0x2a04: [0x800f4240]}
def default_case():
return dict(reads={key: list(value) for key, value in TRACED_READS.items()},
default_read=lambda offset: 0xeffffeff if offset & 0xfff == 0x13c else 0,
registry={}, check=[], feature=[], mutex=[], buffers=list(TRACED_BUFFERS),
channels=0x1000, flags=0, gpu={0x911: 1}, lpwr=None, mc=True, mig=True,
overrides=[], fifo={}, drop_owner=None, restricted=[], gpu_1e0c=0x7a120,
gpu_1e28=0)
def construct(case):
"""Objects as creation, the binders, the constructors and InitLocked leave them."""
cpu.mem_write(OBJ, bytes(OBJ_SIZE))
for name, content in PRISTINE.items():
cpu.mem_write(BASES[name], content)
cpu.mem_write(CHIP + 0x10, struct.pack("<H", 0x23))
cpu.mem_write(RM + 0x10, struct.pack("<H", 2))
state.update(heap=HEAP, events=[], continuations=[], case=case, requests=[], keys=[],
phase="table", records={})
for binder, target in BINDERS:
call(binder, target, CHIP, RM)
for label, base in (("OBJFIFO", OFIFO), ("KernelFifo", KFIFO), ("OBJMC", MC)):
for slot, function in EXPECTED[label].items():
assert q(base + int(slot, 16)) == by_name[function], (label, slot)
wq(GPU + 0x80, CHIP)
wq(GPU + 0x88, RM)
for binder in GPU_BINDERS:
call(binder, GPU)
for slot, function in GPU_SLOTS.items():
assert q(GPU + slot) == by_name[function], hex(slot)
for label, base, slot, function in FOREIGN:
wq(base + slot, by_name[function])
wq(TMR + 0x180, TIMER_SLOT)
for slot in (0x1a0, 0x1a8, 0x1f8, 0x200):
wq(TMR + slot, TIMER_OTHER)
wq(OBUS + 0x220, BUS_220)
for offset, target in ((0x22d0, KFIFO), (0x22d8, OFIFO), (0x1e88, BIF), (0x1e90, KBIF),
(0x1f78, OBUS), (0x1f60, TMR), (0x2110, INTR), (0x1f50, GPU + 0xf000),
(0x1ea0, MC), (0x1fc0, MIG)):
wq(GPU + offset, target)
wb(GPU + 0x915, 1)
wd(GPU + 0x1e0c, case["gpu_1e0c"])
wd(GPU + 0x1e28, case["gpu_1e28"])
# The engine table from the device-info registers of the physical V100.
assert call(q(KFIFO + 0x1a8), GPU, KFIFO) & 0xffffffff == 0
assert (d(KFIFO + 0x340), d(KFIFO + 0x33c), d(KFIFO + 0x338), d(KFIFO + 0x2f0)) == (
16, 15, 13, 14)
# The constructor's access check GPU+558 (_nv030303rm) reads register 0x200.
state["events"].clear()
state["phase"] = "init"
assert call("_nv040227rm", GPU, KFIFO) & 0xffffffff == 0
assert state["events"] == [f"r:2008:{case['channels']:x}"], state["events"]
state["events"].clear()
assert call("_nv027761rm", GPU, OFIFO) & 0xffffffff == 0
constructor_events = list(state["events"])
state["events"].clear()
assert call("_nv006686rm", OFIFO + 0x7e0, 0, 0) & 0xffffffff == 0
status = call("_nv028169rm", GPU, OFIFO) & 0xffffffff
assert status == 0, hex(status)
assert not state["continuations"] and not state["events"], state["events"]
return constructor_events
CACHE = {}
def prepare(case):
key = (case["channels"], tuple(case["buffers"]), tuple(sorted(case["registry"].items())),
case["gpu_1e0c"], case["gpu_1e28"])
if key not in CACHE:
buffers = list(case["buffers"])
case["reads"].setdefault(0x2008, [case["channels"]])
constructor_events = construct(case)
CACHE[key] = (bytes(cpu.mem_read(OBJ, OBJ_SIZE)),
bytes(cpu.mem_read(HEAP, state["heap"] - HEAP)), state["heap"],
{name: bytes(cpu.mem_read(BASES[name], len(sections[name])))
for name in (".data", ".bss")},
list(state["requests"]), list(state["keys"]), constructor_events,
len(buffers) - len(case["buffers"]))
objects, heap, top, data, requests, keys, constructor_events, used = CACHE[key]
cpu.mem_write(OBJ, objects)
cpu.mem_write(HEAP, heap)
for name, content in data.items():
cpu.mem_write(BASES[name], content)
state.update(heap=top, events=[], continuations=[], case=case, requests=list(requests),
keys=list(keys), phase="load", records={}, constructor=constructor_events,
checks=0)
case["reads"].pop(0x2008, None)
wq(GPU + 0x1ea0, MC if case["mc"] else 0)
wq(GPU + 0x1fc0, MIG if case["mig"] else 0)
# Case state the engine constructors and other engines own.
for offset, value in case["gpu"].items():
wb(GPU + offset, value)
for offset, (width, value) in case["fifo"].items():
cpu.mem_write(OFIFO + offset, value.to_bytes(width, "little"))
if case["lpwr"] is not None:
lpwr = case["lpwr"]
wq(GPU + 0x22c8, LPWR)
wb(LPWR + 0x271, lpwr.get("byte_271", 1))
if lpwr.get("pgctrl", True):
wq(LPWR + 0x11c0, PGCTRL)
wd(PGCTRL + 0xe0, lpwr.get("mask", 0))
wd(PGCTRL + 0x130, lpwr.get("policy", 0))
if lpwr.get("child", True):
wq(LPWR + 0x11d8, CHILD)
wb(CHILD + 0x183, lpwr.get("byte_183", 0))
wb(CHILD + 0x184, lpwr.get("byte_184", 0))
if case["overrides"]:
cpu.mem_write(TABLE, b"".join(struct.pack("<3I", *entry) for entry in case["overrides"]))
wq(GPU + 0x6a38, TABLE)
wd(GPU + 0x6a40, len(case["overrides"]))
if case["drop_owner"] is not None:
manager = q(OFIFO + 0x7e0)
wq(manager + 0x58, q(manager + 0x58) & ~(1 << case["drop_owner"]))
def note_record(emu, address, size, unused):
"""_nv015977rm(scheduler, gpu, fifo, record, ...): the buffer record of each runlist."""
scheduler, record = emu.reg_read(UC_X86_REG_RDI), emu.reg_read(UC_X86_REG_RCX)
state["records"][d(scheduler + 0x48)] = (scheduler, record)
cpu.hook_add(UC_HOOK_CODE, note_record, begin=by_name["_nv015977rm"], end=by_name["_nv015977rm"])
def owner_states():
"""Per runlist the load submitted: current buffer index, entry count, the word at +504,
the bytes at +500 and +50c of the buffer record and byte +50 of the scheduler."""
return {runlist: (d(record + 0x490), d(record + 0x4f8), d(record + 0x504),
b(record + 0x500), b(record + 0x50c), b(scheduler + 0x50))
for runlist, (scheduler, record) in sorted(state["records"].items())}
rows = []
GPU_BYTES = (0x911, 0x93b, 0x917, 0x918, 0x919, 0x926, 0x52f2, 0x52f3)
FIFO_FIELDS = ((0x808, 4), (0x80c, 1), (0x80d, 1), (0x810, 4), (0x814, 4), (0x7c7, 1), (0x838, 1))
def listed(values):
return "/".join(f"{value:x}" for value in values) or "-"
def run(kind, **changes):
case = default_case()
case.update(changes)
inputs = dict(reads={key: list(value) for key, value in case["reads"].items()},
check=list(case["check"]), feature=list(case["feature"]),
mutex=list(case["mutex"]), buffers=list(case["buffers"]))
prepare(case)
requests = list(state["requests"])
config = [int.from_bytes(cpu.mem_read(OFIFO + offset, width), "little")
for offset, width in FIFO_FIELDS]
status = call("_nv028309rm", GPU, OFIFO, case["flags"]) & 0xffffffff
assert not state["continuations"]
events = list(state["events"])
stored = (b(GPU + 0x99f), d(GPU + 0x6bd8), d(OFIFO + 0x7f0), b(OFIFO + 0x80d),
b(OFIFO + 0x838))
lpwr = case["lpwr"]
fields = [f"{case['flags']:x}", f"{int(case['mc'])}", f"{int(case['mig'])}",
" ".join(f"{case['gpu'].get(offset, 0):x}" for offset in GPU_BYTES),
"-" if lpwr is None else " ".join(f"{value:x}" for value in (
int(lpwr.get("pgctrl", True)), lpwr.get("mask", 0), lpwr.get("policy", 0),
lpwr.get("byte_271", 1), int(lpwr.get("child", True)),
lpwr.get("byte_183", 0), lpwr.get("byte_184", 0))),
" ".join(f"{value:x}" for value in config),
"-" if case["drop_owner"] is None else f"{case['drop_owner']:x}",
",".join(f"{offset:x}:{listed(values)}"
for offset, values in sorted(inputs["reads"].items())) or "-",
listed(inputs["check"]), listed(inputs["feature"]), listed(inputs["mutex"]),
listed(inputs["buffers"]),
",".join("%x:%x:%x" % entry for entry in case["overrides"]) or "-"]
owners = " ".join(f"{runlist:x}:" + ":".join(f"{value:x}" for value in values)
for runlist, values in owner_states().items()) or "-"
rows.append(f"{kind};" + ";".join(fields) + f";{status:x};"
+ " ".join(f"{value:x}" for value in stored) + f";{owners};" + " ".join(events))
return case, status, events, stored, requests
def transcript_case():
"""Read values of transcript lines FIRST_LINE to LAST_LINE, in order per register."""
lines = TRANSCRIPT.read_text().split("\n")[FIRST_LINE - 1:LAST_LINE]
reads, tokens = {}, []
for line in lines:
kind, offset, value = line.split()[:3]
offset, value = int(offset, 16), int(value, 16)
tokens.append(f"{kind.lower()}:{offset:x}:{value:x}")
if kind == "R":
reads.setdefault(offset, []).append(value)
return reads, tokens
class Random:
"""Deterministic values for the register words."""
def __init__(self, seed):
self.state = seed
def word(self):
self.state = (self.state * 6364136223846793005 + 1442695040888963407) & (1 << 64) - 1
return self.state >> 32
def pick(self, values):
return values[self.word() % len(values)]
def main():
hook = cpu.hook_add(UC_HOOK_CODE, record_function, begin=BASES[".text"],
end=BASES[".text"] + len(sections[".text"]))
# The physical V100: the Lpwr object as its constructor leaves it (reports/
# gpu-clock-gating-providers-validation.json), no LPWR engine supported yet.
transcript = None
v100 = dict(lpwr={})
if TRANSCRIPT.exists():
reads, tokens = transcript_case()
bus = [token for token in tokens
if token.split(":")[1] in ("1100", "1140", "9080", "88714")]
v100["reads"] = {offset: values for offset, values in reads.items()
if offset not in (0x1100, 0x9080, 0x88714)}
case, status, physical, stored, requests = run("V", **v100)
cpu.hook_del(hook)
load_executed = set(executed)
table = bytes(cpu.mem_read(q(KFIFO + 0x348), 1600))
assert status == 0 and stored == (1, 0, 0x7fffffff, 0, 0), (status, stored)
assert set(requests) == {(0x20000, 0x1000, 2, 0x86)} and len(requests) == 26
assert not any(token[0] in "eAS" for token in physical)
state["events"].clear()
call(q(KFIFO + 0x208), GPU, KFIFO, 1, 0)
assert state["events"] == ["w:2254:10000000"]
if TRANSCRIPT.exists():
registers = []
for token in physical:
if token == "b220":
registers += bus
elif token[0] in "rw" and token[1] == ":":
registers.append(token)
registers += state["events"]
assert registers == tokens, "transcript"
transcript = {"lines": f"{FIRST_LINE}-{LAST_LINE}", "register_accesses": len(tokens),
"equal": True,
"bus_function_accesses_taken_from_the_transcript": bus,
"last_line_is": "KernelFifo+208 _nv040417rm(gpu, fifo, 1, 0), called by "
"_nv028064rm after the load"}
rows.insert(0, "T;" + table.hex())
random = Random(0x28309)
# Load flags, missing objects, GPU bytes.
for flags in (0, 1, 2, 3, 0xfffffffe, 0xffffffff):
for lpwr in (None, {}):
run("L", flags=flags, lpwr=lpwr)
for mc in (True, False):
for mig in (True, False):
run("L", mc=mc, mig=mig, lpwr={})
for gpu_911 in (0, 1, 0x80):
for gpu_93b in (0, 1, 0x80):
run("L", gpu={0x911: gpu_911, 0x93b: gpu_93b}, lpwr={})
# The Lpwr object, its two children and the feature queries of the table loads.
for lpwr in (None, dict(child=False), dict(pgctrl=False), dict(byte_183=1), dict(byte_184=1),
dict(byte_183=1, byte_184=1), dict(byte_271=0, mask=4), dict(mask=4),
dict(mask=1), dict(mask=1, policy=2), dict(mask=1, policy=0xfffffffd),
dict(mask=5, policy=2), dict(mask=0xfffffffa, policy=2), dict(mask=2)):
for feature in ([], [1, 1], [1, 0], [0, 1], [2, 3], [3, 2]):
run("L", lpwr=lpwr, feature=feature)
# The LPWR reference of the scheduling switch and of the submit: mutex outcomes.
for lpwr in (dict(mask=4), dict(mask=1, policy=2), dict(mask=5, policy=2)):
for mutex in ([], [99], [99, 99, 0], [99] * 19 + [0], [99] * 20, [0x40], [99, 0x40],
[0, 99, 0, 0x65], [0x65] * 6):
run("L", lpwr=lpwr, mutex=mutex)
# Configuration: context-switch timeout, PBDMA timeout, the forced timeout byte.
for value, enable in ((0x3fffff, 1), (0, 0), (1, 1), (0x7fffffff, 1), (0, 1), (0x80000000, 0),
(0x80000000, 1), (0xffffffff, 1), (0x12345, 0), (0x7fffffff, 2)):
for debug in (0, 1):
run("L", lpwr={}, fifo={0x808: (4, value), 0x80c: (1, enable), 0x80d: (1, debug)})
for pbdma in (0, 1, 2, 0xffff, 0x10000, 0xffffffff):
for forced in (0, 1):
run("L", lpwr={}, fifo={0x814: (4, pbdma), 0x7c7: (1, forced)})
for wait in (0, 1, 0x7a120, 0xffffffff):
run("L", lpwr={}, fifo={0x810: (4, wait)})
# Register words: PCI configuration, PMC enable, PBDMA interrupt enables, scheduling
# disables, status words.
for number in range(60):
reads = {0x88004: [random.word()], 0x200: [random.word()], 0x88014: [random.word()],
0x88018: [random.word()], 0x2a04: [random.word()],
0x2630: [random.word() for unused in range(random.pick((1, 3, 30)))]}
for pbdma in range(14):
reads[0x4013c + 0x2000 * pbdma] = [random.word()]
reads[0x3080 + 4 * pbdma] = [random.word()]
for engine in range(15):
reads[0x2640 + 8 * engine] = [random.word()]
run("L", lpwr={}, reads=reads)
for word in (0, 0x1000, 0x2000, 0xa000, 0xc000, 0xe000, 0x1000a000, 0x10005000, 0x80000000,
0xffffffff, 0x10021002, 0xfff1fff):
reads = {0x3080 + 4 * pbdma: [word] for pbdma in range(14)}
reads.update({0x2640 + 8 * engine: [word] for engine in range(15)})
run("L", lpwr={}, reads=reads)
# The preempt wait: pending bits and the timeout check.
for pending in ([0xffffffff, 0], [0xffffffff, 0xffffffff, 0], [1, 0], [0x1ffe, 0],
[0xffffffff] * 5 + [0]):
for check in ([], [0x65], [0, 0x65], [0x10, 0], [0, 0, 0, 0x65], [3, 0x65]):
run("L", lpwr={}, reads={0x2638: pending}, check=check)
for row in (0, 1, 3, 7, 14):
# The row's own poll stays pending and times out.
pending = [0] * row + [0xffffffff]
for gpu in ({}, {0x917: 1}, {0x918: 1}, {0x919: 1}, {0x926: 1}):
run("L", lpwr={}, reads={0x2638: pending}, check=[0x65] * 16,
gpu={0x911: 1, **gpu})
for gpu in ({0x917: 1}, {0x918: 1}, {0x919: 1}, {0x926: 1}, {0x52f3: 1}, {0x52f2: 1},
{0x52f2: 1, 0x52f3: 1}, {0x917: 1, 0x52f3: 1}):
run("L", lpwr={}, gpu={0x911: 1, **gpu})
# A runlist without an owner object.
for runlist in range(13):
run("L", lpwr={}, drop_owner=runlist)
run("L", lpwr={}, drop_owner=6, gpu={0x911: 1, 0x917: 1})
# Register override table of the GPU object.
for overrides in ([(0x2630, 0xff, 0x100)], [(0x1fff, 1, 2), (0x2000, 0xffffffff, 0)],
[(0x3fff, 0, 0x55), (0x4000, 0, 1)], [(0xf0002100, 0xf, 0x30)],
[(0x2140, 0x7fffffff, 0), (0x2a0c, 0, 1), (0x40108, 1, 1), (0x3ffc, 3, 3)]):
run("L", lpwr={}, overrides=overrides, reads={0x2630: [0xa5a5a5a5]})
# Buffer addresses and channel counts (the request the owners make at InitLocked).
# Below 2^40: the original keeps 28 bits of the page number; core refuses the rest.
for base in (0x20000, 0xffff000000, 0x12345000, 0xff00000000, 0x1ffffff000):
run("L", lpwr={}, buffers=[(base + 0x20000 * number) & (1 << 64) - 1
for number in range(26)])
for channels in (0x1000, 0x800, 0x200, 0x80, 1, 0x1001, 0x2000):
case, status, events, stored, requests = run("L", lpwr={}, channels=channels)
assert len(set(requests)) == 1 and len(requests) == 26
rows.append("B;%x;%x %x %x %x;%x" % (channels, *requests[0], len(requests)))
# The OBJFIFO constructor's fields the load reads.
for registry, gpu_1e0c, gpu_1e28 in (
({}, 0x7a120, 0), ({}, 0x1e8480, 0x20000005), ({}, 0, 0x20ffffff),
({"RmEngineContextSwitchTimeoutUs": 0}, 0x7a120, 0),
({"RmEngineContextSwitchTimeoutUs": 1}, 0x7a120, 0),
({"RmEngineContextSwitchTimeoutUs": 0x80000000}, 0x7a120, 0),
({"RmEngineContextSwitchTimeoutUs": 0x80000123}, 0x7a120, 0),
({"RmEngineContextSwitchTimeoutUs": 0xffffffff}, 0x7a120, 0x20000002),
({"RmEngineContextSwitchTimeoutUs": 0x3e8}, 0x7a120, 0x30000003),
({"RmEngineContextSwitchTimeoutUs": 0}, 0x7a120, 0x20400000),
({"RmPbdmaTimeout": 0}, 0x7a120, 0), ({"RmPbdmaTimeout": 1}, 0x7a120, 0),
({"RmPbdmaTimeout": 0x12345678}, 0x7a120, 0),
({"RmPbdmaTimeout": 7, "RmEngineContextSwitchTimeoutUs": 0x7fffffff}, 5, 0)):
case = default_case()
case.update(registry=dict(registry), gpu_1e0c=gpu_1e0c, gpu_1e28=gpu_1e28, lpwr={})
prepare(case)
config = [int.from_bytes(cpu.mem_read(OFIFO + offset, width), "little")
for offset, width in FIFO_FIELDS]
rows.append("C;%s;%s;%x %x;%s;%s" % (
"-" if "RmPbdmaTimeout" not in registry else "%x" % registry["RmPbdmaTimeout"],
"-" if "RmEngineContextSwitchTimeoutUs" not in registry
else "%x" % registry["RmEngineContextSwitchTimeoutUs"],
gpu_1e0c, gpu_1e28, " ".join(f"{value:x}" for value in config),
" ".join(state["constructor"])))
assert state["keys"] == REGISTRY_KEYS, state["keys"]
# OBJFIFO StateUnload _nv028312rm -> _nv028311rm after a load, as the early caller's
# teardown _nv028321rm runs it (flags 0): the table unload +120 _nv027819rm ->
# _nv030368rm, the pending-interrupt service +1c8 _nv028265rm -> +190 _nv028230rm
# (+188, +130, +688 _nv028258rm -> _nv028263rm -> the owner's function at vtable +b8,
# +170) and the interrupt disable +6b8 _nv027774rm.
unload_executed = set()
def unload(pending, enabled=(0x61810101,), events=(0x1fff,), gpu=None, lpwr=None,
drop_owner=None, more=None):
case = default_case()
case.update(lpwr={} if lpwr is None else lpwr)
prepare(case)
assert call("_nv028309rm", GPU, OFIFO, 0) & 0xffffffff == 0
assert b(GPU + 0x99f) == 1
# State changed after the load.
case["gpu"] = {0x911: 1, **(gpu or {})}
for offset, value in case["gpu"].items():
wb(GPU + offset, value)
if drop_owner is not None:
manager = q(OFIFO + 0x7e0)
wq(manager + 0x58, q(manager + 0x58) & ~(1 << drop_owner))
# The MemoryManager object, with no object at +498.
wq(GPU + 0x1ed0, MEMMGR)
state["events"].clear()
executed.clear()
reads = {0x2100: list(pending), 0x2140: list(enabled), 0x2a00: list(events)}
reads.update(more or {})
case["reads"].clear()
case["reads"].update({key: list(value) for key, value in reads.items()})
hook = cpu.hook_add(UC_HOOK_CODE, record_function, begin=BASES[".text"],
end=BASES[".text"] + len(sections[".text"]))
status = call("_nv028312rm", GPU, OFIFO, 0) & 0xffffffff
cpu.hook_del(hook)
unload_executed.update(executed)
lpwr_text = " ".join(f"{value:x}" for value in (
int(case["lpwr"].get("pgctrl", True)), case["lpwr"].get("mask", 0),
case["lpwr"].get("policy", 0), case["lpwr"].get("byte_271", 1),
int(case["lpwr"].get("child", True)), case["lpwr"].get("byte_183", 0),
case["lpwr"].get("byte_184", 0))) if lpwr != "absent" else "-"
rows.append("X;%s;%s;%s;%s;%x;%x;%s" % (
" ".join(f"{case['gpu'].get(offset, 0):x}" for offset in GPU_BYTES), lpwr_text,
"-" if drop_owner is None else f"{drop_owner:x}",
",".join(f"{offset:x}:{listed(values)}" for offset, values in sorted(reads.items())),
status, b(GPU + 0x99f), " ".join(state["events"])))
return state["events"]
traced_unload = unload([0x40000000, 0])
for pending in ([0, 0], [0x40000000, 0], [0x40000000, 0x40000000], [0x800000, 0],
[0x40800000, 0x1], [0x1, 0], [0x10000, 0], [0x1000000, 0], [0x41810001, 0],
[0xffffffff, 0]):
for enabled in (0x61810101, 0x7fffffff, 0, 0x40000000, 0x41810001, 0x00800000):
if pending[0] & enabled & 0xa0000100:
# PBDMA service, the function at +718 and _nv026827rm are not executed.
continue
for events in (0x1fff, 0, 1, 0x1040, 0x2000, 0x3fff, 0x80000001):
unload(pending, (enabled,), (events,),
more={0x252c: [0x11], 0x256c: [0x22], 0x258c: [0x33]})
for gpu in ({0x917: 1}, {0x918: 1}, {0x919: 1}, {0x926: 1}, {0x93b: 1}):
unload([0x40000000, 0], gpu=gpu)
for runlist in (0, 6, 12):
for events in (0x1fff, 1 << runlist, 0x1fff & ~(1 << runlist)):
unload([0x40000000, 0], events=(events,), drop_owner=runlist)
for lpwr in ({"child": False}, {"pgctrl": False}, {"byte_184": 1}, {"byte_183": 1},
{"mask": 5, "policy": 2}):
unload([0x40000000, 0], lpwr=lpwr)
# KernelFifo+208 _nv040417rm(gpu, fifo, enable, offset).
prepare(dict(default_case(), lpwr={}))
for enable in (0, 1, 2, 0x100, 0x101, 0xff):
for offset in (0, 0xfff, 0x1000, 0x7ffdf0000, 0xffffffffff000, 0xfffffffffffff000):
state["events"].clear()
call(q(KFIFO + 0x208), GPU, KFIFO, enable, offset)
rows.append(f"U;{enable:x};{offset:x};" + " ".join(state["events"]))
out = ROOT / "target/gpu-stage"
out.mkdir(parents=True, exist_ok=True)
oracle = "\n".join(rows) + "\n"
(out / "original-fifo-load.txt").write_text(oracle)
kinds = {}
for row in rows:
kinds[row.split(";", 1)[0]] = kinds.get(row.split(";", 1)[0], 0) + 1
loads = [row.split(";") for row in rows if row[0] in "LV"]
failed = sum(1 for fields in loads if fields[14] != "0")
hooked = sorted(HANDLERS)
report = {
"original_sha256": DIGEST, "chip_hal": "0x23", "rm_hal": 2,
"entry": "_nv028309rm (OBJFIFO StateLoad) on objects built by the engine table "
"constructor, _nv040227rm, _nv027761rm and _nv028169rm; _nv040417rm",
"executed_on_the_v100_case": sorted(load_executed - set(hooked)),
"executed_count": len(load_executed - set(hooked)),
"fixture_supplied": hooked + ["OBJTMR+0x180", "OBJBUS+0x220", "OBJTMR+0x1a0/1a8/1f8/200"],
"slots_checked_against_bindings_report": EXPECTED,
"foreign_slots_stored_from_the_bindings_report": [
[label, f"{slot:#x}", function] for label, base, slot, function in FOREIGN],
"gpu_object_slots": {f"{slot:#x}": function for slot, function in GPU_SLOTS.items()},
"cases": len(rows), "cases_by_kind": kinds, "load_cases_with_nonzero_status": failed,
"kinds": {"T": "engine table of the physical V100 (16 records of 100 bytes)",
"V": "the traced V100 load", "L": "load cases",
"B": "runlist buffer request of the owners at InitLocked per channel count",
"C": "OBJFIFO constructor fields", "U": "_nv040417rm",
"X": "OBJFIFO StateUnload after a load"},
"v100_runlist_buffer_requests": {
"count": 26, "bytes": "0x20000", "alignment": "0x1000", "address_space": 2,
"descriptor_tag": "0x86", "order": "two per owner, owners created in engine "
"table order of their first engine; the load submits the first of each pair"},
"unload": {
"entry": "_nv028312rm with flags 0 after a load",
"executed": sorted(unload_executed - set(hooked)),
"traced_case_events": traced_unload,
"transcript_lines_141005_141012": "W 26ec 1fffe, R 2100 40000000, R 2140 61810101, "
"R 2a00 1fff, W 2a00 1fff, R 2100 0, W 2140 0, W 2528 0"},
"v100_events": len(physical),
"transcript_comparison": transcript,
"registry_keys_read_by_the_constructor": REGISTRY_KEYS,
"oracle": "target/gpu-stage/original-fifo-load.txt",
"oracle_sha256": hashlib.sha256(oracle.encode()).hexdigest(),
"scope": "Original GV100 OBJFIFO StateLoad with binder-selected tables on original "
"InitLocked state. Register values, timeouts, delays, memory addresses, the "
"timer and bus functions, the clock-gating feature state, the LPWR mutex and "
"the recovery service are fixture-supplied; no hardware executed."}
(ROOT / "reports/gpu-fifo-load-original.json").write_text(json.dumps(report, indent=2) + "\n")
print(f"{len(rows)} original FIFO load rows ({failed} loads with a nonzero status); executed "
f"{len(load_executed - set(hooked))} original functions"
+ ("; transcript lines %s equal" % transcript["lines"] if transcript
else "; transcript absent"))
print(report["oracle_sha256"])
REGISTRY_KEYS = ["RmPbdmaTimeout", "RmDefaultPbTimeslice", "RmReplayableFaultsDefault",
"RMHostBug1748740War", "RMEnableQoSRunlistIntr",
"RmAllowChannelCreationOnPendingReset", "RmPbdmaAcquireTimeout",
"RmPpbmaLbPbbufThrottle0", "RmPpbmaLbPbbufThrottle1", "RMOverrideVfsConfig",
"RmEngineContextSwitchTimeoutUs", "RmCtxswTimeoutDebugDump"]
if __name__ == "__main__":
main()