diff options
Diffstat (limited to 'kernel/printk/printk.c')
| -rw-r--r-- | kernel/printk/printk.c | 23 | 
1 files changed, 22 insertions, 1 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 02ca827b8fac..1888f6a3b694 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-only  /*   *  linux/kernel/printk.c   * @@ -86,6 +87,12 @@ static DEFINE_SEMAPHORE(console_sem);  struct console *console_drivers;  EXPORT_SYMBOL_GPL(console_drivers); +/* + * System may need to suppress printk message under certain + * circumstances, like after kernel panic happens. + */ +int __read_mostly suppress_printk; +  #ifdef CONFIG_LOCKDEP  static struct lockdep_map console_lock_dep_map = {  	.name = "console_lock" @@ -1943,6 +1950,10 @@ asmlinkage int vprintk_emit(int facility, int level,  	unsigned long flags;  	u64 curr_log_seq; +	/* Suppress unimportant messages after panic happens */ +	if (unlikely(suppress_printk)) +		return 0; +  	if (level == LOGLEVEL_SCHED) {  		level = LOGLEVEL_DEFAULT;  		in_sched = true; @@ -2525,10 +2536,11 @@ void console_unblank(void)  /**   * console_flush_on_panic - flush console content on panic + * @mode: flush all messages in buffer or just the pending ones   *   * Immediately output all pending messages no matter what.   */ -void console_flush_on_panic(void) +void console_flush_on_panic(enum con_flush_mode mode)  {  	/*  	 * If someone else is holding the console lock, trylock will fail @@ -2539,6 +2551,15 @@ void console_flush_on_panic(void)  	 */  	console_trylock();  	console_may_schedule = 0; + +	if (mode == CONSOLE_REPLAY_ALL) { +		unsigned long flags; + +		logbuf_lock_irqsave(flags); +		console_seq = log_first_seq; +		console_idx = log_first_idx; +		logbuf_unlock_irqrestore(flags); +	}  	console_unlock();  }  |