@@ -51,6 +51,7 @@
#include <linux/syscalls.h>
#include <linux/of.h>
#include <linux/rcupdate.h>
+#include <linux/irq_work.h>
#include <asm/ptrace.h>
#include <asm/irq_regs.h>
@@ -112,6 +113,7 @@ static const struct sysrq_key_op sysrq_loglevel_op = {
.help_msg = "loglevel(0-9)",
.action_msg = "Changing Loglevel",
.enable_mask = SYSRQ_ENABLE_LOG,
+ .nmi_safe = true,
};
#ifdef CONFIG_VT
@@ -159,6 +161,7 @@ static const struct sysrq_key_op sysrq_crash_op = {
.help_msg = "crash(c)",
.action_msg = "Trigger a crash",
.enable_mask = SYSRQ_ENABLE_DUMP,
+ .nmi_safe = true,
};
static void sysrq_handle_reboot(int key)
@@ -172,6 +175,7 @@ static const struct sysrq_key_op sysrq_reboot_op = {
.help_msg = "reboot(b)",
.action_msg = "Resetting",
.enable_mask = SYSRQ_ENABLE_BOOT,
+ .nmi_safe = true,
};
const struct sysrq_key_op *__sysrq_reboot_op = &sysrq_reboot_op;
@@ -219,6 +223,7 @@ static const struct sysrq_key_op sysrq_showlocks_op = {
.handler = sysrq_handle_showlocks,
.help_msg = "show-all-locks(d)",
.action_msg = "Show Locks Held",
+ .nmi_safe = true,
};
#else
#define sysrq_showlocks_op (*(const struct sysrq_key_op *)NULL)
@@ -291,6 +296,7 @@ static const struct sysrq_key_op sysrq_showregs_op = {
.help_msg = "show-registers(p)",
.action_msg = "Show Regs",
.enable_mask = SYSRQ_ENABLE_DUMP,
+ .nmi_safe = true,
};
static void sysrq_handle_showstate(int key)
@@ -328,6 +334,7 @@ static const struct sysrq_key_op sysrq_ftrace_dump_op = {
.help_msg = "dump-ftrace-buffer(z)",
.action_msg = "Dump ftrace buffer",
.enable_mask = SYSRQ_ENABLE_DUMP,
+ .nmi_safe = true,
};
#else
#define sysrq_ftrace_dump_op (*(const struct sysrq_key_op *)NULL)
@@ -566,6 +573,32 @@ static void __sysrq_put_key_op(int key, const struct sysrq_key_op *op_p)
sysrq_key_table[i] = op_p;
}
+static int sysrq_nmi_key = -1;
+
+static void sysrq_do_irq_work(struct irq_work *work)
+{
+ const struct sysrq_key_op *op_p;
+ int orig_suppress_printk;
+
+ orig_suppress_printk = suppress_printk;
+ suppress_printk = 0;
+
+ rcu_sysrq_start();
+ rcu_read_lock();
+
+ op_p = __sysrq_get_key_op(sysrq_nmi_key);
+ if (op_p)
+ op_p->handler(sysrq_nmi_key);
+
+ rcu_read_unlock();
+ rcu_sysrq_end();
+
+ suppress_printk = orig_suppress_printk;
+ sysrq_nmi_key = -1;
+}
+
+static DEFINE_IRQ_WORK(sysrq_irq_work, sysrq_do_irq_work);
+
void __handle_sysrq(int key, bool check_mask)
{
const struct sysrq_key_op *op_p;
@@ -573,6 +606,10 @@ void __handle_sysrq(int key, bool check_mask)
int orig_suppress_printk;
int i;
+ /* Skip sysrq handling if one already in progress */
+ if (sysrq_nmi_key != -1)
+ return;
+
orig_suppress_printk = suppress_printk;
suppress_printk = 0;
@@ -596,7 +633,13 @@ void __handle_sysrq(int key, bool check_mask)
if (!check_mask || sysrq_on_mask(op_p->enable_mask)) {
pr_info("%s\n", op_p->action_msg);
console_loglevel = orig_log_level;
- op_p->handler(key);
+
+ if (in_nmi() && !op_p->nmi_safe) {
+ sysrq_nmi_key = key;
+ irq_work_queue(&sysrq_irq_work);
+ } else {
+ op_p->handler(key);
+ }
} else {
pr_info("This sysrq operation is disabled.\n");
console_loglevel = orig_log_level;
@@ -34,6 +34,7 @@ struct sysrq_key_op {
const char * const help_msg;
const char * const action_msg;
const int enable_mask;
+ const bool nmi_safe;
};
#ifdef CONFIG_MAGIC_SYSRQ
@@ -978,6 +978,7 @@ static const struct sysrq_key_op sysrq_dbg_op = {
.handler = sysrq_handle_dbg,
.help_msg = "debug(g)",
.action_msg = "DEBUG",
+ .nmi_safe = true,
};
#endif