Skip to content

Commit 77f88ab

Browse files
Ming Leibjorn-helgaas
authored andcommitted
PCI/MSI: Return -ENOSPC from pci_alloc_irq_vectors_affinity()
The API of pci_alloc_irq_vectors_affinity() says it returns -ENOSPC if fewer than @min_vecs interrupt vectors are available for @dev. However, if a device supports MSI-X but not MSI and a caller requests @min_vecs that can't be satisfied by MSI-X, we previously returned -EINVAL (from the failed attempt to enable MSI), not -ENOSPC. When -ENOSPC is returned, callers may reduce the number IRQs they request and try again. Most callers can use the @min_vecs and @max_vecs parameters to avoid this retry loop, but that doesn't work when using IRQ affinity "nr_sets" because rebalancing the sets is driver-specific. This return value bug has been present since pci_alloc_irq_vectors() was added in v4.10 by aff1716 ("PCI: Provide sensible IRQ vector alloc/free routines"), but it wasn't an issue because @min_vecs/@max_vecs removed the need for callers to iteratively reduce the number of IRQs requested and retry the allocation, so they didn't need to distinguish -ENOSPC from -EINVAL. In v5.0, 6da4b3a ("genirq/affinity: Add support for allocating interrupt sets") added IRQ sets to the interface, which reintroduced the need to check for -ENOSPC and possibly reduce the number of IRQs requested and retry the allocation. Signed-off-by: Ming Lei <ming.lei@redhat.com> [bhelgaas: changelog] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Cc: Jens Axboe <axboe@fb.com> Cc: Keith Busch <keith.busch@intel.com> Cc: Christoph Hellwig <hch@lst.de>
1 parent 2e8cb2c commit 77f88ab

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

drivers/pci/msi.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,8 @@ int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
11681168
const struct irq_affinity *affd)
11691169
{
11701170
static const struct irq_affinity msi_default_affd;
1171-
int vecs = -ENOSPC;
1171+
int msix_vecs = -ENOSPC;
1172+
int msi_vecs = -ENOSPC;
11721173

11731174
if (flags & PCI_IRQ_AFFINITY) {
11741175
if (!affd)
@@ -1179,16 +1180,17 @@ int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
11791180
}
11801181

11811182
if (flags & PCI_IRQ_MSIX) {
1182-
vecs = __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs,
1183-
affd);
1184-
if (vecs > 0)
1185-
return vecs;
1183+
msix_vecs = __pci_enable_msix_range(dev, NULL, min_vecs,
1184+
max_vecs, affd);
1185+
if (msix_vecs > 0)
1186+
return msix_vecs;
11861187
}
11871188

11881189
if (flags & PCI_IRQ_MSI) {
1189-
vecs = __pci_enable_msi_range(dev, min_vecs, max_vecs, affd);
1190-
if (vecs > 0)
1191-
return vecs;
1190+
msi_vecs = __pci_enable_msi_range(dev, min_vecs, max_vecs,
1191+
affd);
1192+
if (msi_vecs > 0)
1193+
return msi_vecs;
11921194
}
11931195

11941196
/* use legacy irq if allowed */
@@ -1199,7 +1201,9 @@ int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
11991201
}
12001202
}
12011203

1202-
return vecs;
1204+
if (msix_vecs == -ENOSPC)
1205+
return -ENOSPC;
1206+
return msi_vecs;
12031207
}
12041208
EXPORT_SYMBOL(pci_alloc_irq_vectors_affinity);
12051209

0 commit comments

Comments
 (0)