Skip to content

Commit 372e0d0

Browse files
committed
ftrace: Check for empty hash and comment the race with registering probes
The race between adding a function probe and reading the probes that exist is very subtle. It needs a comment. Also, the issue can also happen if the probe has has the EMPTY_HASH as its func_hash. Cc: [email protected] Fixes: 7b60f3d ("ftrace: Dynamically create the probe ftrace_ops for the trace_array") Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 7bd4664 commit 372e0d0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

kernel/trace/ftrace.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3096,7 +3096,11 @@ t_probe_next(struct seq_file *m, loff_t *pos)
30963096

30973097
hash = iter->probe->ops.func_hash->filter_hash;
30983098

3099-
if (!hash)
3099+
/*
3100+
* A probe being registered may temporarily have an empty hash
3101+
* and it's at the end of the func_probes list.
3102+
*/
3103+
if (!hash || hash == EMPTY_HASH)
31003104
return NULL;
31013105

31023106
size = 1 << hash->size_bits;
@@ -4324,6 +4328,10 @@ register_ftrace_function_probe(char *glob, struct trace_array *tr,
43244328

43254329
mutex_unlock(&ftrace_lock);
43264330

4331+
/*
4332+
* Note, there's a small window here that the func_hash->filter_hash
4333+
* may be NULL or empty. Need to be carefule when reading the loop.
4334+
*/
43274335
mutex_lock(&probe->ops.func_hash->regex_lock);
43284336

43294337
orig_hash = &probe->ops.func_hash->filter_hash;

0 commit comments

Comments
 (0)