diff options
| author | John Ogness <john.ogness@linutronix.de> | 2024-12-09 12:23:46 +0106 |
|---|---|---|
| committer | Petr Mladek <pmladek@suse.com> | 2024-12-16 13:26:31 +0100 |
| commit | 0161e2d6950fe66cf6ac1c10d945bae971f33667 (patch) | |
| tree | e12087793cfe89c62446951321929beeb03ae651 /kernel/printk/printk_safe.c | |
| parent | f1c21cf470595c4561d4671fd499af94152175d5 (diff) | |
printk: Defer legacy printing when holding printk_cpu_sync
The documentation of printk_cpu_sync_get() clearly states
that the owner must never perform any activities where it waits
for a CPU. For legacy printing there can be spinning on the
console_lock and on the port lock. Therefore legacy printing
must be deferred when holding the printk_cpu_sync.
Note that in the case of emergency states, atomic consoles
are not prevented from printing when printk is deferred. This
is appropriate because they do not spin-wait indefinitely for
other CPUs.
Reported-by: Rik van Riel <riel@surriel.com>
Closes: https://lore.kernel.org/r/20240715232052.73eb7fb1@imladris.surriel.com
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Fixes: 55d6af1d6688 ("lib/nmi_backtrace: explicitly serialize banner and regs")
Reviewed-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20241209111746.192559-3-john.ogness@linutronix.de
Signed-off-by: Petr Mladek <pmladek@suse.com>
Diffstat (limited to 'kernel/printk/printk_safe.c')
| -rw-r--r-- | kernel/printk/printk_safe.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c index 6283bc0b55e6..32a28f563b13 100644 --- a/kernel/printk/printk_safe.c +++ b/kernel/printk/printk_safe.c @@ -61,10 +61,15 @@ bool is_printk_legacy_deferred(void) /* * The per-CPU variable @printk_context can be read safely in any * context. CPU migration is always disabled when set. + * + * A context holding the printk_cpu_sync must not spin waiting for + * another CPU. For legacy printing, it could be the console_lock + * or the port lock. */ return (force_legacy_kthread() || this_cpu_read(printk_context) || - in_nmi()); + in_nmi() || + is_printk_cpu_sync_owner()); } asmlinkage int vprintk(const char *fmt, va_list args) |