From patchwork Mon Oct 24 11:30:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8430 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp400837wru; Mon, 24 Oct 2022 04:47:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM51+N5oJR+SOT8FWdvSN6AXSmfMT1dPo9STG6Orjb+nI+fLU2DreD8CErn8EhXZXGbYbTGM X-Received: by 2002:a05:6402:5162:b0:457:6ef2:df3 with SMTP id d2-20020a056402516200b004576ef20df3mr30246630ede.128.1666612068406; Mon, 24 Oct 2022 04:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666612068; cv=none; d=google.com; s=arc-20160816; b=sxMAPw5NC9VFhfQXzudDvjUb49HVeIT4mo0q0OPFerf0UL1Kphkgeh1tq3GBV9ic+8 fmKeDfFL7kI6G/9/qGIYaOAOqAlaz8YRhTr7yKrUseRhwH0Wxb2yNTwvsaEkL/Y4ujuC pogCEXl1NFjWv+GhCrZU45rsyijsPRDAvwan2oCRYDFTtix1W9DTrTGpRNBNU9TZ8f5G BhZKbnvHAo2yZCbNuDci0jyexgeOGfvHY1B45uWIRlvZOxLhdUO3TVr/tRPLhD3bfo9S XKOrniB4sdcZBuTEJGoYwv8vlEDewj2QjWI2Vw5kHES3UfzgKBkCDgBRrvglYXCXn0Vf 8Pcg== 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=+rQzwhh/Ik1UAbn15gSm0Dh9Qn9y2V0rvLmD+9Y9MSg=; b=LYcEK4eQnCNaQtO0uiSNZbS12EwWPSgx/2fDU03fjAI2hiIbWaZlrYrFie37cunAEC 8rBWtq8LfH03GBuOl2cfAdfw/2PVIdLziaTaf1EOCOgYZNxXxW/RSzaa6oEJr/ONtVCi HCSTTHaQvhsMGGuR2vxQ/b2WP8ok0xzyY8KwpGbXJrS9ymJ1QcGxxr26Tz88ZcFXbMaQ YoVee+67DqxtHY6Bmvdgm3sUTST/q6BbEh6B1zxiUUNO2gWgT4OKKzlsMU9z4JDRvVh1 1mEY5r156wqzUmzEDweqvS+RRVIGiaW0cfHe5ef7+zsnVgIqPzAgxIDqxih9TaS0aZfO WPVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ri3MVWqD; 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 go10-20020a1709070d8a00b0078e11cbb722si33778559ejc.92.2022.10.24.04.47.24; Mon, 24 Oct 2022 04:47:48 -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=Ri3MVWqD; 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 S231473AbiJXLqu (ORCPT + 99 others); Mon, 24 Oct 2022 07:46:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231866AbiJXLoj (ORCPT ); Mon, 24 Oct 2022 07:44:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B1F754A6; Mon, 24 Oct 2022 04:42: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 dfw.source.kernel.org (Postfix) with ESMTPS id 55FE9612A3; Mon, 24 Oct 2022 11:40:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66641C433D6; Mon, 24 Oct 2022 11:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611649; bh=HleRpNnRVYw5VRTljs6TvCLKvfcsk+4I4s4hYiy2qTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ri3MVWqDsJdAS7Rly4z0ftWrrGCeyzV3nU/tKy9JHS2HF0j1i0Z/oVWBpo6rJjg/D 9f03aiq6DU4TDak/NOXkaQJP+Xzbw8nVSnaZWRwGci4tgBK8FkVW6p4xzPqatcV9/Y I5oMFx9DAoBMbvQ5mpSbQRZ6mIVa1QTluKqogJ24= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (Google)" Subject: [PATCH 4.9 059/159] ring-buffer: Allow splice to read previous partially read pages Date: Mon, 24 Oct 2022 13:30:13 +0200 Message-Id: <20221024112951.590823450@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@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?1747569416221352754?= X-GMAIL-MSGID: =?utf-8?q?1747569416221352754?= 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 @@ -4623,7 +4623,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))