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
266 lines
14 KiB
Python
266 lines
14 KiB
Python
#!/usr/bin/env python3
|
|
"""Run the original GV100 PMU class constructor, ConstructEngine, InitLocked and Load.
|
|
|
|
The environment is the one tools/check_gpu_acr_load_binary.py builds, executed
|
|
unchanged up to and including its traced V100 Load case, so the Falcons, the
|
|
light-secure manager and OBJACR are in the state the original leaves after the
|
|
ACR load. tools/pmu_original_environment.py adds what the PMU class needs.
|
|
|
|
Executed original code (chip HAL 0x23, RM HAL 2), all with the object's real
|
|
relocations and the function tables its own binders fill:
|
|
|
|
PMU class property initialiser _nv005852rm(object, RM owner, chip owner);
|
|
class constructor _nv051986rm with the sub-object creators
|
|
_nv006737rm (+a00), _nv006057rm/_nv006726rm (+b08), _nv006735rm
|
|
(+b10), _nv006738rm (+c20), _nv006746rm (+f68), _nv006743rm
|
|
(+df8), _nv006749rm (+e88); ConstructEngine _nv051982rm (its
|
|
+308 part was already executed by the image harness);
|
|
InitLocked _nv051858rm with _nv052645rm/_nv052643rm (address
|
|
space), _nv052270rm and _nv052601rm (instance block), the
|
|
surface producer _nv052583rm -> _nv052522rm -> _nv052518rm ->
|
|
_nv052601rm and its 1 MiB fills; Load _nv051860rm with the
|
|
reset _nv052192rm (+a58) and _nv052253rm, _nv052194rm,
|
|
_nv052252rm, _nv052248rm, _nv052223rm, _nv052197rm, _nv052213rm,
|
|
_nv052188rm, the gating functions _nv030977rm and _nv030976rm,
|
|
the surface mapping _nv052584rm -> _nv052610rm -> _nv052346rm ->
|
|
_nv052341rm, the instance block function _nv052399rm ->
|
|
_nv052304rm with the bind _nv052272rm, _nv052277rm, _nv052288rm,
|
|
_nv052284rm, _nv052215rm, the transfer index functions
|
|
_nv051924rm and _nv051927rm, the boot _nv051841rm with the
|
|
argument builder _nv051947rm, the writer _nv051929rm with
|
|
_nv052607rm and the DMEM port, _nv052204rm, _nv052256rm.
|
|
|
|
Not exercised: a resume (GPU+69e4 = 4), which reorders the Load body, and a
|
|
DMEM larger than 64 KiB.
|
|
|
|
Fixture-supplied (recorded as events): everything the ACR harness supplies,
|
|
and: the address-space mapping _nv026096rm (which also performs the pin of the
|
|
PMU address space: on the first mapping of the surface it continues into the
|
|
original _nv052399rm(gpu, pmu, space, 1), the function the address space calls
|
|
through _nv013511rm); KernelBus+4a8 and _nv039553rm; the GPU child iteration
|
|
_nv030645rm (no PMU clients); _nv053004rm; the clock manager function at +198
|
|
(clock domain 0x13); OBJFUSE+150; the GCX object's child function; OBJSEQ; the
|
|
interrupt service pass _nv037739rm; the monotonic clock. No hardware.
|
|
|
|
Deviations from the original order, all stated in the report: the class
|
|
constructor and ConstructEngine run after the image harness configured the
|
|
Falcon (two Falcon fields are restored around the constructor), and InitLocked
|
|
runs after the light-secure manager's Load, so the byte Falcon+3a4 that Load
|
|
stores is restored after InitLocked.
|
|
"""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
HERE = Path(__file__).resolve()
|
|
exec(compile((HERE.with_name("pmu_original_environment.py")).read_text(), # noqa: S102
|
|
str(HERE.with_name("pmu_original_environment.py")), "exec"), globals())
|
|
|
|
V100_PMU = dict(instance=0x7fdf7e000, surface=0x7fdb98000, buffer=0x7fdf7d000,
|
|
surface_va=0x4000000, buffer_va=0x5000000)
|
|
LS_SETTINGS = dict(g90c=0, g916=0, g6d59=0, g69e4=0, freq=540000, clk=0, fuse=0x56, fusev=0,
|
|
fs13=0, fs7=0, fail="", vbios=0, lp=0)
|
|
rows, counts = [], {}
|
|
|
|
# ------------------------------------------------------------ construction
|
|
before = bytes(cpu.mem_read(PMU, 0x1000))
|
|
construct_pmu()
|
|
state["instance_space"] = 2
|
|
assert construct_engine() == 0
|
|
assert word(PMU + 0xc20 + 0x84) == 0 and pointer(F_PMU + 0x5e0) == sym("_nv000008rm")
|
|
CONSTRUCTED = {"PMU+0x58c": byte(PMU + 0x58c), "PMU+0x56c": byte(PMU + 0x56c),
|
|
"PMU+0x428": byte(PMU + 0x428), "PMU+0x429": byte(PMU + 0x429),
|
|
"PMU+0x42b": byte(PMU + 0x42b), "PMU+0x42c": byte(PMU + 0x42c),
|
|
"PMU+0xaf8": byte(PMU + 0xaf8), "Falcon+0x650": word(F_PMU + 0x650),
|
|
"Falcon+0x3a7": byte(F_PMU + 0x3a7), "Falcon+0x5e8": word(F_PMU + 0x5e8),
|
|
"*Falcon+0x5e0": word(pointer(F_PMU + 0x5e0))}
|
|
assert CONSTRUCTED["PMU+0x58c"] == 1 and CONSTRUCTED["Falcon+0x650"] == 1, CONSTRUCTED
|
|
|
|
# ------------------------------------------------------------- InitLocked
|
|
b(VBIOS + 0x2d6, 1)
|
|
del trace[:]
|
|
state.update(addresses=[V100_PMU["instance"], V100_PMU["surface"], V100_PMU["buffer"]],
|
|
virtual=[V100_PMU["surface_va"], V100_PMU["buffer_va"]], counts={}, fail={},
|
|
reads={}, checks=[])
|
|
assert call("_nv051858rm", GPU, PMUX) == 0
|
|
INIT_EVENTS = [token for token in trace if not token.startswith(("m:", "u:", "df", "sd"))]
|
|
FILLS = [token for token in trace if token.startswith("m:")]
|
|
assert INIT_EVENTS[:6] == [
|
|
"vc:90f1:1:0:1fffffff:4000810:0", "dc:1000:0:1:2:1:4:0", "da:e:1000:0:7fdf7e000",
|
|
"z:7fdf7e000:1000:0", "dc:207a00:0:0:2:1:4:0", "da:e:207a00:0:7fdb98000"], INIT_EVENTS
|
|
b(F_PMU + 0x3a4, 0) # stored by the light-secure manager's Load, which follows InitLocked
|
|
b(GPU + 0x915, 1)
|
|
INITIALISED = pmu_snapshot()
|
|
SURFACE_DESCRIPTOR = next(handle for handle, entry in descriptors.items()
|
|
if entry["size"] == 0x207a00 and entry["parent"] is None)
|
|
|
|
|
|
def load_case(kind, reads, checks=(), **changes):
|
|
settings = dict(LS_SETTINGS, **changes)
|
|
pmu_restore(INITIALISED)
|
|
del trace[:], diag[:], asserts[:]
|
|
fail = {}
|
|
for item in filter(None, settings["fail"].split(",")):
|
|
name, number, status = item.split(":")
|
|
fail[name] = (int(number), int(status, 16))
|
|
state.update(reads={offset: list(values) for offset, values in reads.items()},
|
|
checks=list(checks), counts={}, fail=fail, v238=settings["vbios"],
|
|
virtual=[V100_PMU["surface_va"], V100_PMU["buffer_va"]], addresses=[])
|
|
pmu_vm["first"] = True
|
|
knobs.update(freq=settings["freq"], clk_status=settings["clk"],
|
|
fuse_status=settings["fuse"], fuse_value=settings["fusev"],
|
|
fs13=settings["fs13"], fs7=settings["fs7"])
|
|
for offset, name in ((0x90c, "g90c"), (0x916, "g916"), (0x6d59, "g6d59")):
|
|
b(GPU + offset, settings[name])
|
|
d(GPU + 0x69e4, settings["g69e4"])
|
|
q(LPWR + 0x11d8, LPWR_GATING if settings["lp"] else 0)
|
|
try:
|
|
status = call("_nv051860rm", GPU, PMUX)
|
|
except Exception:
|
|
print("FAILED", kind, changes, reads, checks, trace[-8:], file=sys.stderr)
|
|
raise
|
|
left = len(state["checks"])
|
|
counts[kind] = counts.get(kind, 0) + 1
|
|
events = list(trace)
|
|
arguments = bytes(cpu.mem_read(PMU + 0xd30, 0x30)).hex()
|
|
rows.append("|".join((
|
|
kind, " ".join(f"{key}={value}" if isinstance(value, str) else f"{key}={value:x}"
|
|
for key, value in settings.items()),
|
|
" ".join(f"{offset:x}=" + ",".join(f"{value:x}" for value in values)
|
|
for offset, values in reads.items()),
|
|
",".join(f"{value:x}" for value in list(checks)[:len(checks) - left]),
|
|
f"{status:x}", arguments, f"{byte(pointer(PMU + 0xb08) - 8 + 0x80):x}",
|
|
" ".join(events))))
|
|
return status, events
|
|
|
|
|
|
# ------------------------------------------------------------ the traced V100
|
|
FIRST, LAST = 147279, 147456
|
|
CLOCK_LINES = (147426, 147431) # the clock manager's own register reads
|
|
traced = transcript_reads(FIRST, LAST)
|
|
status, events = load_case("T", traced, lp=1)
|
|
assert status == 0
|
|
registers = [token for token in events if token[:2] in ("r:", "w:")]
|
|
expected = [token for line, token in transcript_numbered(FIRST, LAST)
|
|
if not CLOCK_LINES[0] <= line <= CLOCK_LINES[1]]
|
|
assert registers == expected, next(
|
|
(index, a, e) for index, (a, e) in enumerate(zip(registers + [None], expected)) if a != e)
|
|
ARGUMENTS_TRACED = bytes(cpu.mem_read(PMU + 0xd30, 0x30))
|
|
assert ARGUMENTS_TRACED.hex() == (
|
|
"00bf2f20" + "00" * 24 + "00000004" + "00000000" + "007a2020" + "00000000" + "00000000")
|
|
PHYSICAL = {"lines": [FIRST, LAST], "register_accesses_compared": len(registers),
|
|
"not_compared": {
|
|
"147278": "read of 0x1598 inside the VBIOS function at +238 (fixture)",
|
|
"147426-147431": "clock manager reads behind ClockManager+198 (fixture)",
|
|
"service registers": "0x100c80, 0x100cb8, 0x100cec, 0x100cbc, 0x70000, "
|
|
"0x1373a0 belong to memory services"},
|
|
"sha256_of_compared_lines": hashlib.sha256("\n".join(registers).encode()).hexdigest()}
|
|
TRACED_EXECUTED = sorted(set(calls))
|
|
if "--traced" in sys.argv:
|
|
print("traced case only:", len(registers), "register accesses equal the transcript")
|
|
sys.exit(0)
|
|
|
|
# ------------------------------------------------------------------ variations
|
|
BASE = {0x10a100: [0x50], 0x10a3c0: [0], 0x1221fc: [0], 0x10a3c4: [0x77], 0x10a040: [0],
|
|
0x10a10c: [1], 0x10a04c: [0], 0: [0x140000a1], 0x10a048: [4, 5], 0x10a090: [0x40, 0x10040],
|
|
0x10ac0c: [0], 0x10a0dc: [0xed03d, 0xe003f], 0x10a108: [0x400e0100], 0x10a268: [0x100],
|
|
0x10a130: [0], 0x10a1c0: [0]}
|
|
|
|
|
|
def vary(checks=(), **reads_and_settings):
|
|
reads = dict(BASE)
|
|
settings = {}
|
|
for key, value in reads_and_settings.items():
|
|
if key.startswith("r"):
|
|
reads[int(key[1:], 16)] = value
|
|
else:
|
|
settings[key] = value
|
|
return load_case("V", reads, checks, **settings)
|
|
|
|
|
|
vary()
|
|
# Engine reset register and its status.
|
|
for value in ([1], [0xfffffffe], [0xffffffff]):
|
|
vary(r10a3c0=value)
|
|
for value in ([0x67], [0], [0x10], [0xffffffef]):
|
|
vary(r10a3c4=value)
|
|
# Memory scrub wait (DMACTL), at once, late, timeout.
|
|
for value, checks in (([0], ()), ([6, 0], (0,)), ([7, 7, 1], (0, 0)), ([6], (0, 0x65) + (0x65,) * 15),
|
|
([2, 2, 0], (0x56,)), ([6], (0x65,) * 16)):
|
|
vary(checks=checks, r10a10c=value)
|
|
for value in ([5], [0xffffffff]):
|
|
vary(r10a040=value)
|
|
# Idle wait.
|
|
for value, checks in (([1, 0], (0,)), ([2, 2, 0], (0, 0)), ([0xfffe], (0x65,) * 16),
|
|
([0x10000], ()), ([1], (0, 0x65) + (0x65,) * 15)):
|
|
vary(checks=checks, r10a04c=value)
|
|
# Bind: interface and debug words, the state machine word, the two branches.
|
|
for value in ([0, 1], [0xfffffffe, 0xffffffff], [5, 5]):
|
|
vary(r10a048=value)
|
|
for value in ([0, 0x10000], [0xfffeffff, 0xffffffff]):
|
|
vary(r10a090=value)
|
|
for value in ([1], [0xffffffff]):
|
|
vary(r10ac0c=value)
|
|
for value, checks in (([0x2000, 0x2], (0,)), ([0x5000, 0x5002], ()), ([0, 0, 2], (0, 0)),
|
|
([0x1000], (0x65,) * 16), ([0x2002], ()), ([0x5000, 0x2000, 0x3002], (0, 0)),
|
|
([0], (0x56,) * 16)):
|
|
vary(checks=checks, r10a0dc=value)
|
|
# Arguments: frequency source, flags, DMEM size, boundary.
|
|
for changes in (dict(freq=1), dict(freq=0), dict(freq=0xffffffff), dict(clk=0x40),
|
|
dict(fuse=0, fusev=1), dict(fuse=0, fusev=0), dict(fuse=0x40, fusev=1),
|
|
dict(g90c=1), dict(g916=1), dict(g6d59=1), dict(lp=1), dict(lp=1, fs13=1, fs7=1),
|
|
dict(g90c=1, g916=1, g6d59=1, fuse=0, fusev=1)):
|
|
vary(**changes)
|
|
for value in ([0x400e0000], [0x40000200], [0x200]):
|
|
vary(r10a108=value)
|
|
for value in ([0], [0xff], [0x80], [0x1000]):
|
|
vary(r10a268=value)
|
|
for value in ([0x10], [0], [0xffffffff]):
|
|
vary(r10a100=value)
|
|
for value in ([0x40], [0xfffffffd]):
|
|
vary(r10a130=value)
|
|
# Gating feature states.
|
|
for changes in (dict(fs13=1), dict(fs7=1), dict(fs13=1, fs7=1)):
|
|
vary(**changes)
|
|
# Services that fail.
|
|
for fail in ("pagesize:1:1f", "vmap:1:1a", "instance:1:40", "m:1:1", "pagesize:2:1f",
|
|
"vmap:2:1a"):
|
|
vary(fail=fail)
|
|
# PMU+2f8 with a halted PMU: the scratch word (field 15:12) changes nothing.
|
|
# (A PMU that is not halted with field 1 reaches PMU+2f0; that branch is
|
|
# executed in tools/check_gpu_acr_load_binary.py, rows P.)
|
|
for vbios in (0x1000, 0x22081045, 0x22082045, 0xffffffff):
|
|
for value in ([0x50], [0x10]):
|
|
vary(vbios=vbios, r10a100=value)
|
|
for vbios in (0x2000, 0x22082045, 0xffff0fff):
|
|
vary(vbios=vbios, r10a100=[0x20])
|
|
|
|
out = ROOT / "target/gpu-stage"
|
|
out.mkdir(parents=True, exist_ok=True)
|
|
oracle = "\n".join(rows) + "\n"
|
|
(out / "original-pmu-ls-start.txt").write_text(oracle)
|
|
report = {
|
|
"original_sha256": DIGEST, "chip_hal": "0x23", "rm_hal": 2,
|
|
"environment": "tools/check_gpu_acr_load_binary.py up to and including its traced Load, "
|
|
"then tools/pmu_original_environment.py",
|
|
"constructed_state": CONSTRUCTED,
|
|
"init_locked_events": INIT_EVENTS, "init_locked_fill_mappings": FILLS,
|
|
"surface": {"bytes": 0x207a00, "tag": "0xe", "page_size": "0x1000",
|
|
"producer": "_nv052583rm -> _nv052522rm -> _nv052518rm -> _nv052601rm"},
|
|
"executed_on_the_traced_case": TRACED_EXECUTED,
|
|
"argument_block_traced": ARGUMENTS_TRACED.hex(),
|
|
"physical_transcript": dict(PHYSICAL, file="target/trace/b3-bar0.txt",
|
|
reproduced_by_original_instructions=True),
|
|
"cases": len(rows), "cases_by_kind": counts,
|
|
"oracle": "target/gpu-stage/original-pmu-ls-start.txt",
|
|
"oracle_sha256": hashlib.sha256(oracle.encode()).hexdigest(),
|
|
"fixture_supplied": sorted(name for name, unused in hooks.values()
|
|
if not name.startswith("__x86")),
|
|
"scope": "Original GV100 PMU class constructor, ConstructEngine, InitLocked and Load. "
|
|
"Register values, time, memory, address-space, clock, fuse and interrupt "
|
|
"services are fixture-supplied; no hardware executed."}
|
|
(ROOT / "reports/gpu-pmu-ls-start-original.json").write_text(json.dumps(report, indent=2) + "\n")
|
|
print(f"{len(rows)} original PMU start cases {counts}; traced case: {len(registers)} register "
|
|
f"accesses equal transcript lines {FIRST}-{LAST}; oracle sha256 {report['oracle_sha256']}")
|