Skip to contentSkip to conversation

ftrace: Have ftrace_free_filter() WARN and exit if ops is active

PATCH In review Steven Rostedt 2 participants 2 messages Feb 19, 2025 – Feb 20, 2025

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 ftrace: Have ftrace_free_filter() WARN and exit if ops is active

From: Steven Rostedt <[email protected]>

The ftrace_free_filter() is used to reset the ops filters. But it must be done if the ops is not currently active (tracing). If it is, it will mess up the ftrace accounting of what functions are attached and what is not.

WARN and exit the ftrace_free_filter() if the ops is active when it is called.

Currently, it doesn't seem if anything does this, but it may in the future.

---
 kernel/trace/ftrace.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/ftrace.c +2 -0
index 189eb0a12f4b..4f6cad3b05b2 100644
@@ -1296,6 +1296,8 @@ static void free_ftrace_hash_rcu(struct ftrace_hash *hash)
 void ftrace_free_filter(struct ftrace_ops *ops)
 {
 	ftrace_ops_init(ops);
+	if (WARN_ON(ops->flags & FTRACE_OPS_FL_ENABLED))
+		return;
 	free_ftrace_hash(ops->func_hash->filter_hash);
 	free_ftrace_hash(ops->func_hash->notrace_hash);
 }
Signature · 1 line
2.47.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Wed, 19 Feb 2025 13:50:40 -0500 Steven Rostedt <[email protected]> wrote:

From: Steven Rostedt <[email protected]>

The ftrace_free_filter() is used to reset the ops filters. But it must be done if the ops is not currently active (tracing). If it is, it will mess up the ftrace accounting of what functions are attached and what is not.

WARN and exit the ftrace_free_filter() if the ops is active when it is called.

Quoted 6 lines

Currently, it doesn't seem if anything does this, but it may in the future.

Looks good to me.

Thanks,

Quoted 20 lines
---
 kernel/trace/ftrace.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/ftrace.c +2 -0
index 189eb0a12f4b..4f6cad3b05b2 100644
@@ -1296,6 +1296,8 @@ static void free_ftrace_hash_rcu(struct ftrace_hash *hash)
 void ftrace_free_filter(struct ftrace_ops *ops)
 {
 	ftrace_ops_init(ops);
+	if (WARN_ON(ops->flags & FTRACE_OPS_FL_ENABLED))
+		return;
 	free_ftrace_hash(ops->func_hash->filter_hash);
 	free_ftrace_hash(ops->func_hash->notrace_hash);
 }
Signature · 1 line
2.47.2
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>