From nobody Fri Dec 19 17:35:59 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 796C61F7069; Wed, 2 Apr 2025 22:57:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743634651; cv=none; b=E672WPwrSwJVDisrSbqz5F5iB81D5PSnBjqdabCmkd9fjcUCYqHN6sOgwAA5o2o2CxqU1cIQHvj0FPZu38pXMiwmma6n/el0HQwmRgXpsWE4BY10K8UkgzXP6NIp5nCZAjhUqsjtRbyWSpqfLQ4GO6jHFLLcKLlRqMzPF5NOOGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743634651; c=relaxed/simple; bh=vGIq4dsFR4Rj0DOR4i84KnH+g25lukcU+8tDpHWA0Z8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=NRaK8lxE/3DXBwAiz4HdI58hH8Xq4x1ueUH9JXbWl1lPzsUWlxx2jPsWLkp9CSefU3NT1nDuenW6O7o68sMi+KLQLXe62bCkyND33iT70AoedC3iX6EuNB+GFAtqRW7Bsu+MwZo1lGKY/VFk/cWcI/QGIrH8jyYAqTNIW8GrWrM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5874AC4CEDD; Wed, 2 Apr 2025 22:57:31 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1u072Z-00000006Z2U-2cT5; Wed, 02 Apr 2025 18:58:35 -0400 Message-ID: <20250402225835.476356782@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 02 Apr 2025 18:57:39 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Linus Torvalds , Vincent Donnefort , Vlastimil Babka , Mike Rapoport , Jann Horn Subject: [for-linus][PATCH 4/4] ring-buffer: Use flush_kernel_vmap_range() over flush_dcache_folio() References: <20250402225735.849814084@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt 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/CAG48ez3w0my4Rwttbc5tEbNsme6tc0mrSN95thjX= UFaJ3aQ6SA@mail.gmail.com/ Cc: stable@vger.kernel.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Vincent Donnefort Cc: Vlastimil Babka Cc: Mike Rapoport Link: https://lore.kernel.org/20250402144953.920792197@goodmis.org Fixes: 117c39200d9d7 ("ring-buffer: Introducing ring-buffer mapping functio= ns"); Suggested-by: Jann Horn Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ring_buffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index f25966b3a1fc..d4b0f7b55cce 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -6016,7 +6016,7 @@ static void rb_update_meta_page(struct ring_buffer_pe= r_cpu *cpu_buffer) meta->read =3D cpu_buffer->read; =20 /* Some archs do not have data cache coherency between kernel and user-sp= ace */ - flush_dcache_folio(virt_to_folio(cpu_buffer->meta_page)); + flush_kernel_vmap_range(cpu_buffer->meta_page, PAGE_SIZE); } =20 static void @@ -7319,7 +7319,8 @@ int ring_buffer_map_get_reader(struct trace_buffer *b= uffer, int cpu) =20 out: /* Some archs do not have data cache coherency between kernel and user-sp= ace */ - 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); =20 rb_update_meta_page(cpu_buffer); =20 --=20 2.47.2