Skip to content

Commit 21581dd

Browse files
douglas-raillard-armrostedt
authored andcommitted
tracing: Ensure module defining synth event cannot be unloaded while tracing
Currently, using synth_event_delete() will fail if the event is being used (tracing in progress), but that is normally done in the module exit function. At that stage, failing is problematic as returning a non-zero status means the module will become locked (impossible to unload or reload again). Instead, ensure the module exit function does not get called in the first place by increasing the module refcnt when the event is enabled. Cc: stable@vger.kernel.org Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Fixes: 35ca520 ("tracing: Add synthetic event command generation functions") Link: https://lore.kernel.org/20250318180906.226841-1-douglas.raillard@arm.com Signed-off-by: Douglas Raillard <douglas.raillard@arm.com> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 0c588ac commit 21581dd

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

kernel/trace/trace_events_synth.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,34 @@ static struct trace_event_fields synth_event_fields_array[] = {
852852
{}
853853
};
854854

855+
static int synth_event_reg(struct trace_event_call *call,
856+
enum trace_reg type, void *data)
857+
{
858+
struct synth_event *event = container_of(call, struct synth_event, call);
859+
860+
switch (type) {
861+
case TRACE_REG_REGISTER:
862+
case TRACE_REG_PERF_REGISTER:
863+
if (!try_module_get(event->mod))
864+
return -EBUSY;
865+
break;
866+
default:
867+
break;
868+
}
869+
870+
int ret = trace_event_reg(call, type, data);
871+
872+
switch (type) {
873+
case TRACE_REG_UNREGISTER:
874+
case TRACE_REG_PERF_UNREGISTER:
875+
module_put(event->mod);
876+
break;
877+
default:
878+
break;
879+
}
880+
return ret;
881+
}
882+
855883
static int register_synth_event(struct synth_event *event)
856884
{
857885
struct trace_event_call *call = &event->call;
@@ -881,7 +909,7 @@ static int register_synth_event(struct synth_event *event)
881909
goto out;
882910
}
883911
call->flags = TRACE_EVENT_FL_TRACEPOINT;
884-
call->class->reg = trace_event_reg;
912+
call->class->reg = synth_event_reg;
885913
call->class->probe = trace_event_raw_event_synth;
886914
call->data = event;
887915
call->tp = event->tp;

0 commit comments

Comments
 (0)