[PATCH printk v2 2/8] printk: Provide debug_store() for nbcon debugging

From: John Ogness
Date: Thu Jul 27 2023 - 20:02:45 EST


To debug and validate nbcon ownership transitions, provide a new
macro debug_store() (enabled with DEBUG_NBCON) to log transition
information to the ringbuffer. If enabled, this macro only logs
to the ringbuffer and does not trigger any printing. This is to
avoid triggering recursive printing in the nbcon consoles.

Signed-off-by: John Ogness <john.ogness@xxxxxxxxxxxxx>
---
kernel/printk/printk_nbcon.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)

diff --git a/kernel/printk/printk_nbcon.c b/kernel/printk/printk_nbcon.c
index bb379a4f6263..f9462b088439 100644
--- a/kernel/printk/printk_nbcon.c
+++ b/kernel/printk/printk_nbcon.c
@@ -10,6 +10,35 @@
* the legacy style console_lock mechanism.
*/

+/*
+ * Define DEBUG_NBCON to allow for nbcon ownership transitions to be logged
+ * to the ringbuffer. The debug_store() macro only logs to the lockless
+ * ringbuffer and does not trigger any printing.
+ */
+#undef DEBUG_NBCON
+
+#ifdef DEBUG_NBCON
+/* Only write to ringbuffer. */
+int __debug_store(const char *fmt, ...)
+{
+ va_list args;
+ int r;
+
+ va_start(args, fmt);
+ r = vprintk_store(2, 7, NULL, fmt, args);
+ va_end(args);
+
+ return r;
+}
+#define debug_store(cond, fmt, ...) \
+ do { \
+ if (cond) \
+ __debug_store(pr_fmt("DEBUG: " fmt), ##__VA_ARGS__) \
+ } while (0)
+#else
+#define debug_store(cond, fmt, ...)
+#endif
+
/**
* nbcon_state_set - Helper function to set the console state
* @con: Console to update
--
2.39.2