Merge branch 'master' into for-next
[platform/kernel/linux-starfive.git] / kernel / printk / printk_safe.c
index 08a8bf7..e95d2a5 100644 (file)
@@ -6,10 +6,12 @@
 #include <linux/preempt.h>
 #include <linux/spinlock.h>
 #include <linux/debug_locks.h>
+#include <linux/kdb.h>
 #include <linux/smp.h>
 #include <linux/cpumask.h>
 #include <linux/irq_work.h>
 #include <linux/printk.h>
+#include <linux/kprobes.h>
 
 #include "internal.h"
 
@@ -27,7 +29,6 @@
  * There are situations when we want to make sure that all buffers
  * were handled or when IRQs are blocked.
  */
-static int printk_safe_irq_ready __read_mostly;
 
 #define SAFE_LOG_BUF_LEN ((1 << CONFIG_PRINTK_SAFE_LOG_BUF_SHIFT) -    \
                                sizeof(atomic_t) -                      \
@@ -51,7 +52,7 @@ static DEFINE_PER_CPU(struct printk_safe_seq_buf, nmi_print_seq);
 /* Get flushed in a more safe context. */
 static void queue_flush_work(struct printk_safe_seq_buf *s)
 {
-       if (printk_safe_irq_ready)
+       if (printk_percpu_data_ready())
                irq_work_queue(&s->work);
 }
 
@@ -294,14 +295,14 @@ static __printf(1, 0) int vprintk_nmi(const char *fmt, va_list args)
        return printk_safe_log_store(s, fmt, args);
 }
 
-void notrace printk_nmi_enter(void)
+void noinstr printk_nmi_enter(void)
 {
-       this_cpu_or(printk_context, PRINTK_NMI_CONTEXT_MASK);
+       this_cpu_add(printk_context, PRINTK_NMI_CONTEXT_OFFSET);
 }
 
-void notrace printk_nmi_exit(void)
+void noinstr printk_nmi_exit(void)
 {
-       this_cpu_and(printk_context, ~PRINTK_NMI_CONTEXT_MASK);
+       this_cpu_sub(printk_context, PRINTK_NMI_CONTEXT_OFFSET);
 }
 
 /*
@@ -360,6 +361,12 @@ void __printk_safe_exit(void)
 
 __printf(1, 0) int vprintk_func(const char *fmt, va_list args)
 {
+#ifdef CONFIG_KGDB_KDB
+       /* Allow to pass printk() to kdb but avoid a recursion. */
+       if (unlikely(kdb_trap_printk && kdb_printf_cpu < 0))
+               return vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args);
+#endif
+
        /*
         * Try to use the main logbuf even in NMI. But avoid calling console
         * drivers that might have their own locks.
@@ -402,14 +409,6 @@ void __init printk_safe_init(void)
 #endif
        }
 
-       /*
-        * In the highly unlikely event that a NMI were to trigger at
-        * this moment. Make sure IRQ work is set up before this
-        * variable is set.
-        */
-       barrier();
-       printk_safe_irq_ready = 1;
-
        /* Flush pending messages that did not have scheduled IRQ works. */
        printk_safe_flush();
 }