[RFC PATCH 1/3] printk: convert ignore_loglevel to atomic_t
From: Eugeniu Rosca
Date: Sun Mar 15 2020 - 13:15:04 EST
Prepare for using the 'ignore_loglevel' variable as a lockless and SMP
safe vehicle to turn console verbosity on and off in error paths which
usually (but not necessarily) end up with panic (configurable via
user-selectable knobs).
No functional change intended. Tested on R-Car H3ULCB.
Cc: Petr Mladek <pmladek@xxxxxxxx>
Cc: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Signed-off-by: Eugeniu Rosca <erosca@xxxxxxxxxxxxxx>
---
kernel/printk/printk.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index fada22dc4ab6..d2c75955a0d7 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1181,24 +1181,46 @@ void __init setup_log_buf(int early)
free, (free * 100) / __LOG_BUF_LEN);
}
-static bool __read_mostly ignore_loglevel;
+atomic_t __read_mostly ignore_loglevel = ATOMIC_INIT(0);
static int __init ignore_loglevel_setup(char *str)
{
- ignore_loglevel = true;
+ atomic_set(&ignore_loglevel, 1);
pr_info("debug: ignoring loglevel setting.\n");
return 0;
}
+static int kparam_set_atomic(const char *val, const struct kernel_param *kp)
+{
+ if (param_set_bool(val, kp))
+ return -EINVAL;
+
+ atomic_set(&ignore_loglevel, *(bool *)kp->arg ? 1 : 0);
+
+ return 0;
+}
+
+static int kparam_get_atomic(char *val, const struct kernel_param *kp)
+{
+ return sprintf(val, "%c\n", atomic_read(&ignore_loglevel) ? 'Y' : 'N');
+}
+
+static const struct kernel_param_ops kparam_ops = {
+ .set = kparam_set_atomic,
+ .get = kparam_get_atomic,
+};
+
+static int kparam_buf;
+
early_param("ignore_loglevel", ignore_loglevel_setup);
-module_param(ignore_loglevel, bool, S_IRUGO | S_IWUSR);
+module_param_cb(ignore_loglevel, &kparam_ops, &kparam_buf, 0644);
MODULE_PARM_DESC(ignore_loglevel,
"ignore loglevel setting (prints all kernel messages to the console)");
static bool suppress_message_printing(int level)
{
- return (level >= console_loglevel && !ignore_loglevel);
+ return (level >= console_loglevel && !atomic_read(&ignore_loglevel));
}
#ifdef CONFIG_BOOT_PRINTK_DELAY
--
2.25.0