Console driver(-s) can be in any state when CPU stop IPI
arrives from panic() issued on another CPU, so
console_flush_on_panic()->console_unlock() can call
con->write() callback on a locked console driver.

Introduce reset_console_drivers() that attempts to reset()
every console in via a console driver specific ->reset()
call.

Invoke reset_console_drivers() from console_reset_on_panic().

WARNING
=======
console_reset_on_panic() needs to be fixed.

Not-Yet-Signed-off-by: Sergey Senozhatsky <sergey.senozhat...@gmail.com>
---
 include/linux/console.h |  1 +
 kernel/printk/printk.c  | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/include/linux/console.h b/include/linux/console.h
index 6edc2ea..f745ffe 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -125,6 +125,7 @@ struct console {
        void    (*unblank)(void);
        int     (*setup)(struct console *, char *);
        int     (*match)(struct console *, char *name, int idx, char *options);
+       void    (*reset)(struct console *);
        short   flags;
        short   index;
        int     cflag;
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 34642f7..e245f9f 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1462,6 +1462,15 @@ static void call_console_drivers(int level,
        }
 }
 
+static void reset_console_drivers(void)
+{
+       struct console *con;
+
+       for_each_console(con)
+               if ((con->flags & CON_ENABLED) && con->reset)
+                       con->reset(con);
+}
+
 /*
  * Zap console related locks when oopsing.
  * To leave time for slow consoles to print a full oops,
@@ -2397,6 +2406,7 @@ void console_flush_on_panic(void)
 void console_reset_on_panic(void)
 {
        zap_locks();
+       reset_console_drivers();
 }
 
 /*
-- 
2.7.0

Reply via email to