diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2022-06-17 14:57:42 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2022-06-17 14:57:42 -0500 |
commit | 93d17c1c8c1cc987aad378d5266d99e46efca43c (patch) | |
tree | a8cffc099e31bbdc254a492df2a3ff18445299de /kernel/printk/printk_safe.c | |
parent | ef06e68290b2b1b674950da276d6f7724e0b9874 (diff) | |
parent | 38335cc5ffafa111210ad6bbe5a63a87db38ee68 (diff) |
Merge tag 'printk-for-5.19-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux
Pull printk fixes from Petr Mladek:
"Make the global console_sem available for CPU that is handling panic()
or shutdown.
This is an old problem when an existing console lock owner might block
console output, but it became more visible with the kthreads"
* tag 'printk-for-5.19-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux:
printk: Wait for the global console lock when the system is going down
printk: Block console kthreads when direct printing will be required
Diffstat (limited to 'kernel/printk/printk_safe.c')
-rw-r--r-- | kernel/printk/printk_safe.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c index ef0f9a2044da..caac4de1ea59 100644 --- a/kernel/printk/printk_safe.c +++ b/kernel/printk/printk_safe.c @@ -8,7 +8,9 @@ #include <linux/smp.h> #include <linux/cpumask.h> #include <linux/printk.h> +#include <linux/console.h> #include <linux/kprobes.h> +#include <linux/delay.h> #include "internal.h" @@ -50,3 +52,33 @@ asmlinkage int vprintk(const char *fmt, va_list args) return vprintk_default(fmt, args); } EXPORT_SYMBOL(vprintk); + +/** + * try_block_console_kthreads() - Try to block console kthreads and + * make the global console_lock() avaialble + * + * @timeout_ms: The maximum time (in ms) to wait. + * + * Prevent console kthreads from starting processing new messages. Wait + * until the global console_lock() become available. + * + * Context: Can be called in any context. + */ +void try_block_console_kthreads(int timeout_ms) +{ + block_console_kthreads = true; + + /* Do not wait when the console lock could not be safely taken. */ + if (this_cpu_read(printk_context) || in_nmi()) + return; + + while (timeout_ms > 0) { + if (console_trylock()) { + console_unlock(); + return; + } + + udelay(1000); + timeout_ms -= 1; + } +} |