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/fetch_from_guest.sh | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 userspace/cuda/570.144/scripts/fetch_from_guest.sh (limited to 'userspace/cuda/570.144/scripts/fetch_from_guest.sh') diff --git a/userspace/cuda/570.144/scripts/fetch_from_guest.sh b/userspace/cuda/570.144/scripts/fetch_from_guest.sh new file mode 100755 index 0000000..6ed24f1 --- /dev/null +++ b/userspace/cuda/570.144/scripts/fetch_from_guest.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# SPDX-License-Identifier: BSD-3-Clause +# +# fetch_from_guest.sh - copy a file out of a running Open-IOV guest. +# +# The guest agent is used to start a netcat transfer from the guest to the +# host (QEMU user networking: the host is 10.0.2.2), which is much faster and +# more robust than pushing tens of megabytes through the agent in base64 +# chunks. +# +# Usage: scripts/fetch_from_guest.sh [guest-bind-ip] +# e.g. scripts/fetch_from_guest.sh \ +# /usr/lib/x86_64-linux-gnu/libcuda.so.570.144 +set -e + +HERE="$(cd "$(dirname "$0")" && pwd)" +RUN="$(cd "$HERE/.." && pwd)/run" +VMEXEC="$HERE/../../../scripts/vgpu_vm.py" +PORT="${PORT:-47311}" + +GUEST_PATH="${1:?usage: $0 [guest-bind-ip]}" +HOST_IP="${2:-10.0.2.2}" +OUT="$RUN/$(basename "$GUEST_PATH")" + +mkdir -p "$RUN" + +# Guest-side md5 for verification +GUEST_MD5=$("$VMEXEC" exec "md5sum '$GUEST_PATH'" 2>/dev/null | awk '{print $1}') +[ -n "$GUEST_MD5" ] || { echo "cannot stat $GUEST_PATH in guest"; exit 1; } + +echo "[*] guest md5: $GUEST_MD5" +echo "[*] listening on :$PORT -> $OUT" +rm -f "$OUT" + +nc -l "$PORT" > "$OUT" & +NCPID=$! +sleep 1 + +"$VMEXEC" exec "setsid sh -c 'nc $HOST_IP $PORT < $GUEST_PATH' >/dev/null 2>&1 &" >/dev/null 2>&1 || true + +# Wait for the transfer to settle (size stable for two checks) +prev=0 +for _ in $(seq 1 60); do + sleep 2 + cur=$(stat -c%s "$OUT" 2>/dev/null || echo 0) + [ "$cur" -gt 0 ] && [ "$cur" = "$prev" ] && break + prev=$cur +done +wait $NCPID 2>/dev/null || true + +HOST_MD5=$(md5sum "$OUT" | awk '{print $1}') +echo "[*] host md5: $HOST_MD5" +if [ "$GUEST_MD5" != "$HOST_MD5" ]; then + echo "[FAIL] md5 mismatch" + exit 1 +fi +echo "[ok] $OUT ($(stat -c%s "$OUT") bytes)" -- cgit v1.2.3