解除 Radeon 绑定 > 移交给 VFIO-PCI

解除 Radeon 绑定 > 移交给 VFIO-PCI

我有两个 Radeon GPU(AMD R9 290 和 AMD HD7870),我想将 R9 290 从 Radeon 驱动程序中解除绑定,并将其移交给 QEMU 的 VFIO-PCI 驱动程序。我使用以下命令:

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

但我的系统在 5 秒后就冻结了。我不想绑定 GPU,pci-stub因为我想在启动 VM 之前使用两个屏幕。就像在这个视频中一样:https://www.youtube.com/watch?v=17qxEpn4EGs

有人能帮我吗?

此致

答案1

我目前正在使用这个,但它需要重启 lightdm。从不同的 tty 控制台执行它,而不是在 lightdm 会话本身内执行。

(CTRL+ALT+F# 用于控制台,F7 通常是 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

我正在寻找一种解决方法,因为重新启动 lig​​htdm 并不理想,我想我将为此提出一个带有不同标签的新问题。

答案2

我不建议你像视频中那样做。我在 grub 内核参数中将我的显卡绑定到 pci-stub 驱动程序,并在我的电脑上插入第二个鼠标和第二根 HDMI 电缆,然后切换显示器上的源。

这是我的启动脚本。

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 \`

相关内容