Skip to content

Commit

Permalink
tracing: Increase trace array ref count on enable and filter files
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
rostedt committed Sep 7, 2023
1 parent 9879e5e commit f5ca233
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
27 changes: 27 additions & 0 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -4973,6 +4973,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);
Expand Down
2 changes: 2 additions & 0 deletions kernel/trace/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,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);
Expand Down
6 changes: 4 additions & 2 deletions kernel/trace/trace_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -2103,9 +2103,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,
};

Expand All @@ -2122,9 +2123,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,
};

Expand Down

0 comments on commit f5ca233

Please sign in to comment.