You are not logged in.

#1 2016-12-19 10:48:15

tomsk
Member
Registered: 2016-12-17
Posts: 170

Unbind GPU while system is running

Is possible (any method) to switch between Graphics Cards while system is running? And than disabled card bind to KVM/QEMU?

I have 2 GPUs (1x Intel HD 4600 and 1x NVIDIA GeForce 1060)

I would like to have virtual Windows 7 using KVM with GPU passthrough.

Intel Graphics for Linux (host) NVIDIA for Windows 7 (guest)

I know that i have to set stub for NVIDIA.

I would like to have primary GPU Intel Graphics and use sometimes NVIDIA card using Bumblebee (nvidia optimus).

But problem is that then i cant bind NVIDIA card to virtual machine. Is possible to unbind drivers while system is running? I dont think it is problem, because X server is using primary iGPU (Intel Graphics, not NVIDIA)

Thank you very much

PS: I have a desktop


I use several linux distros like: Archlinux, Ubuntu, Fedora, Linux Mint

Offline

#2 2016-12-19 12:40:36

Omar007
Member
Registered: 2015-04-09
Posts: 368

Re: Unbind GPU while system is running

If the GPU is not used by X, I think it should be possible. (I know from experience that with X using said GPU, your system will freeze tongue )

What I have used myself to unbind the driver was:

echo $dev > /sys/bus/pci/devices/$dev/driver/unbind

I executed this twice, where (for me) $dev was 0000:02:00.0 (the 2nd nVidia GPU in my system) with the first execution and 0000:02:00.1 (the GPU's audio) for the second.

You should be able to rebind it afterwards with

echo $dev > /sys/bus/pci/drivers/nvidia/bind

for the GPU and

echo $dev > /sys/bus/pci/drivers/snd_hda_intel/bind

for the audio component of the GPU.


If you're using libvirt to manage your VM it should be able to handle things for you automatically. Note that I have not used this much so from memory I can only say it managed to detach it from the host and attach it to the VM. I can't remember if it re-attached it to the host when the VM was shut down.

Last edited by Omar007 (2016-12-19 12:47:30)

Offline

#3 2016-12-19 13:15:21

tomsk
Member
Registered: 2016-12-17
Posts: 170

Re: Unbind GPU while system is running

So

echo $dev > /sys/bus/pci/devices/$dev/driver/unbind

Does the same job like pci-stub?


I use several linux distros like: Archlinux, Ubuntu, Fedora, Linux Mint

Offline

#4 2016-12-19 15:52:04

Omar007
Member
Registered: 2015-04-09
Posts: 368

Re: Unbind GPU while system is running

Not exactly; pci-stub binds in place of the nVidia driver so the nVidia driver has no chance to bind to the device, whereas with the above command the nVidia driver did bind with the GPU and you manually unbind it.
The end result is the same though; you have a GPU that can be freely used inside a VM.

Last edited by Omar007 (2016-12-19 15:52:56)

Offline

#5 2016-12-20 10:31:26

tomsk
Member
Registered: 2016-12-17
Posts: 170

Re: Unbind GPU while system is running

It must be nvidia opensource driver or proprietary driver? smile Or it doesn't matter? smile


I use several linux distros like: Archlinux, Ubuntu, Fedora, Linux Mint

Offline

#6 2016-12-20 11:37:56

mich41
Member
Registered: 2012-06-22
Posts: 796

Re: Unbind GPU while system is running

Unbinding works on every driver, you can even boot with pci-stub bound to some device and later unbind pci-stub and bind nvidia. Or switch from nvidia to nouveau and back - as long as the device isn't being used at the moment. There is also analogous functionality on USB devices and possibly others.

Offline

Board footer

Powered by FluxBB