Skip to content

Commit 659f451

Browse files
Steven Rostedtrostedt
Steven Rostedt
authored andcommitted
ring-buffer: Add integrity check at end of iter read
There use to be ring buffer integrity checks after updating the size of the ring buffer. But now that the ring buffer can modify the size while the system is running, the integrity checks were removed, as they require the ring buffer to be disabed to perform the check. Move the integrity check to the reading of the ring buffer via the iterator reads (the "trace" file). As reading via an iterator requires disabling the ring buffer, it is a perfect place to have it. If the ring buffer happens to be disabled when updating the size, we still perform the integrity check. Cc: Vaibhav Nagarnaik <[email protected]> Signed-off-by: Steven Rostedt <[email protected]>
1 parent 5040b4b commit 659f451

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

kernel/trace/ring_buffer.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,29 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
15991599
}
16001600

16011601
out:
1602+
/*
1603+
* The ring buffer resize can happen with the ring buffer
1604+
* enabled, so that the update disturbs the tracing as little
1605+
* as possible. But if the buffer is disabled, we do not need
1606+
* to worry about that, and we can take the time to verify
1607+
* that the buffer is not corrupt.
1608+
*/
1609+
if (atomic_read(&buffer->record_disabled)) {
1610+
atomic_inc(&buffer->record_disabled);
1611+
/*
1612+
* Even though the buffer was disabled, we must make sure
1613+
* that it is truly disabled before calling rb_check_pages.
1614+
* There could have been a race between checking
1615+
* record_disable and incrementing it.
1616+
*/
1617+
synchronize_sched();
1618+
for_each_buffer_cpu(buffer, cpu) {
1619+
cpu_buffer = buffer->buffers[cpu];
1620+
rb_check_pages(cpu_buffer);
1621+
}
1622+
atomic_dec(&buffer->record_disabled);
1623+
}
1624+
16021625
mutex_unlock(&buffer->mutex);
16031626
return size;
16041627

@@ -3750,6 +3773,12 @@ ring_buffer_read_finish(struct ring_buffer_iter *iter)
37503773
{
37513774
struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer;
37523775

3776+
/*
3777+
* Ring buffer is disabled from recording, here's a good place
3778+
* to check the integrity of the ring buffer.
3779+
*/
3780+
rb_check_pages(cpu_buffer);
3781+
37533782
atomic_dec(&cpu_buffer->record_disabled);
37543783
atomic_dec(&cpu_buffer->buffer->resize_disabled);
37553784
kfree(iter);

0 commit comments

Comments
 (0)