In the event debugfs is not mounted, or if built with the .config
setting DEBUG_FS_ALLOW_NONE chosen, this gives the sysadmin access
to reset the WARN_ONCE() state on a periodic basis.

Cc: Andi Kleen <a...@linux.intel.com>
Cc: Petr Mladek <pmla...@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhat...@gmail.com>
Cc: Steven Rostedt <rost...@goodmis.org>
Cc: John Ogness <john.ogn...@linutronix.de>
Signed-off-by: Paul Gortmaker <paul.gortma...@windriver.com>
---
 .../admin-guide/kernel-parameters.txt         |  8 +++++++
 kernel/panic.c                                | 21 +++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 44fde25bb221..89f54444fee7 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -5863,6 +5863,14 @@
        vt.underline=   [VT] Default color for underlined text; 0-15.
                        Default: 3 = cyan.
 
+       warn_once_reset=
+                       [KNL]
+                       Set the WARN_ONCE reset period in seconds.  Normally
+                       a WARN_ONCE() will only ever emit a message once per
+                       boot, but for example, setting this to 3600 would
+                       effectively rate-limit WARN_ONCE to once per hour.
+                       Default: 0 = never.
+
        watchdog timers [HW,WDT] For information on watchdog timers,
                        see Documentation/watchdog/watchdog-parameters.rst
                        or other driver-specific files in the
diff --git a/kernel/panic.c b/kernel/panic.c
index a23eb239fb17..f813ca3a5cd5 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -716,10 +716,31 @@ static __init int register_warn_debugfs(void)
        /* Don't care about failure */
        debugfs_create_file_unsafe("clear_warn_once", 0600, NULL,
                                   &warn_once_reset, &clear_warn_once_fops);
+
+       /* if a bootarg was used, set the initial timer */
+       if (warn_once_reset)
+               warn_once_set(NULL, warn_once_reset);
+
        return 0;
 }
 
 device_initcall(register_warn_debugfs);
+
+static int __init warn_once_setup(char *s)
+{
+       int r;
+
+       if (!s)
+               return -EINVAL;
+
+       r = kstrtoull(s, 0, &warn_once_reset);
+       if (r)
+               return r;
+
+       return 1;
+}
+__setup("warn_once_reset=", warn_once_setup);
+
 #endif
 
 #ifdef CONFIG_STACKPROTECTOR
-- 
2.25.1

Reply via email to