lkml.org 
[lkml]   [2020]   [Mar]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 1/3] printk: convert ignore_loglevel to atomic_t
Date
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@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---
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
\
 
 \ /
  Last update: 2020-03-15 18:10    [W:0.159 / U:9.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site