Blob Blame History Raw
From b68f92a4e6eade35ea5bd2111fe161de79006709 Mon Sep 17 00:00:00 2001
From: John Ogness <john.ogness@linutronix.de>
Date: Mon, 7 Feb 2022 15:54:54 +0106
Subject: [PATCH] printk: remove @console_locked

References: SLE Realtime Extension
Patch-mainline: Queued in subsystem maintainer repository
Git-commit: 3efc5682a7c00d08ac7ad3384587860fd974dfc1
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git

The static global variable @console_locked is used to help debug VT
code to make sure that certain code paths are running with the
console_lock held. However, this information is also available with
the static global variable @consoles_paused (for locking via
console_lock()), and the static global variable @console_lock_count
(for locking via console_trylock()).

Remove @console_locked and update is_console_locked() to use the
alternative variables.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Mel Gorman <mgorman@suse.de>
---
 kernel/printk/printk.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 2ab16af3e5bb..1bb40529c54c 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -307,15 +307,7 @@ static void __pause_all_consoles(bool do_pause)
 #define pause_all_consoles() __pause_all_consoles(true)
 #define unpause_all_consoles() __pause_all_consoles(false)
 
-/*
- * This is used for debugging the mess that is the VT code by
- * keeping track if we have the console semaphore held. It's
- * definitely not the perfect debug tool (we don't know if _WE_
- * hold it and are racing, but it helps tracking those weird code
- * paths in the console code where we end up in places I want
- * locked without the console semaphore held).
- */
-static int console_locked, console_suspended;
+static int console_suspended;
 
 /*
  *	Array of consoles built from command line options (console=)
@@ -2622,7 +2614,6 @@ void console_lock(void)
 	if (console_suspended)
 		return;
 	pause_all_consoles();
-	console_locked = 1;
 	console_may_schedule = 1;
 }
 EXPORT_SYMBOL(console_lock);
@@ -2647,7 +2638,6 @@ int console_trylock(void)
 		up_console_sem();
 		return 0;
 	}
-	console_locked = 1;
 	console_may_schedule = 0;
 	return 1;
 }
@@ -2674,14 +2664,25 @@ static int console_trylock_sched(bool may_schedule)
 		return 0;
 	}
 	pause_all_consoles();
-	console_locked = 1;
 	console_may_schedule = 1;
 	return 1;
 }
 
+/*
+ * This is used to help to make sure that certain paths within the VT code are
+ * running with the console lock held. It is definitely not the perfect debug
+ * tool (it is not known if the VT code is the task holding the console lock),
+ * but it helps tracking those weird code paths in the console code such as
+ * when the console is suspended: where the console is not locked but no
+ * console printing may occur.
+ *
+ * Note: This returns true when the console is suspended but is not locked.
+ *       This is intentional because the VT code must consider that situation
+ *       the same as if the console was locked.
+ */
 int is_console_locked(void)
 {
-	return (console_locked || atomic_read(&console_lock_count));
+	return (consoles_paused || atomic_read(&console_lock_count));
 }
 EXPORT_SYMBOL(is_console_locked);
 
@@ -2714,8 +2715,6 @@ static inline bool console_is_usable(struct console *con)
 
 static void __console_unlock(void)
 {
-	console_locked = 0;
-
 	/*
 	 * Depending on whether console_lock() or console_trylock() was used,
 	 * appropriately allow the kthread printers to continue.
@@ -2993,7 +2992,6 @@ void console_unblank(void)
 		console_lock();
 	}
 
-	console_locked = 1;
 	console_may_schedule = 0;
 	for_each_console(c)
 		if ((c->flags & CON_ENABLED) && c->unblank)