Skip to content

Commit 8852325

Browse files
pengdonglinopsiff
authored andcommitted
ftrace: Fix preemption accounting for stacktrace trigger command
commit e333332 upstream. When using the stacktrace trigger command to trace syscalls, the preemption count was consistently reported as 1 when the system call event itself had 0 ("."). For example: root@ubuntu22-vm:/sys/kernel/tracing/events/syscalls/sys_enter_read $ echo stacktrace > trigger $ echo 1 > enable sshd-416 [002] ..... 232.864910: sys_read(fd: a, buf: 556b1f3221d0, count: 8000) sshd-416 [002] ...1. 232.864913: <stack trace> => ftrace_syscall_enter => syscall_trace_enter => do_syscall_64 => entry_SYSCALL_64_after_hwframe The root cause is that the trace framework disables preemption in __DO_TRACE before invoking the trigger callback. Use the tracing_gen_ctx_dec() that will accommodate for the increase of the preemption count in __DO_TRACE when calling the callback. The result is the accurate reporting of: sshd-410 [004] ..... 210.117660: sys_read(fd: 4, buf: 559b725ba130, count: 40000) sshd-410 [004] ..... 210.117662: <stack trace> => ftrace_syscall_enter => syscall_trace_enter => do_syscall_64 => entry_SYSCALL_64_after_hwframe Cc: stable@vger.kernel.org Fixes: ce33c84 ("tracing: Dump stacktrace trigger to the corresponding instance") Link: https://lore.kernel.org/20250512094246.1167956-1-dolinux.peng@gmail.com Signed-off-by: pengdonglin <dolinux.peng@gmail.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit fa75d941b104e7248e0b5e532fc92c202203eb05)
1 parent 394a5b4 commit 8852325

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

kernel/trace/trace_events_trigger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ stacktrace_trigger(struct event_trigger_data *data,
15541554
struct trace_event_file *file = data->private_data;
15551555

15561556
if (file)
1557-
__trace_stack(file->tr, tracing_gen_ctx(), STACK_SKIP);
1557+
__trace_stack(file->tr, tracing_gen_ctx_dec(), STACK_SKIP);
15581558
else
15591559
trace_dump_stack(STACK_SKIP);
15601560
}

0 commit comments

Comments
 (0)