Prime-run / PCIE passthrough transition

Hello Everyone,

I run on my desktop a Windows VM with Looking-Glass and a GTX1080, while the Host (Arch Linux) uses a RX550 as a display output. That works just fine.

When I don’t need the VM I can run games on the GTX using prime-run. That works just fine as well (even though I don’t have a Igpu).

However, the transition from one mode to the other is not very consistent.
I wrote a small script, which removes the vfio-pcie module, loads the nvidia module, and restarts sddm (effectively the x-server):

#!/bin/bash
sudo -s <<EOF
    modprobe -r vfio-pci 
    echo 1 > /sys/bus/pci/devices/0000:27:00.0/remove
    echo 1 > /sys/bus/pci/devices/0000:27:00.1/remove
    echo 1 > /sys/bus/pci/rescan
EOF
export DISPlAY=:0
qdbus org.kde.ksmserver /KSMServer logout 0 0 0 
sleep 2
sudo -s << EOF
    modprobe  nvidia
    sleep 1
    systemctl restart sddm
EOF

the problem is that sddm does not automatically log me in again, and for some reason only shows up with a black screen an the courser (at least every other sddm release). I tried to troubleshoot that problem many times and decided it is easier to tick the autologin box.

Does anyone know if there is a better solution, which does not involve restarting the x-server?
I can load the proper module without the need to log out or restart the x-server, however prime run only works after the restart.

Or any Ideas what I can try to fix sddm for good?

I’ve been using optimus-manager on Arch to switch GPUs (albeit, just to switch iGPU to GPU on a Thinkpad so not exactly the same use case). However, optimus-manager also suffers from the same issue you’re describing so take a look at the troubleshooting tips in their FAQ and see if anything stands out.

I’ve been using optimus-manager as well (before prime-run was released).
The difference is that optimus will render everything on either the igpu or the dgpu, which requires a restart of the x-server. Prime-run only renders selected programs on the dgpu and everything else on the igpu, which does not require a restart.

My problem is more like hot-plugging a GPU. While the VM is running the x-server has no way of knowing that there even is a dgpu. Once I shut down the VM and load the proper module for the dgpu the x-server could use it for the prime-render-offload but it doesn’t. My guess is that I need to tell the x-server that there is in fact a dgpu in the system. (currently I do that by restarting the server, that way it will figure that out itself)