[PATCH v8 12/21] printk: Ensure sysrq output bypasses per-console filtering

Chris Down posted 21 patches 4 days, 1 hour ago
Only 20 patches received!
[PATCH v8 12/21] printk: Ensure sysrq output bypasses per-console filtering
Posted by Chris Down 4 days, 1 hour ago
During sysrq handling, per-console loglevels are temporarily disabled
to ensure all requisite messages are printed to the console. This is
necessary because sysrq is often used in dire circumstances where
access to /sys/class/console may not be trivially possible, and all
diagnostic output needs to reach the operator regardless of per-console
filtering.

The implementation saves and restores the ignore_per_console_loglevel
flag around the sysrq handler, similar to how suppress_printk is
already handled.

Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Chris Down <chris@chrisdown.name>
---
 drivers/tty/sysrq.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 97f8a9a52285..1d5ae9997e79 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -51,6 +51,7 @@
 #include <linux/syscalls.h>
 #include <linux/of.h>
 #include <linux/rcupdate.h>
+#include <linux/printk.h>
 
 #include <asm/ptrace.h>
 #include <asm/irq_regs.h>
@@ -583,12 +584,16 @@ static void __sysrq_put_key_op(u8 key, const struct sysrq_key_op *op_p)
 void __handle_sysrq(u8 key, bool check_mask)
 {
 	const struct sysrq_key_op *op_p;
+	bool orig_ignore_per_console_loglevel;
 	int orig_suppress_printk;
 	int i;
 
 	orig_suppress_printk = suppress_printk;
 	suppress_printk = 0;
 
+	orig_ignore_per_console_loglevel = ignore_per_console_loglevel;
+	ignore_per_console_loglevel = true;
+
 	rcu_sysrq_start();
 	rcu_read_lock();
 	/*
@@ -634,6 +639,7 @@ void __handle_sysrq(u8 key, bool check_mask)
 	rcu_read_unlock();
 	rcu_sysrq_end();
 
+	ignore_per_console_loglevel = orig_ignore_per_console_loglevel;
 	suppress_printk = orig_suppress_printk;
 }
 
-- 
2.51.2