From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [for-next][PATCH 03/15] tracing: Remove unnecessary copying of tr->current_trace
Date: Mon, 31 Jul 2023 19:16:37 -0400 [thread overview]
Message-ID: <20230731231705.484662632@goodmis.org> (raw)
In-Reply-To: <20230731231634.031452225@goodmis.org>
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
The iterator allocated a descriptor to copy the current_trace. This was done
with the assumption that the function pointers might change. But this was a
false assuption, as it does not change. There's no reason to make a copy of the
current_trace and just use the pointer it points to. This removes needing to
manage freeing the descriptor. Worse yet, there's locations that the iterator
is used but does make a copy and just uses the pointer. This could cause the
actual pointer to the trace descriptor to be freed and not the allocated copy.
This is more of a clean up than a fix.
Link: https://lkml.kernel.org/r/20230715141348.135792275@goodmis.org
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Fixes: d7350c3f45694 ("tracing/core: make the read callbacks reentrants")
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/trace.c | 22 +++-------------------
1 file changed, 3 insertions(+), 19 deletions(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index f6ed6b79d91f..5e665c356df7 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -4189,15 +4189,9 @@ static void *s_start(struct seq_file *m, loff_t *pos)
loff_t l = 0;
int cpu;
- /*
- * copy the tracer to avoid using a global lock all around.
- * iter->trace is a copy of current_trace, the pointer to the
- * name may be used instead of a strcmp(), as iter->trace->name
- * will point to the same string as current_trace->name.
- */
mutex_lock(&trace_types_lock);
- if (unlikely(tr->current_trace && iter->trace->name != tr->current_trace->name))
- *iter->trace = *tr->current_trace;
+ if (unlikely(tr->current_trace != iter->trace))
+ iter->trace = tr->current_trace;
mutex_unlock(&trace_types_lock);
#ifdef CONFIG_TRACER_MAX_TRACE
@@ -4846,16 +4840,8 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot)
iter->fmt = NULL;
iter->fmt_size = 0;
- /*
- * We make a copy of the current tracer to avoid concurrent
- * changes on it while we are reading.
- */
mutex_lock(&trace_types_lock);
- iter->trace = kzalloc(sizeof(*iter->trace), GFP_KERNEL);
- if (!iter->trace)
- goto fail;
-
- *iter->trace = *tr->current_trace;
+ iter->trace = tr->current_trace;
if (!zalloc_cpumask_var(&iter->started, GFP_KERNEL))
goto fail;
@@ -4920,7 +4906,6 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot)
fail:
mutex_unlock(&trace_types_lock);
- kfree(iter->trace);
kfree(iter->temp);
kfree(iter->buffer_iter);
release:
@@ -5005,7 +4990,6 @@ static int tracing_release(struct inode *inode, struct file *file)
free_cpumask_var(iter->started);
kfree(iter->fmt);
kfree(iter->temp);
- kfree(iter->trace);
kfree(iter->buffer_iter);
seq_release_private(inode, file);
--
2.40.1
next prev parent reply other threads:[~2023-07-31 23:17 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-31 23:16 [for-next][PATCH 00/15] tracing: Updates for v6.6 Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 01/15] tracing: Add back FORTIFY_SOURCE logic to kernel_stack event structure Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 02/15] ring_buffer: Use try_cmpxchg instead of cmpxchg Steven Rostedt
2023-07-31 23:16 ` Steven Rostedt [this message]
2023-07-31 23:16 ` [for-next][PATCH 04/15] tracing: Add free_trace_iter_content() helper function Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 05/15] tracing: Set actual size after ring buffer resize Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 06/15] tracing: Require all trace events to have a TRACE_SYSTEM Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 07/15] eventfs: Implement tracefs_inode_cache Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 08/15] tracefs: Rename and export some tracefs functions Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 09/15] eventfs: Implement eventfs dir creation functions Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 10/15] eventfs: Implement eventfs file add functions Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 11/15] eventfs: Implement eventfs lookup, read, open functions Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 12/15] eventfs: Implement functions to create files and dirs when accessed Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 13/15] eventfs: Implement removal of meta data from eventfs Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 14/15] eventfs: Move tracing/events to eventfs Steven Rostedt
2023-07-31 23:16 ` [for-next][PATCH 15/15] test: ftrace: Fix kprobe test for eventfs Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230731231705.484662632@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®