Files
nvdriver/tools/post_reboot.sh
morebrackets f7883ebf99 Address CodeRabbit findings in reboot scripts and offline test
- Reject an empty-string first argument in tools/post_reboot.sh and cover it
  in test_post_reboot_rejects_unknown_or_extra_arguments.
- Require a successful nonempty ORIG_SYSRQ read before writing 1 to
  /proc/sys/kernel/sysrq, and set SYSRQ_MODIFIED=1 before the write in both
  capture and restart blocks.
- Shell-quote temp paths with shlex.quote() in test_reboot_scripts.py.
2026-12-02 16:10:50 -08:00

100 lines
4.7 KiB
Bash

#!/bin/sh
# Run once after the reboot that clears the mmiotrace oops of 2026-11-18.
#
# sh tools/post_reboot.sh health check + original-driver CUDA baseline
# sh tools/post_reboot.sh --first-open the same, then the first hardware open of
# nvidia_rs on 0000:b3:00.0 (bring-up level 2)
#
# Every step must pass before the next one runs. The output is also written to
# reports/post-reboot-<UTC time>.log so the next session can read it.
set -u
ROOT=$(cd "$(dirname "$0")/.." && pwd)
PCI=0000:b3:00.0
STAMP=$(date -u +%Y%m%dT%H%M%SZ)
mkdir -p "$ROOT/reports"
LOG="$ROOT/reports/post-reboot-$STAMP.log"
FIRST_OPEN=0
if [ "$#" -eq 0 ]; then
:
elif [ "$#" -eq 1 ] && [ "$1" = "--first-open" ]; then
FIRST_OPEN=1
else
echo "usage: sh tools/post_reboot.sh [--first-open]" >&2
exit 2
fi
say() { printf '%s\n' "$*" | tee -a "$LOG"; }
fail() { say "FAIL: $*"; say "Stopped. Log: $LOG"; exit 1; }
say "post-reboot check $STAMP kernel $(uname -r)"
# 1. The machine is clean (no kernel oops taint bit, no stuck driver tasks).
UP=$(cut -d. -f1 /proc/uptime)
TAINT=$(cat /proc/sys/kernel/tainted)
say "uptime ${UP}s, taint $TAINT"
[ $((TAINT & 128)) -eq 0 ] || fail "kernel taint $TAINT has oops bit (128) set"
STUCK=$(ps -eo stat,comm | grep -E '^D.*(nv_open_q|nvidia)' || true)
[ -z "$STUCK" ] || fail "stuck driver tasks in D state: $STUCK"
pgrep -x native-hello >/dev/null && fail "a native-hello process exists"
[ -e /sys/module/nvidia_rs ] && fail "nvidia_rs is loaded"
[ "$(cat /sys/devices/system/cpu/online)" = "0-63" ] || fail "not all CPUs are online"
TRACER=$(sudo -n cat /sys/kernel/tracing/current_tracer 2>/dev/null || echo unreadable)
say "tracer $TRACER"
[ "$TRACER" = "nop" ] || fail "tracer is '$TRACER', expected nop (is sudo available without a password?)"
# 2. All eight V100s are on the original driver.
for d in 1a 1b 3d 3e 88 89 b2 b3; do
link=/sys/bus/pci/devices/0000:$d:00.0/driver
name=$([ -e "$link" ] && basename "$(readlink "$link")" || echo none)
say "0000:$d:00.0 driver=$name"
[ "$name" = "nvidia" ] || fail "0000:$d:00.0 is not bound to the original driver"
done
grep -q "580.178.04" /proc/driver/nvidia/version || fail "original driver is not 580.178.04"
# 3. nvidia-smi answers (it hung before the reboot) and nothing is using a GPU.
SMI=$(timeout 120 nvidia-smi --query-gpu=pci.bus_id,memory.used --format=csv,noheader,nounits 2>&1) \
|| fail "nvidia-smi failed or timed out: $SMI"
say "$SMI"
[ "$(printf '%s\n' "$SMI" | wc -l)" -eq 8 ] || fail "nvidia-smi does not list eight GPUs"
APPS=$(timeout 120 nvidia-smi --query-compute-apps=pid --format=csv,noheader 2>&1) \
|| fail "nvidia-smi compute-apps query failed or timed out: $APPS"
[ -z "$APPS" ] || fail "GPU compute processes are running: $APPS"
# 4. Original-driver baseline: the native CUDA kernel on the test GPU.
HELLO="$ROOT/target/hardware-hello"
[ -x "$HELLO/native-hello" ] || fail "$HELLO/native-hello is missing (rebuild it first)"
OUT=$(timeout 600 "$HELLO/native-hello" "$HELLO/native_hello.sm70.cubin" "$PCI" 317866785 2>&1) \
|| fail "native-hello failed on the original driver: $OUT"
say "baseline: $OUT"
printf '%s' "$OUT" | grep -q '"verified_words": *64' || fail "baseline did not verify 64 words"
say "PASS: machine is healthy and the original driver runs CUDA on $PCI"
if [ "$FIRST_OPEN" -eq 0 ]; then
say "First hardware open not requested. To run it: sh tools/post_reboot.sh --first-open"
say "Log: $LOG"
exit 0
fi
# 5. Replacement hardware execution: first open of nvidia_rs, then restore.
say "module $(sha256sum "$ROOT/kernel-open/nvidia_rs.ko")"
FIRST_OPEN_OUT=$(mktemp)
trap 'rm -f "$FIRST_OPEN_OUT"' EXIT
sudo python3 "$ROOT/tools/run_hardware_first_open.py" --pci "$PCI" --confirm "$PCI" \
--label "b3-$STAMP" --bringup "${BRINGUP:-2}" ${BRINGUP_BAR1:+--bringup-bar1} >"$FIRST_OPEN_OUT" 2>&1
FIRST_OPEN_RC=$?
tee -a "$LOG" <"$FIRST_OPEN_OUT"
rm -f "$FIRST_OPEN_OUT"
trap - EXIT
AFTER_LINK="/sys/bus/pci/devices/$PCI/driver"
AFTER_DRV=$([ -e "$AFTER_LINK" ] && basename "$(readlink "$AFTER_LINK")" || echo none)
say "driver after: $AFTER_DRV"
[ "$FIRST_OPEN_RC" -eq 0 ] || fail "run_hardware_first_open.py exited $FIRST_OPEN_RC (driver=$AFTER_DRV)"
[ "$AFTER_DRV" = "nvidia" ] || fail "$PCI was not restored to nvidia (driver=$AFTER_DRV)"
# 6. The original driver must still work on the GPU afterwards.
OUT=$(timeout 600 "$HELLO/native-hello" "$HELLO/native_hello.sm70.cubin" "$PCI" 317866785 2>&1) \
|| fail "native-hello failed after restoring the GPU: $OUT"
say "after restore: $OUT"
printf '%s' "$OUT" | grep -q '"verified_words": *64' || fail "post-restore run did not verify 64 words"
say "PASS: first open ran and the GPU is back on the original driver. Log: $LOG"