Skip to content

Commit fc128e8

Browse files
douglas-raillard-armgregkh
authored andcommitted
tracing: Ensure module defining synth event cannot be unloaded while tracing
commit 21581dd upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 099ef33 commit fc128e8

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

kernel/trace/trace_events_synth.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,34 @@ static struct trace_event_fields synth_event_fields_array[] = {
859859
{}
860860
};
861861

862+
static int synth_event_reg(struct trace_event_call *call,
863+
enum trace_reg type, void *data)
864+
{
865+
struct synth_event *event = container_of(call, struct synth_event, call);
866+
867+
switch (type) {
868+
case TRACE_REG_REGISTER:
869+
case TRACE_REG_PERF_REGISTER:
870+
if (!try_module_get(event->mod))
871+
return -EBUSY;
872+
break;
873+
default:
874+
break;
875+
}
876+
877+
int ret = trace_event_reg(call, type, data);
878+
879+
switch (type) {
880+
case TRACE_REG_UNREGISTER:
881+
case TRACE_REG_PERF_UNREGISTER:
882+
module_put(event->mod);
883+
break;
884+
default:
885+
break;
886+
}
887+
return ret;
888+
}
889+
862890
static int register_synth_event(struct synth_event *event)
863891
{
864892
struct trace_event_call *call = &event->call;
@@ -888,7 +916,7 @@ static int register_synth_event(struct synth_event *event)
888916
goto out;
889917
}
890918
call->flags = TRACE_EVENT_FL_TRACEPOINT;
891-
call->class->reg = trace_event_reg;
919+
call->class->reg = synth_event_reg;
892920
call->class->probe = trace_event_raw_event_synth;
893921
call->data = event;
894922
call->tp = event->tp;

0 commit comments

Comments
 (0)