mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 02:39:48 +00:00
PCI/MSI: Return -ENOSPC from pci_alloc_irq_vectors_affinity()
[ Upstream commit77f88abd4a
] 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 byaff171641d
("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,6da4b3ab9a
("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
acf72ff8b6
commit
5ab9b2bc8a
1 changed files with 13 additions and 9 deletions
|
@ -1156,7 +1156,8 @@ int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
|
|||
const struct irq_affinity *affd)
|
||||
{
|
||||
static const struct irq_affinity msi_default_affd;
|
||||
int vecs = -ENOSPC;
|
||||
int msix_vecs = -ENOSPC;
|
||||
int msi_vecs = -ENOSPC;
|
||||
|
||||
if (flags & PCI_IRQ_AFFINITY) {
|
||||
if (!affd)
|
||||
|
@ -1167,16 +1168,17 @@ int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
|
|||
}
|
||||
|
||||
if (flags & PCI_IRQ_MSIX) {
|
||||
vecs = __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs,
|
||||
affd);
|
||||
if (vecs > 0)
|
||||
return vecs;
|
||||
msix_vecs = __pci_enable_msix_range(dev, NULL, min_vecs,
|
||||
max_vecs, affd);
|
||||
if (msix_vecs > 0)
|
||||
return msix_vecs;
|
||||
}
|
||||
|
||||
if (flags & PCI_IRQ_MSI) {
|
||||
vecs = __pci_enable_msi_range(dev, min_vecs, max_vecs, affd);
|
||||
if (vecs > 0)
|
||||
return vecs;
|
||||
msi_vecs = __pci_enable_msi_range(dev, min_vecs, max_vecs,
|
||||
affd);
|
||||
if (msi_vecs > 0)
|
||||
return msi_vecs;
|
||||
}
|
||||
|
||||
/* use legacy irq if allowed */
|
||||
|
@ -1187,7 +1189,9 @@ int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
|
|||
}
|
||||
}
|
||||
|
||||
return vecs;
|
||||
if (msix_vecs == -ENOSPC)
|
||||
return -ENOSPC;
|
||||
return msi_vecs;
|
||||
}
|
||||
EXPORT_SYMBOL(pci_alloc_irq_vectors_affinity);
|
||||
|
||||
|
|
Loading…
Reference in a new issue