ftrace: Factor ftrace_ops ops_func interface
authorJiri Olsa <jolsa@kernel.org>
Tue, 30 Dec 2025 14:50:09 +0000 (15:50 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 28 Jan 2026 19:44:57 +0000 (11:44 -0800)
We are going to remove "ftrace_ops->private == bpf_trampoline" setup
in following changes.

Adding ip argument to ftrace_ops_func_t callback function, so we can
use it to look up the trampoline.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Link: https://lore.kernel.org/bpf/20251230145010.103439-9-jolsa@kernel.org
include/linux/ftrace.h
kernel/bpf/trampoline.c
kernel/trace/ftrace.c

index b8461e5..705db0a 100644 (file)
@@ -403,7 +403,7 @@ enum ftrace_ops_cmd {
  *        Negative on failure. The return value is dependent on the
  *        callback.
  */
-typedef int (*ftrace_ops_func_t)(struct ftrace_ops *op, enum ftrace_ops_cmd cmd);
+typedef int (*ftrace_ops_func_t)(struct ftrace_ops *op, unsigned long ip, enum ftrace_ops_cmd cmd);
 
 #ifdef CONFIG_DYNAMIC_FTRACE
 
index 1d4f618..64556aa 100644 (file)
@@ -33,7 +33,8 @@ static DEFINE_MUTEX(trampoline_mutex);
 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
 static int bpf_trampoline_update(struct bpf_trampoline *tr, bool lock_direct_mutex);
 
-static int bpf_tramp_ftrace_ops_func(struct ftrace_ops *ops, enum ftrace_ops_cmd cmd)
+static int bpf_tramp_ftrace_ops_func(struct ftrace_ops *ops, unsigned long ip,
+                                    enum ftrace_ops_cmd cmd)
 {
        struct bpf_trampoline *tr = ops->private;
        int ret = 0;
index 794ab5e..ee2d7b8 100644 (file)
@@ -2075,7 +2075,7 @@ static int __ftrace_hash_update_ipmodify(struct ftrace_ops *ops,
                                 */
                                if (!ops->ops_func)
                                        return -EBUSY;
-                               ret = ops->ops_func(ops, FTRACE_OPS_CMD_ENABLE_SHARE_IPMODIFY_SELF);
+                               ret = ops->ops_func(ops, rec->ip, FTRACE_OPS_CMD_ENABLE_SHARE_IPMODIFY_SELF);
                                if (ret)
                                        return ret;
                        } else if (is_ipmodify) {
@@ -9061,7 +9061,7 @@ static int prepare_direct_functions_for_ipmodify(struct ftrace_ops *ops)
                                if (!op->ops_func)
                                        return -EBUSY;
 
-                               ret = op->ops_func(op, FTRACE_OPS_CMD_ENABLE_SHARE_IPMODIFY_PEER);
+                               ret = op->ops_func(op, ip, FTRACE_OPS_CMD_ENABLE_SHARE_IPMODIFY_PEER);
                                if (ret)
                                        return ret;
                        }
@@ -9108,7 +9108,7 @@ static void cleanup_direct_functions_after_ipmodify(struct ftrace_ops *ops)
 
                        /* The cleanup is optional, ignore any errors */
                        if (found_op && op->ops_func)
-                               op->ops_func(op, FTRACE_OPS_CMD_DISABLE_SHARE_IPMODIFY_PEER);
+                               op->ops_func(op, ip, FTRACE_OPS_CMD_DISABLE_SHARE_IPMODIFY_PEER);
                }
        }
        mutex_unlock(&direct_mutex);