From nobody Fri Dec 19 22:02:58 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEC1EC38A2D for ; Mon, 24 Oct 2022 14:08:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232761AbiJXOIe (ORCPT ); Mon, 24 Oct 2022 10:08:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237117AbiJXOEh (ORCPT ); Mon, 24 Oct 2022 10:04:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 331FFDE91; Mon, 24 Oct 2022 05:49:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8CEBEB818D7; Mon, 24 Oct 2022 12:37:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA33AC433D6; Mon, 24 Oct 2022 12:37:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615057; bh=xOCrOLyRxikjXMjdmMyMA8e4ou2lTkcLcUt1dOy066U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sj7HTNM9UHfjONjRw4shvNwmh1o9fvO36/9poVdau81jhnOS9iT3BF10Q09CgS97+ DRI0B+SMyfva6WsZGPpDupDboqQE1PqsH4KuTHDd6NkMXtlnDXYDX25YLUV+TKzx2b 7hHwqL0AYfFPCm7doZ1MigjO3nuhfiEWyGKL8kmQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (Google)" Subject: [PATCH 5.15 106/530] ring-buffer: Allow splice to read previous partially read pages Date: Mon, 24 Oct 2022 13:27:30 +0200 Message-Id: <20221024113049.824115881@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Steven Rostedt (Google) commit fa8f4a89736b654125fb254b0db753ac68a5fced upstream. If a page is partially read, and then the splice system call is run against the ring buffer, it will always fail to read, no matter how much is in the ring buffer. That's because the code path for a partial read of the page does will fail if the "full" flag is set. The splice system call wants full pages, so if the read of the ring buffer is not yet full, it should return zero, and the splice will block. But if a previous read was done, where the beginning has been consumed, it should still be given to the splice caller if the rest of the page has been written to. This caused the splice command to never consume data in this scenario, and let the ring buffer just fill up and lose events. Link: https://lkml.kernel.org/r/20220927144317.46be6b80@gandalf.local.home Cc: stable@vger.kernel.org Fixes: 8789a9e7df6bf ("ring-buffer: read page interface") Signed-off-by: Steven Rostedt (Google) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/ring_buffer.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -5574,7 +5574,15 @@ int ring_buffer_read_page(struct trace_b unsigned int pos =3D 0; unsigned int size; =20 - if (full) + /* + * If a full page is expected, this can still be returned + * if there's been a previous partial read and the + * rest of the page can be read and the commit page is off + * the reader page. + */ + if (full && + (!read || (len < (commit - read)) || + cpu_buffer->reader_page =3D=3D cpu_buffer->commit_page)) goto out_unlock; =20 if (len > (commit - read))