LINUX.ORG.RU

проброс видеокарты в qemu

 , ,


0

1

я пытался пробросить видеокарту в qemu(8.0.3) запуская его через консоль вот такой скрипт у меня получился:

#!/bin/bash

#<===[default value]===>

DISC=1 # 0: test(install: kubuntu) | 1: windows(install)
NEW_SYS=0 # 0: no | 1: kubuntu | 2: windows
NEW_SYS_STR=""

#<===[stettings]===>

if [ -v 1 ]; then
    DISC=$1
fi

if [ -v 2 ]; then
    NEW_SYS=$2
fi

if (($DISC == 0)); then
    DISC_STR="virtual-disc-50G.img"
elif (($DISC == 1)); then
    DISC_STR="virtual-disc-50G-windows.img"
fi

if (($NEW_SYS == 1)); then
    NEW_SYS_STR="-boot d -cdrom $HOME/Downloads/kubuntu-22.04-desktop-amd64.iso"
elif (($NEW_SYS == 2)); then
    NEW_SYS_STR="-boot d -cdrom $HOME/Downloads/windows_22H2_or_21H2_x64/windows_22H2_or_21H2_x64.iso"
fi

#<===[start]===>

rm -rf ./qemu-output.txt

qemu-start () {
    qemu-system-x86_64 \
    -name andrewkoro105 \
    -machine accel=kvm \
    -enable-kvm \
    -cpu host \
    -smp 4 \
    -m 8G \
    -hda ${DISC_STR} \
    ${NEW_SYS_STR} \
    -device vfio-pci,host=04:00.0 \
    -device vfio-pci,host=04:00.1 \
    2> qemu-output.txt
}
qemu-start &

sleep 1

if [ ! -s ./qemu-output.txt ]; then
    xdotool key Super+b
    xdotool key Super+m
    xdotool key ctrl+alt+m
else
    echo "< ./qemu-output.txt >"
    cat ./qemu-output.txt
fi

при запуске у меня вылетает ошибка:

qemu-system-x86_64: -device vfio-pci,host=04:00.0: vfio 0000:04:00.0: group 0 is not viable
Please ensure all devices within the iommu_group are bound to their vfio bus driver.

Если что без проброса видеокарты всё работает отлично.

В ошибке сказано что нужно всем устройствам указать драйвер vfio но судя по выводу lspci -nnk далеко не у всем нужны драйвера, возможно это связано с тем сто видеокарта находится в iommu группе 0 в которой почему то много устройств (например моя основная видеокарта находится в группе 2 в которой всего 4 устройства).

На всякий случай держите список устройств в группе 0:

0000:00:01.0  0000:00:01.2  0000:02:00.0  0000:02:00.2  0000:03:04.0  0000:03:07.0  0000:03:09.0  0000:04:00.1  0000:09:00.0 0000:00:01.1  0000:01:00.0  0000:02:00.1  0000:03:00.0  0000:03:06.0  0000:03:08.0  0000:04:00.0  0000:05:00.0

и вывод команды lspci -nnk:

00:00.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse Root Complex [1022:1480]
	Subsystem: Advanced Micro Devices, Inc. [AMD] Starship/Matisse Root Complex [1022:1480]
00:00.2 IOMMU [0806]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse IOMMU [1022:1481]
	Subsystem: Advanced Micro Devices, Inc. [AMD] Starship/Matisse IOMMU [1022:1481]
00:01.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge [1022:1482]
00:01.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse GPP Bridge [1022:1483]
	Subsystem: Advanced Micro Devices, Inc. [AMD] Starship/Matisse GPP Bridge [1022:1453]
	Kernel driver in use: pcieport
00:01.2 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse GPP Bridge [1022:1483]
	Subsystem: Advanced Micro Devices, Inc. [AMD] Starship/Matisse GPP Bridge [1022:1453]
	Kernel driver in use: pcieport
00:02.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge [1022:1482]
00:03.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge [1022:1482]
00:03.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse GPP Bridge [1022:1483]
	Subsystem: Advanced Micro Devices, Inc. [AMD] Starship/Matisse GPP Bridge [1022:1453]
	Kernel driver in use: pcieport
00:04.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge [1022:1482]
00:05.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge [1022:1482]
00:07.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge [1022:1482]
00:07.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse Internal PCIe GPP Bridge 0 to bus[E:B] [1022:1484]
	Subsystem: Advanced Micro Devices, Inc. [AMD] Starship/Matisse Internal PCIe GPP Bridge 0 to bus[E:B] [1022:1484]
	Kernel driver in use: pcieport
00:08.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Host Bridge [1022:1482]
00:08.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse Internal PCIe GPP Bridge 0 to bus[E:B] [1022:1484]
	Subsystem: Advanced Micro Devices, Inc. [AMD] Starship/Matisse Internal PCIe GPP Bridge 0 to bus[E:B] [1022:1484]
	Kernel driver in use: pcieport
00:14.0 SMBus [0c05]: Advanced Micro Devices, Inc. [AMD] FCH SMBus Controller [1022:790b] (rev 61)
	Subsystem: Gigabyte Technology Co., Ltd FCH SMBus Controller [1458:5001]
	Kernel modules: i2c_piix4, sp5100_tco
00:14.3 ISA bridge [0601]: Advanced Micro Devices, Inc. [AMD] FCH LPC Bridge [1022:790e] (rev 51)
	Subsystem: Gigabyte Technology Co., Ltd FCH LPC Bridge [1458:5001]
00:18.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Matisse/Vermeer Data Fabric: Device 18h; Function 0 [1022:1440]
00:18.1 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Matisse/Vermeer Data Fabric: Device 18h; Function 1 [1022:1441]
00:18.2 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Matisse/Vermeer Data Fabric: Device 18h; Function 2 [1022:1442]
00:18.3 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Matisse/Vermeer Data Fabric: Device 18h; Function 3 [1022:1443]
	Kernel driver in use: k10temp
	Kernel modules: k10temp
00:18.4 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Matisse/Vermeer Data Fabric: Device 18h; Function 4 [1022:1444]
00:18.5 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Matisse/Vermeer Data Fabric: Device 18h; Function 5 [1022:1445]
00:18.6 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Matisse/Vermeer Data Fabric: Device 18h; Function 6 [1022:1446]
00:18.7 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Matisse/Vermeer Data Fabric: Device 18h; Function 7 [1022:1447]
01:00.0 Non-Volatile memory controller [0108]: Realtek Semiconductor Co., Ltd. Device [10ec:5763] (rev 01)
	Subsystem: Realtek Semiconductor Co., Ltd. Device [10ec:5763]
	Kernel driver in use: nvme
	Kernel modules: nvme
02:00.0 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] 500 Series Chipset USB 3.1 XHCI Controller [1022:43ee]
	Subsystem: ASMedia Technology Inc. ASM1042A USB 3.0 Host Controller [1b21:1142]
	Kernel driver in use: xhci_hcd
	Kernel modules: xhci_pci
02:00.1 SATA controller [0106]: Advanced Micro Devices, Inc. [AMD] 500 Series Chipset SATA Controller [1022:43eb]
	Subsystem: ASMedia Technology Inc. ASM1062 Serial ATA Controller [1b21:1062]
	Kernel driver in use: ahci
02:00.2 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] 500 Series Chipset Switch Upstream Port [1022:43e9]
	Subsystem: ASMedia Technology Inc. 500 Series Chipset Switch Upstream Port [1b21:0201]
	Kernel driver in use: pcieport
03:00.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Device [1022:43ea]
	Subsystem: ASMedia Technology Inc. Device [1b21:3308]
	Kernel driver in use: pcieport
03:04.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Device [1022:43ea]
	Subsystem: ASMedia Technology Inc. Device [1b21:3308]
	Kernel driver in use: pcieport
03:06.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Device [1022:43ea]
	Subsystem: ASMedia Technology Inc. Device [1b21:3308]
	Kernel driver in use: pcieport
03:07.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Device [1022:43ea]
	Subsystem: ASMedia Technology Inc. Device [1b21:3308]
	Kernel driver in use: pcieport
03:08.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Device [1022:43ea]
	Subsystem: ASMedia Technology Inc. Device [1b21:3308]
	Kernel driver in use: pcieport
03:09.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Device [1022:43ea]
	Subsystem: ASMedia Technology Inc. Device [1b21:3308]
	Kernel driver in use: pcieport
04:00.0 VGA compatible controller [0300]: NVIDIA Corporation GA104 [GeForce RTX 3060] [10de:2487] (rev a1)
	Subsystem: Gigabyte Technology Co., Ltd GA104 [GeForce RTX 3060] [1458:4074]
	Kernel driver in use: vfio-pci
	Kernel modules: nouveau, nvidia_drm, nvidia
04:00.1 Audio device [0403]: NVIDIA Corporation GA104 High Definition Audio Controller [10de:228b] (rev a1)
	Subsystem: Gigabyte Technology Co., Ltd GA104 High Definition Audio Controller [1458:4074]
	Kernel driver in use: vfio-pci
	Kernel modules: snd_hda_intel
05:00.0 Non-Volatile memory controller [0108]: Kingston Technology Company, Inc. SNVS2000G [NV1 NVMe PCIe SSD 2TB] [2646:500e] (rev 01)
	Subsystem: Kingston Technology Company, Inc. SNVS2000G [NV1 NVMe PCIe SSD 2TB] [2646:500e]
	Kernel driver in use: nvme
	Kernel modules: nvme
09:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller [10ec:8168] (rev 16)
	Subsystem: Gigabyte Technology Co., Ltd Onboard Ethernet [1458:e000]
	Kernel driver in use: r8169
	Kernel modules: r8169
0a:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK104 [GeForce GTX 770] [10de:1184] (rev a1)
	Subsystem: Micro-Star International Co., Ltd. [MSI] GK104 [GeForce GTX 770] [1462:2835]
	Kernel driver in use: nvidia
	Kernel modules: nouveau, nvidia_drm, nvidia
0a:00.1 Audio device [0403]: NVIDIA Corporation GK104 HDMI Audio Controller [10de:0e0a] (rev a1)
	Subsystem: Micro-Star International Co., Ltd. [MSI] GK104 HDMI Audio Controller [1462:2835]
	Kernel driver in use: snd_hda_intel
	Kernel modules: snd_hda_intel
0b:00.0 Non-Essential Instrumentation [1300]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Function [1022:148a]
	Subsystem: Advanced Micro Devices, Inc. [AMD] Starship/Matisse PCIe Dummy Function [1022:148a]
0c:00.0 Non-Essential Instrumentation [1300]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse Reserved SPP [1022:1485]
	Subsystem: Advanced Micro Devices, Inc. [AMD] Starship/Matisse Reserved SPP [1022:1485]
0c:00.1 Encryption controller [1080]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse Cryptographic Coprocessor PSPCPP [1022:1486]
	Subsystem: Advanced Micro Devices, Inc. [AMD] Starship/Matisse Cryptographic Coprocessor PSPCPP [1022:1486]
	Kernel driver in use: ccp
	Kernel modules: ccp
0c:00.3 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Matisse USB 3.0 Host Controller [1022:149c]
	Subsystem: Gigabyte Technology Co., Ltd Matisse USB 3.0 Host Controller [1458:5007]
	Kernel driver in use: xhci_hcd
	Kernel modules: xhci_pci
0c:00.4 Audio device [0403]: Advanced Micro Devices, Inc. [AMD] Starship/Matisse HD Audio Controller [1022:1487]
	DeviceName: Realtek ALC1220
	Subsystem: Gigabyte Technology Co., Ltd Starship/Matisse HD Audio Controller [1458:a184]
	Kernel driver in use: snd_hda_intel
	Kernel modules: snd_hda_intel

в которой почему то много устройств

https://wiki.archlinux.org/title/PCI_passthrough_via_OVMF#Bypassing_the_IOMMU_groups_(ACS_override_patch)

If you find your PCI devices grouped among others that you do not wish to pass through, you may be able to seperate them using Alex Williamson’s ACS override patch. Make sure you understand the potential risk of doing so.

You will need a kernel with the patch applied. The easiest method to acquiring this is through the linux-zen or linux-vfio package.

whbex
()