Merge tag 'trace-ring-buffer-v7.2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull ring-buffer updates from Steven Rostedt

 - Do not invalidate entire buffer for invalid sub-buffers

   For the persistent ring buffer, if one sub-buffer is found to be
   invalid, it invalidates the entire per CPU ring buffer. This can lose
   a lot of valuable data if there's some corruption with the writes to
   the buffer not syncing properly on a hard crash. Instead, if a
   sub-buffer is found to be invalid, simply zero it out and mark it for
   "missed events".

   When the persistent ring buffer is read and a sub-buffer that was
   cleared due to being invalid on boot up is discovered, the output
   will show "[LOST EVENTS]" to let the user know that events were
   missing at that location. Displaying the events from valid buffers
   can still be useful.

 - Add a test to be able to test corrupted sub-buffers

   If a persistent ring buffer is created as "ptraingtest" and the new
   config that adds the test is enabled, when a panic happens, the
   kernel will randomly corrupt one of the per CPU ring buffers. On boot
   up, the sub-buffers with the corruption should be cleared and
   flagged. When reading this buffer, the missed events should should
   [LOST EVENTS].

 - Add commit number in the sub-buffer meta debug info

   The commit is used to know the content of a meta page. Add it to the
   buffer_meta file that is shown for each per CPU buffer.

 - Clean up the persistent ring buffer validation code

   Add some helper functions and make variable names more consistent.

* tag 'trace-ring-buffer-v7.2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
  ring-buffer: Better comment the use of RB_MISSED_EVENTS
  ring-buffer: Show persistent buffer dropped events in trace_pipe file
  ring-buffer: Show persistent buffer dropped events in trace file
  ring-buffer: Have dropped subbuffers be persistent across reboots
  ring-buffer: Cleanup buffer_data_page related code
  ring-buffer: Cleanup persistent ring buffer validation
  ring-buffer: Show commit numbers in buffer_meta file
  ring-buffer: Add persistent ring buffer invalid-page inject test
  ring-buffer: Skip invalid sub-buffers when rewinding persistent ring buffer
  ring-buffer: Skip invalid sub-buffers when validating persistent ring buffer
This commit is contained in:
Linus Torvalds
2026-06-18 21:23:22 -07:00
4 changed files with 418 additions and 182 deletions

View File

@@ -238,6 +238,7 @@ int ring_buffer_subbuf_size_get(struct trace_buffer *buffer);
enum ring_buffer_flags {
RB_FL_OVERWRITE = 1 << 0,
RB_FL_TESTING = 1 << 1,
};
#ifdef CONFIG_RING_BUFFER

View File

@@ -1202,6 +1202,40 @@ config RING_BUFFER_VALIDATE_TIME_DELTAS
Only say Y if you understand what this does, and you
still want it enabled. Otherwise say N
config RING_BUFFER_PERSISTENT_INJECT
bool "Enable persistent ring buffer error injection test"
depends on RING_BUFFER
help
This option will have the kernel check if the persistent ring
buffer is named "ptracingtest". and if so, it will corrupt some
of its pages on a kernel panic. This is used to test if the
persistent ring buffer can recover from some of its sub-buffers
being corrupted.
To use this, boot a kernel with a "ptracingtest" persistent
ring buffer, e.g.
reserve_mem=20M:2M:trace trace_instance=ptracingtest@trace panic=1
And after the 1st boot, run the following commands:
cd /sys/kernel/tracing/instances/ptracingtest
echo 1 > events/enable
echo 1 > tracing_on
sleep 3
echo c > /proc/sysrq-trigger
After the panic message, the kernel will reboot and will show
the test results in the console output.
Note that events for the test ring buffer needs to be enabled
prior to crashing the kernel so that the ring buffer has content
that the test will corrupt.
As the test will corrupt events in the "ptracingtest" persistent
ring buffer, it should not be used for any other purpose other
than this test.
If unsure, say N
config MMIOTRACE_TEST
tristate "Test module for mmiotrace"
depends on MMIOTRACE && m

File diff suppressed because it is too large Load Diff

View File

@@ -8380,6 +8380,8 @@ static void setup_trace_scratch(struct trace_array *tr,
memset(tscratch, 0, size);
}
#define TRACE_TEST_PTRACING_NAME "ptracingtest"
int allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int size)
{
enum ring_buffer_flags rb_flags;
@@ -8391,6 +8393,8 @@ int allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int
buf->tr = tr;
if (tr->range_addr_start && tr->range_addr_size) {
if (tr->name && !strcmp(tr->name, TRACE_TEST_PTRACING_NAME))
rb_flags |= RB_FL_TESTING;
/* Add scratch buffer to handle 128 modules */
buf->buffer = ring_buffer_alloc_range(size, rb_flags, 0,
tr->range_addr_start,