Add add the 'force_early_printk' kernel parameter to override printk()
and force it into early_printk(). This bypasses all the cruft and fail
from printk() and makes things work again.

Signed-off-by: Peter Zijlstra (Intel) <pet...@infradead.org>
---
 kernel/printk/printk.c |   74 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 49 insertions(+), 25 deletions(-)

--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -344,6 +344,42 @@ __packed __aligned(4)
 #endif
 ;
 
+#ifdef CONFIG_EARLY_PRINTK
+struct console *early_console;
+
+static bool __read_mostly force_early_printk;
+
+static int __init force_early_printk_setup(char *str)
+{
+       force_early_printk = true;
+       return 0;
+}
+early_param("force_early_printk", force_early_printk_setup);
+
+static int early_vprintk(const char *fmt, va_list args)
+{
+       char buf[512];
+       int n;
+
+       n = vscnprintf(buf, sizeof(buf), fmt, args);
+       early_console->write(early_console, buf, n);
+
+       return n;
+}
+
+asmlinkage __visible void early_printk(const char *fmt, ...)
+{
+       va_list ap;
+
+       if (!early_console)
+               return;
+
+       va_start(ap, fmt);
+       early_vprintk(fmt, ap);
+       va_end(ap);
+}
+#endif
+
 /*
  * The logbuf_lock protects kmsg buffer, indices, counters.  This can be taken
  * within the scheduler's rq lock. It must be released before calling
@@ -1751,10 +1787,13 @@ asmlinkage int vprintk_emit(int facility
        static unsigned int logbuf_cpu = UINT_MAX;
 
 #ifdef CONFIG_KGDB_KDB
-       if (unlikely(kdb_trap_printk)) {
-               r = vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args);
-               return r;
-       }
+       if (unlikely(kdb_trap_printk))
+               return vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args);
+#endif
+
+#ifdef CONFIG_EARLY_PRINTK
+       if (force_early_printk && early_console)
+               return early_vprintk(fmt, args);
 #endif
 
        if (level == LOGLEVEL_SCHED) {
@@ -1970,7 +2009,12 @@ asmlinkage __visible int printk(const ch
        int r;
 
        va_start(args, fmt);
-       r = vprintk_func(fmt, args);
+#ifdef CONFIG_EARLY_PRINTK
+       if (force_early_printk && early_console)
+               r = vprintk_default(fmt, args);
+       else
+#endif
+               r = vprintk_func(fmt, args);
        va_end(args);
 
        return r;
@@ -2020,26 +2064,6 @@ DEFINE_PER_CPU(printk_func_t, printk_fun
 
 #endif /* CONFIG_PRINTK */
 
-#ifdef CONFIG_EARLY_PRINTK
-struct console *early_console;
-
-asmlinkage __visible void early_printk(const char *fmt, ...)
-{
-       va_list ap;
-       char buf[512];
-       int n;
-
-       if (!early_console)
-               return;
-
-       va_start(ap, fmt);
-       n = vscnprintf(buf, sizeof(buf), fmt, ap);
-       va_end(ap);
-
-       early_console->write(early_console, buf, n);
-}
-#endif
-
 static int __add_preferred_console(char *name, int idx, char *options,
                                   char *brl_options)
 {


Reply via email to