@@ -505,14 +505,12 @@ static void __sysrq_put_key_op(int key, struct sysrq_key_op *op_p)
sysrq_key_table[i] = op_p;
}
-void __handle_sysrq(int key, bool check_mask)
+void __handle_sysrq_nolock(int key, bool check_mask)
{
struct sysrq_key_op *op_p;
int orig_log_level;
int i;
- unsigned long flags;
- spin_lock_irqsave(&sysrq_key_table_lock, flags);
/*
* Raise the apparent loglevel to maximum so that the sysrq header
* is shown to provide the user with positive feedback. We do not
@@ -554,6 +552,13 @@ void __handle_sysrq(int key, bool check_mask)
printk("\n");
console_loglevel = orig_log_level;
}
+}
+
+void __handle_sysrq(int key, bool check_mask)
+{
+ unsigned long flags;
+ spin_lock_irqsave(&sysrq_key_table_lock, flags);
+ __handle_sysrq_nolock(key, check_mask);
spin_unlock_irqrestore(&sysrq_key_table_lock, flags);
}
@@ -44,6 +44,7 @@ struct sysrq_key_op {
void handle_sysrq(int key);
void __handle_sysrq(int key, bool check_mask);
+void __handle_sysrq_nolock(int key, bool 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);
@@ -1924,7 +1924,7 @@ static int kdb_sr(int argc, const char **argv)
if (argc != 1)
return KDB_ARGCOUNT;
kdb_trap_printk++;
- __handle_sysrq(*argv[1], false);
+ __handle_sysrq_nolock(*argv[1], false);
kdb_trap_printk--;
return 0;
If kdb is triggered using SysRq-g then any use of the sr command results in the SysRq key table lock being recursively acquired, killing the debug session. That patch resolves the problem by introducing a _nolock alternative for __handle_sysrq. Strictly speaking this approach risks racing on the key table when kdb is triggered by something other than SysRq-g however in that case any other CPU involved should release the spin lock before kgdb parks the slave CPUs. Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org> --- drivers/tty/sysrq.c | 11 ++++++++--- include/linux/sysrq.h | 1 + kernel/debug/kdb/kdb_main.c | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-)