BigAnteater / KVM-GPU-Passthrough

This is a simple, mostly automated guide to pass a GPU through to a VM.
314 stars 27 forks source link

Fix for nvdia driver not being unloaded #40

Open polaco1782 opened 1 year ago

polaco1782 commented 1 year ago

This patch fixes an issue introduced with latest nvidia driver, there is a daemon which keeps a socket open to the driver, thus making it impossible to unload them. I also enforced a loop to make sure all modules were unloaded.

--- hooks/vfio-startup.sh   2023-05-07 20:09:39.931155434 -0300
+++ /usr/bin/vfio-startup.sh    2023-05-07 22:39:20.973968263 -0300
@@ -122,14 +122,19 @@ if lspci -nn | grep -e VGA | grep -s NVI
     grep -qsF "true" "/tmp/vfio-is-nvidia" || echo "true" >/tmp/vfio-is-nvidia
     echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind

-    ## Unload NVIDIA GPU drivers ##
-    modprobe -r nvidia_uvm
-    modprobe -r nvidia_drm
-    modprobe -r nvidia_modeset
-    modprobe -r nvidia
-    modprobe -r i2c_nvidia_gpu
-    modprobe -r drm_kms_helper
-    modprobe -r drm
+    systemctl stop nvidia-persistenced.service
+
+    for i in {1..10}
+    do
+      ## Unload NVIDIA GPU drivers ##
+      modprobe -r nvidia_uvm
+      modprobe -r nvidia_drm
+      modprobe -r nvidia_modeset
+      modprobe -r nvidia
+      modprobe -r i2c_nvidia_gpu
+      modprobe -r drm_kms_helper
+      modprobe -r drm
+    done

     echo "$DATE NVIDIA GPU Drivers Unloaded"
 fi
searinminecraft commented 1 year ago

creating a pr would have been much better