From 937c997ef624dc656a64c97a47ef57b4a189bbc6 Mon Sep 17 00:00:00 2001 From: Sameer Nanda Date: Mon, 6 Aug 2012 09:16:21 -0700 Subject: [PATCH] CHROMIUM: sysrq: Added Chrome OS specific 'x' key 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 Reviewed-on: https://gerrit.chromium.org/gerrit/29316 Reviewed-by: Kees Cook Reviewed-by: Olof Johansson --- drivers/tty/sysrq.c | 23 +++++++++++++++++++++-- include/linux/sysrq.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 4a63a4dfd8e8..9a91f29bd953 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -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 */ diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h index 386032aecb46..1326fb839c8c 100644 --- a/include/linux/sysrq.h +++ b/include/linux/sysrq.h @@ -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); -- 2.20.1