kernel debug: support resetting WARN_ONCE for all architectures
authorAndi Kleen <ak@linux.intel.com>
Fri, 17 Nov 2017 23:27:06 +0000 (15:27 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 18 Nov 2017 00:10:01 +0000 (16:10 -0800)
Some architectures store the WARN_ONCE state in the flags field of the
bug_entry.  Clear that one too when resetting once state through
/sys/kernel/debug/clear_warn_once

Pointed out by Michael Ellerman

Improves the earlier patch that add clear_warn_once.

[ak@linux.intel.com: add a missing ifdef CONFIG_MODULES]
Link: http://lkml.kernel.org/r/20171020170633.9593-1-andi@firstfloor.org
[akpm@linux-foundation.org: fix unused var warning]
[akpm@linux-foundation.org: Use 0200 for clear_warn_once file, per mpe]
[akpm@linux-foundation.org: clear BUGFLAG_DONE in clear_once_table(), per mpe]
Link: http://lkml.kernel.org/r/20171019204642.7404-1-andi@firstfloor.org
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Tested-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/bug.h
kernel/panic.c
lib/bug.c

index da4231c905c85a644c4d2223b5167bfe811ad36f..fe5916550da8c5c4da102dd91385eef8123167f6 100644 (file)
@@ -43,6 +43,8 @@ enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs);
 /* These are defined by the architecture */
 int is_valid_bugaddr(unsigned long addr);
 
+void generic_bug_clear_once(void);
+
 #else  /* !CONFIG_GENERIC_BUG */
 
 static inline enum bug_trap_type report_bug(unsigned long bug_addr,
@@ -51,6 +53,9 @@ static inline enum bug_trap_type report_bug(unsigned long bug_addr,
        return BUG_TRAP_TYPE_BUG;
 }
 
+
+static inline void generic_bug_clear_once(void) {}
+
 #endif /* CONFIG_GENERIC_BUG */
 
 /*
index 672a91dc20fe83f6fe60dd7d1a9f7557796bc2fb..67cebf2a3b67829cbb119a1262fa1e52d1aaa318 100644 (file)
@@ -595,6 +595,7 @@ EXPORT_SYMBOL(warn_slowpath_null);
 
 static int clear_warn_once_set(void *data, u64 val)
 {
+       generic_bug_clear_once();
        memset(__start_once, 0, __end_once - __start_once);
        return 0;
 }
@@ -607,7 +608,7 @@ DEFINE_SIMPLE_ATTRIBUTE(clear_warn_once_fops,
 static __init int register_warn_debugfs(void)
 {
        /* Don't care about failure */
-       debugfs_create_file("clear_warn_once", 0644, NULL,
+       debugfs_create_file("clear_warn_once", 0200, NULL,
                            NULL, &clear_warn_once_fops);
        return 0;
 }
index 1e094408c893db33f42542960406e93eb19a1d87..f66be6bf6206296ad6b08a375b4a80ab5ff51837 100644 (file)
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -196,3 +196,26 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
 
        return BUG_TRAP_TYPE_BUG;
 }
+
+static void clear_once_table(struct bug_entry *start, struct bug_entry *end)
+{
+       struct bug_entry *bug;
+
+       for (bug = start; bug < end; bug++)
+               bug->flags &= ~BUGFLAG_DONE;
+}
+
+void generic_bug_clear_once(void)
+{
+#ifdef CONFIG_MODULES
+       struct module *mod;
+
+       rcu_read_lock_sched();
+       list_for_each_entry_rcu(mod, &module_bug_list, bug_list)
+               clear_once_table(mod->bug_table,
+                                mod->bug_table + mod->num_bugs);
+       rcu_read_unlock_sched();
+#endif
+
+       clear_once_table(__start___bug_table, __stop___bug_table);
+}