Skip to content

Commit 8b0e6c7

Browse files
committed
tracing: Add DYNAMIC flag for dynamic events
To differentiate between static and dynamic events, add a new flag DYNAMIC to the event flags that all dynamic events have set. This will allow to differentiate when attaching to a dynamic event from a static event. Static events have a mod pointer that references the module they were created in (or NULL for core kernel). This can be incremented when the event has something attached to it. But there exists no such mechanism for dynamic events. This is dangerous as the dynamic events may now disappear without the "attachment" knowing that it no longer exists. To enforce the dynamic flag, change dyn_event_add() to pass the event that is being created such that it can set the DYNAMIC flag of the event. This helps make sure that no location that creates a dynamic event misses setting this flag. Link: https://lore.kernel.org/linux-trace-devel/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Suggested-by: Masami Hiramatsu <[email protected]> Acked-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 99c37d1 commit 8b0e6c7

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

include/linux/trace_events.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ enum {
310310
TRACE_EVENT_FL_NO_SET_FILTER_BIT,
311311
TRACE_EVENT_FL_IGNORE_ENABLE_BIT,
312312
TRACE_EVENT_FL_TRACEPOINT_BIT,
313+
TRACE_EVENT_FL_DYNAMIC_BIT,
313314
TRACE_EVENT_FL_KPROBE_BIT,
314315
TRACE_EVENT_FL_UPROBE_BIT,
315316
};
@@ -321,6 +322,7 @@ enum {
321322
* NO_SET_FILTER - Set when filter has error and is to be ignored
322323
* IGNORE_ENABLE - For trace internal events, do not enable with debugfs file
323324
* TRACEPOINT - Event is a tracepoint
325+
* DYNAMIC - Event is a dynamic event (created at run time)
324326
* KPROBE - Event is a kprobe
325327
* UPROBE - Event is a uprobe
326328
*/
@@ -330,6 +332,7 @@ enum {
330332
TRACE_EVENT_FL_NO_SET_FILTER = (1 << TRACE_EVENT_FL_NO_SET_FILTER_BIT),
331333
TRACE_EVENT_FL_IGNORE_ENABLE = (1 << TRACE_EVENT_FL_IGNORE_ENABLE_BIT),
332334
TRACE_EVENT_FL_TRACEPOINT = (1 << TRACE_EVENT_FL_TRACEPOINT_BIT),
335+
TRACE_EVENT_FL_DYNAMIC = (1 << TRACE_EVENT_FL_DYNAMIC_BIT),
333336
TRACE_EVENT_FL_KPROBE = (1 << TRACE_EVENT_FL_KPROBE_BIT),
334337
TRACE_EVENT_FL_UPROBE = (1 << TRACE_EVENT_FL_UPROBE_BIT),
335338
};

kernel/trace/trace_dynevent.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ int dyn_event_init(struct dyn_event *ev, struct dyn_event_operations *ops)
7676
return 0;
7777
}
7878

79-
static inline int dyn_event_add(struct dyn_event *ev)
79+
static inline int dyn_event_add(struct dyn_event *ev,
80+
struct trace_event_call *call)
8081
{
8182
lockdep_assert_held(&event_mutex);
8283

8384
if (!ev || !ev->ops)
8485
return -EINVAL;
8586

87+
call->flags |= TRACE_EVENT_FL_DYNAMIC;
8688
list_add_tail(&ev->list, &dyn_event_list);
8789
return 0;
8890
}

kernel/trace/trace_events_synth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ static int __create_synth_event(const char *name, const char *raw_fields)
12981298
}
12991299
ret = register_synth_event(event);
13001300
if (!ret)
1301-
dyn_event_add(&event->devent);
1301+
dyn_event_add(&event->devent, &event->call);
13021302
else
13031303
free_synth_event(event);
13041304
out:

kernel/trace/trace_kprobe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ static int append_trace_kprobe(struct trace_kprobe *tk, struct trace_kprobe *to)
618618
if (ret)
619619
trace_probe_unlink(&tk->tp);
620620
else
621-
dyn_event_add(&tk->devent);
621+
dyn_event_add(&tk->devent, trace_probe_event_call(&tk->tp));
622622

623623
return ret;
624624
}
@@ -661,7 +661,7 @@ static int register_trace_kprobe(struct trace_kprobe *tk)
661661
if (ret < 0)
662662
unregister_kprobe_event(tk);
663663
else
664-
dyn_event_add(&tk->devent);
664+
dyn_event_add(&tk->devent, trace_probe_event_call(&tk->tp));
665665

666666
end:
667667
mutex_unlock(&event_mutex);

kernel/trace/trace_uprobe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static int append_trace_uprobe(struct trace_uprobe *tu, struct trace_uprobe *to)
455455
/* Append to existing event */
456456
ret = trace_probe_append(&tu->tp, &to->tp);
457457
if (!ret)
458-
dyn_event_add(&tu->devent);
458+
dyn_event_add(&tu->devent, trace_probe_event_call(&tu->tp));
459459

460460
return ret;
461461
}
@@ -518,7 +518,7 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
518518
goto end;
519519
}
520520

521-
dyn_event_add(&tu->devent);
521+
dyn_event_add(&tu->devent, trace_probe_event_call(&tu->tp));
522522

523523
end:
524524
mutex_unlock(&event_mutex);

0 commit comments

Comments
 (0)