Skip to content

Commit bb9616b

Browse files
douglas-raillard-armgregkh
authored andcommitted
tracing: Ensure module defining synth event cannot be unloaded while tracing
commit 21581dd4e7ff6c07d0ab577e3c32b13a74b31522 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: [email protected] Cc: Mathieu Desnoyers <[email protected]> Fixes: 35ca520 ("tracing: Add synthetic event command generation functions") Link: https://lore.kernel.org/[email protected] Signed-off-by: Douglas Raillard <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a2cce54 commit bb9616b

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
@@ -875,6 +875,34 @@ static struct trace_event_fields synth_event_fields_array[] = {
875875
{}
876876
};
877877

878+
static int synth_event_reg(struct trace_event_call *call,
879+
enum trace_reg type, void *data)
880+
{
881+
struct synth_event *event = container_of(call, struct synth_event, call);
882+
883+
switch (type) {
884+
case TRACE_REG_REGISTER:
885+
case TRACE_REG_PERF_REGISTER:
886+
if (!try_module_get(event->mod))
887+
return -EBUSY;
888+
break;
889+
default:
890+
break;
891+
}
892+
893+
int ret = trace_event_reg(call, type, data);
894+
895+
switch (type) {
896+
case TRACE_REG_UNREGISTER:
897+
case TRACE_REG_PERF_UNREGISTER:
898+
module_put(event->mod);
899+
break;
900+
default:
901+
break;
902+
}
903+
return ret;
904+
}
905+
878906
static int register_synth_event(struct synth_event *event)
879907
{
880908
struct trace_event_call *call = &event->call;
@@ -904,7 +932,7 @@ static int register_synth_event(struct synth_event *event)
904932
goto out;
905933
}
906934
call->flags = TRACE_EVENT_FL_TRACEPOINT;
907-
call->class->reg = trace_event_reg;
935+
call->class->reg = synth_event_reg;
908936
call->class->probe = trace_event_raw_event_synth;
909937
call->data = event;
910938
call->tp = event->tp;

0 commit comments

Comments
 (0)