Skip to contentSkip to conversation

i386 IPI handlers running with hardirq_count == 0

DISCUSSION Keith Owens 4 participants 8 messages Jun 29, 2006

lore
Share & tools
lore
#0 lore raw

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()?

#1 lore raw
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_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()?

The IPI handlers run with IRQs disabled. Do we need a fix?

#2 lore raw
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_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.

Quoted 5 lines
Quoted 3 lines

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()?

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

#3 lore raw
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_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.

Quoted 5 lines
Quoted 3 lines

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()?

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.

#4 lore raw
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_64 function irq_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

#5 lore raw
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_64 function irq_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.

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.

#6 lore raw
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. But preempt_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

#7 lore raw
In reply to Andrew Morton
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_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.

Quoted 5 lines
Quoted 3 lines

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()?

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.