Skip to content

Commit b1c4c67

Browse files
jognesspmladek
authored andcommitted
printk: ringbuffer: Skip non-finalized records in panic
Normally a reader will stop once reaching a non-finalized record. However, when a panic happens, writers from other CPUs (or an interrupted context on the panic CPU) may have been writing a record and were unable to finalize it. The panic CPU will reserve/commit/finalize its panic records, but these will be located after the non-finalized records. This results in panic() not flushing the panic messages. Extend _prb_read_valid() to skip over non-finalized records if on the panic CPU. Fixes: 896fbe2 ("printk: use the lockless ringbuffer") Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
1 parent ac7d784 commit b1c4c67

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

kernel/printk/printk_ringbuffer.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,10 @@ u64 prb_next_reserve_seq(struct printk_ringbuffer *rb)
20992099
*
21002100
* On failure @seq is updated to a record that is not yet available to the
21012101
* reader, but it will be the next record available to the reader.
2102+
*
2103+
* Note: When the current CPU is in panic, this function will skip over any
2104+
* non-existent/non-finalized records in order to allow the panic CPU
2105+
* to print any and all records that have been finalized.
21022106
*/
21032107
static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq,
21042108
struct printk_record *r, unsigned int *line_count)
@@ -2121,8 +2125,28 @@ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq,
21212125
(*seq)++;
21222126

21232127
} else {
2124-
/* Non-existent/non-finalized record. Must stop. */
2125-
return false;
2128+
/*
2129+
* Non-existent/non-finalized record. Must stop.
2130+
*
2131+
* For panic situations it cannot be expected that
2132+
* non-finalized records will become finalized. But
2133+
* there may be other finalized records beyond that
2134+
* need to be printed for a panic situation. If this
2135+
* is the panic CPU, skip this
2136+
* non-existent/non-finalized record unless it is
2137+
* at or beyond the head, in which case it is not
2138+
* possible to continue.
2139+
*
2140+
* Note that new messages printed on panic CPU are
2141+
* finalized when we are here. The only exception
2142+
* might be the last message without trailing newline.
2143+
* But it would have the sequence number returned
2144+
* by "prb_next_reserve_seq() - 1".
2145+
*/
2146+
if (this_cpu_in_panic() && ((*seq + 1) < prb_next_reserve_seq(rb)))
2147+
(*seq)++;
2148+
else
2149+
return false;
21262150
}
21272151
}
21282152

0 commit comments

Comments
 (0)