Re: [PATCH 1/2] bug: Provide WARN_ON.*DEFERRED() macros for console deferred output
From: Petr Mladek <pmladek@suse.com>
Date: 2026-06-23 15:49:18
Also in:
linux-arch, lkml, sched-ext
On Tue 2026-06-23 08:12:58, Andrew Morton wrote:
On Tue, 23 Jun 2026 16:26:49 +0200 Sebastian Andrzej Siewior [off-list ref] wrote:quoted
Provide a deferred version of the WARN_ON() macro. It will delay flushing the console until a later context. It is needed in a context where the caller holds locks which can lead to a deadlock content is flushed to the console driver. An example would from a warning from within the scheduler resulting in a wake-up of a task. Deferring the output works by using printk_deferred_enter/ exit() around the printing output. This must be used in a context where the task can't migrate to another CPU. This should be the case usually, since the scheduler would acquire the rq lock whith disabled interrupts, but to be safe preemption is disabled to guarantee this. In order not to bloat the code on architectures which provide an optimized __WARN_FLAGS() define BUGFLAG_DEFERRED which is handled by __report_bug() and does not increase the code size. Provide the DEFERRED macros based on __WARN_FLAGS and __WARN_FLAGS macros. Extend __report_bug() to handle the deferred case. ...--- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h@@ -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(); + }For some reason the comment over printk_deferred_enter() says "Interrupts must be disabled for the deferred duration". Is that the case for all the printk_deferred_enter() calls which this patch adds?
Strictly speaking, "only" CPU migration must be disabled around printk_deferred_enter()/exit() call because the state is stored in a per-CPU variable. It means that preempt_disable() would work. I do not recall whether we mentioned interrupts by mistake or on purpose. It is possible that we suggested to disable interrupts because we did not want to deffer messages from unrelated (interrupt) context. Best Regards, Petr