console_lock() and, thus, console_unlock() can be executed by
user-space processes doing sys calls (e.g. tty, drm, etc.) so we
may end up in a situation when systemd loops in console_unlock()
printing kernel messages. Always offload printing duty from
user-space process (if we can safely wake up printk_kthread,
of course).

Signed-off-by: Sergey Senozhatsky <sergey.senozhat...@gmail.com>
---
 kernel/printk/printk.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 6da4e21c3b45..0ffbaa33280f 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -592,6 +592,13 @@ static inline bool console_offload_printing(void)
        if (!is_printk_offloading_safe())
                return false;
 
+       /*
+        * Always offload from user-space processes, we've got printk kthread
+        * for printing.
+        */
+       if (!(current->flags & PF_KTHREAD))
+               goto offload;
+
        /* A new task - reset the counters. */
        if (printing_task != current) {
                printing_start_ts = local_clock() >> 30LL;
@@ -634,6 +641,7 @@ static inline bool console_offload_printing(void)
                return true;
        }
 
+offload:
        /*
         * We try to set `printk_kthread' CPU affinity to any online CPU
         * except for this_cpu. Because otherwise `printk_kthread' may be
-- 
2.14.1

Reply via email to