From 8df8aa0fde50fae34cf5799698ab6ba1c3b337c2 Mon Sep 17 00:00:00 2001
From: Junxiao Chang <junxiao.chang@intel.com>
Date: Tue, 23 Jan 2024 05:40:32 +0000
Subject: [PATCH] printk: nbcon: move locked_port flag to struct uart_port
From fce60ec62bffefd5bf741742abc9b3eac7e1597b Mon Sep 17 00:00:00 2001
References: bsc#1214683 (PREEMPT_RT prerequisite backports)
Git-commit: b07c1d0e81140da5ac7871633737687213d1aadf
Patch-mainline: v6.6.20
Console pointer in uart_port might be shared among multiple uart
ports. Flag port locked by nbcon should be saved in uart_port
structure instead of in console structure.
Fixes: 6424f396c49e ("printk: nbcon: Implement processing in port->lock wrapper")
Suggested-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Junxiao Chang <junxiao.chang@intel.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lore.kernel.org/all/20240123054033.183114-2-junxiao.chang@intel.com
(cherry picked from commit d4fb86a96cb4a1efd24ca13a2ac234a1c9a3fdc5)
Signed-off-by: Clark Williams <clark.williams@gmail.com>
Signed-off-by: Mel Gorman <mgorman@suse.de>
---
include/linux/console.h | 2 --
include/linux/serial_core.h | 1 +
kernel/printk/nbcon.c | 8 ++++----
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/include/linux/console.h b/include/linux/console.h
index 266b47d585ce..3877f010305e 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -311,7 +311,6 @@ struct nbcon_write_context {
* @nbcon_state: State for nbcon consoles
* @nbcon_seq: Sequence number of the next record for nbcon to print
* @pbufs: Pointer to nbcon private buffer
- * @locked_port: True, if the port lock is locked by nbcon
* @kthread: Printer kthread for this console
* @rcuwait: RCU-safe wait object for @kthread waking
* @irq_work: Defer @kthread waking to IRQ work context
@@ -345,7 +344,6 @@ struct console {
atomic_t __private nbcon_state;
atomic_long_t __private nbcon_seq;
struct printk_buffers *pbufs;
- bool locked_port;
struct task_struct *kthread;
struct rcuwait rcuwait;
struct irq_work irq_work;
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 245c11753eff..b2221a50fcb2 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -488,6 +488,7 @@ struct uart_port {
struct uart_icount icount; /* statistics */
struct console *cons; /* struct console, if any */
+ bool nbcon_locked_port; /* True, if the port is locked by nbcon */
/* flags must be updated while holding port mutex */
upf_t flags;
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 1b1b585b1675..b53d93585ee7 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1586,7 +1586,7 @@ void nbcon_acquire(struct uart_port *up)
if (!uart_is_nbcon(up))
return;
- WARN_ON_ONCE(con->locked_port);
+ WARN_ON_ONCE(up->nbcon_locked_port);
do {
do {
@@ -1597,7 +1597,7 @@ void nbcon_acquire(struct uart_port *up)
} while (!nbcon_context_enter_unsafe(&ctxt));
- con->locked_port = true;
+ up->nbcon_locked_port = true;
}
EXPORT_SYMBOL_GPL(nbcon_acquire);
@@ -1623,13 +1623,13 @@ void nbcon_release(struct uart_port *up)
.prio = NBCON_PRIO_NORMAL,
};
- if (!con->locked_port)
+ if (!up->nbcon_locked_port)
return;
if (nbcon_context_exit_unsafe(&ctxt))
nbcon_context_release(&ctxt);
- con->locked_port = false;
+ up->nbcon_locked_port = false;
}
EXPORT_SYMBOL_GPL(nbcon_release);