From: Josh Law <objecting@objecting.org>
To: Andrew Morton <akpm@linux-foundation.org>,
Josh Law <objecting@objecting.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] lib/bug: add debugfs interface to list all BUG/WARN sites
Date: Sun, 15 Mar 2026 19:49:39 +0000 [thread overview]
Message-ID: <20260315194939.328612-4-objecting@objecting.org> (raw)
In-Reply-To: <20260315194939.328612-1-objecting@objecting.org>
Currently there is no way to inspect the runtime state of WARN_ONCE
sites. The existing clear_warn_once debugfs file lets operators reset
them, but there is no counterpart to see which sites exist or which
have already fired. On production systems this matters: when a
WARN_ONCE fires during a transient event, the only evidence is a
single dmesg line that may have already rotated out. Operators
investigating later have no way to tell which WARN_ONCE sites have
tripped without rebooting or reproducing the issue.
Add /sys/kernel/debug/bug_sites which lists every registered BUG()
and WARN() site in the kernel, including those from loaded modules.
Each line shows the symbolized address, source location (file:line
when CONFIG_DEBUG_BUGVERBOSE is enabled), type and state flags, and
the module name if applicable. Example output:
func+0x10/0x20 kernel/foo.c:123 warn,once,done
bar+0x5/0x10 drivers/baz.c:456 warn [baz_mod]
The "done" flag indicates that a WARN_ONCE site has fired at least
once since boot (or since the last clear_warn_once), giving operators
a reliable way to audit warning state on a running system without
depending on log retention.
Signed-off-by: Josh Law <objecting@objecting.org>
---
lib/bug.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/lib/bug.c b/lib/bug.c
index 9d76703ff7d1..ddf4531d6661 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -48,6 +48,8 @@
#include <linux/rculist.h>
#include <linux/ftrace.h>
#include <linux/context_tracking.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
extern struct bug_entry __start___bug_table[], __stop___bug_table[];
@@ -311,3 +313,68 @@ void generic_bug_clear_once(void)
clear_once_table(__start___bug_table, __stop___bug_table);
}
+
+#ifdef CONFIG_DEBUG_FS
+static void bug_show_entry(struct seq_file *m, const struct bug_entry *bug,
+ const char *modname)
+{
+ const char *file;
+ unsigned int line;
+ unsigned short flags = READ_ONCE(bug->flags);
+
+ bug_get_file_line(bug, &file, &line);
+
+ seq_printf(m, "%pS\t", (void *)bug_addr(bug));
+
+ if (file)
+ seq_printf(m, "%s:%u\t", file, line);
+ else
+ seq_puts(m, "-\t");
+
+ if (flags & BUGFLAG_WARNING)
+ seq_puts(m, "warn");
+ else
+ seq_puts(m, "bug");
+ if (flags & BUGFLAG_ONCE)
+ seq_puts(m, ",once");
+ if (flags & BUGFLAG_DONE)
+ seq_puts(m, ",done");
+
+ if (modname)
+ seq_printf(m, "\t[%s]", modname);
+
+ seq_putc(m, '\n');
+}
+
+static int bug_sites_show(struct seq_file *m, void *v)
+{
+ struct bug_entry *bug;
+
+ for (bug = __start___bug_table; bug < __stop___bug_table; bug++)
+ bug_show_entry(m, bug, NULL);
+
+#ifdef CONFIG_MODULES
+ {
+ struct module *mod;
+ unsigned int i;
+
+ rcu_read_lock();
+ list_for_each_entry_rcu(mod, &module_bug_list, bug_list)
+ for (i = 0; i < mod->num_bugs; i++)
+ bug_show_entry(m, &mod->bug_table[i],
+ mod->name);
+ rcu_read_unlock();
+ }
+#endif
+
+ return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(bug_sites);
+
+static int __init bug_debugfs_init(void)
+{
+ debugfs_create_file("bug_sites", 0444, NULL, NULL, &bug_sites_fops);
+ return 0;
+}
+device_initcall(bug_debugfs_init);
+#endif /* CONFIG_DEBUG_FS */
--
2.34.1
prev parent reply other threads:[~2026-03-15 19:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-15 19:49 [PATCH 0/3] lib/bug: concurrency fix, cleanups, and debugfs inspection Josh Law
2026-03-15 19:49 ` [PATCH 1/3] lib/bug: annotate concurrent access to bug->flags with READ_ONCE/WRITE_ONCE Josh Law
2026-03-15 19:49 ` [PATCH 2/3] lib/bug: clean up types in bug reporting helpers Josh Law
2026-03-15 19:49 ` Josh Law [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260315194939.328612-4-objecting@objecting.org \
--to=objecting@objecting.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®