Skip to contentSkip to conversation

printk: kmsg_dump: revert msg_print_text() workaround

PATCH In review John Ogness 2 participants 2 messages Jan 14, 2021 Printk

lore
Share & tools
lore

John Ogness

author maintainer
#0 lore raw

PATCH 1/1 printk: kmsg_dump: revert msg_print_text() workaround

The old msg_print_text() function only filled up to size-1 bytes of the buffer. A workaround for this quirky behavior was implemented with commit c9dccacfccc7 ("printk: Do not lose last line in kmsg buffer dump").

However, with commit 896fbe20b4e2 ("printk: use the lockless ringbuffer"), msg_print_text() was replaced by record_print_text(), which will fill the full buffer. Therefore, the workaround is now incorrectly assuming less data can fit into the buffer. Revert the workaround.

Fixes 896fbe20b4e2 ("printk: use the lockless ringbuffer")

---
This patch is on top of https://lkml.kernel.org/r/[email protected]
and possibly could be squashed into that patch. However I recommend
keeping them separate since they affect kmsg_dump_get_buffer() in
different ways.

 kernel/printk/printk.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/printk/printk.c +1 -2
index 848b56efc9d7..489b9330f7f7 100644
@@ -3433,8 +3433,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
 
 	/* move first record forward until length fits into the buffer */
 	seq = dumper->cur_seq;
-	while (l >= size && prb_read_valid_info(prb, seq,
-						&info, &line_count)) {
+	while (l > size && prb_read_valid_info(prb, seq, &info, &line_count)) {
 		if (r.info->seq >= dumper->next_seq)
 			break;
 		l -= get_record_print_text_size(&info, line_count, syslog, time);
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 10 lines · John Ogness

The old msg_print_text() function only filled up to size-1 bytes of the buffer. A workaround for this quirky behavior was implemented with commit c9dccacfccc7 ("printk: Do not lose last line in kmsg buffer dump").

However, with commit 896fbe20b4e2 ("printk: use the lockless ringbuffer"), msg_print_text() was replaced by,
which will fill the full buffer. Therefore, the workaround is now incorrectly assuming less data can fit into the buffer. Revert the workaround.

We should make record_print_text() behave the same as msg_print_text() behaved. There might be more users affected by this change and even in userspace :-(

Let's discuss it in the other thread
https://lore.kernel.org/lkml/[email protected]/

Best Regards,
Petr