From patchwork Thu Dec 21 16:10:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 182337 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp517563dyi; Thu, 21 Dec 2023 08:12:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGI1VhdnlGvbAnjX580P0HASQuDUpcOP8CloEwLq5W35Pgtb/skoOm8mzjxJHst+Cst5bs X-Received: by 2002:a17:906:7490:b0:a23:6e16:310c with SMTP id e16-20020a170906749000b00a236e16310cmr15443ejl.2.1703175170622; Thu, 21 Dec 2023 08:12:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703175170; cv=none; d=google.com; s=arc-20160816; b=NEpSP3r9TrIYDhTi1thkwamAdkMo6M+waO0g4PIEuJqkLb+MT9BRoYuYXRWZj0edng rHiSQBZrt9CKlI+uBV4RHhOtBMixGlGAd6/Hwdj/ismBk8jxX6MPFAF8oJZeTuHUy9e4 RGKsGsun5tzgAKgIQilh5Uyv79CP2mjOqEvTXsxSZhI97o72S52wRkegezd8YqUSF2En 36lYl2K9BKfNOq10QuP0HsT12/AN8pB6raRR4fmpnP/ny05Mmiw5WyuDoA5y5IhJdaTU 9trblop0+BRuGMsLallg064YyOSDXII9hD/C2a7rOPjdMMr8XF4h0jjh5NdcxOPP9fuR zIow== 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=sOIHL+NE1DitOxba89DChClxzv7XQYnkgbMTnwuLRDg=; fh=e3UoLP0GGIVG/JuDivUt2G6X10h9sIOfzt1IJTPiLuw=; b=OXe760Nat+Yb66frV7sY20cuTmHBndD53iTUVYidvGTeWWcjWAGOuR7iObfbHYuuDc Dhy2B2eAiWAL1GoWTFiSMhmtnLp//UHHPAVAKGU64j3C8xzSBx32aARFMR6Ri4sE7j7b I/357tKHXS2IrwEF9bamDl5N8UPIaspCcL7eSKrTCOrnMuMyqCX5KrtLBE1g9L98oyjz DmoA+HDFTDY9/2DSH29VyEQVgbDu7dbfcuZ8bFcMT1D7UNvEBfa/jnB+aa0ARK6W+bEn /kIGsOv6DN8CQHDEh0gWUlEHJINATRo+GD7UtWJBhmDvlUHZKHyGVRnKEAnCTA31kTRy F1QQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8733-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8733-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ga25-20020a170906b85900b00a235a606ba2si954081ejb.714.2023.12.21.08.12.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 08:12:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8733-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8733-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8733-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 am.mirrors.kernel.org (Postfix) with ESMTPS id E7CA51F25DBB for ; Thu, 21 Dec 2023 16:12:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E839065191; 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 33F7B627E0 for ; Thu, 21 Dec 2023 16:10:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 124A7C433CA; Thu, 21 Dec 2023 16:10:01 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rGLdZ-000000041KY-03JX; Thu, 21 Dec 2023 11:11:05 -0500 Message-ID: <20231221161104.796933244@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 21 Dec 2023 11:10:33 -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 09/16] tracing: Update snapshot order along with main buffer order 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: 1785908607739923851 X-GMAIL-MSGID: 1785908607739923851 From: "Steven Rostedt (Google)" When updating the order of the sub buffers for the main buffer, make sure that if the snapshot buffer exists, that it gets its order updated as well. Link: https://lore.kernel.org/linux-trace-kernel/20231219185630.054668186@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 | 45 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 4dcdc30aa110..2439e00aa4ce 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1263,10 +1263,17 @@ static void set_buffer_entries(struct array_buffer *buf, unsigned long val); int tracing_alloc_snapshot_instance(struct trace_array *tr) { + int order; int ret; if (!tr->allocated_snapshot) { + /* Make the snapshot buffer have the same order as main buffer */ + order = ring_buffer_subbuf_order_get(tr->array_buffer.buffer); + ret = ring_buffer_subbuf_order_set(tr->max_buffer.buffer, order); + if (ret < 0) + return ret; + /* allocate spare buffer */ ret = resize_buffer_duplicate_size(&tr->max_buffer, &tr->array_buffer, RING_BUFFER_ALL_CPUS); @@ -1286,6 +1293,7 @@ static void free_snapshot(struct trace_array *tr) * The max_tr ring buffer has some state (e.g. ring->clock) and * we want preserve it. */ + ring_buffer_subbuf_order_set(tr->max_buffer.buffer, 0); ring_buffer_resize(tr->max_buffer.buffer, 1, RING_BUFFER_ALL_CPUS); set_buffer_entries(&tr->max_buffer, 1); tracing_reset_online_cpus(&tr->max_buffer); @@ -9393,6 +9401,7 @@ buffer_order_write(struct file *filp, const char __user *ubuf, { struct trace_array *tr = filp->private_data; unsigned long val; + int old_order; int ret; ret = kstrtoul_from_user(ubuf, cnt, 10, &val); @@ -9403,12 +9412,44 @@ buffer_order_write(struct file *filp, const char __user *ubuf, if (val < 0 || val > 7) return -EINVAL; + old_order = ring_buffer_subbuf_order_get(tr->array_buffer.buffer); + if (old_order == val) + return 0; + ret = ring_buffer_subbuf_order_set(tr->array_buffer.buffer, val); if (ret) - return ret; + return 0; - (*ppos)++; +#ifdef CONFIG_TRACER_MAX_TRACE + + if (!tr->allocated_snapshot) + goto out_max; + ret = ring_buffer_subbuf_order_set(tr->max_buffer.buffer, val); + if (ret) { + /* Put back the old order */ + cnt = ring_buffer_subbuf_order_set(tr->array_buffer.buffer, old_order); + if (WARN_ON_ONCE(cnt)) { + /* + * AARGH! We are left with different orders! + * The max buffer is our "snapshot" buffer. + * When a tracer needs a snapshot (one of the + * latency tracers), it swaps the max buffer + * with the saved snap shot. We succeeded to + * update the order of the main buffer, but failed to + * update the order of the max buffer. But when we tried + * to reset the main buffer to the original size, we + * failed there too. This is very unlikely to + * happen, but if it does, warn and kill all + * tracing. + */ + tracing_disabled = 1; + } + return ret; + } + out_max: +#endif + (*ppos)++; return cnt; }