Skip to content

Commit 0bbe7f7

Browse files
yangx-jyrostedt
authored andcommitted
tracing: Fix the race between registering 'snapshot' event trigger and triggering 'snapshot' operation
Traced event can trigger 'snapshot' operation(i.e. calls snapshot_trigger() or snapshot_count_trigger()) when register_snapshot_trigger() has completed registration but doesn't allocate buffer for 'snapshot' event trigger. In the rare case, 'snapshot' operation always detects the lack of allocated buffer so make register_snapshot_trigger() allocate buffer first. trigger-snapshot.tc in kselftest reproduces the issue on slow vm: ----------------------------------------------------------- cat trace ... ftracetest-3028 [002] .... 236.784290: sched_process_fork: comm=ftracetest pid=3028 child_comm=ftracetest child_pid=3036 <...>-2875 [003] .... 240.460335: tracing_snapshot_instance_cond: *** SNAPSHOT NOT ALLOCATED *** <...>-2875 [003] .... 240.460338: tracing_snapshot_instance_cond: *** stopping trace here! *** ----------------------------------------------------------- Link: http://lkml.kernel.org/r/[email protected] Cc: [email protected] Fixes: 93e31ff ("tracing: Add 'snapshot' event trigger command") Signed-off-by: Xiao Yang <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 8f3d9f3 commit 0bbe7f7

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

kernel/trace/trace_events_trigger.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,14 +1088,10 @@ register_snapshot_trigger(char *glob, struct event_trigger_ops *ops,
10881088
struct event_trigger_data *data,
10891089
struct trace_event_file *file)
10901090
{
1091-
int ret = register_trigger(glob, ops, data, file);
1092-
1093-
if (ret > 0 && tracing_alloc_snapshot_instance(file->tr) != 0) {
1094-
unregister_trigger(glob, ops, data, file);
1095-
ret = 0;
1096-
}
1091+
if (tracing_alloc_snapshot_instance(file->tr) != 0)
1092+
return 0;
10971093

1098-
return ret;
1094+
return register_trigger(glob, ops, data, file);
10991095
}
11001096

11011097
static int

0 commit comments

Comments
 (0)