From nobody Fri Dec 19 17:15:20 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 EA9EC59927 for ; Thu, 21 Dec 2023 16:10:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B51F4C433BF; Thu, 21 Dec 2023 16:10:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rGLdY-000000041K3-31gc; Thu, 21 Dec 2023 11:11:04 -0500 Message-ID: <20231221161104.501992954@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 21 Dec 2023 11:10:32 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tzvetomir Stoyanov , Vincent Donnefort , Kent Overstreet Subject: [for-next][PATCH 08/16] ring-buffer: Make sure the spare sub buffer used for reads has same size References: <20231221161024.478795180@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 (Google)" Now that the ring buffer specifies the size of its sub buffers, they all need to be the same size. When doing a read, a swap is done with a spare page. Make sure they are the same size before doing the swap, otherwise the read will fail. Link: https://lore.kernel.org/linux-trace-kernel/20231219185629.763664788@g= oodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Tzvetomir Stoyanov Cc: Vincent Donnefort Cc: Kent Overstreet Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 711095aa731d..4dcdc30aa110 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -7582,6 +7582,7 @@ struct ftrace_buffer_info { struct trace_iterator iter; void *spare; unsigned int spare_cpu; + unsigned int spare_size; unsigned int read; }; =20 @@ -8301,6 +8302,15 @@ tracing_buffers_read(struct file *filp, char __user = *ubuf, =20 page_size =3D ring_buffer_subbuf_size_get(iter->array_buffer->buffer); =20 + /* Make sure the spare matches the current sub buffer size */ + if (info->spare) { + if (page_size !=3D info->spare_size) { + ring_buffer_free_read_page(iter->array_buffer->buffer, + info->spare_cpu, info->spare); + info->spare =3D NULL; + } + } + if (!info->spare) { info->spare =3D ring_buffer_alloc_read_page(iter->array_buffer->buffer, iter->cpu_file); @@ -8309,6 +8319,7 @@ tracing_buffers_read(struct file *filp, char __user *= ubuf, info->spare =3D NULL; } else { info->spare_cpu =3D iter->cpu_file; + info->spare_size =3D page_size; } } if (!info->spare) --=20 2.42.0