You are not logged in.

#1 2017-12-14 01:32:28

codedcosmos
Member
Registered: 2017-09-25
Posts: 11

Is it possible to pass GPU to VM and back without restart?

Im using vfio-pci and the 4.14.3-1-zen kernel, on a ryzen 1700 with a motherboard that has sufficient iommu groups for this kind of virtualization. The problem is I only have one "good" gpu and one "reasonable" gpu and as such dont want to completely dedicate the good gpu to passthrough all the time as I perfer to play most of my games on linux, but do wish to play a few windows games on that same gpu. As the second gpu can't really handle the few games I want to play on windows.

I have heard that it is technically possible to do this and pass the gpu dynamically between host/guest (https://arseniyshestakov.com/2016/03/31/how-to-pass-gpu-to-vm-and-back-without-x-restart/ and a few other places I can't find). However these posts are rather old and mention that it is impossible with amdgpu. Have things changed within the last year. Im on mid range but bleeding edge software/hardware and im curious if this is able to be done.

In short how do you toggle vfio-pci to use the same gpu for both the vm and guest. Obviously not all at once but dynamically.

Hardware:
GPU1: r7-240 (slow gpu)
GPU2: Asus strix 570 (good gpu)
MOBO: Asus prime-b350 PLUS
CPU: Ryzen 7 1700
RAM: 8Gb

Offline

#2 2017-12-15 16:56:43

shql
Member
Registered: 2011-02-18
Posts: 3

Re: Is it possible to pass GPU to VM and back without restart?

to unload the amdgpu driver you probably need https://git.kernel.org/pub/scm/linux/ke … 90f94ba29b

other than that it should work ok.

to get the driver to unload you can do something like this

echo 0 > /sys/devices/virtual/vtconsole/vtcon1/bind
rmmod amdgpu

now you can get it to vfio

echo "vfio-pci" > /sys/bus/pci/devices/0000:01:00.0/driver_override
echo 0000:01:00.0 > /sys/bus/pci/drivers/vfio-pci/bind

and from there back again

echo "amdgpu" > /sys/bus/pci/devices/0000:01:00.0/driver_override
echo 0000:01:00.0 > /sys/bus/pci/drivers/vfio-pci/0000:01:00.0/driver/unbind
modprobe amdgpu

obviously replace the values with your own

Offline

#3 2017-12-15 17:50:48

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: Is it possible to pass GPU to VM and back without restart?

I do remember someone who used dynamic binding like that on a system with one gpu with reasonable success.
(it may even have been in a thread on this board i particpated in).

possible  : yes
will your host / guest OSes remain stable after switching : questionable

Last edited by Lone_Wolf (2017-12-15 17:51:11)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#4 2017-12-15 17:59:51

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: Is it possible to pass GPU to VM and back without restart?

Lone_Wolf wrote:

will your host / guest OSes remain stable after switching : questionable

It should work better if the intel gpu is your primary for xorg and you only use the amd gpu with DRI_PRIME=1. And only change the GPU assignment while the virtual machine is stopped.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

Board footer

Powered by FluxBB