Skip to content

Commit 7ef282e

Browse files
committed
tracing: Move pipe reference to trace array instead of current_tracer
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) <[email protected]>
1 parent e6bc5b3 commit 7ef282e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

kernel/trace/trace.c

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

58935893
/* If trace pipe files are being read, we can't change the tracer */
5894-
if (tr->current_trace->ref) {
5894+
if (tr->trace_ref) {
58955895
ret = -EBUSY;
58965896
goto out;
58975897
}
@@ -6107,7 +6107,7 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp)
61076107

61086108
nonseekable_open(inode, filp);
61096109

6110-
tr->current_trace->ref++;
6110+
tr->trace_ref++;
61116111
out:
61126112
mutex_unlock(&trace_types_lock);
61136113
return ret;
@@ -6126,7 +6126,7 @@ static int tracing_release_pipe(struct inode *inode, struct file *file)
61266126

61276127
mutex_lock(&trace_types_lock);
61286128

6129-
tr->current_trace->ref--;
6129+
tr->trace_ref--;
61306130

61316131
if (iter->trace->pipe_close)
61326132
iter->trace->pipe_close(iter);
@@ -7428,7 +7428,7 @@ static int tracing_buffers_open(struct inode *inode, struct file *filp)
74287428

74297429
filp->private_data = info;
74307430

7431-
tr->current_trace->ref++;
7431+
tr->trace_ref++;
74327432

74337433
mutex_unlock(&trace_types_lock);
74347434

@@ -7529,7 +7529,7 @@ static int tracing_buffers_release(struct inode *inode, struct file *file)
75297529

75307530
mutex_lock(&trace_types_lock);
75317531

7532-
iter->tr->current_trace->ref--;
7532+
iter->tr->trace_ref--;
75337533

75347534
__trace_array_put(iter->tr);
75357535

@@ -8737,7 +8737,7 @@ static int __remove_instance(struct trace_array *tr)
87378737
int i;
87388738

87398739
/* Reference counter for a newly created trace array = 1. */
8740-
if (tr->ref > 1 || (tr->current_trace && tr->current_trace->ref))
8740+
if (tr->ref > 1 || (tr->current_trace && tr->trace_ref))
87418741
return -EBUSY;
87428742

87438743
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)