Skip to contentSkip to conversation

x86, kdump: No need to disable ioapic in crash path

PATCH Superseded Don Zickus 3 participants 8 messages Feb 2, 2012 – Feb 9, 2012

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Don Zickus

author
#0 lore raw

PATCH 1/1 x86, kdump: No need to disable ioapic in crash path

A customer of ours noticed when their machine crashed, kdump did not work but hung instead. Using their firmware dumping solution they grabbed a vmcore and decoded the stacks on the cpus. What they noticed seemed to be a rare deadlock with the ioapic_lock.

CPU4:
machine_crash_shutdown
-> machine_ops.crash_shutdown

    -> native_machine_crash_shutdown
       -> kdump_nmi_shootdown_cpus ------> Send NMI to other CPUs
       -> disable_IO_APIC
          -> clear_IO_APIC
             -> clear_IO_APIC_pin
                -> ioapic_read_entry
                   -> spin_lock_irqsave(&ioapic_lock, flags)
                   ---Infinite loop here---

CPU0:
do_IRQ
-> handle_irq

    -> handle_edge_irq
        -> ack_apic_edge
           -> move_native_irq
               -> mask_IO_APIC_irq
                  -> mask_IO_APIC_irq_desc
                     -> spin_lock_irqsave(&ioapic_lock, flags)
                     ---Receive NMI here after getting spinlock---
                        -> nmi
                           -> do_nmi
                              -> crash_nmi_callback
                              ---Infinite loop here---

The problem is that although kdump tries to shutdown minimal hardware, it still needs to disable the IO APIC. This requires spinlocks which may be held by another cpu. This other cpu is being held infinitely in an NMI context by kdump in order to serialize the crashing path. Instant deadlock.

Eric, brought up a point that because the boot code was restructured we may not need to disable the io apic any more in the crash path. The original concern that led to the development of disable_IO_APIC, was that the TSC calibration on boot up relied on the PIT timer for reference. Access to the PIT required 8259 interrupts to be working. This wouldn't work if the ioapic needed to be configured. So on panic path, the ioapic was reconfigured to use virtual wire mode to allow the 8259 to passthrough.

Those concerns don't hold true now, thanks to the fast TSC calibration code not needing the PIT. As a result, we can remove this call and simplify the locking needed in the panic path.

I tested kdump on an Ivy Bridge platform, a Pentium4 and an old athlon that did not have an ioapic. All three were successful.

Cc Eric W. Biederman <[email protected]>
Cc Vivek Goyal <[email protected]>

---
I will probably need some help with my explaination as to why this line is not needed. Any input is appreciated!

---
 arch/x86/kernel/crash.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
arch/x86/kernel/crash.c +0 -3
index 13ad899..b053cf9 100644
@@ -96,9 +96,6 @@ void native_machine_crash_shutdown(struct pt_regs *regs)
 	cpu_emergency_svm_disable();
 
 	lapic_shutdown();
-#if defined(CONFIG_X86_IO_APIC)
-	disable_IO_APIC();
-#endif
 #ifdef CONFIG_HPET_TIMER
 	hpet_disable();
 #endif
Signature · 7 lines
1.7.7.6


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw
Quoted 38 lines · Don Zickus

A customer of ours noticed when their machine crashed, kdump did not work but hung instead. Using their firmware dumping solution they grabbed a vmcore and decoded the stacks on the cpus. What they noticed seemed to be a rare deadlock with the ioapic_lock.

CPU4:
machine_crash_shutdown
-> machine_ops.crash_shutdown

    -> native_machine_crash_shutdown
       -> kdump_nmi_shootdown_cpus ------> Send NMI to other CPUs
       -> disable_IO_APIC
          -> clear_IO_APIC
             -> clear_IO_APIC_pin
                -> ioapic_read_entry
                   -> spin_lock_irqsave(&ioapic_lock, flags)
                   ---Infinite loop here---

CPU0:
do_IRQ
-> handle_irq

    -> handle_edge_irq
        -> ack_apic_edge
           -> move_native_irq
               -> mask_IO_APIC_irq
                  -> mask_IO_APIC_irq_desc
                     -> spin_lock_irqsave(&ioapic_lock, flags)
                     ---Receive NMI here after getting spinlock---
                        -> nmi
                           -> do_nmi
                              -> crash_nmi_callback
                              ---Infinite loop here---

The problem is that although kdump tries to shutdown minimal hardware, it still needs to disable the IO APIC. This requires spinlocks which may be held by another cpu. This other cpu is being held infinitely in an NMI context by kdump in order to serialize the crashing path. Instant deadlock.

Quoted 7 lines

Eric, brought up a point that because the boot code was restructured we may not need to disable the io apic any more in the crash path. The original concern that led to the development of disable_IO_APIC, was that the TSC calibration on boot up relied on the PIT timer for reference. Access to the PIT required 8259 interrupts to be working. This wouldn't work if the ioapic needed to be configured. So on panic path, the ioapic was reconfigured to use virtual wire mode to allow the 8259 to passthrough.

A small clarification originally it was the jiffies calibration that would fail if we could cause the PIT to generate interrupts through the 8259. The boot would then hang at calibrating jiffies.

Quoted 7 lines

Those concerns don't hold true now, thanks to the fast TSC calibration code not needing the PIT. As a result, we can remove this call and simplify the locking needed in the panic path.

I tested kdump on an Ivy Bridge platform, a Pentium4 and an old athlon that did not have an ioapic. All three were successful.

Quoted 7 lines
Cc Eric W. Biederman <[email protected]>
Cc Vivek Goyal <[email protected]>

---
I will probably need some help with my explaination as to why this line is not needed. Any input is appreciated!

Can you test and verify that we also do not need the lapic_shutdown() call and the disable_local_APIC call on the other processors. The same reasoning that supports us not needing to disable the IO_APIC also supports us not needing to disable local apic.

Removing disable_IO_APIC in and of itself and then booting isn't quite sufficient as a practical test to prove this code always works. Sometimes the IOAPIC was not hooked up to interesting interrupt sources like the 8259.

Eric

Quoted 9 lines
---
 arch/x86/kernel/crash.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
arch/x86/kernel/crash.c +0 -0
index 13ad899..b053cf9 100644

arch/x86/kernel/crash.c void native_machine_crash_shutdown(struct pt_regs *regs) · line 101

Quoted 9 lines
arch/x86/kernel/crash.c +0 -3
@@ -96,9 +96,6 @@ void native_machine_crash_shutdown(struct pt_regs *regs)
 	cpu_emergency_svm_disable();
 
 	lapic_shutdown();
-#if defined(CONFIG_X86_IO_APIC)
-	disable_IO_APIC();
-#endif
 #ifdef CONFIG_HPET_TIMER
 	hpet_disable();
 #endif

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

author
#2 lore raw
Quoted 11 lines · Eric W. Biederman
Quoted 7 lines

Eric, brought up a point that because the boot code was restructured we may not need to disable the io apic any more in the crash path. The original concern that led to the development of disable_IO_APIC, was that the TSC calibration on boot up relied on the PIT timer for reference. Access to the PIT required 8259 interrupts to be working. This wouldn't work if the ioapic needed to be configured. So on panic path, the ioapic was reconfigured to use virtual wire mode to allow the 8259 to passthrough.

A small clarification originally it was the jiffies calibration that would fail if we could cause the PIT to generate interrupts through the 8259. The boot would then hang at calibrating jiffies.

Ok. Thanks!

Quoted 12 lines
Quoted 12 lines

Those concerns don't hold true now, thanks to the fast TSC calibration code not needing the PIT. As a result, we can remove this call and simplify the locking needed in the panic path.

I tested kdump on an Ivy Bridge platform, a Pentium4 and an old athlon that did not have an ioapic. All three were successful.

Cc Eric W. Biederman <[email protected]>
Cc Vivek Goyal <[email protected]>
Quoted 8 lines
Quoted 3 lines

---
I will probably need some help with my explaination as to why this line is not needed. Any input is appreciated!

Can you test and verify that we also do not need the lapic_shutdown() call and the disable_local_APIC call on the other processors. The same reasoning that supports us not needing to disable the IO_APIC also supports us not needing to disable local apic.

I did that and it seemed to work on my Ivy Bridge and core2 quad systems.

Quoted 5 lines

Removing disable_IO_APIC in and of itself and then booting isn't quite sufficient as a practical test to prove this code always works. Sometimes the IOAPIC was not hooked up to interesting interrupt sources like the 8259.

So what systems should I look for to test?

Cheers,
Don

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw
Quoted 9 lines · Don Zickus
Quoted 8 lines · Eric W. Biederman
Quoted 7 lines

Eric, brought up a point that because the boot code was restructured we may not need to disable the io apic any more in the crash path. The original concern that led to the development of disable_IO_APIC, was that the TSC calibration on boot up relied on the PIT timer for reference. Access to the PIT required 8259 interrupts to be working. This wouldn't work if the ioapic needed to be configured. So on panic path, the ioapic was reconfigured to use virtual wire mode to allow the 8259 to passthrough.

Quoted 5 lines
Quoted 3 lines

A small clarification originally it was the jiffies calibration that would fail if we could cause the PIT to generate interrupts through the 8259. The boot would then hang at calibrating jiffies.

Ok. Thanks!

So now what has changed? Do we setup LAPIC and IOAPIC early enough to receive PIT interrupts in regular mode (non-virtual wire mode) or something else?

Thanks
Vivek

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw
Quoted 14 lines · Vivek Goyal
Quoted 13 lines · Don Zickus
Quoted 11 lines · Eric W. Biederman
Quoted 7 lines

Eric, brought up a point that because the boot code was restructured we may not need to disable the io apic any more in the crash path. The original concern that led to the development of disable_IO_APIC, was that the TSC calibration on boot up relied on the PIT timer for reference. Access to the PIT required 8259 interrupts to be working. This wouldn't work if the ioapic needed to be configured. So on panic path, the ioapic was reconfigured to use virtual wire mode to allow the 8259 to passthrough.

A small clarification originally it was the jiffies calibration that would fail if we could cause the PIT to generate interrupts through the 8259. The boot would then hang at calibrating jiffies.

Quoted 5 lines
Quoted 1 line

Ok. Thanks!

So now what has changed? Do we setup LAPIC and IOAPIC early enough to receive PIT interrupts in regular mode (non-virtual wire mode) or something else?

Yes. Part of the Moorstown work required that this be done because moorsetown did not support legacy mode. Last I looked the code hadn't been generalized beyond Moorsetown but empirically it works now.

Don as to what to test the only case I can think of that might be spooky is a screaming interrupt during the handover. You might want to try playing with lkcdtm to try some of the more exotic crash scenarios. But all I expect further testing might reveal are places where we are not as robust in initializing the hardware as we might be. Things that might have been papered over by the ioapic shutdown.

I think we are good to remove my ancient hack of disabling the ioapics, and putting the system into PIT during the crash kernel switchover.

Eric

author
#5 lore raw
Quoted 26 lines · Eric W. Biederman
Quoted 14 lines · Vivek Goyal
Quoted 13 lines · Don Zickus
Quoted 11 lines · Eric W. Biederman
Quoted 7 lines

Eric, brought up a point that because the boot code was restructured we may not need to disable the io apic any more in the crash path. The original concern that led to the development of disable_IO_APIC, was that the TSC calibration on boot up relied on the PIT timer for reference. Access to the PIT required 8259 interrupts to be working. This wouldn't work if the ioapic needed to be configured. So on panic path, the ioapic was reconfigured to use virtual wire mode to allow the 8259 to passthrough.

A small clarification originally it was the jiffies calibration that would fail if we could cause the PIT to generate interrupts through the 8259. The boot would then hang at calibrating jiffies.

Quoted 5 lines
Quoted 1 line

Ok. Thanks!

So now what has changed? Do we setup LAPIC and IOAPIC early enough to receive PIT interrupts in regular mode (non-virtual wire mode) or something else?

Yes. Part of the Moorstown work required that this be done because moorsetown did not support legacy mode. Last I looked the code hadn't been generalized beyond Moorsetown but empirically it works now.

Quoted 6 lines

Don as to what to test the only case I can think of that might be spooky is a screaming interrupt during the handover. You might want to try playing with lkcdtm to try some of the more exotic crash scenarios. But all I expect further testing might reveal are places where we are not as robust in initializing the hardware as we might be. Things that might have been papered over by the ioapic shutdown.

I ran lkdtm by panic'ing in the interrupt handle thus leaving device interrupt un-ack'd and the apic might have been un-ack'd too (jprobes hooked in at do_IRQ). 3 out 3 times the second kernel came up on my core2 quad.

Cheers,
Don

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw
Quoted 34 lines · Don Zickus
Quoted 26 lines · Eric W. Biederman
Quoted 14 lines · Vivek Goyal
Quoted 13 lines · Don Zickus
Quoted 11 lines · Eric W. Biederman
Quoted 7 lines

Eric, brought up a point that because the boot code was restructured we may not need to disable the io apic any more in the crash path. The original concern that led to the development of disable_IO_APIC, was that the TSC calibration on boot up relied on the PIT timer for reference. Access to the PIT required 8259 interrupts to be working. This wouldn't work if the ioapic needed to be configured. So on panic path, the ioapic was reconfigured to use virtual wire mode to allow the 8259 to passthrough.

A small clarification originally it was the jiffies calibration that would fail if we could cause the PIT to generate interrupts through the 8259. The boot would then hang at calibrating jiffies.

Quoted 5 lines
Quoted 1 line

Ok. Thanks!

So now what has changed? Do we setup LAPIC and IOAPIC early enough to receive PIT interrupts in regular mode (non-virtual wire mode) or something else?

Yes. Part of the Moorstown work required that this be done because moorsetown did not support legacy mode. Last I looked the code hadn't been generalized beyond Moorsetown but empirically it works now.

Quoted 6 lines

Don as to what to test the only case I can think of that might be spooky is a screaming interrupt during the handover. You might want to try playing with lkcdtm to try some of the more exotic crash scenarios. But all I expect further testing might reveal are places where we are not as robust in initializing the hardware as we might be. Things that might have been papered over by the ioapic shutdown.

Quoted 4 lines

I ran lkdtm by panic'ing in the interrupt handle thus leaving device interrupt un-ack'd and the apic might have been un-ack'd too (jprobes hooked in at do_IRQ). 3 out 3 times the second kernel came up on my core2 quad.

That sounds like more than enough basic testing for me. Document your testing in a patch description and let's get the unnecessary local apic and ioapic stomping removed from the kexec on panic path.

There were bugs. We deleted the code that had them. The bugs are gone and there are no new problems goes over very well in my book.

Eric

author
#7 lore raw
Quoted 11 lines · Eric W. Biederman
Quoted 4 lines

I ran lkdtm by panic'ing in the interrupt handle thus leaving device interrupt un-ack'd and the apic might have been un-ack'd too (jprobes hooked in at do_IRQ). 3 out 3 times the second kernel came up on my core2 quad.

That sounds like more than enough basic testing for me. Document your testing in a patch description and let's get the unnecessary local apic and ioapic stomping removed from the kexec on panic path.

There were bugs. We deleted the code that had them. The bugs are gone and there are no new problems goes over very well in my book.

Great. Thanks. I'll put together the patch.

Cheers,
Don

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec