Passthrough more than 4 PCIe devices to Proxmox 4.4 and 5 guests

By default in Proxmox 4.4 and 5, you are unable to pass through more than 4 PCIe devices to the guest. If you try, you’ll get an error when attempting to start the VM which reads:

vm 100 - unable to parse value of 'hostpci4' - unknown setting 'hostpci4'

Passed-through PCIe devices are attached to the four ports called “ich9-pcie-port-{1,2,3,4}” which are defined in /usr/share/qemu-server/pve-q35.cfg. These ports occupy PCIe function numbers 0-3, leaving function numbers 4-7 unused.

It’s a simple matter to add definitions for an extra 4 ports to use up those spare function numbers in /usr/share/qemu-server/pve-q35.cfg:

[device "ich9-pcie-port-5"]
 driver = "ioh3420"
 multifunction = "on"
 bus = "pcie.0"
 addr = "1c.4"
 port = "5"
 chassis = "5"

[device "ich9-pcie-port-6"]
 driver = "ioh3420"
 multifunction = "on"
 bus = "pcie.0"
 addr = "1c.5"
 port = "6"
 chassis = "6"

[device "ich9-pcie-port-7"]
 driver = "ioh3420"
 multifunction = "on"
 bus = "pcie.0"
 addr = "1c.6"
 port = "7"
 chassis = "7"

[device "ich9-pcie-port-8"]
 driver = "ioh3420"
 multifunction = "on"
 bus = "pcie.0"
 addr = "1c.7"
 port = "8"
 chassis = "8"

Note that this file is a bit sensitive to extra whitespace on empty lines, so make sure empty lines are fully empty. Then we just need to patch the VM configuration parser in /usr/share/perl5/PVE/QemuServer.pm and /usr/share/perl5/PVE/QemuServer/PCI.pm to accept “hostpci4” through “hostpci7” as valid:

Patch for Proxmox 4.4

Patch for Proxmox 5

Patch for Proxmox 5.1 (also 5.2)

Do note that this patch doesn’t add support for PCI devices in those new positions, only PCIe ones.

In Proxmox 5.1 I’ve found that editing the VM configuration with the web interface sometimes drops the new hostpci definitions, so be sure to keep a backup of those in the VM comments in case you have to re-add them.

After applying those patches, stopping my VMs, and restarting the pve-manager service (service restart pve-manager on Proxmox 4.4 and systemctl restart pve-manager.service on Proxmox 5, not sure if this is really required or not), VM configurations like this that pass through 5 PCIe devices now become valid:

hostpci0: 03:00,pcie=1,x-vga=on
hostpci1: 00:1a.0,pcie=1
hostpci2: 00:1d.0,pcie=1
hostpci3: 82:00.0,pcie=1
hostpci4: 81:00.0,pcie=1

This allowed me to pass through 3 USB controllers, an NVMe SSD, a network adapter, and a graphics card to my macOS VM!

This modification is made at your own risk! There might have been a good reason why the number of PCIe devices was limited to 4 (although I suspect that the reason was that the number of available PCI device numbers was running out).

One thought on “Passthrough more than 4 PCIe devices to Proxmox 4.4 and 5 guests”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.