Re: [PATCH 1/2] bug: Provide WARN_ON.*DEFERRED() macros for console deferred output
From: K Prateek Nayak
Date: Tue Jun 23 2026 - 10:58:00 EST
Hello Sebastian,
On 6/23/2026 7:56 PM, Sebastian Andrzej Siewior wrote:
> --- a/lib/bug.c
> +++ b/lib/bug.c
> @@ -196,7 +196,7 @@ void __warn_printf(const char *fmt, struct pt_regs *regs)
>
> static enum bug_trap_type __report_bug(struct bug_entry *bug, unsigned long bugaddr, struct pt_regs *regs)
> {
> - bool warning, once, done, no_cut, has_args;
> + bool warning, once, done, no_cut, has_args, deferred;
> const char *file, *fmt;
> unsigned line;
>
> @@ -219,6 +219,7 @@ static enum bug_trap_type __report_bug(struct bug_entry *bug, unsigned long buga
> done = bug->flags & BUGFLAG_DONE;
> no_cut = bug->flags & BUGFLAG_NO_CUT_HERE;
> has_args = bug->flags & BUGFLAG_ARGS;
> + deferred = bug->flags & BUGFLAG_DEFERRED;
>
> if (warning && once) {
> if (done)
> @@ -229,7 +230,10 @@ static enum bug_trap_type __report_bug(struct bug_entry *bug, unsigned long buga
> */
> bug->flags |= BUGFLAG_DONE;
> }
> -
> + if (deferred) {
> + preempt_disable_notrace();
> + printk_deferred_enter();
> + }
> /*
> * BUG() and WARN_ON() families don't print a custom debug message
> * before triggering the exception handler, so we must add the
> @@ -245,6 +249,10 @@ static enum bug_trap_type __report_bug(struct bug_entry *bug, unsigned long buga
> /* this is a WARN_ON rather than BUG/BUG_ON */
> __warn(file, line, (void *)bugaddr, BUG_GET_TAINT(bug), regs,
> NULL);
> + if (deferred) {
> + printk_deferred_exit();
> + preempt_enable_notrace();
> + }
> return BUG_TRAP_TYPE_WARN;
nit.
Instead of replicating these bits, can we replace that return with a
"goto out" ...
> }
>
> @@ -254,6 +262,10 @@ static enum bug_trap_type __report_bug(struct bug_entry *bug, unsigned long buga
> pr_crit("kernel BUG at %pB [verbose debug info unavailable]\n",
> (void *)bugaddr);
>
out:
> + if (deferred) {
> + printk_deferred_exit();
> + preempt_enable_notrace();
> + }
> return BUG_TRAP_TYPE_BUG;
... and replace this return with a:
return (warning) ? BUG_TRAP_TYPE_WARN : BUG_TRAP_TYPE_BUG;
Looks a tab bit cleaner to my eyes. Thoughts?
> }
>
--
Thanks and Regards,
Prateek