]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ring-buffer: Use flush_kernel_vmap_range() over flush_dcache_folio()
authorSteven Rostedt <rostedt@goodmis.org>
Wed, 2 Apr 2025 14:49:07 +0000 (10:49 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 20 Apr 2025 08:18:26 +0000 (10:18 +0200)
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: stable@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Vincent Donnefort <vdonnefort@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Mike Rapoport <rppt@kernel.org>
Link: https://lore.kernel.org/20250402144953.920792197@goodmis.org
Fixes: 117c39200d9d7 ("ring-buffer: Introducing ring-buffer mapping functions");
Suggested-by: Jann Horn <jannh@google.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/trace/ring_buffer.c

index fb954a8b7a8b144ff46544f074ac5bae07648cd0..dbb47d7a8def6c3aa00b545e7bc27d8d131e1828 100644 (file)
@@ -5994,7 +5994,7 @@ static void rb_update_meta_page(struct ring_buffer_per_cpu *cpu_buffer)
        meta->read = cpu_buffer->read;
 
        /* Some archs do not have data cache coherency between kernel and user-space */
-       flush_dcache_folio(virt_to_folio(cpu_buffer->meta_page));
+       flush_kernel_vmap_range(cpu_buffer->meta_page, PAGE_SIZE);
 }
 
 static void
@@ -7309,7 +7309,8 @@ consume:
 
 out:
        /* Some archs do not have data cache coherency between kernel and user-space */
-       flush_dcache_folio(virt_to_folio(cpu_buffer->reader_page->page));
+       flush_kernel_vmap_range(cpu_buffer->reader_page->page,
+                               buffer->subbuf_size + BUF_PAGE_HDR_SIZE);
 
        rb_update_meta_page(cpu_buffer);