x86/kdump: No need to disable ioapic/ lapic in crash path
Subsystems (3)
Commit-ID: d9bc9be89629445758670220787683e37c93f6c1 Gitweb: http://git.kernel.org/tip/d9bc9be89629445758670220787683e37c93f6c1 Author: Don Zickus <[email protected]> AuthorDate: Thu, 9 Feb 2012 16:53:41 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 11 Feb 2012 15:38:53 +0100
x86/kdump: No need to disable ioapic/lapic 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 jiffies 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 jiffies calibration code not needing the PIT. As a result, we can remove this call and simplify the locking needed in the panic path.
The same work allowed us to remove the need to disable the local apic on shutdown too. This should allow us to jump to the second a little faster.
I tested kdump on an Ivy Bridge platform, a Pentium4 and an old athlon that did not have an ioapic. All three were successful.
I also tested using lkdtm that would use jprobes to panic the system when entering do_IRQ. The idea was to see how the system reacted with an interrupt pending in the second kernel. My core2 quad successfully kdump'd 3 times in a row with no issues.
v2: removed the disable lapic code too
--- arch/x86/kernel/crash.c | 8 -------- 1 files changed, 0 insertions(+), 8 deletions(-)
arch/x86/kernel/crash.c +0 -8
@@ -54,16 +54,12 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)*/ cpu_emergency_vmxoff (); cpu_emergency_svm_disable(); - - disable_local_APIC(); }static void kdump_nmi_shootdown_cpus (void ) { in_crash_kexec =1 ;nmi_shootdown_cpus (kdump_nmi_callback); - -disable_local_APIC (); }#else
@@ -95,10 +91,6 @@ void native_machine_crash_shutdown(struct pt_regs *regs)cpu_emergency_vmxoff ();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
Quoted 69 lines · tip-bot for Don Zickus
Commit-ID: d9bc9be89629445758670220787683e37c93f6c1
Gitweb: http://git.kernel.org/tip/d9bc9be89629445758670220787683e37c93f6c1
Author: Don Zickus <[email protected]>
AuthorDate: Thu, 9 Feb 2012 16:53:41 -0500
Committer: Ingo Molnar <[email protected]>
CommitDate: Sat, 11 Feb 2012 15:38:53 +0100x86/kdump: No need to disable ioapic/lapic 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 ofdisable_IO_APIC, was that the jiffies 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 jiffies calibration code not needing the PIT. As a result, we can remove this call and simplify the locking needed in the panic path.
The same work allowed us to remove the need to disable the local apic on shutdown too. This should allow us to jump to the second a little faster.
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 6 lines
I also tested using lkdtm that would use jprobes to panic the system when entering
do_IRQ. The idea was to see how the system reacted with an interrupt pending in the second kernel. My core2 quad successfully kdump'd 3 times in a row with no issues.v2: removed the disable lapic code too
with this commit, kdump is not working anymore on my setups with Nehalem, Westmere, sandbridge.
these setup all have VT-d enabled.
After reverting this commit, kdump is working again.
So assume you need to drop this patch.
Thanks
Yinghai Lu
Quoted 78 lines · Yinghai Lu
Quoted 69 lines · tip-bot for Don Zickus
Commit-ID: d9bc9be89629445758670220787683e37c93f6c1
Gitweb: http://git.kernel.org/tip/d9bc9be89629445758670220787683e37c93f6c1
Author: Don Zickus <[email protected]>
AuthorDate: Thu, 9 Feb 2012 16:53:41 -0500
Committer: Ingo Molnar <[email protected]>
CommitDate: Sat, 11 Feb 2012 15:38:53 +0100x86/kdump: No need to disable ioapic/lapic 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 ofdisable_IO_APIC, was that the jiffies 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 jiffies calibration code not needing the PIT. As a result, we can remove this call and simplify the locking needed in the panic path.
The same work allowed us to remove the need to disable the local apic on shutdown too. This should allow us to jump to the second a little faster.
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 6 lines
I also tested using lkdtm that would use jprobes to panic the system when entering
do_IRQ. The idea was to see how the system reacted with an interrupt pending in the second kernel. My core2 quad successfully kdump'd 3 times in a row with no issues.v2: removed the disable lapic code too
Quoted 8 lines
with this commit, kdump is not working anymore on my setups with Nehalem, Westmere, sandbridge.
these setup all have VT-d enabled.After reverting this commit, kdump is working again.
So assume you need to drop this patch.
It sounds like there is a bug in ioapic initialization in the context of VT-d. Where do you fail?
It would be much better to debug this than to blindly revert this patch, as this change has the potential to significantly increase the reliability of the kdump path.
Eric
Quoted 8 lines · Eric W. Biederman
Quoted 3 lines · Yinghai Lu
After reverting this commit, kdump is working again.
So assume you need to drop this patch.
It sounds like there is a bug in ioapic initialization in the context of VT-d. Where do you fail?
before get debug print out from second kernel, the system get reset.
Yinghai
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 11 lines · Yinghai Lu
Quoted 8 lines · Eric W. Biederman
Quoted 3 lines · Yinghai Lu
After reverting this commit, kdump is working again.
So assume you need to drop this patch.
It sounds like there is a bug in ioapic initialization in the context of VT-d. Where do you fail?
before get debug print out from second kernel, the system get reset.
Ouch.
Don can you work with with Yinghai to figure out what is different between your test configuration and his?
YH did you have early printk enabled?
YH Did I understand you properly that things work if you don't enable
VT-d? By VT-d are you referring to interrupt remapping?
For anyone watching. The premise of this patch was that we can boot the kernel without resorting to legacy tricks that require us to put the interrupt controllers in PIT mode.
Apparently there is some weird corner case that YH can reproduce that Don did not have in his test set that YH does that causes things to fail.
I really don't see any likely candidates when looking at the code. The most I can see is some code that we don't run when interrupt remapping is enabled in disable_IO_APIC.
So I suspect we have a bug in our apic initialization somewhere, but apic initialization should happen after printk are enabled. Or at least after early printks so the reset YH is reporting doesn't make much sense.
Eric
Quoted 12 lines · Eric W. Biederman
Quoted 10 lines · Yinghai Lu
Quoted 8 lines · Eric W. Biederman
Quoted 3 lines · Yinghai Lu
After reverting this commit, kdump is working again.
So assume you need to drop this patch.
It sounds like there is a bug in ioapic initialization in the context of VT-d. Where do you fail?
Quoted 8 lines
Quoted 1 line
before get debug print out from second kernel, the system get reset.
Ouch.
Don can you work with with Yinghai to figure out what is different between your test configuration and his?
YH did you have early printk enabled?
yes.
I always have "console=uart8250,io,0x3f8,115200n8" appended.
also i have local patches that print info from arch/x86/boot/compressed/misc.c::decompress_kernel() and arch/x86/kernel/head64.c::x86_64_start_kernel()
Quoted 3 lines
YH Did I understand you properly that things work if you don't enable VT-d?
that is default setting for BIOS and OS.
will check if disable that will help.
Quoted 1 line
By VT-d are you referring to interrupt remapping?
yes, include interrupt rempapping and dma remapping.
Quoted 9 lines
For anyone watching. The premise of this patch was that we can boot the kernel without resorting to legacy tricks that require us to put the interrupt controllers in PIT mode.
Apparently there is some weird corner case that YH can reproduce that Don did not have in his test set that YH does that causes things to fail.
Quoted 7 lines
I really don't see any likely candidates when looking at the code. The most I can see is some code that we don't run when interrupt remapping is enabled in
disable_IO_APIC.So I suspect we have a bug in our apic initialization somewhere, but apic initialization should happen after printk are enabled. Or at least after early printks so the reset YH is reporting doesn't make much sense.
will try Don's first version patch that only removing disable_IO_APIC.
Yinghai
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 5 lines · Yinghai Lu
Quoted 3 lines
So I suspect we have a bug in our apic initialization somewhere, but apic initialization should happen after printk are enabled. Or at least after early printks so the reset YH is reporting doesn't make much sense.
will try Don's first version patch that only removing
disable_IO_APIC.
first version patch (only removing disable_IO_APIC) is working.
Thanks
Yinghai
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 8 lines · Yinghai Lu
Quoted 5 lines · Yinghai Lu
Quoted 3 lines
So I suspect we have a bug in our apic initialization somewhere, but apic initialization should happen after printk are enabled. Or at least after early printks so the reset YH is reporting doesn't make much sense.
will try Don's first version patch that only removing
disable_IO_APIC.first version patch (only removing
disable_IO_APIC) is working.
So I think I figured it out. I went through and commented out code in disable_local_APIC until I narrowed it down to the piece of code that needs to be disabled for it to work.
Surprise, surprise... its LVTPC or perf! :-) Actually it is the nmi_watchdog which uses perf. My theory is NMIs are not disabled and one is generated by the local apic during decompression (just bad timing) and *splat*.
Yinghai, you can probably prove this by
echo 0 > /proc/sys/kernel/nmi_watchdog
then do your kdump crash test.
At least that test worked for me.
So either we explicitly shutdown perf or just mask off LVTPC in a modified disable_local_APIC?
Eric, thoughts, preferences?
Cheers,
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 9 lines · Don Zickus
So I think I figured it out. I went through and commented out code in
disable_local_APICuntil I narrowed it down to the piece of code that needs to be disabled for it to work.Surprise, surprise... its LVTPC or perf! :-) Actually it is the
nmi_watchdogwhich uses perf. My theory is NMIs are not disabled and one is generated by the local apic during decompression (just bad timing) and *splat*.
Quoted 5 lines
Yinghai, you can probably prove this by
echo 0 >
/proc/sys/kernel/nmi_watchdogthen do your kdump crash test.
yes. that will make kdump crash working.
Yinghai
Quoted 11 lines · Yinghai Lu
Quoted 9 lines · Don Zickus
So I think I figured it out. I went through and commented out code in
disable_local_APICuntil I narrowed it down to the piece of code that needs to be disabled for it to work.Surprise, surprise... its LVTPC or perf! :-) Actually it is the
nmi_watchdogwhich uses perf. My theory is NMIs are not disabled and one is generated by the local apic during decompression (just bad timing) and *splat*.
Quoted 7 lines
Quoted 5 lines
Yinghai, you can probably prove this by
echo 0 >
/proc/sys/kernel/nmi_watchdogthen do your kdump crash test.
yes. that will make kdump crash working.
Cool. Thanks.
Eric,
Just let me know how you want to handle disabling NMIs in the kexec in panic shutdown case.
Cheers,
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 18 lines · Don Zickus
Quoted 17 lines · Yinghai Lu
Quoted 14 lines · Don Zickus
So I think I figured it out. I went through and commented out code in
disable_local_APICuntil I narrowed it down to the piece of code that needs to be disabled for it to work.Surprise, surprise... its LVTPC or perf! :-) Actually it is the
nmi_watchdogwhich uses perf. My theory is NMIs are not disabled and one is generated by the local apic during decompression (just bad timing) and *splat*.Yinghai, you can probably prove this by
echo 0 >
/proc/sys/kernel/nmi_watchdogthen do your kdump crash test.
Quoted 8 lines
Quoted 1 line
yes. that will make kdump crash working.
Cool. Thanks.
Eric,
Just let me know how you want to handle disabling NMIs in the kexec in panic shutdown case.
Interesting. Apparently we have been avoiding this problem by accident.
Thanks for hunting this down.
The options I can see are:
- Ensure we can handle and ignore exceptions like this.
- Always shutoff the lapic and ioapic entries that can generate this.
The good news is that both solutions should be lock free.
The current kernel boot code relies on the assumption that all interrupts can be disabled. In this case with nmi's that is clearly not the case.
The most robust solution and what we want to do long term is to install an idt that will simply ignore all interrupts until the idt is replaced. Since really all we need to deal with is the NMI vector, which is vector #2, we can have a very small interrupt descriptor table.
Unfortunately we go through some cpu mode switches in /sbin/kexec, allowing us to enter the kernels 32bit entry point before we run the decompresser, so at first glance both /sbin/kexec and the kernel need to be fixed in a coordinated fashion.
There are two was I can see of removing the need for an exactly coordinated release.
- Document that an old /sbin/kexec userspace requires you not to use the nmi watchdog with modern kernels.
- For a short while simply retain code that stomps the nmi watchdog. (But still leaves us open to other kinds of nmi's).
Grr. Looking a little more closely, all throughout the linux kernel's boot there is the assumption that any interrupt during boot is a failure of some kind, and except for an errant nmi watchdog that is a true assumption.
Don I guess I really have to recommend disabling the nmi watchdog in the kexec on panic path if we can do so at all reasonably.
I like the idea of ignoring nmis during boot but that seems to be a slightly larger project and with little practical improvement in kexec on panic quality. Other than getting what should be one or two i/o writes out of the kexec on panic path.
Eric
Quoted 66 lines · [email protected] (Eric W. Biederman) writes:
Quoted 18 lines · Don Zickus
Quoted 17 lines · Yinghai Lu
Quoted 14 lines · Don Zickus
So I think I figured it out. I went through and commented out code in
disable_local_APICuntil I narrowed it down to the piece of code that needs to be disabled for it to work.Surprise, surprise... its LVTPC or perf! :-) Actually it is the
nmi_watchdogwhich uses perf. My theory is NMIs are not disabled and one is generated by the local apic during decompression (just bad timing) and *splat*.Yinghai, you can probably prove this by
echo 0 >
/proc/sys/kernel/nmi_watchdogthen do your kdump crash test.
Quoted 8 lines
Quoted 1 line
yes. that will make kdump crash working.
Cool. Thanks.
Eric,
Just let me know how you want to handle disabling NMIs in the kexec in panic shutdown case.
Interesting. Apparently we have been avoiding this problem by accident.
Thanks for hunting this down.
The options I can see are:
- Ensure we can handle and ignore exceptions like this.
- Always shutoff the lapic and ioapic entries that can generate this.The good news is that both solutions should be lock free.
The current kernel boot code relies on the assumption that all interrupts can be disabled. In this case with nmi's that is clearly not the case.
The most robust solution and what we want to do long term is to install an idt that will simply ignore all interrupts until the idt is replaced. Since really all we need to deal with is the NMI vector, which is vector #2, we can have a very small interrupt descriptor table.
Unfortunately we go through some cpu mode switches in
/sbin/kexec, allowing us to enter the kernels 32bit entry point before we run the decompresser, so at first glance both/sbin/kexecand the kernel need to be fixed in a coordinated fashion.There are two was I can see of removing the need for an exactly coordinated release.
- Document that an old/sbin/kexecuserspace requires you not to use the nmi watchdog with modern kernels.
- For a short while simply retain code that stomps the nmi watchdog. (But still leaves us open to other kinds of nmi's).Grr. Looking a little more closely, all throughout the linux kernel's boot there is the assumption that any interrupt during boot is a failure of some kind, and except for an errant nmi watchdog that is a true assumption.
Quoted 7 lines
Don I guess I really have to recommend disabling the nmi watchdog in the kexec on panic path if we can do so at all reasonably.
I like the idea of ignoring nmis during boot but that seems to be a slightly larger project and with little practical improvement in kexec on panic quality. Other than getting what should be one or two i/o writes out of the kexec on panic path.
Hmm.
Thinking about it a little more. The kernel's boot path is inconsistent with the rest of the kernel's nmi handling. For anything exception except an nmi stopping and giving up is fine. For an nmi it is very rare for an NMI to signal a truly nasty failure (usually it just means someone saw a bitflip somewhere), and we can almost always continue without problem.
I think in practice we really should make our boot path consistent with the rest of the kernel and ignore/log/report nmis but not fail on them. Triple faulting (trigger a cpu reset) as we do today just seems like a recipe for deep and confusing mystery, and not being helpful to the user.
My preferred fix would be to fix the boot path and /sbin/kexec to ignore and report nmis as we boot, as that is really what we want long term and it gives us the most robust solution.
The fix with a guarantee of no more scope creep is to just disable the nmi watchdog on the kexec on panic path.
Don if you have time please figure out is needed to ignore nmi's and possible record and/or report them while we boot, otherwise please cook up a patch that just disables the nmi watchdog wherever we are sending it from (the local apic or the ioapic).
Eric
2012/2/17 Eric W. Biederman <[email protected]>:
Quoted 98 lines
Quoted 66 lines · [email protected] (Eric W. Biederman) writes:
Quoted 18 lines · Don Zickus
Quoted 17 lines · Yinghai Lu
Quoted 14 lines · Don Zickus
So I think I figured it out. I went through and commented out code in
disable_local_APICuntil I narrowed it down to the piece of code that needs to be disabled for it to work.Surprise, surprise... its LVTPC or perf! :-) Actually it is the
nmi_watchdogwhich uses perf. My theory is NMIs are not disabled and one is generated by the local apic during decompression (just bad timing) and *splat*.Yinghai, you can probably prove this by
echo 0 >
/proc/sys/kernel/nmi_watchdogthen do your kdump crash test.
Quoted 8 lines
Quoted 1 line
yes. that will make kdump crash working.
Cool. Thanks.
Eric,
Just let me know how you want to handle disabling NMIs in the kexec in panic shutdown case.
Interesting. Apparently we have been avoiding this problem by accident.
Thanks for hunting this down.
The options I can see are:
- Ensure we can handle and ignore exceptions like this.
- Always shutoff the lapic and ioapic entries that can generate this.The good news is that both solutions should be lock free.
The current kernel boot code relies on the assumption that all interrupts can be disabled. In this case with nmi's that is clearly not the case.
The most robust solution and what we want to do long term is to install an idt that will simply ignore all interrupts until the idt is replaced. Since really all we need to deal with is the NMI vector, which is vector #2, we can have a very small interrupt descriptor table.
Unfortunately we go through some cpu mode switches in
/sbin/kexec, allowing us to enter the kernels 32bit entry point before we run the decompresser, so at first glance both/sbin/kexecand the kernel need to be fixed in a coordinated fashion.There are two was I can see of removing the need for an exactly coordinated release.
- Document that an old/sbin/kexecuserspace requires you not to use the nmi watchdog with modern kernels.
- For a short while simply retain code that stomps the nmi watchdog. (But still leaves us open to other kinds of nmi's).Grr. Looking a little more closely, all throughout the linux kernel's boot there is the assumption that any interrupt during boot is a failure of some kind, and except for an errant nmi watchdog that is a true assumption.
Quoted 7 lines
Don I guess I really have to recommend disabling the nmi watchdog in the kexec on panic path if we can do so at all reasonably.
I like the idea of ignoring nmis during boot but that seems to be a slightly larger project and with little practical improvement in kexec on panic quality. Other than getting what should be one or two i/o writes out of the kexec on panic path.
Hmm.
Thinking about it a little more. The kernel's boot path is inconsistent with the rest of the kernel's nmi handling. For anything exception except an nmi stopping and giving up is fine. For an nmi it is very rare for an NMI to signal a truly nasty failure (usually it just means someone saw a bitflip somewhere), and we can almost always continue without problem.
I think in practice we really should make our boot path consistent with the rest of the kernel and ignore/log/report nmis but not fail on them. Triple faulting (trigger a cpu reset) as we do today just seems like a recipe for deep and confusing mystery, and not being helpful to the user.
My preferred fix would be to fix the boot path and
/sbin/kexecto ignore and report nmis as we boot, as that is really what we want long term and it gives us the most robust solution.The fix with a guarantee of no more scope creep is to just disable the nmi watchdog on the kexec on panic path.
Quoted 6 lines
Don if you have time please figure out is needed to ignore nmi's and possible record and/or report them while we boot, otherwise please cook up a patch that just disables the nmi watchdog wherever we are sending it from (the local apic or the ioapic).
Eric
A few days ago I investigted the case where system is reseted due to triple fault caused by the NMI after idt is disabled in machine_kexec. I didn't see the reset when trigering the kdump with NMI since the NMI is masked until next iret instruction executed as described in 6.7.2. Handling Multiple NMIs of Intel Manual Vol.3A. The NMI mask remains untill the first iret execution on the 2nd
kernel: just the return path of the first kernel_thread invocation for init process. The exact path is:
switch_to
-> ret_from_fork
-> int_ret_from_sys_call
-> retint_restore_args
-> irq_returnAt that phase idt is already set up and kdump works.
Quoted 1 line
From the discussion I interpret kdump doesn't assume this behaviour,
right?
BTW, does anyone know the detail of the NMI mask? I couldn't figure out about it from the Intel spec more than ``certain hardware conditions''... I expect those who look at here are x86 NMI experts.
Thanks.
HATAYAMA, Daisuke
Quoted 8 lines · HATAYAMA Daisuke
A few days ago I investigted the case where system is reseted due to triple fault caused by the NMI after idt is disabled in
machine_kexec. I didn't see the reset when trigering the kdump with NMI since the NMI is masked until next iret instruction executed as described in 6.7.2. Handling Multiple NMIs of Intel Manual Vol.3A. The NMI mask remains untill the first iret execution on the 2nd
kernel: just the return path of the firstkernel_threadinvocation for init process. The exact path is:
hmm. So even though the local apic was disabled you still got an NMI? That could have been from an external NMI. I forget how that is wired up, if it goes through the IOAPIC to the Local APIC or directly to the NMI pin on the cpu.
Quoted 11 lines
switch_to
->ret_from_fork-> int_ret_from_sys_call -> retint_restore_args -> irq_returnAt that phase idt is already set up and kdump works.
From the discussion I interpret kdump doesn't assume this behaviour, right?
probably not.
Quoted 4 lines
BTW, does anyone know the detail of the NMI mask? I couldn't figure out about it from the Intel spec more than ``certain hardware conditions''... I expect those who look at here are x86 NMI experts.
I don't understand the question.
Cheers,
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
From: Don Zickus <[email protected]>
Subject: Re: [tip:x86/debug] x86/kdump: No need to disable ioapic/ lapic in crash path
Date: Fri, 17 Feb 2012 15:18:42 -0500
Quoted 10 lines · HATAYAMA Daisuke
Quoted 8 lines
A few days ago I investigted the case where system is reseted due to triple fault caused by the NMI after idt is disabled in
machine_kexec. I didn't see the reset when trigering the kdump with NMI since the NMI is masked until next iret instruction executed as described in 6.7.2. Handling Multiple NMIs of Intel Manual Vol.3A. The NMI mask remains untill the first iret execution on the 2nd
kernel: just the return path of the firstkernel_threadinvocation for init process. The exact path is:
Quoted 5 lines
hmm. So even though the local apic was disabled you still got an NMI? That could have been from an external NMI. I forget how that is wired up, if it goes through the IOAPIC to the Local APIC or directly to the NMI pin on the cpu.
Please don't confused. I used RHEL kernels based on 2.6.18 and 2.6.32. I didn't use the patch disabling local apic.
Quoted 7 lines
Quoted 7 lines
switch_to
->ret_from_fork-> int_ret_from_sys_call -> retint_restore_args -> irq_return
Quoted 7 lines
Quoted 4 lines
At that phase idt is already set up and kdump works.
From the discussion I interpret kdump doesn't assume this behaviour, right?
probably not.
Thanks.
Quoted 10 lines
Quoted 4 lines
BTW, does anyone know the detail of the NMI mask? I couldn't figure out about it from the Intel spec more than ``certain hardware conditions''... I expect those who look at here are x86 NMI experts.
I don't understand the question.
Cheers,
Don
Fig 10-4 explaining Local APIC Structure says INIT/NMI/SMI are directly sent to CPU Core, but the later part of this route is not explained formally anyware. Only the explanation is the sentence in 6.7 Nonmaskable Interrupt (NMI):
The processor also invokes certain hardware conditions to insure that no other interrupts, including NMI interrupts, are received until the NMI handler has completed executing.
I'm just wondering if this is explained more formally anyware.
Thanks.
HATAYAMA, Daisuke
Quoted 14 lines · HATAYAMA Daisuke
From: Don Zickus <[email protected]>
Subject: Re: [tip:x86/debug] x86/kdump: No need to disable ioapic/ lapic in crash path
Date: Fri, 17 Feb 2012 15:18:42 -0500Quoted 10 lines · HATAYAMA Daisuke
Quoted 8 lines
A few days ago I investigted the case where system is reseted due to triple fault caused by the NMI after idt is disabled in
machine_kexec. I didn't see the reset when trigering the kdump with NMI since the NMI is masked until next iret instruction executed as described in 6.7.2. Handling Multiple NMIs of Intel Manual Vol.3A. The NMI mask remains untill the first iret execution on the 2nd
kernel: just the return path of the firstkernel_threadinvocation for init process. The exact path is:
Quoted 8 lines
Quoted 5 lines
hmm. So even though the local apic was disabled you still got an NMI? That could have been from an external NMI. I forget how that is wired up, if it goes through the IOAPIC to the Local APIC or directly to the NMI pin on the cpu.
Please don't confused. I used RHEL kernels based on 2.6.18 and 2.6.32. I didn't use the patch disabling local apic.
Sure. Those kernels should be using the 'disable_local_APIC' code. My patch just removed that call, IOW it stops disabling local apic or a simpler way is to say it keeps the local apic enabled.
My question stills stands then, you might have experienced an external NMI, but I am not entirely sure.
Quoted 34 lines
Quoted 8 lines
Quoted 8 lines
switch_to
->ret_from_fork-> int_ret_from_sys_call -> retint_restore_args -> irq_returnQuoted 7 lines
Quoted 4 lines
At that phase idt is already set up and kdump works.
From the discussion I interpret kdump doesn't assume this behaviour, right?
probably not.
Thanks.
Quoted 10 lines
Quoted 4 lines
BTW, does anyone know the detail of the NMI mask? I couldn't figure out about it from the Intel spec more than ``certain hardware conditions''... I expect those who look at here are x86 NMI experts.
I don't understand the question.
Cheers,
DonFig 10-4 explaining Local APIC Structure says INIT/NMI/SMI are directly sent to CPU Core, but the later part of this route is not explained formally anyware. Only the explanation is the sentence in 6.7 Nonmaskable Interrupt (NMI):
Quoted 5 lines
The processor also invokes certain hardware conditions to insure that no other interrupts, including NMI interrupts, are received until the NMI handler has completed executing.
I'm just wondering if this is explained more formally anyware.
It might be I just don't know where. I just view the NMI as an exception. Each cpu exception has a priority. NMI has a higher priority than interrupts but a lower priority that say INIT. Therefore when the cpu gets an exception it classifies it based on priority. Higher priorities will interrupt the current exception, such as NMI, while lower priorities will wait until the current exception is finished.
To me those would be the hardware conditions, but that is my interpretation.
Cheers,
Don
Quoted 4 lines
Thanks.
HATAYAMA, Daisuke
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 8 lines · Eric W. Biederman
The fix with a guarantee of no more scope creep is to just disable the nmi watchdog on the kexec on panic path.
Don if you have time please figure out is needed to ignore nmi's and possible record and/or report them while we boot, otherwise please cook up a patch that just disables the nmi watchdog wherever we are sending it from (the local apic or the ioapic).
Can I keep things even simpler? The original problem was the deadlock with the ioapic lock. We fixed that by removing the call to disable_IO_APIC(). Can we just leave the disable_local_APIC calls in there for now? Is there any real harm?
All this rewrite is going to take time which will delay fixing a current problem with kexec on panic, the ioapic deadlock.
Thoughts?
Cheers,
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 10 lines · Don Zickus
Quoted 8 lines · Eric W. Biederman
The fix with a guarantee of no more scope creep is to just disable the nmi watchdog on the kexec on panic path.
Don if you have time please figure out is needed to ignore nmi's and possible record and/or report them while we boot, otherwise please cook up a patch that just disables the nmi watchdog wherever we are sending it from (the local apic or the ioapic).
Quoted 7 lines
Can I keep things even simpler? The original problem was the deadlock with the ioapic lock. We fixed that by removing the call to
disable_IO_APIC(). Can we just leave thedisable_local_APICcalls in there for now? Is there any real harm?All this rewrite is going to take time which will delay fixing a current problem with kexec on panic, the ioapic deadlock.
Hmm.
My apologies I just realized that we can not disable the nmi watchdog safely in all cases. To avoid the deadlock we fundamentally can not write to the io_apic, because the locks are the io_apic write path. The nmi watchdog can be sourced from either the local apics or the io_apics. To disable the nmi_watchdog we need at least potentially to write io_apic.
So it appears to me that the only reasonable and robust thing we can do is to ignore nmis in the kexec on panic path.
So it looks to me that the only path forward at this point is to fix the other bug where an unexpected nmi will kill the kexec on panic boot.
I just took a look at the code in /sbin/kexec and that code does not in fact change the idt except when we switch to 16bit mode, which we definitely do not do in the kexec on panic case. So it appears that we don't need to coordinate an /sbin/kexec release with a kernel release to ignore nmis.
In fact it looks like we only need to fix the interrupt descriptors loaded in machine_kexec_64.c and head64.c to ignore nmis.
At which point we will have fixed two bugs and have a much more reliable kexec on panic implementation.
Eric
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 20 lines · Eric W. Biederman
Quoted 10 lines · Don Zickus
Quoted 8 lines · Eric W. Biederman
The fix with a guarantee of no more scope creep is to just disable the nmi watchdog on the kexec on panic path.
Don if you have time please figure out is needed to ignore nmi's and possible record and/or report them while we boot, otherwise please cook up a patch that just disables the nmi watchdog wherever we are sending it from (the local apic or the ioapic).
Quoted 7 lines
Can I keep things even simpler? The original problem was the deadlock with the ioapic lock. We fixed that by removing the call to
disable_IO_APIC(). Can we just leave thedisable_local_APICcalls in there for now? Is there any real harm?All this rewrite is going to take time which will delay fixing a current problem with kexec on panic, the ioapic deadlock.
Quoted 8 lines
Hmm.
My apologies I just realized that we can not disable the nmi watchdog safely in all cases. To avoid the deadlock we fundamentally can not write to the
io_apic, because the locks are theio_apicwrite path. The nmi watchdog can be sourced from either the local apics or theio_apics. To disable thenmi_watchdogwe need at least potentially to writeio_apic.
I am curious where you see the nmi watchdog being sourced from the ioapic? I thought I removed that code 3 or 4 releases ago.
Quoted 13 lines
So it appears to me that the only reasonable and robust thing we can do is to ignore nmis in the kexec on panic path.
So it looks to me that the only path forward at this point is to fix the other bug where an unexpected nmi will kill the kexec on panic boot.
I just took a look at the code in
/sbin/kexecand that code does not in fact change the idt except when we switch to 16bit mode, which we definitely do not do in the kexec on panic case. So it appears that we don't need to coordinate an/sbin/kexecrelease with a kernel release to ignore nmis.
Quoted 5 lines
In fact it looks like we only need to fix the interrupt descriptors loaded in
machine_kexec_64.candhead64.cto ignore nmis.At which point we will have fixed two bugs and have a much more reliable kexec on panic implementation.
Ok. I'll talk with Vivek about how the can be implemented.
Cheers.
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Don Zickus <[email protected]> writes:
Quoted 29 lines · Eric W. Biederman
Quoted 20 lines
Quoted 10 lines · Don Zickus
Quoted 8 lines · Eric W. Biederman
The fix with a guarantee of no more scope creep is to just disable the nmi watchdog on the kexec on panic path.
Don if you have time please figure out is needed to ignore nmi's and possible record and/or report them while we boot, otherwise please cook up a patch that just disables the nmi watchdog wherever we are sending it from (the local apic or the ioapic).
Quoted 7 lines
Can I keep things even simpler? The original problem was the deadlock with the ioapic lock. We fixed that by removing the call to
disable_IO_APIC(). Can we just leave thedisable_local_APICcalls in there for now? Is there any real harm?All this rewrite is going to take time which will delay fixing a current problem with kexec on panic, the ioapic deadlock.
Quoted 8 lines
Hmm.
My apologies I just realized that we can not disable the nmi watchdog safely in all cases. To avoid the deadlock we fundamentally can not write to the
io_apic, because the locks are theio_apicwrite path. The nmi watchdog can be sourced from either the local apics or theio_apics. To disable thenmi_watchdogwe need at least potentially to writeio_apic.
Quoted 2 lines
I am curious where you see the nmi watchdog being sourced from the ioapic? I thought I removed that code 3 or 4 releases ago.
In my memory, and in references to the code in comments in various apic related code. I couldn't figure out what the current code was doing and assumed the implementation was equivalent. It does look like you removed the code that used the io_apic. I still haven't figured out just how the new implementation works yet.
So maybe in the short term we can safely just stomp the timer that triggers the nmi watchdog in the local apic. Over the long term that feels like it is just asking for trouble.
I wonder if the reason that we have an hpet stomp in that code is for a similar reason. Did we ever source nmi's from the hpet timer?
Quoted 12 lines
Quoted 12 lines
So it appears to me that the only reasonable and robust thing we can do is to ignore nmis in the kexec on panic path.
So it looks to me that the only path forward at this point is to fix the other bug where an unexpected nmi will kill the kexec on panic boot.
I just took a look at the code in
/sbin/kexecand that code does not in fact change the idt except when we switch to 16bit mode, which we definitely do not do in the kexec on panic case. So it appears that we don't need to coordinate an/sbin/kexecrelease with a kernel release to ignore nmis.
Quoted 7 lines
Quoted 5 lines
In fact it looks like we only need to fix the interrupt descriptors loaded in
machine_kexec_64.candhead64.cto ignore nmis.At which point we will have fixed two bugs and have a much more reliable kexec on panic implementation.
Ok. I'll talk with Vivek about how the can be implemented.
Thanks. It really doesn't look very hard. Just a tiny idt with an nmi entry that says iret.
Eric
Quoted 32 lines · Eric W. Biederman
Don Zickus <[email protected]> writes:
Quoted 29 lines · Eric W. Biederman
Quoted 28 lines
Quoted 10 lines · Don Zickus
Quoted 8 lines · Eric W. Biederman
The fix with a guarantee of no more scope creep is to just disable the nmi watchdog on the kexec on panic path.
Don if you have time please figure out is needed to ignore nmi's and possible record and/or report them while we boot, otherwise please cook up a patch that just disables the nmi watchdog wherever we are sending it from (the local apic or the ioapic).
Quoted 7 lines
Can I keep things even simpler? The original problem was the deadlock with the ioapic lock. We fixed that by removing the call to
disable_IO_APIC(). Can we just leave thedisable_local_APICcalls in there for now? Is there any real harm?All this rewrite is going to take time which will delay fixing a current problem with kexec on panic, the ioapic deadlock.
Hmm.
My apologies I just realized that we can not disable the nmi watchdog safely in all cases. To avoid the deadlock we fundamentally can not write to the
io_apic, because the locks are theio_apicwrite path. The nmi watchdog can be sourced from either the local apics or theio_apics. To disable thenmi_watchdogwe need at least potentially to writeio_apic.
Quoted 8 lines
Quoted 2 lines
I am curious where you see the nmi watchdog being sourced from the ioapic? I thought I removed that code 3 or 4 releases ago.
In my memory, and in references to the code in comments in various apic related code. I couldn't figure out what the current code was doing and assumed the implementation was equivalent. It does look like you removed the code that used the
io_apic. I still haven't figured out just how the new implementation works yet.
It is just a client of perf now. Perf controls the local apic accesses. A lot simpler now.
Quoted 4 lines
So maybe in the short term we can safely just stomp the timer that triggers the nmi watchdog in the local apic. Over the long term that feels like it is just asking for trouble.
I can understand that.
Quoted 19 lines
I wonder if the reason that we have an hpet stomp in that code is for a similar reason. Did we ever source nmi's from the hpet timer?
Quoted 15 lines
Quoted 15 lines
So it appears to me that the only reasonable and robust thing we can do is to ignore nmis in the kexec on panic path.
So it looks to me that the only path forward at this point is to fix the other bug where an unexpected nmi will kill the kexec on panic boot.
I just took a look at the code in
/sbin/kexecand that code does not in fact change the idt except when we switch to 16bit mode, which we definitely do not do in the kexec on panic case. So it appears that we don't need to coordinate an/sbin/kexecrelease with a kernel release to ignore nmis.In fact it looks like we only need to fix the interrupt descriptors loaded in
machine_kexec_64.candhead64.cto ignore nmis.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
At which point we will have fixed two bugs and have a much more reliable kexec on panic implementation.
Ok. I'll talk with Vivek about how the can be implemented.
Thanks. It really doesn't look very hard. Just a tiny idt with an nmi entry that says iret.
It probably is, except I never hacked on idt code before and my assembly isn't that good. I have been trying to find examples to copy from to give it a try. So far I was using early_idt_handlers with early_printk to see if I could capture some printk messages while jumping from the first kernel to the second kernel (when the other early_idt_handlers would kick in for the second kernel).
Tips? Better examples?
Cheers,
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 79 lines · Don Zickus
Quoted 32 lines · Eric W. Biederman
Don Zickus <[email protected]> writes:
Quoted 29 lines · Eric W. Biederman
Quoted 28 lines
Quoted 10 lines · Don Zickus
Quoted 8 lines · Eric W. Biederman
The fix with a guarantee of no more scope creep is to just disable the nmi watchdog on the kexec on panic path.
Don if you have time please figure out is needed to ignore nmi's and possible record and/or report them while we boot, otherwise please cook up a patch that just disables the nmi watchdog wherever we are sending it from (the local apic or the ioapic).
Quoted 7 lines
Can I keep things even simpler? The original problem was the deadlock with the ioapic lock. We fixed that by removing the call to
disable_IO_APIC(). Can we just leave thedisable_local_APICcalls in there for now? Is there any real harm?All this rewrite is going to take time which will delay fixing a current problem with kexec on panic, the ioapic deadlock.
Hmm.
My apologies I just realized that we can not disable the nmi watchdog safely in all cases. To avoid the deadlock we fundamentally can not write to the
io_apic, because the locks are theio_apicwrite path. The nmi watchdog can be sourced from either the local apics or theio_apics. To disable thenmi_watchdogwe need at least potentially to writeio_apic.Quoted 8 lines
Quoted 2 lines
I am curious where you see the nmi watchdog being sourced from the ioapic? I thought I removed that code 3 or 4 releases ago.
In my memory, and in references to the code in comments in various apic related code. I couldn't figure out what the current code was doing and assumed the implementation was equivalent. It does look like you removed the code that used the
io_apic. I still haven't figured out just how the new implementation works yet.It is just a client of perf now. Perf controls the local apic accesses. A lot simpler now.
Quoted 4 lines
So maybe in the short term we can safely just stomp the timer that triggers the nmi watchdog in the local apic. Over the long term that feels like it is just asking for trouble.
I can understand that.
Quoted 19 lines
I wonder if the reason that we have an hpet stomp in that code is for a similar reason. Did we ever source nmi's from the hpet timer?
Quoted 15 lines
Quoted 15 lines
So it appears to me that the only reasonable and robust thing we can do is to ignore nmis in the kexec on panic path.
So it looks to me that the only path forward at this point is to fix the other bug where an unexpected nmi will kill the kexec on panic boot.
I just took a look at the code in
/sbin/kexecand that code does not in fact change the idt except when we switch to 16bit mode, which we definitely do not do in the kexec on panic case. So it appears that we don't need to coordinate an/sbin/kexecrelease with a kernel release to ignore nmis.In fact it looks like we only need to fix the interrupt descriptors loaded in
machine_kexec_64.candhead64.cto ignore nmis.Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
At which point we will have fixed two bugs and have a much more reliable kexec on panic implementation.
Ok. I'll talk with Vivek about how the can be implemented.
Thanks. It really doesn't look very hard. Just a tiny idt with an nmi entry that says iret.
Quoted 8 lines
It probably is, except I never hacked on idt code before and my assembly isn't that good. I have been trying to find examples to copy from to give it a try. So far I was using
early_idt_handlerswithearly_printkto see if I could capture some printk messages while jumping from the first kernel to the second kernel (when the otherearly_idt_handlerswould kick in for the second kernel).Tips? Better examples?
That is a particularly good example. When I took a quick look earlier that is the first place we reload the idt in the kernel boot so that is one of two places that needs to be modified.
The other place in the reboot code page (which will be a little tricky because of it's relocatability) needs to have code that roughly says:
kexec_nmi_handler:
; Does this vector get any other kind of parameters and saved ; registers that we need to restore?
; Different types of exceptions handlers have different rules ; that I don't remember off the top of my head. call gates, trap ; gates, etc.
iret
kexec_idt:
.long 0, 0 ; IDT entry 0 .long 0, 0 ; IDT entry 1 .long something, kexec_nmi_handler ; IDT entry 2 NMI's
You can write to the kexec_idt from C code and for the nmi handler you just need to make certain all is good.
The code has to be tested and the proper Intel CPU manual should probably be consulted to make certain you dot your eyes and cross your t's but we really don't need much code to change on this path.
Eric
p.s. Apologies for the delay I overlooked this message earlier.
Quoted 8 lines · Eric W. Biederman
Quoted 7 lines · Don Zickus
It probably is, except I never hacked on idt code before and my assembly isn't that good. I have been trying to find examples to copy from to give it a try. So far I was using
early_idt_handlerswithearly_printkto see if I could capture some printk messages while jumping from the first kernel to the second kernel (when the otherearly_idt_handlerswould kick in for the second kernel).
Quoted 4 lines
Quoted 1 line
Tips? Better examples?
That is a particularly good example. When I took a quick look earlier that is the first place we reload the idt in the kernel boot so that is one of two places that needs to be modified.
Hi Eric, Don
Sorry for chiming in so late.
We run into the same NMI problems and wrote some patches that tackle the kernel boot side of things. They have been extensively tested using qemu-kvm and things seem to be working as expected (after receiving an early NMI the kernel continues without problem; after the iret there is no stack corruption or register corruption).
I will be replying to this email with the patches.
Thanks,
Fernando
PATCH 1/2 boot: ignore early NMIs
Subject: [PATCH] boot: ignore early NMIs
From: Fernando Luis Vazquez Cao <[email protected]>
NMIs very early in the boot process are rarely critical (usually it just means that there was a spurious bit flip somewhere in the hardware, or that this is a kdump kernel and we received an NMI generated in the previous context), so the current behavior of halting the system when one occurs is probably a bit over the top.
This patch changes the early IDT so that NMIs are ignored and the kernel can, hopefully, continue executing other code. Harsher measures (panic, etc) are defered to the final NMI handler, which can actually make an informed decision.
This issue presented itself in our environment as seemingly random hangs in kdump.
---
arch/x86/kernel/head64.c +2 -7
@@ -71,7 +71,7 @@ void __init x86_64_start_kernel(char * r (__START_KERNEL & PGDIR_MASK)));BUILD_BUG_ON (__fix_to_virt (__end_of_fixed_addresses) <=MODULES_END ); -/* clear bss before set_intr_gate with early_idt_handler */ +/* clear bss before set_intr_gate with early_idt_handlers */ clear_bss ();/* Make NULL pointers segfault */
@@ -79,13 +79,8 @@ void __init x86_64_start_kernel(char * r max_pfn_mapped =KERNEL_IMAGE_SIZE >>PAGE_SHIFT ; -for (i =0 ; i <NUM_EXCEPTION_VECTORS ; i++) { -#ifdef CONFIG_EARLY_PRINTK +for (i =0 ; i <NUM_EXCEPTION_VECTORS ; i++)set_intr_gate (i, &early_idt_handlers[i]); -#else -set_intr_gate (i, early_idt_handler); -#endif - }load_idt ((const struct desc_ptr *)&idt_descr);if (console_loglevel ==10 )
arch/x86/kernel/head_64.S +21 -7
@@ -270,18 +270,29 @@ bad_address: jmp bad_address .section ".init.text","ax" -#ifdef CONFIG_EARLY_PRINTK .globl early_idt_handlers early_idt_handlers: - i = 0 + vector = 0 .rept NUM_EXCEPTION_VECTORS - movl $i, %esi - jmp early_idt_handler - i = i + 1 + /* + * NMIs (vector 2) this early in the boot process are rarely critical + * (usually it just means that there was a spurious bit flip somewhere + * in the hardware, or that this is a kdump kernel and we received an + * NMI generated in the previous context), so we ignore them here and + * try to continue (see early_nmi_handler implementation below). + * Harsher measures (panic, etc) are defered to the final NMI handler, + * which can actually make an informed decision. + */ + .if vector == 2 + jmp early_nmi_handler + .else + movl $vector, %esi + jmp early_exception_handler + .endif + vector = vector + 1 .endr -#endif -ENTRY(early_idt_handler) +early_exception_handler: #ifdef CONFIG_EARLY_PRINTK cmpl $2,early_recursion_flag(%rip) jz 1f
@@ -315,6 +326,9 @@ ENTRY(early_idt_handler) 1: hlt jmp 1b +early_nmi_handler: + iretq + #ifdef CONFIG_EARLY_PRINTK early_recursion_flag: .long 0
PATCH 2/2 boot: add early NMI counter
Subject: [PATCH] boot: add early NMI counter
From: Fernando Luis Vazquez Cao <[email protected]>
We currently ignore early NMIs but it would be nice to be able to know whether they actually occurred.
This patch adds an early NMI counter and exports it trough /proc/interrupts with the name of ENM (Early NMI).
---
arch/x86/include/asm/processor.h +1 -0
@@ -402,6 +402,7 @@ DECLARE_PER_CPU(char *, irq_stack_ptr); DECLARE_PER_CPU(unsigned int, irq_count);extern unsigned long kernel_eflags; extern asmlinkage void ignore_sysret(void); +extern unsigned int early_nmi_count;#else /* X86_64 */ #ifdef CONFIG_CC_STACKPROTECTOR /*
arch/x86/kernel/head_64.S +5 -0
@@ -327,6 +327,7 @@ early_exception_handler: jmp 1b early_nmi_handler: + incl early_nmi_count(%rip) # exported as ENM in /proc/interrupts iretq #ifdef CONFIG_EARLY_PRINTK
@@ -340,6 +341,10 @@ early_idt_ripmsg: #endif /* CONFIG_EARLY_PRINTK */ .previous + .globl early_nmi_count +early_nmi_count: + .long 0 + #define NEXT_PAGE(name) \ .balign PAGE_SIZE; \ ENTRY(name)
arch/x86/kernel/irq.c +1 -0
@@ -125,6 +125,7 @@ int arch_show_interrupts(struct seq_file#if defined(CONFIG_X86_IO_APIC )seq_printf (p,"%*s: %10u\n" , prec,"MIS" ,atomic_read (&irq_mis_count));#endif +seq_printf (p,"%*s: %10u\n" , prec,"ENM" , early_nmi_count);return 0 ; }
Re: [PATCH 2/2] boot: add early NMI counter
Quoted 9 lines · Fernando Luis Vázquez Cao
Subject: [PATCH] boot: add early NMI counter
From: Fernando Luis Vazquez Cao <[email protected]>
We currently ignore early NMIs but it would be nice to be able to know whether they actually occurred.
This patch adds an early NMI counter and exports it trough
/proc/interruptswith the name of ENM (Early NMI).
For a userspace interface I suspect we just want to dump the count into the NMI counter.
It probably makes sense to have a separate variable in early boot like you do, but then about the time we setup the normal NMI handler move the NMI count over and possibly do something like reboot if that is our policy.
I don't see it making sense to educate userspace for an edge case like this.
Eric
Quoted 40 lines
Signed-off-by Fernando Luis Vazquez Cao <[email protected]>---
diff -urNp
linux-3.3-rc6-orig/arch/x86/include/asm/processor.hlinux-3.3-rc6/arch/x86/include/asm/processor.harch/x86/include/asm/processor.h +1
-0@@ -402,6 +402,7 @@ DECLARE_PER_CPU(char *, irq_stack_ptr); DECLARE_PER_CPU(unsigned int, irq_count);extern unsigned long kernel_eflags; extern asmlinkage void ignore_sysret(void); +extern unsigned int early_nmi_count;#else /* X86_64 */ #ifdef CONFIG_CC_STACKPROTECTOR /* diff -urNp
linux-3.3-rc6-orig/arch/x86/kernel/head_64.Slinux-3.3-rc6/arch/x86/kernel/head_64.Sarch/x86/kernel/head_64.S +5
-0@@ -327,6 +327,7 @@ early_exception_handler: jmp 1b early_nmi_handler: + incl early_nmi_count(%rip) # exported as ENM in /proc/interrupts iretq #ifdef CONFIG_EARLY_PRINTK@@ -340,6 +341,10 @@ early_idt_ripmsg: #endif /* CONFIG_EARLY_PRINTK */ .previous + .globl early_nmi_count +early_nmi_count: + .long 0 + #define NEXT_PAGE(name) \ .balign PAGE_SIZE; \ ENTRY(name)diff -urNp
linux-3.3-rc6-orig/arch/x86/kernel/irq.clinux-3.3-rc6/arch/x86/kernel/irq.c
arch/x86/kernel/irq.c int arch_show_interrupts(struct seq_file · line 131
Quoted 7 lines
arch/x86/kernel/irq.c +1
-0@@ -125,6 +125,7 @@ int arch_show_interrupts(struct seq_file#if defined(CONFIG_X86_IO_APIC )seq_printf (p,"%*s: %10u\n" , prec,"MIS" ,atomic_read (&irq_mis_count));#endif +seq_printf (p,"%*s: %10u\n" , prec,"ENM" , early_nmi_count);return 0 ; }
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/2] boot: add early NMI counter
Quoted 11 lines · Eric W. Biederman
Quoted 9 lines · Fernando Luis Vázquez Cao
Subject: [PATCH] boot: add early NMI counter
From: Fernando Luis Vazquez Cao<[email protected]>
We currently ignore early NMIs but it would be nice to be able to know whether they actually occurred.
This patch adds an early NMI counter and exports it trough
/proc/interruptswith the name of ENM (Early NMI).
Quoted 7 lines
For a userspace interface I suspect we just want to dump the count into the NMI counter.
It probably makes sense to have a separate variable in early boot like you do, but then about the time we setup the normal NMI handler move the NMI count over and possibly do something like reboot if that is our policy.
I am fine with either approach. I guess that is the x86 maintainers' call. Ingo, Thomas, Peter, what do you think? Should I add a new entry to /proc/interrupts or move over the early NMI count to the existing per-cpu NMI counter?
Thanks,
Fernando
Re: [PATCH 1/2] boot: ignore early NMIs
In reply to Fernando Luis Vázquez CaoQuoted 65 lines · Fernando Luis Vázquez Cao
Subject: [PATCH] boot: ignore early NMIs
From: Fernando Luis Vazquez Cao <[email protected]>
NMIs very early in the boot process are rarely critical (usually it just means that there was a spurious bit flip somewhere in the hardware, or that this is a kdump kernel and we received an NMI generated in the previous context), so the current behavior of halting the system when one occurs is probably a bit over the top.
This patch changes the early IDT so that NMIs are ignored and the kernel can, hopefully, continue executing other code. Harsher measures (panic, etc) are defered to the final NMI handler, which can actually make an informed decision.
This issue presented itself in our environment as seemingly random hangs in kdump.
Signed-off-by Fernando Luis Vazquez Cao <[email protected]>---
diff -urNp
linux-3.3-rc6-orig/arch/x86/kernel/head64.clinux-3.3-rc6/arch/x86/kernel/head64.carch/x86/kernel/head64.c +2
-7@@ -71,7 +71,7 @@ void __init x86_64_start_kernel(char * r (__START_KERNEL & PGDIR_MASK)));BUILD_BUG_ON (__fix_to_virt (__end_of_fixed_addresses) <=MODULES_END ); -/* clear bss before set_intr_gate with early_idt_handler */ +/* clear bss before set_intr_gate with early_idt_handlers */ clear_bss ();/* Make NULL pointers segfault */ @@ -79,13 +79,8 @@ void __init x86_64_start_kernel(char * r max_pfn_mapped =KERNEL_IMAGE_SIZE >>PAGE_SHIFT ; -for (i =0 ; i <NUM_EXCEPTION_VECTORS ; i++) { -#ifdef CONFIG_EARLY_PRINTK +for (i =0 ; i <NUM_EXCEPTION_VECTORS ; i++)set_intr_gate (i, &early_idt_handlers[i]); -#else -set_intr_gate (i, early_idt_handler); -#endif - }load_idt ((const struct desc_ptr *)&idt_descr);if (console_loglevel ==10 )diff -urNp
linux-3.3-rc6-orig/arch/x86/kernel/head_64.Slinux-3.3-rc6/arch/x86/kernel/head_64.Sarch/x86/kernel/head_64.S +2
-5@@ -270,18 +270,29 @@ bad_address: jmp bad_address .section ".init.text","ax" -#ifdef CONFIG_EARLY_PRINTK .globl early_idt_handlers early_idt_handlers: - i = 0 + vector = 0 .rept NUM_EXCEPTION_VECTORS - movl $i, %esi - jmp early_idt_handler - i = i + 1 + /*
arch/x86/kernel/head_64.S bad_address: · line 287
Quoted 10 lines
arch/x86/kernel/head_64.S +10
-0+ * NMIs (vector 2) this early in the boot process are rarely critical + * (usually it just means that there was a spurious bit flip somewhere + * in the hardware, or that this is a kdump kernel and we received an + * NMI generated in the previous context), so we ignore them here and + * try to continue (see early_nmi_handler implementation below). + * Harsher measures (panic, etc) are defered to the final NMI handler, + * which can actually make an informed decision. + */ + .if vector == 2 + jmp early_nmi_handler
Is just a jump and not a move followed by a jump still 10 bytes? I hate to say it but I think this fails miserably for any exception after a nmi.
I expect the simplest solution is to modify early_idt_handler to test for vector == 2.
Doing something less brittle than:
arch/x86/kernel/head_64.S bad_address: · line 288
Quoted 1 line
arch/x86/kernel/head_64.S +0
-0extern const char early_idt_handlers[NUM_EXCEPTION_VECTORS][10];
in segment.h might be a good idea as well.
Eric
Quoted 23 lines
arch/x86/kernel/head_64.S +6
-2+ .else + movl $vector, %esi + jmp early_exception_handler + .endif + vector = vector + 1 .endr -#endif -ENTRY(early_idt_handler) +early_exception_handler: #ifdef CONFIG_EARLY_PRINTK cmpl $2,early_recursion_flag(%rip)arch/x86/kernel/head_64.S +3
-0jz 1f@@ -315,6 +326,9 @@ ENTRY(early_idt_handler) 1: hlt jmp 1b +early_nmi_handler: + iretq + #ifdef CONFIG_EARLY_PRINTK early_recursion_flag: .long 0
Re: [PATCH 1/2] boot: ignore early NMIs
Quoted 72 lines · Eric W. Biederman
Quoted 70 lines · Fernando Luis Vázquez Cao
Subject: [PATCH] boot: ignore early NMIs
From: Fernando Luis Vazquez Cao<[email protected]>
NMIs very early in the boot process are rarely critical (usually it just means that there was a spurious bit flip somewhere in the hardware, or that this is a kdump kernel and we received an NMI generated in the previous context), so the current behavior of halting the system when one occurs is probably a bit over the top.
This patch changes the early IDT so that NMIs are ignored and the kernel can, hopefully, continue executing other code. Harsher measures (panic, etc) are defered to the final NMI handler, which can actually make an informed decision.
This issue presented itself in our environment as seemingly random hangs in kdump.
Signed-off-by Fernando Luis Vazquez Cao<[email protected]>---
diff -urNp
linux-3.3-rc6-orig/arch/x86/kernel/head64.clinux-3.3-rc6/arch/x86/kernel/head64.carch/x86/kernel/head64.c +2
-7@@ -71,7 +71,7 @@ void __init x86_64_start_kernel(char * r (__START_KERNEL& PGDIR_MASK)));BUILD_BUG_ON (__fix_to_virt (__end_of_fixed_addresses)<=MODULES_END ); -/* clear bss before set_intr_gate with early_idt_handler */ +/* clear bss before set_intr_gate with early_idt_handlers */ clear_bss ();/* Make NULL pointers segfault */ @@ -79,13 +79,8 @@ void __init x86_64_start_kernel(char * r max_pfn_mapped =KERNEL_IMAGE_SIZE >>PAGE_SHIFT ; -for (i =0 ; i<NUM_EXCEPTION_VECTORS ; i++) { -#ifdef CONFIG_EARLY_PRINTK +for (i =0 ; i<NUM_EXCEPTION_VECTORS ; i++)set_intr_gate (i,&early_idt_handlers[i]); -#else -set_intr_gate (i, early_idt_handler); -#endif - }load_idt ((const struct desc_ptr *)&idt_descr);if (console_loglevel ==10 )diff -urNp
linux-3.3-rc6-orig/arch/x86/kernel/head_64.Slinux-3.3-rc6/arch/x86/kernel/head_64.Sarch/x86/kernel/head_64.S +7
-5@@ -270,18 +270,29 @@ bad_address: jmp bad_address .section ".init.text","ax" -#ifdef CONFIG_EARLY_PRINTK .globl early_idt_handlers early_idt_handlers: - i = 0 + vector = 0 .rept NUM_EXCEPTION_VECTORS - movl $i, %esi - jmp early_idt_handler - i = i + 1 + /* + * NMIs (vector 2) this early in the boot process are rarely critical + * (usually it just means that there was a spurious bit flip somewhere + * in the hardware, or that this is a kdump kernel and we received an + * NMI generated in the previous context), so we ignore them here and + * try to continue (see early_nmi_handler implementation below).
Quoted 8 lines
arch/x86/kernel/head_64.S bad_address: · line 287
Quoted 5 lines
arch/x86/kernel/head_64.S +5
-0+ * Harsher measures (panic, etc) are defered to the final NMI handler, + * which can actually make an informed decision. + */ + .if vector == 2 + jmp early_nmi_handlerIs just a jump and not a move followed by a jump still 10 bytes? I hate to say it but I think this fails miserably for any exception after a nmi.
Thank you for the heads up! Actually, it was working for the exceptions after the nmi but with a corrupted esi (vector number). My original intention was to fill the empty space with nops but forgot to actually implement it... Sorry about that. Will fix for the next iteration.
Quoted 2 lines
I expect the simplest solution is to modify
early_idt_handlerto test for vector == 2.
That is precisely what I did on a previous version but that would involve using registers which need to be saved and restored and I wanted to avoid using the stack in the NMI path. We would also need to add a "pushq rsi " in early_idt_handlers which implies modifying "early_idt_handlers" definition in "segment.h".
If you are OK with it I would like to go with the approach in the two patches I sent.
Quoted 3 lines
Doing something less brittle than:
arch/x86/kernel/head_64.S bad_address: · line 288
Quoted 1 line
arch/x86/kernel/head_64.S +0
-0extern const char early_idt_handlers[NUM_EXCEPTION_VECTORS][10];in
segment.hmight be a good idea as well.
Yes, I agree. I will give it some thought.
Re: [PATCH 1/2] boot: ignore early NMIs
Quoted 9 lines · Fernando Luis Vázquez Cao
Quoted 3 lines
Is just a jump and not a move followed by a jump still 10 bytes? I hate to say it but I think this fails miserably for any exception after a nmi.
Thank you for the heads up! Actually, it was working for the exceptions after the nmi but with a corrupted esi (vector number). My original intention was to fill the empty space with nops but forgot to actually implement it... Sorry about that. Will fix for the next iteration.
Sound good, and thank you very much for tackling this.
Quoted 11 lines
Quoted 2 lines
I expect the simplest solution is to modify
early_idt_handlerto test for vector == 2.That is precisely what I did on a previous version but that would involve using registers which need to be saved and restored and I wanted to avoid using the stack in the NMI path. We would also need to add a "pushq rsi " in
early_idt_handlerswhich implies modifying "early_idt_handlers" definition in "segment.h".If you are OK with it I would like to go with the approach in the two patches I sent.
I am fine with your approach. I suggest a big fat comment mentioning the 10 byte requirement and the register requirement.
Neither one is locally obvious which makes it easy to goof when modifying the code.
Quoted 5 lines
Quoted 3 lines
Doing something less brittle than:
Quoted 1 line
extern const char early_idt_handlers[NUM_EXCEPTION_VECTORS][10];
in
segment.hmight be a good idea as well.Yes, I agree. I will give it some thought.
Eric
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] boot: ignore early NMIs
Quoted 5 lines · Eric W. Biederman
I am fine with your approach. I suggest a big fat comment mentioning the 10 byte requirement and the register requirement.
Neither one is locally obvious which makes it easy to goof when modifying the code.
Done.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Doing something less brittle than:
Quoted 1 line
extern const char early_idt_handlers[NUM_EXCEPTION_VECTORS][10];
in
segment.hmight be a good idea as well.
Tackled that one too.
I will be replying to this email with the updated patches.
Thanks,
Fernando
PATCH 1/3 boot: fortify early_idt_handlers definition
Subject: [PATCH 1/3] boot: fortify early_idt_handlers definition
From: Fernando Luis Vazquez Cao <[email protected]>
The current definition is too brittle which makes it easy to screw things up when modifying the code. Add some comments while at it.
---
arch/x86/include/asm/segment.h +3 -1
@@ -210,8 +210,10 @@#define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES * 8)#ifdef __KERNEL__ +#define EARLY_IDT_HANDLER_SIZE 16#ifndef __ASSEMBLY__ -extern const char early_idt_handlers[NUM_EXCEPTION_VECTORS ][10 ]; +extern const char + early_idt_handlers[NUM_EXCEPTION_VECTORS ][EARLY_IDT_HANDLER_SIZE ];#endif #endif
arch/x86/kernel/head_64.S +9 -0
@@ -272,11 +272,20 @@ bad_address: .section ".init.text","ax" #ifdef CONFIG_EARLY_PRINTK .globl early_idt_handlers + .align EARLY_IDT_HANDLER_SIZE early_idt_handlers: i = 0 .rept NUM_EXCEPTION_VECTORS movl $i, %esi jmp early_idt_handler + /* + * early_idt_handlers is treated as a + * [NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE] array from C code + * so we have to make sure that each handler fits in its + * EARLY_IDT_HANDLER_SIZE bytes long slot. Handlers shorter than that + * will be taken care of by the align directive below. + */ + .align EARLY_IDT_HANDLER_SIZE i = i + 1 .endr #endif
PATCH 2/3 boot: ignore early NMIs
Subject: [PATCH 2/3] boot: ignore early NMIs
From: Fernando Luis Vazquez Cao <[email protected]>
NMIs very early in the boot process are rarely critical (usually it just means that there was a spurious bit flip somewhere in the hardware, or that this is a kdump kernel and we received an NMI generated in the previous context), so the current behavior of halting the system when one occurs is probably a bit over the top.
This patch changes the early IDT so that NMIs are ignored and the kernel can, hopefully, continue executing other code. Harsher measures (panic, etc) are defered to the final NMI handler, which can actually make an informed decision.
This issue presented itself in our environment as seemingly random hangs in kdump.
---
arch/x86/kernel/head64.c +2 -7
@@ -71,7 +71,7 @@ void __init x86_64_start_kernel(char * r (__START_KERNEL & PGDIR_MASK)));BUILD_BUG_ON (__fix_to_virt (__end_of_fixed_addresses) <=MODULES_END ); -/* clear bss before set_intr_gate with early_idt_handler */ +/* clear bss before set_intr_gate with early_idt_handlers */ clear_bss ();/* Make NULL pointers segfault */
@@ -79,13 +79,8 @@ void __init x86_64_start_kernel(char * r max_pfn_mapped =KERNEL_IMAGE_SIZE >>PAGE_SHIFT ; -for (i =0 ; i <NUM_EXCEPTION_VECTORS ; i++) { -#ifdef CONFIG_EARLY_PRINTK +for (i =0 ; i <NUM_EXCEPTION_VECTORS ; i++)set_intr_gate (i, &early_idt_handlers[i]); -#else -set_intr_gate (i, early_idt_handler); -#endif - }load_idt ((const struct desc_ptr *)&idt_descr);if (console_loglevel ==10 )
arch/x86/kernel/head_64.S +25 -7
@@ -270,14 +270,30 @@ bad_address: jmp bad_address .section ".init.text","ax" -#ifdef CONFIG_EARLY_PRINTK .globl early_idt_handlers .align EARLY_IDT_HANDLER_SIZE early_idt_handlers: - i = 0 + vector = 0 .rept NUM_EXCEPTION_VECTORS - movl $i, %esi - jmp early_idt_handler + /* + * NMIs (vector 2) this early in the boot process are rarely critical + * (usually it just means that there was a spurious bit flip somewhere + * in the hardware, or that this is a kdump kernel and we received an + * NMI generated in the previous context), so we ignore them here and + * try to continue (see early_nmi_handler implementation below). + * Harsher measures (panic, etc) are defered to the final NMI handler, + * which can actually make an informed decision. + */ + .if vector == 2 + /* + * We are careful not to use any register to avoid having to use the + * stack in the NMI path. + */ + jmp early_nmi_handler + .else + movl $vector, %esi + jmp early_exception_handler + .endif /* * early_idt_handlers is treated as a * [NUM_EXCEPTION_VECTORS][EARLY_IDT_HANDLER_SIZE] array from C code
@@ -286,11 +302,10 @@ early_idt_handlers: * will be taken care of by the align directive below. */ .align EARLY_IDT_HANDLER_SIZE - i = i + 1 + vector = vector + 1 .endr -#endif -ENTRY(early_idt_handler) +early_exception_handler: #ifdef CONFIG_EARLY_PRINTK cmpl $2,early_recursion_flag(%rip) jz 1f
@@ -324,6 +339,9 @@ ENTRY(early_idt_handler) 1: hlt jmp 1b +early_nmi_handler: + iretq + #ifdef CONFIG_EARLY_PRINTK early_recursion_flag: .long 0
PATCH 3/3 boot: add early NMI counter
Subject: [PATCH 3/3] boot: add early NMI counter
From: Fernando Luis Vazquez Cao <[email protected]>
We currently ignore early NMIs but it would be nice to be able to know whether they actually occurred.
This patch adds an early NMI counter, whose count is moved over to the per-cpu NMI counter before the kernel frees the init sections.
---
arch/x86/include/asm/processor.h +5 -0
@@ -402,6 +402,11 @@ DECLARE_PER_CPU(char *, irq_stack_ptr); DECLARE_PER_CPU(unsigned int, irq_count);extern unsigned long kernel_eflags; extern asmlinkage void ignore_sysret(void); +/* +* early_nmi_count is in the .init.text ELF section so it can only be accessed +* before the init sections are freed by the kernel. +*/ +extern unsigned int early_nmi_count;#else /* X86_64 */ #ifdef CONFIG_CC_STACKPROTECTOR /*
arch/x86/kernel/head_64.S +4 -0
@@ -340,6 +340,7 @@ early_exception_handler: jmp 1b early_nmi_handler: + incl early_nmi_count(%rip) iretq #ifdef CONFIG_EARLY_PRINTK
@@ -351,6 +352,9 @@ early_idt_msg: early_idt_ripmsg: .asciz "RIP %s\n" #endif /* CONFIG_EARLY_PRINTK */ + .globl early_nmi_count +early_nmi_count: + .long 0 .previous #define NEXT_PAGE(name) \
arch/x86/kernel/traps.c +1 -0
@@ -719,6 +719,7 @@ void __init trap_init(void) x86_init.irqs.trap_init ();#ifdef CONFIG_X86_64 +percpu_add (irq_stat.__nmi_count, early_nmi_count);memcpy (&nmi_idt_table, &idt_table,IDT_ENTRIES *16 );set_nmi_gate (1 , &debug);set_nmi_gate (3 , &int3);
H. Peter Anvin
reviewerRe: [PATCH 1/2] boot: ignore early NMIs
In reply to Eric W. BiedermanOkay, I need to ask this...
Is there a reason to not just simply block these NMIs during the kexec sequence?
-hpa
Signature · 8 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf. _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] boot: ignore early NMIs
Quoted 2 lines · H. Peter Anvin
Is there a reason to not just simply block these NMIs during the kexec sequence?
Ok, some background:
In the reboot path to the kdump kernel we disable local interrupts and the APICs in native_machine_crash_shutdown() and reset the IDT in machine_kexec(), which leaves an in valid IDT installed.
However, disabling the I/O APIC involves taking a lock, which in the event of a crash can is racy and can lead to a deadlock. To solve this issue Don wrote a patch that left the I/O APICs and the LAPIC of the crashing CPU untouched in the kdump reboot path, but this seemed to cause mysterious reboots in some systems. It turned out that an NMI coming from the perf based hardlockup detector was causing the system to triple fault. If a NMI happens to arrive in the window between the invalidation of the IDT in machine_kexec() and the configuration of the final IDT we will be in big trouble. In particular, the system will either triple fault or halt, depending on whether the NMI arrived before or after installing the early IDT.
To tackle this issue we can either stop the hardlockup detector or disable the LAPIC (the NMIs needed by x86's hardlockup detector are generated using performance counters in the LAPIC), leaving the I/O APICs untouched. The second is simpler and I think it is the approach Don took to fix this issue in RHEL kernels.
Unfortunately, this is not enough, we are still exposed to external NMIs not routed through the LAPIC. In other words, we have to make sure that we always have and IDT that is able to handle NMIs without seemingly random reboots and lockups. To achieve this goal we need to fix machine_kexec() and the early IDT handlers. The current patch set takes care of the latter.
- Fernando
H. Peter Anvin
reviewerRe: [PATCH 1/2] boot: ignore early NMIs
Quoted 7 lines · Fernando Luis Vázquez Cao
To tackle this issue we can either stop the hardlockup detector or disable the LAPIC (the NMIs needed by x86's hardlockup detector are generated using performance counters in the LAPIC), leaving the I/O APICs untouched. The second is simpler and I think it is the approach Don took to fix this issue in RHEL kernels.
Quoted 7 lines
Unfortunately, this is not enough, we are still exposed to external NMIs not routed through the LAPIC. In other words, we have to make sure that we always have and IDT that is able to handle NMIs without seemingly random reboots and lockups. To achieve this goal we need to fix
machine_kexec()and the early IDT handlers. The current patch set takes care of the latter.
The only source of NMIs other than the LAPIC should be the system error which can be disabled through the RTC port, so I think your second paragraph here is way more mechanism than you need for very little gain.
-hpa
Signature · 8 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf. _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] boot: ignore early NMIs
Quoted 13 lines · H. Peter Anvin
Quoted 6 lines · Fernando Luis Vázquez Cao
To tackle this issue we can either stop the hardlockup detector or disable the LAPIC (the NMIs needed by x86's hardlockup detector are generated using performance counters in the LAPIC), leaving the I/O APICs untouched. The second is simpler and I think it is the approach Don took to fix this issue in RHEL kernels.
Quoted 6 lines
Unfortunately, this is not enough, we are still exposed to external NMIs not routed through the LAPIC. In other words, we have to make sure that we always have and IDT that is able to handle NMIs without seemingly random reboots and lockups. To achieve this goal we need to fix
machine_kexec()and the early IDT handlers. The current patch set takes care of the latter.
Quoted 3 lines
The only source of NMIs other than the LAPIC should be the system error which can be disabled through the RTC port, so I think your second paragraph here is way more mechanism than you need for very little gain.
The thing is that we want to avoid playing with hardware in the kdump reboot patch when we can avoid it, the premise being that it cannot be accessed without risking a lockup or worse (as the deadlock accessing the I/O APIC showed). The kernel is crashing after all. What is more, I forgot to mention that the long term goal is to leave the LAPIC untouched too (we really want to keep the number of things we do in the context of the crashing kernel to the bare minimum), so we would still need to fix the early IDT.
My patch set just installs a special handler for the NMI case so I think it is pretty simple and self contained.
Another reason to apply these patches is to be consistent with the rest of the kernel. Spurious NMIs that would have been ignored after installing the final IDT would cause the system to halt if they happen
to arrive while the early IDT is in place.
- Fernando
Re: [PATCH 1/2] boot: ignore early NMIs
On Mon, Mar 12, 2012 at 03:14:20PM +0900, Fernando Luis Vázquez Cao wrote:
[..]
Quoted 4 lines
The thing is that we want to avoid playing with hardware in the kdump reboot patch when we can avoid it, the premise being that it cannot be accessed without risking a lockup or worse (as the deadlock accessing the I/O APIC showed).
I think there needs to be a limit to being paranoid. On one hand people want to run panic notifiers, all the kmsg_dump() hooks in panic path, and on the other hand we are afraid of even disabling LAPIC.
I personally think that disabling LAPIC is reasonably practical solution to the problem until and unless somebody shows that it deadlocks easily.
Thanks
Vivek
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] boot: ignore early NMIs
Quoted 11 lines · Vivek Goyal
On Mon, Mar 12, 2012 at 03:14:20PM +0900, Fernando Luis Vázquez Cao wrote:
[..]
Quoted 4 lines
The thing is that we want to avoid playing with hardware in the kdump reboot patch when we can avoid it, the premise being that it cannot be accessed without risking a lockup or worse (as the deadlock accessing the I/O APIC showed).
I think there needs to be a limit to being paranoid. On one hand people want to run panic notifiers, all the
kmsg_dump()hooks in panic path, and on the other hand we are afraid of even disabling LAPIC.
And the kmsg_dump code and the panic notifiers aren't being run. Having seen some of their failure modes being patched up recently (Adding and removing sysfs files!!!!) I'm very comfortable with the level of paranoia.
It has been proven time and time again that the more you do in the failing kernel that the greater your likely-hood of not getting your failure information out.
Quoted 3 lines
I personally think that disabling LAPIC is reasonably practical solution to the problem until and unless somebody shows that it deadlocks easily.
Disabling NMI generation in the LAPIC is fine, and for the short term I don't even have a problem with disabling the entire LAPIC as all of our platforms seem to have code for completely reprogramming it.
At the same time there have been cases like the i8259 routed through the ExtInt pin of the lapci that we haven't been given programming information about and that if we want to work we should avoid touching.
Furthermore we have two reported cases of people experiencing real NMIs on the kdump path. So we have to assume the presence of the CMOS nmi disable as well if we are going to unequivocally disable NMIs.
Given the variety of x86 hardware today and the growing variety of x86 hardware tomorrow we are going to be fixing this until we can actually handle the NMIs. Hardware designers are unfortunately creative enough that we aren't going to think of everything. Given that it is has taken us almost a decade to realize that there actually is a real world problem I'm not too keen on a solution that is just good enough to fix a small problem.
I would love it if x86 had an architectural NMI off switch but with Intel pushing EFI and the removal of the cmos clock x86 no longer has an always available NMI off switch.
Furthermore handling of NMI is not hard it is just a little tricky, to test.
Eric
Re: [PATCH 1/2] boot: ignore early NMIs
On Mon, Mar 12, 2012 at 12:02:06PM -0700, Eric W. Biederman wrote:
[..]
Quoted 9 lines
Quoted 4 lines
I personally think that disabling LAPIC is reasonably practical solution to the problem until and unless somebody shows that it deadlocks easily.
Disabling NMI generation in the LAPIC is fine, and for the short term I don't even have a problem with disabling the entire LAPIC as all of our platforms seem to have code for completely reprogramming it.
Quoted 7 lines
At the same time there have been cases like the i8259 routed through the ExtInt pin of the lapci that we haven't been given programming information about and that if we want to work we should avoid touching.
Furthermore we have two reported cases of people experiencing real NMIs on the kdump path. So we have to assume the presence of the CMOS nmi disable as well if we are going to unequivocally disable NMIs.
So Don reported NMI problem only after he stopped disable_local_APIC(). His NMIs were being generated from Local APIC. The only question left is what kind of NMIs Fernando was seeing.
Quoted 8 lines
Given the variety of x86 hardware today and the growing variety of x86 hardware tomorrow we are going to be fixing this until we can actually handle the NMIs. Hardware designers are unfortunately creative enough that we aren't going to think of everything. Given that it is has taken us almost a decade to realize that there actually is a real world problem I'm not too keen on a solution that is just good enough to fix a small problem.
Problem might be small but it has been noticed and fix is simple. That's a different thing that it might not cover all other cases you mention.
And to begin with problem was with ioapic lock and we are blocking the that fix because we want NMI handling to be cleaned up too.
So atleast Don's ioapic locking fix should be allowed to go in and then debate can continue that what's the best fix to handle NMIs from all sort of situations.
Thanks
Vivek
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
H. Peter Anvin
reviewerRe: [PATCH 1/2] boot: ignore early NMIs
In reply to Eric W. BiedermanQuoted 9 lines · Eric W. Biederman
Disabling NMI generation in the LAPIC is fine, and for the short term I don't even have a problem with disabling the entire LAPIC as all of our platforms seem to have code for completely reprogramming it.
At the same time there have been cases like the i8259 routed through the ExtInt pin of the lapci that we haven't been given programming information about and that if we want to work we should avoid touching.
I'm pretty sure that information is in the SDM (I'm looking at it now.)
You can also block NMI though this route, since external NMI really is LINT1 and hence is routed through the LAPIC; you can mask it by clearing bit 16 in LVT LINT1 as described in the SDM.
-hpa
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
H. Peter Anvin
reviewerRe: [PATCH 1/2] boot: ignore early NMIs
In reply to Fernando Luis Vázquez CaoQuoted 10 lines · Fernando Luis Vázquez Cao
The thing is that we want to avoid playing with hardware in the kdump reboot patch when we can avoid it, the premise being that it cannot be accessed without risking a lockup or worse (as the deadlock accessing the I/O APIC showed). The kernel is crashing after all. What is more, I forgot to mention that the long term goal is to leave the LAPIC untouched too (we really want to keep the number of things we do in the context of the crashing kernel to the bare minimum), so we would still need to fix the early IDT.
Quoted 8 lines
My patch set just installs a special handler for the NMI case so I think it is pretty simple and self contained.
Another reason to apply these patches is to be consistent with the rest of the kernel. Spurious NMIs that would have been ignored after installing the final IDT would cause the system to halt if they happen
to arrive while the early IDT is in place.
I'm concerned that you're adding failure modes because you don't want to solve the real problem which is you need to block this at the source. It is way more than the IDT that has to work (at the very least, you need the GDT and a working stack) at all times in order for NMIs to be receivable. That doesn't address what happens if you're getting an NMI storm either.
-hpa
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] boot: ignore early NMIs
Quoted 20 lines · H. Peter Anvin
Quoted 10 lines · Fernando Luis Vázquez Cao
The thing is that we want to avoid playing with hardware in the kdump reboot patch when we can avoid it, the premise being that it cannot be accessed without risking a lockup or worse (as the deadlock accessing the I/O APIC showed). The kernel is crashing after all. What is more, I forgot to mention that the long term goal is to leave the LAPIC untouched too (we really want to keep the number of things we do in the context of the crashing kernel to the bare minimum), so we would still need to fix the early IDT.
Quoted 8 lines
My patch set just installs a special handler for the NMI case so I think it is pretty simple and self contained.
Another reason to apply these patches is to be consistent with the rest of the kernel. Spurious NMIs that would have been ignored after installing the final IDT would cause the system to halt if they happen
to arrive while the early IDT is in place.
Quoted 6 lines
I'm concerned that you're adding failure modes because you don't want to solve the real problem which is you need to block this at the source. It is way more than the IDT that has to work (at the very least, you need the GDT and a working stack) at all times in order for NMIs to be receivable. That doesn't address what happens if you're getting an NMI storm either.
Good criticism.
The basic problem is what do we do when we receive NMIs during the kernel boot. Dying mysteriously certainly isn't a good solution.
In the kexec on panic code path we already have a stack and as long as we can fit the GDT and the LDT on that same page we can have all of the rest during the entire transition.
After that is basically the kernel's boot code.
The basic problem is which source do we block this at? How many sources are their? And architecturally last I looked x86 no longer has a NMI disable EFI and similar systems want to get away without a CMOS legacy clock because designers so often get them wrong.
Eric
H. Peter Anvin
reviewerRe: [PATCH 1/2] boot: ignore early NMIs
Quoted 6 lines · Eric W. Biederman
The basic problem is which source do we block this at? How many sources are their? And architecturally last I looked x86 no longer has a NMI disable EFI and similar systems want to get away without a CMOS legacy clock because designers so often get them wrong.
On all processors which have an LAPIC you can block all NMI sources at the LAPIC. I think it's safe to assume that if you don't have an LAPIC -- an ancient system by now -- you have port 70h.
-hpa
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
H. Peter Anvin
reviewerRe: [PATCH 1/2] boot: ignore early NMIs
Quoted 8 lines · H. Peter Anvin
Quoted 6 lines · Eric W. Biederman
The basic problem is which source do we block this at? How many sources are their? And architecturally last I looked x86 no longer has a NMI disable EFI and similar systems want to get away without a CMOS legacy clock because designers so often get them wrong.
Quoted 4 lines
On all processors which have an LAPIC you can block all NMI sources at the LAPIC. I think it's safe to assume that if you don't have an LAPIC -- an ancient system by now -- you have port 70h.
One thing: *disabling* the LAPIC will allow external NMIs coming in on LINT1 through, since the LAPIC in the disabled state tries to mimic the no-LAPIC configuration. So I don't think you want to disable LAPIC as much as disable the interrupt vectors within.
-hpa
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] boot: ignore early NMIs
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · Eric W. Biederman
The basic problem is which source do we block this at? How many sources are their? And architecturally last I looked x86 no longer has a NMI disable EFI and similar systems want to get away without a CMOS legacy clock because designers so often get them wrong.
Quoted 8 lines
Quoted 4 lines
On all processors which have an LAPIC you can block all NMI sources at the LAPIC. I think it's safe to assume that if you don't have an LAPIC -- an ancient system by now -- you have port 70h.
One thing: *disabling* the LAPIC will allow external NMIs coming in on LINT1 through, since the LAPIC in the disabled state tries to mimic the no-LAPIC configuration. So I don't think you want to disable LAPIC as much as disable the interrupt vectors within.
Does this sound like a plan to get the ball rolling?:
1.- Merge Don's patch to disable the LAPIC in kdump reboot path (this
fixes a real issue seen in the field, is a net win and certainly not a regression - indeed it makes the code simpler because the I/O APICs are left untouched).
2.- Merge my patch set to ignore early NMIs (this brings the behavior
of the boot code in line with what we do in the rest of the kernel a we can avoid situations were a spurious NMI causes the kernel to halt). The early NMI handler is temporary and the final NMI handler installed shortly afterwards will take care of subsequent NMIs.
3.- Make sure that spurious NMIs (i.e. NMIs that for whatever reason
could not be stopped at the source) received during the reboot path to the kdump kernel do not cause a triple fault or a system lockup. This is under testing.
4.- Identify all the NMI sources and keep them from reaching the CPU
when it can be done in a race-free way.
Can we get 1 and 2 merged while we work on further improvements (3 and 4)?
Thanks,
Fernando
Re: [PATCH 1/2] boot: ignore early NMIs
Quoted 17 lines · Fernando Luis Vázquez Cao
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · Eric W. Biederman
The basic problem is which source do we block this at? How many sources are their? And architecturally last I looked x86 no longer has a NMI disable EFI and similar systems want to get away without a CMOS legacy clock because designers so often get them wrong.
Quoted 8 lines
Quoted 4 lines
On all processors which have an LAPIC you can block all NMI sources at the LAPIC. I think it's safe to assume that if you don't have an LAPIC -- an ancient system by now -- you have port 70h.
One thing: *disabling* the LAPIC will allow external NMIs coming in on LINT1 through, since the LAPIC in the disabled state tries to mimic the no-LAPIC configuration. So I don't think you want to disable LAPIC as much as disable the interrupt vectors within.
Quoted 6 lines
Does this sound like a plan to get the ball rolling?:
1.- Merge Don's patch to disable the LAPIC in kdump reboot path (this
fixes a real issue seen in the field, is a net win and certainly not a regression - indeed it makes the code simpler because the I/O APICs are left untouched).
I think you mean my patch to stop disabling the I/O APIC. That patch hasn't seen any new issues. It was the piece that stopped disabling the LAPIC that opened the doors for NMIs to fault the system.
Quoted 8 lines
2.- Merge my patch set to ignore early NMIs (this brings the behavior
of the boot code in line with what we do in the rest of the kernel a we can avoid situations were a spurious NMI causes the kernel to halt). The early NMI handler is temporary and the final NMI handler installed shortly afterwards will take care of subsequent NMIs.
Quoted 4 lines
3.- Make sure that spurious NMIs (i.e. NMIs that for whatever reason
could not be stopped at the source) received during the reboot path to the kdump kernel do not cause a triple fault or a system lockup. This is under testing.
This will require changes in kexec-tools as the purgatory code zaps the GDT I believe. This is going to make a 'complete solution' dependent on a version of kexec-tools. Not sure what we want to do there.
Quoted 3 lines
4.- Identify all the NMI sources and keep them from reaching the CPU
when it can be done in a race-free way.
Cheers,
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] boot: ignore early NMIs
Quoted 37 lines · Don Zickus
Quoted 17 lines · Fernando Luis Vázquez Cao
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · Eric W. Biederman
The basic problem is which source do we block this at? How many sources are their? And architecturally last I looked x86 no longer has a NMI disable EFI and similar systems want to get away without a CMOS legacy clock because designers so often get them wrong.
Quoted 8 lines
Quoted 4 lines
On all processors which have an LAPIC you can block all NMI sources at the LAPIC. I think it's safe to assume that if you don't have an LAPIC -- an ancient system by now -- you have port 70h.
One thing: *disabling* the LAPIC will allow external NMIs coming in on LINT1 through, since the LAPIC in the disabled state tries to mimic the no-LAPIC configuration. So I don't think you want to disable LAPIC as much as disable the interrupt vectors within.
Quoted 6 lines
Does this sound like a plan to get the ball rolling?:
1.- Merge Don's patch to disable the LAPIC in kdump reboot path (this
fixes a real issue seen in the field, is a net win and certainly not a regression - indeed it makes the code simpler because the I/O APICs are left untouched).I think you mean my patch to stop disabling the I/O APIC. That patch hasn't seen any new issues. It was the piece that stopped disabling the LAPIC that opened the doors for NMIs to fault the system.
Quoted 8 lines
2.- Merge my patch set to ignore early NMIs (this brings the behavior
of the boot code in line with what we do in the rest of the kernel a we can avoid situations were a spurious NMI causes the kernel to halt). The early NMI handler is temporary and the final NMI handler installed shortly afterwards will take care of subsequent NMIs.
Quoted 8 lines
Quoted 4 lines
3.- Make sure that spurious NMIs (i.e. NMIs that for whatever reason
could not be stopped at the source) received during the reboot path to the kdump kernel do not cause a triple fault or a system lockup. This is under testing.This will require changes in kexec-tools as the purgatory code zaps the GDT I believe. This is going to make a 'complete solution' dependent on a version of kexec-tools. Not sure what we want to do there.
Ouch. I guess that in the event that purgatory needs to be modified some backwards-compatibility will need to be provided, possibly by allowing purgatory to switch between two behaviours based on e.g. a command line parameter.
Quoted 2 lines
Quoted 2 lines
4.- Identify all the NMI sources and keep them from reaching the CPU
when it can be done in a race-free way.
Re: [PATCH 1/2] boot: ignore early NMIs
In reply to H. Peter AnvinQuoted 10 lines · H. Peter Anvin
Quoted 9 lines · Fernando Luis Vázquez Cao
The thing is that we want to avoid playing with hardware in the kdump reboot patch when we can avoid it, the premise being that it cannot be accessed without risking a lockup or worse (as the deadlock accessing the I/O APIC showed). The kernel is crashing after all. What is more, I forgot to mention that the long term goal is to leave the LAPIC untouched too (we really want to keep the number of things we do in the context of the crashing kernel to the bare minimum), so we would still need to fix the early IDT.
Quoted 8 lines
Quoted 7 lines
My patch set just installs a special handler for the NMI case so I think it is pretty simple and self contained.
Another reason to apply these patches is to be consistent with the rest of the kernel. Spurious NMIs that would have been ignored after installing the final IDT would cause the system to halt if they happen
to arrive while the early IDT is in place.I'm concerned that you're adding failure modes
This patch set just brings the early IDT in line with what we do after switching to the final IDT, i.e. we ignore NMIs. The only difference is that we do not honor panic*nmi and unknown_nmi_panic. As things stand now the kernel will sometimes mysteriously hang. I really think that independently of the kdump problem it would be nice to be consistent in this regard.
Quoted 2 lines
because you don't want to
solve the real problem which is you need to block this at the source.
Indeed, I want to do both. Try to block NMIs at the source when possible and install an IDT that ignores NMIs to have our backs covered (avoid triple faults and lockups). As Eric mentioned it is not clear that we can always identify and stop all the sources.
Quoted 3 lines
It is way more than the IDT that has to work (at the very least, you need the GDT and a working stack) at all times in order for NMIs to be receivable.
Of course, and that is what the follow-up patch set does. It just needs some more testing. The patches I sent make use of the early GDT and it works as expected.
Quoted 2 lines
That doesn't address what happens if you're getting an NMI storm either.
Well, the same applies to the final IDT. As I mentioned before I think we should also try to stop things at the source when it is safe (of course, first we need to identify all the sources).
- Fernando
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] boot: ignore early NMIs
In reply to H. Peter AnvinQuoted 17 lines · H. Peter Anvin
Quoted 7 lines · Fernando Luis Vázquez Cao
To tackle this issue we can either stop the hardlockup detector or disable the LAPIC (the NMIs needed by x86's hardlockup detector are generated using performance counters in the LAPIC), leaving the I/O APICs untouched. The second is simpler and I think it is the approach Don took to fix this issue in RHEL kernels.
Quoted 7 lines
Unfortunately, this is not enough, we are still exposed to external NMIs not routed through the LAPIC. In other words, we have to make sure that we always have and IDT that is able to handle NMIs without seemingly random reboots and lockups. To achieve this goal we need to fix
machine_kexec()and the early IDT handlers. The current patch set takes care of the latter.
Quoted 3 lines
The only source of NMIs other than the LAPIC should be the system error which can be disabled through the RTC port, so I think your second paragraph here is way more mechanism than you need for very little gain.
I forgot about the RTC port. I can't seem to find the documentation for it, but I believe it was port 0x70? That would cover external NMIs I believe. Leaving the disable_lapic would cover internal NMIs.
I don't know how far do we want to go with installing stub idt handlers and such. Honestly, I just wanted to i/o apic race condition fixed.
http://lkml.indiana.edu/hypermail/linux/kernel/1202.3/02533.html
Cheers,
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 17 lines · Fernando Luis Vázquez Cao
Quoted 8 lines · Eric W. Biederman
Quoted 7 lines · Don Zickus
It probably is, except I never hacked on idt code before and my assembly isn't that good. I have been trying to find examples to copy from to give it a try. So far I was using
early_idt_handlerswithearly_printkto see if I could capture some printk messages while jumping from the first kernel to the second kernel (when the otherearly_idt_handlerswould kick in for the second kernel).Quoted 4 lines
Quoted 1 line
Tips? Better examples?
That is a particularly good example. When I took a quick look earlier that is the first place we reload the idt in the kernel boot so that is one of two places that needs to be modified.
Hi Eric, Don
Quoted 7 lines
Sorry for chiming in so late.
We run into the same NMI problems and wrote some patches that tackle the kernel boot side of things. They have been extensively tested using qemu-kvm and things seem to be working as expected (after receiving an early NMI the kernel continues without problem; after the iret there is no stack corruption or register corruption).
What happens if NMI happens while we are still in purgatory code?
Thanks
Vivek
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
2012/3/7 Vivek Goyal <[email protected]>:
Quoted 20 lines · Fernando Luis Vázquez Cao
Quoted 19 lines · Eric W. Biederman
Quoted 9 lines
Quoted 7 lines · Don Zickus
It probably is, except I never hacked on idt code before and my assembly isn't that good. I have been trying to find examples to copy from to give it a try. So far I was using
early_idt_handlerswithearly_printkto see if I could capture some printk messages while jumping from the first kernel to the second kernel (when the otherearly_idt_handlerswould kick in for the second kernel).Quoted 4 lines
Quoted 1 line
Tips? Better examples?
That is a particularly good example. When I took a quick look earlier that is the first place we reload the idt in the kernel boot so that is one of two places that needs to be modified.
Hi Eric, Don
Sorry for chiming in so late.
Quoted 8 lines
Quoted 5 lines
We run into the same NMI problems and wrote some patches that tackle the kernel boot side of things. They have been extensively tested using qemu-kvm and things seem to be working as expected (after receiving an early NMI the kernel continues without problem; after the iret there is no stack corruption or register corruption).
What happens if NMI happens while we are still in purgatory code?
yes, you are right. that is too late to set that in arch/x86/kernel/head64.c
i even not get print out "early console in decompress_kernel" from arch/x86/boot/compressed/misc.c::decompress_kernel()
Yinghai
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 8 lines · Yinghai Lu
2012/3/7 Vivek Goyal<[email protected]>:
Quoted 7 lines · Fernando Luis Vázquez Cao
Quoted 5 lines
We run into the same NMI problems and wrote some patches that tackle the kernel boot side of things. They have been extensively tested using qemu-kvm and things seem to be working as expected (after receiving an early NMI the kernel continues without problem; after the iret there is no stack corruption or register corruption).
What happens if NMI happens while we are still in purgatory code?
The system triple faults. As Eric said we need to fix both the reboot path to kdump and kdump kernel's boot code. The two patches I sent address the later. I sent these first because I had time to test them properly, fix a real issue and can be applied independently.
Quoted 1 line
yes, you are right. that is too late to set that in
arch/x86/kernel/head64.c
Of course, the reboot path needs to be fixed too. Now that I solved some problems I was having with my qemu-kvm test environment (NMIs injected through the qemu monitor only get devivered to the BSP, etc), I will make sure that the code I wrote for it works as expected.
In the meantime, I would appreciate it if you could review/ack yesterday's patches.
Thanks,
Fernando
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
From: Fernando Luis Vázquez Cao <[email protected]>
Subject: Re: [tip:x86/debug] x86/kdump: No need to disable ioapic/ lapic in crash path
Date: Wed, 07 Mar 2012 19:53:16 +0900
Quoted 32 lines · Eric W. Biederman
Quoted 13 lines
Quoted 11 lines · Don Zickus
It probably is, except I never hacked on idt code before and my assembly
isn't that good. I have been trying to find examples to copy from to give
it a try. So far I was usingearly_idt_handlerswithearly_printkto see
if I could capture some printk messages while jumping from the first kernel to the second kernel (when the otherearly_idt_handlerswould kick
in for the second kernel).Quoted 5 lines
Quoted 1 line
Tips? Better examples?
That is a particularly good example. When I took a quick look earlier that is the first place we reload the idt in the kernel boot so that is
one of two places that needs to be modified.Hi Eric, Don
Sorry for chiming in so late.
We run into the same NMI problems and wrote some patches that tackle the kernel boot side of things. They have been extensively tested using
qemu-kvm and things seem to be working as expected (after receiving an early NMI the kernel continues without problem; after the iret there is no
stack corruption or register corruption).
Quoted 2 lines
I will be replying to this email with the patches.
Should the following also be fixed?
/*
* Do not allocate memory (or fail in any way) in machine_kexec().
* We are past the point of no return, committed to rebooting now. */
void machine_kexec(struct kimage *image)
{
unsigned long page_list[PAGES_NR];
void *control_page;
int save_ftrace_enabled;
<cut>
/*
* The gdt & idt are now invalid.
* If you want to load them you must set up your own idt & gdt.
*/
set_gdt(phys_to_virt(0), 0);
set_idt(phys_to_virt(0), 0); <--- ThisThanks.
HATAYAMA, Daisuke
Quoted 36 lines · HATAYAMA Daisuke
From: Fernando Luis Vázquez Cao <[email protected]>
Subject: Re: [tip:x86/debug] x86/kdump: No need to disable ioapic/ lapic in crash path
Date: Wed, 07 Mar 2012 19:53:16 +0900Quoted 32 lines · Eric W. Biederman
Quoted 13 lines
Quoted 11 lines · Don Zickus
It probably is, except I never hacked on idt code before and my assembly
isn't that good. I have been trying to find examples to copy from to give
it a try. So far I was usingearly_idt_handlerswithearly_printkto see
if I could capture some printk messages while jumping from the first kernel to the second kernel (when the otherearly_idt_handlerswould kick
in for the second kernel).Quoted 5 lines
Quoted 1 line
Tips? Better examples?
That is a particularly good example. When I took a quick look earlier that is the first place we reload the idt in the kernel boot so that is
one of two places that needs to be modified.Hi Eric, Don
Sorry for chiming in so late.
We run into the same NMI problems and wrote some patches that tackle the kernel boot side of things. They have been extensively tested using
qemu-kvm and things seem to be working as expected (after receiving an early NMI the kernel continues without problem; after the iret there is no
stack corruption or register corruption).
Quoted 4 lines
Quoted 2 lines
I will be replying to this email with the patches.
Should the following also be fixed?
Most definitely. I think Fernando said he was going to tackle that next.
Eric
Quoted 17 lines
/*
* Do not allocate memory (or fail in any way) inmachine_kexec().
* We are past the point of no return, committed to rebooting now. */
voidmachine_kexec(struct kimage *image){ unsigned long page_list[PAGES_NR]; void *control_page; int save_ftrace_enabled; <cut> /* * The gdt & idt are now invalid. * If you want to load them you must set up your own idt & gdt. */ set_gdt(phys_to_virt(0), 0); set_idt(phys_to_virt(0), 0); <--- This
Quoted 2 lines
Thanks.
HATAYAMA, Daisuke
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 78 lines · Yinghai Lu
Quoted 69 lines · tip-bot for Don Zickus
Commit-ID: d9bc9be89629445758670220787683e37c93f6c1
Gitweb: http://git.kernel.org/tip/d9bc9be89629445758670220787683e37c93f6c1
Author: Don Zickus <[email protected]>
AuthorDate: Thu, 9 Feb 2012 16:53:41 -0500
Committer: Ingo Molnar <[email protected]>
CommitDate: Sat, 11 Feb 2012 15:38:53 +0100x86/kdump: No need to disable ioapic/lapic 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 ofdisable_IO_APIC, was that the jiffies 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 jiffies calibration code not needing the PIT. As a result, we can remove this call and simplify the locking needed in the panic path.
The same work allowed us to remove the need to disable the local apic on shutdown too. This should allow us to jump to the second a little faster.
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 6 lines
I also tested using lkdtm that would use jprobes to panic the system when entering
do_IRQ. The idea was to see how the system reacted with an interrupt pending in the second kernel. My core2 quad successfully kdump'd 3 times in a row with no issues.v2: removed the disable lapic code too
Quoted 7 lines
with this commit, kdump is not working anymore on my setups with Nehalem, Westmere, sandbridge.
these setup all have VT-d enabled.After reverting this commit, kdump is working again.
So assume you need to drop this patch.
Dropped the patch, thanks for reporting this.
Don, Eric?
Ingo
Quoted 6 lines · Yinghai Lu
Quoted 2 lines
v2: removed the disable lapic code too
with this commit, kdump is not working anymore on my setups with Nehalem, Westmere, sandbridge.
these setup all have VT-d enabled.
Hi Yinghai,
Thanks for the report. Can you attach the .config you were using and what vendor you were using for Nehalem, Westmere and Sandybridge. I'll try to reproduce it in my lab.
Cheers,
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 8 lines · Don Zickus
Quoted 6 lines · Yinghai Lu
Quoted 2 lines
v2: removed the disable lapic code too
with this commit, kdump is not working anymore on my setups with Nehalem, Westmere, sandbridge.
these setup all have VT-d enabled.
Quoted 5 lines
Hi Yinghai,
Thanks for the report. Can you attach the .config you were using and what vendor you were using for Nehalem, Westmere and Sandybridge. I'll try to reproduce it in my lab.
Sure, please check attached one
Yinghai
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 9 lines · Yinghai Lu
Quoted 8 lines · Don Zickus
Quoted 6 lines · Yinghai Lu
Quoted 2 lines
v2: removed the disable lapic code too
with this commit, kdump is not working anymore on my setups with Nehalem, Westmere, sandbridge.
these setup all have VT-d enabled.
Quoted 7 lines
Quoted 5 lines
Hi Yinghai,
Thanks for the report. Can you attach the .config you were using and what vendor you were using for Nehalem, Westmere and Sandybridge. I'll try to reproduce it in my lab.
Sure, please check attached one
Looks like I can reproduce the hang with my original patch and things work when we stick the disable_local_APIC() back in there. I'll keep poking.
Cheers,
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 12 lines · Don Zickus
Quoted 11 lines · Yinghai Lu
Quoted 10 lines · Don Zickus
Quoted 6 lines · Yinghai Lu
Quoted 2 lines
v2: removed the disable lapic code too
with this commit, kdump is not working anymore on my setups with Nehalem, Westmere, sandbridge.
these setup all have VT-d enabled.Hi Yinghai,
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Thanks for the report. Can you attach the .config you were using and what vendor you were using for Nehalem, Westmere and Sandybridge. I'll try to reproduce it in my lab.
Sure, please check attached one
Looks like I can reproduce the hang with my original patch and things work when we stick the
disable_local_APIC()back in there. I'll keep poking.
Hmm, my config worked fine in both cases, hence why I didn't catch it (its based on a bloated Fedora config). I'll look at the differences to see if something pops out.
Cheers,
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 9 lines · Yinghai Lu
Quoted 8 lines · Don Zickus
Quoted 6 lines · Yinghai Lu
Quoted 2 lines
v2: removed the disable lapic code too
with this commit, kdump is not working anymore on my setups with Nehalem, Westmere, sandbridge.
these setup all have VT-d enabled.
Quoted 7 lines
Quoted 5 lines
Hi Yinghai,
Thanks for the report. Can you attach the .config you were using and what vendor you were using for Nehalem, Westmere and Sandybridge. I'll try to reproduce it in my lab.
Sure, please check attached one
For some reason using gzip instead of xz makes things work for me with your config.
CONFIG_KERNEL_GZIP=yCONFIG_KERNEL_XZ=n
Do you see the same thing?
Cheers,
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 8 lines · Don Zickus
For some reason using gzip instead of xz makes things work for me with your config.
CONFIG_KERNEL_GZIP=yCONFIG_KERNEL_XZ=nDo you see the same thing?
no.
with GZIP still get instant reset.
Yinghai
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 5 lines · Yinghai Lu
Quoted 4 lines · Don Zickus
For some reason using gzip instead of xz makes things work for me with your config.
Quoted 8 lines
Quoted 4 lines
CONFIG_KERNEL_GZIP=yCONFIG_KERNEL_XZ=nDo you see the same thing?
no.
with GZIP still get instant reset.
What about my other idea, 'echo 0 > /proc/sys/kernel/nmi_watchdog'?
Cheers,
Don
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec