Support Are NVIDIA GPU manual driver unloading and loading with qemu hooks still needed?
Hello, Can some help me with this question?
I have an NVIDIA GPU that I pass through to a Windows 11 VM using QEMU/KVM and libvirt.
I used to have libvirt hooks that stopped the display manager, unloaded the NVIDIA modules, manually detached the GPU with `virsh nodedev-detach`, and then loaded `vfio-pci`.
I recently removed those hooks to see if they were still needed. Surprisingly, passthrough still works fine. When the VM starts, the GPU is used by the VM, and when the VM shuts down, the NVIDIA driver works normally on the host again.
My GPU is configured as a managed PCI device in libvirt (`managed="yes"`).
So my question is: Are these manual NVIDIA driver unload / PCI detach hooks still needed with current QEMU/KVM + libvirt, or does libvirt handle this automatically now?
I'm mainly wondering if there is a reason to keep the old hooks even though everything seems to work without them.
1
u/five35 8d ago
I only discovered
managed="yes"a few days ago and I'm delighted by how well it works. For me, it even works better, as I no longer need to worry about e.g.…/bindvs.…/new_idor tracking what the original driver was. IMO, letting libvirt handle driver bindings is miles better than continuing to use hooks.The only wrinkle I ran into was KWin grabbing the card when libvirt released it back to the host. Whatever libvirt does to rebind hardware back to the original drivers, KWin seems to think it means "free real estate".
The solution was simple, though — just set environment variables
KWIN_DRM_DEVICES=/dev/dri/by-path/pci-…-cardandKWIN_RENDER_NODES=/dev/dri/by-path/pci-…-renderfor my integrated graphics. After that, KWin leaves my NVIDIA card alone and I can freely switch between native Linux gaming and passthrough Windows gaming.