Skip to contentSkip to conversation

sysrq: secondary sysrq key table

RFC/PATCH Randy Dunlap 1 participant 1 message Apr 2, 2008

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi,

Ingo noticed that the sysrq table is close to filling up. Has anyone thought about how to handle that condition?

Here's one patch for it, although I'm not entirely thrilled with it. Any other suggestions?

Thanks.
---

From: Randy Dunlap <[email protected]>

We are close to running out of empty sysrq table entries, so add a way to extend sysrq handling. This extension takes sysrq-= + next_key to mean "use the alternate sysrq table for handling of <next_key>". This also works with "echo =X > /proc/sysrq-trigger".

SysRq help text now looks like this:

SysRq : HELP : loglevel0-8 reBoot tErm Full kIll saK showMem Nice powerOff showPc show-all-timers(Q) unRaw Sync showTasks Unmount shoW-blocked-tasks SysRq-= HELP : sleep(Z)

where SysRq-=-z (for sleep) is just an example.

---
 Documentation/sysrq.txt |   21 +++++---
 drivers/char/keyboard.c |   10 +++
 drivers/char/sysrq.c    |  122 ++++++++++++++++++++++++++++++++++++++++++------
 fs/proc/proc_misc.c     |    8 ++-
 include/linux/sysrq.h   |   15 +++++
 5 files changed, 151 insertions(+), 25 deletions(-)
include/linux/sysrq.h +13 -2
@@ -37,6 +37,9 @@ struct sysrq_key_op {
 
 #ifdef CONFIG_MAGIC_SYSRQ
 
+/* used to extend primary sysrq key table to secondary key table */
+#define SYSRQ_EXTEND_KEY	'='
+
 extern int sysrq_on(void);
 
 /*
@@ -50,10 +53,15 @@ extern int __sysrq_enabled;
  */
 
 void handle_sysrq(int key, struct tty_struct *tty);
-void __handle_sysrq(int key, struct tty_struct *tty, int check_mask);
+void handle_sysrq_extend(int key, struct tty_struct *tty);
+void __handle_sysrq(struct sysrq_key_op **op_table, int key,
+			struct tty_struct *tty, int check_mask);
 int register_sysrq_key(int key, struct sysrq_key_op *op);
 int unregister_sysrq_key(int key, struct sysrq_key_op *op);
-struct sysrq_key_op *__sysrq_get_key_op(int key);
+struct sysrq_key_op *__sysrq_get_key_op(struct sysrq_key_op **op_table, int key);
+
+extern struct sysrq_key_op *sysrq_key_table[36];
+extern struct sysrq_key_op *sysrq_key_table2[36];
 
 #else
 
@@ -68,6 +76,9 @@ static inline int __reterr(void)
 static inline void handle_sysrq(int key, struct tty_struct *tty)
 {
 }
+static inline void handle_sysrq_extend(int key, struct tty_struct *tty)
+{
+}
 
 #define register_sysrq_key(ig,nore) __reterr()
 #define unregister_sysrq_key(ig,nore) __reterr()
drivers/char/keyboard.c +9 -1
@@ -157,6 +157,7 @@ unsigned char kbd_sysrq_xlate[KEY_MAX + 
         "\r\000/";                                      /* 0x60 - 0x6f */
 static int sysrq_down;
 static int sysrq_alt_use;
+static int sysrq_extend;
 #endif
 static int sysrq_alt;
 
@@ -1189,7 +1190,14 @@ static void kbd_keycode(unsigned int key
 	if (sysrq_down && !down && keycode == sysrq_alt_use)
 		sysrq_down = 0;
 	if (sysrq_down && down && !rep) {
-		handle_sysrq(kbd_sysrq_xlate[keycode], tty);
+		if (sysrq_extend) {
+			handle_sysrq_extend(kbd_sysrq_xlate[keycode], tty);
+			sysrq_extend = 0;
+		}
+		else if (kbd_sysrq_xlate[keycode] == SYSRQ_EXTEND_KEY)
+			sysrq_extend = 1;
+		else
+			handle_sysrq(kbd_sysrq_xlate[keycode], tty);
 		return;
 	}
 #endif
drivers/char/sysrq.c +107 -15

202 lines not on this page · raw message

fs/proc/proc_misc.c +7 -1
@@ -669,7 +669,13 @@ static ssize_t write_sysrq_trigger(struc
 
 		if (get_user(c, buf))
 			return -EFAULT;
-		__handle_sysrq(c, NULL, 0);
+		if (c == SYSRQ_EXTEND_KEY) {
+			if (count <= 1 || get_user(c, buf + 1))
+				return -EFAULT;
+			__handle_sysrq(sysrq_key_table2, c, NULL, 0);
+		}
+		else
+			__handle_sysrq(sysrq_key_table, c, NULL, 0);
 	}
 	return count;
 }
Documentation/sysrq.txt +15 -6
@@ -1,6 +1,6 @@
 Linux Magic System Request Key Hacks
 Documentation for sysrq.c
-Last update: 2007-AUG-04
+Last update: 2008-APR-01
 
 *  What is the magic SysRq key?
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -39,13 +39,18 @@ allowed (by a user with admin privileges
 
 *  How do I use the magic SysRq key?
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-On x86   - You press the key combo 'ALT-SysRq-<command key>'. Note - Some
+On x86   - You press the key combo 'ALT-SysRq-<command key>'. Note: Some
            keyboards may not have a key labeled 'SysRq'. The 'SysRq' key is
            also known as the 'Print Screen' key. Also some keyboards cannot
 	   handle so many keys being pressed at the same time, so you might
 	   have better luck with "press Alt", "press SysRq", "release SysRq",
 	   "press <command key>", release everything.
 
+	   Extended SysRq key handling is indicated by using
+	   'ALT-SysRq-=-<command key>'.  The Alt and SysRq keys should be
+	   held down while pressing the '=' key and the following
+	   command key.
+
 On SPARC - You press 'ALT-STOP-<command key>', I believe.
 
 On the serial console (PC style standard serial ports only) -
@@ -58,9 +63,13 @@ On PowerPC - Press 'ALT - Print Screen (
 On other - If you know of the key combos for other architectures, please
            let me know so I can add them to this section.
 
-On all -  write a character to /proc/sysrq-trigger.  e.g.:
+On all -  write a character(s) to /proc/sysrq-trigger.  E.g.:
 
 		echo t > /proc/sysrq-trigger
+	  or
+		echo =z > /proc/sysrq-trigger
+
+	  for extended SysRq key handling.
 
 *  What are the 'command' keys?
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -177,10 +186,10 @@ for ten seconds.
 *  I want to add SysRQ key events to a module, how does it work?
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 In order to register a basic function with the table, you must first include
-the header 'include/linux/sysrq.h', this will define everything else you need.
+the header 'include/linux/sysrq.h'. This will define everything else you need.
 Next, you must create a sysrq_key_op struct, and populate it with A) the key
-handler function you will use, B) a help_msg string, that will print when SysRQ
-prints help, and C) an action_msg string, that will print right before your
+handler function you will use, B) a help_msg string that will print when SysRQ
+prints help, and C) an action_msg string that will print right before your
 handler is called. Your handler must conform to the prototype in 'sysrq.h'.
 
 After the sysrq_key_op is created, you can call the kernel function