i386 IPI handlers running with hardirq_count == 0
Macro arch/i386/kernel/entry.S::BUILD_INTERRUPT generates the code to handle an IPI and call the corresponding smp_<name> C code. BUILD_INTERRUPT does not update the hardirq_count for the interrupted task, that is left to the C code. Some of the C IPI handlers do not call irq_enter(), so they are running in IRQ context but the hardirq_count field does not reflect this. For example, smp_invalidate_interrupt does not set the hardirq count.
What is the best fix, change BUILD_INTERRUPT to adjust the hardirq count or audit all the C handlers to ensure that they call irq_enter()?
Quoted 11 lines · On Thu, 29 Jun 2006 19:01:17 +1000 Keith Owens <[email protected]> wrote:
Macro arch/i386/kernel/entry.S::BUILD_INTERRUPT generates the code to handle an IPI and call the corresponding smp_<name> C code.
BUILD_INTERRUPTdoes not update thehardirq_countfor the interrupted task, that is left to the C code. Some of the C IPI handlers do not callirq_enter(), so they are running in IRQ context but thehardirq_countfield does not reflect this. For example,smp_invalidate_interruptdoes not set the hardirq count.What is the best fix, change
BUILD_INTERRUPTto adjust the hardirq count or audit all the C handlers to ensure that they callirq_enter()?
The IPI handlers run with IRQs disabled. Do we need a fix?
Quoted 11 lines · Andrew Morton
Quoted 8 lines · On Thu, 29 Jun 2006 19:01:17 +1000 Keith Owens <[email protected]> wrote:
Macro arch/i386/kernel/entry.S::BUILD_INTERRUPT generates the code to handle an IPI and call the corresponding smp_<name> C code.
BUILD_INTERRUPTdoes not update thehardirq_countfor the interrupted task, that is left to the C code. Some of the C IPI handlers do not callirq_enter(), so they are running in IRQ context but thehardirq_countfield does not reflect this. For example,smp_invalidate_interruptdoes not set the hardirq count.
Quoted 5 lines
Quoted 3 lines
What is the best fix, change
BUILD_INTERRUPTto adjust the hardirq count or audit all the C handlers to ensure that they callirq_enter()?The IPI handlers run with IRQs disabled. Do we need a fix?
They have to because if there was another interrupt it would execute IRET and then clear the NMI flag in the hardware and allow nested NMIs which would cause all sorts of problems.
The only reason to change it would be complex callbacks in the current handlers using notifier chains. Maybe if they're that complex they should become simpler?
-Andi
Quoted 19 lines · Andi Kleen (on 29 Jun 2006 13:25:38 +0200) wrote:
Quoted 11 lines · Andrew Morton
Quoted 8 lines · On Thu, 29 Jun 2006 19:01:17 +1000 Keith Owens <[email protected]> wrote:
Macro arch/i386/kernel/entry.S::BUILD_INTERRUPT generates the code to handle an IPI and call the corresponding smp_<name> C code.
BUILD_INTERRUPTdoes not update thehardirq_countfor the interrupted task, that is left to the C code. Some of the C IPI handlers do not callirq_enter(), so they are running in IRQ context but thehardirq_countfield does not reflect this. For example,smp_invalidate_interruptdoes not set the hardirq count.Quoted 5 lines
Quoted 3 lines
What is the best fix, change
BUILD_INTERRUPTto adjust the hardirq count or audit all the C handlers to ensure that they callirq_enter()?The IPI handlers run with IRQs disabled. Do we need a fix?
Quoted 7 lines
They have to because if there was another interrupt it would execute IRET and then clear the NMI flag in the hardware and allow nested NMIs which would cause all sorts of problems.
The only reason to change it would be complex callbacks in the current handlers using notifier chains. Maybe if they're that complex they should become simpler?
My question has nothing to do with NMI. I am querying inconsistent behaviour amongst normal IPIs, this list :-
i386 function irq_enter?
smp_apic_timer_interrupt yes smp_call_function_interrupt yes smp_error_interrupt yes smp_invalidate_interrupt no - why smp_reschedule_interrupt no (does not need it) smp_spurious_interrupt yes smp_thermal_interrupt yes
x86_64 function irq_enter?
mce_threshold_interrupt yes smp_apic_timer_interrupt yes smp_call_function_interrupt yes smp_error_interrupt yes smp_invalidate_interrupt no - why smp_reschedule_interrupt no (does not need it) smp_spurious_interrupt yes smp_thermal_interrupt yes
That is just the mach-default list, I have not checked the platforms like voyager.
Quoted 13 lines · Keith Owens
My question has nothing to do with NMI. I am querying inconsistent behaviour amongst normal IPIs, this list :-
i386 function
irq_enter?smp_apic_timer_interrupt yes smp_call_function_interrupt yes smp_error_interrupt yes smp_invalidate_interrupt no - why smp_reschedule_interrupt no (does not need it) smp_spurious_interrupt yes smp_thermal_interrupt yes
x86_64functionirq_enter?
Quoted 8 lines
mce_threshold_interrupt yes smp_apic_timer_interrupt yes smp_call_function_interrupt yes smp_error_interrupt yes smp_invalidate_interrupt no - why smp_reschedule_interrupt no (does not need it) smp_spurious_interrupt yes smp_thermal_interrupt yes
irq_enter() is mostly just for the purpose of in_interrupt()/in_irq() to work as expected, not much else. [also the timer code assumes that update_process_times() is called in a HARDIRQ_OFFSET elevated context, so the apic timer IRQ needs irq_enter() too.] The smp_invalidate_interrupt() and smp_reschedule_interrupt() is performance-critical and they dont need irq_enter()/irq_exit().
Since smp_call_function_interrupt() can be called with driver-supplied function vectors, it's best to keep the irq_enter()/exit there. [for example mm/slab.c has some in_interrupt() sanity checks.] Obviously do_IRQ() itself needs irq_enter()/exit() too - plus the APIC timer irq as mentioned above.
Otherwise, the rest of the SMP functions technically dont need irq_enter()/irq_exit(). [i.e. threshold, error, spurious and thermal] We could remove it from them.
Ingo
Quoted 39 lines · Ingo Molnar
Quoted 13 lines · Keith Owens
My question has nothing to do with NMI. I am querying inconsistent behaviour amongst normal IPIs, this list :-
i386 function
irq_enter?smp_apic_timer_interrupt yes smp_call_function_interrupt yes smp_error_interrupt yes smp_invalidate_interrupt no - why smp_reschedule_interrupt no (does not need it) smp_spurious_interrupt yes smp_thermal_interrupt yes
x86_64functionirq_enter?Quoted 8 lines
mce_threshold_interrupt yes smp_apic_timer_interrupt yes smp_call_function_interrupt yes smp_error_interrupt yes smp_invalidate_interrupt no - why smp_reschedule_interrupt no (does not need it) smp_spurious_interrupt yes smp_thermal_interrupt yes
irq_enter()is mostly just for the purpose of in_interrupt()/in_irq() to work as expected, not much else. [also the timer code assumes thatupdate_process_times()is called in aHARDIRQ_OFFSETelevated context, so the apic timer IRQ needsirq_enter()too.] Thesmp_invalidate_interrupt()andsmp_reschedule_interrupt()is performance-critical and they dont need irq_enter()/irq_exit().Since
smp_call_function_interrupt()can be called with driver-supplied function vectors, it's best to keep the irq_enter()/exit there. [for examplemm/slab.chas somein_interrupt()sanity checks.] Obviouslydo_IRQ()itself needs irq_enter()/exit() too - plus the APIC timer irq as mentioned above.
Quoted 4 lines
Otherwise, the rest of the SMP functions technically dont need irq_enter()/irq_exit(). [i.e. threshold, error, spurious and thermal] We could remove it from them.
There's a risk that spin_unlock() in an IPI handler could blow up due to it trying to reschedule. But preempt_schedule() explicitly checks the CPU's interupt flag so as long as that doesn't change we're OK.
Quoted 3 lines · Andrew Morton
There's a risk that
spin_unlock()in an IPI handler could blow up due to it trying to reschedule. Butpreempt_schedule()explicitly checks the CPU's interupt flag so as long as that doesn't change we're OK.
yes. Enabling hardirqs in an IPI handler would be a quite bad idea anyway, they are all quite short.
Ingo
Quoted 11 lines · Andrew Morton (on Thu, 29 Jun 2006 02:18:00 -0700) wrote:
Quoted 8 lines · On Thu, 29 Jun 2006 19:01:17 +1000 Keith Owens <[email protected]> wrote:
Macro arch/i386/kernel/entry.S::BUILD_INTERRUPT generates the code to handle an IPI and call the corresponding smp_<name> C code.
BUILD_INTERRUPTdoes not update thehardirq_countfor the interrupted task, that is left to the C code. Some of the C IPI handlers do not callirq_enter(), so they are running in IRQ context but thehardirq_countfield does not reflect this. For example,smp_invalidate_interruptdoes not set the hardirq count.
Quoted 5 lines
Quoted 3 lines
What is the best fix, change
BUILD_INTERRUPTto adjust the hardirq count or audit all the C handlers to ensure that they callirq_enter()?The IPI handlers run with IRQs disabled. Do we need a fix?
Some IPI handlers issue irq_enter() to bump hard_irq_count, some IPI handlers do not. It is inconsistent, with no obvious reason for doing it either way. All the external irqs go via do_IRQ which does issue irq_enter(). I guess that my real question is why are some IPIs not using irq_enter()? The lack of consistency concerns me.