[PATCH] printk: save loglevel before console_verbose()
From: Stephen Brennan
Date: Thu Feb 15 2024 - 19:54:22 EST
In panic() cases, console_verbose() is called, clobbering the
console_loglevel value. If the bug which led to the panic related to
printk, it can be useful to know the log level prior to the
console_verbose() call. Save it to allow debugging these cases.
Signed-off-by: Stephen Brennan <stephen.s.brennan@xxxxxxxxxx>
---
kernel/printk/printk.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index f2444b581e16..97bd9427f118 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2521,11 +2521,19 @@ MODULE_PARM_DESC(console_suspend, "suspend console during suspend"
" and hibernate operations");
static bool printk_console_no_auto_verbose;
+int saved_console_loglevel;
void console_verbose(void)
{
- if (console_loglevel && !printk_console_no_auto_verbose)
+ if (console_loglevel && !printk_console_no_auto_verbose) {
+ /*
+ * Save the prior log level for later debugging. Avoid
+ * clobbering in case of multiple console_verbose() calls.
+ */
+ if (console_loglevel != CONSOLE_LOGLEVEL_MOTORMOUTH)
+ saved_console_loglevel = console_loglevel;
console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
+ }
}
EXPORT_SYMBOL_GPL(console_verbose);
--
2.39.3