aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/printk
diff options
context:
space:
mode:
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>2017-01-21 05:47:29 -0500
committerPetr Mladek <pmladek@suse.com>2017-03-24 11:09:46 -0400
commit64ca752dcbc018054bfea53b784d4c85d3ec896c (patch)
tree8b11043b4bc3b6cf60a7297a951929a887236527 /kernel/printk
parent7d91de74436a69c2b78a7a72f1e7f97f8b4396fa (diff)
printk: use console_trylock() in console_cpu_notify()
There is no need to always call blocking console_lock() in console_cpu_notify(), it's quite possible that console_sem can be locked by other CPU on the system, either already printing or soon to begin printing the messages. console_lock() in this case can simply block CPU hotplug for unknown period of time (console_unlock() is time unbound). Not that hotplug is very fast, but still, with other CPUs being online and doing printk() console_cpu_notify() can stuck. Use console_trylock() instead and opt-out if console_sem is already acquired from another CPU, since that CPU will do the printing for us. Link: http://lkml.kernel.org/r/20170121104729.8585-1-sergey.senozhatsky@gmail.com Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Cc: linux-kernel@vger.kernel.org Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Signed-off-by: Petr Mladek <pmladek@suse.com>
Diffstat (limited to 'kernel/printk')
-rw-r--r--kernel/printk/printk.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 34da86e73d00..94e2b104cdaa 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2028,15 +2028,16 @@ void resume_console(void)
2028 * @cpu: unused 2028 * @cpu: unused
2029 * 2029 *
2030 * If printk() is called from a CPU that is not online yet, the messages 2030 * If printk() is called from a CPU that is not online yet, the messages
2031 * will be spooled but will not show up on the console. This function is 2031 * will be printed on the console only if there are CON_ANYTIME consoles.
2032 * called when a new CPU comes online (or fails to come up), and ensures 2032 * This function is called when a new CPU comes online (or fails to come
2033 * that any such output gets printed. 2033 * up) or goes offline.
2034 */ 2034 */
2035static int console_cpu_notify(unsigned int cpu) 2035static int console_cpu_notify(unsigned int cpu)
2036{ 2036{
2037 if (!cpuhp_tasks_frozen) { 2037 if (!cpuhp_tasks_frozen) {
2038 console_lock(); 2038 /* If trylock fails, someone else is doing the printing */
2039 console_unlock(); 2039 if (console_trylock())
2040 console_unlock();
2040 } 2041 }
2041 return 0; 2042 return 0;
2042} 2043}