Skip to content

Commit cb525a6

Browse files
committed
Merge tag 'trace-v6.1-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull tracing fixes from Steven Rostedt: - Fix osnoise duration type to 64bit not 32bit - Have histogram triggers be able to handle an unexpected NULL pointer for the record event, which can happen when the histogram first starts up - Clear out ring buffers when dynamic events are removed, as the type that is saved in the ring buffer is used to read the event, and a stale type that is reused by another event could cause use after free issues - Trivial comment fix - Fix memory leak in user_event_create() * tag 'trace-v6.1-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: tracing: Free buffers when a used dynamic event is removed tracing: Add tracing_reset_all_online_cpus_unlocked() function tracing: Fix race where histograms can be called before the event tracing/osnoise: Fix duration type tracing/user_events: Fix memory leak in user_event_create() tracing/hist: add in missing * in comment blocks
2 parents f35badc + 4313e5a commit cb525a6

File tree

8 files changed

+35
-11
lines changed

8 files changed

+35
-11
lines changed

kernel/trace/trace.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,10 +2180,12 @@ void tracing_reset_online_cpus(struct array_buffer *buf)
21802180
}
21812181

21822182
/* Must have trace_types_lock held */
2183-
void tracing_reset_all_online_cpus(void)
2183+
void tracing_reset_all_online_cpus_unlocked(void)
21842184
{
21852185
struct trace_array *tr;
21862186

2187+
lockdep_assert_held(&trace_types_lock);
2188+
21872189
list_for_each_entry(tr, &ftrace_trace_arrays, list) {
21882190
if (!tr->clear_trace)
21892191
continue;
@@ -2195,6 +2197,13 @@ void tracing_reset_all_online_cpus(void)
21952197
}
21962198
}
21972199

2200+
void tracing_reset_all_online_cpus(void)
2201+
{
2202+
mutex_lock(&trace_types_lock);
2203+
tracing_reset_all_online_cpus_unlocked();
2204+
mutex_unlock(&trace_types_lock);
2205+
}
2206+
21982207
/*
21992208
* The tgid_map array maps from pid to tgid; i.e. the value stored at index i
22002209
* is the tgid last observed corresponding to pid=i.

kernel/trace/trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ int tracing_is_enabled(void);
580580
void tracing_reset_online_cpus(struct array_buffer *buf);
581581
void tracing_reset_current(int cpu);
582582
void tracing_reset_all_online_cpus(void);
583+
void tracing_reset_all_online_cpus_unlocked(void);
583584
int tracing_open_generic(struct inode *inode, struct file *filp);
584585
int tracing_open_generic_tr(struct inode *inode, struct file *filp);
585586
bool tracing_is_disabled(void);

kernel/trace/trace_dynevent.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ int dyn_event_release(const char *raw_command, struct dyn_event_operations *type
118118
if (ret)
119119
break;
120120
}
121+
tracing_reset_all_online_cpus();
121122
mutex_unlock(&event_mutex);
122123
out:
123124
argv_free(argv);
@@ -214,6 +215,7 @@ int dyn_events_release_all(struct dyn_event_operations *type)
214215
break;
215216
}
216217
out:
218+
tracing_reset_all_online_cpus();
217219
mutex_unlock(&event_mutex);
218220

219221
return ret;

kernel/trace/trace_events.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,7 +2880,10 @@ static int probe_remove_event_call(struct trace_event_call *call)
28802880
* TRACE_REG_UNREGISTER.
28812881
*/
28822882
if (file->flags & EVENT_FILE_FL_ENABLED)
2883-
return -EBUSY;
2883+
goto busy;
2884+
2885+
if (file->flags & EVENT_FILE_FL_WAS_ENABLED)
2886+
tr->clear_trace = true;
28842887
/*
28852888
* The do_for_each_event_file_safe() is
28862889
* a double loop. After finding the call for this
@@ -2893,6 +2896,12 @@ static int probe_remove_event_call(struct trace_event_call *call)
28932896
__trace_remove_event_call(call);
28942897

28952898
return 0;
2899+
busy:
2900+
/* No need to clear the trace now */
2901+
list_for_each_entry(tr, &ftrace_trace_arrays, list) {
2902+
tr->clear_trace = false;
2903+
}
2904+
return -EBUSY;
28962905
}
28972906

28982907
/* Remove an event_call */
@@ -2972,7 +2981,7 @@ static void trace_module_remove_events(struct module *mod)
29722981
* over from this module may be passed to the new module events and
29732982
* unexpected results may occur.
29742983
*/
2975-
tracing_reset_all_online_cpus();
2984+
tracing_reset_all_online_cpus_unlocked();
29762985
}
29772986

29782987
static int trace_module_notify(struct notifier_block *self,

kernel/trace/trace_events_hist.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ static struct hist_field *find_any_var_ref(struct hist_trigger_data *hist_data,
983983
* A trigger can define one or more variables. If any one of them is
984984
* currently referenced by any other trigger, this function will
985985
* determine that.
986-
986+
*
987987
* Typically used to determine whether or not a trigger can be removed
988988
* - if there are any references to a trigger's variables, it cannot.
989989
*
@@ -3226,7 +3226,7 @@ static struct field_var *create_field_var(struct hist_trigger_data *hist_data,
32263226
* events. However, for convenience, users are allowed to directly
32273227
* specify an event field in an action, which will be automatically
32283228
* converted into a variable on their behalf.
3229-
3229+
*
32303230
* This function creates a field variable with the name var_name on
32313231
* the hist trigger currently being defined on the target event. If
32323232
* subsys_name and event_name are specified, this function simply
@@ -5143,6 +5143,9 @@ static void event_hist_trigger(struct event_trigger_data *data,
51435143
void *key = NULL;
51445144
unsigned int i;
51455145

5146+
if (unlikely(!rbe))
5147+
return;
5148+
51465149
memset(compound_key, 0, hist_data->key_size);
51475150

51485151
for_each_hist_key_field(i, hist_data) {

kernel/trace/trace_events_synth.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,6 @@ int synth_event_delete(const char *event_name)
14251425
mutex_unlock(&event_mutex);
14261426

14271427
if (mod) {
1428-
mutex_lock(&trace_types_lock);
14291428
/*
14301429
* It is safest to reset the ring buffer if the module
14311430
* being unloaded registered any events that were
@@ -1437,7 +1436,6 @@ int synth_event_delete(const char *event_name)
14371436
* occur.
14381437
*/
14391438
tracing_reset_all_online_cpus();
1440-
mutex_unlock(&trace_types_lock);
14411439
}
14421440

14431441
return ret;

kernel/trace/trace_events_user.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,10 @@ static int user_event_create(const char *raw_command)
11001100

11011101
group = current_user_event_group();
11021102

1103-
if (!group)
1103+
if (!group) {
1104+
kfree(name);
11041105
return -ENOENT;
1106+
}
11051107

11061108
mutex_lock(&group->reg_mutex);
11071109

kernel/trace/trace_osnoise.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ void osnoise_trace_irq_entry(int id)
917917
void osnoise_trace_irq_exit(int id, const char *desc)
918918
{
919919
struct osnoise_variables *osn_var = this_cpu_osn_var();
920-
int duration;
920+
s64 duration;
921921

922922
if (!osn_var->sampling)
923923
return;
@@ -1048,7 +1048,7 @@ static void trace_softirq_entry_callback(void *data, unsigned int vec_nr)
10481048
static void trace_softirq_exit_callback(void *data, unsigned int vec_nr)
10491049
{
10501050
struct osnoise_variables *osn_var = this_cpu_osn_var();
1051-
int duration;
1051+
s64 duration;
10521052

10531053
if (!osn_var->sampling)
10541054
return;
@@ -1144,7 +1144,7 @@ thread_entry(struct osnoise_variables *osn_var, struct task_struct *t)
11441144
static void
11451145
thread_exit(struct osnoise_variables *osn_var, struct task_struct *t)
11461146
{
1147-
int duration;
1147+
s64 duration;
11481148

11491149
if (!osn_var->sampling)
11501150
return;

0 commit comments

Comments
 (0)