From patchwork Tue Dec 19 18:54:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 181220 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2156377dyi; Tue, 19 Dec 2023 10:58:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1DV24ARS1y3GclhMfWuCIdSJAhiKnZVQ8ondIfAWCm8O+jDucXsBkFVZ4/NpFlKvpb++d X-Received: by 2002:a05:620a:468d:b0:77e:fba3:58eb with SMTP id bq13-20020a05620a468d00b0077efba358ebmr23304936qkb.124.1703012314919; Tue, 19 Dec 2023 10:58:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703012314; cv=none; d=google.com; s=arc-20160816; b=barPD6EfHARN6nnIfbyN10celykmU45HhGgL/WaqxSuKq06NDcGnF8S/l6dgIcv0H3 W3N+1EdBnAa2LPsq2yqE9ZlXuGv4qv1rXk4KdWgX6JUrEOc2ZKycMU8xaiAbIL4lSHgc dVKpkaDlvfO6gCzNlhholWK9R/L+aNApQlmIjhX6yoNhlwjQYhhY4nXtsV0Ckd+U/+r3 /HHaPfKUsBKFAbb+aWOGTLi9CIeAQFcoLIPH3qXYUSs6lPyynr7GlHy+/3u5CidD6koy iGrBlsp8FWlLOgy5mx/aDc2ddPBPL14G1x/9rO2tmOVLYzvwPuwUiec9hqBVRrw3C1Au CrcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=lf2FhDQW42eD5xMwPQ5Fbi2NVhnwxzvV52eSBieXvHU=; fh=pL1t9p0RxD5qCgSUniSa3P4+XmpksJYPzX6TE+dndao=; b=ujighfks4ybFpZn5dVFKgWzBwCLA9yyqyhuv26+AdL0dGQ3YELX4z16VdRkFQF5cAb zrylxxZzqvlzIsa67r0naUwx6zR7We243fNr0ke6U4YzjEbDoqTm84I5lwQwDvC228/A xjs7f+rcF7Ri8jqYbXaJUDY7jLXeVqx0g9m+9XbiIznnS8qKiXItBSd323rW2bKbazr7 MbHlYt8ssfo52qwVIAOXENp1+eyTM0vM0DtkSX0/7iaO0vgv0HoRi/veCNhSyTgvw3Bg 8m5jfsGDPYnGZSfxlr4Pi5Se5nAQ2mgSWSificVKwD2Q8Tn4+9e91hXhwvE1gRzkptWp 4GSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-5841-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5841-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d22-20020a05620a137600b0077fa9e50717si11632851qkl.779.2023.12.19.10.58.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 10:58:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5841-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-5841-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5841-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B42E41C23624 for ; Tue, 19 Dec 2023 18:58:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8BFD40C1F; Tue, 19 Dec 2023 18:55:33 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org 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 110043A29B; Tue, 19 Dec 2023 18:55:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76B60C433C9; Tue, 19 Dec 2023 18:55:30 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rFfGX-00000003R3L-47qm; Tue, 19 Dec 2023 13:56:29 -0500 Message-ID: <20231219185629.763664788@goodmis.org> User-Agent: quilt/0.67 Date: Tue, 19 Dec 2023 13:54:22 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tzvetomir Stoyanov , Vincent Donnefort , Kent Overstreet Subject: [PATCH v5 08/15] ring-buffer: Make sure the spare sub buffer used for reads has same size References: <20231219185414.474197117@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785737841239205708 X-GMAIL-MSGID: 1785737841239205708 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. 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; }; @@ -8301,6 +8302,15 @@ tracing_buffers_read(struct file *filp, char __user *ubuf, page_size = ring_buffer_subbuf_size_get(iter->array_buffer->buffer); + /* Make sure the spare matches the current sub buffer size */ + if (info->spare) { + if (page_size != info->spare_size) { + ring_buffer_free_read_page(iter->array_buffer->buffer, + info->spare_cpu, info->spare); + info->spare = NULL; + } + } + if (!info->spare) { info->spare = 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 = NULL; } else { info->spare_cpu = iter->cpu_file; + info->spare_size = page_size; } } if (!info->spare)