Skip to content

Commit b196e2b

Browse files
committed
tracing: Warn if a tracepoint is not set via debugfs
Tracepoints were made to allow enabling a tracepoint in a module before that module was loaded. When a tracepoint is enabled and it does not exist, the name is stored and will be enabled when the tracepoint is created. The problem with this approach is that when a tracepoint is enabled when it expects to be there, it gives no warning that it does not exist. To add salt to the wound, if a module is added and sets the FORCED flag, which can happen if it isn't signed properly, the tracepoint code will not enabled the tracepoints, but they will be created in the debugfs system! When a user goes to enable the tracepoint, the tracepoint code will not see it existing and will think it is to be enabled later AND WILL NOT GIVE A WARNING. The tracing will look like it succeeded but will actually be doing nothing. This will cause lots of confusion and headaches for developers trying to figure out why they are not seeing their tracepoints. Link: http://lkml.kernel.org/r/20140213154507.4040fb06@gandalf.local.home Reported-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Reported-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 3fd40d1 commit b196e2b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎kernel/tracepoint.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct tracepoint_entry {
6262
struct hlist_node hlist;
6363
struct tracepoint_func *funcs;
6464
int refcount; /* Number of times armed. 0 if disarmed. */
65+
int enabled; /* Tracepoint enabled */
6566
char name[0];
6667
};
6768

@@ -237,6 +238,7 @@ static struct tracepoint_entry *add_tracepoint(const char *name)
237238
memcpy(&e->name[0], name, name_len);
238239
e->funcs = NULL;
239240
e->refcount = 0;
241+
e->enabled = 0;
240242
hlist_add_head(&e->hlist, head);
241243
return e;
242244
}
@@ -316,6 +318,7 @@ static void tracepoint_update_probe_range(struct tracepoint * const *begin,
316318
if (mark_entry) {
317319
set_tracepoint(&mark_entry, *iter,
318320
!!mark_entry->refcount);
321+
mark_entry->enabled = !!mark_entry->refcount;
319322
} else {
320323
disable_tracepoint(*iter);
321324
}
@@ -380,6 +383,8 @@ tracepoint_add_probe(const char *name, void *probe, void *data)
380383
int tracepoint_probe_register(const char *name, void *probe, void *data)
381384
{
382385
struct tracepoint_func *old;
386+
struct tracepoint_entry *entry;
387+
int ret = 0;
383388

384389
mutex_lock(&tracepoints_mutex);
385390
old = tracepoint_add_probe(name, probe, data);
@@ -388,9 +393,13 @@ int tracepoint_probe_register(const char *name, void *probe, void *data)
388393
return PTR_ERR(old);
389394
}
390395
tracepoint_update_probes(); /* may update entry */
396+
entry = get_tracepoint(name);
397+
/* Make sure the entry was enabled */
398+
if (!entry || !entry->enabled)
399+
ret = -ENODEV;
391400
mutex_unlock(&tracepoints_mutex);
392401
release_probes(old);
393-
return 0;
402+
return ret;
394403
}
395404
EXPORT_SYMBOL_GPL(tracepoint_probe_register);
396405

0 commit comments

Comments
 (0)