Skip to content

Commit 47c7efa

Browse files
committed
Merge tag 'probes-fixes-v6.14-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull probes fixes from Masami Hiramatsu: - Clean up tprobe correctly when module unload Tracepoint probes do not set TRACEPOINT_STUB on the 'tpoint' pointer when unloading a module, thus they show as a normal 'fprobe' instead of 'tprobe' and never come back - Fix leakage of tprobe module refcount When a tprobe's target module is loaded, it gets the module's refcount in the module notifier but forgot to put it after registering the probe on it. Fix it by getting the refcount only when registering tprobe. * tag 'probes-fixes-v6.14-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: tracing: tprobe-events: Fix leakage of module refcount tracing: tprobe-events: Fix to clean up tprobe correctly when module unload
2 parents 4701f33 + ac91052 commit 47c7efa

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

kernel/trace/trace_fprobe.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -920,13 +920,8 @@ static void __find_tracepoint_module_cb(struct tracepoint *tp, struct module *mo
920920

921921
if (!data->tpoint && !strcmp(data->tp_name, tp->name)) {
922922
data->tpoint = tp;
923-
if (!data->mod) {
923+
if (!data->mod)
924924
data->mod = mod;
925-
if (!try_module_get(data->mod)) {
926-
data->tpoint = NULL;
927-
data->mod = NULL;
928-
}
929-
}
930925
}
931926
}
932927

@@ -938,13 +933,7 @@ static void __find_tracepoint_cb(struct tracepoint *tp, void *priv)
938933
data->tpoint = tp;
939934
}
940935

941-
/*
942-
* Find a tracepoint from kernel and module. If the tracepoint is in a module,
943-
* this increments the module refcount to prevent unloading until the
944-
* trace_fprobe is registered to the list. After registering the trace_fprobe
945-
* on the trace_fprobe list, the module refcount is decremented because
946-
* tracepoint_probe_module_cb will handle it.
947-
*/
936+
/* Find a tracepoint from kernel and module. */
948937
static struct tracepoint *find_tracepoint(const char *tp_name,
949938
struct module **tp_mod)
950939
{
@@ -973,6 +962,7 @@ static void reenable_trace_fprobe(struct trace_fprobe *tf)
973962
}
974963
}
975964

965+
/* Find a tracepoint from specified module. */
976966
static struct tracepoint *find_tracepoint_in_module(struct module *mod,
977967
const char *tp_name)
978968
{
@@ -1008,10 +998,13 @@ static int __tracepoint_probe_module_cb(struct notifier_block *self,
1008998
reenable_trace_fprobe(tf);
1009999
}
10101000
} else if (val == MODULE_STATE_GOING && tp_mod->mod == tf->mod) {
1011-
tracepoint_probe_unregister(tf->tpoint,
1001+
unregister_fprobe(&tf->fp);
1002+
if (trace_fprobe_is_tracepoint(tf)) {
1003+
tracepoint_probe_unregister(tf->tpoint,
10121004
tf->tpoint->probestub, NULL);
1013-
tf->tpoint = NULL;
1014-
tf->mod = NULL;
1005+
tf->tpoint = TRACEPOINT_STUB;
1006+
tf->mod = NULL;
1007+
}
10151008
}
10161009
}
10171010
mutex_unlock(&event_mutex);
@@ -1176,6 +1169,11 @@ static int trace_fprobe_create_internal(int argc, const char *argv[],
11761169
if (is_tracepoint) {
11771170
ctx->flags |= TPARG_FL_TPOINT;
11781171
tpoint = find_tracepoint(symbol, &tp_mod);
1172+
/* lock module until register this tprobe. */
1173+
if (tp_mod && !try_module_get(tp_mod)) {
1174+
tpoint = NULL;
1175+
tp_mod = NULL;
1176+
}
11791177
if (tpoint) {
11801178
ctx->funcname = kallsyms_lookup(
11811179
(unsigned long)tpoint->probestub,

0 commit comments

Comments
 (0)