Skip to content

Commit c0386f8

Browse files
rostedtjfvogel
authored andcommitted
ring-buffer: Use flush_kernel_vmap_range() over flush_dcache_folio()
commit e4d4b8670c44cdd22212cab3c576e2d317efa67c upstream. Some architectures do not have data cache coherency between user and kernel space. For these architectures, the cache needs to be flushed on both the kernel and user addresses so that user space can see the updates the kernel has made. Instead of using flush_dcache_folio() and playing with virt_to_folio() within the call to that function, use flush_kernel_vmap_range() which takes the virtual address and does the work for those architectures that need it. This also fixes a bug where the flush of the reader page only flushed one page. If the sub-buffer order is 1 or more, where the sub-buffer size would be greater than a page, it would miss the rest of the sub-buffer content, as the "reader page" is not just a page, but the size of a sub-buffer. Link: https://lore.kernel.org/all/CAG48ez3w0my4Rwttbc5tEbNsme6tc0mrSN95thjXUFaJ3aQ6SA@mail.gmail.com/ Cc: [email protected] Cc: Linus Torvalds <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Vincent Donnefort <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Mike Rapoport <[email protected]> Link: https://lore.kernel.org/[email protected] Fixes: 117c392 ("ring-buffer: Introducing ring-buffer mapping functions"); Suggested-by: Jann Horn <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 92ca7270fe5eae90015a54a818df46f7f7886a41) Signed-off-by: Jack Vogel <[email protected]>
1 parent f27b16f commit c0386f8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kernel/trace/ring_buffer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5994,7 +5994,7 @@ static void rb_update_meta_page(struct ring_buffer_per_cpu *cpu_buffer)
59945994
meta->read = cpu_buffer->read;
59955995

59965996
/* Some archs do not have data cache coherency between kernel and user-space */
5997-
flush_dcache_folio(virt_to_folio(cpu_buffer->meta_page));
5997+
flush_kernel_vmap_range(cpu_buffer->meta_page, PAGE_SIZE);
59985998
}
59995999

60006000
static void
@@ -7309,7 +7309,8 @@ int ring_buffer_map_get_reader(struct trace_buffer *buffer, int cpu)
73097309

73107310
out:
73117311
/* Some archs do not have data cache coherency between kernel and user-space */
7312-
flush_dcache_folio(virt_to_folio(cpu_buffer->reader_page->page));
7312+
flush_kernel_vmap_range(cpu_buffer->reader_page->page,
7313+
buffer->subbuf_size + BUF_PAGE_HDR_SIZE);
73137314

73147315
rb_update_meta_page(cpu_buffer);
73157316

0 commit comments

Comments
 (0)