printk: change recursion_bug type to bool
[cascardo/linux.git] / kernel / printk / printk.c
index 0c9f025..e794391 100644 (file)
@@ -1661,7 +1661,7 @@ asmlinkage int vprintk_emit(int facility, int level,
                            const char *dict, size_t dictlen,
                            const char *fmt, va_list args)
 {
-       static int recursion_bug;
+       static bool recursion_bug;
        static char textbuf[LOG_LINE_MAX];
        char *text = textbuf;
        size_t text_len = 0;
@@ -1697,7 +1697,7 @@ asmlinkage int vprintk_emit(int facility, int level,
                 * it can be printed at the next appropriate moment:
                 */
                if (!oops_in_progress && !lockdep_recursing(current)) {
-                       recursion_bug = 1;
+                       recursion_bug = true;
                        local_irq_restore(flags);
                        return 0;
                }
@@ -1712,7 +1712,7 @@ asmlinkage int vprintk_emit(int facility, int level,
                static const char recursion_msg[] =
                        "BUG: recent printk recursion!";
 
-               recursion_bug = 0;
+               recursion_bug = false;
                /* emit KERN_CRIT message */
                printed_len += log_store(0, 2, LOG_PREFIX|LOG_NEWLINE, 0,
                                         NULL, 0, recursion_msg,
@@ -2234,13 +2234,24 @@ void console_unlock(void)
        static u64 seen_seq;
        unsigned long flags;
        bool wake_klogd = false;
-       bool retry;
+       bool do_cond_resched, retry;
 
        if (console_suspended) {
                up_console_sem();
                return;
        }
 
+       /*
+        * Console drivers are called under logbuf_lock, so
+        * @console_may_schedule should be cleared before; however, we may
+        * end up dumping a lot of lines, for example, if called from
+        * console registration path, and should invoke cond_resched()
+        * between lines if allowable.  Not doing so can cause a very long
+        * scheduling stall on a slow console leading to RCU stall and
+        * softlockup warnings which exacerbate the issue with more
+        * messages practically incapacitating the system.
+        */
+       do_cond_resched = console_may_schedule;
        console_may_schedule = 0;
 
        /* flush buffered message fragment immediately to console */
@@ -2312,6 +2323,9 @@ skip:
                call_console_drivers(level, ext_text, ext_len, text, len);
                start_critical_timings();
                local_irq_restore(flags);
+
+               if (do_cond_resched)
+                       cond_resched();
        }
        console_locked = 0;
 
@@ -2379,6 +2393,25 @@ void console_unblank(void)
        console_unlock();
 }
 
+/**
+ * console_flush_on_panic - flush console content on panic
+ *
+ * Immediately output all pending messages no matter what.
+ */
+void console_flush_on_panic(void)
+{
+       /*
+        * If someone else is holding the console lock, trylock will fail
+        * and may_schedule may be set.  Ignore and proceed to unlock so
+        * that messages are flushed out.  As this can be called from any
+        * context and we don't want to get preempted while flushing,
+        * ensure may_schedule is cleared.
+        */
+       console_trylock();
+       console_may_schedule = 0;
+       console_unlock();
+}
+
 /*
  * Return the console tty driver structure and its associated index
  */