BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] samples/bpf: tracex2: Replace kfree_skb from kprobe to tracepoint
@ 2024-08-28  1:18 Rong Tao
  2024-08-30 20:01 ` Andrii Nakryiko
  0 siblings, 1 reply; 4+ messages in thread
From: Rong Tao @ 2024-08-28  1:18 UTC (permalink / raw)
  To: andrii, daniel, ast
  Cc: rongtao, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa,
	open list:BPF [GENERAL] (Safe Dynamic Programs and Tools),
	open list

From: Rong Tao <rongtao@cestc.cn>

In commit ba8de796baf4 ("net: introduce sk_skb_reason_drop function")
kfree_skb_reason() becomes an inline function and cannot be traced.
We can use the stable tracepoint kfree_skb to get 'ip'.

Link: https://github.com/torvalds/linux/commit/ba8de796baf4bdc03530774fb284fe3c97875566
Signed-off-by: Rong Tao <rongtao@cestc.cn>
---
 samples/bpf/tracex2.bpf.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/samples/bpf/tracex2.bpf.c b/samples/bpf/tracex2.bpf.c
index 0a5c75b367be..dc3d91b65a6f 100644
--- a/samples/bpf/tracex2.bpf.c
+++ b/samples/bpf/tracex2.bpf.c
@@ -17,20 +17,15 @@ struct {
 	__uint(max_entries, 1024);
 } my_map SEC(".maps");
 
-/* kprobe is NOT a stable ABI. If kernel internals change this bpf+kprobe
- * example will no longer be meaningful
- */
-SEC("kprobe/kfree_skb_reason")
-int bpf_prog2(struct pt_regs *ctx)
+SEC("tracepoint/skb/kfree_skb")
+int bpf_prog1(struct trace_event_raw_kfree_skb *ctx)
 {
 	long loc = 0;
 	long init_val = 1;
 	long *value;
 
-	/* read ip of kfree_skb_reason caller.
-	 * non-portable version of __builtin_return_address(0)
-	 */
-	BPF_KPROBE_READ_RET_IP(loc, ctx);
+	/* read ip */
+	loc = (long)ctx->location;
 
 	value = bpf_map_lookup_elem(&my_map, &loc);
 	if (value)
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-09-04 19:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-28  1:18 [PATCH bpf-next] samples/bpf: tracex2: Replace kfree_skb from kprobe to tracepoint Rong Tao
2024-08-30 20:01 ` Andrii Nakryiko
2024-08-31  0:03   ` [PATCH bpf-next] samples/bpf: Remove sample tracex2 Rong Tao
2024-09-04 19:00     ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox