Re: [PATCH] Support resetting WARN*_ONCE

Andrew Morton
2017-10-17T21:55:01Z

On Tue, 17 Oct 2017 14:40:17 -0700 Andi Kleen <andi@firstfloor.org> wrote:

> From: Andi Kleen <ak@linux.intel.com>
>
> I like _ONCE warnings because it's guaranteed that they don't
> flood the log.
>
> During testing I find it useful to reset the state of the once warnings,
> so that I can rerun tests and see if they trigger again, or can
> guarantee that a test run always hits the same warnings.
>
> This patch adds a debugfs interface to reset all the _ONCE
> warnings so that they appear again:
>
> echo 1 > /sys/kernel/debug/clear_warn_once
>
> This is implemented by putting all the warning booleans into
> a special section, and clearing it.

Seems useful. Can we document the new interface please?

I'm not sure where :( If it was in /proc/sys/kernel then we'd have a
Documentation file. But debugfs?

> --- a/kernel/panic.c
> +++ b/kernel/panic.c
> @@ -27,6 +27,7 @@
> #include <linux/console.h>
> #include <linux/bug.h>
> #include <linux/ratelimit.h>
> +#include <linux/debugfs.h>
>
> #define PANIC_TIMER_STEP 100
> #define PANIC_BLINK_SPD 18
> @@ -587,6 +588,32 @@ void warn_slowpath_null(const char *file, int line)
> EXPORT_SYMBOL(warn_slowpath_null);
> #endif
>
> +#ifdef CONFIG_BUG
> +
> +/* Support resetting WARN*_ONCE state */
> +
> +static int clear_warn_once_set(void *data, u64 val)
> +{
> + memset(__start_once, 0, __end_once - __start_once);

Suggest we include asm/sections.h explicitly, rather than by luck.

> + return 0;
> +}