mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
- 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
533 lines
27 KiB
Python
533 lines
27 KiB
Python
#!/usr/bin/env python3
|
|
"""Run the original GV100 host interrupt table builder and write an oracle.
|
|
|
|
Executed original code: the builder _nv037657rm (Intr slot 0x310), the slot
|
|
functions it calls -- _nv037672rm (0x318), _nv037647rm (0x330) and
|
|
_nv037665rm (0x338), which reaches _nv037659rm through slot 0x308 -- the
|
|
binders _nv005896rm, _nv005897rm and _nv005787rm that populate the object,
|
|
the vector helpers of the table at Intr+0x430, the GPU accessors
|
|
_nv030544rm and _nv030608rm and, in the physical case, the KernelFifo
|
|
engine lookup _nv040256rm over the original constructor's 16 records.
|
|
Allocation, the engine count, the engine lookup of the modelled cases,
|
|
engine objects and their class cast, the per-engine vector providers
|
|
(_nv013840rm), the Intr slots 0x2e0 and 0x2e8, slot 0x190 of the object at
|
|
GPU+0x1ea0 and diagnostics are fixture-supplied. No hardware is involved.
|
|
"""
|
|
import bisect
|
|
import hashlib
|
|
import itertools
|
|
import json
|
|
from pathlib import Path
|
|
import struct
|
|
|
|
from elftools.elf.elffile import ELFFile
|
|
from unicorn import UC_ARCH_X86, UC_HOOK_CODE, UC_MODE_64, Uc
|
|
from unicorn.x86_const import (UC_X86_REG_R8, UC_X86_REG_R9, UC_X86_REG_RAX, UC_X86_REG_RBP,
|
|
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"
|
|
TEXT, RODATA, DATA, STACK, STOP = 0x10000000, 0x20000000, 0x30000000, 0x40000000, 0x50000000
|
|
OTHER, HEAP = 0x60000000, 0x70000000
|
|
GPU, INTR, KFIFO, KERNEL = DATA, DATA + 0x10000, DATA + 0x13000, DATA + 0x14000
|
|
OBJECTS, SERVICES, CHIP, RM = DATA + 0x15000, DATA + 0x16000, DATA + 0x3c000, DATA + 0x3d000
|
|
ENGINE_TABLE = DATA + 0x18000
|
|
INDIRECT, INDIRECT_R8, ALLOCATOR = STOP + 0x100, STOP + 0x180, STOP + 0x400
|
|
SLOT_190, LOOKUP, ROUTE_2E0, ROUTE_2E8, SUBCONTEXTS = (STOP + 0x200 + 0x10 * n for n in range(5))
|
|
TABLE, SERVICE_VECTOR = INTR + 0x430, INTR + 0x15e8
|
|
MODULE_CONTAINER = 0xef90c6e
|
|
FIXED = (0x4d3bf60, 0x4d3c050)
|
|
NONE = 0xffffffff
|
|
CONTAINER = ("_nv060217rm", "_nv060218rm", "_nv060220rm", "_nv060221rm", "_nv060222rm",
|
|
"_nv060223rm", "_nv060225rm", "_nv060226rm", "_nv060228rm", "_nv016421rm")
|
|
# The binders only store pointers, so the functions they select are listed.
|
|
ROOTS = ("_nv005896rm", "_nv005897rm", "_nv005787rm", "_nv037657rm", "_nv037672rm",
|
|
"_nv037647rm", "_nv037665rm", "_nv037659rm", "_nv040256rm") + CONTAINER
|
|
HOOKED = ("_nv052691rm", "_nv015312rm", "_nv015317rm", "_nv031426rm", "_nv040331rm",
|
|
"_nv052687rm", "_nv052701rm", "_nv052705rm", "_nv052695rm", "_nv030522rm",
|
|
"_nv005245rm", "_nv013840rm", "_nv047869rm", "_nv046745rm", "_nv046747rm")
|
|
# Entered and traced, then executed.
|
|
OBSERVED = ("_nv060222rm", "_nv060217rm", "_nv060221rm", "_nv060228rm", "_nv040256rm")
|
|
EXPECTED_SLOTS = {0x308: "_nv037659rm", 0x310: "_nv037657rm", 0x318: "_nv037672rm",
|
|
0x330: "_nv037647rm", 0x338: "_nv037665rm"}
|
|
PROPERTIES = (0x3f1, 0x3f2, 0x3f3, 0x1569)
|
|
# Descriptor classes whose GV100 stall provider reads column 7 of the
|
|
# engine's own record (reports/gv100-stall-provider-validation.json).
|
|
PROVIDER_CLASSES = (0xd334df, 0x793ceb, 0xe97b6c, 0x8f99e1, 0x28c408)
|
|
|
|
assert hashlib.sha256(ORIGINAL.read_bytes()).hexdigest() == DIGEST
|
|
with ORIGINAL.open("rb") as stream:
|
|
elf = ELFFile(stream)
|
|
symbols = list(elf.get_section_by_name(".symtab").iter_symbols())
|
|
by_name = {symbol.name: symbol for symbol in symbols}
|
|
text = bytearray(elf.get_section_by_name(".text").data())
|
|
rodata = elf.get_section_by_name(".rodata").data()
|
|
text_section, rodata_section = (elf.get_section_index(name) for name in (".text", ".rodata"))
|
|
starts = sorted((symbol["st_value"], symbol["st_size"], symbol.name) for symbol in symbols
|
|
if symbol["st_shndx"] == text_section and symbol["st_size"])
|
|
relocations = sorted((relocation["r_offset"], relocation["r_info_type"],
|
|
relocation["r_info_sym"], relocation["r_addend"])
|
|
for relocation in elf.get_section_by_name(".rela.text").iter_relocations())
|
|
offsets = [entry[0] for entry in relocations]
|
|
names = {symbol[0]: symbol[2] for symbol in starts}
|
|
executed, pending, fixed_bounds = [], list(ROOTS), []
|
|
while pending:
|
|
name = pending.pop()
|
|
if name in executed or name in HOOKED:
|
|
continue
|
|
executed.append(name)
|
|
start, size = by_name[name]["st_value"], by_name[name]["st_size"]
|
|
for offset, kind, index, addend in relocations[bisect.bisect_left(offsets, start):
|
|
bisect.bisect_left(offsets, start + size)]:
|
|
target = symbols[index]
|
|
if target.name == "__x86_indirect_thunk_rax":
|
|
address = INDIRECT
|
|
elif target.name == "__x86_indirect_thunk_r8":
|
|
address = INDIRECT_R8
|
|
elif target["st_shndx"] == rodata_section:
|
|
address = RODATA + target["st_value"]
|
|
if name == "_nv037647rm":
|
|
fixed_bounds.append(target["st_value"] + addend)
|
|
elif target["st_shndx"] == text_section:
|
|
address = TEXT + target["st_value"]
|
|
# Follow direct calls and tail calls only, not stored pointers.
|
|
if kind in (2, 4) and text[offset - 1] in (0xe8, 0xe9):
|
|
callee = names.get(target["st_value"] + addend + 4)
|
|
if callee and callee not in HOOKED:
|
|
pending.append(callee)
|
|
else:
|
|
# Class descriptors are only passed to the hooked class cast.
|
|
address = OTHER + target["st_value"]
|
|
value = address + addend
|
|
if kind in (2, 4):
|
|
value -= TEXT + offset
|
|
else:
|
|
assert kind == 11, kind
|
|
struct.pack_into("<i", text, offset, value)
|
|
assert tuple(fixed_bounds) == FIXED, fixed_bounds
|
|
fixed_rows = bytes(rodata[FIXED[0]:FIXED[1]])
|
|
# Variant 1: a two-bit mask, a nonstall vector with bit 5 and an all-ones row.
|
|
variant_rows = bytearray(fixed_rows)
|
|
struct.pack_into("<I", variant_rows, 2 * 16 + 4, 0x300000)
|
|
struct.pack_into("<I", variant_rows, 5 * 16 + 8, 0x25)
|
|
struct.pack_into("<II", variant_rows, 9 * 16 + 4, NONE, NONE)
|
|
# The interrupt-service class descriptor _nv003131rm, wherever it is mapped.
|
|
CLASS_INFO = {base + by_name["_nv003131rm"]["st_value"] for base in (RODATA, OTHER)}
|
|
container_ranges = [(TEXT + by_name[name]["st_value"],
|
|
TEXT + by_name[name]["st_value"] + by_name[name]["st_size"])
|
|
for name in CONTAINER]
|
|
|
|
cpu = Uc(UC_ARCH_X86, UC_MODE_64)
|
|
for address, data in ((TEXT, bytes(text)), (RODATA, bytes(rodata))):
|
|
cpu.mem_map(address, (len(data) + 4095) & ~4095)
|
|
cpu.mem_write(address, data)
|
|
for address, size in ((DATA, 0x40000), (STACK, 0x10000), (STOP, 0x1000), (HEAP, 0x100000)):
|
|
cpu.mem_map(address, size)
|
|
case, trace, container_diagnostics = {}, [], [0]
|
|
|
|
|
|
def leave(emu, value=0):
|
|
rsp = emu.reg_read(UC_X86_REG_RSP)
|
|
emu.reg_write(UC_X86_REG_RSP, rsp + 8)
|
|
emu.reg_write(UC_X86_REG_RAX, value)
|
|
emu.reg_write(UC_X86_REG_RIP, struct.unpack("<Q", emu.mem_read(rsp, 8))[0])
|
|
|
|
|
|
def u32(emu, address):
|
|
return struct.unpack("<I", emu.mem_read(address, 4))[0]
|
|
|
|
|
|
def allocate(size):
|
|
address = case["heap"]
|
|
case["heap"] += (size + 0x1f) & ~0xf
|
|
assert case["heap"] < HEAP + 0x100000
|
|
return address
|
|
|
|
|
|
def from_container(emu):
|
|
caller = struct.unpack("<Q", emu.mem_read(emu.reg_read(UC_X86_REG_RSP), 8))[0]
|
|
return any(start <= caller < end for start, end in container_ranges)
|
|
|
|
|
|
def row_words(emu, address):
|
|
return struct.unpack("<IIII", emu.mem_read(address, 16))
|
|
|
|
|
|
def leaf(name):
|
|
def run(emu, address, size, unused):
|
|
a, b, c, d, e = (emu.reg_read(register) for register in (
|
|
UC_X86_REG_RDI, UC_X86_REG_RSI, UC_X86_REG_RDX, UC_X86_REG_RCX, UC_X86_REG_R8))
|
|
low_a, low_b, low_c, low_d = (value & 0xffffffff for value in (a, b, c, d))
|
|
value = 0
|
|
if name == "_nv052691rm":
|
|
value = ALLOCATOR
|
|
elif name == "_nv015312rm":
|
|
assert a == ALLOCATOR
|
|
value = allocate(b)
|
|
elif name == "_nv015317rm":
|
|
assert a == ALLOCATOR
|
|
elif name == "_nv031426rm":
|
|
value = a
|
|
elif name == "_nv040331rm":
|
|
assert a == KFIFO
|
|
trace.append("cnt")
|
|
value = case["count"]
|
|
elif name == "_nv052687rm":
|
|
trace.append(f"al:{a:x}")
|
|
value = allocate(a) if case["alloc_ok"] else 0
|
|
case["scratch"] = value
|
|
elif name == "_nv052701rm":
|
|
assert a == case["scratch"] != 0
|
|
trace.append("fr")
|
|
elif name == "_nv052705rm":
|
|
emu.mem_write(a, bytes([b & 0xff]) * low_c)
|
|
value = a
|
|
elif name == "_nv052695rm":
|
|
emu.mem_write(a, bytes(emu.mem_read(c, low_d)))
|
|
value = a
|
|
elif name == "_nv030522rm":
|
|
assert a == GPU
|
|
trace.append(f"svc:{low_b:x}")
|
|
index = case["lookups"]
|
|
case["lookups"] += 1
|
|
value = OBJECTS + 0x10 * (index + 1) if case["engines"][index][4] else 0
|
|
elif name == "_nv005245rm":
|
|
index = (a - OBJECTS) // 0x10 - 1
|
|
assert index == case["lookups"] - 1 and b in CLASS_INFO, hex(b)
|
|
value = SERVICES + 0x10 * (index + 1) if case["engines"][index][4] == 2 else 0
|
|
elif name == "_nv013840rm":
|
|
assert (a, b) == (GPU, INTR)
|
|
handle = (c - SERVICES) // 0x10
|
|
nonstall = e == TEXT + by_name["_nv013839rm"]["st_value"]
|
|
assert nonstall or e == TEXT + by_name["_nv013838rm"]["st_value"]
|
|
engine = struct.unpack("<H", emu.mem_read(d, 2))[0]
|
|
trace.append(f"{'ns' if nonstall else 'st'}:{handle:x}:{engine:x}")
|
|
words = case["engines"][handle - 1]
|
|
status, stored, vector = words[5:8] if nonstall else words[8:11]
|
|
if stored:
|
|
emu.mem_write(d + (8 if nonstall else 12), struct.pack("<I", vector))
|
|
value = status
|
|
elif name == "_nv047869rm":
|
|
if low_a == MODULE_CONTAINER:
|
|
container_diagnostics[0] += 1
|
|
else:
|
|
shown = f"{low_c:x}" if low_b & 0x1000 else "-"
|
|
trace.append(f"p:{low_a:x}:{low_b >> 16:x}:{shown}")
|
|
elif name == "_nv046745rm":
|
|
if not from_container(emu):
|
|
trace.append(f"a:{low_a:x}")
|
|
elif name == "_nv046747rm":
|
|
trace.append(f"as:{low_b:x}:{low_a:x}")
|
|
else:
|
|
raise AssertionError(f"{name} must not be reached")
|
|
leave(emu, value)
|
|
return run
|
|
|
|
|
|
def observe(name):
|
|
def run(emu, address, size, unused):
|
|
a, b, c, d, e = (emu.reg_read(register) for register in (
|
|
UC_X86_REG_RDI, UC_X86_REG_RSI, UC_X86_REG_RDX, UC_X86_REG_RCX, UC_X86_REG_R8))
|
|
if name == "_nv060222rm":
|
|
assert (a, b) == (TABLE, ALLOCATOR)
|
|
trace.append(f"ti:{c & 0xffffffff:x}:{d & 0xffffffff:x}")
|
|
if case["init"]:
|
|
leave(emu, case["init"])
|
|
elif name == "_nv060217rm":
|
|
if a == SERVICE_VECTOR:
|
|
handle = (struct.unpack("<Q", emu.mem_read(b, 8))[0] - SERVICES) // 0x10
|
|
trace.append(f"reg:{handle:x}")
|
|
case["registers"] += 1
|
|
leave(emu, 0 if case["registers"] - 1 == case["register_fail"] else b)
|
|
return
|
|
assert a == TABLE
|
|
trace.append("ap:" + ":".join(f"{word:x}" for word in row_words(emu, b)))
|
|
case["appends"] += 1
|
|
if case["appends"] - 1 == case["append_fail"]:
|
|
leave(emu, 0)
|
|
elif name == "_nv060221rm":
|
|
assert a == TABLE
|
|
trace.append("td")
|
|
elif name == "_nv060228rm":
|
|
assert (a, b & 0xffffffff) == (TABLE, 0)
|
|
trace.append("trim")
|
|
else:
|
|
# The physical case runs the real KernelFifo lookup.
|
|
assert (a, b, c & 0xffffffff) == (GPU, KFIFO, 0x10)
|
|
trace.append(f"x:{d & 0xffffffff:x}:{e & 0xffffffff:x}")
|
|
return run
|
|
|
|
|
|
def thunk(register):
|
|
def run(emu, address, size, unused):
|
|
target = emu.reg_read(register)
|
|
a, b, c, d, e, f = (emu.reg_read(r) for r in (
|
|
UC_X86_REG_RDI, UC_X86_REG_RSI, UC_X86_REG_RDX, UC_X86_REG_RCX, UC_X86_REG_R8,
|
|
UC_X86_REG_R9))
|
|
low_c, low_d, low_e = (value & 0xffffffff for value in (c, d, e))
|
|
if target == SLOT_190:
|
|
assert (a, b, low_c, low_d, low_e) == (GPU, KERNEL, NONE, 1, 1)
|
|
trace.append("k190")
|
|
leave(emu, case["status_190"])
|
|
elif target == LOOKUP:
|
|
assert (a, b, low_c) == (GPU, KFIFO, 0x10) and low_e in (0, 8)
|
|
trace.append(f"x:{low_d:x}:{low_e:x}")
|
|
status, word = case["engines"][low_d][0:2] if low_e else case["engines"][low_d][2:4]
|
|
if not status:
|
|
emu.mem_write(f, struct.pack("<I", word))
|
|
leave(emu, status)
|
|
elif target in (ROUTE_2E0, ROUTE_2E8):
|
|
assert (a, b) == (GPU, INTR)
|
|
trace.append(f"{'r2e0' if target == ROUTE_2E0 else 'r2e8'}:{low_c:x}:{low_d:x}")
|
|
leave(emu, 0x77)
|
|
elif target == SUBCONTEXTS:
|
|
raise AssertionError("fault translation must not be reached")
|
|
else:
|
|
assert TEXT <= target < TEXT + len(text), hex(target)
|
|
emu.reg_write(UC_X86_REG_RIP, target)
|
|
return run
|
|
|
|
|
|
cpu.hook_add(UC_HOOK_CODE, thunk(UC_X86_REG_RAX), begin=INDIRECT, end=INDIRECT)
|
|
cpu.hook_add(UC_HOOK_CODE, thunk(UC_X86_REG_R8), begin=INDIRECT_R8, end=INDIRECT_R8)
|
|
for hooked in HOOKED:
|
|
entry = TEXT + by_name[hooked]["st_value"]
|
|
cpu.hook_add(UC_HOOK_CODE, leaf(hooked), begin=entry, end=entry)
|
|
for observed in OBSERVED:
|
|
entry = TEXT + by_name[observed]["st_value"]
|
|
cpu.hook_add(UC_HOOK_CODE, observe(observed), begin=entry, end=entry)
|
|
|
|
|
|
def call(name, *arguments):
|
|
for register, argument in zip((UC_X86_REG_RDI, UC_X86_REG_RSI, UC_X86_REG_RDX,
|
|
UC_X86_REG_RCX), arguments):
|
|
cpu.reg_write(register, argument)
|
|
rsp = STACK + 0xffc8
|
|
cpu.reg_write(UC_X86_REG_RSP, rsp)
|
|
cpu.reg_write(UC_X86_REG_RBP, STACK + 0x8000)
|
|
cpu.mem_write(rsp, struct.pack("<Q", STOP))
|
|
cpu.emu_start(TEXT + by_name[name]["st_value"], STOP, count=2000000)
|
|
assert cpu.reg_read(UC_X86_REG_RIP) == STOP, name
|
|
return cpu.reg_read(UC_X86_REG_RAX) & 0xffffffff
|
|
|
|
|
|
cpu.mem_write(CHIP + 0x10, struct.pack("<H", 0x23))
|
|
cpu.mem_write(RM + 0x10, struct.pack("<H", 2))
|
|
call("_nv005896rm", INTR, CHIP, RM)
|
|
call("_nv005897rm", INTR, CHIP, RM)
|
|
call("_nv005787rm", INTR, CHIP)
|
|
bound = {f"{slot:#x}": names[struct.unpack("<Q", cpu.mem_read(INTR + slot, 8))[0] - TEXT]
|
|
for slot in EXPECTED_SLOTS}
|
|
assert bound == {f"{slot:#x}": name for slot, name in EXPECTED_SLOTS.items()}, bound
|
|
properties = {f"{offset:#x}": cpu.mem_read(INTR + offset, 1)[0] for offset in PROPERTIES}
|
|
assert call("_nv037672rm", GPU, INTR) == 0
|
|
bound_object = bytes(cpu.mem_read(INTR, 0x2000))
|
|
physical = json.loads((ROOT / "reports/engine-cache-binary.json").read_text())["physical_gv100"]
|
|
physical_table = bytes(physical["table_bytes"])
|
|
assert len(physical_table) == 100 * physical["record_count"] == 1600
|
|
branches, rows, physical_rows = {}, [], []
|
|
MARKS = {
|
|
"p:e441f39:465:": "builder: table init failed",
|
|
"a:2e3": "builder: stall rows already built",
|
|
"a:2e6": "builder: nonstall rows already built",
|
|
"as:2ed:": "builder: slot 0x330 failed",
|
|
"a:2fb": "builder: fixed row with more than one mask bit",
|
|
"as:476:": "builder: slot 0x338 failed",
|
|
"a:492": "builder: nonstall vector with bit 5 reported",
|
|
"a:3b": "fixed rows: append failed",
|
|
"a:3a7": "engine rows: scratch allocation failed",
|
|
"k190": "engine rows: GPU+0x1ea0 slot 0x190 called",
|
|
"as:3b1:": "engine rows: GPU+0x1ea0 slot 0x190 failed",
|
|
"as:3bf:": "engine rows: engine index lookup failed",
|
|
"as:3c7:": "engine rows: row append failed",
|
|
"as:3cf:": "engine rows: descriptor lookup failed",
|
|
"a:3dc": "engine rows: service registration failed without freeing",
|
|
"as:3f3:": "engine rows: nonstall provider failed",
|
|
"as:408:": "engine rows: stall provider failed",
|
|
"ns:": "engine rows: nonstall provider called",
|
|
"st:": "engine rows: stall provider called",
|
|
"r2e0:": "engine rows: nonstall vector routed through slot 0x2e0",
|
|
"r2e8:": "engine rows: stall vector routed through slot 0x2e8",
|
|
"reg:": "engine rows: interrupt service registered",
|
|
"trim": "builder: success",
|
|
}
|
|
|
|
|
|
def run(kind, flags, state=(0, 0, 0, 0, 0, 1), variant=0, init=0, append_fail=NONE,
|
|
alloc_ok=1, status_190=0, register_fail=NONE, engines=(), table=b""):
|
|
"""State is the bytes at Intr+0x3f1, 3f2, 3f3, 3f8, 3f9 and 0x1569."""
|
|
trace.clear()
|
|
cpu.mem_write(DATA, bytes(0x10000))
|
|
cpu.mem_write(INTR, bound_object)
|
|
cpu.mem_write(INTR + 0x3f0, b"\x77" * (0x2000 - 0x3f0))
|
|
cpu.mem_write(TABLE, bytes(0x20))
|
|
cpu.mem_write(KFIFO, bytes(0x1000))
|
|
for offset, byte in zip((0x3f1, 0x3f2, 0x3f3, 0x3f8, 0x3f9, 0x1569), state):
|
|
cpu.mem_write(INTR + offset, bytes([byte]))
|
|
for base, offset, target in ((GPU, 0x22d0, KFIFO), (GPU, 0x1ea0, KERNEL),
|
|
(KERNEL, 0x190, SLOT_190), (INTR, 0x2e0, ROUTE_2E0),
|
|
(INTR, 0x2e8, ROUTE_2E8), (KFIFO, 0x170, SUBCONTEXTS),
|
|
(KFIFO, 0x1b8, LOOKUP)):
|
|
cpu.mem_write(base + offset, struct.pack("<Q", target))
|
|
if table:
|
|
cpu.mem_write(ENGINE_TABLE, table)
|
|
cpu.mem_write(KFIFO + 0x1b8, struct.pack("<Q", TEXT + by_name["_nv040256rm"]["st_value"]))
|
|
cpu.mem_write(KFIFO + 0x340, struct.pack("<I", len(table) // 100))
|
|
cpu.mem_write(KFIFO + 0x348, struct.pack("<Q", ENGINE_TABLE))
|
|
cpu.mem_write(RODATA + FIXED[0], bytes(variant_rows) if variant else fixed_rows)
|
|
case.update(heap=HEAP, init=init, append_fail=append_fail, appends=0, alloc_ok=alloc_ok,
|
|
status_190=status_190, register_fail=register_fail, registers=0,
|
|
engines=engines, count=len(engines), lookups=0, scratch=0)
|
|
status = call("_nv037657rm", GPU, INTR, TABLE, flags)
|
|
cpu.mem_write(RODATA + FIXED[0], fixed_rows)
|
|
pointer, length = struct.unpack("<Q", cpu.mem_read(TABLE, 8))[0], u32(cpu, TABLE + 0x18)
|
|
result = [word for index in range(length) for word in row_words(cpu, pointer + 16 * index)]
|
|
inputs = [flags, *state, variant, init, append_fail, alloc_ok, status_190, register_fail,
|
|
len(engines)] + [word for engine in engines for word in engine]
|
|
outputs = [status, cpu.mem_read(INTR + 0x3f8, 1)[0], cpu.mem_read(INTR + 0x3f9, 1)[0]]
|
|
joined = " ".join(trace)
|
|
rows.append(kind + " " + ";".join(" ".join(f"{value:x}" for value in group) for group in (
|
|
inputs, outputs, result, table)) + ";" + joined)
|
|
hit = [label for mark, label in MARKS.items()
|
|
if any(event.startswith(mark) for event in trace)]
|
|
if status == 0 and not engines:
|
|
hit.append("engine rows: no engines")
|
|
if status == 0 and any(engine[4] == 0 for engine in engines):
|
|
hit.append("engine rows: engine without an object")
|
|
if status == 0 and any(engine[4] == 1 for engine in engines):
|
|
hit.append("engine rows: object without the interrupt interface")
|
|
if status == 0 and state[0] and engines:
|
|
hit.append("engine rows: masks kept zero by Intr+0x3f1")
|
|
if status == 0 and not flags & 2:
|
|
hit.append("fixed rows: skipped without flag bit 1")
|
|
for label in hit:
|
|
branches[label] = branches.get(label, 0) + 1
|
|
return status, result
|
|
|
|
|
|
def engine(index, kind=2, nonstall=(0, 1, None), stall=(0, 1, None), lookup=(0, 0)):
|
|
"""One engine's fixture answers in oracle order."""
|
|
nonstall = (nonstall[0], nonstall[1], 0x40 + index if nonstall[2] is None else nonstall[2])
|
|
stall = (stall[0], stall[1], 3 + 2 * index if stall[2] is None else stall[2])
|
|
return (lookup[0], 0x10050 + index, lookup[1], 0xd334df00 + index, kind, *nonstall, *stall)
|
|
|
|
|
|
# T: the builder's own preconditions, with no engines.
|
|
for flags, byte_3f8, byte_3f9, init in itertools.product(
|
|
(0, 1, 2, 3, 0x12, 0xfffffffd), (0, 1, 0x77), (0, 1), (0, 0x51, 0x1f)):
|
|
status, result = run("T", flags, state=(0, 0, 0, byte_3f8, byte_3f9, 1), init=init)
|
|
if init:
|
|
assert status == init
|
|
elif (flags & 1 and byte_3f8) or (flags & 2 and byte_3f9):
|
|
assert status == 0x40 and not result
|
|
else:
|
|
assert status == 0 and len(result) == (60 if flags & 2 else 0)
|
|
for flags, fail in itertools.product((2, 3), (0, 7, 14)):
|
|
assert run("T", flags, append_fail=fail)[0] == 0x51
|
|
for flags, byte_3f2 in itertools.product((0, 1, 2, 3), (0, 1)):
|
|
run("R", flags, state=(0, byte_3f2, 0, 0, 0, 1), variant=1)
|
|
|
|
# D: per-engine rows.
|
|
SETS = (
|
|
(engine(0),),
|
|
(engine(0), engine(1, kind=0), engine(2, kind=1), engine(3)),
|
|
(engine(0, nonstall=(0, 0, 0), stall=(0, 0, 0)), engine(1, stall=(0, 1, NONE)),
|
|
engine(2, nonstall=(0, 1, 0x25), stall=(0, 1, 31)),
|
|
engine(3, nonstall=(0, 1, NONE), stall=(0, 1, 32)),
|
|
engine(4, nonstall=(0, 1, 0x1f), stall=(0, 1, 0x47))),
|
|
tuple(engine(index, kind=index % 3) for index in range(9)),
|
|
)
|
|
for flags, engines, state in itertools.product(
|
|
(0, 1, 2, 3), SETS, itertools.product((0, 1), (0, 1), (0, 1), (0,), (0,), (0, 1))):
|
|
status, result = run("D", flags, state=state, engines=engines)
|
|
assert status == 0 and len(result) == 4 * (len(engines) + (15 if flags & 2 else 0))
|
|
FOUR = SETS[1]
|
|
for flags in (0, 1, 2, 3):
|
|
base = 15 if flags & 2 else 0
|
|
assert run("D", flags, engines=FOUR, alloc_ok=0)[0] == 0x51
|
|
assert run("D", flags, engines=(), alloc_ok=0)[0] == 0x51
|
|
for status_190 in (0, 0x55):
|
|
assert run("D", flags, state=(0, 0, 1, 0, 0, 1), engines=FOUR,
|
|
status_190=status_190)[0] == status_190
|
|
for index in (0, 3):
|
|
failing = list(FOUR)
|
|
failing[index] = engine(index, lookup=(0x57, 0))
|
|
assert run("D", flags, engines=tuple(failing))[0] == 0x57
|
|
failing[index] = engine(index, lookup=(0, 0x1f))
|
|
assert run("D", flags, engines=tuple(failing))[0] == 0x1f
|
|
assert run("D", flags, engines=FOUR, append_fail=base + index)[0] == 0x51
|
|
failing[index] = engine(index, nonstall=(0x65, 1, None))
|
|
assert run("D", flags, engines=tuple(failing))[0] == (0x65 if flags & 2 else 0)
|
|
failing[index] = engine(index, nonstall=(0x66, 0, 0), stall=(0x40, 0, 0))
|
|
assert run("D", flags, engines=tuple(failing))[0] == (
|
|
0x66 if flags & 2 else 0x40 if flags & 1 else 0)
|
|
failing[index] = engine(index, stall=(0x56, 1, None))
|
|
assert run("D", flags, engines=tuple(failing))[0] == (0x56 if flags & 1 else 0)
|
|
for fail in (0, 1):
|
|
assert run("D", flags, engines=FOUR, register_fail=fail)[0] == 0x51
|
|
# The builder's own precondition failures never reach the engine rows.
|
|
assert run("D", flags, state=(0, 0, 0, 1, 1, 1), engines=FOUR)[0] == (0x40 if flags & 3 else 0)
|
|
|
|
# V: the original constructor's engine records of a physical V100. The
|
|
# stall provider answers with column 7 of the engine's own record, the rule
|
|
# validated for these five classes; the nonstall provider stores nothing.
|
|
records = [struct.unpack("<21I", physical_table[index * 100:index * 100 + 84])
|
|
for index in range(16)]
|
|
assert records[15][0] == 0x95a6f500
|
|
assert all(record[0] >> 8 in PROVIDER_CLASSES for record in records[:15])
|
|
physical_engines = tuple((0, 0, 0, 0, 2, 0, 0, 0, 0, 1, record[7]) for record in records[:15])
|
|
for flags in (1, 2, 3):
|
|
status, result = run("V", flags, engines=physical_engines, table=physical_table)
|
|
assert status == 0
|
|
if flags == 3:
|
|
physical_rows = [{"index": index, "engine": result[4 * index] & 0xffff,
|
|
"pmc_mask": f"{result[4 * index + 1]:#010x}",
|
|
"nonstall_vector": f"{result[4 * index + 2]:#x}",
|
|
"stall_vector": f"{result[4 * index + 3]:#x}",
|
|
"source": "fixed" if index < 15 else
|
|
bytes(physical_table[(index - 15) * 100 + 84:(index - 14) * 100])
|
|
.split(b"\0")[0].decode()}
|
|
for index in range(len(result) // 4)]
|
|
assert all(result[4 * (15 + index)] == records[index][8] for index in range(15))
|
|
|
|
missing = sorted(set(MARKS.values()) - set(branches))
|
|
assert not missing, missing
|
|
out = ROOT / "target/gpu-stage"
|
|
out.mkdir(parents=True, exist_ok=True)
|
|
oracle = "\n".join(rows) + "\n"
|
|
(out / "original-intr-table.txt").write_text(oracle)
|
|
kinds = {"T": "builder preconditions, original fixed rows",
|
|
"R": "fixed rows replaced in the emulated .rodata",
|
|
"D": "modelled engines", "V": "physical V100 engine records"}
|
|
report = {"original_sha256": DIGEST, "chip_hal": "0x23", "rm_hal": 2,
|
|
"executed": sorted(executed),
|
|
"fixture_supplied": list(HOOKED) + [
|
|
"GPU+0x1ea0 slot 0x190", "KernelFifo+0x1b8 in the modelled cases",
|
|
"Intr+0x2e0", "Intr+0x2e8", "memory copy and fill are performed as such"],
|
|
"observed_then_executed": list(OBSERVED),
|
|
"bindings": bound, "hal_properties": properties,
|
|
"fixed_table_rodata": [hex(offset) for offset in FIXED],
|
|
"fixed_rows": [list(row) for row in struct.iter_unpack("<HxxIII", fixed_rows)],
|
|
"cases": len(rows),
|
|
"cases_per_kind": {f"{kind}: {label}": sum(1 for row in rows if row[0] == kind)
|
|
for kind, label in kinds.items()},
|
|
"branches": dict(sorted(branches.items())),
|
|
"container_diagnostics_not_compared": container_diagnostics[0],
|
|
"physical_gv100": {
|
|
"source": "reports/engine-cache-binary.json physical_gv100.table_bytes",
|
|
"flags": 3, "engine_count_supplied": 15,
|
|
"engine_lookup": "original _nv040256rm over the 16 records",
|
|
"stall_provider": "fixture: column 7 of the engine's own record",
|
|
"nonstall_provider": "fixture: stores nothing, so the column stays 0xffffffff",
|
|
"rows": physical_rows},
|
|
"oracle": "target/gpu-stage/original-intr-table.txt",
|
|
"oracle_sha256": hashlib.sha256(oracle.encode()).hexdigest(),
|
|
"scope": "Original GV100 host interrupt table builder with its fixed-row and "
|
|
"per-engine-row slot functions and the vector helpers of the table. "
|
|
"Allocation, the engine count, engine objects, vector providers, routing "
|
|
"slots and diagnostics are fixture-supplied; no hardware executed."}
|
|
(ROOT / "reports/gpu-intr-table-original.json").write_text(json.dumps(report, indent=2) + "\n")
|
|
print(f"{len(rows)} original Intr table cases; executed {len(executed)} functions")
|