[PATCH bpf-next v2 10/21] bpf: Shrink CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS guard scope for bpf_tracing_multi_attach()
From: Leon Hwang
Date: Mon Oct 12 2026 - 12:01:48 EST
When adding tracing_multi link support for bpf progs, it will use the same
UAPI of the tracing_multi link for kernel functions in
bpf_tracing_multi_attach().
However, the tracing_multi link support for bpf progs does not require
CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS. So, shrink its guard scope to add
new code in bpf_tracing_multi_attach() for the tracing_multi link support
for bpf progs.
To simplify the change, validate CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS only
here, because the execution path in trampoline of the tracing_multi link
support for kernel functions is already guarded with the
CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS and
CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS.
Meanwhile, provide a stub of bpf_trampoline_multi_detach() out of the
CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS and
CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS guard.
Signed-off-by: Leon Hwang <leon.hwang@xxxxxxxxx>
---
kernel/bpf/trampoline.c | 5 +++++
kernel/trace/bpf_trace.c | 15 +++------------
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
index e57c687955fd..6e18f69a63ad 100644
--- a/kernel/bpf/trampoline.c
+++ b/kernel/bpf/trampoline.c
@@ -1867,6 +1867,11 @@ void bpf_trampoline_multi_detach(struct bpf_prog *prog,
#undef for_each_mnode_cnt
#undef for_each_mnode
+#else
+
+void bpf_trampoline_multi_detach(struct bpf_prog *prog,
+ struct bpf_tracing_multi_link *link) {}
+
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS &&
CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS &&
CONFIG_BPF_SYSCALL */
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 195f78db9bda..69559158ab0b 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3679,9 +3679,6 @@ __bpf_kfunc int bpf_copy_from_user_task_str_dynptr(const struct bpf_dynptr *dptr
__bpf_kfunc_end_defs();
-#if defined(CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS) && \
- defined(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS)
-
static void bpf_tracing_multi_link_release(struct bpf_link *link)
{
struct bpf_tracing_multi_link *tr_link =
@@ -3858,6 +3855,9 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
if (attr->link_create.flags || attr->link_create.target_fd)
return -EINVAL;
+ if (!IS_ENABLED(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS))
+ return -EOPNOTSUPP;
+
ids = kvmalloc_objs(*ids, cnt);
if (!ids)
return -ENOMEM;
@@ -3924,12 +3924,3 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
kvfree(link);
return err;
}
-
-#else
-
-int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
-{
- return -EOPNOTSUPP;
-}
-
-#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS && CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS */
--
2.55.0