mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
* fix(ga10x/rmapi/modeset): R620 control translation, rmmod refcnt, modeset RM ops (#504, #491, #466, #501) * chore(pr513): drop gsp_route R620 hunk in favor of live-verified #514 * fix(gpu_owner): balance get_task_struct with put_task_struct after kthread_stop * fix(gpu_owner/irq): wait for runtime worker join & pin/teardown failed runtime IRQ close Addresses CodeRabbit review findings on PR #513 (and #491/#528): - gpu_owner.c: Wait for runtime_stopped in a 10s warning loop and always join via kthread_stop() + put_task_struct() so an unpinned runtime worker can never outlive module text during PCI removal / rmmod. - irq_adapter.c: When nv_rs_irq_close() fails to quiesce an unpinned runtime-kthread IRQ owner, acquire THIS_MODULE before returning the error (or force-disable/synchronize/free handlers if the module is already unloading so no callback can outlive module text). - ga10x_events.rs: Check nv_rs_irq_close() status in stop() and restore e.irq on failure instead of discarding the handle. - tests/irq-mock: Cover both live-pin and unloading-force-teardown paths. * fix(pci,irq): disable PCI INTx on forced IRQ close and bound AER/shutdown runtime stop Address follow-up review findings on #513: - In nv_rs_irq_close() forced teardown (unpinned runtime worker after mask failure), call pci_intx(owner->pdev, 0) for legacy INTx mode so the device stops asserting its level-triggered line without disabling a shared IRQ line for other devices, and add an irq-mock regression test. - Add nv_rs_gpu_owner_runtime_stop_bounded(owner, timeout_ms) preserving runtime_task and runtime_stopping on timeout (preventing restart races and allowing a later nv_rs_remove() stop to complete the join). - In nv_rs_shutdown() and nv_rs_aer_error_detected(), call pci_clear_master() first for immediate DMA containment, then use a bounded runtime stop so shutdown and PCIe AER callbacks never wedge indefinitely. * fix(pci,pm): bound runtime_lock wait, reclaim retired worker on start/AER, and reassert BME clear Address follow-up review findings on #513: - Include runtime_lock acquisition inside nv_rs_gpu_owner_runtime_stop_bounded()'s deadline via bounded mutex_trylock() polling so shutdown/AER cannot hang when startup holds runtime_lock waiting for runtime_ready. - Reclaim a retired worker in nv_rs_gpu_owner_runtime_start() via nv_rs_gpu_owner_runtime_reclaim_locked() and in nv_rs_aer_resume() so a timed-out bounded stop never strands runtime engines unavailable after recovery. - Reassert pci_clear_master(pdev) after the serialized stop attempt in nv_rs_shutdown() and nv_rs_aer_error_detected() so in-flight GPU bring-up cannot leave Bus Master enabled. - Use nv_rs_gpu_owner_runtime_stop_bounded() in PM suspend/runtime_suspend with full state rollback on timeout so suspend cannot wedge indefinitely while nv_rs_remove() keeps the unconditional join required before module unload. * fix(pci): keep Bus Master enabled during bounded GSP unload on shutdown Address final review comment on #513: - In nv_rs_shutdown(), invoke nv_rs_gpu_owner_runtime_stop_bounded(owner, 10000) before pci_clear_master(pdev) so an active GSP session can complete its DMA unload RPC during clean shutdown, then clear Bus Master Enable once the stop finishes or hits its bounded deadline. * fix(pci,pm): return DISCONNECT on AER stop timeout and keep full PM suspend stop Address review findings on #513: - In nv_rs_aer_error_detected(), return PCI_ERS_RESULT_DISCONNECT rather than PCI_ERS_RESULT_NEED_RESET if nv_rs_gpu_owner_runtime_stop_bounded() times out, preventing a PCIe slot reset while a live runtime worker could still issue MMIO or re-enable Bus Master. - In nv_rs_pm_do_suspend() and nv_rs_pmops_runtime_suspend(), wait for worker retirement via nv_rs_gpu_owner_runtime_stop() before entering D3hot rather than half-aborting after modeset suspend and USERD VMA revocation. --------- Co-authored-by: morebrackets <19673572+morebrackets@users.noreply.github.com>
416 lines
18 KiB
Bash
Executable File
416 lines
18 KiB
Bash
Executable File
#!/bin/bash
|
|
# Build, sign (when Secure Boot needs it), install and reload nvdriver
|
|
# (standalone nvidia_rs.ko + nvidia_rs_modeset.ko + nvidia_rs_drm.ko, plus
|
|
# optional UVM/modeset bridge modules).
|
|
#
|
|
# Order matters: build first, so a build failure leaves the running driver
|
|
# untouched; unload only once there is something to install; never report
|
|
# success while the old modules are still loaded.
|
|
set -euo pipefail
|
|
cd "$(dirname "$(readlink -f "$0")")"
|
|
|
|
RUNNING_KREL=$(uname -r)
|
|
KREL=${KREL:-$RUNNING_KREL}
|
|
if [[ "$KREL" != "$RUNNING_KREL" ]]; then
|
|
printf 'KREL=%s does not match running kernel %s. Use make modules_install with KERNEL_UNAME and INSTALL_MOD_PATH to stage for another kernel.\n' "$KREL" "$RUNNING_KREL" >&2
|
|
exit 2
|
|
fi
|
|
SIGN_FILE=/lib/modules/$KREL/build/scripts/sign-file
|
|
MOK_PRIV=${MOK_PRIV:-/var/lib/shim-signed/mok/MOK.priv}
|
|
MOK_DER=${MOK_DER:-/var/lib/shim-signed/mok/MOK.der}
|
|
INSTALL_DIR=/lib/modules/$KREL/updates/nvdriver
|
|
STANDALONE_DESKTOP=${STANDALONE_DESKTOP:-1}
|
|
LOAD_DESKTOP_KMS=${LOAD_DESKTOP_KMS:-$STANDALONE_DESKTOP}
|
|
BUILD_BRIDGES=${BUILD_BRIDGES:-1}
|
|
BIND_DEV_NODES=${BIND_DEV_NODES:-1}
|
|
CONFIGURE_MODPROBE=${CONFIGURE_MODPROBE:-1}
|
|
CONFIGURE_UDEV=${CONFIGURE_UDEV:-1}
|
|
# Keep stock NVIDIA modules loaded by default when the user opted into side-by-side mode
|
|
# (BIND_DEV_NODES=0 CONFIGURE_MODPROBE=0) so another GPU retains its stock driver.
|
|
if [ -z "${UNLOAD_STOCK+x}" ]; then
|
|
if [ "$BIND_DEV_NODES" = "0" ] && [ "$CONFIGURE_MODPROBE" = "0" ]; then
|
|
UNLOAD_STOCK=0
|
|
else
|
|
UNLOAD_STOCK=1
|
|
fi
|
|
fi
|
|
EXTRACT_FIRMWARE=${EXTRACT_FIRMWARE:-1}
|
|
MODPROBE_ARGS=${MODPROBE_ARGS:-"runtime_engines=1 pci_target=*"}
|
|
INSTALL_VOLTA_FOREVER=${INSTALL_VOLTA_FOREVER:-auto}
|
|
SKIP_VOLTA_FOREVER=${SKIP_VOLTA_FOREVER:-0}
|
|
VOLTA_FOREVER_VERSION=${VOLTA_FOREVER_VERSION:-0.1.6}
|
|
VOLTA_FOREVER_DEFAULT_VERSION=0.1.6
|
|
VOLTA_FOREVER_DEFAULT_INSTALLER_SHA256=c71507aada55892087bce2df05621533ba9edf60cd805ac12bc0e6f55c5b52e1
|
|
|
|
sb_enabled() { mokutil --sb-state 2>/dev/null | grep -q 'SecureBoot enabled'; }
|
|
# mokutil exits non-zero when the key IS enrolled; under pipefail a plain pipeline would read as "not enrolled"
|
|
mok_enrolled() { local out; out=$(mokutil --test-key "$MOK_DER" 2>/dev/null || true); grep -q 'is already enrolled' <<<"$out"; }
|
|
|
|
has_volta_gpu() {
|
|
local dev vendor id
|
|
for dev in /sys/bus/pci/devices/*; do
|
|
[ -r "$dev/vendor" ] && [ -r "$dev/device" ] || continue
|
|
vendor=$(<"$dev/vendor")
|
|
[ "$vendor" = "0x10de" ] || continue
|
|
id=$(<"$dev/device")
|
|
case "${id,,}" in
|
|
0x1d81|0x1db1|0x1db2|0x1db3|0x1db4|0x1db5|0x1db6|0x1db7|0x1db8|0x1dba|0x1df0|0x1df2|0x1df5|0x1df6)
|
|
return 0
|
|
;;
|
|
esac
|
|
done
|
|
return 1
|
|
}
|
|
|
|
install_volta_forever() {
|
|
if [ "$SKIP_VOLTA_FOREVER" = "1" ] || [ "$INSTALL_VOLTA_FOREVER" = "0" ]; then
|
|
return 0
|
|
fi
|
|
if [ "$INSTALL_VOLTA_FOREVER" = "auto" ]; then
|
|
if ! has_volta_gpu; then
|
|
return 0
|
|
fi
|
|
elif [ "$INSTALL_VOLTA_FOREVER" != "1" ]; then
|
|
echo "WARN: unknown INSTALL_VOLTA_FOREVER=$INSTALL_VOLTA_FOREVER (expected auto, 1, or 0); skipping volta-forever." >&2
|
|
return 0
|
|
fi
|
|
|
|
local vf_prefix vf_bin vf_url vf_script expected_sha got_sha
|
|
if [ "$(id -u)" = "0" ]; then
|
|
vf_prefix=${VF_PREFIX:-/opt/volta-forever}
|
|
vf_bin=${VF_BIN:-/usr/local/bin}
|
|
else
|
|
vf_prefix=${VF_PREFIX:-${XDG_DATA_HOME:-$HOME/.local/share}/volta-forever}
|
|
vf_bin=${VF_BIN:-$HOME/.local/bin}
|
|
fi
|
|
|
|
if [ -x "$vf_bin/vf" ] && [ -f "$vf_prefix/volta-forever-$VOLTA_FOREVER_VERSION-linux-x86_64/VERSION" ]; then
|
|
echo "== volta-forever =="
|
|
echo "volta-forever v$VOLTA_FOREVER_VERSION already installed at $vf_bin/vf (set SKIP_VOLTA_FOREVER=1 to skip)."
|
|
return 0
|
|
fi
|
|
|
|
echo "== volta-forever (CUDA 13 compatibility for Volta / V100) =="
|
|
echo "Volta GPU detected; installing pinned volta-forever v$VOLTA_FOREVER_VERSION (set SKIP_VOLTA_FOREVER=1 to opt out)."
|
|
vf_url="https://raw.githubusercontent.com/nbald/volta-forever/v${VOLTA_FOREVER_VERSION}/install.sh"
|
|
vf_script=$(mktemp "${TMPDIR:-/tmp}/nvdriver-vf-install.XXXXXX")
|
|
|
|
if command -v curl >/dev/null 2>&1; then
|
|
if ! curl -fsSL --proto '=https' --proto-redir '=https' --retry 3 -o "$vf_script" "$vf_url"; then
|
|
rm -f "$vf_script"
|
|
echo "WARN: failed to download volta-forever installer ($vf_url); skipping (nvdriver itself is installed)." >&2
|
|
return 0
|
|
fi
|
|
elif command -v wget >/dev/null 2>&1; then
|
|
if ! wget -q --https-only -O "$vf_script" "$vf_url"; then
|
|
rm -f "$vf_script"
|
|
echo "WARN: failed to download volta-forever installer ($vf_url); skipping (nvdriver itself is installed)." >&2
|
|
return 0
|
|
fi
|
|
else
|
|
rm -f "$vf_script"
|
|
echo "WARN: neither curl nor wget found; skipping volta-forever install." >&2
|
|
return 0
|
|
fi
|
|
|
|
expected_sha=${VOLTA_FOREVER_INSTALLER_SHA256:-}
|
|
if [ -z "$expected_sha" ] && [ "$VOLTA_FOREVER_VERSION" = "$VOLTA_FOREVER_DEFAULT_VERSION" ]; then
|
|
expected_sha=$VOLTA_FOREVER_DEFAULT_INSTALLER_SHA256
|
|
fi
|
|
if [ -n "$expected_sha" ]; then
|
|
got_sha=$(sha256sum "$vf_script" | awk '{print $1}')
|
|
if [ "$got_sha" != "$expected_sha" ]; then
|
|
rm -f "$vf_script"
|
|
echo "WARN: volta-forever installer SHA-256 mismatch (got $got_sha, expected $expected_sha); refusing to run it." >&2
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
if ! VF_VERSION="$VOLTA_FOREVER_VERSION" sh "$vf_script"; then
|
|
echo "WARN: volta-forever install did not complete; nvdriver itself is installed and verified." >&2
|
|
fi
|
|
rm -f "$vf_script"
|
|
}
|
|
|
|
echo "== build =="
|
|
make modules
|
|
KO_FILES=(kernel-open/nvidia_rs.ko)
|
|
HAS_MODESET_KO=0
|
|
HAS_DRM_KO=0
|
|
for opt_ko in kernel-open/nvidia_rs_modeset.ko kernel-open/nvidia_rs_drm.ko kernel-open/nvidia_rs_peermem.ko; do
|
|
if [ -f "$opt_ko" ]; then
|
|
KO_FILES+=("$opt_ko")
|
|
fi
|
|
done
|
|
if [ -f kernel-open/nvidia_rs_modeset.ko ]; then HAS_MODESET_KO=1; fi
|
|
if [ -f kernel-open/nvidia_rs_drm.ko ]; then HAS_DRM_KO=1; fi
|
|
if [ "$BUILD_BRIDGES" = "1" ]; then
|
|
make uvm-bridge
|
|
make modeset-bridge
|
|
KO_FILES+=(
|
|
kernel-open/uvm_bridge/nvidia_rs_uvm_bridge.ko
|
|
kernel-open/modeset_bridge/nvidia_rs_modeset_bridge.ko
|
|
)
|
|
fi
|
|
|
|
if sb_enabled; then
|
|
echo "== Secure Boot is enabled: signing =="
|
|
if [ ! -r "$MOK_PRIV" ] && ! sudo test -r "$MOK_PRIV"; then
|
|
echo "ABORT: Secure Boot is on and no MOK private key at $MOK_PRIV." >&2
|
|
echo " Unsigned modules will not load; the box would come up GPU-less." >&2
|
|
echo " Create one (e.g. 'sudo update-secureboot-policy --new-key') or set MOK_PRIV/MOK_DER." >&2
|
|
exit 1
|
|
fi
|
|
if ! mok_enrolled; then
|
|
echo "ABORT: $MOK_DER is not enrolled in the firmware; signed modules would still be rejected." >&2
|
|
echo " Run: sudo mokutil --import $MOK_DER ; reboot ; 'Enroll MOK' in MokManager. Then rerun." >&2
|
|
exit 1
|
|
fi
|
|
for ko in "${KO_FILES[@]}"; do
|
|
sudo "$SIGN_FILE" sha256 "$MOK_PRIV" "$MOK_DER" "$ko"
|
|
modinfo -F signer "$ko" | grep -q . || { echo "ABORT: signing $ko failed" >&2; exit 1; }
|
|
done
|
|
fi
|
|
|
|
echo "== unload =="
|
|
PERSISTENCED_WAS_ACTIVE=0
|
|
if systemctl is-active --quiet nvidia-persistenced 2>/dev/null; then
|
|
PERSISTENCED_WAS_ACTIVE=1
|
|
fi
|
|
sudo systemctl stop nvidia-persistenced 2>/dev/null || true
|
|
for f in /dev/nvidia[0-9]* /dev/nvidiactl /dev/nvidia-uvm /dev/nvidia-modeset; do
|
|
if mountpoint -q "$f" 2>/dev/null; then sudo umount "$f" 2>/dev/null || true; fi
|
|
done
|
|
if [ -d /sys/bus/pci/drivers/nvidia_rs ]; then
|
|
for dev in /sys/bus/pci/drivers/nvidia_rs/[0-9a-f][0-9a-f][0-9a-f][0-9a-f]:*; do
|
|
[ -e "$dev" ] || continue
|
|
echo "$(basename "$dev")" | sudo tee /sys/bus/pci/drivers/nvidia_rs/unbind >/dev/null 2>&1 || true
|
|
done
|
|
fi
|
|
if [ "$UNLOAD_STOCK" = "1" ]; then
|
|
for m in nvidia_drm nvidia_modeset nvidia_uvm nvidia; do
|
|
# Stock DRM/modeset modules can remain pinned by fbdev/DRM registration with no /dev/nvidia* holders (#178);
|
|
# unload base nvidia last (#133, #177) and tolerate rmmod failure so install can proceed cleanly.
|
|
module_list=$(lsmod)
|
|
if grep -q "^$m " <<<"$module_list"; then
|
|
if [ "$CONFIGURE_MODPROBE" = "1" ]; then
|
|
sudo rmmod "$m" 2>/dev/null || echo "WARN: stock $m is still pinned; modprobe blacklist will keep it out after reboot." >&2
|
|
else
|
|
sudo rmmod "$m" 2>/dev/null || echo "WARN: stock $m is still pinned; CONFIGURE_MODPROBE=0, so configure a modprobe blacklist separately to keep it out after reboot." >&2
|
|
fi
|
|
fi
|
|
done
|
|
else
|
|
echo "Keeping stock NVIDIA modules loaded (UNLOAD_STOCK=0 / side-by-side mode)."
|
|
fi
|
|
for m in nvidia_rs_drm nvidia_rs_modeset nvidia_rs_peermem nvidia_rs_modeset_bridge nvidia_rs_uvm_bridge nvidia_rs; do
|
|
# A short-circuiting grep can give lsmod SIGPIPE under pipefail.
|
|
module_list=$(lsmod)
|
|
if grep -q "^$m " <<<"$module_list"; then sudo rmmod "$m"; fi
|
|
done
|
|
module_list=$(lsmod)
|
|
if grep -q '^nvidia_rs ' <<<"$module_list"; then
|
|
echo "ABORT: nvidia_rs is still loaded (something holds /dev/nvidia*). Stop GPU users and rerun." >&2
|
|
echo " sudo fuser -v /dev/nvidia*" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "== install =="
|
|
# Auto-extract packed pre-GSP firmware (GV100 / Maxwell / Pascal) from the local
|
|
# 580.178.04 nv-kernel.o_binary when present, so first-open bring-up works out of the box.
|
|
if [ "$EXTRACT_FIRMWARE" = "1" ] && [ -f tools/extract_gv100_firmware.py ]; then
|
|
if [ ! -f target/firmware/nvidia-rs/580.178.04/gv100.fw ]; then
|
|
for cand in \
|
|
/usr/src/nvidia-srv-580.178.04/nvidia/nv-kernel.o_binary \
|
|
/usr/src/nvidia-580.178.04/nvidia/nv-kernel.o_binary \
|
|
/usr/src/nvidia*/nvidia/nv-kernel.o_binary; do
|
|
if [ -r "$cand" ]; then
|
|
echo "Extracting pre-GSP firmware packs (GV100 + Maxwell/Pascal) from $cand ..."
|
|
python3 tools/extract_gv100_firmware.py --rm-object "$cand" --family all || \
|
|
echo "WARN: firmware extraction from $cand did not match 580.178.04 digest; continuing." >&2
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
fi
|
|
# Install any extracted ROM/firmware packs (tools/extract_gv100_firmware.py writes
|
|
# under target/firmware) so first-open PMU/SEC2 bring-up finds them.
|
|
if [ -d target/firmware/nvidia-rs ]; then
|
|
for fw in target/firmware/nvidia-rs/*/*.fw; do
|
|
[ -e "$fw" ] || continue
|
|
rel=${fw#target/firmware/}
|
|
sudo install -d -m 0755 "/lib/firmware/$(dirname "$rel")"
|
|
sudo install -m 0644 "$fw" "/lib/firmware/$rel"
|
|
done
|
|
fi
|
|
# Copy GSP firmware blobs into /lib/firmware/nvidia/<ver>/ if found under /usr/src/nvidia*
|
|
# and not already installed.
|
|
for fwdir in /usr/src/nvidia*/firmware; do
|
|
[ -d "$fwdir" ] || continue
|
|
for gsp in "$fwdir"/gsp_*.bin; do
|
|
[ -r "$gsp" ] || continue
|
|
ver=$(basename "$(dirname "$fwdir")" | sed -E 's/^nvidia(-srv)?-//')
|
|
if [ -n "$ver" ] && [ ! -f "/lib/firmware/nvidia/$ver/$(basename "$gsp")" ]; then
|
|
sudo install -d -m 0755 "/lib/firmware/nvidia/$ver"
|
|
sudo install -m 0644 "$gsp" "/lib/firmware/nvidia/$ver/$(basename "$gsp")"
|
|
fi
|
|
done
|
|
done
|
|
# Warn early when a host has non-580 stock GSP firmware (e.g. 595/620) but lacks the
|
|
# 580.178.04 / 580.196.07 GSP-RM blobs required by default ga10x_gsp=1 (#501).
|
|
if [ ! -f /lib/firmware/nvidia/580.178.04/gsp_ga10x.bin ] && \
|
|
[ ! -f /lib/firmware/nvidia/580.196.07/gsp_ga10x.bin ]; then
|
|
other_gsp=$(ls /lib/firmware/nvidia/*/gsp_ga10x.bin 2>/dev/null | head -n 1 || true)
|
|
if [ -n "$other_gsp" ]; then
|
|
echo "WARN: /lib/firmware/nvidia/580.178.04/gsp_ga10x.bin not found (only found $other_gsp)." >&2
|
|
echo " Do NOT copy a 595/620 blob into 580.178.04/; extract genuine 580.178.04 gsp_ga10x.bin" >&2
|
|
echo " (or gsp_tu10x.bin for Turing/GA100) from NVIDIA-Linux-x86_64-580.178.04.run." >&2
|
|
fi
|
|
fi
|
|
sudo install -d -m 0755 "$INSTALL_DIR"
|
|
for ko in "${KO_FILES[@]}"; do
|
|
sudo install -m 0644 "$ko" "$INSTALL_DIR/"
|
|
done
|
|
sudo depmod -a "$KREL"
|
|
|
|
if [ "$CONFIGURE_MODPROBE" = "1" ]; then
|
|
echo "== configure modprobe & autoload =="
|
|
{
|
|
cat <<'EOF'
|
|
# Managed by nvdriver ./install.sh (set CONFIGURE_MODPROBE=0 to opt out)
|
|
blacklist nouveau
|
|
blacklist nvidia
|
|
blacklist nvidia_drm
|
|
blacklist nvidia_modeset
|
|
blacklist nvidia_uvm
|
|
install nvidia /bin/false
|
|
install nvidia_drm /bin/false
|
|
install nvidia_modeset /bin/false
|
|
install nvidia_uvm /bin/false
|
|
alias char-major-195-* nvidia_rs
|
|
EOF
|
|
printf 'options nvidia_rs %s\n' "$MODPROBE_ARGS"
|
|
if [ "$LOAD_DESKTOP_KMS" = "1" ] && [ "$HAS_DRM_KO" = "1" ]; then
|
|
echo "options nvidia_rs_drm modeset=1"
|
|
fi
|
|
} | sudo tee /etc/modprobe.d/nvdriver.conf >/dev/null
|
|
{
|
|
echo "nvidia_rs"
|
|
if [ "$LOAD_DESKTOP_KMS" = "1" ]; then
|
|
if [ "$HAS_MODESET_KO" = "1" ]; then
|
|
echo "nvidia_rs_modeset"
|
|
fi
|
|
if [ "$HAS_DRM_KO" = "1" ]; then
|
|
echo "nvidia_rs_drm"
|
|
fi
|
|
fi
|
|
if [ "$BUILD_BRIDGES" = "1" ]; then
|
|
echo "nvidia_rs_uvm_bridge"
|
|
echo "nvidia_rs_modeset_bridge"
|
|
fi
|
|
} | sudo tee /etc/modules-load.d/nvdriver.conf >/dev/null
|
|
fi
|
|
|
|
if [ "$CONFIGURE_UDEV" = "1" ]; then
|
|
echo "== configure udev permissions (real bind-mounted /dev/nvidia* nodes via systemd) =="
|
|
sudo tee /etc/udev/rules.d/70-nvdriver.rules >/dev/null <<'EOF'
|
|
# Managed by nvdriver ./install.sh (set CONFIGURE_UDEV=0 to opt out)
|
|
# Note: /dev/nvidia* symlinks are intentionally omitted because nvidia-ctk cdi generate skips
|
|
# symlinks (#158); nvdriver-devnodes.service creates real bind mounts at boot.
|
|
# /dev/char/195:* symlinks are published so NVML char-major-195 lookups succeed (#178).
|
|
KERNEL=="nvidia-rs-rmapi-ctl", MODE="0666", SYMLINK+="char/195:255"
|
|
KERNEL=="nvidia-rs-uvm", MODE="0666", SYMLINK+="char/504:0"
|
|
KERNEL=="nvidia-rs-modeset", MODE="0666", SYMLINK+="char/195:254"
|
|
KERNEL=="nvidia-rs-rmapi-gpu[0-9]*", MODE="0666", SYMLINK+="char/195:%n"
|
|
# Standalone DRM KMS/render nodes exposed by nvidia_rs_drm
|
|
SUBSYSTEM=="drm", KERNEL=="card[0-9]*", DRIVERS=="nvidia_rs", MODE="0660"
|
|
SUBSYSTEM=="drm", KERNEL=="renderD[0-9]*", DRIVERS=="nvidia_rs", MODE="0666"
|
|
SUBSYSTEM=="drm", KERNEL=="card[0-9]*|renderD[0-9]*", DRIVERS=="nvidia_rs", TEST!="/etc/udev/rules.d/62-nvdriver-dev.rules", TEST!="/run/udev/rules.d/62-nvdriver-dev.rules", TAG+="uaccess"
|
|
EOF
|
|
sudo udevadm control --reload-rules 2>/dev/null || true
|
|
fi
|
|
|
|
if [ "$BIND_DEV_NODES" = "1" ] && command -v systemctl >/dev/null 2>&1; then
|
|
echo "== install boot-time /dev/nvidia* bind-mount service (Docker/CDI compatible) =="
|
|
sudo install -m 0755 tools/bind_dev_nodes.sh /usr/local/sbin/nvdriver-bind-dev-nodes
|
|
sudo tee /etc/systemd/system/nvdriver-devnodes.service >/dev/null <<'EOF'
|
|
[Unit]
|
|
Description=Bind-mount nvidia_rs character devices onto /dev/nvidia*
|
|
After=systemd-modules-load.service systemd-udev-trigger.service
|
|
Before=docker.service containerd.service nvidia-cdi-refresh.service nvidia-persistenced.service
|
|
|
|
[Service]
|
|
Type=oneshot
|
|
RemainAfterExit=yes
|
|
ExecStartPre=/bin/sh -c 'for i in $(seq 1 60); do [ -c /dev/nvidia-rs-rmapi-ctl ] && exit 0; sleep 1; done; exit 1'
|
|
ExecStart=/usr/local/sbin/nvdriver-bind-dev-nodes --bind
|
|
ExecStop=/usr/local/sbin/nvdriver-bind-dev-nodes --unbind
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
sudo systemctl daemon-reload 2>/dev/null || true
|
|
sudo systemctl enable nvdriver-devnodes.service 2>/dev/null || true
|
|
|
|
# If NVIDIA Container Toolkit's nvidia-cdi-refresh.service is present, ensure the
|
|
# generated CDI spec includes a read-only /dev/char bind mount so NVML inside
|
|
# containers can resolve misc-major nvidia_rs nodes (#159).
|
|
if systemctl list-unit-files nvidia-cdi-refresh.service 2>/dev/null | grep -q nvidia-cdi-refresh; then
|
|
if ! python3 -c 'import yaml' >/dev/null 2>&1; then
|
|
echo "WARN: NVIDIA CDI integration requires PyYAML for python3. Install it and restart nvidia-cdi-refresh.service." >&2
|
|
fi
|
|
sudo install -m 0755 tools/patch_cdi.py /usr/local/sbin/nvdriver-cdi-patch
|
|
sudo install -d -m 0755 /etc/systemd/system/nvidia-cdi-refresh.service.d
|
|
sudo tee /etc/systemd/system/nvidia-cdi-refresh.service.d/10-nvdriver-dev-char.conf >/dev/null <<'EOF'
|
|
[Unit]
|
|
After=nvdriver-devnodes.service
|
|
[Service]
|
|
ExecStartPost=-/usr/local/sbin/nvdriver-cdi-patch /var/run/cdi/nvidia.yaml
|
|
EOF
|
|
sudo systemctl daemon-reload 2>/dev/null || true
|
|
fi
|
|
fi
|
|
|
|
echo "== reload =="
|
|
# shellcheck disable=SC2086
|
|
sudo modprobe nvidia_rs $MODPROBE_ARGS
|
|
if [ "$LOAD_DESKTOP_KMS" = "1" ]; then
|
|
if [ "$HAS_MODESET_KO" = "1" ]; then
|
|
sudo modprobe nvidia_rs_modeset
|
|
fi
|
|
if [ "$HAS_DRM_KO" = "1" ]; then
|
|
sudo modprobe nvidia_rs_drm modeset=1
|
|
fi
|
|
fi
|
|
if [ "$BUILD_BRIDGES" = "1" ]; then
|
|
sudo modprobe nvidia_rs_uvm_bridge || true
|
|
sudo modprobe nvidia_rs_modeset_bridge || true
|
|
fi
|
|
if [ "$BIND_DEV_NODES" = "1" ]; then
|
|
if [ -d /sys/module/nvidia ]; then
|
|
# bind_dev_nodes.sh refuses to cover the stock driver's nodes; failing here under set -e would skip
|
|
# the verify step after the host configuration above has already been written.
|
|
echo "WARN: stock nvidia is still loaded; /dev/nvidia* not bound now; nvdriver-devnodes.service binds them on the next boot, once the blacklist keeps stock nvidia out." >&2
|
|
echo " On a host that keeps stock nvidia for another GPU, run ./uninstall.sh (or remove /etc/modprobe.d/nvdriver.conf and disable nvdriver-devnodes.service) before rerunning with BIND_DEV_NODES=0 CONFIGURE_MODPROBE=0." >&2
|
|
else
|
|
sudo bash tools/bind_dev_nodes.sh --bind
|
|
fi
|
|
fi
|
|
|
|
echo "== verify =="
|
|
loaded=$(modinfo -n nvidia_rs)
|
|
built_src=$(modinfo -F srcversion kernel-open/nvidia_rs.ko)
|
|
loaded_src=$(cat /sys/module/nvidia_rs/srcversion 2>/dev/null || true)
|
|
echo "module file: $loaded"
|
|
echo "built srcversion: $built_src, loaded: $loaded_src"
|
|
[ -n "$loaded_src" ] && [ "$built_src" = "$loaded_src" ] || {
|
|
echo "ABORT: loaded nvidia_rs srcversion differs from freshly built module" >&2
|
|
exit 1
|
|
}
|
|
echo "nvdriver installed and verified."
|
|
if [ "$PERSISTENCED_WAS_ACTIVE" = "1" ]; then
|
|
sudo systemctl start nvidia-persistenced 2>/dev/null || echo "WARN: nvidia-persistenced did not restart; check 'systemctl status nvidia-persistenced'." >&2
|
|
fi
|
|
|
|
install_volta_forever
|