Skip to contentSkip to conversation

Support resetting WARN_ONCE for all architectures

PATCH Applied Andi Kleen 1 participant 1 message Oct 20, 2017 Library code

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 Support resetting WARN_ONCE for all architectures

From: Andi Kleen <[email protected]>

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.

Cc: [email protected]
v2: Add a missing ifdef CONFIG_MODULES. Thanks 0day!

---
 include/linux/bug.h |  5 +++++
 kernel/panic.c      |  1 +
 lib/bug.c           | 23 +++++++++++++++++++++++
 3 files changed, 29 insertions(+)
include/linux/bug.h +5 -0
index 5d5554c874fd..b8666ee88086 100644
@@ -42,6 +42,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,
@@ -50,6 +52,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 */
 
 /*
kernel/panic.c +1 -0
index 49dbdb231a77..840a98fa4963 100644
@@ -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;
 }
lib/bug.c +23 -0
index a6a1137d06db..2adafcb41d5b 100644
@@ -195,3 +195,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_ONCE;
+}
+
+void generic_bug_clear_once(void)
+{
+	struct module *mod;
+
+#ifdef CONFIG_MODULES
+	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);
+}
Signature · 1 line
2.13.6