From patchwork Fri Dec 15 17:55:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 179495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9464104dys; Fri, 15 Dec 2023 09:58:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYxnaHEiXaOPh5cxs6qgTzb6CJwVvvwRYl0u0Xema6OykFctCE6C1PPE07QJ8iBcOmMkNc X-Received: by 2002:a05:6214:1d0c:b0:67f:fb3:8622 with SMTP id e12-20020a0562141d0c00b0067f0fb38622mr4236581qvd.5.1702663105913; Fri, 15 Dec 2023 09:58:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702663105; cv=none; d=google.com; s=arc-20160816; b=aMuvit7I3IG/iYiQgf1XQX6OCl7WHMOCyhQmyMTu5o2fwPUJRaQ/r/Niqh3vw2SLxB Rt6yant7Uv0RaB1QnUY7kMg+fBN4aujnKR8guA7GcmjHx6oTFCQJ7nAE8gFT9Mr7GnIp sCp9togKuKO12beJ3BVsNKBrBsUSM9w4w12aBAPNDscelA90hAjwdtnHZ9CrMJMMre7w w9FKf8dDCrJC8+Tyg97yhm1QgPwev/z/iyaIiJtCa26WAALBKRPwdxgIeTJ8673inbF8 9qRa7DJ6hUWgY0hlJ3sC8blpNLre478ok/1hm5RnwJoa03UCZYZ+3p+y3YZ8AI1dZnT6 0AVw== 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=xtse0r7WegWUPx1aoNFeJ+8ToTFo2eZh5hUEj0IPS4I=; fh=pL1t9p0RxD5qCgSUniSa3P4+XmpksJYPzX6TE+dndao=; b=xLp38clBYu+GOK93Cg0j8DT8lzLGHH0lkqbGHLPmUozQWPP45Yktj/mNycdQSi73CT xotfHJF69aX+TVr09xfTmKxQgnu/x4XnAJbLoB5aGI7v7kwAJEW50uG5HFM+m+kOJr1n 2K6DuyUZ6U6zrlBBgZmQKdZTO+OOaDviPzHOXQ5s/zTV03ZCtqVq4w5zkt8rHqabHBbM w279CRQtB46vAukiThyQ6/ruU4lRUsZjuhmbQm/hLL3qhMiuO/ThWfkVcQx9+WcXjMzY zJxyHDXDBPAjDDCWBu/LOcrUwXktqksfA/K5kFJXPfDoUDeNbOxSUJuYmtRX+q4JoZQJ 98Vw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1486-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1486-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 i11-20020a0cd84b000000b0067ef59c437csi6633612qvj.543.2023.12.15.09.58.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:58:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1486-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-1486-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1486-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 AD8661C24563 for ; Fri, 15 Dec 2023 17:58:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 717B7563A2; Fri, 15 Dec 2023 17:54:58 +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 820704655F; Fri, 15 Dec 2023 17:54:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F2F2C4163C; Fri, 15 Dec 2023 17:54:56 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rECPa-00000002wRm-0BoG; Fri, 15 Dec 2023 12:55:46 -0500 Message-ID: <20231215175545.829633185@goodmis.org> User-Agent: quilt/0.67 Date: Fri, 15 Dec 2023 12:55:11 -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 v4 09/15] tracing: Update snapshot order along with main buffer order References: <20231215175502.106587604@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: 1785371668708060860 X-GMAIL-MSGID: 1785371668708060860 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. 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 c148797afe6d..836514e566c7 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); @@ -9400,6 +9408,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); @@ -9410,12 +9419,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; }