Skip to content

Commit

Permalink
printk: report dropping of messages from logbuf
Browse files Browse the repository at this point in the history
If the log ring buffer becomes full, we silently overwrite old messages
with new data.  console_unlock will detect this case and fast-forward the
console_* pointers to skip over the corrupted data, but nothing will be
reported to the user.

This patch hijacks the first valid log message after detecting that we
dropped messages and prefixes it with a note detailing how many messages
were dropped.  For long (~1000 char) messages, this will result in some
truncation of the real message, but given that we're dropping things
anyway, that doesn't seem to be the end of the world.

Signed-off-by: Will Deacon <[email protected]>
Acked-by: Peter Zijlstra <[email protected]>
Cc: Kay Sievers <[email protected]>
Cc: Jan Kara <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
wildea01 authored and torvalds committed Jun 4, 2014
1 parent 6e099f5 commit 84b5ec8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions kernel/printk/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2157,10 +2157,15 @@ void console_unlock(void)
}

if (console_seq < log_first_seq) {
len = sprintf(text, "** %u printk messages dropped ** ",
(unsigned)(log_first_seq - console_seq));

/* messages are gone, move to first one */
console_seq = log_first_seq;
console_idx = log_first_idx;
console_prev = 0;
} else {
len = 0;
}
skip:
if (console_seq == log_next_seq)
Expand All @@ -2185,8 +2190,8 @@ void console_unlock(void)
}

level = msg->level;
len = msg_print_text(msg, console_prev, false,
text, sizeof(text));
len += msg_print_text(msg, console_prev, false,
text + len, sizeof(text) - len);
console_idx = log_next(console_idx);
console_seq++;
console_prev = msg->flags;
Expand Down

0 comments on commit 84b5ec8

Please sign in to comment.