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
187 lines
9.5 KiB
Python
187 lines
9.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Run the original GV100 Graphics StateUnload (_nv033671rm -> _nv033670rm) and write an
|
|
oracle.
|
|
|
|
Executed original code on the objects of check_gpu_graphics_load_binary.py after the
|
|
original StateLoad (with the original ZBC service of check_gpu_graphics_zbc_binary.py).
|
|
The physical transcript ends before any unload, so this is instruction-emulation evidence
|
|
only. The two Falcon functions (_nv027643rm on the Graphics+15e8 object and the function
|
|
at +88 of the Graphics+15f0 object) and the context unload _nv033702rm are fixtures in the
|
|
rows; one row records what the original Falcon functions do on the emulated objects.
|
|
"""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
ARGUMENTS = sys.argv[1:]
|
|
sys.argv = sys.argv[:1]
|
|
import check_gpu_graphics_zbc_binary as z # noqa: E402
|
|
|
|
h = z.h
|
|
ROOT = h.ROOT
|
|
rows = []
|
|
LOADED = {}
|
|
|
|
|
|
def falcon(name):
|
|
def handler(a):
|
|
status = h.pop(name, 0)
|
|
h.emit(f"{name}:{a[2] & 0xffffffff:x}:{status:x}")
|
|
return status
|
|
return handler
|
|
|
|
|
|
def loaded(case):
|
|
"""The objects after the original StateLoad for this geometry."""
|
|
key = (tuple(sorted((offset, tuple(values)) for offset, values in case["reads"].items()
|
|
if offset in h.V100_GEOMETRY and offset != 0x200)),
|
|
tuple(sorted(case["fuse"].items())))
|
|
if key not in LOADED:
|
|
load = dict(case, check=[], busy=[], busy_status=[], gpu={0x911: 1}, gr={}, grmgr={},
|
|
reads={offset: list(values) for offset, values in case["reads"].items()
|
|
if offset in h.V100_GEOMETRY})
|
|
load["reads"][0x12006c] = [0x10]
|
|
z.prepare(load)
|
|
h.state["real"] = False
|
|
assert h.call("_nv033665rm", h.GPU, h.GR, 0) & 0xffffffff == 0
|
|
assert h.d(h.GR + 0x1620) == 1 and h.b(h.GR + 0x1591) == 1
|
|
LOADED[key] = (bytes(h.cpu.mem_read(h.OBJ, h.OBJ_SIZE)),
|
|
bytes(h.cpu.mem_read(h.HEAP, h.state["heap"] - h.HEAP)), h.state["heap"],
|
|
{name: bytes(h.cpu.mem_read(h.BASES[name], len(h.sections[name])))
|
|
for name in (".data", ".bss")})
|
|
objects, heap, top, data = LOADED[key]
|
|
h.cpu.mem_write(h.OBJ, objects)
|
|
h.cpu.mem_write(h.HEAP, heap)
|
|
for name, content in data.items():
|
|
h.cpu.mem_write(h.BASES[name], content)
|
|
h.state.update(heap=top, events=[], continuations=[], case=case, keys=[], phase="unload",
|
|
checks=0, real=case.get("real", False))
|
|
case["reads"] = {offset: values for offset, values in case["reads"].items()
|
|
if offset not in h.V100_GEOMETRY or offset == 0x200}
|
|
|
|
|
|
def unload(kind="U", **changes):
|
|
case = h.default_load()
|
|
case.update(flags=0, loaded=1, f643=[], g88=[])
|
|
case.update(changes)
|
|
case["reads"] = {**h.default_load()["reads"], 0x12006c: [0x10], **changes.get("reads", {})}
|
|
case["gpu"] = {**h.default_load()["gpu"], **changes.get("gpu", {})}
|
|
loaded(case)
|
|
for offset, value in case["gpu"].items():
|
|
h.wb(h.GPU + offset, value)
|
|
for offset, value in case["gr"].items():
|
|
h.wb(h.GR + offset, value)
|
|
h.wd(h.GR + 0x1620, case["loaded"])
|
|
h.wd(h.q(h.GRMGR + 0x2b0) + 0x25c, case["done_mask"])
|
|
block = h.grinfo()
|
|
records = h.q(block + 0x570)
|
|
count = h.call(h.q(h.GR + 0xc78), h.GPU, h.GR) & 0xffffffff
|
|
fields = [f"{case['flags']:x}",
|
|
" ".join(f"{h.b(h.GPU + offset):x}" for offset in (0x91d,) + h.GPU_BYTES[5:]),
|
|
"%x %x %x %x %x %x %x" % (h.b(h.GR + 0x160c), h.b(h.GR + 0x50), h.d(h.GR + 0x1620),
|
|
h.d(h.GR + 0x188c), h.d(h.q(h.GRMGR + 0x2b0) + 0x25c),
|
|
h.b(h.GR + 0x45f4), h.b(h.GR + 0xf8)),
|
|
" ".join(f"{h.d(records + 0x1f0 * gpc):x}" for gpc in range(count))]
|
|
h.state["events"].clear()
|
|
status = h.call("_nv033671rm", h.GPU, h.GR, case["flags"]) & 0xffffffff
|
|
assert not h.state["continuations"]
|
|
events = z.kept(h.state["events"])
|
|
rows.append(f"{kind};" + ";".join(fields) + f";{status:x};{h.d(h.GR + 0x1620):x} "
|
|
f"{h.b(h.GR + 0x1591):x};" + " ".join(events))
|
|
return status, events
|
|
|
|
|
|
def main():
|
|
h.hook("os_delay_us", lambda a: h.emit(f"du:{a[0] & 0xffffffff:x}") or 0)
|
|
# R: the Falcon functions as the original runs them on the emulated objects. The Falcon
|
|
# objects are only constructed here (no Falcon PreInit or Init), so this row documents the
|
|
# shape of the calls and is not compared with Rust.
|
|
# Hooks must exist before the code runs once (translated blocks are cached), so the three
|
|
# fixtures are installed first and pass through to the original while a case is "real".
|
|
case = h.default_load()
|
|
z.prepare(case)
|
|
gpccs_88 = h.function_at(h.q(h.q(h.GR + 0x15f0) + 0x88))
|
|
h.fixture("_nv027643rm", falcon("f643"))
|
|
h.fixture(gpccs_88, falcon("g88"))
|
|
h.fixture("_nv033702rm", lambda a: h.emit("cu") or 0)
|
|
status, original = unload("R", real=True)
|
|
assert status == 0
|
|
falcon_tail = original[original.index("w:409c24:0") + 1:]
|
|
random = h.Random(0x33670)
|
|
for flags in (0, 1, 2, 3, 0x20, 0xffffffff):
|
|
for is_loaded in (1, 0):
|
|
for gpu_91d in (0, 1):
|
|
for done_mask in (0, 1):
|
|
unload(flags=flags, loaded=is_loaded, gpu={0x91d: gpu_91d},
|
|
done_mask=done_mask)
|
|
for is_loaded in (1, 0, 0x100):
|
|
for f643, g88 in (([0x3d], []), ([], [0x3d]), ([0x3d, 0x40], [0x56, 0x57]), ([0, 0x65], [])):
|
|
unload(loaded=is_loaded, gpu={0x91d: 1}, f643=list(f643), g88=list(g88))
|
|
for three_d in (1, 0):
|
|
for count in (0, 1, 0x10, 0x1f, 0x3f, 0xffffffe2):
|
|
unload(gr={0x160c: three_d}, reads={0x12006c: [count]})
|
|
# The current-context word with unload flag 1.
|
|
for word in (0, 0x80000000, 0x7fffffff, 0xb07fdb90, 0xffffffff):
|
|
for flags in (0, 1, 3):
|
|
unload(flags=flags, reads={0x409b00: [0, word]})
|
|
# Wait for idle before the body: it runs whatever the wait returned.
|
|
for current in ([0], [0x80000000, 0], [0x80000000] * 3 + [0x7fffffff], [0xffffffff] * 40):
|
|
for pending, busy in (([0], []), ([1, 0], []), ([0], [1, 0]), ([1], [1])):
|
|
for check in ([], [0, 0x65], [0x65]):
|
|
unload(reads={0x409b00: list(current), 0x40060c: list(pending)},
|
|
busy=list(busy), check=list(check) + [0x65] * 40)
|
|
for gpu in ({0x917: 1}, {0x918: 1}, {0x919: 1}, {0x926: 1}, {0x915: 0}):
|
|
unload(reads={0x409b00: [0x80000000], 0x40060c: [1]}, gpu={0x911: 1, **gpu},
|
|
check=[0x65] * 40)
|
|
unload(gr={0x50: 1}, reads={0x409b00: [0x80000000], 0x40060c: [1]})
|
|
# Geometry.
|
|
for words, fuse in (((0x40007,) * 6, {}), ((0x40006,) * 6, {0xc38 + 4 * gpc: 1 for gpc in range(6)}),
|
|
((0x40007, 0x40005, 0x40007, 0x40007, 0x40004, 0x40007),
|
|
{0xc3c: 3, 0xc48: 7}), ((0x7,) * 6, {})):
|
|
for three_d in (1, 0):
|
|
unload(gr={0x160c: three_d}, **h.geometry(words, fuse))
|
|
for number in range(24):
|
|
unload(default_read=h.hashed(random.word()), flags=number & 2,
|
|
gr={0x160c: number & 1}, check=[0x65] * 40,
|
|
reads={0x12006c: [random.pick((0, 3, 0x10, 0x1f))], 0x409b00: [0]})
|
|
|
|
out = ROOT / "target/gpu-stage"
|
|
oracle = "\n".join(rows) + "\n"
|
|
(out / "original-graphics-unload.txt").write_text(oracle)
|
|
kinds = {}
|
|
for row in rows:
|
|
kinds[row.split(";", 1)[0]] = kinds.get(row.split(";", 1)[0], 0) + 1
|
|
failed = sum(1 for row in rows if row[0] == "U" and row.split(";")[5] != "0")
|
|
report = {
|
|
"original_sha256": h.DIGEST, "chip_hal": "0x23", "rm_hal": 2,
|
|
"entry": "_nv033671rm(gpu, graphics, flags) -> _nv033670rm after the original "
|
|
"_nv033665rm on the objects of check_gpu_graphics_zbc_binary.py",
|
|
"gpccs_unload_function": gpccs_88,
|
|
"original_falcon_calls_on_the_emulated_objects": {
|
|
"events_after_0x409c24": falcon_tail,
|
|
"note": "FECS: _nv027643rm -> +90 of the Falcon (_nv028773rm -> _nv028772rm -> "
|
|
"_nv028467rm(.., 0)): read 0x409048, 1 us delay, 0x409014 = 0xffffffff. The "
|
|
"second pair (read 0x48, write 0x14) is the same sequence on the GPCCS "
|
|
"object, whose register base is 0 here because no Falcon PreInit or Init ran; "
|
|
"these events document the call shape only."},
|
|
"fixture_supplied": ["register values", "time", "_nv027871rm",
|
|
"_nv027643rm and the GPCCS +88 function (rows U)",
|
|
"_nv033702rm (rows U)"],
|
|
"cases": len(rows), "cases_by_kind": kinds, "cases_with_nonzero_status": failed,
|
|
"kinds": {"R": "the unload with the original Falcon functions (not compared)",
|
|
"U": "_nv033671rm with fixture Falcon functions"},
|
|
"oracle": "target/gpu-stage/original-graphics-unload.txt",
|
|
"oracle_sha256": hashlib.sha256(oracle.encode()).hexdigest(),
|
|
"scope": "Original GV100 Graphics StateUnload for instance 0 without MIG, Graphics+45f4 "
|
|
"and Graphics+f8 clear. Instruction emulation only: the physical transcript "
|
|
"contains no unload. No hardware executed."}
|
|
(ROOT / "reports/gpu-graphics-unload-original.json").write_text(json.dumps(report, indent=1) + "\n")
|
|
print(f"{len(rows)} original Graphics unload rows {kinds}; {failed} with a non-zero status")
|
|
print(report["oracle_sha256"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|