Skip to content

Commit 12ecef0

Browse files
committed
tracing: Reverse the order of trace_types_lock and event_mutex
In order to make future changes where we need to call tracing_set_clock() from within an event command, the order of trace_types_lock and event_mutex must be reversed, as the event command will hold event_mutex and the trace_types_lock is taken from within tracing_set_clock(). Link: http://lkml.kernel.org/r/[email protected] Requested-by: Tom Zanussi <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 6e7a239 commit 12ecef0

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

kernel/trace/trace.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7687,6 +7687,7 @@ static int instance_mkdir(const char *name)
76877687
struct trace_array *tr;
76887688
int ret;
76897689

7690+
mutex_lock(&event_mutex);
76907691
mutex_lock(&trace_types_lock);
76917692

76927693
ret = -EEXIST;
@@ -7742,6 +7743,7 @@ static int instance_mkdir(const char *name)
77427743
list_add(&tr->list, &ftrace_trace_arrays);
77437744

77447745
mutex_unlock(&trace_types_lock);
7746+
mutex_unlock(&event_mutex);
77457747

77467748
return 0;
77477749

@@ -7753,6 +7755,7 @@ static int instance_mkdir(const char *name)
77537755

77547756
out_unlock:
77557757
mutex_unlock(&trace_types_lock);
7758+
mutex_unlock(&event_mutex);
77567759

77577760
return ret;
77587761

@@ -7765,6 +7768,7 @@ static int instance_rmdir(const char *name)
77657768
int ret;
77667769
int i;
77677770

7771+
mutex_lock(&event_mutex);
77687772
mutex_lock(&trace_types_lock);
77697773

77707774
ret = -ENODEV;
@@ -7810,6 +7814,7 @@ static int instance_rmdir(const char *name)
78107814

78117815
out_unlock:
78127816
mutex_unlock(&trace_types_lock);
7817+
mutex_unlock(&event_mutex);
78137818

78147819
return ret;
78157820
}

kernel/trace/trace_events.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,8 +1406,8 @@ static int subsystem_open(struct inode *inode, struct file *filp)
14061406
return -ENODEV;
14071407

14081408
/* Make sure the system still exists */
1409-
mutex_lock(&trace_types_lock);
14101409
mutex_lock(&event_mutex);
1410+
mutex_lock(&trace_types_lock);
14111411
list_for_each_entry(tr, &ftrace_trace_arrays, list) {
14121412
list_for_each_entry(dir, &tr->systems, list) {
14131413
if (dir == inode->i_private) {
@@ -1421,8 +1421,8 @@ static int subsystem_open(struct inode *inode, struct file *filp)
14211421
}
14221422
}
14231423
exit_loop:
1424-
mutex_unlock(&event_mutex);
14251424
mutex_unlock(&trace_types_lock);
1425+
mutex_unlock(&event_mutex);
14261426

14271427
if (!system)
14281428
return -ENODEV;
@@ -2294,15 +2294,15 @@ static void __add_event_to_tracers(struct trace_event_call *call);
22942294
int trace_add_event_call(struct trace_event_call *call)
22952295
{
22962296
int ret;
2297-
mutex_lock(&trace_types_lock);
22982297
mutex_lock(&event_mutex);
2298+
mutex_lock(&trace_types_lock);
22992299

23002300
ret = __register_event(call, NULL);
23012301
if (ret >= 0)
23022302
__add_event_to_tracers(call);
23032303

2304-
mutex_unlock(&event_mutex);
23052304
mutex_unlock(&trace_types_lock);
2305+
mutex_unlock(&event_mutex);
23062306
return ret;
23072307
}
23082308

@@ -2356,13 +2356,13 @@ int trace_remove_event_call(struct trace_event_call *call)
23562356
{
23572357
int ret;
23582358

2359-
mutex_lock(&trace_types_lock);
23602359
mutex_lock(&event_mutex);
2360+
mutex_lock(&trace_types_lock);
23612361
down_write(&trace_event_sem);
23622362
ret = probe_remove_event_call(call);
23632363
up_write(&trace_event_sem);
2364-
mutex_unlock(&event_mutex);
23652364
mutex_unlock(&trace_types_lock);
2365+
mutex_unlock(&event_mutex);
23662366

23672367
return ret;
23682368
}
@@ -2424,8 +2424,8 @@ static int trace_module_notify(struct notifier_block *self,
24242424
{
24252425
struct module *mod = data;
24262426

2427-
mutex_lock(&trace_types_lock);
24282427
mutex_lock(&event_mutex);
2428+
mutex_lock(&trace_types_lock);
24292429
switch (val) {
24302430
case MODULE_STATE_COMING:
24312431
trace_module_add_events(mod);
@@ -2434,8 +2434,8 @@ static int trace_module_notify(struct notifier_block *self,
24342434
trace_module_remove_events(mod);
24352435
break;
24362436
}
2437-
mutex_unlock(&event_mutex);
24382437
mutex_unlock(&trace_types_lock);
2438+
mutex_unlock(&event_mutex);
24392439

24402440
return 0;
24412441
}
@@ -2950,24 +2950,24 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr)
29502950
* creates the event hierachry in the @parent/events directory.
29512951
*
29522952
* Returns 0 on success.
2953+
*
2954+
* Must be called with event_mutex held.
29532955
*/
29542956
int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr)
29552957
{
29562958
int ret;
29572959

2958-
mutex_lock(&event_mutex);
2960+
lockdep_assert_held(&event_mutex);
29592961

29602962
ret = create_event_toplevel_files(parent, tr);
29612963
if (ret)
2962-
goto out_unlock;
2964+
goto out;
29632965

29642966
down_write(&trace_event_sem);
29652967
__trace_add_event_dirs(tr);
29662968
up_write(&trace_event_sem);
29672969

2968-
out_unlock:
2969-
mutex_unlock(&event_mutex);
2970-
2970+
out:
29712971
return ret;
29722972
}
29732973

@@ -2996,9 +2996,10 @@ early_event_add_tracer(struct dentry *parent, struct trace_array *tr)
29962996
return ret;
29972997
}
29982998

2999+
/* Must be called with event_mutex held */
29993000
int event_trace_del_tracer(struct trace_array *tr)
30003001
{
3001-
mutex_lock(&event_mutex);
3002+
lockdep_assert_held(&event_mutex);
30023003

30033004
/* Disable any event triggers and associated soft-disabled events */
30043005
clear_event_triggers(tr);
@@ -3019,8 +3020,6 @@ int event_trace_del_tracer(struct trace_array *tr)
30193020

30203021
tr->event_dir = NULL;
30213022

3022-
mutex_unlock(&event_mutex);
3023-
30243023
return 0;
30253024
}
30263025

0 commit comments

Comments
 (0)