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
117 lines
5.5 KiB
JavaScript
117 lines
5.5 KiB
JavaScript
// CLOCK_MONOTONIC stamps own-process events; correlation needs a verified matching recorder clock.
|
|
const traceLibc = Process.getModuleByName('libc.so.6');
|
|
const traceClock = new NativeFunction(traceLibc.getExportByName('clock_gettime'), 'int', ['int', 'pointer']);
|
|
const traceTime = Memory.alloc(16);
|
|
function sendStamped(payload) {
|
|
const status = traceClock(1, traceTime);
|
|
payload.monotonic_ns = status === 0 ?
|
|
(BigInt(traceTime.readU64().toString()) * 1000000000n + BigInt(traceTime.add(8).readU64().toString())).toString() : null;
|
|
send(payload);
|
|
}
|
|
// Observe only this spawned acceptance workload's NVIDIA device ioctls.
|
|
// No target memory or ioctl parameters are modified.
|
|
const libc = Process.getModuleByName('libc.so.6');
|
|
const readlink = new NativeFunction(libc.getExportByName('readlink'), 'long',
|
|
['pointer', 'pointer', 'ulong']);
|
|
function devicePath(fd) {
|
|
const path = Memory.allocUtf8String('/proc/self/fd/' + fd);
|
|
const output = Memory.alloc(512);
|
|
const count = Number(readlink(path, output, 511));
|
|
return count > 0 ? output.readUtf8String(count) : '';
|
|
}
|
|
function bytes(pointer, length) {
|
|
if (length === 0) return '';
|
|
return Array.from(new Uint8Array(pointer.readByteArray(length)),
|
|
b => b.toString(16).padStart(2, '0')).join('');
|
|
}
|
|
let sequence = 0;
|
|
const phases = new Map();
|
|
function observeCuda(cuda) {
|
|
sendStamped({kind: 'cuda_module', path: cuda.path});
|
|
for (const name of ['cuInit', 'cuDeviceGetByPCIBusId', 'cuCtxCreate_v2',
|
|
'cuModuleLoad', 'cuMemAlloc_v2', 'cuMemsetD8_v2',
|
|
'cuLaunchKernel', 'cuCtxSynchronize', 'cuMemcpyDtoH_v2',
|
|
'cuMemFree_v2', 'cuModuleUnload', 'cuCtxDestroy_v2']) {
|
|
Interceptor.attach(cuda.getExportByName(name), {
|
|
onEnter() {
|
|
this.tid = Process.getCurrentThreadId();
|
|
this.previous = phases.get(this.tid);
|
|
phases.set(this.tid, name);
|
|
sendStamped({kind: 'cuda_enter', sequence: sequence++, tid: this.tid, name});
|
|
},
|
|
onLeave(result) {
|
|
sendStamped({kind: 'cuda_leave', sequence: sequence++, tid: this.tid,
|
|
name, result: result.toInt32()});
|
|
if (this.previous === undefined) phases.delete(this.tid);
|
|
else phases.set(this.tid, this.previous);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
const moduleObserver = Process.attachModuleObserver({
|
|
onAdded(module) {
|
|
if (module.name.startsWith('libcuda.so')) observeCuda(module);
|
|
}
|
|
});
|
|
Interceptor.attach(libc.getExportByName('write'), {
|
|
onEnter(args) {
|
|
if (args[0].toInt32() === 1) {
|
|
try {
|
|
sendStamped({kind: 'stdout', text: args[1].readUtf8String(Math.min(args[2].toUInt32(), 512))});
|
|
} catch (error) { sendStamped({kind: 'stdout_read_error', error: String(error)}); }
|
|
}
|
|
}
|
|
});
|
|
Interceptor.attach(libc.getExportByName('ioctl'), {
|
|
onEnter(args) {
|
|
this.record = null;
|
|
const fd = args[0].toInt32();
|
|
const path = devicePath(fd);
|
|
if (!path.startsWith('/dev/nvidia')) return;
|
|
const request = args[1].toUInt32();
|
|
const size = (request >>> 16) & 0x3fff;
|
|
this.argument = args[2];
|
|
this.size = Math.min(size, 256);
|
|
const record = {sequence: sequence++, fd, path, request,
|
|
number: request & 0xff, declared_size: size,
|
|
captured_size: this.size, tid: Process.getCurrentThreadId(),
|
|
synchronous_api: phases.get(Process.getCurrentThreadId()) || null};
|
|
try { record.before = bytes(this.argument, this.size); }
|
|
catch (error) { record.read_error_before = String(error); }
|
|
// Exact64-bit580 RM headers; other ioctls remain opaque observations.
|
|
if (request === 0xc030462b || request === 0xc020462a) {
|
|
try {
|
|
this.nested = this.argument.add(16).readPointer();
|
|
const declared = this.argument.add(request === 0xc030462b ? 32 : 24).readU32();
|
|
let effective = declared;
|
|
// Exact580 resource metadata supplies these implicit sizes.
|
|
// Preserve the zero wire size and identify the inference.
|
|
if (request === 0xc030462b && declared === 0) {
|
|
const resourceClass = this.argument.add(12).readU32();
|
|
if (resourceClass === 0x80) effective = 56;
|
|
if (resourceClass === 0x2080) effective = 4;
|
|
if (effective !== declared)
|
|
record.nested_size_source = 'exact580 resource class metadata';
|
|
}
|
|
this.nestedSize = Math.min(effective, 4096);
|
|
record.nested_declared_size = declared;
|
|
record.nested_captured_size = this.nestedSize;
|
|
record.nested_before = bytes(this.nested, this.nestedSize);
|
|
} catch (error) { record.nested_read_error_before = String(error); }
|
|
}
|
|
this.record = record;
|
|
},
|
|
onLeave(result) {
|
|
if (this.record === null) return;
|
|
this.record.result = result.toInt32();
|
|
try { this.record.after = bytes(this.argument, this.size); }
|
|
catch (error) { this.record.read_error_after = String(error); }
|
|
if (this.nestedSize !== undefined) {
|
|
try { this.record.nested_after = bytes(this.nested, this.nestedSize); }
|
|
catch (error) { this.record.nested_read_error_after = String(error); }
|
|
}
|
|
sendStamped(this.record);
|
|
}
|
|
});
|
|
sendStamped({kind: 'ready', scope: 'read-only ioctl observation in spawned native hello'});
|