Skip to content

Commit 5af507b

Browse files
Saurabh SengarKAGA-KOKO
authored andcommitted
x86/ioapic: Don't return 0 from arch_dynirq_lower_bound()
arch_dynirq_lower_bound() is invoked by the core interrupt code to retrieve the lowest possible Linux interrupt number for dynamically allocated interrupts like MSI. The x86 implementation uses this to exclude the IO/APIC GSI space. This works correctly as long as there is an IO/APIC registered, but returns 0 if not. This has been observed in VMs where the BIOS does not advertise an IO/APIC. 0 is an invalid interrupt number except for the legacy timer interrupt on x86. The return value is unchecked in the core code, so it ends up to allocate interrupt number 0 which is subsequently considered to be invalid by the caller, e.g. the MSI allocation code. The function has already a check for 0 in the case that an IO/APIC is registered, as ioapic_dynirq_base is 0 in case of device tree setups. Consolidate this and zero check for both ioapic_dynirq_base and gsi_top, which is used in the case that no IO/APIC is registered. Fixes: 3e5bedc ("x86/apic: Fix arch_dynirq_lower_bound() bug for DT enabled machines") Signed-off-by: Saurabh Sengar <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f96fb2d commit 5af507b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

arch/x86/kernel/apic/io_apic.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,17 +2477,21 @@ static int io_apic_get_redir_entries(int ioapic)
24772477

24782478
unsigned int arch_dynirq_lower_bound(unsigned int from)
24792479
{
2480+
unsigned int ret;
2481+
24802482
/*
24812483
* dmar_alloc_hwirq() may be called before setup_IO_APIC(), so use
24822484
* gsi_top if ioapic_dynirq_base hasn't been initialized yet.
24832485
*/
2484-
if (!ioapic_initialized)
2485-
return gsi_top;
2486+
ret = ioapic_dynirq_base ? : gsi_top;
2487+
24862488
/*
2487-
* For DT enabled machines ioapic_dynirq_base is irrelevant and not
2488-
* updated. So simply return @from if ioapic_dynirq_base == 0.
2489+
* For DT enabled machines ioapic_dynirq_base is irrelevant and
2490+
* always 0. gsi_top can be 0 if there is no IO/APIC registered.
2491+
* 0 is an invalid interrupt number for dynamic allocations. Return
2492+
* @from instead.
24892493
*/
2490-
return ioapic_dynirq_base ? : from;
2494+
return ret ? : from;
24912495
}
24922496

24932497
#ifdef CONFIG_X86_32

0 commit comments

Comments
 (0)