From patchwork Thu Dec 21 16:10:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 182347 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp522267dyi; Thu, 21 Dec 2023 08:19:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVjz9TpFTiX08b6wXKS6wJUXOkQjI0yKeqYIXS7STUSirOp45nUczRJM7DjUrZUbRtBpSF X-Received: by 2002:a05:6a00:2311:b0:6ce:f74e:ff4f with SMTP id h17-20020a056a00231100b006cef74eff4fmr12879746pfh.50.1703175573664; Thu, 21 Dec 2023 08:19:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703175573; cv=none; d=google.com; s=arc-20160816; b=TdDs4XjdnfaNCyiZatR7IUk6hdU3syAlNX7Yl9o4lTPGGatS9Hf6Wvu1MiOpHTf9II MsnqiFsW8zwgH/nTicHnzjDwU0hN48KS/70OXKZ4OmNzNzPbNYkNpvhhZIDFNFeNWNDl Vc9EE8bnKNx96EhzfQL/9eTFgEktFLgDa2aVV8QPGkcr6LVPVn1NF8TT1UbWCayCevyv K8PM0jKT1s3uq7mjLst3E50JSw8e+yx87EjHir6R/ybghm96aG87hsbr1G5PhuBjumPo j+qDRblggGB8MvzHD7GQ49ISWsRWWme+pf1cSdVwxyBOsXhkGb97ET9IKCNXOz65HEIk XHEQ== 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=iu0Q76K9SyTr6h0Kq6xnCxEbvy8hMpXowVN697MoZ0Y=; fh=e3UoLP0GGIVG/JuDivUt2G6X10h9sIOfzt1IJTPiLuw=; b=Nsi6rDfFBTilURhWjSDH5O+gb7mJsSjuyhH+PbuGjHBIr5Btz5ADzFIhP07UmGvP+9 1LUW1/u1ZpXmorIHSP8DggBlmUZaEcIk8NbQmabEhnrQt6NTmvDJlchfN0vz71ilClj9 s8sP094yfoFwpnbvxUcV48gwqPoujVmyv9gjxy/T/W6R8fDzw6++iMUiQansNx4wys5w Lfp98oiEj6hLLQv5nmf5FYPC1bVKIdRzy9HkYz6eiTFMDZMOQliHtc6uO1FzTYW2Zw/v C9ouUu7T04mc06Elu8x6xPaHvzDKUW9M+F9PWwR3L3chvcJq1jjIxL9UxCmV8APja6Ph dQSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8731-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8731-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m16-20020aa78a10000000b006ce7b6f8c7esi1752327pfa.210.2023.12.21.08.19.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 08:19:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8731-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8731-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8731-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D010428B40D for ; Thu, 21 Dec 2023 16:12:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A844F64AAE; Thu, 21 Dec 2023 16:10:02 +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 EA9EC59927 for ; Thu, 21 Dec 2023 16:10:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B51F4C433BF; Thu, 21 Dec 2023 16:10:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rGLdY-000000041K3-31gc; Thu, 21 Dec 2023 11:11:04 -0500 Message-ID: <20231221161104.501992954@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 21 Dec 2023 11:10:32 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tzvetomir Stoyanov , Vincent Donnefort , Kent Overstreet Subject: [for-next][PATCH 08/16] ring-buffer: Make sure the spare sub buffer used for reads has same size References: <20231221161024.478795180@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: 1785909030410635405 X-GMAIL-MSGID: 1785909030410635405 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. Link: https://lore.kernel.org/linux-trace-kernel/20231219185629.763664788@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Tzvetomir Stoyanov Cc: Vincent Donnefort Cc: Kent Overstreet 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)