Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

irqchip/gic-v2m: Handle Multiple MSI base IRQ Alignment

The PCI Local Bus Specification 3.0 (section 6.8.1.6) allows modifying the
low-order bits of the MSI Message DATA register to encode nr_irqs interrupt
numbers in the log2(nr_irqs) bits for the domain.

The problem arises if the base vector (GICV2m base spi) is not aligned with
nr_irqs; in this case, the low-order log2(nr_irqs) bits from the base
vector conflict with the nr_irqs masking, causing the wrong MSI interrupt
to be identified.

To fix this, use bitmap_find_next_zero_area_off() instead of
bitmap_find_free_region() to align the initial base vector with nr_irqs.

Signed-off-by: Christian Bruel <christian.bruel@foss.st.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/all/20250902091045.220847-1-christian.bruel@foss.st.com

authored by

Christian Bruel and committed by
Thomas Gleixner
2ef3886c d36bf356

+9 -4
+9 -4
drivers/irqchip/irq-gic-v2m.c
··· 153 153 { 154 154 msi_alloc_info_t *info = args; 155 155 struct v2m_data *v2m = NULL, *tmp; 156 - int hwirq, offset, i, err = 0; 156 + int hwirq, i, err = 0; 157 + unsigned long offset; 158 + unsigned long align_mask = nr_irqs - 1; 157 159 158 160 spin_lock(&v2m_lock); 159 161 list_for_each_entry(tmp, &v2m_nodes, entry) { 160 - offset = bitmap_find_free_region(tmp->bm, tmp->nr_spis, 161 - get_count_order(nr_irqs)); 162 - if (offset >= 0) { 162 + unsigned long align_off = tmp->spi_start - (tmp->spi_start & ~align_mask); 163 + 164 + offset = bitmap_find_next_zero_area_off(tmp->bm, tmp->nr_spis, 0, 165 + nr_irqs, align_mask, align_off); 166 + if (offset < tmp->nr_spis) { 163 167 v2m = tmp; 168 + bitmap_set(v2m->bm, offset, nr_irqs); 164 169 break; 165 170 } 166 171 }