[PATCH 1/1] Fix 'sleeping function called from invalid context' warning in sysrq generated crash.
From: Ani Sinha
Date: Fri Dec 11 2015 - 15:07:42 EST
Commit 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq")
replaced spin_lock_irqsave() calls with
rcu_read_lock() calls in sysrq. Since rcu_read_lock() does not
disable preemption, faulthandler_disabled() in
__do_page_fault() in x86/fault.c returns false. When the code
later calls might_sleep() in the pagefault handler, we get the
following warning:
BUG: sleeping function called from invalid context at ../arch/x86/mm/fault.c:1187
in_atomic(): 0, irqs_disabled(): 0, pid: 4706, name: bash
Preemption disabled at:[<ffffffff81484339>] printk+0x48/0x4a
To fix this, replace RCU call in handle_sysrq() to use SRCU.
Tested this patch on linux 3.18 by booting off one of our boards.
Fixes: 984d74a72076a1 ("sysrq: rcu-ify __handle_sysrq")
Signed-off-by: Ani Sinha <ani@xxxxxxxxxx>
---
drivers/tty/sysrq.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 5381a72..904865f 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -519,10 +519,12 @@ void __handle_sysrq(int key, bool check_mask)
{
struct sysrq_key_op *op_p;
int orig_log_level;
- int i;
+ int i, idx;
+ struct srcu_struct sysrq_rcu;
+ init_srcu_struct(&sysrq_rcu);
rcu_sysrq_start();
- rcu_read_lock();
+ idx = srcu_read_lock(&sysrq_rcu);
/*
* Raise the apparent loglevel to maximum so that the sysrq header
* is shown to provide the user with positive feedback. We do not
@@ -564,7 +566,7 @@ void __handle_sysrq(int key, bool check_mask)
pr_cont("\n");
console_loglevel = orig_log_level;
}
- rcu_read_unlock();
+ srcu_read_unlock(&sysrq_rcu, idx);
rcu_sysrq_end();
}
--
1.8.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/