From: Rong Tao <rongtao@xxxxxxxx> 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@xxxxxxxx> --- 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