lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZuRRTbapH0DCj334@pathway.suse.cz>
Date: Fri, 13 Sep 2024 16:50:53 +0200
From: Petr Mladek <pmladek@...e.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Sergey Senozhatsky <senozhatsky@...omium.org>,
	Steven Rostedt <rostedt@...dmis.org>,
	John Ogness <john.ogness@...utronix.de>,
	Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
	Rasmus Villemoes <linux@...musvillemoes.dk>,
	Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
	Thomas Gleixner <tglx@...utronix.de>, Jan Kara <jack@...e.cz>,
	Peter Zijlstra <peterz@...radead.org>, linux-kernel@...r.kernel.org
Subject: [GIT PULL] printk for 6.12

Hi Linus,

please pull the latest printk changes from

  git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git tags/printk-for-6.12

=============================================

This is the "last" part of the support for the new nbcon consoles.
Where "nbcon" stays for "No Big console lock CONsoles" aka not under
the console_lock.

New callbacks are added to struct console:

  - write_thread() for flushing nbcon consoles in task context.

  - write_atomic() for flushing nbcon consoles in atomic context,
    including NMI.

  - con->device_lock() and device_unlock() for taking the driver
    specific lock, for example, port->lock.

New printk-specific kthreads are created:

  - per-console kthreads which get responsible for flushing normal
    priority messages on nbcon consoles.

  - thread which gets responsible for flushing normal priority messages
    on all consoles when CONFIG_RT enabled.

The new callbacks are called under a special per-console lock which has
already been added back in v6.7. It allows to distinguish three severities:
normal, emergency, and panic. A context with a higher priority could take
over the ownership when it is safe even in the middle of handling a record.
The panic context could do it even when it is not safe. But it is allowed
only for the final desperate flush before entering the infinite loop.

The new lock helps to flush the messages directly in emergency and panic
contexts. But it is not enough in all situations:

  - console_lock() is still need for synchronization against boot consoles.

  - con->device_lock() is need for synchronization against other operations
    on the same HW, e.g. serial port speed setting, non-printk related
    read/write.

The dependency on con->device_lock() is mutual. Any code taking the driver
specific lock has to acquire the related nbcon console context as well.
For example, see the new uart_port_lock() API. It provides the necessary
synchronization against emergency and panic contexts where the messages
are flushed only under the new per-console lock.

Maybe surprisingly, a quite tricky part is the decision how to flush
the consoles in various situations. It has to take into account:

  - message priority:	 normal, emergency, panic

  - scheduling context:	 task, atomic, deferred_legacy

  - registered consoles: boot, legacy, nbcon

  - threads are running: early boot, suspend, shutdown, panic

  - caller:		 printk(), pr_flush(), printk_flush_in_panic(),
			 console_unlock(), console_start(), ...

The primary decision is made in printk_get_console_flush_type(). It creates
a hint what the caller should do:

  - flush nbcon consoles directly or via the kthread

  - call the legacy loop (console_unlock()) directly or via irq_work

The existing behavior is preserved for the legacy consoles. The only
exception is that they are not longer flushed directly from printk() in
panic() before CPUs are stopped. But this blocking happens only when at
least one nbcon console is registered. The motivation is to increase
a chance to produce the crash dump. They legacy consoles might create
a deadlock in compare with nbcon consoles. The nbcon console should
allow to see the messages even when the crash dump fails.

There are three possible ways how nbcon consoles are flushed:

  - The per-nbcon-console kthread is responsible for flushing messages
    added with the normal priority. This is the default mode.

  - The legacy loop, aka console_unlock(), is used when there is still
    a boot console registered. There is no easy way how to match an early
    console driver with a nbcon console driver. And the console_lock()
    provides the only reliable serialization at the moment.

    The legacy loop uses either con->write_atomic() or con->write_thread()
    callbacks depending on whether it is allowed to schedule. The atomic
    variant has to be used from printk().

  - In other situations, the messages are flushed directly using
    write_atomic() which can be called in any context, including NMI.
    It is primary needed during early boot or shutdown, in emergency
    situations, and panic.

The emergency priority is used by a code called within
nbcon_cpu_emergency_enter()/exit(). At the moment, it is used in four
situations: WARN(), Oops, lockdep, and RCU stall reports.

Finally, there is no nbcon console at the moment. It means that the changes
should _not_ modify the existing behavior. The only exception is CONFIG_RT
which would force offloading the legacy loop, for normal priority context,
into the dedicated kthread.

===============================================

Two thirds of the changes has already been in the pull request for 6.11.
The user-visible change is that the flushing is no longer postponed
in the emergency sections. The logic has been further simplified
by using printk_get_console_flush_type() already at this stage.

The new third of the changes added the write_thread() callback,
implemented the kthreads, and updated procfs and sysfs interfaces.

----------------------------------------------------------------
Jinjie Ruan (1):
      printk: Use the BITS_PER_LONG macro

John Ogness (47):
      printk: Add notation to console_srcu locking
      printk: nbcon: Consolidate alloc() and init()
      printk: nbcon: Clarify rules of the owner/waiter matching
      printk: nbcon: Remove return value for write_atomic()
      printk: nbcon: Add detailed doc for write_atomic()
      printk: nbcon: Add callbacks to synchronize with driver
      printk: nbcon: Use driver synchronization while (un)registering
      serial: core: Provide low-level functions to lock port
      serial: core: Introduce wrapper to set @uart_port->cons
      console: Improve console_srcu_read_flags() comments
      nbcon: Add API to acquire context for non-printing operations
      serial: core: Acquire nbcon context in port->lock wrapper
      printk: nbcon: Do not rely on proxy headers
      printk: Make console_is_usable() available to nbcon.c
      printk: Let console_is_usable() handle nbcon
      printk: Add @flags argument for console_is_usable()
      printk: nbcon: Add helper to assign priority based on CPU state
      printk: Track registered boot consoles
      printk: nbcon: Use nbcon consoles in console_flush_all()
      printk: Add is_printk_legacy_deferred()
      printk: nbcon: Flush new records on device_release()
      printk: Flush nbcon consoles first on panic
      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
      printk: Add helper for flush type logic
      panic: Mark emergency section in oops
      rcu: Mark emergency sections in rcu stalls
      lockdep: Mark emergency sections in lockdep splats
      printk: nbcon: Use raw_cpu_ptr() instead of open coding
      printk: nbcon: Add function for printers to reacquire ownership
      printk: Fail pr_flush() if before SYSTEM_SCHEDULING
      printk: Flush console on unregister_console()
      printk: nbcon: Add context to usable() and emit()
      printk: nbcon: Init @nbcon_seq to highest possible
      printk: nbcon: Relocate nbcon_atomic_emit_one()
      printk: nbcon: Use thread callback if in task context for legacy
      printk: nbcon: Rely on kthreads for normal operation
      printk: Provide helper for message prepending
      printk: nbcon: Show replay message on takeover
      proc: consoles: Add notation to c_start/c_stop
      proc: Add nbcon support for /proc/consoles
      tty: sysfs: Add nbcon support for 'active'
      printk: Implement legacy printer kthread for PREEMPT_RT
      printk: nbcon: Assign nice -20 for printing threads
      printk: Avoid false positive lockdep report for legacy printing

Petr Mladek (1):
      printk: Properly deal with nbcon consoles on seq init

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

Thomas Gleixner (4):
      printk: nbcon: Provide function to flush using write_atomic()
      printk: nbcon: Implement emergency sections
      panic: Mark emergency section in warn
      printk: nbcon: Introduce printer kthreads

 drivers/tty/serial/8250/8250_core.c |   6 +-
 drivers/tty/serial/amba-pl011.c     |   2 +-
 drivers/tty/serial/serial_core.c    |  16 +-
 drivers/tty/tty_io.c                |   2 +-
 fs/proc/consoles.c                  |   7 +-
 include/linux/console.h             | 158 +++++-
 include/linux/printk.h              |  33 +-
 include/linux/serial_core.h         | 117 ++++-
 kernel/locking/lockdep.c            |  83 +++-
 kernel/panic.c                      |   9 +
 kernel/printk/internal.h            | 207 +++++++-
 kernel/printk/nbcon.c               | 936 +++++++++++++++++++++++++++++++++---
 kernel/printk/printk.c              | 714 ++++++++++++++++++++++-----
 kernel/printk/printk_ringbuffer.h   |   7 +-
 kernel/printk/printk_safe.c         |  25 +-
 kernel/rcu/tree_exp.h               |   7 +
 kernel/rcu/tree_stall.h             |   9 +
 17 files changed, 2125 insertions(+), 213 deletions(-)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ