|
Revision tags: v6.15, v6.15-rc7, v6.15-rc6, v6.15-rc5, v6.15-rc4, v6.15-rc3, v6.15-rc2, v6.15-rc1, v6.14 |
|
| #
c1aa3daa |
| 18-Mar-2025 |
Donghyeok Choe <[email protected]> |
printk/panic: Add option to allow non-panic CPUs to write to the ring buffer.
Commit 779dbc2e78d7 ("printk: Avoid non-panic CPUs writing to ringbuffer") aimed to isolate panic-related messages. Howe
printk/panic: Add option to allow non-panic CPUs to write to the ring buffer.
Commit 779dbc2e78d7 ("printk: Avoid non-panic CPUs writing to ringbuffer") aimed to isolate panic-related messages. However, when panic() itself malfunctions, messages from non-panic CPUs become crucial for debugging.
While commit bcc954c6caba ("printk/panic: Allow cpu backtraces to be written into ringbuffer during panic") enables non-panic CPU backtraces, it may not provide sufficient diagnostic information.
Introduce the "debug_non_panic_cpus" command-line option, enabling non-panic CPU messages to be stored in the ring buffer during a panic. This also prevents discarding non-finalized messages from non-panic CPUs during console flushing, providing a more comprehensive view of system state during critical failures.
Link: https://lore.kernel.org/all/Z8cLEkqLL2IOyNIj@pathway/ Signed-off-by: Donghyeok Choe <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: Added documentation, added module_parameter, removed printk_ prefix.] Tested-by: Petr Mladek <[email protected]> Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
|
Revision tags: v6.14-rc7 |
|
| #
2f1f7787 |
| 14-Mar-2025 |
Adam Simonelli <[email protected]> |
printk: Add an option to allow ttynull to be a default console device
The new option is CONFIG_NULL_TTY_DEFAULT_CONSOLE.
if enabled, and CONFIG_VT is disabled, ttynull will become the default prima
printk: Add an option to allow ttynull to be a default console device
The new option is CONFIG_NULL_TTY_DEFAULT_CONSOLE.
if enabled, and CONFIG_VT is disabled, ttynull will become the default primary console device.
ttynull will be the only console device usually with this option enabled. Some architectures do call add_preferred_console() which may add another console though.
Motivation:
Many distributions ship with CONFIG_VT enabled. On tested desktop hardware if CONFIG_VT is disabled, the default console device falls back to /dev/ttyS0 instead of /dev/tty.
This could cause issues in user space, and hardware problems:
1. The user space issues include the case where /dev/ttyS0 is disconnected, and the TCGETS ioctl, which some user space libraries use as a probe to determine if a file is a tty, is called on /dev/console and fails. Programs that call isatty() on /dev/console and get an incorrect false value may skip expected logging to /dev/console.
2. The hardware issues include the case if a user has a science instrument or other device connected to the /dev/ttyS0 port, and they were to upgrade to a kernel that is disabling the CONFIG_VT option, kernel logs will then be sent to the device connected to /dev/ttyS0 unless they edit their kernel command line manually.
The new CONFIG_NULL_TTY_DEFAULT_CONSOLE option will give users and distribution maintainers an option to avoid this. Disabling CONFIG_VT and enabling CONFIG_NULL_TTY_DEFAULT_CONSOLE will ensure the default kernel console behavior is not dependent on hardware configuration by default, and avoid unexpected new behavior on devices connected to the /dev/ttyS0 serial port.
Reviewed-by: Petr Mladek <[email protected]> Tested-by: Petr Mladek <[email protected]> Signed-off-by: Adam Simonelli <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: Fixed indentation of the commit message.] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
|
Revision tags: v6.14-rc6, v6.14-rc5 |
|
| #
72c96a2d |
| 26-Feb-2025 |
Marcos Paulo de Souza <[email protected]> |
printk: Check CON_SUSPEND when unblanking a console
The commit 9e70a5e109a4 ("printk: Add per-console suspended state") introduced the CON_SUSPENDED flag for consoles. The suspended consoles will st
printk: Check CON_SUSPEND when unblanking a console
The commit 9e70a5e109a4 ("printk: Add per-console suspended state") introduced the CON_SUSPENDED flag for consoles. The suspended consoles will stop receiving messages, so don't unblank suspended consoles because it won't be showing anything either way.
Signed-off-by: Marcos Paulo de Souza <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Reviewed-by: John Ogness <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
5395e09c |
| 26-Feb-2025 |
Marcos Paulo de Souza <[email protected]> |
printk: Rename console_start to console_resume
The intent of console_start was to resume a previously suspended console, so rename it accordingly.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@su
printk: Rename console_start to console_resume
The intent of console_start was to resume a previously suspended console, so rename it accordingly.
Signed-off-by: Marcos Paulo de Souza <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Reviewed-by: John Ogness <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: Fixed typo in the commit message. Updated also new drm_log.c.] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
242fafe3 |
| 26-Feb-2025 |
Marcos Paulo de Souza <[email protected]> |
printk: Rename console_stop to console_suspend
The intent of console_stop was in fact to suspend it, so rename the function accordingly.
Signed-off-by: Marcos Paulo de Souza <[email protected]> Re
printk: Rename console_stop to console_suspend
The intent of console_stop was in fact to suspend it, so rename the function accordingly.
Signed-off-by: Marcos Paulo de Souza <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Reviewed-by: John Ogness <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: Fixed typo in the commit message. Updated also new drm_log.c] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
63830aef |
| 26-Feb-2025 |
Marcos Paulo de Souza <[email protected]> |
printk: Rename resume_console to console_resume_all
The function resume_console has a misleading name, since it resumes all consoles, so rename it accordingly.
Signed-off-by: Marcos Paulo de Souza
printk: Rename resume_console to console_resume_all
The function resume_console has a misleading name, since it resumes all consoles, so rename it accordingly.
Signed-off-by: Marcos Paulo de Souza <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Reviewed-by: John Ogness <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: Fixed typo in the commit message.] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
e9cec448 |
| 26-Feb-2025 |
Marcos Paulo de Souza <[email protected]> |
printk: Rename suspend_console to console_suspend_all
The function suspend_console has a misleading name, since it suspends all consoles, so rename it accordingly.
Signed-off-by: Marcos Paulo de So
printk: Rename suspend_console to console_suspend_all
The function suspend_console has a misleading name, since it suspends all consoles, so rename it accordingly.
Signed-off-by: Marcos Paulo de Souza <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Reviewed-by: John Ogness <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: Fixed typo in the commit message.] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
6ea9a178 |
| 25-Feb-2025 |
Paul E. McKenney <[email protected]> |
Flush console log from kernel_power_off()
Kernels built with CONFIG_PREEMPT_RT=y can lose significant console output and shutdown time, which hides shutdown-time RCU issues from rcutorture. Therefor
Flush console log from kernel_power_off()
Kernels built with CONFIG_PREEMPT_RT=y can lose significant console output and shutdown time, which hides shutdown-time RCU issues from rcutorture. Therefore, make pr_flush() public and invoke it after then last print in kernel_power_off().
[ paulmck: Apply John Ogness feedback. ] [ paulmck: Appy Sebastian Andrzej Siewior feedback. ] [ paulmck: Apply kernel test robot feedback. ]
Signed-off-by: Paul E. McKenney <[email protected]> Reviewed-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Link: https://lore.kernel.org/r/5f743488-dc2a-4f19-bdda-cf50b9314832@paulmck-laptop Signed-off-by: Boqun Feng <[email protected]>
show more ...
|
|
Revision tags: v6.14-rc4, v6.14-rc3, v6.14-rc2, v6.14-rc1, v6.13, v6.13-rc7, v6.13-rc6, v6.13-rc5, v6.13-rc4, v6.13-rc3 |
|
| #
0161e2d6 |
| 09-Dec-2024 |
John Ogness <[email protected]> |
printk: Defer legacy printing when holding printk_cpu_sync
The documentation of printk_cpu_sync_get() clearly states that the owner must never perform any activities where it waits for a CPU. For le
printk: Defer legacy printing when holding printk_cpu_sync
The documentation of printk_cpu_sync_get() clearly states that the owner must never perform any activities where it waits for a CPU. For legacy printing there can be spinning on the console_lock and on the port lock. Therefore legacy printing must be deferred when holding the printk_cpu_sync.
Note that in the case of emergency states, atomic consoles are not prevented from printing when printk is deferred. This is appropriate because they do not spin-wait indefinitely for other CPUs.
Reported-by: Rik van Riel <[email protected]> Closes: https://lore.kernel.org/r/[email protected] Signed-off-by: John Ogness <[email protected]> Fixes: 55d6af1d6688 ("lib/nmi_backtrace: explicitly serialize banner and regs") Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
|
Revision tags: v6.13-rc2, v6.13-rc1, v6.12, v6.12-rc7, v6.12-rc6, v6.12-rc5, v6.12-rc4, v6.12-rc3, v6.12-rc2, v6.12-rc1 |
|
| #
3d6f83df |
| 28-Sep-2024 |
Kuan-Wei Chiu <[email protected]> |
printk: Fix signed integer overflow when defining LOG_BUF_LEN_MAX
Shifting 1 << 31 on a 32-bit int causes signed integer overflow, which leads to undefined behavior. To prevent this, cast 1 to u32 b
printk: Fix signed integer overflow when defining LOG_BUF_LEN_MAX
Shifting 1 << 31 on a 32-bit int causes signed integer overflow, which leads to undefined behavior. To prevent this, cast 1 to u32 before performing the shift, ensuring well-defined behavior.
This change explicitly avoids any potential overflow by ensuring that the shift occurs on an unsigned 32-bit integer.
Signed-off-by: Kuan-Wei Chiu <[email protected]> Acked-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
ed76c07c |
| 05-Nov-2024 |
Marcos Paulo de Souza <[email protected]> |
printk: Introduce FORCE_CON flag
Introduce FORCE_CON flag to printk. The new flag will make it possible to create a context where printk messages will never be suppressed.
This mechanism will be us
printk: Introduce FORCE_CON flag
Introduce FORCE_CON flag to printk. The new flag will make it possible to create a context where printk messages will never be suppressed.
This mechanism will be used in the next patch to create a force_con context on sysrq handling, removing an existing workaround on the loglevel global variable. The workaround existed to make sure that sysrq header messages were sent to all consoles, but this doesn't work with deferred messages because the loglevel might be restored to its original value before a console flushes the messages.
Signed-off-by: Marcos Paulo de Souza <[email protected]> Reviewed-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
93190bc3 |
| 04-Nov-2024 |
Marco Elver <[email protected]> |
seqlock, treewide: Switch to non-raw seqcount_latch interface
Switch all instrumentable users of the seqcount_latch interface over to the non-raw interface.
Co-developed-by: "Peter Zijlstra (Intel)
seqlock, treewide: Switch to non-raw seqcount_latch interface
Switch all instrumentable users of the seqcount_latch interface over to the non-raw interface.
Co-developed-by: "Peter Zijlstra (Intel)" <[email protected]> Signed-off-by: "Peter Zijlstra (Intel)" <[email protected]> Signed-off-by: Marco Elver <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
show more ...
|
| #
a961ec4e |
| 30-Sep-2024 |
Isaac J. Manjarres <[email protected]> |
printk: Improve memory usage logging during boot
When the initial printk ring buffer size is updated, setup_log_buf() allocates a new ring buffer, as well as a set of meta-data structures for the ne
printk: Improve memory usage logging during boot
When the initial printk ring buffer size is updated, setup_log_buf() allocates a new ring buffer, as well as a set of meta-data structures for the new ring buffer. The function also emits the new size of the ring buffer, but not the size of the meta-data structures.
This makes it difficult to assess how changing the log buffer size impacts memory usage during boot.
For instance, increasing the ring buffer size from 512 KB to 1 MB through the command line yields an increase of 2304 KB in reserved memory at boot, while the only obvious change is the 512 KB difference in the ring buffer sizes:
log_buf_len=512K:
printk: log_buf_len: 524288 bytes Memory: ... (... 733252K reserved ...)
log_buf_len=1M:
printk: log_buf_len: 1048576 bytes Memory: ... (... 735556K reserved ...)
This is because of how the size of the meta-data structures scale with the size of the ring buffer.
Even when there aren't changes to the printk ring buffer size (i.e. the initial size == 1 << CONFIG_LOG_BUF_SHIFT), it is impossible to tell how much memory is consumed by the printk ring buffer during boot.
Therefore, unconditionally log the sizes of the printk ring buffer and its meta-data structures, so that it's easier to understand how changing the log buffer size (either through the command line or by changing CONFIG_LOG_BUF_SHIFT) affects boot time memory usage.
With the new logs, it is much easier to see exactly why the memory increased by 2304 KB:
log_buf_len=512K:
printk: log buffer data + meta data: 524288 + 1835008 = 2359296 bytes Memory: ... (... 733252K reserved ...)
log_buf_len=1M:
printk: log buffer data + meta data: 1048576 + 3670016 = 4718592 bytes Memory: ... (... 735556K reserved ...)
Signed-off-by: Isaac J. Manjarres <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Tested-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: Updated the examples in the commit message, simplified comment for default buffer.] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
|
Revision tags: v6.11 |
|
| #
3e5b2e81 |
| 09-Sep-2024 |
Yu Liao <[email protected]> |
printk: Export match_devname_and_update_preferred_console()
When building serial_base as a module, modpost fails with the following error message:
ERROR: modpost: "match_devname_and_update_prefer
printk: Export match_devname_and_update_preferred_console()
When building serial_base as a module, modpost fails with the following error message:
ERROR: modpost: "match_devname_and_update_preferred_console" [drivers/tty/serial/serial_base.ko] undefined!
Export the symbol to allow using it from modules.
Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Fixes: 12c91cec3155 ("serial: core: Add serial_base_match_and_update_preferred_console()") Signed-off-by: Yu Liao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
|
Revision tags: v6.11-rc7 |
|
| #
daeed159 |
| 04-Sep-2024 |
John Ogness <[email protected]> |
printk: Avoid false positive lockdep report for legacy printing
Legacy console printing from printk() caller context may invoke the console driver from atomic context. This leads to a lockdep splat
printk: Avoid false positive lockdep report for legacy printing
Legacy console printing from printk() caller context may invoke the console driver from atomic context. This leads to a lockdep splat because the console driver will acquire a sleeping lock and the caller may already hold a spinning lock. This is noticed by lockdep on !PREEMPT_RT configurations because it will lead to a problem on PREEMPT_RT.
However, on PREEMPT_RT the printing path from atomic context is always avoided and the console driver is always invoked from a dedicated thread. Thus the lockdep splat on !PREEMPT_RT is a false positive.
For !PREEMPT_RT override the lock-context before invoking the console driver to avoid the false positive.
Do not override the lock-context for PREEMPT_RT in order to allow lockdep to catch any real locking context issues related to the write callback usage.
Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
1529bbb6 |
| 04-Sep-2024 |
John Ogness <[email protected]> |
printk: nbcon: Assign nice -20 for printing threads
It is important that console printing threads are scheduled shortly after a printk call and with generous runtime budgets.
Signed-off-by: John Og
printk: nbcon: Assign nice -20 for printing threads
It is important that console printing threads are scheduled shortly after a printk call and with generous runtime budgets.
Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
5f53ca3f |
| 04-Sep-2024 |
John Ogness <[email protected]> |
printk: Implement legacy printer kthread for PREEMPT_RT
The write() callback of legacy consoles usually makes use of spinlocks. This is not permitted with PREEMPT_RT in atomic contexts.
For PREEMPT
printk: Implement legacy printer kthread for PREEMPT_RT
The write() callback of legacy consoles usually makes use of spinlocks. This is not permitted with PREEMPT_RT in atomic contexts.
For PREEMPT_RT, create a new kthread to handle printing of all the legacy consoles (and nbcon consoles if boot consoles are registered). This allows legacy consoles to work on PREEMPT_RT without requiring modification. (However they will not have the reliability properties guaranteed by nbcon atomic consoles.)
Use the existing printk_kthreads_check_locked() to start/stop the legacy kthread as needed.
Introduce the macro force_legacy_kthread() to query if the forced threading of legacy consoles is in effect. Although currently only enabled for PREEMPT_RT, this acts as a simple mechanism for the future to allow other preemption models to easily take advantage of the non-interference property provided by the legacy kthread.
When force_legacy_kthread() is true, the legacy kthread fulfills the role of the console_flush_type @legacy_offload by waking the legacy kthread instead of printing via the console_lock in the irq_work. If the legacy kthread is not yet available, no legacy printing takes place (unless in panic).
If for some reason the legacy kthread fails to create, any legacy consoles are unregistered. With force_legacy_kthread(), the legacy kthread is a critical component for legacy consoles.
These changes only affect CONFIG_PREEMPT_RT.
Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
5102981d |
| 04-Sep-2024 |
John Ogness <[email protected]> |
printk: nbcon: Show replay message on takeover
An emergency or panic context can takeover console ownership while the current owner was printing a printk message. The atomic printer will re-print th
printk: nbcon: Show replay message on takeover
An emergency or panic context can takeover console ownership while the current owner was printing a printk message. The atomic printer will re-print the message that the previous owner was printing. However, this can look confusing to the user and may even seem as though a message was lost.
[3430014.1 [3430014.181123] usb 1-2: Product: USB Audio
Add a new field @nbcon_prev_seq to struct console to track the sequence number to print that was assigned to the previous console owner. If this matches the sequence number to print that the current owner is assigned, then a takeover must have occurred. In this case, print an additional message to inform the user that the previous message is being printed again.
[3430014.1 ** replaying previous printk message ** [3430014.181123] usb 1-2: Product: USB Audio
Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
75d43037 |
| 04-Sep-2024 |
John Ogness <[email protected]> |
printk: Provide helper for message prepending
In order to support prepending different texts to printk messages, split out the prepending code into a helper function.
Signed-off-by: John Ogness <jo
printk: Provide helper for message prepending
In order to support prepending different texts to printk messages, split out the prepending code into a helper function.
Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
13189fa7 |
| 04-Sep-2024 |
John Ogness <[email protected]> |
printk: nbcon: Rely on kthreads for normal operation
Once the kthread is running and available (i.e. @printk_kthreads_running is set), the kthread becomes responsible for flushing any pending messag
printk: nbcon: Rely on kthreads for normal operation
Once the kthread is running and available (i.e. @printk_kthreads_running is set), the kthread becomes responsible for flushing any pending messages which are added in NBCON_PRIO_NORMAL context. Namely the legacy console_flush_all() and device_release() no longer flush the console. And nbcon_atomic_flush_pending() used by nbcon_cpu_emergency_exit() no longer flushes messages added after the emergency messages.
The console context is safe when used by the kthread only when one of the following conditions are true:
1. Other caller acquires the console context with NBCON_PRIO_NORMAL with preemption disabled. It will release the context before rescheduling.
2. Other caller acquires the console context with NBCON_PRIO_NORMAL under the device_lock.
3. The kthread is the only context which acquires the console with NBCON_PRIO_NORMAL.
This is satisfied for all atomic printing call sites:
nbcon_legacy_emit_next_record() (#1)
nbcon_atomic_flush_pending_con() (#1)
nbcon_device_release() (#2)
It is even double guaranteed when @printk_kthreads_running is set because then _only_ the kthread will print for NBCON_PRIO_NORMAL. (#3)
Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
5c586baa |
| 04-Sep-2024 |
John Ogness <[email protected]> |
printk: nbcon: Use thread callback if in task context for legacy
When printing via console_lock, the write_atomic() callback is used for nbcon consoles. However, if it is known that the current cont
printk: nbcon: Use thread callback if in task context for legacy
When printing via console_lock, the write_atomic() callback is used for nbcon consoles. However, if it is known that the current context is a task context, the write_thread() callback can be used instead.
Using write_thread() instead of write_atomic() helps to reduce large disabled preemption regions when the device_lock does not disable preemption.
This is mainly a preparatory change to allow avoiding write_atomic() completely during normal operation if boot consoles are registered.
As a side-effect, it also allows consolidating the printing code for legacy printing and the kthread printer.
Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
76f258bf |
| 04-Sep-2024 |
Thomas Gleixner <[email protected]> |
printk: nbcon: Introduce printer kthreads
Provide the main implementation for running a printer kthread per nbcon console that is takeover/handover aware. This includes:
- new mandatory write_threa
printk: nbcon: Introduce printer kthreads
Provide the main implementation for running a printer kthread per nbcon console that is takeover/handover aware. This includes:
- new mandatory write_thread() callback - kthread creation - kthread main printing loop - kthread wakeup mechanism - kthread shutdown
kthread creation is a bit tricky because consoles may register before kthreads can be created. In such cases, registration will succeed, even though no kthread exists. Once kthreads can be created, an early_initcall will set @printk_kthreads_ready. If there are no registered boot consoles, the early_initcall creates the kthreads for all registered nbcon consoles. If kthread creation fails, the related console is unregistered.
If there are registered boot consoles when @printk_kthreads_ready is set, no kthreads are created until the final boot console unregisters.
Once kthread creation finally occurs, @printk_kthreads_running is set so that the system knows kthreads are available for all registered nbcon consoles.
If @printk_kthreads_running is already set when the console is registering, the kthread is created during registration. If kthread creation fails, the registration will fail.
Until @printk_kthreads_running is set, console printing occurs directly via the console_lock.
kthread shutdown on system shutdown/reboot is necessary to ensure the printer kthreads finish their printing so that the system can cleanly transition back to direct printing via the console_lock in order to reliably push out the final shutdown/reboot messages. @printk_kthreads_running is cleared before shutting down the individual kthreads.
The kthread uses a new mandatory write_thread() callback that is called with both device_lock() and the console context acquired.
The console ownership handling is necessary for synchronization against write_atomic() which is synchronized only via the console context ownership.
The device_lock() serializes acquiring the console context with NBCON_PRIO_NORMAL. It is needed in case the device_lock() does not disable preemption. It prevents the following race:
CPU0 CPU1
[ task A ]
nbcon_context_try_acquire() # success with NORMAL prio # .unsafe == false; // safe for takeover
[ schedule: task A -> B ]
WARN_ON() nbcon_atomic_flush_pending() nbcon_context_try_acquire() # success with EMERGENCY prio
# flushing nbcon_context_release()
# HERE: con->nbcon_state is free # to take by anyone !!!
nbcon_context_try_acquire() # success with NORMAL prio [ task B ]
[ schedule: task B -> A ]
nbcon_enter_unsafe() nbcon_context_can_proceed()
BUG: nbcon_context_can_proceed() returns "true" because the console is owned by a context on CPU0 with NBCON_PRIO_NORMAL.
But it should return "false". The console is owned by a context from task B and we do the check in a context from task A.
Note that with these changes, the printer kthreads do not yet take over full responsibility for nbcon printing during normal operation. These changes only focus on the lifecycle of the kthreads.
Co-developed-by: John Ogness <[email protected]> Signed-off-by: John Ogness <[email protected]> Signed-off-by: Thomas Gleixner (Intel) <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
6cb58cfe |
| 04-Sep-2024 |
John Ogness <[email protected]> |
printk: nbcon: Add context to usable() and emit()
The nbcon consoles will have two callbacks to be used for different contexts. In order to determine if an nbcon console is usable, console_is_usable
printk: nbcon: Add context to usable() and emit()
The nbcon consoles will have two callbacks to be used for different contexts. In order to determine if an nbcon console is usable, console_is_usable() must know if it is a context that will need to use the optional write_atomic() callback. Also, nbcon_emit_next_record() must know which callback it needs to call.
Add an extra parameter @use_atomic to console_is_usable() and nbcon_emit_next_record() to specify this.
Since so far only the write_atomic() callback exists, @use_atomic is set to true for all call sites.
For legacy consoles, @use_atomic is not used.
Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
0e53e2d9 |
| 04-Sep-2024 |
John Ogness <[email protected]> |
printk: Flush console on unregister_console()
Ensure consoles have flushed pending records before unregistering. The console should print up to at least its related "console disabled" record.
Signe
printk: Flush console on unregister_console()
Ensure consoles have flushed pending records before unregistering. The console should print up to at least its related "console disabled" record.
Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|
| #
e37577eb |
| 04-Sep-2024 |
John Ogness <[email protected]> |
printk: Fail pr_flush() if before SYSTEM_SCHEDULING
A follow-up change adds pr_flush() to console unregistration. However, with boot consoles unregistration can happen very early if there are also r
printk: Fail pr_flush() if before SYSTEM_SCHEDULING
A follow-up change adds pr_flush() to console unregistration. However, with boot consoles unregistration can happen very early if there are also regular consoles registering as well. In this case the pr_flush() is not important because all consoles are flushed when checking the initial console sequence number.
Allow pr_flush() to fail if @system_state has not yet reached SYSTEM_SCHEDULING. This avoids might_sleep() and msleep() explosions that would otherwise occur:
[ 0.436739][ T0] printk: legacy console [ttyS0] enabled [ 0.439820][ T0] printk: legacy bootconsole [earlyser0] disabled [ 0.446822][ T0] BUG: scheduling while atomic: swapper/0/0/0x00000002 [ 0.450491][ T0] 1 lock held by swapper/0/0: [ 0.457897][ T0] #0: ffffffff82ae5f88 (console_mutex){+.+.}-{4:4}, at: console_list_lock+0x20/0x70 [ 0.463141][ T0] Modules linked in: [ 0.465307][ T0] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.10.0-rc1+ #372 [ 0.469394][ T0] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014 [ 0.474402][ T0] Call Trace: [ 0.476246][ T0] <TASK> [ 0.481473][ T0] dump_stack_lvl+0x93/0xb0 [ 0.483949][ T0] dump_stack+0x10/0x20 [ 0.486256][ T0] __schedule_bug+0x68/0x90 [ 0.488753][ T0] __schedule+0xb9b/0xd80 [ 0.491179][ T0] ? lock_release+0xb5/0x270 [ 0.493732][ T0] schedule+0x43/0x170 [ 0.495998][ T0] schedule_timeout+0xc5/0x1e0 [ 0.498634][ T0] ? __pfx_process_timeout+0x10/0x10 [ 0.501522][ T0] ? msleep+0x13/0x50 [ 0.503728][ T0] msleep+0x3c/0x50 [ 0.505847][ T0] __pr_flush.constprop.0.isra.0+0x56/0x500 [ 0.509050][ T0] ? _printk+0x58/0x80 [ 0.511332][ T0] ? lock_is_held_type+0x9c/0x110 [ 0.514106][ T0] unregister_console_locked+0xe1/0x450 [ 0.517144][ T0] register_console+0x509/0x620 [ 0.519827][ T0] ? __pfx_univ8250_console_init+0x10/0x10 [ 0.523042][ T0] univ8250_console_init+0x24/0x40 [ 0.525845][ T0] console_init+0x43/0x210 [ 0.528280][ T0] start_kernel+0x493/0x980 [ 0.530773][ T0] x86_64_start_reservations+0x18/0x30 [ 0.533755][ T0] x86_64_start_kernel+0xae/0xc0 [ 0.536473][ T0] common_startup_64+0x12c/0x138 [ 0.539210][ T0] </TASK>
And then the kernel goes into an infinite loop complaining about:
1. releasing a pinned lock 2. unpinning an unpinned lock 3. bad: scheduling from the idle thread! 4. goto 1
Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
show more ...
|