From d9fd8f631f4da4e234ba50129fb58c953ee68f3d Mon Sep 17 00:00:00 2001
From: "Luis Claudio R. Goncalves" <lgoncalv@redhat.com>
Date: Mon, 24 May 2021 16:58:26 -0300
Subject: [PATCH 506/518] printk: revamp "Make rt aware"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Commit 7fcfb8fdfc41e ("printk: Make rt aware") from v4.19-rt is more
comprehensive than its equivalent in v4.14-rt (commit 70ce7ac4c16f1).

As one example, this commit resolves the following build warnings from
v4.14-rt:

  kernel/printk/printk.c: At top level:
  kernel/printk/printk.c:1608:13: warning: ‘console_lock_spinning_enable’ defined but not used [-Wunused-function]
   static void console_lock_spinning_enable(void)
               ^
  kernel/printk/printk.c:1633:12: warning: ‘console_lock_spinning_disable_and_check’ defined but not used [-Wunused-function]
   static int console_lock_spinning_disable_and_check(void)
              ^

Note: fixed a migrate_enable/disable imbalance in printk_late_init() in
      v4.14.232-rt113.

Fixes: 70ce7ac4c16f1 ("printk: Make rt aware")
Fixes: 10de28bbf31a1 (printk: revamp "Make rt aware")
Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
---
 kernel/printk/printk.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 19dbf2820db0f..1e569bca948c3 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1583,6 +1583,7 @@ SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)
 	return do_syslog(type, buf, len, SYSLOG_FROM_READER);
 }
 
+#ifndef CONFIG_PREEMPT_RT_FULL
 /*
  * Special console_lock variants that help to reduce the risk of soft-lockups.
  * They allow to pass console_lock to another printk() call using a busy wait.
@@ -1723,6 +1724,15 @@ static int console_trylock_spinning(void)
 	return 1;
 }
 
+#else
+
+static int console_trylock_spinning(void)
+{
+	return console_trylock();
+}
+
+#endif
+
 /*
  * Call the console drivers, asking them to write out
  * log_buf[start] to log_buf[end - 1].
@@ -2864,6 +2874,7 @@ static int __init printk_late_init(void)
 	struct console *con;
 	int ret;
 
+	migrate_disable();
 	for_each_console(con) {
 		if (!(con->flags & CON_BOOT))
 			continue;
@@ -2890,6 +2901,7 @@ static int __init printk_late_init(void)
 	ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "printk:online",
 					console_cpu_notify, NULL);
 	WARN_ON(ret < 0);
+	migrate_enable();
 	return 0;
 }
 late_initcall(printk_late_init);
-- 
2.41.0

