Skip to content

Commit da36840

Browse files
rostedtgregkh
authored andcommitted
tracing: Move pipe reference to trace array instead of current_tracer
[ Upstream commit 7ef282e ] If a process has the trace_pipe open on a trace_array, the current tracer for that trace array should not be changed. This was original enforced by a global lock, but when instances were introduced, it was moved to the current_trace. But this structure is shared by all instances, and a trace_pipe is for a single instance. There's no reason that a process that has trace_pipe open on one instance should prevent another instance from changing its current tracer. Move the reference counter to the trace_array instead. This is marked as "Fixes" but is more of a clean up than a true fix. Backport if you want, but its not critical. Fixes: cf6ab6d ("tracing: Add ref count to tracer for when they are being read by pipe") Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d579cc1 commit da36840

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

‎kernel/trace/trace.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5887,7 +5887,7 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)
58875887
}
58885888

58895889
/* If trace pipe files are being read, we can't change the tracer */
5890-
if (tr->current_trace->ref) {
5890+
if (tr->trace_ref) {
58915891
ret = -EBUSY;
58925892
goto out;
58935893
}
@@ -6103,7 +6103,7 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp)
61036103

61046104
nonseekable_open(inode, filp);
61056105

6106-
tr->current_trace->ref++;
6106+
tr->trace_ref++;
61076107
out:
61086108
mutex_unlock(&trace_types_lock);
61096109
return ret;
@@ -6122,7 +6122,7 @@ static int tracing_release_pipe(struct inode *inode, struct file *file)
61226122

61236123
mutex_lock(&trace_types_lock);
61246124

6125-
tr->current_trace->ref--;
6125+
tr->trace_ref--;
61266126

61276127
if (iter->trace->pipe_close)
61286128
iter->trace->pipe_close(iter);
@@ -7424,7 +7424,7 @@ static int tracing_buffers_open(struct inode *inode, struct file *filp)
74247424

74257425
filp->private_data = info;
74267426

7427-
tr->current_trace->ref++;
7427+
tr->trace_ref++;
74287428

74297429
mutex_unlock(&trace_types_lock);
74307430

@@ -7525,7 +7525,7 @@ static int tracing_buffers_release(struct inode *inode, struct file *file)
75257525

75267526
mutex_lock(&trace_types_lock);
75277527

7528-
iter->tr->current_trace->ref--;
7528+
iter->tr->trace_ref--;
75297529

75307530
__trace_array_put(iter->tr);
75317531

@@ -8733,7 +8733,7 @@ static int __remove_instance(struct trace_array *tr)
87338733
int i;
87348734

87358735
/* Reference counter for a newly created trace array = 1. */
8736-
if (tr->ref > 1 || (tr->current_trace && tr->current_trace->ref))
8736+
if (tr->ref > 1 || (tr->current_trace && tr->trace_ref))
87378737
return -EBUSY;
87388738

87398739
list_del(&tr->list);

‎kernel/trace/trace.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ struct trace_array {
356356
struct trace_event_file *trace_marker_file;
357357
cpumask_var_t tracing_cpumask; /* only trace on set CPUs */
358358
int ref;
359+
int trace_ref;
359360
#ifdef CONFIG_FUNCTION_TRACER
360361
struct ftrace_ops *ops;
361362
struct trace_pid_list __rcu *function_pids;
@@ -547,7 +548,6 @@ struct tracer {
547548
struct tracer *next;
548549
struct tracer_flags *flags;
549550
int enabled;
550-
int ref;
551551
bool print_max;
552552
bool allow_instances;
553553
#ifdef CONFIG_TRACER_MAX_TRACE

0 commit comments

Comments
 (0)