Skip to content

Commit aaf5dcf

Browse files
Andi Kleentorvalds
authored andcommitted
kernel debug: support resetting WARN_ONCE for all architectures
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>
1 parent b1fca27 commit aaf5dcf

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎include/linux/bug.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs);
4343
/* These are defined by the architecture */
4444
int is_valid_bugaddr(unsigned long addr);
4545

46+
void generic_bug_clear_once(void);
47+
4648
#else /* !CONFIG_GENERIC_BUG */
4749

4850
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,
5153
return BUG_TRAP_TYPE_BUG;
5254
}
5355

56+
57+
static inline void generic_bug_clear_once(void) {}
58+
5459
#endif /* CONFIG_GENERIC_BUG */
5560

5661
/*

‎kernel/panic.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ EXPORT_SYMBOL(warn_slowpath_null);
595595

596596
static int clear_warn_once_set(void *data, u64 val)
597597
{
598+
generic_bug_clear_once();
598599
memset(__start_once, 0, __end_once - __start_once);
599600
return 0;
600601
}
@@ -607,7 +608,7 @@ DEFINE_SIMPLE_ATTRIBUTE(clear_warn_once_fops,
607608
static __init int register_warn_debugfs(void)
608609
{
609610
/* Don't care about failure */
610-
debugfs_create_file("clear_warn_once", 0644, NULL,
611+
debugfs_create_file("clear_warn_once", 0200, NULL,
611612
NULL, &clear_warn_once_fops);
612613
return 0;
613614
}

‎lib/bug.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,26 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
196196

197197
return BUG_TRAP_TYPE_BUG;
198198
}
199+
200+
static void clear_once_table(struct bug_entry *start, struct bug_entry *end)
201+
{
202+
struct bug_entry *bug;
203+
204+
for (bug = start; bug < end; bug++)
205+
bug->flags &= ~BUGFLAG_DONE;
206+
}
207+
208+
void generic_bug_clear_once(void)
209+
{
210+
#ifdef CONFIG_MODULES
211+
struct module *mod;
212+
213+
rcu_read_lock_sched();
214+
list_for_each_entry_rcu(mod, &module_bug_list, bug_list)
215+
clear_once_table(mod->bug_table,
216+
mod->bug_table + mod->num_bugs);
217+
rcu_read_unlock_sched();
218+
#endif
219+
220+
clear_once_table(__start___bug_table, __stop___bug_table);
221+
}

0 commit comments

Comments
 (0)