From 90f2086c8dd073792b0be382944440e3d0f1977f Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Wed, 27 Nov 2019 09:16:23 -0800 Subject: [PATCH] do not use BPF_F_REUSE_STACKID incorrectly Do not use BPF_F_REUSE_STACKID if the stack id is used together with process specific info like pid/tgid/comm. Using BPF_F_REUSE_STACKID may cause stack id pointing to a different stack later on. Signed-off-by: Yonghong Song --- tools/deadlock.c | 4 ++-- tools/memleak.py | 2 +- tools/old/profile.py | 4 ++-- tools/stackcount.py | 4 ++-- tools/stacksnoop.lua | 2 +- tools/trace.py | 4 ++-- tools/wakeuptime.py | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/deadlock.c b/tools/deadlock.c index 82d22a834af1..a6a6d9155ea7 100644 --- a/tools/deadlock.c +++ b/tools/deadlock.c @@ -95,7 +95,7 @@ int trace_mutex_acquire(struct pt_regs *ctx, void *mutex_addr) { } u64 stack_id = - stack_traces.get_stackid(ctx, BPF_F_USER_STACK | BPF_F_REUSE_STACKID); + stack_traces.get_stackid(ctx, BPF_F_USER_STACK); int added_mutex = 0; #pragma unroll @@ -190,7 +190,7 @@ int trace_clone(struct pt_regs *ctx, unsigned long flags, void *child_stack, struct thread_created_leaf_t thread_created_leaf = {}; thread_created_leaf.parent_pid = bpf_get_current_pid_tgid(); thread_created_leaf.stack_id = - stack_traces.get_stackid(ctx, BPF_F_USER_STACK | BPF_F_REUSE_STACKID); + stack_traces.get_stackid(ctx, BPF_F_USER_STACK); bpf_get_current_comm(&thread_created_leaf.comm, sizeof(thread_created_leaf.comm)); diff --git a/tools/memleak.py b/tools/memleak.py index fd08bc4d8426..9fa6805c6cb6 100755 --- a/tools/memleak.py +++ b/tools/memleak.py @@ -399,7 +399,7 @@ def run_command_get_pid(command): size_filter = "if (size > %d) return 0;" % max_size bpf_source = bpf_source.replace("SIZE_FILTER", size_filter) -stack_flags = "BPF_F_REUSE_STACKID" +stack_flags = "0" if not kernel_trace: stack_flags += "|BPF_F_USER_STACK" bpf_source = bpf_source.replace("STACK_FLAGS", stack_flags) diff --git a/tools/old/profile.py b/tools/old/profile.py index e6940e678e6b..7c768f436452 100755 --- a/tools/old/profile.py +++ b/tools/old/profile.py @@ -209,9 +209,9 @@ def positive_nonzero_int(val): # handle stack args kernel_stack_get = "stack_traces.get_stackid(args, " \ - "%d | BPF_F_REUSE_STACKID)" % skip + "%d)" % skip user_stack_get = \ - "stack_traces.get_stackid(args, BPF_F_REUSE_STACKID | BPF_F_USER_STACK)" + "stack_traces.get_stackid(args, BPF_F_USER_STACK)" stack_context = "" if args.user_stacks_only: stack_context = "user" diff --git a/tools/stackcount.py b/tools/stackcount.py index 6aec429fe1b6..a58f9e316224 100755 --- a/tools/stackcount.py +++ b/tools/stackcount.py @@ -110,14 +110,14 @@ def load(self): if self.user_stack: stack_trace += """ key.user_stack_id = stack_traces.get_stackid( - %s, BPF_F_REUSE_STACKID | BPF_F_USER_STACK + %s, BPF_F_USER_STACK );""" % (ctx_name) else: stack_trace += "key.user_stack_id = -1;" if self.kernel_stack: stack_trace += """ key.kernel_stack_id = stack_traces.get_stackid( - %s, BPF_F_REUSE_STACKID + %s, 0 );""" % (ctx_name) else: stack_trace += "key.kernel_stack_id = -1;" diff --git a/tools/stacksnoop.lua b/tools/stacksnoop.lua index 5bcef8c4828f..d8d79c7945ed 100755 --- a/tools/stacksnoop.lua +++ b/tools/stacksnoop.lua @@ -32,7 +32,7 @@ void trace_stack(struct pt_regs *ctx) { 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)); diff --git a/tools/trace.py b/tools/trace.py index 1f4f5893c45f..0bd28613d79d 100755 --- a/tools/trace.py +++ b/tools/trace.py @@ -487,12 +487,12 @@ def generate_program(self, include_self): if self.user_stack: stack_trace += """ __data.user_stack_id = %s.get_stackid( - %s, BPF_F_REUSE_STACKID | BPF_F_USER_STACK + %s, BPF_F_USER_STACK );""" % (self.stacks_name, ctx_name) if self.kernel_stack: stack_trace += """ __data.kernel_stack_id = %s.get_stackid( - %s, BPF_F_REUSE_STACKID + %s, 0 );""" % (self.stacks_name, ctx_name) text = heading + """ diff --git a/tools/wakeuptime.py b/tools/wakeuptime.py index 18e70e4807fc..a22245a7b43d 100755 --- a/tools/wakeuptime.py +++ b/tools/wakeuptime.py @@ -135,7 +135,7 @@ def signal_ignore(signal, frame): struct key_t key = {}; - key.w_k_stack_id = stack_traces.get_stackid(ctx, BPF_F_REUSE_STACKID); + key.w_k_stack_id = stack_traces.get_stackid(ctx, 0); bpf_probe_read(&key.target, sizeof(key.target), p->comm); bpf_get_current_comm(&key.waker, sizeof(key.waker));