The ring buffer resizing and resetting relies on a schedule RCU action. The buffers are disabled, a synchronize_sched() is called and then the resize or reset takes place. But this only works if the disabling of the buffers are within the preempt disabled section, otherwise a window exists that the buffers can be written to while a reset or resize takes place.
Showing the changes to kernel/trace (1 of 1 file). Show all
Unified · Split
| @@ -2232,12 +2232,12 @@ ring_buffer_lock_reserve(struct ring_buffer *buffer, unsigned long length) · 2231 unmodified lines | ||
| 2232 | 2232 | if (ring_buffer_flags != RB_BUFFERS_ON) |
| 2233 | 2233 | return NULL; |
| 2234 | 2234 | |
| 2235 | − if (atomic_read(&buffer->record_disabled)) | |
| 2236 | − return NULL; | |
| 2237 | − | |
| 2238 | 2235 | /* If we are tracing schedule, we don't want to recurse */ |
| 2239 | 2236 | resched = ftrace_preempt_disable(); |
| 2240 | 2237 | |
| 2238 | + if (atomic_read(&buffer->record_disabled)) | |
| 2239 | + goto out_nocheck; | |
| 2240 | + | |
| 2241 | 2241 | if (trace_recursive_lock()) |
| 2242 | 2242 | goto out_nocheck; |
| 2243 | 2243 | |
| @@ -2469,11 +2469,11 @@ int ring_buffer_write(struct ring_buffer *buffer, · 225 unmodified lines | ||
| 2469 | 2469 | if (ring_buffer_flags != RB_BUFFERS_ON) |
| 2470 | 2470 | return -EBUSY; |
| 2471 | 2471 | |
| 2472 | − if (atomic_read(&buffer->record_disabled)) | |
| 2473 | − return -EBUSY; | |
| 2474 | − | |
| 2475 | 2472 | resched = ftrace_preempt_disable(); |
| 2476 | 2473 | |
| 2474 | + if (atomic_read(&buffer->record_disabled)) | |
| 2475 | + goto out; | |
| 2476 | + | |
| 2477 | 2477 | cpu = raw_smp_processor_id(); |
| 2478 | 2478 | |
| 2479 | 2479 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |