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/ghidra_decompile.sh | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 userspace/cuda/570.144/scripts/ghidra_decompile.sh (limited to 'userspace/cuda/570.144/scripts/ghidra_decompile.sh') diff --git a/userspace/cuda/570.144/scripts/ghidra_decompile.sh b/userspace/cuda/570.144/scripts/ghidra_decompile.sh new file mode 100755 index 0000000..bf95e8c --- /dev/null +++ b/userspace/cuda/570.144/scripts/ghidra_decompile.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# SPDX-License-Identifier: BSD-3-Clause +# +# ghidra_decompile.sh - decompile the function containing a file vaddr. +# +# Runs Ghidra headless with -noanalysis: the program is imported, the crash +# address is disassembled and turned into a function on demand, then +# decompiled. That avoids a full auto-analysis pass over a ~70 MB library. +# +# Usage: scripts/ghidra_decompile.sh [outfile] +# env: GHIDRA_HOME (default: /snap/ghidra/current/ghidra) +# PROJECT_DIR (default: ../run/ghidra-proj) +# +# Output: run/_.c unless outfile is given. +set -e + +HERE="$(cd "$(dirname "$0")" && pwd)" +ROOT="$(cd "$HERE/.." && pwd)" +RUN="$ROOT/run" +BIN="${1:?usage: $0 [outfile]}" +VADDR="${2:?usage: $0 [outfile]}" +OUT="${3:-$RUN/$(basename "$BIN")_${VADDR}.c}" + +GHIDRA_HOME="${GHIDRA_HOME:-/snap/ghidra/current/ghidra}" +ANALYZE="$GHIDRA_HOME/support/analyzeHeadless" +PROJECT_DIR="${PROJECT_DIR:-$RUN/ghidra-proj}" +PROJECT_NAME="${PROJECT_NAME:-cuda-analysis}" + +[ -x "$ANALYZE" ] || { echo "analyzeHeadless not found at $ANALYZE"; exit 1; } +mkdir -p "$PROJECT_DIR" "$RUN" + +echo "[*] decompiling $BIN at $VADDR -> $OUT" +"$ANALYZE" "$PROJECT_DIR" "$PROJECT_NAME" \ + -import "$BIN" \ + -overwrite \ + -noanalysis \ + -scriptPath "$ROOT/ghidra" \ + -postScript DecompileAt.java "$VADDR" "$OUT" \ + -deleteProject \ + 2>&1 | tail -5 + +[ -f "$OUT" ] || { echo "[FAIL] no output produced"; exit 1; } +echo "[ok] $OUT" -- cgit v1.2.3