[PATCH RFC 1/2] x86/apic: Do not make an exception for PIC_CASCADE_IR when marking legacy irqs in irq_matrix

From: Vitaly Kuznetsov
Date: Fri Feb 19 2021 - 06:33:14 EST


Trying to offline/online CPU0 seems to work only once:

# echo 0 > /sys/devices/system/cpu/cpu0/online
# echo 1 > /sys/devices/system/cpu/cpu0/online
# echo 0 > /sys/devices/system/cpu/cpu0/online
-bash: echo: write error: No space left on device

with the following in dmesg:

[ ... ] CPU 0 has 4294967295 vectors, 589 available. Cannot disable CPU

Clearly, we went negative with cm->allocated in irq_matrix and think that
there are too many vectors require re-assigning.

The problem turns to be: lapic_assign_system_vectors() called from
native_init_IRQ() makes an exception for PIC_CASCADE_IR and doesn't
mark it in irq_matrix. Later, when x86_vector_alloc_irqs() called
from setup_IO_APIC() does clear_irq_vector() for all legacy entries,
it doesn't make an exception so we go negative.

CPU0 offlining still works for the first time because some other vectors
get assigned and the overall balance remains positive (it's off-by-one, but
the check passes). When we online CPU0 back, no vectors get assigned and
the overall balance remains '-1'.

The simplest solution seems to be to not make an exception for
PIC_CASCADE_IR. Nothing seems to blow up immediately.

Signed-off-by: Vitaly Kuznetsov <vkuznets@xxxxxxxxxx>
---
arch/x86/kernel/apic/vector.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/kernel/apic/vector.c b/arch/x86/kernel/apic/vector.c
index 3c9c7492252f..f3aa02ced929 100644
--- a/arch/x86/kernel/apic/vector.c
+++ b/arch/x86/kernel/apic/vector.c
@@ -745,8 +745,7 @@ void __init lapic_assign_system_vectors(void)

/* Mark the preallocated legacy interrupts */
for (i = 0; i < nr_legacy_irqs(); i++) {
- if (i != PIC_CASCADE_IR)
- irq_matrix_assign(vector_matrix, ISA_IRQ_VECTOR(i));
+ irq_matrix_assign(vector_matrix, ISA_IRQ_VECTOR(i));
}
}

--
2.29.2