vga-passthrough with fglrx and kvm

Questions about virtualization software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
amadren

vga-passthrough with fglrx and kvm

Post by amadren »

Following this thread: http://forums.linuxmint.com/viewtopic.p ... 1&t=198897

Is there a way to enable vga passthrough using KVM please?

I always have this error:

Code: Select all

qemu-system-x86_64: -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on: vfio: Error: Failed to setup INTx fd: Device or resource busy
qemu-system-x86_64: -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on: Device initialization failed.
qemu-system-x86_64: -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on: Device 'vfio-pci' could not be initialized
My script:

Code: Select all

#!/bin/bash
#vfio-bind 0000:01:00.0 0000:01:00.1
#mount -t ext4 /dev/sdb1 /media/pinkie/Windows-VM -o rw
configfile=/etc/vfio-pci1.cfg

vfiobind() {
    dev="$1"
        vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
        device=$(cat /sys/bus/pci/devices/$dev/device)
        if [ -e /sys/bus/pci/devices/$dev/driver ]; then
                echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
        fi
        echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id

}

modprobe vfio-pci

cat $configfile | while read line;do
    echo $line | grep ^# >/dev/null 2>&1 && continue
        vfiobind $line
done

sudo qemu-system-x86_64 -enable-kvm -M q35 -m 4096 -cpu host \
-smp 4,sockets=1,cores=4,threads=1 \
-bios /usr/share/qemu/bios.bin -vga none \
-device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
-device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on \
-device vfio-pci,host=01:00.1,bus=root.1,addr=00.1 \
-drive file=/home/pinkie/VMs/VM1,id=disk,format=raw -device ide-hd,bus=ide.0,drive=disk \
-drive file=/home/pinkie/Téléchargements/Windows_7_Edition_Familiale_Premium_64Bits/Windows.iso,id=isocd -device ide-cd,bus=ide.1,drive=isocd \
-boot menu=on

exit 0
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
powerhouse
Level 6
Level 6
Posts: 1144
Joined: Thu May 03, 2012 3:54 am
Location: Israel
Contact:

Re: vga-passthrough with fglrx and kvm

Post by powerhouse »

I'm not a 100% sure but the -m 4096 option could be incorrect. Try -m 4G.

Also, I use -machine type=q35,accel=kvm \ instead of -M q35.

The following device line is exactly the same as mine:

Code: Select all

-device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
Have you checked the bus and addr parameters that they match your hardware?

Here is my boot script for an AMD-7770 VGA card:

Code: Select all

 #!/bin/bash

    configfile=/etc/vfio-pci.cfg

    vfiobind() {
       dev="$1"
            vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
            device=$(cat /sys/bus/pci/devices/$dev/device)
            if [ -e /sys/bus/pci/devices/$dev/driver ]; then
                    echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
            fi
            echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id
       
    }

    modprobe vfio-pci

    cat $configfile | while read line;do
       echo $line | grep ^# >/dev/null 2>&1 && continue
       vfiobind $line
       done

    sudo qemu-system-x86_64 \
    -bios /usr/share/qemu/bios.bin -vga none \
    -name win7 \
    -cpu host \
    -smp 6,sockets=1,cores=3,threads=2 \
    -enable-kvm \
    -m 8G \
    -rtc clock=host \
    -vga none \
    -serial null \
    -parallel null \
    -monitor none \
    -display none \
    -k en-us \
    -machine type=q35,accel=kvm \
    -device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
    -boot order=c \
    -device piix4-ide,bus=pcie.0,id=piix4-ide \
    -drive file=/media/user/win7kvm/windows.img,id=disk,format=raw -device ide-hd,bus=piix4-ide.0,drive=disk \
    -drive file=/home/user/Win7.iso,id=isocd -device ide-cd,bus=piix4-ide.1,drive=isocd \
    -drive file=/home/user/virtio-win-0.1-74.iso,id=virtiocd -device ide-cd,bus=ide.1,drive=virtiocd \
    -device vfio-pci,host=01:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on \
    -device vfio-pci,host=01:00.1,bus=pcie.0 \
    -device vfio-pci,host=00:1a.0,bus=pcie.0 \
    -net nic,model=virtio,macaddr=00:16:3e:01:01:01 -net bridge,br=virbr0

    exit 0
However, looking at the error, my guess is that the graphics card you try to pass through to the guest VM is in use by the host! Make sure that it's not bound to any graphics driver. See my HOW-TO on Xen VGA passthrough (the sticky) on how to prevent the graphics driver from binding to the VGA card during system boot. Of course you need a second VGA card or the graphics chip on the CPU for use with Linux, unless you run Linux without screen and use a remote PC with remote access (but let's don't complicate matters).

In my Xen how-to you find a link to the Archlinux forum where there is a thread on KVM and VGA passthrough - still by far the best source of information. But please post here to share your experience.
Subjects of interest: Linux, vfio passthrough virtualization, photography
See my blog on virtualization, including tutorials: https://www.heiko-sieger.info/category/ ... alization/
amadren

Re: vga-passthrough with fglrx and kvm

Post by amadren »

I blacklisted radeon driver like it was written on arch forum and it seems to work. I'm now using virt-manager (easier) and I'm installing video driver but it sounds good. I'll repost here when I'll have some tests done.

Thanks for your help
amadren

Re: vga-passthrough with fglrx and kvm

Post by amadren »

Hi, I have a blackscreen in Windows after installing the drivers. I found that it's a qemu problem (qemu 2.0 crashes) so I installed qemu from its sources but virt-manager stopped working. i wanted to try Sabayon from a long time so I installed it to use kvm and now I'm installing kvm in my system.

Also I found that Dual Graphics solution automatically crossfire the graphic cards. But crossfire is not compatible with IOMMU enabled. So now I bought an HD 7970 to passthrough. I'll test when I'll receive it.
Locked

Return to “Virtual Machines”