Skip to content

Commit 1bfc1f1

Browse files
Sebastian Andrzej Siewiorgregkh
authored andcommitted
ftrace: Correct preemption accounting for function tracing.
commit 57b76be upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e28e7d7 commit 1bfc1f1

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
@@ -193,7 +193,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
193193
if (bit < 0)
194194
return;
195195

196-
trace_ctx = tracing_gen_ctx();
196+
trace_ctx = tracing_gen_ctx_dec();
197197

198198
cpu = smp_processor_id();
199199
data = per_cpu_ptr(tr->array_buffer.data, cpu);
@@ -298,7 +298,6 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
298298
struct trace_array *tr = op->private;
299299
struct trace_array_cpu *data;
300300
unsigned int trace_ctx;
301-
unsigned long flags;
302301
int bit;
303302
int cpu;
304303

@@ -325,8 +324,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
325324
if (is_repeat_check(tr, last_info, ip, parent_ip))
326325
goto out;
327326

328-
local_save_flags(flags);
329-
trace_ctx = tracing_gen_ctx_flags(flags);
327+
trace_ctx = tracing_gen_ctx_dec();
330328
process_repeats(tr, ip, parent_ip, last_info, trace_ctx);
331329

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

0 commit comments

Comments
 (0)