Skip to content

Commit 3d2353d

Browse files
committed
ring-buffer: Don't deactivate the ring buffer on failed iterator reads
If the function tracer is running and the trace file is read (which uses the ring buffer iterator), the iterator can get in sync with the writes, and caues it to fail to find a page with content it can read three times. This causes a warning and deactivation of the ring buffer code. Looking at the other cases of failure to get an event, it appears that there's a chance that the writer could cause them too. Since the iterator is a "best effort" to read the ring buffer if there's an active writer (the consumer reader is made for this case "see trace_pipe"), if it fails to get an event after three tries, simply give up and return NULL. Don't warn, nor disable the ring buffer on this failure. Link: https://lore.kernel.org/r/20200429090508.GG5770@shao2-debian Reported-by: kernel test robot <lkp@intel.com> Fixes: ff84c50 ("ring-buffer: Do not die if rb_iter_peek() fails more than thrice") Tested-by: Sven Schnelle <svens@linux.ibm.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 59566b0 commit 3d2353d

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

‎kernel/trace/ring_buffer.c‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,7 +4034,6 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
40344034
struct ring_buffer_per_cpu *cpu_buffer;
40354035
struct ring_buffer_event *event;
40364036
int nr_loops = 0;
4037-
bool failed = false;
40384037

40394038
if (ts)
40404039
*ts = 0;
@@ -4056,19 +4055,14 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
40564055
return NULL;
40574056

40584057
/*
4059-
* We repeat when a time extend is encountered or we hit
4060-
* the end of the page. Since the time extend is always attached
4061-
* to a data event, we should never loop more than three times.
4062-
* Once for going to next page, once on time extend, and
4063-
* finally once to get the event.
4064-
* We should never hit the following condition more than thrice,
4065-
* unless the buffer is very small, and there's a writer
4066-
* that is causing the reader to fail getting an event.
4058+
* As the writer can mess with what the iterator is trying
4059+
* to read, just give up if we fail to get an event after
4060+
* three tries. The iterator is not as reliable when reading
4061+
* the ring buffer with an active write as the consumer is.
4062+
* Do not warn if the three failures is reached.
40674063
*/
4068-
if (++nr_loops > 3) {
4069-
RB_WARN_ON(cpu_buffer, !failed);
4064+
if (++nr_loops > 3)
40704065
return NULL;
4071-
}
40724066

40734067
if (rb_per_cpu_empty(cpu_buffer))
40744068
return NULL;
@@ -4079,10 +4073,8 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
40794073
}
40804074

40814075
event = rb_iter_head_event(iter);
4082-
if (!event) {
4083-
failed = true;
4076+
if (!event)
40844077
goto again;
4085-
}
40864078

40874079
switch (event->type_len) {
40884080
case RINGBUF_TYPE_PADDING:

0 commit comments

Comments
 (0)