ring-buffer: Update pages_touched to reflect persistent buffer content
authorSteven Rostedt <rostedt@goodmis.org>
Fri, 14 Feb 2025 17:35:12 +0000 (12:35 -0500)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Sat, 15 Feb 2025 19:00:59 +0000 (14:00 -0500)
The pages_touched field represents the number of subbuffers in the ring
buffer that have content that can be read. This is used in accounting of
"dirty_pages" and "buffer_percent" to allow the user to wait for the
buffer to be filled to a certain amount before it reads the buffer in
blocking mode.

The persistent buffer never updated this value so it was set to zero, and
this accounting would take it as it had no content. This would cause user
space to wait for content even though there's enough content in the ring
buffer that satisfies the buffer_percent.

Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Vincent Donnefort <vdonnefort@google.com>
Link: https://lore.kernel.org/20250214123512.0631436e@gandalf.local.home
Fixes: 5f3b6e839f3ce ("ring-buffer: Validate boot range memory events")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/ring_buffer.c

index 0419d41a2060433884b51d9816fb497a18d80019..bb6089c2951e502bd82a7803aa49b8f9e0da0acc 100644 (file)
@@ -1850,6 +1850,11 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
                                cpu_buffer->cpu);
                        goto invalid;
                }
+
+               /* If the buffer has content, update pages_touched */
+               if (ret)
+                       local_inc(&cpu_buffer->pages_touched);
+
                entries += ret;
                entry_bytes += local_read(&head_page->page->commit);
                local_set(&cpu_buffer->head_page->entries, ret);