From e7ddcbcc5e939ac91e16b42fca303c31816590a5 Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Thu, 5 Dec 2019 22:47:33 -0800 Subject: [PATCH] remove inproper usage of BPF_F_REUSE_STACKID in examples When the application bundles stack id with process specific info (like pid, comm, etc.), BPF_F_REUSE_STACKID should not be used as it may associate wrong stack with processes. This patch corrected several such uses in examples/ directory. Signed-off-by: Yonghong Song --- examples/lua/memleak.lua | 2 +- examples/lua/offcputime.lua | 2 +- examples/tracing/mallocstacks.py | 3 +-- examples/tracing/stacksnoop.py | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/lua/memleak.lua b/examples/lua/memleak.lua index 99c15225ffd9..1181b4ef1e14 100755 --- a/examples/lua/memleak.lua +++ b/examples/lua/memleak.lua @@ -113,7 +113,7 @@ return function(BPF, utils) size_filter = "if (size > %d) return 0;" % args.max_size end - local stack_flags = "BPF_F_REUSE_STACKID" + local stack_flags = "0" if args.pid then stack_flags = stack_flags .. "|BPF_F_USER_STACK" end diff --git a/examples/lua/offcputime.lua b/examples/lua/offcputime.lua index 6d23cd87892e..120226582e36 100755 --- a/examples/lua/offcputime.lua +++ b/examples/lua/offcputime.lua @@ -54,7 +54,7 @@ int oncpu(struct pt_regs *ctx, struct task_struct *prev) { // create map key u64 zero = 0, *val; struct key_t key = {}; - int stack_flags = BPF_F_REUSE_STACKID; + int stack_flags = 0; /* if (!(prev->flags & PF_KTHREAD)) diff --git a/examples/tracing/mallocstacks.py b/examples/tracing/mallocstacks.py index 31306a4917e8..4b10e6c29426 100755 --- a/examples/tracing/mallocstacks.py +++ b/examples/tracing/mallocstacks.py @@ -39,8 +39,7 @@ BPF_STACK_TRACE(stack_traces, """ + stacks + """); int alloc_enter(struct pt_regs *ctx, size_t size) { - int key = stack_traces.get_stackid(ctx, - BPF_F_USER_STACK|BPF_F_REUSE_STACKID); + int key = stack_traces.get_stackid(ctx, BPF_F_USER_STACK); if (key < 0) return 0; diff --git a/examples/tracing/stacksnoop.py b/examples/tracing/stacksnoop.py index 0ade2dbba3fb..8a68e69b38e8 100755 --- a/examples/tracing/stacksnoop.py +++ b/examples/tracing/stacksnoop.py @@ -59,7 +59,7 @@ u32 pid = bpf_get_current_pid_tgid(); FILTER struct data_t data = {}; - data.stack_id = stack_traces.get_stackid(ctx, BPF_F_REUSE_STACKID), + data.stack_id = stack_traces.get_stackid(ctx, 0), data.pid = pid; bpf_get_current_comm(&data.comm, sizeof(data.comm)); events.perf_submit(ctx, &data, sizeof(data));