Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3888432rwi; Sat, 22 Oct 2022 01:36:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Mi4zaIkt8Tj+eORt8qCT7NtP9inWs4lE185h8SXx/N5BITkS0UzRziWJ1pL3Cu6Ft2y5z X-Received: by 2002:a17:90a:4594:b0:20b:23d5:8ead with SMTP id v20-20020a17090a459400b0020b23d58eadmr61387242pjg.127.1666427771918; Sat, 22 Oct 2022 01:36:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427771; cv=none; d=google.com; s=arc-20160816; b=nyx19Wgex7GJ0eL3dqbrABOYbIVSeCVtgiyJi25jZy48CTwA6iIEdqq6/DzrZJ6LGq NFL0BThEuJzgXv63gI+TCkzxUhzWhLdxOKzpTRjXgISWxh1+pZcmpTdiU0AfCzQa/7S6 eKZXWClVAGEpCkyw9xQPtYi9Dx5/6RI5qsc73NOOK1f71De+G4RP/+ogllBIae8aBQiK ryAjuPyvhN2zqkLgSa5atje3DwP3eK3Za7j5VkUt/O8RCZZO+4e/7LVA0XKNmI5evGWx 405hNWgK1JAp5BXYCxC2PHkjNRzrGuvjcjN1bV+0gpnpLVXF01yTcPcYvX1isYqgv1on +d3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iAcpwmqtvMsWnBA1wKY6nqifE/qZlcrQLqQuTj1uuPc=; b=QIP31VHvoYcSjQuGrvTKwOPb4MHzZAbgOZ0OMM47MpQ2zMTf8RfHH46KhotK/k0kPl pQJvRTR97ha70TRdDfuJIW/keMteKuNoxA9xFRf4DBpJXfXLJiLCpwYYawjdk1pXdi/d vXnaF4nWyprkrduPN6LHPTGilnFWePWjcRlYNb/REOYU5Mji2crFkFQZQt9aC6jJn8x8 R027MQjx0NCwlRsI+ytzIpu55UwEbVxC4hSGYPjbdVtmZdLTab2CvXisa4gVtwvHgcPY azyyPWcKP29DjRO/4cOFMuzVenFcBZbtTol1+/v9LtVm0iZn6AGEOyIVZVjEnAbLv9t6 t5DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gNGLmX8+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s3-20020a632c03000000b00460c67afbd9si3498256pgs.771.2022.10.22.01.35.55; Sat, 22 Oct 2022 01:36:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gNGLmX8+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233185AbiJVIVU (ORCPT + 99 others); Sat, 22 Oct 2022 04:21:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233805AbiJVITq (ORCPT ); Sat, 22 Oct 2022 04:19:46 -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 856E52DF44E; Sat, 22 Oct 2022 00:58:14 -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 A708FB82DF9; Sat, 22 Oct 2022 07:40:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F118AC433C1; Sat, 22 Oct 2022 07:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424421; bh=FBSqfGdqenbLRx3kzmze2zovm+J2vRZ3J4A4qSTPPVo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gNGLmX8+Fo6ekLPDvG3Ib7p6Pv9vaoPLHPupPEpBC9BXKA2I3cE/rHG/o6OqSf+3k bUKEmQmbsNYmscT/IDnpIbXJGekLJwCJWXp86nmhlAWPzKfqXFjEDpWgHhwLedVA3d wi+MMzcqlmU37s8vMi/nCD6ZiwQUwL/Vh8unYUvE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (Google)" Subject: [PATCH 5.19 140/717] ring-buffer: Allow splice to read previous partially read pages Date: Sat, 22 Oct 2022 09:20:19 +0200 Message-Id: <20221022072440.357709319@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 @@ -5616,7 +5616,15 @@ int ring_buffer_read_page(struct trace_b unsigned int pos = 0; unsigned int size; - 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 == cpu_buffer->commit_page)) goto out_unlock; if (len > (commit - read))