3

i have two Radeon GPUs (AMD R9 290 and AMD HD7870) i want to unbind the R9 290 from the radeon driver and hand over it to QEMUs VFIO-PCI driver. I'm using these commands:

echo 0000:06:00.0 > /sys/bus/pci/drivers/radeon/unbind
echo 1002 67b1 > /sys/bus/pci/drivers/vfio-pci/new_id
echo 0000:06:00.1 > /sys/bus/pci/drivers/snd_hda_intel/unbind
echo 1002 aac8 > /sys/bus/pci/drivers/vfio-pci/new_id

but my system freez after 5 seconds. I dont want bind the GPU to pci-stub because want to use two screens before i starting the VM. Like in this video: https://www.youtube.com/watch?v=17qxEpn4EGs

Can someone help me?

Best Regards

2 Answers 2

2

I am currently using this, it requires a lightdm restart though. Execute it from a different tty console, not within the lightdm session itself.

(CTRL+ALT+F# for a console, F7 is normally the xsession)

#!/bin/bash

read -n3 -rsp "Restart lightdm to unbind the GPU? [yes] " res
test "$res" != 'yes' && exit 1
echo

sudo service lightdm stop
sudo echo "1002 683d" > /sys/bus/pci/drivers/vfio-pci/new_id
sudo echo "1002 aab0" > /sys/bus/pci/drivers/vfio-pci/new_id
sudo echo "0000:01:00.0" > /sys/bus/pci/devices/0000:01:00.0/driver/unbind
sudo echo "0000:01:00.1" > /sys/bus/pci/devices/0000:01:00.1/driver/unbind
sudo echo "0000:01:00.0" > /sys/bus/pci/drivers/vfio-pci/bind
sudo echo "0000:01:00.1" > /sys/bus/pci/drivers/vfio-pci/bind
sudo echo "1002 683d" > /sys/bus/pci/drivers/vfio-pci/remove_id
sudo echo "1002 aab0" > /sys/bus/pci/drivers/vfio-pci/remove_id
sudo service lightdm start

echo "Rebind Audio"
sudo modprobe pci_stub
sudo echo "8086 8ca0" > /sys/bus/pci/drivers/pci-stub/new_id
sudo echo "0000:00:1b.0" > /sys/bus/pci/drivers/snd_hda_intel/unbind
sudo echo "0000:00:1b.0" > /sys/bus/pci/drivers/pci-stub/bind
sudo echo "8086 8ca0" > /sys/bus/pci/drivers/pci-stub/remove_id

# Check if VM drive is mounted
if ! grep -qs '/media/ljosalfur/VM' /proc/mounts; then
echo "Attempting to mount VM drive. I don't know how though."
#sudo mkdir /media/ljosalfur/VM
#sudo mount /dev/disk/by-id/0BD253F0-EF7F-6F40-BDD8-FABF85161762 /media/ljosalfur/VM
fi

sudo kvm -monitor stdio -vnc :0 \
-m 6G -mem-path /dev/hugepages \
-drive if=pflash,format=raw,file=./OVMF.fd -rtc base=localtime \
-cpu host -smp 6,sockets=1,cores=6,threads=1 \
-device vfio-pci,host=01:00.0,multifunction=on,x-vga=on \
-device vfio-pci,host=01:00.1 \
-device pci-assign,host=00:1b.0 \
-drive file=/media/ljosalfur/VM/vm7.img,format=raw,cache=writethrough \
-smb /media/ljosalfur \
-usb -usbdevice host:046d:c24a -show-cursor \
-usb -usbdevice host:1b1c:1b08

echo
echo "Re-Rebind Audio"
sudo echo "0000:00:1b.0" > /sys/bus/pci/drivers/pci-stub/unbind
sudo echo "0000:00:1b.0" > /sys/bus/pci/drivers/snd_hda_intel/bind

echo "Unbind GPU from vfio-pci"
sudo echo "0000:01:00.0" > /sys/bus/pci/drivers/vfio-pci/unbind
sudo echo "0000:01:00.1" > /sys/bus/pci/drivers/vfio-pci/unbind

read -n3 -rsp "Restart lightdm to rebind the GPU? [yes] " ress
test "$ress" != 'yes' && (exit 1)
echo
sudo echo "0000:01:00.0" > /sys/bus/pci/drivers/radeon/bind

I am looking for a workaround as restarting lightdm is not favourable, I think I will open a new question with different tags for this.

1
  • sudo echo XXX > file doesn't write to a file as root. What you want is echo XXX | sudo tee file to actually write as root.
    – Eric
    Jul 18, 2019 at 11:57
0

I wouldn't suggest you to do it like shown in the video. I bound it my graphics card to pci-stub driver in grub kernel parameters and plugged a second mouse and a second HDMI cable in my computer and switch the source on my monitor.

So here is my start script.

qemu-system-x86_64 -enable-kvm -m 10240 -cpu host,kvm=off \
-smp 4,sockets=1,cores=4,threads=1 \
-bios /home/qemu/.qemu/bios/ovmf.bin \
-soundhw hda \`
-usb -usbdevice host:046d:c53b \
-rtc base=localtime \
-hda /home/qemu/.qemu/boot/Windows8_1pro.img \
-hdb /home/qemu/.qemu/hdd/HDD1.img \
-device vfio-pci,host=01:00.0 -device vfio-pci,host=01:00.1 \
-vga none \`
3
  • At the moment i use the same solution, but i want to change. Jun 27, 2015 at 14:03
  • @BlackYDeath Well okay I'm sorry than I can't answer yout question. If I may ask you something: Are you running qemu as root or as normal user?
    – Marton
    Jun 27, 2015 at 14:06
  • I running QEMU as root Jun 27, 2015 at 14:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .