Skip to content

Commit ae415fa

Browse files
committed
ring-buffer: Do no reuse reader page if still in use
To free the reader page that is allocated with ring_buffer_alloc_read_page(), ring_buffer_free_read_page() must be called. For faster performance, this page can be reused by the ring buffer to avoid having to free and allocate new pages. The issue arises when the page is used with a splice pipe into the networking code. The networking code may up the page counter for the page, and keep it active while sending it is queued to go to the network. The incrementing of the page ref does not prevent it from being reused in the ring buffer, and this can cause the page that is being sent out to the network to be modified before it is sent by reading new data. Add a check to the page ref counter, and only reuse the page if it is not being used anywhere else. Cc: [email protected] Fixes: 73a757e ("ring-buffer: Return reader page back into existing ring buffer") Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 6b7e633 commit ae415fa

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

kernel/trace/ring_buffer.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4404,8 +4404,13 @@ void ring_buffer_free_read_page(struct ring_buffer *buffer, int cpu, void *data)
44044404
{
44054405
struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
44064406
struct buffer_data_page *bpage = data;
4407+
struct page *page = virt_to_page(bpage);
44074408
unsigned long flags;
44084409

4410+
/* If the page is still in use someplace else, we can't reuse it */
4411+
if (page_ref_count(page) > 1)
4412+
goto out;
4413+
44094414
local_irq_save(flags);
44104415
arch_spin_lock(&cpu_buffer->lock);
44114416

@@ -4417,6 +4422,7 @@ void ring_buffer_free_read_page(struct ring_buffer *buffer, int cpu, void *data)
44174422
arch_spin_unlock(&cpu_buffer->lock);
44184423
local_irq_restore(flags);
44194424

4425+
out:
44204426
free_page((unsigned long)bpage);
44214427
}
44224428
EXPORT_SYMBOL_GPL(ring_buffer_free_read_page);

0 commit comments

Comments
 (0)