#!/bin/bash # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2026 Open-IOV contributors # vmrestart.sh - stop QEMU, reload vgsp.ko from the tree, fresh mdev, # relaunch the vGPU VM. Everything bounded so a stuck step cannot hang the # caller. set -u cd "$(dirname "$(readlink -f "$0")")/../.." sudo pkill -f qemu-system-x86_64 2>/dev/null # Reap host-side watchers too: a pin_gr_stream/semfix pair left over from the # previous boot holds the vsock port and the single QMP socket slot and will # silently corrupt the next run (two QMP clients). pkill -f "pin_gr_stream" 2>/dev/null pkill -f "semfix_uvmt" 2>/dev/null pkill -f "guest_pin_stream" 2>/dev/null sleep 4 sudo rm -f /tmp/qemu-guest-agent.sock /tmp/qemu-qmp.sock for m in /sys/bus/mdev/devices/*; do [ -d "$m" ] || continue timeout 20 sudo sh -c "echo 1 > $m/remove" || echo "WARN: mdev remove timeout" done timeout 30 sudo rmmod vgsp || { echo "ERROR: rmmod failed"; exit 1; } sudo insmod kernel/vgsp.ko || { echo "ERROR: insmod failed"; exit 1; } U=$(uuidgen) echo "$U" | sudo tee /sys/class/mdev_bus/0000:01:00.0/mdev_supported_types/nvidia-nvidia-vgpu-turing/create >/dev/null sed -i "s|/sys/bus/mdev/devices/[0-9a-f-]*|/sys/bus/mdev/devices/$U|" tools/guest-diag/launch_qemu_rootport.run.sh mkdir -p /tmp/sockets/e726ba0b-204f-4ec9-91da-983ed7f41d06 (setsid nohup tools/guest-diag/launch_qemu_rootport.run.sh > tools/guest-diag/run/qemu.log 2>&1 &) sleep 6 if pgrep -f qemu-system-x86_64 >/dev/null; then echo "VM up (mdev $U)" else echo "VM FAILED"; tail -5 tools/guest-diag/run/qemu.log; exit 1 fi