[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250105124403.991-2-laoar.shao@gmail.com>
Date: Sun, 5 Jan 2025 20:44:02 +0800
From: Yafang Shao <laoar.shao@...il.com>
To: andrii@...nel.org,
eddyz87@...il.com,
ast@...nel.org,
daniel@...earbox.net,
martin.lau@...ux.dev,
song@...nel.org,
yonghong.song@...ux.dev,
john.fastabend@...il.com,
kpsingh@...nel.org,
sdf@...ichev.me,
haoluo@...gle.com,
jolsa@...nel.org,
edumazet@...gle.com
Cc: bpf@...r.kernel.org,
netdev@...r.kernel.org,
Yafang Shao <laoar.shao@...il.com>
Subject: [RFC PATCH bpf-next 1/2] libbpf: Add support for dynamic tracepoint
Dynamic tracepoints can be created using debugfs. For example:
echo 'p:myprobe kernel_clone args' >> /sys/kernel/debug/tracing/kprobe_events
This command creates a new tracepoint under debugfs:
$ ls /sys/kernel/debug/tracing/events/kprobes/myprobe/
enable filter format hist id trigger
Although this dynamic tracepoint appears as a tracepoint, it is internally
implemented as a kprobe. However, it must be attached as a tracepoint to
function correctly in certain contexts.
This update adds support in libbpf for handling such tracepoints,
simplifying their usage and integration in BPF workflows.
Signed-off-by: Yafang Shao <laoar.shao@...il.com>
---
tools/lib/bpf/libbpf.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 66173ddb5a2d..077bec761ebf 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9504,6 +9504,7 @@ static const struct bpf_sec_def section_defs[] = {
SEC_DEF("struct_ops.s+", STRUCT_OPS, 0, SEC_SLEEPABLE),
SEC_DEF("sk_lookup", SK_LOOKUP, BPF_SK_LOOKUP, SEC_ATTACHABLE),
SEC_DEF("netfilter", NETFILTER, BPF_NETFILTER, SEC_NONE),
+ SEC_DEF("dynamic_tp+", KPROBE, 0, SEC_NONE, attach_tp),
};
int libbpf_register_prog_handler(const char *sec,
@@ -12500,6 +12501,8 @@ static int attach_tp(const struct bpf_program *prog, long cookie, struct bpf_lin
/* extract "tp/<category>/<name>" or "tracepoint/<category>/<name>" */
if (str_has_pfx(prog->sec_name, "tp/"))
tp_cat = sec_name + sizeof("tp/") - 1;
+ else if (str_has_pfx(prog->sec_name, "dynamic_tp/"))
+ tp_cat = sec_name + sizeof("dynamic_tp/") - 1;
else
tp_cat = sec_name + sizeof("tracepoint/") - 1;
tp_name = strchr(tp_cat, '/');
--
2.43.5
Powered by blists - more mailing lists