diff options
Diffstat (limited to '')
-rw-r--r-- | debian/patches-rt/0025-printk-nbcon-Implement-emergency-sections.patch (renamed from debian/patches-rt/0028-printk-nbcon-Implement-emergency-sections.patch) | 116 |
1 files changed, 99 insertions, 17 deletions
diff --git a/debian/patches-rt/0028-printk-nbcon-Implement-emergency-sections.patch b/debian/patches-rt/0025-printk-nbcon-Implement-emergency-sections.patch index f3a05868e7..44327c280a 100644 --- a/debian/patches-rt/0028-printk-nbcon-Implement-emergency-sections.patch +++ b/debian/patches-rt/0025-printk-nbcon-Implement-emergency-sections.patch @@ -1,7 +1,7 @@ From: Thomas Gleixner <tglx@linutronix.de> Date: Mon, 11 Sep 2023 15:21:57 +0000 -Subject: [PATCH 28/48] printk: nbcon: Implement emergency sections -Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/6.8/older/patches-6.8.2-rt11.tar.xz +Subject: [PATCH 25/46] printk: nbcon: Implement emergency sections +Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/6.9/older/patches-6.9-rt5.tar.xz In emergency situations (something has gone wrong but the system continues to operate), usually important information @@ -38,28 +38,51 @@ Signed-off-by: John Ogness <john.ogness@linutronix.de> Signed-off-by: Thomas Gleixner (Intel) <tglx@linutronix.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> --- - include/linux/console.h | 4 ++ - kernel/printk/nbcon.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ - kernel/printk/printk.c | 13 ++++++- - 3 files changed, 98 insertions(+), 2 deletions(-) + include/linux/console.h | 6 ++ + kernel/printk/internal.h | 11 ++++ + kernel/printk/nbcon.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++ + kernel/printk/printk.c | 25 +++++----- + 4 files changed, 146 insertions(+), 12 deletions(-) --- a/include/linux/console.h +++ b/include/linux/console.h -@@ -559,10 +559,14 @@ static inline bool console_is_registered +@@ -553,10 +553,16 @@ static inline bool console_is_registered hlist_for_each_entry(con, &console_list, node) #ifdef CONFIG_PRINTK +extern void nbcon_cpu_emergency_enter(void); +extern void nbcon_cpu_emergency_exit(void); ++extern void nbcon_cpu_emergency_flush(void); extern bool nbcon_can_proceed(struct nbcon_write_context *wctxt); extern bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt); extern bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt); #else +static inline void nbcon_cpu_emergency_enter(void) { } +static inline void nbcon_cpu_emergency_exit(void) { } ++static inline void nbcon_cpu_emergency_flush(void) { } static inline bool nbcon_can_proceed(struct nbcon_write_context *wctxt) { return false; } static inline bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt) { return false; } static inline bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt) { return false; } +--- a/kernel/printk/internal.h ++++ b/kernel/printk/internal.h +@@ -153,6 +153,17 @@ static inline bool console_is_usable(str + + #endif /* CONFIG_PRINTK */ + ++extern bool have_boot_console; ++extern bool have_legacy_console; ++ ++/* ++ * Specifies if the console lock/unlock dance is needed for console ++ * printing. If @have_boot_console is true, the nbcon consoles will ++ * be printed serially along with the legacy consoles because nbcon ++ * consoles cannot print simultaneously with boot consoles. ++ */ ++#define printing_via_unlock (have_legacy_console || have_boot_console) ++ + extern struct printk_buffers printk_shared_pbufs; + + /** --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -936,6 +936,29 @@ static bool nbcon_emit_next_record(struc @@ -90,9 +113,9 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> +} + /** - * nbcon_atomic_emit_one - Print one record for an nbcon console using the - * write_atomic() callback -@@ -977,9 +1000,15 @@ static bool nbcon_atomic_emit_one(struct + * nbcon_get_default_prio - The appropriate nbcon priority to use for nbcon + * printing on the current CPU +@@ -946,9 +969,15 @@ static bool nbcon_emit_next_record(struc */ enum nbcon_prio nbcon_get_default_prio(void) { @@ -108,12 +131,12 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> return NBCON_PRIO_NORMAL; } -@@ -1147,6 +1176,60 @@ void nbcon_atomic_flush_unsafe(void) +@@ -1200,6 +1229,93 @@ void nbcon_atomic_flush_unsafe(void) } /** + * nbcon_cpu_emergency_enter - Enter an emergency section where printk() -+ * messages for that CPU are only stored ++ * messages for that CPU are only stored + * + * Upon exiting the emergency section, all stored messages are flushed. + * @@ -136,7 +159,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> + +/** + * nbcon_cpu_emergency_exit - Exit an emergency section and flush the -+ * stored messages ++ * stored messages + * + * Flushing only occurs when exiting all nesting for the CPU. + * @@ -149,16 +172,24 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> + + cpu_emergency_nesting = nbcon_get_cpu_emergency_nesting(); + -+ WARN_ON_ONCE(*cpu_emergency_nesting == 0); -+ ++ /* ++ * Flush the messages before enabling preemtion to see them ASAP. ++ * ++ * Reduce the risk of potential softlockup by using the ++ * flush_pending() variant which ignores messages added later. It is ++ * called before decrementing the counter so that the printing context ++ * for the emergency messages is NBCON_PRIO_EMERGENCY. ++ */ + if (*cpu_emergency_nesting == 1) { + nbcon_atomic_flush_pending(); + do_trigger_flush = true; + } + -+ /* Undo the nesting count of nbcon_cpu_emergency_enter(). */ + (*cpu_emergency_nesting)--; + ++ if (WARN_ON_ONCE(*cpu_emergency_nesting < 0)) ++ *cpu_emergency_nesting = 0; ++ + preempt_enable(); + + if (do_trigger_flush) @@ -166,12 +197,63 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> +} + +/** ++ * nbcon_cpu_emergency_flush - Explicitly flush consoles while ++ * within emergency context ++ * ++ * Both nbcon and legacy consoles are flushed. ++ * ++ * It should be used only when there are too many messages printed ++ * in emergency context, for example, printing backtraces of all ++ * CPUs or processes. It is typically needed when the watchdogs ++ * need to be touched as well. ++ */ ++void nbcon_cpu_emergency_flush(void) ++{ ++ /* The explicit flush is needed only in the emergency context. */ ++ if (*(nbcon_get_cpu_emergency_nesting()) == 0) ++ return; ++ ++ nbcon_atomic_flush_pending(); ++ ++ if (printing_via_unlock && !in_nmi()) { ++ if (console_trylock()) ++ console_unlock(); ++ } ++} ++ ++/** * nbcon_alloc - Allocate buffers needed by the nbcon console * @con: Console to allocate buffers for * --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c -@@ -2417,16 +2417,25 @@ asmlinkage int vprintk_emit(int facility +@@ -468,7 +468,7 @@ static DEFINE_MUTEX(syslog_lock); + * present, it is necessary to perform the console lock/unlock dance + * whenever console flushing should occur. + */ +-static bool have_legacy_console; ++bool have_legacy_console; + + /* + * Specifies if an nbcon console is registered. If nbcon consoles are present, +@@ -483,15 +483,7 @@ static bool have_nbcon_console; + * the console lock. This is because boot consoles and nbcon consoles may + * have mapped the same hardware. + */ +-static bool have_boot_console; +- +-/* +- * Specifies if the console lock/unlock dance is needed for console +- * printing. If @have_boot_console is true, the nbcon consoles will +- * be printed serially along with the legacy consoles because nbcon +- * consoles cannot print simultaneously with boot consoles. +- */ +-#define printing_via_unlock (have_legacy_console || have_boot_console) ++bool have_boot_console; + + #ifdef CONFIG_PRINTK + DECLARE_WAIT_QUEUE_HEAD(log_wait); +@@ -2412,16 +2404,25 @@ asmlinkage int vprintk_emit(int facility * printing of all remaining records to all consoles so that * this context can return as soon as possible. Hopefully * another printk() caller will take over the printing. |