Skip to contentSkip to conversation

Adding ctrl-o sysrq hack support to 8250 driver

PATCH In review Olaf Hering 4 participants 12 messages Dec 9, 2005 – Jan 3, 2006 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Adding ctrl-o sysrq hack support to 8250 driver

If you can queue this up in -mm for a decade or two, just to make sure it doesnt make some setup unhappy.

a POWER4 system in 'full-system-partition' mode has the console device on ttyS0. But the user interface to the Linux system console may still be on the hardware management console (HMC). If this is the case, there is no way to send a break to trigger a sysrq.
Other setups do already use 'ctrl o' to trigger sysrq. This includes iSeries virtual console on tty1, and pSeries LPAR console on hvc0 or hvsi0.

'ctrl o' is currently mapped to 'flush output', see 'stty -a'

 drivers/serial/8250.c |    7 +++++++
 1 files changed, 7 insertions(+)
drivers/serial/8250.c +7 -0
Index: linux-2.6.15-rc5-olh/drivers/serial/8250.c
===================================================================
@@ -1154,6 +1154,13 @@ receive_chars(struct uart_8250_port *up,
 			 */
 		}
 		ch = serial_inp(up, UART_RX);
+
+#if defined(CONFIG_MAGIC_SYSRQ) && defined(CONFIG_SERIAL_CORE_CONSOLE)
+		/* Handle the SysRq ^O Hack, but only on the system console */
+		if (ch == '\x0f' && uart_handle_break(&up->port))
+			goto ignore_char;
+#endif
+
 		flag = TTY_NORMAL;
 		up->port.icount.rx++;
 
Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan
#1 lore raw
Quoted 5 lines · Olaf Hering

If you can queue this up in -mm for a decade or two, just to make sure it doesnt make some setup unhappy.

Quoted 8 lines

a POWER4 system in 'full-system-partition' mode has the console device on ttyS0. But the user interface to the Linux system console may still be on the hardware management console (HMC). If this is the case, there is no way to send a break to trigger a sysrq.
Other setups do already use 'ctrl o' to trigger sysrq. This includes iSeries virtual console on tty1, and pSeries LPAR console on hvc0 or hvsi0.

'ctrl o' is currently mapped to 'flush output', see 'stty -a'

I still strongly disagree with the idea of using a well defined control character which already has an expected purpose for this.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#2 lore raw
In reply to Olaf Hering
Quoted 5 lines · Olaf Hering

If you can queue this up in -mm for a decade or two, just to make sure it doesnt make some setup unhappy.

Quoted 8 lines

a POWER4 system in 'full-system-partition' mode has the console device on ttyS0. But the user interface to the Linux system console may still be on the hardware management console (HMC). If this is the case, there is no way to send a break to trigger a sysrq.
Other setups do already use 'ctrl o' to trigger sysrq. This includes iSeries virtual console on tty1, and pSeries LPAR console on hvc0 or hvsi0.

'ctrl o' is currently mapped to 'flush output', see 'stty -a'

And... you're going to make it impossible to run ppp over the serial console port. For everyone, not just your big POWER4 boxes. As far as I know, if you turn off the printk log level, this should work just fine today.

Signature · 2 lines
Daniel Jacobowitz
CodeSourcery, LLC
#3 lore raw
Quoted 4 lines · Daniel Jacobowitz

And... you're going to make it impossible to run ppp over the serial console port. For everyone, not just your big POWER4 boxes. As far as I know, if you turn off the printk log level, this should work just fine today.

Can one send break (via ppp) in this setup?

Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan
#4 lore raw
Quoted 8 lines · Olaf Hering
Quoted 4 lines · Daniel Jacobowitz

And... you're going to make it impossible to run ppp over the serial console port. For everyone, not just your big POWER4 boxes. As far as I know, if you turn off the printk log level, this should work just fine today.

Can one send break (via ppp) in this setup?

Huh?

Maybe I'm misunderstanding your patch, but the issue is that you've just made the serial console not-eight-bit-clean.

Signature · 2 lines
Daniel Jacobowitz
CodeSourcery, LLC
#5 lore raw
Quoted 2 lines · Daniel Jacobowitz

Maybe I'm misunderstanding your patch, but the issue is that you've just made the serial console not-eight-bit-clean.

True. Have to throw more stuff in the if() for this part of the issue.

Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan
#6 lore raw
In reply to Olaf Hering
Quoted 6 lines · Olaf Hering

a POWER4 system in 'full-system-partition' mode has the console device on ttyS0. But the user interface to the Linux system console may still be on the hardware management console (HMC). If this is the case, there is no way to send a break to trigger a sysrq.
Other setups do already use 'ctrl o' to trigger sysrq. This includes iSeries virtual console on tty1, and pSeries LPAR console on hvc0 or hvsi0.

So it's a POWER4 problem.

Quoted 1 line

'ctrl o' is currently mapped to 'flush output', see 'stty -a'

Eww... If you can't use a serial break, why can't you use an established control character like ctrl-] (telnet) or [enter]~ (ssh) ?

If you really want to use ctrl-o, could you make a way that pressing ctrl-o twice sends a single ctrl-o to the process attached to the console?

Quoted 10 lines
 drivers/serial/8250.c |    7 +++++++
 1 files changed, 7 insertions(+)

Index: linux-2.6.15-rc5-olh/drivers/serial/8250.c
===================================================================

drivers/serial/8250.c receive_chars(struct uart_8250_port *up, · line 1158

Quoted 5 lines
drivers/serial/8250.c +2 -0
@@ -1154,6 +1154,13 @@ receive_chars(struct uart_8250_port *up,
 			 */
 		}
 		ch = serial_inp(up, UART_RX);
+
+#if defined(CONFIG_MAGIC_SYSRQ) && defined(CONFIG_SERIAL_CORE_CONSOLE)

If it is a POWER4-only problem, why isn't there a dependency on CONFIG_POWER4 over here? I don't like to have the ctrl-o sysrq stuff enabled on my regular PC if it only matters to some rare (in absolute numbers) system.

Erik

Signature · 2 lines
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands
#7 lore raw
Quoted 4 lines · Erik Mouw
Quoted 1 line

'ctrl o' is currently mapped to 'flush output', see 'stty -a'

Eww... If you can't use a serial break, why can't you use an established control character like ctrl-] (telnet) or [enter]~ (ssh) ?

There are many ways to get to the console session on the HMC. One is ssh. But maybe this would work somehow.

Quoted 3 lines

If you really want to use ctrl-o, could you make a way that pressing ctrl-o twice sends a single ctrl-o to the process attached to the console?

Sounds good. Have to check how to handle that.

Quoted 4 lines

If it is a POWER4-only problem, why isn't there a dependency on CONFIG_POWER4 over here? I don't like to have the ctrl-o sysrq stuff enabled on my regular PC if it only matters to some rare (in absolute numbers) system.

More CONFIG_PPC_PSERIES, the mentioned option is for gcc optimization.

Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan
#8 lore raw
Quoted 4 lines · Olaf Hering
Quoted 4 lines

If it is a POWER4-only problem, why isn't there a dependency on CONFIG_POWER4 over here? I don't like to have the ctrl-o sysrq stuff enabled on my regular PC if it only matters to some rare (in absolute numbers) system.

The system with the build tree on it just crashed hard. Thats what I saved from the screen session:

drivers/serial/8250.c +6 -0
Index: linux-2.6.15-rc5-olh/drivers/serial/8250.c
===================================================================
@@ -85,6 +85,8 @@ static unsigned int share_irqs = SERIAL8
 #define CONFIG_SERIAL_MANY_PORTS 1
 #endif
 
+#define arch_8250_sysrq_via_ctrl_o(x) (0)
+
 /*
  * HUB6 is always on.  This will be removed once the header
  * files have been cleaned.
@@ -1154,6 +1156,10 @@ receive_chars(struct uart_8250_port *up,
                         */
                }
                ch = serial_inp(up, UART_RX);
+
+               if (arch_8250_sysrq_via_ctrl_o(ch, &up->port))
+                       goto ignore_char;
+
                flag = TTY_NORMAL;
                up->port.icount.rx++;
 
include/asm-powerpc/serial.h +7 -0
Index: linux-2.6.15-rc5-olh/include/asm-powerpc/serial.h
===================================================================
@@ -15,4 +15,11 @@
 /* Default baud base if not found in device-tree */
 #define BASE_BAUD ( 1843200 / 16 )
 
+
+#if defined(SUPPORT_SYSRQ) && defined(CONFIG_PPC_PSERIES)
+       /* Handle the SysRq ^O Hack, but only on the system console */
+#undef arch_8250_sysrq_via_ctrl_o
+#define arch_8250_sysrq_via_ctrl_o(ch, port) ((ch) == '\x0f' && uart_handle_break((port)))
+#endif
+
 #endif /* _PPC64_SERIAL_H */
Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan
#9 lore raw
In reply to Erik Mouw
Quoted 3 lines · Erik Mouw

If you really want to use ctrl-o, could you make a way that pressing ctrl-o twice sends a single ctrl-o to the process attached to the console?

That's already handled by adding uart_handle_break() - the first call to this function will set sysrq status and return 1 (ignore character). The second call will clear sysrq status and return 0 (don't ignore).

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#10 lore raw
Quoted 8 lines · Russell King
Quoted 3 lines · Erik Mouw

If you really want to use ctrl-o, could you make a way that pressing ctrl-o twice sends a single ctrl-o to the process attached to the console?

That's already handled by adding uart_handle_break() - the first call to this function will set sysrq status and return 1 (ignore character). The second call will clear sysrq status and return 0 (don't ignore).

Russel,
are you ok with the arch specific approach? I could trim it down further by checking the model type in the device-tree, somewhere in arch/powerpc/kernel/setup-common.c.

 drivers/serial/8250.c        |    6 ++++++
 include/asm-powerpc/serial.h |   19 +++++++++++++++++++
 2 files changed, 25 insertions(+)
drivers/serial/8250.c +6 -0
Index: linux-2.6.15-rc5-olh/drivers/serial/8250.c
===================================================================
@@ -85,6 +85,8 @@ static unsigned int share_irqs = SERIAL8
 #define CONFIG_SERIAL_MANY_PORTS 1
 #endif
 
+#define arch_8250_sysrq_via_ctrl_o(x) (0)
+
 /*
  * HUB6 is always on.  This will be removed once the header
  * files have been cleaned.
@@ -1154,6 +1156,10 @@ receive_chars(struct uart_8250_port *up,
 			 */
 		}
 		ch = serial_inp(up, UART_RX);
+
+		if (arch_8250_sysrq_via_ctrl_o(ch, &up->port))
+			goto ignore_char;
+
 		flag = TTY_NORMAL;
 		up->port.icount.rx++;
 
include/asm-powerpc/serial.h +19 -0
Index: linux-2.6.15-rc5-olh/include/asm-powerpc/serial.h
===================================================================
@@ -15,4 +15,23 @@
 /* Default baud base if not found in device-tree */
 #define BASE_BAUD ( 1843200 / 16 )
 
+
+#if defined(SUPPORT_SYSRQ) && defined(CONFIG_PPC_PSERIES)
+	/*
+	 * Handle the SysRq ^O Hack also via ttyS0 on POWER4 systems
+	 * but only on the system console
+	 * affected Models:
+	 * p690 7040-681
+	 * p670 7040-671
+	 * p655 7039-651
+	 * p650 7038-6M2
+	 * p630 7028-6E4 tower
+	 * p630 7028-6C4 rack
+	 * p615 7029-6E3 tower
+	 * p615 7029-6C3 rack
+	 */
+#undef arch_8250_sysrq_via_ctrl_o
+#define arch_8250_sysrq_via_ctrl_o(ch, port) ((ch) == '\x0f' && uart_handle_break((port)))
+#endif
+
 #endif /* _PPC64_SERIAL_H */
Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan
#11 lore raw

On Mon, Dec 12, Olaf Hering wrote:

Russell,
are you ok with the arch specific approach?

a POWER4 system in 'full-system-partition' mode has the console device on ttyS0. But the user interface to the Linux system console may still be on the hardware management console (HMC). If this is the case, there is no way to send a break to trigger a sysrq.
Other setups do already use 'ctrl o' to trigger sysrq. This includes iSeries virtual console on tty1, and pSeries LPAR console on hvc0 or hvsi0.

To limit the 'ctrl o' only to the affected systems, query the model property in the device-tree. The patch makes the serial console not-eight-bit-clean. Booting with 'console=ttyS0' will disable 'ctrl o', it is only enabled with console autodetection.

'ctrl o' is currently mapped to 'flush output', see 'stty -a'

 arch/powerpc/kernel/setup-common.c |   45 +++++++++++++++++++++++++++++++++++++
 drivers/serial/8250.c              |    4 +++
 include/asm-powerpc/serial.h       |    6 ++++
 3 files changed, 55 insertions(+)
arch/powerpc/kernel/setup-common.c +45 -0
Index: linux-2.6.15-rc6-olh/arch/powerpc/kernel/setup-common.c
===================================================================
@@ -295,6 +295,48 @@ struct seq_operations cpuinfo_op = {
 };
 
 #ifdef CONFIG_PPC_MULTIPLATFORM
+#if defined(CONFIG_PPC_PSERIES) && defined(CONFIG_SERIAL_8250_CONSOLE)
+/*
+ * Handle the SysRq ^O Hack also via ttyS0 on POWER4 systems
+ * but only on the system console, see asm/serial.h
+ * If they run in FullSystemPartition mode, the firmware console comes in via ttyS0
+ * But BREAK does not work via the HMC, to trigger sysrq.
+ * Affected Models:
+ * p690 7040-681
+ * p670 7040-671
+ * p655 7039-651
+ * p650 7038-6M2
+ * p630 7028-6E4 tower
+ * p630 7028-6C4 rack
+ * p615 7029-6E3 tower
+ * p615 7029-6C3 rack
+ */
+int power4_sysrq_via_ctrl_o;
+
+static void detect_power4_console(void)
+{
+	struct device_node *root;
+	char *model;
+
+	root = of_find_node_by_path("/");
+	if (root) {
+		model = get_property(root, "model", NULL);
+		if (model) {
+			if(!strcmp(model, "IBM,7040-681") ||
+			   !strcmp(model, "IBM,7040-671") ||
+			   !strcmp(model, "IBM,7039-651") ||
+			   !strcmp(model, "IBM,7038-6M2") ||
+			   !strcmp(model, "IBM,7028-6E4") ||
+			   !strcmp(model, "IBM,7028-6C4") ||
+			   !strcmp(model, "IBM,7029-6E3") ||
+			   !strcmp(model, "IBM,7029-6C3"))
+				power4_sysrq_via_ctrl_o = 1;
+		}
+		of_node_put(root);
+	}
+}
+#endif
+
 static int __init set_preferred_console(void)
 {
 	struct device_node *prom_stdout = NULL;
@@ -359,6 +401,9 @@ static int __init set_preferred_console(
 					/* We dont recognise the serial port */
 					goto not_found;
 			}
+#ifdef CONFIG_PPC_PSERIES
+			detect_power4_console();
+#endif /* CONFIG_PPC_PSERIES */
 		}
 	}
 #endif /* CONFIG_SERIAL_8250_CONSOLE */
drivers/serial/8250.c +4 -0
Index: linux-2.6.15-rc6-olh/drivers/serial/8250.c
===================================================================
@@ -85,6 +85,8 @@ static unsigned int share_irqs = SERIAL8
 #define CONFIG_SERIAL_MANY_PORTS 1
 #endif
 
+#define arch_8250_sysrq_via_ctrl_o(x) (0)
+
 /*
  * HUB6 is always on.  This will be removed once the header
  * files have been cleaned.
@@ -1154,6 +1156,8 @@ receive_chars(struct uart_8250_port *up,
 			 */
 		}
 		ch = serial_inp(up, UART_RX);
+		if (arch_8250_sysrq_via_ctrl_o(ch, &up->port))
+			goto ignore_char;
 		flag = TTY_NORMAL;
 		up->port.icount.rx++;
 
include/asm-powerpc/serial.h +6 -0
Index: linux-2.6.15-rc6-olh/include/asm-powerpc/serial.h
===================================================================
@@ -15,4 +15,10 @@
 /* Default baud base if not found in device-tree */
 #define BASE_BAUD ( 1843200 / 16 )
 
+#if defined(SUPPORT_SYSRQ) && defined(CONFIG_PPC_PSERIES)
+#undef arch_8250_sysrq_via_ctrl_o
+extern int power4_sysrq_via_ctrl_o;
+#define arch_8250_sysrq_via_ctrl_o(ch, port) ((ch) == '\x0f' && power4_sysrq_via_ctrl_o && uart_handle_break((port)))
+#endif
+
 #endif /* _PPC64_SERIAL_H */
Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan