From 54ca82d81bacb56197a607d0039ca6a015f5ac44 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Rasmusson Date: Wed, 23 Sep 2026 07:05:45 -0400 Subject: userspace/cuda: libcuda analysis tree (debug-focused), guest ioctl tracer Analysis tooling for debugging CUDA execution in Open-IOV guests: - userspace/cuda/570.144/: fetch a library from a running guest (nc), objdump helpers, crash ip -> file vaddr + symbol mapping, and Ghidra headless import/analysis/decompile scripts (project kept so single functions decompile in seconds). The purpose is debugging correctness and performance of CUDA in Open-IOV VMs (not a reimplementation); extracted binaries and decompiled output are gitignored. - tools/guest-diag/ioctl_trace.c: ptrace tracker for the NVIDIA driver ioctls of a child (libcuda issues raw syscalls, so LD_PRELOAD sees nothing). Decodes RM_ALLOC (class) and RM_CONTROL (cmd) arguments; this is how the cuCtxCreate crash sequence was captured. - tools/test/cuda_drv_test.c: unbuffered + per-call markers so a crash identifies the CUDA call it happened in. --- userspace/cuda/570.144/scripts/disasm.sh | 65 ++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 userspace/cuda/570.144/scripts/disasm.sh (limited to 'userspace/cuda/570.144/scripts/disasm.sh') diff --git a/userspace/cuda/570.144/scripts/disasm.sh b/userspace/cuda/570.144/scripts/disasm.sh new file mode 100755 index 0000000..01fea69 --- /dev/null +++ b/userspace/cuda/570.144/scripts/disasm.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# SPDX-License-Identifier: BSD-3-Clause +# +# disasm.sh - objdump helpers for a library under analysis. +# +# Usage: +# scripts/disasm.sh [before] [after] +# disassemble [vaddr-before, vaddr+after] (default 0x40 each side) +# scripts/disasm.sh --bytes +# raw bytes in the range +# scripts/disasm.sh --symbol +# exported symbol address/size (readelf dyn-syms) +# scripts/disasm.sh --nearest +# nearest preceding exported symbol (FUNC) and the offset into it +set -e + +cmd="${1:?usage: disasm.sh [--bytes|--symbol|--nearest] ...}" +case "$cmd" in +--bytes) + file="$2"; start="$3"; end="$4" + objdump -s --start-address="$start" --stop-address="$end" "$file" + ;; +--symbol) + file="$2"; name="$3" + readelf -sW --dyn-syms "$file" | awk -v n="$name" '$8 == n {print}' + ;; +--nearest) + file="$2"; target="$3" + python3 - "$file" "$target" <<'PY' +import subprocess, sys +path, t = sys.argv[1], int(sys.argv[2], 16) +out = subprocess.check_output(["readelf", "-sW", "--dyn-syms", path], text=True) +syms = [] +for line in out.splitlines(): + p = line.split() + if len(p) >= 8 and p[3] == "FUNC": + try: + syms.append((int(p[1], 16), int(p[2]), p[7])) + except ValueError: + pass +syms.sort() +prev = None +for a, s, n in syms: + if a <= t: + prev = (a, s, n) + else: + break +if prev: + print("nearest exported: %s at 0x%x size 0x%x (+0x%x)" % + (prev[2], prev[0], prev[1], t - prev[0])) +else: + print("no exported symbol before 0x%x" % t) +PY + ;; +*) + file="$1"; vaddr="$2" + before="${3:-0x40}"; after="${4:-0x40}" + start=$(printf '0x%x' $(( vaddr - before )) 2>/dev/null || echo "$vaddr") + end=$(printf '0x%x' $(( vaddr + after )) 2>/dev/null || echo "$vaddr") + # allow hex arithmetic with shell + start=$(python3 -c "print(hex(int('$vaddr',16)-int('$before',16)))") + end=$(python3 -c "print(hex(int('$vaddr',16)+int('$after',16)))") + objdump -d -Mintel --start-address="$start" --stop-address="$end" "$file" + ;; +esac -- cgit v1.2.3