GPU passthrough on POPOS using PCIe Id instead of manufacturer ID

I’m trying to do some gpu passthrough for a gaming machine I have an rx590 and an rx570 and they both have the same id when doing LSPCI -nn so is there a way around that fact or do I have to go vega 56 and be done with it?

You can assign the card based on the PCIe slot id by getting your initramfs to run this (with the DEVS being the PCIe slot id for both the video and audio device)

#!/bin/sh

DEVS="0000:0f:00.0 0000:0f:00.1"

for DEV in $DEVS; do
     echo "vfio-pci" > /sys/bus/pci/devices/$DEV/driver_override
done
modprobe -i vfio-pci

or this which will assign every graphics card that isn’t the one in the primary slot without needing to specify any IDs.

#!/bin/sh

for i in $(find /sys/devices/pci* -name boot_vga); do
    if [ $(cat $i) -eq 0 ]; then
        GPU=$(dirname $i)
        AUDIO=$(echo $GPU | sed -e "s/0$/1/")
        echo "vfio-pci" > $GPU/driver_override
        if [ -d $AUDIO ]; then
            echo "vfio-pci" > $AUDIO/driver_override
        fi
    fi
done

modprobe -i vfio-pci

How todo this largely depends on how your distro handles the initramfs but for Fedora I save the script as /usr/sbin/vfio-pci-override-vga.sh and in /etc/dracut.conf.d/vfio.conf I put:

add_drivers+="vfio vfio_iommu_type1 vfio_pci vfio_virqfd"
install_items+="/sbin/vfio-pci-override-vga.sh /usr/bin/find /usr/bin/dirname"

rebuild the initramfs with dracut --kver -f

and also add it to you /etc/modprobe.d/vfio.conf

install vfio-pci /sbin/vfio-pci-override-vga.sh
2 Likes

see above for separating pci-ids.

after that, if your cards have the reset bug, you got the reset bug (probably) forever, unfortunately.

Thanks for the scripts they look like just what I need I’m on popos though and I’m still trying to figure out where to put your last 2 command in /etc/initramfs-tools/modules seems good but I’m not sure

1 Like

If your using Pop OS Wendell has a guide on the forum which will tell you exactly how to set it up. Look for the The Initial Ramdisk and You section.

2 Likes