ring_buffer: use list_replace() in rb_get_reader_page()
Subsystems (2)
PATCH 1/1 ring_buffer: use list_replace() in rb_get_reader_page()
Use list_replace() to splice list in rb_get_reader_page()
[ Impact: cleanup ]
--- kernel/trace/ring_buffer.c | 12 ++---------- 1 files changed, 2 insertions(+), 10 deletions(-)
kernel/trace/ring_buffer.c +2 -10
@@ -2179,22 +2179,14 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)if (cpu_buffer->commit_page == cpu_buffer->reader_page) goto out; -/* -* Splice the empty reader page into the list around the head. -* Reset the reader page to size zero. -*/ - +/* Reset the reader page to size zero */ reader = cpu_buffer->head_page; - cpu_buffer->reader_page->list.next = reader->list.next; - cpu_buffer->reader_page->list.prev = reader->list.prev; -local_set (&cpu_buffer->reader_page->write,0 );local_set (&cpu_buffer->reader_page->entries,0 );local_set (&cpu_buffer->reader_page->page->commit,0 );/* Make the reader page now replace the head */ - reader->list.prev->next = &cpu_buffer->reader_page->list; - reader->list.next->prev = &cpu_buffer->reader_page->list; +list_replace (&reader->list, &cpu_buffer->reader_page->list);/* * If the tail is on the reader, then we must set the head
Signature · 1 line
1.6.1.2
Steven Rostedt
maintainerQuoted 1 line · Xiao Guangrong
Use
list_replace()to splice list inrb_get_reader_page()
This code is very sensitive to change. But I think you actually uncovered a potential bug. There was a reason that I did not use list_replace, and it is because we need memory barriers here. And that is the bug you uncovered. We don't have memory barriers.
Ah, it's not a bug (yet). When we make this lockless we will need to add memory barriers here. Once reader->list.prev->next points to cpu_buffer->reader_page->list, the cpu_buffer->reader_page->list had better have both next and prev visible.
If we add this code now, we will just have to remove it when it goes lockless.
-- Steve
Quoted 42 lines
[ Impact: cleanup ]
Signed-off-by Xiao Guangrong <[email protected]>--- kernel/trace/ring_buffer.c | 12 ++---------- 1 files changed, 2 insertions(+), 10 deletions(-)kernel/trace/ring_buffer.c +2
-10@@ -2179,22 +2179,14 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)if (cpu_buffer->commit_page == cpu_buffer->reader_page) goto out; -/* -* Splice the empty reader page into the list around the head. -* Reset the reader page to size zero. -*/ - +/* Reset the reader page to size zero */ reader = cpu_buffer->head_page; - cpu_buffer->reader_page->list.next = reader->list.next; - cpu_buffer->reader_page->list.prev = reader->list.prev; -local_set (&cpu_buffer->reader_page->write,0 );local_set (&cpu_buffer->reader_page->entries,0 );local_set (&cpu_buffer->reader_page->page->commit,0 );/* Make the reader page now replace the head */ - reader->list.prev->next = &cpu_buffer->reader_page->list; - reader->list.next->prev = &cpu_buffer->reader_page->list; +list_replace (&reader->list, &cpu_buffer->reader_page->list);/* * If the tail is on the reader, then we must set the head Signature · 1 line
1.6.1.2