Skip to content

Commit 6de8ecd

Browse files
Nikita Yushchenkogregkh
authored andcommitted
tracing/osnoise: Properly unhook events if start_per_cpu_kthreads() fails
commit 0878355 upstream. If start_per_cpu_kthreads() called from osnoise_workload_start() returns error, event hooks are left in broken state: unhook_irq_events() called but unhook_thread_events() and unhook_softirq_events() not called, and trace_osnoise_callback_enabled flag not cleared. On the next tracer enable, hooks get not installed due to trace_osnoise_callback_enabled flag. And on the further tracer disable an attempt to remove non-installed hooks happened, hitting a WARN_ON_ONCE() in tracepoint_remove_func(). Fix the error path by adding the missing part of cleanup. While at this, introduce osnoise_unhook_events() to avoid code duplication between this error path and normal tracer disable. Link: https://lkml.kernel.org/r/20220109153459.3701773-1-nikita.yushchenko@virtuozzo.com Cc: stable@vger.kernel.org Fixes: bce29ac ("trace: Add osnoise tracer") Acked-by: Daniel Bristot de Oliveira <bristot@kernel.org> Signed-off-by: Nikita Yushchenko <nikita.yushchenko@virtuozzo.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7dd8db8 commit 6de8ecd

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

‎kernel/trace/trace_osnoise.c‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,13 @@ static int osnoise_hook_events(void)
21232123
return -EINVAL;
21242124
}
21252125

2126+
static void osnoise_unhook_events(void)
2127+
{
2128+
unhook_thread_events();
2129+
unhook_softirq_events();
2130+
unhook_irq_events();
2131+
}
2132+
21262133
/*
21272134
* osnoise_workload_start - start the workload and hook to events
21282135
*/
@@ -2155,7 +2162,14 @@ static int osnoise_workload_start(void)
21552162

21562163
retval = start_per_cpu_kthreads();
21572164
if (retval) {
2158-
unhook_irq_events();
2165+
trace_osnoise_callback_enabled = false;
2166+
/*
2167+
* Make sure that ftrace_nmi_enter/exit() see
2168+
* trace_osnoise_callback_enabled as false before continuing.
2169+
*/
2170+
barrier();
2171+
2172+
osnoise_unhook_events();
21592173
return retval;
21602174
}
21612175

@@ -2186,9 +2200,7 @@ static void osnoise_workload_stop(void)
21862200

21872201
stop_per_cpu_kthreads();
21882202

2189-
unhook_irq_events();
2190-
unhook_softirq_events();
2191-
unhook_thread_events();
2203+
osnoise_unhook_events();
21922204
}
21932205

21942206
static void osnoise_tracer_start(struct trace_array *tr)

0 commit comments

Comments
 (0)