CHROMIUM: sysrq: Added Chrome OS specific 'x' key
authorSameer Nanda <snanda@chromium.org>
Mon, 6 Aug 2012 16:16:21 +0000 (09:16 -0700)
committerGerrit <chrome-bot@google.com>
Mon, 6 Aug 2012 23:31:56 +0000 (16:31 -0700)
On Chrome OS systems the magic sysrq x key will cause the following to
happen:
- show processes in blocked state
- emergency file sync
- crash the system

This key combination can be used in the field by users to cause the
system to crash so that crash dumps can be collected to help debug UI
freeze issues.

BUG=chromium-os:33249
TEST=First "echo 0x1000 > /proc/sys/kernel/sysrq", then do the two tests
below:
1. Alt-F10-x should cause the system to crash. Looks for kcrash logs
under /var/spool/crash when the system reboots.
2. All other magic sysrq operation aside from alt-F10-x should be
ineffective.

Change-Id: I62d0a7f0028c072928be0125da4e069bafa5d88c
Signed-off-by: Sameer Nanda <snanda@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/29316
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Olof Johansson <olofj@chromium.org>
drivers/tty/sysrq.c
include/linux/sysrq.h

index 4a63a4d..9a91f29 100644 (file)
@@ -41,6 +41,7 @@
 #include <linux/slab.h>
 #include <linux/input.h>
 #include <linux/uaccess.h>
+#include <linux/delay.h>
 
 #include <asm/ptrace.h>
 #include <asm/irq_regs.h>
@@ -398,6 +399,21 @@ static struct sysrq_key_op sysrq_unrt_op = {
        .enable_mask    = SYSRQ_ENABLE_RTNICE,
 };
 
+static void sysrq_handle_cros_xkey(int key)
+{
+       sysrq_handle_showstate_blocked(key);
+       sysrq_handle_sync(key);
+       mdelay(1000); /* Delay for a bit to give time for sync to complete */
+       sysrq_handle_crash(key);
+}
+
+static struct sysrq_key_op sysrq_cros_xkey = {
+       .handler        = sysrq_handle_cros_xkey,
+       .help_msg       = "Cros-dump-and-crash",
+       .action_msg     = "Cros dump and crash",
+       .enable_mask    = SYSRQ_ENABLE_CROS_XKEY,
+};
+
 /* Key Operations table and lock */
 static DEFINE_SPINLOCK(sysrq_key_table_lock);
 
@@ -451,8 +467,11 @@ static struct sysrq_key_op *sysrq_key_table[36] = {
        /* v: May be registered for frame buffer console restore */
        NULL,                           /* v */
        &sysrq_showstate_blocked_op,    /* w */
-       /* x: May be registered on ppc/powerpc for xmon */
-       NULL,                           /* x */
+       /*
+        * x: May be registered on ppc/powerpc for xmon. On Chrome OS, this
+        * is the dump and crash key.
+        */
+       &sysrq_cros_xkey,               /* x */
        /* y: May be registered on sparc64 for global register dump */
        NULL,                           /* y */
        &sysrq_ftrace_dump_op,          /* z */
index 386032a..1326fb8 100644 (file)
@@ -30,6 +30,7 @@
 #define SYSRQ_ENABLE_SIGNAL    0x0040
 #define SYSRQ_ENABLE_BOOT      0x0080
 #define SYSRQ_ENABLE_RTNICE    0x0100
+#define SYSRQ_ENABLE_CROS_XKEY 0x1000
 
 struct sysrq_key_op {
        void (*handler)(int);