MIPS: SGI-IP27: print the NMI dump on an nbcon console
Subsystems (2)
PATCH 1/1 MIPS: SGI-IP27: print the NMI dump on an nbcon console
Since the 8250 console became nbcon, printk() in nmi_dump() only queues records for the printer thread, which never runs because no CPU leaves the NMI handler before the hub reset. Print the dump from an emergency section.
--- arch/mips/sgi-ip27/ip27-nmi.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/mips/sgi-ip27/ip27-nmi.c +7 -0
@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/console.h> #include <linux/kernel.h> #include <linux/mmzone.h> #include <linux/nodemask.h>
@@ -183,6 +184,12 @@ static void nmi_dump(void)*/ arch_spin_lock (&nmi_lock); +/* +* No CPU leaves the NMI handler before the hub reset below, so an +* nbcon console's printer thread would never print the dump. +*/ +nbcon_cpu_emergency_enter (); +#ifdef REAL_NMI_SIGNAL /* * Wait up to 15 seconds for the other cpus to respond to the NMI.
base-commit: 5dd1818b15d98d4a20806cd00b1b40320b06004f
Signature · 1 line
2.47.3
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
Since the 8250 console became nbcon,
printk()innmi_dump()only queues records for the printer thread, which never runs because no CPU leaves the NMI handler before the hub reset. Print the dump from an emergency section.Fixes d3539347022a ("serial: 8250: Switch to nbcon console, take 2")Signed-off-by Imre Kaloz <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 4 lines · Imre Kaloz
Since the 8250 console became nbcon,
printk()innmi_dump()only queues records for the printer thread, which never runs because no CPU leaves the NMI handler before the hub reset. Print the dump from an emergency section.
Please excuse my ignorance, but could you inform me about the context? When is nmi_dump() called? Does the hardware always reset/reboot/hang from this call?
Quoted 19 lines
Fixes d3539347022a ("serial: 8250: Switch to nbcon console, take 2")Signed-off-by Imre Kaloz <[email protected]>--- arch/mips/sgi-ip27/ip27-nmi.c | 7 +++++++ 1 file changed, 7 insertions(+)arch/mips/sgi-ip27/ip27-nmi.c +1
-0@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/console.h> #include <linux/kernel.h> #include <linux/mmzone.h> #include <linux/nodemask.h> @@ -183,6 +184,12 @@ static void nmi_dump(void)*/ arch_spin_lock (&nmi_lock);
arch/mips/sgi-ip27/ip27-nmi.c static void nmi_dump(void) · line 195
Quoted 10 lines
arch/mips/sgi-ip27/ip27-nmi.c +6
-0+/* +* No CPU leaves the NMI handler before the hub reset below, so an +* nbcon console's printer thread would never print the dump. +*/ +nbcon_cpu_emergency_enter (); +#ifdef REAL_NMI_SIGNAL /* * Wait up to 15 seconds for the other cpus to respond to the NMI.
The CPU enters an emergency state, but shouldn't it exit the emergency state at some point? Or does the machine always unstoppably reset/reboot/hang after this point?
John Ogness
Hi John,
Quoted 9 lines · John Ogness
Quoted 4 lines · Imre Kaloz
Since the 8250 console became nbcon,
printk()innmi_dump()only queues records for the printer thread, which never runs because no CPU leaves the NMI handler before the hub reset. Print the dump from an emergency section.Please excuse my ignorance, but could you inform me about the context? When is
nmi_dump()called? Does the hardware always reset/reboot/hang from this call?
nmi_dump() has no caller in Linux. install_cpu_nmi_handler() stores its address in the per-CPU NMI vector the PROM keeps in low memory, and the PROM jumps to it when the system controller asserts NMI on the CPUs: the "nmi" command at the L1 (or the MMSC on an Origin 2000), typically used to get a dump out of a hung machine.
Every CPU that takes the NMI enters nmi_dump(). The first one to get nmi_lock waits until all online CPUs have arrived, prints the saved state of every CPU and ends with the NI_PORT_RESET write. The others spin on nmi_lock, which is never released. No CPU goes back to the interrupted context, so the printer kthread never runs, which is why the dump never reaches the 8250 console today.
On the IP35 machines I tested the reset write takes effect and the PROM restarts right after the dump.
<snip>
Quoted 4 lines
Quoted 4 lines
arch/mips/sgi-ip27/ip27-nmi.c +0
-0@@ -183,6 +184,12 @@ static void nmi_dump(void)*/ arch_spin_lock (&nmi_lock);
Quoted 13 lines
arch/mips/sgi-ip27/ip27-nmi.c static void nmi_dump(void) · line 195
Quoted 9 lines
arch/mips/sgi-ip27/ip27-nmi.c +6
-0+/* +* No CPU leaves the NMI handler before the hub reset below, so an +* nbcon console's printer thread would never print the dump. +*/ +nbcon_cpu_emergency_enter (); +#ifdef REAL_NMI_SIGNAL /* * Wait up to 15 seconds for the other cpus to respond to the NMI. The CPU enters an emergency state, but shouldn't it exit the emergency state at some point? Or does the machine always unstoppably reset/reboot/hang after this point?
If the reset write did not take effect, nmi_dump() would return to the PROM.
Best,
Imre
Quoted 11 lines · Imre Kaloz
nmi_dump()has no caller in Linux.install_cpu_nmi_handler()stores its address in the per-CPU NMI vector the PROM keeps in low memory, and the PROM jumps to it when the system controller asserts NMI on the CPUs: the "nmi" command at the L1 (or the MMSC on an Origin 2000), typically used to get a dump out of a hung machine.Every CPU that takes the NMI enters
nmi_dump(). The first one to getnmi_lockwaits until all online CPUs have arrived, prints the saved state of every CPU and ends with theNI_PORT_RESETwrite. The others spin onnmi_lock, which is never released. No CPU goes back to the interrupted context
Thanks for the explanation. I guess it should have been obvious, also because @nmi_lock is locked and never unlocked.
arch/mips/sgi-ip27/ip27-nmi.c static void nmi_dump(void) · line 192
Quoted 10 lines
arch/mips/sgi-ip27/ip27-nmi.c +6
-0@@ -183,6 +184,12 @@ static void nmi_dump(void)*/ arch_spin_lock (&nmi_lock); +/* +* No CPU leaves the NMI handler before the hub reset below, so an +* nbcon console's printer thread would never print the dump. +*/ +nbcon_cpu_emergency_enter (); +
Note that putting the CPU into emergency state does not cause any printing. A later printk call is required.
Also note that only _this_ CPU is put into the emergency state. So any printk's on other CPUs will not be visible until _this_ CPU performs a printk.
In order to make sure that any backlog is flushed, I suggest also adding:
printk_trigger_flush();
after the loop waiting for the other CPUs, just before triggering the reset.
John
Hi John,
Quoted 34 lines · John Ogness
Quoted 11 lines · Imre Kaloz
nmi_dump()has no caller in Linux.install_cpu_nmi_handler()stores its address in the per-CPU NMI vector the PROM keeps in low memory, and the PROM jumps to it when the system controller asserts NMI on the CPUs: the "nmi" command at the L1 (or the MMSC on an Origin 2000), typically used to get a dump out of a hung machine.Every CPU that takes the NMI enters
nmi_dump(). The first one to getnmi_lockwaits until all online CPUs have arrived, prints the saved state of every CPU and ends with theNI_PORT_RESETwrite. The others spin onnmi_lock, which is never released. No CPU goes back to the interrupted contextThanks for the explanation. I guess it should have been obvious, also because @nmi_lock is locked and never unlocked.
arch/mips/sgi-ip27/ip27-nmi.c static void nmi_dump(void) · line 192
Quoted 10 lines
arch/mips/sgi-ip27/ip27-nmi.c +6
-0@@ -183,6 +184,12 @@ static void nmi_dump(void)*/ arch_spin_lock (&nmi_lock); +/* +* No CPU leaves the NMI handler before the hub reset below, so an +* nbcon console's printer thread would never print the dump. +*/ +nbcon_cpu_emergency_enter (); +Note that putting the CPU into emergency state does not cause any printing. A later printk call is required.
Also note that only _this_ CPU is put into the emergency state. So any printk's on other CPUs will not be visible until _this_ CPU performs a printk.
Quoted 8 lines
In order to make sure that any backlog is flushed, I suggest also adding:
printk_trigger_flush();after the loop waiting for the other CPUs, just before triggering the reset.
Makes sense, thanks. v2 will flush after the dump, right before the NI_PORT_RESET write.
Best,
Imre
Quoted 6 lines · John Ogness
Quoted 6 lines
nmi_dump()has no caller in Linux.install_cpu_nmi_handler()stores its address in the per-CPU NMI vector the PROM keeps in low memory, and the PROM jumps to it when the system controller asserts NMI on the CPUs: the "nmi" command at the L1 (or the MMSC on an Origin 2000), typically used to get a dump out of a hung machine.
Quoted 8 lines
Quoted 5 lines
Every CPU that takes the NMI enters
nmi_dump(). The first one to getnmi_lockwaits until all online CPUs have arrived, prints the saved state of every CPU and ends with theNI_PORT_RESETwrite. The others spin onnmi_lock, which is never released. No CPU goes back to the interrupted contextThanks for the explanation. I guess it should have been obvious, also because @nmi_lock is locked and never unlocked.
Mind that NMI on MIPS is not recoverable in the general case, unlike with
say x86.
First the event takes the reset vector, which typically is handled by the
machine firmware and while it can be told apart by software from other events causing execution to reach there, it requires a machine-specific protocol.
The use of the error level for the exception handler switches off the MMU
for KUSEG and lets the register context be dumped for later restoration using $zero register as the base pointer, but again it has to be there in the firmware and then not to clash with OS use of memory. Alternatively scratch GPRs could be put aside for NMI handling in the ABI such as with the kernel $k0-$k1 registers, but that'd be an overkill wasting precious resources.
Then nesting is not supported since obviously it would clobber the state
of the outer NMI handler, so that'd have to be prevented from triggering by system circuitry until cleared by software. There's no internal latch in the CPU such as with x86 that would prevent an NMI from retriggering.
All in all we do not strive to recover and only dump available state for
any post-mortem examination. Some platforms can't even do that.
Maciej