Skip to content

Commit 8b1742c

Browse files
sergey-senozhatskypmladek
authored andcommitted
printk: remove zap_locks() function
We use printk-safe now which makes printk-recursion detection code in vprintk_emit() unreachable. The tricky thing here is that, apart from detecting and reporting printk recursions, that code also used to zap_locks() in case of panic() from the same CPU. However, zap_locks() does not look to be needed anymore: 1) Since commit 08d7865 ("panic: release stale console lock to always get the logbuf printed out") panic flushing of `logbuf' to console ignores the state of `console_sem' by doing panic() console_trylock(); console_unlock(); 2) Since commit cf9b110 ("printk/nmi: flush NMI messages on the system panic") panic attempts to zap the `logbuf_lock' spin_lock to successfully flush nmi messages to `logbuf'. Basically, it seems that we either already do what zap_locks() used to do but in other places or we ignore the state of the lock. The only reaming difference is that we don't re-init the console semaphore in printk_safe_flush_on_panic(), but this is not necessary because we don't call console drivers from printk_safe_flush_on_panic() due to the fact that we are using a deferred printk() version (as was suggested by Petr Mladek). Link: http://lkml.kernel.org/r/20161227141611.940-8-sergey.senozhatsky@gmail.com Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Jan Kara <jack@suse.cz> Cc: Tejun Heo <tj@kernel.org> Cc: Calvin Owens <calvinowens@fb.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Peter Hurley <peter@hurleysoftware.com> Cc: linux-kernel@vger.kernel.org Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Signed-off-by: Petr Mladek <pmladek@suse.com>
1 parent f975237 commit 8b1742c

File tree

1 file changed

+0
-61
lines changed

1 file changed

+0
-61
lines changed

kernel/printk/printk.c

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,28 +1557,6 @@ static void call_console_drivers(int level,
15571557
}
15581558
}
15591559

1560-
/*
1561-
* Zap console related locks when oopsing.
1562-
* To leave time for slow consoles to print a full oops,
1563-
* only zap at most once every 30 seconds.
1564-
*/
1565-
static void zap_locks(void)
1566-
{
1567-
static unsigned long oops_timestamp;
1568-
1569-
if (time_after_eq(jiffies, oops_timestamp) &&
1570-
!time_after(jiffies, oops_timestamp + 30 * HZ))
1571-
return;
1572-
1573-
oops_timestamp = jiffies;
1574-
1575-
debug_locks_off();
1576-
/* If a crash is occurring, make sure we can't deadlock */
1577-
raw_spin_lock_init(&logbuf_lock);
1578-
/* And make sure that we print immediately */
1579-
sema_init(&console_sem, 1);
1580-
}
1581-
15821560
int printk_delay_msec __read_mostly;
15831561

15841562
static inline void printk_delay(void)
@@ -1688,17 +1666,13 @@ asmlinkage int vprintk_emit(int facility, int level,
16881666
const char *dict, size_t dictlen,
16891667
const char *fmt, va_list args)
16901668
{
1691-
static bool recursion_bug;
16921669
static char textbuf[LOG_LINE_MAX];
16931670
char *text = textbuf;
16941671
size_t text_len = 0;
16951672
enum log_flags lflags = 0;
16961673
unsigned long flags;
1697-
int this_cpu;
16981674
int printed_len = 0;
16991675
bool in_sched = false;
1700-
/* cpu currently holding logbuf_lock in this function */
1701-
static unsigned int logbuf_cpu = UINT_MAX;
17021676

17031677
if (level == LOGLEVEL_SCHED) {
17041678
level = LOGLEVEL_DEFAULT;
@@ -1709,42 +1683,8 @@ asmlinkage int vprintk_emit(int facility, int level,
17091683
printk_delay();
17101684

17111685
printk_safe_enter_irqsave(flags);
1712-
this_cpu = smp_processor_id();
1713-
1714-
/*
1715-
* Ouch, printk recursed into itself!
1716-
*/
1717-
if (unlikely(logbuf_cpu == this_cpu)) {
1718-
/*
1719-
* If a crash is occurring during printk() on this CPU,
1720-
* then try to get the crash message out but make sure
1721-
* we can't deadlock. Otherwise just return to avoid the
1722-
* recursion and return - but flag the recursion so that
1723-
* it can be printed at the next appropriate moment:
1724-
*/
1725-
if (!oops_in_progress && !lockdep_recursing(current)) {
1726-
recursion_bug = true;
1727-
printk_safe_exit_irqrestore(flags);
1728-
return 0;
1729-
}
1730-
zap_locks();
1731-
}
1732-
17331686
/* This stops the holder of console_sem just where we want him */
17341687
raw_spin_lock(&logbuf_lock);
1735-
logbuf_cpu = this_cpu;
1736-
1737-
if (unlikely(recursion_bug)) {
1738-
static const char recursion_msg[] =
1739-
"BUG: recent printk recursion!";
1740-
1741-
recursion_bug = false;
1742-
/* emit KERN_CRIT message */
1743-
printed_len += log_store(0, 2, LOG_PREFIX|LOG_NEWLINE, 0,
1744-
NULL, 0, recursion_msg,
1745-
strlen(recursion_msg));
1746-
}
1747-
17481688
/*
17491689
* The printf needs to come first; we need the syslog
17501690
* prefix which might be passed-in as a parameter.
@@ -1787,7 +1727,6 @@ asmlinkage int vprintk_emit(int facility, int level,
17871727

17881728
printed_len += log_output(facility, level, lflags, dict, dictlen, text, text_len);
17891729

1790-
logbuf_cpu = UINT_MAX;
17911730
raw_spin_unlock(&logbuf_lock);
17921731
printk_safe_exit_irqrestore(flags);
17931732

0 commit comments

Comments
 (0)