]> git.baikalelectronics.ru Git - kernel.git/commitdiff
tracing: Increase trace array ref count on enable and filter files
authorSteven Rostedt (Google) <rostedt@goodmis.org>
Thu, 7 Sep 2023 02:47:12 +0000 (22:47 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 23 Sep 2023 09:11:11 +0000 (11:11 +0200)
commit f5ca233e2e66dc1c249bf07eefa37e34a6c9346a upstream.

When the trace event enable and filter files are opened, increment the
trace array ref counter, otherwise they can be accessed when the trace
array is being deleted. The ref counter keeps the trace array from being
deleted while those files are opened.

Link: https://lkml.kernel.org/r/20230907024803.456187066@goodmis.org
Link: https://lore.kernel.org/all/1cb3aee2-19af-c472-e265-05176fe9bd84@huawei.com/
Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Fixes: 8530dec63e7b4 ("tracing: Add tracing_check_open_get_tr()")
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Reported-by: Zheng Yejian <zhengyejian1@huawei.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/trace/trace.c
kernel/trace/trace.h
kernel/trace/trace_events.c

index a9a54581694efd1b2b36bcc41084a496278019a4..1ea3f969c36b0b8e0e376afbdcf0db7f1040e564 100644 (file)
@@ -4899,6 +4899,33 @@ int tracing_open_generic_tr(struct inode *inode, struct file *filp)
        return 0;
 }
 
+/*
+ * The private pointer of the inode is the trace_event_file.
+ * Update the tr ref count associated to it.
+ */
+int tracing_open_file_tr(struct inode *inode, struct file *filp)
+{
+       struct trace_event_file *file = inode->i_private;
+       int ret;
+
+       ret = tracing_check_open_get_tr(file->tr);
+       if (ret)
+               return ret;
+
+       filp->private_data = inode->i_private;
+
+       return 0;
+}
+
+int tracing_release_file_tr(struct inode *inode, struct file *filp)
+{
+       struct trace_event_file *file = inode->i_private;
+
+       trace_array_put(file->tr);
+
+       return 0;
+}
+
 static int tracing_mark_open(struct inode *inode, struct file *filp)
 {
        stream_open(inode, filp);
index dbb86b0dd3b7be54d65386b1c97464fc724356b5..7e6d5101bdb0540c1481544a4f20950d970597d4 100644 (file)
@@ -590,6 +590,8 @@ void tracing_reset_all_online_cpus(void);
 void tracing_reset_all_online_cpus_unlocked(void);
 int tracing_open_generic(struct inode *inode, struct file *filp);
 int tracing_open_generic_tr(struct inode *inode, struct file *filp);
+int tracing_open_file_tr(struct inode *inode, struct file *filp);
+int tracing_release_file_tr(struct inode *inode, struct file *filp);
 bool tracing_is_disabled(void);
 bool tracer_tracing_is_on(struct trace_array *tr);
 void tracer_tracing_on(struct trace_array *tr);
index 0447c46ef4d710012486bc1b25c100f03ce75491..9da418442a0633cbbfc9c79dbf9869136fca629e 100644 (file)
@@ -2101,9 +2101,10 @@ static const struct file_operations ftrace_set_event_notrace_pid_fops = {
 };
 
 static const struct file_operations ftrace_enable_fops = {
-       .open = tracing_open_generic,
+       .open = tracing_open_file_tr,
        .read = event_enable_read,
        .write = event_enable_write,
+       .release = tracing_release_file_tr,
        .llseek = default_llseek,
 };
 
@@ -2120,9 +2121,10 @@ static const struct file_operations ftrace_event_id_fops = {
 };
 
 static const struct file_operations ftrace_event_filter_fops = {
-       .open = tracing_open_generic,
+       .open = tracing_open_file_tr,
        .read = event_filter_read,
        .write = event_filter_write,
+       .release = tracing_release_file_tr,
        .llseek = default_llseek,
 };