Skip to content

Commit 796b755

Browse files
author
Alex Williamson
committed
vfio/pci: Fix handling of RC integrated endpoint PCIe capability size
Root complex integrated endpoints do not have a link and therefore may use a smaller PCIe capability in config space than we expect when building our config map. Add a case for these to avoid reporting an erroneous overlap. Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 9f47803 commit 796b755

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/vfio/pci/vfio_pci_config.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ static int vfio_exp_config_write(struct vfio_pci_device *vdev, int pos,
839839
/* Permissions for PCI Express capability */
840840
static int __init init_pci_cap_exp_perm(struct perm_bits *perm)
841841
{
842-
/* Alloc larger of two possible sizes */
842+
/* Alloc largest of possible sizes */
843843
if (alloc_perm_bits(perm, PCI_CAP_EXP_ENDPOINT_SIZEOF_V2))
844844
return -ENOMEM;
845845

@@ -1243,11 +1243,16 @@ static int vfio_cap_len(struct vfio_pci_device *vdev, u8 cap, u8 pos)
12431243
vdev->extended_caps = (dword != 0);
12441244
}
12451245

1246-
/* length based on version */
1247-
if ((pcie_caps_reg(pdev) & PCI_EXP_FLAGS_VERS) == 1)
1246+
/* length based on version and type */
1247+
if ((pcie_caps_reg(pdev) & PCI_EXP_FLAGS_VERS) == 1) {
1248+
if (pci_pcie_type(pdev) == PCI_EXP_TYPE_RC_END)
1249+
return 0xc; /* "All Devices" only, no link */
12481250
return PCI_CAP_EXP_ENDPOINT_SIZEOF_V1;
1249-
else
1251+
} else {
1252+
if (pci_pcie_type(pdev) == PCI_EXP_TYPE_RC_END)
1253+
return 0x2c; /* No link */
12501254
return PCI_CAP_EXP_ENDPOINT_SIZEOF_V2;
1255+
}
12511256
case PCI_CAP_ID_HT:
12521257
ret = pci_read_config_byte(pdev, pos + 3, &byte);
12531258
if (ret)

0 commit comments

Comments
 (0)