From patchwork Mon Oct 24 11:29:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9809 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp554919wru; Mon, 24 Oct 2022 09:58:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4VcSDbUdym+ByZsOznjc9Dl/HXLj3HhqAyZRIDeuofE1Q4ZkI3zsTihgGK09k8wDoBJRj7 X-Received: by 2002:a17:90b:1c06:b0:20a:f070:9f3c with SMTP id oc6-20020a17090b1c0600b0020af0709f3cmr40415217pjb.151.1666630706993; Mon, 24 Oct 2022 09:58:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666630706; cv=none; d=google.com; s=arc-20160816; b=G3FRSHtKtapBLd33unK/adLLo+SCzsZiocuZ8OOyJyCUIa2LRjSBHKcovlyMxXv3LI 6yYSKvdlMkpslZFJ6/rm64aCiN99CeQ6/l5Jc1dN8zAJrSzSNcBFs0K+WYLWQVY+Gj+j 9yGkaKa8GYoC4ic2rsEb0a9kDaiZ6a5M58+X1zMsWNDgkw+vgHD7hYmd5aK25qWll68R XVCKMlppZ+dpAStAisHoQznWC2wKHv111584uuD3B0YuXsBJN/hZ/aTbqkrMBJfNABPN thAuluu2t+Z96y33DIdGppkQYvxU2JtGuxEIoPD5zWAdwzhvrHx6J2LysyP47XnF634V sJFw== 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=Utz/02xJvIOtZkxUUcNH09X6XpNcQQL7Y74KPTN50pw=; b=ynMhFLRv9vHfG6dxNnYIZdYn91cf4nRG0T4DC09NEopeO2+sAPlSJHwWe2D/Dyfets 2iq+P108q0VNuMu3Fb3HDCRqKkxWn435HTRHhWDxf03fT/8RrohyD2SDxx6o+RTzyD+s RusMiZATsQRQHnkuT/e9SKo4+OkPOpTKap+V9qxlEsIq5yeuNvCFYkFopOnMLHKOIbiy kB8r3goUOvfWW/2kzzdU8hCr1IspRG8kDQ7KgHt+etBKxaWGMW5o+/dS38IUqTQ9wNKD oTIea1lg05iXbaPBqvCSaigzIX9wtrK/6BmOOz+UgFHHew4oo2R0DbSnP+qtlWy0aufg MRbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="AaXnha/8"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id on13-20020a17090b1d0d00b00212ee026b3csi559811pjb.24.2022.10.24.09.58.03; Mon, 24 Oct 2022 09:58:26 -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="AaXnha/8"; 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 S232384AbiJXQw4 (ORCPT + 99 others); Mon, 24 Oct 2022 12:52:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235286AbiJXQtW (ORCPT ); Mon, 24 Oct 2022 12:49:22 -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 0DF0283F03; Mon, 24 Oct 2022 08:32:28 -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 CDF64B811C0; Mon, 24 Oct 2022 12:06:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EF57C433D6; Mon, 24 Oct 2022 12:06:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613203; bh=l6/JJYg71Tp2CdzP8UNQum0EZe0uGk6D7/A7ysK3Bd8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AaXnha/8/a7grlQt8T4RAetTN0RTHSGTKuicaNkWjn2amnQrv608Qc2wZ7n1aNa63 eMSz+0U8pF/WKvFC0i82oXj1gVChDPMb5UXgwkRcMPHfpuCN3gA0iG8n+B32HZ5d3n //aoiExxbH9kOwgs1GDyXjY9wAGFAVGjztCb4aDU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (Google)" Subject: [PATCH 5.4 047/255] ring-buffer: Allow splice to read previous partially read pages Date: Mon, 24 Oct 2022 13:29:17 +0200 Message-Id: <20221024113004.000546176@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747588960152616558?= X-GMAIL-MSGID: =?utf-8?q?1747588960152616558?= 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 @@ -4825,7 +4825,15 @@ int ring_buffer_read_page(struct ring_bu 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))