Skip to content

Commit

Permalink
PCI: iproc: Fix multi-MSI base vector number allocation
Browse files Browse the repository at this point in the history
[ Upstream commit e673d69 ]

Commit fc54bae ("PCI: iproc: Allow allocation of multiple MSIs")
introduced multi-MSI support with a broken allocation mechanism (it failed
to reserve the proper number of bits from the inner domain).  Natural
alignment of the base vector number was also not guaranteed.

Link: https://lore.kernel.org/r/20210622152630.40842-1-sbodomerle@gmail.com
Fixes: fc54bae ("PCI: iproc: Allow allocation of multiple MSIs")
Reported-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Sandor Bodo-Merle <sbodomerle@gmail.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Marc Zyngier <maz@kernel.org>
Acked-by: Pali Rohár <pali@kernel.org>
Acked-by: Ray Jui <ray.jui@broadcom.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
sbodomerle authored and gregkh committed Jul 20, 2021
1 parent ac2e498 commit 54dc6fc
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions drivers/pci/controller/pcie-iproc-msi.c
Expand Up @@ -252,18 +252,18 @@ static int iproc_msi_irq_domain_alloc(struct irq_domain *domain,

mutex_lock(&msi->bitmap_lock);

/* Allocate 'nr_cpus' number of MSI vectors each time */
hwirq = bitmap_find_next_zero_area(msi->bitmap, msi->nr_msi_vecs, 0,
msi->nr_cpus, 0);
if (hwirq < msi->nr_msi_vecs) {
bitmap_set(msi->bitmap, hwirq, msi->nr_cpus);
} else {
mutex_unlock(&msi->bitmap_lock);
return -ENOSPC;
}
/*
* Allocate 'nr_irqs' multiplied by 'nr_cpus' number of MSI vectors
* each time
*/
hwirq = bitmap_find_free_region(msi->bitmap, msi->nr_msi_vecs,
order_base_2(msi->nr_cpus * nr_irqs));

mutex_unlock(&msi->bitmap_lock);

if (hwirq < 0)
return -ENOSPC;

for (i = 0; i < nr_irqs; i++) {
irq_domain_set_info(domain, virq + i, hwirq + i,
&iproc_msi_bottom_irq_chip,
Expand All @@ -284,7 +284,8 @@ static void iproc_msi_irq_domain_free(struct irq_domain *domain,
mutex_lock(&msi->bitmap_lock);

hwirq = hwirq_to_canonical_hwirq(msi, data->hwirq);
bitmap_clear(msi->bitmap, hwirq, msi->nr_cpus);
bitmap_release_region(msi->bitmap, hwirq,
order_base_2(msi->nr_cpus * nr_irqs));

mutex_unlock(&msi->bitmap_lock);

Expand Down

0 comments on commit 54dc6fc

Please sign in to comment.