Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Will Deacon and committed by
Linus Torvalds
84b5ec8a 6e099f55

+7 -2
+7 -2
kernel/printk/printk.c
··· 2157 2157 } 2158 2158 2159 2159 if (console_seq < log_first_seq) { 2160 + len = sprintf(text, "** %u printk messages dropped ** ", 2161 + (unsigned)(log_first_seq - console_seq)); 2162 + 2160 2163 /* messages are gone, move to first one */ 2161 2164 console_seq = log_first_seq; 2162 2165 console_idx = log_first_idx; 2163 2166 console_prev = 0; 2167 + } else { 2168 + len = 0; 2164 2169 } 2165 2170 skip: 2166 2171 if (console_seq == log_next_seq) ··· 2190 2185 } 2191 2186 2192 2187 level = msg->level; 2193 - len = msg_print_text(msg, console_prev, false, 2194 - text, sizeof(text)); 2188 + len += msg_print_text(msg, console_prev, false, 2189 + text + len, sizeof(text) - len); 2195 2190 console_idx = log_next(console_idx); 2196 2191 console_seq++; 2197 2192 console_prev = msg->flags;