Files
nvdriver/tools/check_gv100_stall_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

165 lines
6.8 KiB
Python

#!/usr/bin/env python3
"""Generate GV100 stall traces from closed 580 ELF instructions and scripted MMIO."""
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_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,
UC_X86_REG_R8, UC_X86_REG_R9,
)
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, DATA, STACK, EXIT = 0x10000000, 0x30000000, 0x40000000, 0x50000000
GPU, INTR, GMMU, KERNEL_GMMU = DATA, DATA + 0x10000, DATA + 0x12000, DATA + 0x14000
INDIRECT = EXIT + 0x200
BINDINGS = {
0x148: "_nv037550rm", 0x150: "_nv037527rm", 0x248: "_nv037622rm",
0x250: "_nv037744rm", 0x300: "_nv037779rm", 0x348: "_nv037760rm", 0x350: "_nv037580rm",
0x398: "_nv037753rm", 0x3a0: "_nv037574rm", 0x3a8: "_nv037553rm",
0x3b0: "_nv037628rm", 0x3b8: "_nv037747rm",
}
FUNCTIONS = ("_nv005896rm", "_nv037753rm", "_nv037550rm", "_nv013845rm", "_nv037747rm", "_nv037576rm", "_nv005975rm", "_nv029411rm",
"_nv037772rm", "_nv037779rm")
assert hashlib.sha256(ORIGINAL.read_bytes()).hexdigest() == DIGEST
with ORIGINAL.open("rb") as stream:
elf = ELFFile(stream)
symtab = list(elf.get_section_by_name(".symtab").iter_symbols())
symbols = {symbol.name: symbol for symbol in symtab}
section = elf.get_section_index(".text")
text = bytearray(elf.get_section_by_name(".text").data())
original_functions = {
name: {"offset": symbols[name]["st_value"], "size": symbols[name]["st_size"]}
for name in set(FUNCTIONS) | set(BINDINGS.values())
}
ranges = [(symbols[name]["st_value"], symbols[name]["st_size"]) for name in FUNCTIONS]
for relocation in elf.get_section_by_name(".rela.text").iter_relocations():
offset = relocation["r_offset"]
if not any(start <= offset < start + size for start, size in ranges):
continue
target = symtab[relocation["r_info_sym"]]
if target.name == "__x86_indirect_thunk_rax":
address = INDIRECT
else:
assert target["st_shndx"] == section, target.name
address = TEXT + target["st_value"]
value = address + relocation["r_addend"]
kind = relocation["r_info_type"]
if kind in (2, 4):
value -= TEXT + offset
else:
assert kind == 11, (kind, target.name)
struct.pack_into("<i", text, offset, value)
cpu = Uc(UC_ARCH_X86, UC_MODE_64)
for address, size in ((TEXT, (len(text) + 4095) & ~4095), (DATA, 0x20000),
(STACK, 0x10000), (EXIT, 0x1000)):
cpu.mem_map(address, size)
cpu.mem_write(TEXT, bytes(text))
def write(address, value, width=4):
cpu.mem_write(address, value.to_bytes(width, "little"))
def read(address, width=8):
return int.from_bytes(cpu.mem_read(address, width), "little")
def call(name, *arguments):
registers = (UC_X86_REG_RDI, UC_X86_REG_RSI, UC_X86_REG_RDX,
UC_X86_REG_RCX, UC_X86_REG_R8, UC_X86_REG_R9)
for register, argument in zip(registers, arguments, strict=False):
cpu.reg_write(register, argument)
cpu.reg_write(UC_X86_REG_RSP, STACK + 0xfff8)
cpu.reg_write(UC_X86_REG_RBP, STACK + 0x8000)
write(STACK + 0xfff8, EXIT, 8)
cpu.emu_start(TEXT + symbols[name]["st_value"], EXIT, count=20000)
assert cpu.reg_read(UC_X86_REG_RIP) == EXIT, name
write(DATA + 0x18010, 0x23, 2)
write(DATA + 0x18110, 2, 2)
call("_nv005896rm", INTR, DATA + 0x18000, DATA + 0x18100)
for slot, name in BINDINGS.items():
assert read(INTR + slot) == TEXT + symbols[name]["st_value"], (slot, name)
write(GPU + 0x1f88, GMMU, 8)
write(GPU + 0x1f90, KERNEL_GMMU, 8)
call("_nv005975rm", GMMU, DATA + 0x18000)
assert read(GMMU + 0x2c8) == TEXT + symbols["_nv029411rm"]["st_value"]
write(GMMU + 0x8e0, 0x1000)
write(INTR + 0x16cc, 1, 1)
mmio_write = TEXT + symbols["_nv053912rm"]["st_value"]
events = []
def intercept(emu, pc, _size, _user):
if pc == INDIRECT:
emu.reg_write(UC_X86_REG_RIP, emu.reg_read(UC_X86_REG_RAX))
return
if pc == mmio_write:
assert emu.reg_read(UC_X86_REG_RDI) == GPU + 0x4120
offset = emu.reg_read(UC_X86_REG_RCX) & 0xffffffff
mask = emu.reg_read(UC_X86_REG_R8) & 0xffffffff
events.append(f"w:{offset:x}:{mask:x}")
else:
return
stack = emu.reg_read(UC_X86_REG_RSP)
emu.reg_write(UC_X86_REG_RSP, stack + 8)
emu.reg_write(UC_X86_REG_RIP, read(stack))
cpu.hook_add(UC_HOOK_CODE, intercept)
rows = []
for mode, reporting, allowed, owned, hub, rail in itertools.product(
range(4), (0, 1), (0, 0xffffffff, 0x80001200),
(0, 0xffffffff, 0x00001200, 0x7ffffdff), (0, 0x20, 0x04, 0x03, 0x88, 0xff), (0, 1),
):
write(INTR + 0x16b8, reporting)
write(INTR + 0x1684, allowed)
write(GPU + 0xdec, owned)
write(KERNEL_GMMU + 0x4a0, hub)
write(GPU + 0x69e4, 3 if rail else 0)
events.clear()
call("_nv037753rm", GPU, INTR, mode, 0)
inputs = (mode, reporting, allowed, owned, hub, 0x1000, rail)
rows.append(" ".join(format(value, "x") for value in inputs) + ";" + " ".join(events))
out = ROOT / "target/gv100-stall/original-traces.txt"
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text("\n".join(rows) + "\n")
report = {
"original_sha256": DIGEST, "chip_hal": "0x23", "rm_hal": 2,
"bindings": {hex(slot): target for slot, target in BINDINGS.items()},
"objgmmu_mask_binding": {"slot": "0x2c8", "target": "_nv029411rm"},
"functions": {name: original_functions[name] for name in sorted(original_functions)},
"trace_cases": len(rows), "trace_sha256": hashlib.sha256(out.read_bytes()).hexdigest(),
"scope": "GV100 PF original stall programming instructions. Original GMMU source translation executes. MMIO writes are intercepted. No physical GPU access."
}
(ROOT / "reports/gv100-stall-original.json").write_text(json.dumps(report, indent=2) + "\n")
print(f"{len(rows)} completed original instruction traces")
# Execute the original cold full-PF ownership initializer, before a GMMU
# producer has registered HUB leaves. Then invoke the selected direct masks.
cpu.mem_write(GPU, bytes(0x8000))
write(INTR + 0x3f6, 0, 1)
call("_nv037772rm", GPU, INTR)
assert read(GPU + 0xdec, 4) == read(INTR + 0x1684, 4) == 0xffffffff
write(GPU + 0x1f88, GMMU, 8)
write(GPU + 0x1f90, KERNEL_GMMU, 8)
write(KERNEL_GMMU + 0x4a0, 0)
write(GPU + 0x911, 1, 1)
events.clear()
call("_nv037753rm", GPU, INTR, 0, 0)
call("_nv037779rm", GPU)
assert len(events) == 4
(out.parent / "cold-mask-original.txt").write_text(" ".join(events) + "\n")
print("Completed original cold GV100 PMC mask writes")