[PATCH printk v2 00/26] wire up write_atomic() printing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/20230919230856.661435-1-john.ogness@xxxxxxxxxxxxx
[1] https://lore.kernel.org/lkml/20230302195618.156940-1-john.ogness@xxxxxxxxxxxxx

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





[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux