Skip to contentSkip to conversation

MIPS: SGI-IP27: print the NMI dump on an nbcon console

PATCH Applied Imre Kaloz 6 participants 6 messages Oct 1 – Nov 5

Subsystems (2)
lore
Share & tools
lore

Imre Kaloz

author
#0 lore raw

PATCH v2 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 a printer thread that never runs, as no CPU leaves the NMI handler. Print from an emergency section and flush pending records before the hub reset.

Fixes d3539347022a ("serial: 8250: Switch to nbcon console, take 2")

---
v2: flush pending records before the hub reset (John Ogness)
v1: https://lore.kernel.org/all/[email protected]/

This conflicts by context with patch 14/38 of the IP35 series,
https://lore.kernel.org/all/76f2a9c32eba23de36817f0a186def01e009e1c7.1790857966.git.kaloz@kernel.org/
which rewrites the reset write. Whichever lands second places the printk_trigger_flush() call above the system_is_ip35 branch.

 arch/mips/sgi-ip27/ip27-nmi.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/mips/sgi-ip27/ip27-nmi.c +8 -0
index fc2816398d0c..c502982621e6 100644
@@ -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.
@@ -227,5 +234,6 @@ static void nmi_dump(void)
 	 * Save the nmi cpu registers for all cpu in the eframe format.
 	 */
 	nmi_eframes_save();
+	printk_trigger_flush();
 	LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET);
 }
Signature · 1 line
2.47.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Imre Kaloz

Since the 8250 console became nbcon, printk() in nmi_dump() only queues records for a printer thread that never runs, as no CPU leaves the NMI handler. Print from an emergency section and flush pending records before the hub reset.

Fixes d3539347022a ("serial: 8250: Switch to nbcon console, take 2")
Reviewed-by on v2 1/1
#2 lore raw
In reply to Imre Kaloz
Quoted 7 lines · Imre Kaloz

Since the 8250 console became nbcon, printk() in nmi_dump() only queues records for a printer thread that never runs, as no CPU leaves the NMI handler. Print from an emergency section and flush pending records before the hub reset.

Fixes d3539347022a ("serial: 8250: Switch to nbcon console, take 2")

Looks good to me:

I assume that it would go via mips or drivers tree. Please, let me know if you would prefer to push it via printk tree.

Best Regards,
Petr

#3 lore raw
Quoted 9 lines · Petr Mladek
Quoted 7 lines · Imre Kaloz

Since the 8250 console became nbcon, printk() in nmi_dump() only queues records for a printer thread that never runs, as no CPU leaves the NMI handler. Print from an emergency section and flush pending records before the hub reset.

Fixes d3539347022a ("serial: 8250: Switch to nbcon console, take 2")
Quoted 6 lines

Looks good to me:

I assume that it would go via mips or drivers tree. Please, let me know if you would prefer to push it via printk tree.

Should probably go through a mips tree to resolve the conflicts.

thanks,

greg k-h

#4 lore raw
In reply to Imre Kaloz
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] printk: NMI dump output lost due to nbcon timeout if console is in unsafe state --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] printk: NMI dump output lost due to nbcon timeout if console is in unsafe state --

commit f9358977a85eff3b02febdb716b027b3e2f5107f
Author: Imre Kaloz <[email protected]>

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 a printer thread that never runs, as no CPU leaves the NMI handler. Print from an emergency section and flush pending records before the hub reset.

arch/mips/sgi-ip27/ip27-nmi.c static void nmi_dump(void) · line 185

Quoted 7 lines
arch/mips/sgi-ip27/ip27-nmi.c +0 -0
index fc2816398d0cf..c502982621e6b 100644
@@ -183,6 +184,12 @@ static void nmi_dump(void)
 	 */
 	arch_spin_lock(&nmi_lock);

[Severity: High]
If another CPU was interrupted while holding an nbcon console in an unsafe state, will it be trapped here spinning indefinitely on nmi_lock?

If so, it would never be able to release the console.

arch/mips/sgi-ip27/ip27-nmi.c static void nmi_dump(void) · line 191

Quoted 6 lines
arch/mips/sgi-ip27/ip27-nmi.c +5 -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();

[Severity: High]
Does entering EMERGENCY priority here instead of PANIC prevent a hostile takeover of the console?

Hostile unsafe takeovers require panic_on_this_cpu() to be true via nbcon_allow_unsafe_takeover().

Since panic() is not called during this NMI dump sequence, it appears this would fall short of allowing a takeover if the console is locked.

Quoted 3 lines
arch/mips/sgi-ip27/ip27-nmi.c +1 -0
+
 #ifdef REAL_NMI_SIGNAL
 	/*

[ ... ]

arch/mips/sgi-ip27/ip27-nmi.c static void nmi_dump(void) · line 237

Quoted 5 lines
arch/mips/sgi-ip27/ip27-nmi.c +1 -0
@@ -227,5 +234,6 @@ static void nmi_dump(void)
 	 * Save the nmi cpu registers for all cpu in the eframe format.
 	 */
 	nmi_eframes_save();
+	printk_trigger_flush();

[Severity: High]
Will this flush completely suppress the dump output if the console was held by one of the trapped CPUs?

If the system attempts a handover here, it will wait 2000us and time out because the other CPU is trapped on nmi_lock.

Following the timeout, nbcon_context_try_acquire_hostile() will fail with -EPERM because PANIC priority was not established.

Could this cause the flush to fail entirely, silently triggering a hardware reset via LOCAL_HUB_S() without outputting any diagnostic information?

Quoted 2 lines
arch/mips/sgi-ip27/ip27-nmi.c +0 -0
 	LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET);
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#5 lore raw
In reply to Imre Kaloz
Quoted 51 lines · Imre Kaloz

Since the 8250 console became nbcon, printk() in nmi_dump() only queues records for a printer thread that never runs, as no CPU leaves the NMI handler. Print from an emergency section and flush pending records before the hub reset.

Fixes d3539347022a ("serial: 8250: Switch to nbcon console, take 2")

---
v2: flush pending records before the hub reset (John Ogness)
v1: https://lore.kernel.org/all/[email protected]/

This conflicts by context with patch 14/38 of the IP35 series,
https://lore.kernel.org/all/76f2a9c32eba23de36817f0a186def01e009e1c7.1790857966.git.kaloz@kernel.org/
which rewrites the reset write. Whichever lands second places the printk_trigger_flush() call above the system_is_ip35 branch.

 arch/mips/sgi-ip27/ip27-nmi.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/mips/sgi-ip27/ip27-nmi.c +8 -0
index fc2816398d0c..c502982621e6 100644
@@ -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.
@@ -227,5 +234,6 @@ static void nmi_dump(void)
 	 * Save the nmi cpu registers for all cpu in the eframe format.
 	 */
 	nmi_eframes_save();
+	printk_trigger_flush();
 	LOCAL_HUB_S(NI_PORT_RESET, NPR_PORTRESET | NPR_LOCALRESET);
 }
Signature · 1 line
2.47.3

applied to mips-fixes

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]