Skip to content

Commit f5ca233

Browse files
committed
tracing: Increase trace array ref count on enable and filter files
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/[email protected] Link: https://lore.kernel.org/all/[email protected]/ Cc: [email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Andrew Morton <[email protected]> Fixes: 8530dec ("tracing: Add tracing_check_open_get_tr()") Tested-by: Linux Kernel Functional Testing <[email protected]> Tested-by: Naresh Kamboju <[email protected]> Reported-by: Zheng Yejian <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 9879e5e commit f5ca233

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

kernel/trace/trace.c

+27
Original file line numberDiff line numberDiff line change
@@ -4973,6 +4973,33 @@ int tracing_open_generic_tr(struct inode *inode, struct file *filp)
49734973
return 0;
49744974
}
49754975

4976+
/*
4977+
* The private pointer of the inode is the trace_event_file.
4978+
* Update the tr ref count associated to it.
4979+
*/
4980+
int tracing_open_file_tr(struct inode *inode, struct file *filp)
4981+
{
4982+
struct trace_event_file *file = inode->i_private;
4983+
int ret;
4984+
4985+
ret = tracing_check_open_get_tr(file->tr);
4986+
if (ret)
4987+
return ret;
4988+
4989+
filp->private_data = inode->i_private;
4990+
4991+
return 0;
4992+
}
4993+
4994+
int tracing_release_file_tr(struct inode *inode, struct file *filp)
4995+
{
4996+
struct trace_event_file *file = inode->i_private;
4997+
4998+
trace_array_put(file->tr);
4999+
5000+
return 0;
5001+
}
5002+
49765003
static int tracing_mark_open(struct inode *inode, struct file *filp)
49775004
{
49785005
stream_open(inode, filp);

kernel/trace/trace.h

+2
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ void tracing_reset_all_online_cpus(void);
610610
void tracing_reset_all_online_cpus_unlocked(void);
611611
int tracing_open_generic(struct inode *inode, struct file *filp);
612612
int tracing_open_generic_tr(struct inode *inode, struct file *filp);
613+
int tracing_open_file_tr(struct inode *inode, struct file *filp);
614+
int tracing_release_file_tr(struct inode *inode, struct file *filp);
613615
bool tracing_is_disabled(void);
614616
bool tracer_tracing_is_on(struct trace_array *tr);
615617
void tracer_tracing_on(struct trace_array *tr);

kernel/trace/trace_events.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -2103,9 +2103,10 @@ static const struct file_operations ftrace_set_event_notrace_pid_fops = {
21032103
};
21042104

21052105
static const struct file_operations ftrace_enable_fops = {
2106-
.open = tracing_open_generic,
2106+
.open = tracing_open_file_tr,
21072107
.read = event_enable_read,
21082108
.write = event_enable_write,
2109+
.release = tracing_release_file_tr,
21092110
.llseek = default_llseek,
21102111
};
21112112

@@ -2122,9 +2123,10 @@ static const struct file_operations ftrace_event_id_fops = {
21222123
};
21232124

21242125
static const struct file_operations ftrace_event_filter_fops = {
2125-
.open = tracing_open_generic,
2126+
.open = tracing_open_file_tr,
21262127
.read = event_filter_read,
21272128
.write = event_filter_write,
2129+
.release = tracing_release_file_tr,
21282130
.llseek = default_llseek,
21292131
};
21302132

0 commit comments

Comments
 (0)