Support resetting WARN*_ONCE
PATCH 1/1 Support resetting WARN*_ONCE
From: Andi Kleen <[email protected]>
I like _ONCE warnings because it's guaranteed that they don't flood the log.
During testing I find it useful to reset the state of the once warnings, so that I can rerun tests and see if they trigger again, or can guarantee that a test run always hits the same warnings.
This patch adds a debugfs interface to reset all the _ONCE warnings so that they appear again:
echo 1 > /sys/kernel/debug/clear_warn_once
This is implemented by putting all the warning booleans into a special section, and clearing it.
--- include/asm-generic/bug.h | 6 +++--- include/asm-generic/sections.h | 1 + include/asm-generic/vmlinux.lds.h | 3 +++ kernel/panic.c | 27 +++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-)
include/asm-generic/bug.h +3 -3
@@ -129,7 +129,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint,#ifndef WARN_ON_ONCE #define WARN_ON_ONCE (condition) ({ \ - static bool __section(.data.unlikely) __warned; \ + static bool __section(.data.once) __warned; \ int __ret_warn_once = !!(condition); \ \ if (unlikely(__ret_warn_once && !__warned)) { \
@@ -141,7 +141,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint,#endif #define WARN_ONCE(condition, format...) ({ \ - static bool __section(.data.unlikely) __warned; \ + static bool __section(.data.once) __warned; \ int __ret_warn_once = !!(condition); \ \ if (unlikely(__ret_warn_once && !__warned)) { \
@@ -152,7 +152,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint, }) #define WARN_TAINT_ONCE(condition, taint, format...) ({ \ - static bool __section(.data.unlikely) __warned; \ + static bool __section(.data.once) __warned; \ int __ret_warn_once = !!(condition); \ \ if (unlikely(__ret_warn_once && !__warned)) { \
include/asm-generic/sections.h +1 -0
@@ -43,6 +43,7 @@ extern char __entry_text_start[], __entry_text_end[];extern char __start_rodata[], __end_rodata[];extern char __irqentry_text_start[], __irqentry_text_end[];extern char __softirqentry_text_start[], __softirqentry_text_end[]; +extern char __start_once[], __end_once[];/* Start and end of .ctors section - used for constructor calls. */ extern char __ctors_start[], __ctors_end[];
include/asm-generic/vmlinux.lds.h +3 -0
@@ -223,6 +223,9 @@ MEM_KEEP(init.data) \MEM_KEEP (exit.data) \ *(.data.unlikely) \ + VMLINUX_SYMBOL(__start_once) = .; \ + *(.data.once) \ + VMLINUX_SYMBOL(__end_once) = .; \STRUCT_ALIGN (); \ *(__tracepoints) \/* implement dynamic printk debug */ \
kernel/panic.c +27 -0
@@ -27,6 +27,7 @@#include <linux/console.h> #include <linux/bug.h> #include <linux/ratelimit.h> +#include <linux/debugfs.h> #define PANIC_TIMER_STEP 100#define PANIC_BLINK_SPD 18
@@ -587,6 +588,32 @@ void warn_slowpath_null(const char *file, int line)EXPORT_SYMBOL (warn_slowpath_null);#endif +#ifdef CONFIG_BUG + +/* Support resetting WARN*_ONCE state */ + +static int clear_warn_once_set (void *data,u64 val) +{ +memset (__start_once,0 , __end_once - __start_once); +return 0 ; +} + +DEFINE_SIMPLE_ATTRIBUTE (clear_warn_once_fops, +NULL , + clear_warn_once_set, +"%lld\n" ); + +static __init int register_warn_debugfs (void ) +{ +/* Don't care about failure */ +debugfs_create_file ("clear_warn_once" ,0644 ,NULL , +NULL , &clear_warn_once_fops); +return 0 ; +} + +__initcall (register_warn_debugfs); +#endif +#ifdef CONFIG_CC_STACKPROTECTOR /*
Signature · 1 line
2.13.6
Quoted 9 lines · On Tue, 17 Oct 2017 14:40:17 -0700 Andi Kleen <[email protected]> wrote:
From: Andi Kleen <[email protected]>
I like
_ONCEwarnings because it's guaranteed that they don't flood the log.During testing I find it useful to reset the state of the once warnings, so that I can rerun tests and see if they trigger again, or can guarantee that a test run always hits the same warnings.
Quoted 7 lines
This patch adds a debugfs interface to reset all the
_ONCEwarnings so that they appear again:echo 1 >
/sys/kernel/debug/clear_warn_onceThis is implemented by putting all the warning booleans into a special section, and clearing it.
Seems useful. Can we document the new interface please?
I'm not sure where :( If it was in /proc/sys/kernel then we'd have a Documentation file. But debugfs?
Quoted 11 lines
kernel/panic.c +1
-0@@ -27,6 +27,7 @@#include <linux/console.h> #include <linux/bug.h> #include <linux/ratelimit.h> +#include <linux/debugfs.h> #define PANIC_TIMER_STEP 100#define PANIC_BLINK_SPD 18
kernel/panic.c void warn_slowpath_null(const char *file, int line) · line 597
Quoted 10 lines
kernel/panic.c +7
-0@@ -587,6 +588,32 @@ void warn_slowpath_null(const char *file, int line)EXPORT_SYMBOL (warn_slowpath_null);#endif +#ifdef CONFIG_BUG + +/* Support resetting WARN*_ONCE state */ + +static int clear_warn_once_set (void *data,u64 val) +{ +memset (__start_once,0 , __end_once - __start_once);
Suggest we include asm/sections.h explicitly, rather than by luck.
Quoted 2 lines
kernel/panic.c +2
-0+return 0 ; +}
Quoted 4 lines
Seems useful. Can we document the new interface please?
I'm not sure where :( If it was in
/proc/sys/kernelthen we'd have a Documentation file. But debugfs?
I added a new file Documentation/clearing-warn-once.txt
But longer term would be good to document all the debugfs entries systematically. Won't tackle that for this patchkit though.
-Andi
Quoted 9 lines · Andi Kleen
From: Andi Kleen <[email protected]>
I like
_ONCEwarnings because it's guaranteed that they don't flood the log.During testing I find it useful to reset the state of the once warnings, so that I can rerun tests and see if they trigger again, or can guarantee that a test run always hits the same warnings.
Quoted 7 lines
This patch adds a debugfs interface to reset all the
_ONCEwarnings so that they appear again:echo 1 >
/sys/kernel/debug/clear_warn_onceThis is implemented by putting all the warning booleans into a special section, and clearing it.
That won't work for arches that do the ONCE logic with a flag will it? ie. arm64, parisc, powerpc, s390, sh, x86.
They use the version of WARN_ON_ONCE at line ~64 of bug.h
#define __WARN_ONCE_TAINT(taint) __WARN_FLAGS(BUGFLAG_ONCE|BUGFLAG_TAINT(taint))
#define WARN_ON_ONCE(condition) ({ \
int __ret_warn_on = !!(condition); \
if (unlikely(__ret_warn_on)) \
__WARN_ONCE_TAINT(TAINT_WARN); \
unlikely(__ret_warn_on); \
})cheers
Quoted 31 lines
include/asm-generic/bug.h +3
-3@@ -129,7 +129,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint,#ifndef WARN_ON_ONCE #define WARN_ON_ONCE (condition) ({ \ - static bool __section(.data.unlikely) __warned; \ + static bool __section(.data.once) __warned; \ int __ret_warn_once = !!(condition); \ \ if (unlikely(__ret_warn_once && !__warned)) { \@@ -141,7 +141,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint,#endif #define WARN_ONCE(condition, format...) ({ \ - static bool __section(.data.unlikely) __warned; \ + static bool __section(.data.once) __warned; \ int __ret_warn_once = !!(condition); \ \ if (unlikely(__ret_warn_once && !__warned)) { \@@ -152,7 +152,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint, }) #define WARN_TAINT_ONCE(condition, taint, format...) ({ \ - static bool __section(.data.unlikely) __warned; \ + static bool __section(.data.once) __warned; \ int __ret_warn_once = !!(condition); \ \ if (unlikely(__ret_warn_once && !__warned)) { \
Quoted 14 lines · Michael Ellerman
Quoted 12 lines · Andi Kleen
From: Andi Kleen <[email protected]>
I like
_ONCEwarnings because it's guaranteed that they don't flood the log.During testing I find it useful to reset the state of the once warnings, so that I can rerun tests and see if they trigger again, or can guarantee that a test run always hits the same warnings.
This patch adds a debugfs interface to reset all the
_ONCEwarnings so that they appear again:
Quoted 7 lines
Quoted 4 lines
echo 1 >
/sys/kernel/debug/clear_warn_onceThis is implemented by putting all the warning booleans into a special section, and clearing it.
That won't work for arches that do the ONCE logic with a flag will it? ie. arm64, parisc, powerpc, s390, sh, x86.
Thanks. I sent an incremential patch that fixes this.
-Andi
Quoted 17 lines · Andi Kleen
kernel/panic.c +9
-0@@ -587,6 +588,32 @@ void warn_slowpath_null(const char *file, int line)EXPORT_SYMBOL (warn_slowpath_null);#endif +#ifdef CONFIG_BUG + +/* Support resetting WARN*_ONCE state */ + +static int clear_warn_once_set (void *data,u64 val) +{ +memset (__start_once,0 , __end_once - __start_once); +return 0 ; +}
kernel/panic.c void warn_slowpath_null(const char *file, int line) · line 609
Quoted 10 lines
kernel/panic.c +10
-0+ +DEFINE_SIMPLE_ATTRIBUTE (clear_warn_once_fops, +NULL , + clear_warn_once_set, +"%lld\n" ); + +static __init int register_warn_debugfs (void ) +{ +/* Don't care about failure */ + debugfs_create_file("clear_warn_once", 0644, NULL,
^
Wouldn't 0200 be more appropriate if it's only writable?
Otherwise it appears readable, but cat'ing it gives you an error.
cheers