linux-stable/kernel/printk
John Ogness 6690d6b527 printk: Add helper for flush type logic
There are many call sites where console flushing occur.
Depending on the system state and types of consoles, the flush
methods to use are different. A flush call site generally must
consider:

	@have_boot_console
	@have_nbcon_console
	@have_legacy_console
	@legacy_allow_panic_sync
	is_printk_preferred()

and take into account the current CPU state:

	NBCON_PRIO_NORMAL
	NBCON_PRIO_EMERGENCY
	NBCON_PRIO_PANIC

in order to decide if it should:

	flush nbcon directly via atomic_write() callback
	flush legacy directly via console_unlock
	flush legacy via offload to irq_work

All of these call sites use their own logic to make this
decision, which is complicated and error prone. Especially
later when two more flush methods will be introduced:

	flush nbcon via offload to kthread
	flush legacy via offload to kthread

Introduce a new internal struct console_flush_type that specifies
which console flushing methods should be used in the context of
the caller.

Introduce a helper function to fill out console_flush_type to
be used for flushing call sites.

Replace the logic of all flushing call sites to use the new
helper.

This change standardizes behavior, leading to both fixes and
optimizations across various call sites. For instance, in
console_cpu_notify(), the new logic ensures that nbcon consoles
are flushed when they aren’t managed by the legacy loop.
Similarly, in console_flush_on_panic(), the system no longer
needs to flush nbcon consoles if none are present.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20240820063001.36405-31-john.ogness@linutronix.de
[pmladek@suse.com: Updated the commit message.]
Signed-off-by: Petr Mladek <pmladek@suse.com>
2024-08-21 14:56:49 +02:00
..
braille.c printk: Replace strncmp() with str_has_prefix() 2019-08-16 09:54:08 +02:00
braille.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
console_cmdline.h printk: Add match_devname_and_update_preferred_console() 2024-07-04 15:41:44 +02:00
index.c kernel/printk/index.c: fix memory leak with using debugfs_lookup() 2023-02-03 10:42:02 +01:00
internal.h printk: Add helper for flush type logic 2024-08-21 14:56:49 +02:00
Makefile Revert "printk: Save console options for add_preferred_console_match()" 2024-06-25 07:58:10 +02:00
nbcon.c printk: Add helper for flush type logic 2024-08-21 14:56:49 +02:00
printk_ringbuffer.c printk: ringbuffer: Skip non-finalized records in panic 2024-02-07 17:23:18 +01:00
printk_ringbuffer.h printk: nbcon: Do not rely on proxy headers 2024-08-21 14:56:23 +02:00
printk_safe.c printk: Add is_printk_legacy_deferred() 2024-08-21 14:56:24 +02:00
printk.c printk: Add helper for flush type logic 2024-08-21 14:56:49 +02:00
sysctl.c sysctl: treewide: constify the ctl_table argument of proc_handlers 2024-07-24 20:59:29 +02:00