From: Alexander Holler <holler@ahsoftware.de>
To: Ingo Molnar <mingo@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: Tejun Heo <htejun@gmail.com>,
Louis Langholtz <lou_langholtz@me.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
trivial@kernel.org, Rusty Russell <rusty@rustcorp.com.au>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] debug: Deprecate BUG_ON() use in new code, introduce CRASH_ON()
Date: Mon, 08 Jun 2015 09:40:22 +0200 [thread overview]
Message-ID: <557546E6.5030304@ahsoftware.de> (raw)
In-Reply-To: <20150608071215.GA369@gmail.com>
Am 08.06.2015 um 09:12 schrieb Ingo Molnar:
>
> * Linus Torvalds <torvalds@linux-foundation.org> wrote:
>
>> Stop with the random BUG_ON() additions.
>
> Yeah, so I propose the attached patch which attempts to resist new BUG_ON()
> additions.
As this reminded me at flame I received once from a maintainer because I
wanted to avoid a desastrous memory corruption by using a BUG_ON().
maybe someone should mention that a BUG_ON or now CRASH_ON should be
still prefered instead of some random memory corruption which might lead
to worse things. Or how is the viewpoint of the kernel masters in regard
to memory corruptions and use of BUG_ON, WARN_ON or CRASH_ON?
Regards,
Alexander Holler
>
> Thanks,
>
> Ingo
>
> ================================>
> From 724052923fbae2e3a14e0b9383c89b18217d817f Mon Sep 17 00:00:00 2001
> From: Ingo Molnar <mingo@kernel.org>
> Date: Mon, 8 Jun 2015 09:01:43 +0200
> Subject: [PATCH] debug: Deprecate BUG_ON() use in new code, introduce CRASH_ON()
>
> So people still keep adding random BUG_ON() lines, as a mistaken practice
> to put asserts that will never trigger, into supposedly perfect kernel code.
>
> So such BUG_ON()s should either not be added, because the code is truly
> perfect, or if there's a chance that it's imperfect, use WARN_ON() instead
> and limp along, in the hope of getting some debug information back from
> the user.
>
> Using BUG_ON() will just hang or reboot most systems, with no useful
> feedback provided. It's as user hostile as it gets.
>
> Add a checkpatch rule that warns against new BUG_ON() uses:
>
> WARNING: Using BUG_ON() is generally wrong, use WARN_ON() instead - or CRASH_ON() if the kernel absolutely must crash.
>
> CRASH_ON() can be used in code that must absolutely crash right then,
> in the very rare case where there's no way the system can be allowed
> to continue execution.
>
> It should be used sparingly, and its name will hopefully achieve this.
>
> Signed-off-by: Ingo Molnar <mingo@kernel.org>
> ---
> include/asm-generic/bug.h | 7 +++++++
> scripts/checkpatch.pl | 6 ++++++
> 2 files changed, 13 insertions(+)
>
> diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
> index 630dd2372238..c6424723277b 100644
> --- a/include/asm-generic/bug.h
> +++ b/include/asm-generic/bug.h
> @@ -165,6 +165,13 @@ extern void warn_slowpath_null(const char *file, const int line);
> #define WARN_TAINT(condition, taint, format...) WARN(condition, format)
> #define WARN_TAINT_ONCE(condition, taint, format...) WARN(condition, format)
>
> +/*
> + * BUG_ON() is deprecated, use either one of the WARN_ON() variants,
> + * or if it's absolutely unavoidable to crash the system due to
> + * some grave condition, use CRASH_ON():
> + */
> +#define CRASH_ON(condition) BUG_ON(condition)
> +
> #endif
>
> /*
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 89b1df4e72ab..6e0887057398 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -5414,6 +5414,12 @@ sub process {
> "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
> }
>
> +# check for use of BUG_ON()
> + if ($line =~ /\bBUG_ON\s*\(/) {
> + WARN("BUG_ON",
> + "Using BUG_ON() is generally wrong, use WARN_ON() instead - or CRASH_ON() if the kernel absolutely must crash.\n" . $herecurr);
> + }
> +
> # whine mightly about in_atomic
> if ($line =~ /\bin_atomic\s*\(/) {
> if ($realfile =~ m@^drivers/@) {
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
next prev parent reply other threads:[~2015-06-08 7:40 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <http://marc.info/?l=linux-kernel&m=143351431301630>
2015-06-07 23:54 ` [PATCH] kernel/params.c: make use of unused but set variable Louis Langholtz
2015-06-08 0:00 ` Tejun Heo
2015-06-08 0:17 ` Linus Torvalds
2015-06-08 0:58 ` Tejun Heo
2015-06-08 5:24 ` [PATCH v2] " Louis Langholtz
2015-06-10 17:05 ` [PATCH] " Louis Langholtz
2015-06-11 1:54 ` Tejun Heo
2015-06-12 3:17 ` Louis Langholtz
2015-06-08 5:44 ` [PATCH] checkpatch: Warn on BUG and BUG_ON uses Joe Perches
2015-06-08 5:46 ` [PATCH] kernel/params.c: make use of unused but set variable Louis Langholtz
2015-06-08 7:12 ` [PATCH] debug: Deprecate BUG_ON() use in new code, introduce CRASH_ON() Ingo Molnar
2015-06-08 7:40 ` Alexander Holler [this message]
2015-06-08 8:08 ` Richard Weinberger
2015-06-08 8:42 ` Alexander Holler
2015-06-08 9:05 ` Ingo Molnar
2015-06-08 9:11 ` Ingo Molnar
2015-06-08 9:22 ` Alexander Holler
2015-06-08 11:29 ` Ingo Molnar
2015-06-08 9:16 ` Alexander Holler
2015-06-08 11:27 ` Ingo Molnar
2015-06-08 18:07 ` Alexander Holler
2015-06-08 19:35 ` Ingo Molnar
2015-06-09 1:07 ` Alexander Holler
2015-06-08 8:09 ` Ingo Molnar
2015-06-12 1:27 ` [PATCH] kernel/params.c: make use of unused but set variable Rusty Russell
2015-06-12 1:48 ` Tejun Heo
2015-06-14 19:49 ` Rusty Russell
2015-06-16 19:54 ` Tejun Heo
2015-06-08 14:26 [PATCH] debug: Deprecate BUG_ON() use in new code, introduce CRASH_ON() Alexey Dobriyan
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=557546E6.5030304@ahsoftware.de \
--to=holler@ahsoftware.de \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=htejun@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lou_langholtz@me.com \
--cc=mingo@kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=trivial@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