mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kernel: count warnings and make count accessible to userspace
@ 2022-01-18  6:04 John Sperbeck
  2022-01-19 12:01 ` Petr Mladek
  0 siblings, 1 reply; 6+ messages in thread
From: John Sperbeck @ 2022-01-18  6:04 UTC (permalink / raw)
  To: Petr Mladek; +Cc: Steven Rostedt, John Ogness, linux-kernel, John Sperbeck

When testing, it's common to consider a warning to be a test failure,
but it's currently awkward to determine which of multiple sequential
tests is responsible for triggering a warning.  Scraping dmesg or
/var/log/messages is somewhat expensive and error-prone.  Setting
panic_on_warn is reliable, but spoils test runs for minor issues.
Looking at the taint bit is also reliable, but only works for a single
warning.

We can track the warning count and expose it as a sysfs file.  Test
infrastructures can snapshot the value before and after a test.  If
the value changes, they can do more expensive things like extracting
logs.

Signed-off-by: John Sperbeck <jsperbeck@google.com>
---
 kernel/panic.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/panic.c b/kernel/panic.c
index cefd7d82366f..5262c2a0ebf4 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -571,6 +571,8 @@ struct warn_args {
 	va_list args;
 };
 
+static atomic_t  __maybe_unused warn_counter;
+
 void __warn(const char *file, int line, void *caller, unsigned taint,
 	    struct pt_regs *regs, struct warn_args *args)
 {
@@ -612,6 +614,8 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
 
 	/* Just a warning, don't kill lockdep. */
 	add_taint(taint, LOCKDEP_STILL_OK);
+
+	atomic_inc(&warn_counter);
 }
 
 #ifndef __WARN_FLAGS
@@ -667,6 +671,7 @@ static __init int register_warn_debugfs(void)
 	/* Don't care about failure */
 	debugfs_create_file_unsafe("clear_warn_once", 0200, NULL, NULL,
 				   &clear_warn_once_fops);
+	debugfs_create_atomic_t("warn_count", 0444, NULL, &warn_counter);
 	return 0;
 }
 
-- 
2.34.1.703.g22d0c6ccf7-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-02-11 10:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18  6:04 [PATCH] kernel: count warnings and make count accessible to userspace John Sperbeck
2022-01-19 12:01 ` Petr Mladek
2022-01-22 20:58   ` John Sperbeck
2022-01-25  8:52     ` Petr Mladek
2022-01-27  0:23       ` John Sperbeck
2022-02-11 10:34         ` Petr Mladek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome