]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ftrace: Correct preemption accounting for function tracing.
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Thu, 20 Feb 2025 14:07:49 +0000 (15:07 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Mar 2025 15:56:40 +0000 (16:56 +0100)
commit 57b76bedc5c52c66968183b5ef57234894c25ce7 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: ce5e48036c9e7 ("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>
kernel/trace/trace_functions.c

index 9f1bfbe105e8d9213e6134992341135724bac843..69e92c7359fb9a5a81b0ed9cf4321558794f4d27 100644 (file)
@@ -185,7 +185,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
        if (bit < 0)
                return;
 
-       trace_ctx = tracing_gen_ctx();
+       trace_ctx = tracing_gen_ctx_dec();
 
        cpu = smp_processor_id();
        data = per_cpu_ptr(tr->array_buffer.data, cpu);
@@ -285,7 +285,6 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
        struct trace_array *tr = op->private;
        struct trace_array_cpu *data;
        unsigned int trace_ctx;
-       unsigned long flags;
        int bit;
        int cpu;
 
@@ -312,8 +311,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
        if (is_repeat_check(tr, last_info, ip, parent_ip))
                goto out;
 
-       local_save_flags(flags);
-       trace_ctx = tracing_gen_ctx_flags(flags);
+       trace_ctx = tracing_gen_ctx_dec();
        process_repeats(tr, ip, parent_ip, last_info, trace_ctx);
 
        trace_function(tr, ip, parent_ip, trace_ctx);