Skip to content

Conversation

@adl09
Copy link

@adl09 adl09 commented Oct 29, 2025

This change increases the constant value to ensure proper PCI device enumeration on Supermicro E300-9D hardware.
With the previous value, both 10 GbE NICs (Intel X557-AT2) fail to be detected during initialization, causing PCI passthrough to break.

Signed-off-by: Alberto Daniel Lange <adlange09@gmail.com>
Copy link
Contributor

@midnightveil midnightveil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine.

I'll approve; for other reviewers the reason for there being a hardcoded constant is because there is a hardcoded list of all PCI devices up to this number:

libpci_device_t libpci_device_list[PCI_MAX_DEVICES];
which is populated by

util_libs/libpci/src/pci.c

Lines 80 to 109 in 486afd6

static int libpci_add_fun(uint8_t bus, uint8_t dev, uint8_t fun)
{
uint16_t vendor_id = libpci_read_reg16(bus, dev, fun, PCI_VENDOR_ID);
if (vendor_id == PCI_VENDOR_ID_INVALID) {
/* No device here. */
return 0;
}
ZF_LOGD("PCI :: Device found at BUS %d DEV %d FUN %d:\n", (int)bus, (int)dev, (int)fun);
ZF_LOGD(" vendorID = %s [0x%x]\n", libpci_vendorID_str(vendor_id), vendor_id);
uint16_t device_id = libpci_read_reg16(bus, dev, fun, PCI_DEVICE_ID);
ZF_LOGD(" deviceID = %s [0x%x]\n", libpci_deviceID_str(vendor_id, device_id), device_id);
if (libpci_num_devices + 1 > PCI_MAX_DEVICES) {
return 0;
}
libpci_device_list[libpci_num_devices].bus = bus;
libpci_device_list[libpci_num_devices].dev = dev;
libpci_device_list[libpci_num_devices].fun = fun;
libpci_device_list[libpci_num_devices].vendor_id = vendor_id;
libpci_device_list[libpci_num_devices].device_id = device_id;
libpci_device_list[libpci_num_devices].vendor_name = libpci_vendorID_str(vendor_id);
libpci_device_list[libpci_num_devices].device_name = libpci_deviceID_str(vendor_id, device_id);
libpci_device_list[libpci_num_devices].interrupt_line = libpci_read_reg8(bus, dev, fun, PCI_INTERRUPT_LINE);
libpci_device_list[libpci_num_devices].interrupt_pin = libpci_read_reg8(bus, dev, fun, PCI_INTERRUPT_PIN);
libpci_device_list[libpci_num_devices].subsystem_id = libpci_read_reg16(bus, dev, fun, PCI_SUBSYSTEM_ID);
libpci_read_ioconfig(&libpci_device_list[libpci_num_devices].cfg, bus, dev, fun);
.

The other use is

libpci_device_t* matched_devices[PCI_MAX_DEVICES];
int nfound = libpci_find_device_all(vendor_id, device_id, matched_devices);
for (int i = 0; i < nfound; i++) {
bool ret = libpci_virtual_pci_device_allow(self, matched_devices[i]);
if (!ret) return ret;
}
return true;
}

where it allocates a large array on the stack. That is probably the most questionable part of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants