Skip to content

Commit 84b5ec8

Browse files
wildea01torvalds
authored andcommitted
printk: report dropping of messages from logbuf
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 <will.deacon@arm.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Cc: Kay Sievers <kay@vrfy.org> Cc: Jan Kara <jack@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6e099f5 commit 84b5ec8

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎kernel/printk/printk.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,10 +2157,15 @@ void console_unlock(void)
21572157
}
21582158

21592159
if (console_seq < log_first_seq) {
2160+
len = sprintf(text, "** %u printk messages dropped ** ",
2161+
(unsigned)(log_first_seq - console_seq));
2162+
21602163
/* messages are gone, move to first one */
21612164
console_seq = log_first_seq;
21622165
console_idx = log_first_idx;
21632166
console_prev = 0;
2167+
} else {
2168+
len = 0;
21642169
}
21652170
skip:
21662171
if (console_seq == log_next_seq)
@@ -2185,8 +2190,8 @@ void console_unlock(void)
21852190
}
21862191

21872192
level = msg->level;
2188-
len = msg_print_text(msg, console_prev, false,
2189-
text, sizeof(text));
2193+
len += msg_print_text(msg, console_prev, false,
2194+
text + len, sizeof(text) - len);
21902195
console_idx = log_next(console_idx);
21912196
console_seq++;
21922197
console_prev = msg->flags;

0 commit comments

Comments
 (0)