[tip: irq/drivers] irqchip/bcm2712-mip: Fix multi-MSI allocation for non-power-of-two counts

From: tip-bot2 for Nicolai Buchwitz

Date: Tue Dec 01 2026 - 15:15:56 EST


The following commit has been merged into the irq/drivers branch of tip:

Commit-ID: e5cd48011ba4b5e52e7b873485eaac199f4a46cb
Gitweb: https://git.kernel.org/tip/e5cd48011ba4b5e52e7b873485eaac199f4a46cb
Author: Nicolai Buchwitz <nb@xxxxxxxxxxx>
AuthorDate: Thu, 12 Nov 2026 12:58:11 +01:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Tue, 01 Dec 2026 21:12:22 +01:00

irqchip/bcm2712-mip: Fix multi-MSI allocation for non-power-of-two counts

ilog2() rounds down, so a request for three vectors reserves only two
slots and the third can overlap another allocation. The alignment is
also applied to the bitmap index and ignores the msi_offset that is
added to the message data.

Reserve exactly the requested number of slots and align the start of
the message data block to the vector count rounded up to a power of
two.

Fixes: 32c6c054661a ("irqchip: Add Broadcom BCM2712 MSI-X interrupt controller")
Signed-off-by: Nicolai Buchwitz <nb@xxxxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Reviewed-by: Florian Fainelli <florian.fainelli@xxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Link: https://patch.msgid.link/20261112-bcm2712-mip-msi-align-v1-1-68090868c979@xxxxxxxxxxx
---
drivers/irqchip/irq-bcm2712-mip.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/irqchip/irq-bcm2712-mip.c b/drivers/irqchip/irq-bcm2712-mip.c
index 06a6ab6..a0f45df 100644
--- a/drivers/irqchip/irq-bcm2712-mip.c
+++ b/drivers/irqchip/irq-bcm2712-mip.c
@@ -71,15 +71,24 @@ static struct irq_chip mip_middle_irq_chip = {

static int mip_alloc_hwirq(struct mip_priv *mip, unsigned int nr_irqs)
{
+ unsigned long hwirq;
+
guard(spinlock)(&mip->lock);
- return bitmap_find_free_region(mip->bitmap, mip->num_msis, ilog2(nr_irqs));
+ hwirq = bitmap_find_next_zero_area_off(mip->bitmap, mip->num_msis, 0,
+ nr_irqs, roundup_pow_of_two(nr_irqs) - 1,
+ mip->msi_offset);
+ if (hwirq >= mip->num_msis)
+ return -ENOSPC;
+
+ bitmap_set(mip->bitmap, hwirq, nr_irqs);
+ return hwirq;
}

static void mip_free_hwirq(struct mip_priv *mip, unsigned int hwirq,
unsigned int nr_irqs)
{
guard(spinlock)(&mip->lock);
- bitmap_release_region(mip->bitmap, hwirq, ilog2(nr_irqs));
+ bitmap_clear(mip->bitmap, hwirq, nr_irqs);
}

static int mip_middle_domain_alloc(struct irq_domain *domain, unsigned int virq,