From: John Ogness <john.ogness@linutronix.de> Date: Thu, 14 Dec 2023 14:38:42 +0000 Subject: [PATCH 17/46] printk: nbcon: Add helper to assign priority based on CPU state Add a helper function to use the current state of the CPU to determine which priority to assign to the printing context. The EMERGENCY priority handling is added in a follow-up commit. It will use a per-CPU variable. Note: nbcon_driver_try_acquire(), which is used by console drivers to acquire the nbcon console for non-printing activities, will always use NORMAL priority. Signed-off-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> --- kernel/printk/internal.h | 2 ++ kernel/printk/nbcon.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) @ kernel/printk/internal.h:87 @ void nbcon_seq_force(struct console *con bool nbcon_alloc(struct console *con); void nbcon_init(struct console *con, u64 init_seq); void nbcon_free(struct console *con); +enum nbcon_prio nbcon_get_default_prio(void); /* * Check if the given console is currently capable and allowed to print @ kernel/printk/internal.h:142 @ static inline void nbcon_seq_force(struc static inline bool nbcon_alloc(struct console *con) { return false; } static inline void nbcon_init(struct console *con, u64 init_seq) { } static inline void nbcon_free(struct console *con) { } +static inline enum nbcon_prio nbcon_get_default_prio(void) { return NBCON_PRIO_NONE; } static inline bool console_is_usable(struct console *con, short flags) { return false; } --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @ kernel/printk/internal.h:941 @ static bool nbcon_emit_next_record(struc } /** + * nbcon_get_default_prio - The appropriate nbcon priority to use for nbcon + * printing on the current CPU + * + * Context: Any context which could not be migrated to another CPU. + * Return: The nbcon_prio to use for acquiring an nbcon console in this + * context for printing. + */ +enum nbcon_prio nbcon_get_default_prio(void) +{ + if (this_cpu_in_panic()) + return NBCON_PRIO_PANIC; + + return NBCON_PRIO_NORMAL; +} + +/** * nbcon_alloc - Allocate buffers needed by the nbcon console * @con: Console to allocate buffers for *