mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +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
135 lines
7.6 KiB
Python
135 lines
7.6 KiB
Python
#!/usr/bin/env python3
|
|
"""CPU-only original conftest/C vs Rust/config differential; no driver calls."""
|
|
import ctypes
|
|
import hashlib
|
|
import importlib.util
|
|
import itertools
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import tempfile
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
ARTIFACT = Path('/home/geodd/nvidia-driver/analysis-580.178.04/extracted/kernel')
|
|
NAMES = ('VGX_BUILD', 'VGX_KVM_BUILD', 'VGX_DEVICE_VM_BUILD')
|
|
CASES = ('dom0_kernel_present', 'nvidia_vgpu_kvm_build', 'device_vm_build')
|
|
DEFINES = ('NV_DOM0_KERNEL_PRESENT', 'NV_VGPU_KVM_BUILD', 'NV_DEVICE_VM_BUILD')
|
|
CFG = ('nv_rs_vgx_dom0', 'nv_rs_vgx_kvm', 'nv_rs_vgx_device_vm')
|
|
|
|
|
|
def run(argv, **kwargs):
|
|
return subprocess.check_output(argv, text=True, **kwargs).strip()
|
|
|
|
|
|
def main():
|
|
spec = importlib.util.spec_from_file_location('product', ROOT/'tools/timer-timeout-build-product.py')
|
|
product = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(product)
|
|
source_paths = [ARTIFACT/'conftest.sh', ARTIFACT/'nvidia/os-interface.c', ARTIFACT/'common/inc/nv-linux.h']
|
|
conftest, os_source, header = [p.read_text() for p in source_paths]
|
|
# Execute exact extracted shell branches, not translated Python booleans.
|
|
branches = [re.search(r'(?m)^\s*'+case+r'\)\n(.*?)^\s*;;', conftest, re.S).group(1) for case in CASES]
|
|
shell = 'append_conftest() { cat; }; probe() { case "$1" in\n'
|
|
shell += ''.join(case+')\n'+body+'\n;;\n' for case, body in zip(CASES, branches))
|
|
shell += 'esac; }; for probe_case in '+ ' '.join(CASES)+'; do probe "$probe_case"; done'
|
|
os_function = re.search(r'NvBool NV_API_CALL os_is_vgx_hyper\(void\)\n\{.*?\n\}', os_source, re.S).group()
|
|
conditional = re.search(r'#if defined\(NV_DOM0_KERNEL_PRESENT\) \|\|.*?\n#define NV_VGX_HYPER', header).group()+'\n#endif\n'
|
|
values = (None, '', '0', '1', ' ', '\t', "';$(touch NEVER_EXECUTE_VGX);#", 'line1\nline2')
|
|
cfg_cases = 0
|
|
with tempfile.TemporaryDirectory(prefix='nv-vgx-test-') as temp:
|
|
out = Path(temp)
|
|
rustc = str(Path.home()/'.cargo/bin/rustc')
|
|
executables = []
|
|
for mask in range(9):
|
|
binary = out/f'provider-{mask}'
|
|
args = [rustc, '--edition=2021', '-Dwarnings', str(ROOT/'tests/timer-timeout-vgx/provider.rs'), '-o', str(binary)]
|
|
if mask != 8:
|
|
args += ['--cfg=nv_rs_build_product_resolved']
|
|
args += ['--cfg='+cfg for bit,cfg in enumerate(CFG) if mask & (1<<bit)]
|
|
run(args)
|
|
run([str(binary),str(mask)])
|
|
executables.append(binary)
|
|
libraries = []
|
|
for mask in range(8):
|
|
prefix = ''.join('#define '+define+'\n' for bit,define in enumerate(DEFINES) if mask & (1<<bit))
|
|
cpath = out/f'original-{mask}.c'
|
|
cpath.write_text('typedef unsigned char NvBool;\n#define NV_TRUE 1\n#define NV_FALSE 0\n#define NV_API_CALL\n'+prefix+conditional+os_function+'\n')
|
|
libpath = out/f'original-{mask}.so'
|
|
run(['cc','-shared','-fPIC','-Wall','-Wextra','-Werror',str(cpath),'-o',str(libpath)])
|
|
library = ctypes.CDLL(str(libpath))
|
|
library.os_is_vgx_hyper.restype = ctypes.c_ubyte
|
|
assert library.os_is_vgx_hyper() == int(mask != 0)
|
|
libraries.append(library)
|
|
# Injected metacharacters remain environment data, even through Make.
|
|
makefile = out/'Makefile'
|
|
makefile.write_text('ROOT := '+str(ROOT)+'\nRUST_BUILD_PRODUCT_RECEIPT := '+str(out/'make-receipt.json')+'\ninclude $(ROOT)/utils.mk\n.PHONY: show\nshow:\n\t@echo $(RUST_BUILD_PRODUCT_FLAGS)\n')
|
|
for combination in itertools.product(values, repeat=3):
|
|
env = dict(os.environ)
|
|
for name,value in zip(NAMES,combination):
|
|
env.pop(name,None)
|
|
if value is not None:
|
|
env[name] = value
|
|
expected = sum(1<<bit for bit,value in enumerate(combination) if value)
|
|
original = run(['sh','-c',shell], env=env)
|
|
actual = product.resolve(env)
|
|
for bit,define in enumerate(DEFINES):
|
|
assert ('#define '+define in original) == bool(expected & (1<<bit))
|
|
assert actual[define] == bool(expected & (1<<bit))
|
|
flags = run(['make','--no-print-directory','-s','-f',str(makefile)], env=env, cwd=out).split()
|
|
assert '--cfg=nv_rs_build_product_resolved' in flags
|
|
for bit,cfg in enumerate(CFG):
|
|
assert ('--cfg='+cfg in flags) == bool(expected & (1<<bit))
|
|
run([str(executables[expected]),str(expected)])
|
|
assert libraries[expected].os_is_vgx_hyper() == int(expected != 0)
|
|
cfg_cases += 1
|
|
# Command-line Make values override opposite inherited values.
|
|
for combination in itertools.product(values[1:], repeat=3):
|
|
env = dict(os.environ, **dict.fromkeys(NAMES,'inherited'))
|
|
flags = run(['make','--no-print-directory','-s','-f',str(makefile),*[name+'='+value for name,value in zip(NAMES,combination)]],env=env,cwd=out).split()
|
|
# GNU Make strips leading whitespace on command-line assignments.
|
|
# The resolved Make value is what conftest would receive, too.
|
|
for value,cfg in zip(combination,CFG):
|
|
assert ('--cfg='+cfg in flags) == bool(value.lstrip())
|
|
assert not (out/'NEVER_EXECUTE_VGX').exists()
|
|
# Stable receipt doesn't spuriously invalidate builds; role changes do.
|
|
receipt = out/'receipt.json'
|
|
env = dict(os.environ, **dict.fromkeys(NAMES,''))
|
|
tool = ['python3',str(ROOT/'tools/timer-timeout-build-product.py'),'--receipt',str(receipt)]
|
|
run(tool,env=env); before = receipt.stat().st_mtime_ns
|
|
run(tool,env=env); assert receipt.stat().st_mtime_ns == before
|
|
env[NAMES[0]] = '0'; run(tool,env=env)
|
|
assert receipt.stat().st_mtime_ns != before
|
|
# Exercise actual utils.mk invalidation and automatic-variable behavior
|
|
# in a private build root, without rebuilding shared production artifacts.
|
|
project = out/'project'
|
|
(project/'tools').mkdir(parents=True)
|
|
(project/'tools/timer-timeout-build-product.py').symlink_to(ROOT/'tools/timer-timeout-build-product.py')
|
|
target = project/'kernel-open/nvidia/libnv_rs_abi.rlib'
|
|
target.parent.mkdir(parents=True)
|
|
source = project/'source.rs'
|
|
source.write_text('actual first prerequisite\n')
|
|
buildfile = project/'Makefile'
|
|
buildfile.write_text('ROOT := '+str(project)+'\ninclude '+str(ROOT/'utils.mk')+'\n.PHONY: all\nall: '+str(target)+'\n'+str(target)+': '+str(source)+'\n\t@cp $< $@\n')
|
|
env[NAMES[0]] = ''
|
|
command = ['make','--no-print-directory','-s','-f',str(buildfile)]
|
|
run(command,env=env,cwd=out)
|
|
assert target.read_text() == source.read_text()
|
|
first_time = target.stat().st_mtime_ns
|
|
run(command,env=env,cwd=out)
|
|
assert target.stat().st_mtime_ns == first_time
|
|
env[NAMES[0]] = '0'
|
|
run(command,env=env,cwd=out)
|
|
assert target.stat().st_mtime_ns != first_time
|
|
report = {'scope':'CPU-only exact extracted closed580 shell/C vs actual Rust provider and Make parser; no GPU activity',
|
|
'original_shell_environment_cases':cfg_cases,'make_command_line_cases':len(values[1:])**3,
|
|
'compiled_original_c_profiles':8,'compiled_rust_profiles':9,'unresolved_receipt_rejected':True,
|
|
'sources':[{'path':str(p),'sha256':hashlib.sha256(p.read_bytes()).hexdigest()} for p in source_paths]}
|
|
(ROOT/'reports/timer-timeout-vgx-validation.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
print(json.dumps(report,indent=2))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|