2024-02-18 19:06:03

by John Ogness

[permalink] [raw]
Subject: [PATCH printk v2 00/26] wire up write_atomic() printing

Hi,

This is v3 of a series to wire up the nbcon consoles so that
they actually perform printing using their write_atomic()
callback. v2 is here [0]. For information about the motivation
of the atomic consoles, please read the cover letter of v1 [1].

The main focus of this series:

- For nbcon consoles, always call write_atomic() directly from
printk() caller context for the panic CPU.

- For nbcon consoles, call write_atomic() when unlocking the
console lock.

- Only perform the console_lock()/_unlock() dance if legacy or
boot consoles are registered.

- For legacy consoles, if nbcon consoles are registered, do not
attempt to print from printk() caller context for the panic
CPU until nbcon consoles have had a chance to print the most
significant messages.

- Mark emergency sections. In these sections printk() calls
will only store the messages. Upon exiting the emergency
section, console flushing is triggered via irq_work.

This series does _not_ include threaded printing or nbcon
drivers. Those features will be added in separate follow-up
series.

Note1: With this series, a system with _only_ nbcon consoles
registered will not have any console printing except
on panic. This is on purpose. When nbcon kthreads are
introduced, they will fill this gap.

Note2: Patches 1-3 are already mainline, but not yet in the
printk/for-next tree. They are included for
completeness, but are not actually part of this series.

The changes since v2:

- Eliminate CPU states (normal, emergency, panic) and instead
just track per-cpu emergency nesting.

- Instead of talking about "atomic mode", talk about "using the
write_atomic() callback". This avoids confusion about what
"atomic mode" means (i.e. "atomic" always means the
write_atomic() callback is used).

- Rename atomic_enter()/_exit() to
cpu_emergency_enter()/_exit().

- When entering emergency mode for a CPU, disable preemption
rather than just migration to allow the warning to be
completely handled before permitting rescheduling.

- Implement nbcon locking within the uart port lock wrappers.
This provides synchronization between write_atomic() and
non-printing driver activities (such as changing the baud
rate.)

- Implement a one-way trigger printk_legacy_allow_panic_sync()
to allow legacy consoles to print from the printk() caller
context for the panic CPU. This allows the safe nbcon
consoles to print before falling back to legacy consoles.
Note that if no nbcon consoles are registered, legacy
consoles are always allowed to print from the printk() caller
context.

- Perform unsafe nbcon flushing at the very end of panic before
going into the infinite loop.

- Add nbcon_get_default_prio() helper to return the appropriate
prio for the current CPU.

- Do not assume that if write_atomic() returns false that the
console has been released.

- For nbcon_atomic_emit_one(), rely on @ctxt->backlog rather
than trying to read the next record.

- Rename nbcon_console_emit_next_record() to
nbcon_legacy_emit_next_record() and have it use the same
procedure as console_emit_next_record() (enter printk_safe,
enable console_lock spinning, stop critical timings).

- Add nbcon_atomic_flush_unsafe() to allow flushing nbcon
consoles in an unsafe manner.

- For nbcon flushing, add @stop_seq argument limit how much to
print. This avoids a CPU getting stuck printing endlessly.

- For nbcon flushing, disable irqs to avoid an interrupt
possibly calling into console code and deadlocking on nbcon
ownership.

- The rules for allowing printing from the printk() caller
context are getting quite complex. Move all this logic into
vprintk_emit().

- For console_init_seq(), also consider nbcon consoles.

- For __pr_flush(), only take the console_lock if legacy or
boot consoles are registered.

- For printk_trigger_flush(), do not flush nbcon consoles
directly.

- For defer_console_output(), only trigger
console_lock()/unlock() if legacy or boot consoles are
registered.

- Add detailed kerneldoc for the write_atomic() callback.

- Fix kerneldoc for enum types (cons_flags, nbcon_prio).

- Add extra check to printk_deferred_enter()/_exit() to ensure
it is called with migration disabled.

[0] https://lore.kernel.org/lkml/[email protected]
[1] https://lore.kernel.org/lkml/[email protected]

John Ogness (19):
printk: Consider nbcon boot consoles on seq init
printk: Add notation to console_srcu locking
printk: nbcon: Ensure ownership release on failed emit
printk: nbcon: Implement processing in port->lock wrapper
printk: nbcon: Add detailed doc for write_atomic()
printk: nbcon: Fix kerneldoc for enums
printk: Make console_is_usable() available to nbcon
printk: Let console_is_usable() handle nbcon
printk: Add @flags argument for console_is_usable()
printk: Track registered boot consoles
printk: nbcon: Use nbcon consoles in console_flush_all()
printk: nbcon: Assign priority based on CPU state
printk: nbcon: Add unsafe flushing on panic
printk: Avoid console_lock dance if no legacy or boot consoles
printk: Track nbcon consoles
printk: Coordinate direct printing in panic
panic: Mark emergency section in oops
rcu: Mark emergency section in rcu stalls
lockdep: Mark emergency section in lockdep splats

Randy Dunlap (1):
serial: core: fix kernel-doc for uart_port_unlock_irqrestore()

Sebastian Andrzej Siewior (1):
printk: Check printk_deferred_enter()/_exit() usage

Thomas Gleixner (5):
serial: core: Provide port lock wrappers
serial: core: Use lock wrappers
printk: nbcon: Provide function to flush using write_atomic()
printk: nbcon: Implement emergency sections
panic: Mark emergency section in warn

drivers/tty/serial/8250/8250_port.c | 1 +
include/linux/console.h | 42 +++-
include/linux/printk.h | 30 ++-
include/linux/serial_core.h | 106 +++++++-
kernel/locking/lockdep.c | 5 +
kernel/panic.c | 9 +
kernel/printk/internal.h | 57 +++++
kernel/printk/nbcon.c | 362 +++++++++++++++++++++++++++-
kernel/printk/printk.c | 248 +++++++++++++------
kernel/printk/printk_safe.c | 12 +
kernel/rcu/tree_stall.h | 5 +
11 files changed, 784 insertions(+), 93 deletions(-)


base-commit: e7081d5a9d976b84f61f497316d7c940a4a2e67a
--
2.39.2



2024-02-18 19:06:05

by John Ogness

[permalink] [raw]
Subject: [PATCH printk v2 03/26] serial: core: fix kernel-doc for uart_port_unlock_irqrestore()

From: Randy Dunlap <[email protected]>

mainline commit: 29bff582b74ed0bdb7e6986482ad9e6799ea4d2f

Fix the function name to avoid a kernel-doc warning:

include/linux/serial_core.h:666: warning: expecting prototype for uart_port_lock_irqrestore(). Prototype was for uart_port_unlock_irqrestore() instead

Fixes: b0af4bcb4946 ("serial: core: Provide port lock wrappers")
Signed-off-by: Randy Dunlap <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: John Ogness <[email protected]>
Cc: [email protected]
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Jiri Slaby <[email protected]>
Reviewed-by: John Ogness <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/serial_core.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 3091c62ec37b..89f7b6c63598 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -658,7 +658,7 @@ static inline void uart_port_unlock_irq(struct uart_port *up)
}

/**
- * uart_port_lock_irqrestore - Unlock the UART port, restore interrupts
+ * uart_port_unlock_irqrestore - Unlock the UART port, restore interrupts
* @up: Pointer to UART port structure
* @flags: The saved interrupt flags for restore
*/
--
2.39.2