Skip to content

Commit 57b76be

Browse files
Sebastian Andrzej Siewiorrostedt
authored andcommitted
ftrace: Correct preemption accounting for function tracing.
The function tracer should record the preemption level at the point when the function is invoked. If the tracing subsystem decrement the preemption counter it needs to correct this before feeding the data into the trace buffer. This was broken in the commit cited below while shifting the preempt-disabled section. Use tracing_gen_ctx_dec() which properly subtracts one from the preemption counter on a preemptible kernel. Cc: stable@vger.kernel.org Cc: Wander Lairson Costa <wander@redhat.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/20250220140749.pfw8qoNZ@linutronix.de Fixes: ce5e480 ("ftrace: disable preemption when recursion locked") Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Tested-by: Wander Lairson Costa <wander@redhat.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent e85c5e9 commit 57b76be

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

kernel/trace/trace_functions.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
216216

217217
parent_ip = function_get_true_parent_ip(parent_ip, fregs);
218218

219-
trace_ctx = tracing_gen_ctx();
219+
trace_ctx = tracing_gen_ctx_dec();
220220

221221
data = this_cpu_ptr(tr->array_buffer.data);
222222
if (!atomic_read(&data->disabled))
@@ -321,7 +321,6 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
321321
struct trace_array *tr = op->private;
322322
struct trace_array_cpu *data;
323323
unsigned int trace_ctx;
324-
unsigned long flags;
325324
int bit;
326325

327326
if (unlikely(!tr->function_enabled))
@@ -347,8 +346,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
347346
if (is_repeat_check(tr, last_info, ip, parent_ip))
348347
goto out;
349348

350-
local_save_flags(flags);
351-
trace_ctx = tracing_gen_ctx_flags(flags);
349+
trace_ctx = tracing_gen_ctx_dec();
352350
process_repeats(tr, ip, parent_ip, last_info, trace_ctx);
353351

354352
trace_function(tr, ip, parent_ip, trace_ctx);

0 commit comments

Comments
 (0)