linux-stable/kernel/trace
Nico Pache 1e9c23db31 tracing/osnoise: Fix possible recursive locking in stop_per_cpu_kthreads
[ Upstream commit 99ee9317a1 ]

There is a recursive lock on the cpu_hotplug_lock.

In kernel/trace/trace_osnoise.c:<start/stop>_per_cpu_kthreads:
    - start_per_cpu_kthreads calls cpus_read_lock() and if
	start_kthreads returns a error it will call stop_per_cpu_kthreads.
    - stop_per_cpu_kthreads then calls cpus_read_lock() again causing
      deadlock.

Fix this by calling cpus_read_unlock() before calling
stop_per_cpu_kthreads. This behavior can also be seen in commit
f46b16520a ("trace/hwlat: Implement the per-cpu mode").

This error was noticed during the LTP ftrace-stress-test:

WARNING: possible recursive locking detected
--------------------------------------------
sh/275006 is trying to acquire lock:
ffffffffb02f5400 (cpu_hotplug_lock){++++}-{0:0}, at: stop_per_cpu_kthreads

but task is already holding lock:
ffffffffb02f5400 (cpu_hotplug_lock){++++}-{0:0}, at: start_per_cpu_kthreads

other info that might help us debug this:
 Possible unsafe locking scenario:

      CPU0
      ----
 lock(cpu_hotplug_lock);
 lock(cpu_hotplug_lock);

 *** DEADLOCK ***

May be due to missing lock nesting notation

3 locks held by sh/275006:
 #0: ffff8881023f0470 (sb_writers#24){.+.+}-{0:0}, at: ksys_write
 #1: ffffffffb084f430 (trace_types_lock){+.+.}-{3:3}, at: rb_simple_write
 #2: ffffffffb02f5400 (cpu_hotplug_lock){++++}-{0:0}, at: start_per_cpu_kthreads

Link: https://lkml.kernel.org/r/20220919144932.3064014-1-npache@redhat.com

Fixes: c8895e271f ("trace/osnoise: Support hotplug operations")
Signed-off-by: Nico Pache <npache@redhat.com>
Acked-by: Daniel Bristot de Oliveira <bristot@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-10-26 12:35:27 +02:00
..
blktrace.c blktrace: Trace remapped requests correctly 2022-08-17 14:23:13 +02:00
bpf_trace.c bpf: Add MEM_RDONLY for helper args that are pointers to rdonly mem. 2022-05-01 17:22:26 +02:00
bpf_trace.h
error_report-traces.c tracing: add error_report_end trace point 2021-02-26 09:41:02 -08:00
fgraph.c tracing: Fix various typos in comments 2021-03-23 14:08:18 -04:00
ftrace.c ftrace: Properly unset FTRACE_HASH_FL_MOD 2022-10-26 12:34:30 +02:00
ftrace_internal.h
Kconfig tracing: Simplify the Kconfig dependency of FTRACE 2021-08-16 11:37:20 -04:00
kprobe_event_gen_test.c tracing: kprobe: Make gen test module work in arm and riscv 2022-10-26 12:35:27 +02:00
Makefile tracing: Place trace_pid_list logic into abstract functions 2022-07-29 17:25:29 +02:00
pid_list.c tracing: Place trace_pid_list logic into abstract functions 2022-07-29 17:25:29 +02:00
pid_list.h tracing: Place trace_pid_list logic into abstract functions 2022-07-29 17:25:29 +02:00
power-traces.c
preemptirq_delay_test.c kernel: trace: preemptirq_delay_test: add cpu affinity 2021-02-02 17:02:07 -05:00
ring_buffer.c ring-buffer: Fix race between reset page and reading page 2022-10-26 12:34:31 +02:00
ring_buffer_benchmark.c
rpm-traces.c
synth_event_gen_test.c tracing: Fix various typos in comments 2021-03-23 14:08:18 -04:00
trace.c tracing: Add ioctl() to force ring buffer waiters to wake up 2022-10-26 12:34:31 +02:00
trace.h tracing: Add '__rel_loc' using trace event macros 2022-08-17 14:24:26 +02:00
trace_benchmark.c tracing: Fix some typos in comments 2020-11-10 20:39:40 -05:00
trace_benchmark.h
trace_boot.c tracing: Initialize integer variable to prevent garbage return value 2022-06-09 10:23:21 +02:00
trace_branch.c tracing: Merge irqflags + preempt counter. 2021-02-02 17:02:06 -05:00
trace_clock.c tracing: Do no increment trace_clock_global() by one 2021-06-18 09:10:00 -04:00
trace_dynevent.c tracing: Disable "other" permission bits in the tracefs files 2021-11-18 19:16:15 +01:00
trace_dynevent.h tracing: Add DYNAMIC flag for dynamic events 2021-08-18 18:10:32 -04:00
trace_entries.h trace: Add timerlat tracer 2021-06-25 19:57:24 -04:00
trace_eprobe.c tracing: Move duplicate code of trace_kprobe/eprobe.c into header 2022-10-26 12:34:31 +02:00
trace_event_perf.c tracing/perf: Fix double put of trace event when init fails 2022-08-25 11:39:57 +02:00
trace_events.c tracing: Have filter accept "common_cpu" to be consistent 2022-08-25 11:39:58 +02:00
trace_events_filter.c tracing: Add ustring operation to filtering string pointers 2022-03-08 19:12:33 +01:00
trace_events_filter_test.h
trace_events_hist.c tracing/histograms: Fix memory leak problem 2022-07-21 21:24:11 +02:00
trace_events_inject.c tracing: Merge irqflags + preempt counter. 2021-02-02 17:02:06 -05:00
trace_events_synth.c tracing: Fix reading strings from synthetic events 2022-10-26 12:34:32 +02:00
trace_events_trigger.c tracing: Fix to check event_mutex is held while accessing trigger list 2022-09-15 11:30:02 +02:00
trace_export.c tracing: Fix some typos in comments 2020-11-10 20:39:40 -05:00
trace_functions.c tracing: Add "func_no_repeats" option for function tracing 2021-04-15 14:50:02 -04:00
trace_functions_graph.c tracing: Disable "other" permission bits in the tracefs files 2021-11-18 19:16:15 +01:00
trace_hwlat.c tracing: Disable "other" permission bits in the tracefs files 2021-11-18 19:16:15 +01:00
trace_irqsoff.c tracing: Merge irqflags + preempt counter. 2021-02-02 17:02:06 -05:00
trace_kdb.c kdb: Rename members of struct kdbtab_t 2021-07-27 17:05:06 +01:00
trace_kprobe.c tracing: Move duplicate code of trace_kprobe/eprobe.c into header 2022-10-26 12:34:31 +02:00
trace_kprobe_selftest.c
trace_kprobe_selftest.h
trace_mmiotrace.c tracing: Remove definition of DEBUG in trace_mmiotrace.c 2021-02-02 17:02:07 -05:00
trace_nop.c
trace_osnoise.c tracing/osnoise: Fix possible recursive locking in stop_per_cpu_kthreads 2022-10-26 12:35:27 +02:00
trace_output.c tracing: Add migrate-disabled counter to tracing output. 2021-09-03 19:42:35 -04:00
trace_output.h ftrace: Add recording of functions that caused recursion 2020-11-06 08:42:26 -05:00
trace_preemptirq.c tracing: hold caller_addr to hardirq_{enable,disable}_ip 2022-09-20 12:39:43 +02:00
trace_printk.c tracing: Disable "other" permission bits in the tracefs files 2021-11-18 19:16:15 +01:00
trace_probe.c tracing/probes: Have kprobes and uprobes use $COMM too 2022-08-25 11:39:58 +02:00
trace_probe.h tracing: Add a probe that attaches to trace events 2021-08-20 14:18:40 -04:00
trace_probe_kernel.h tracing: Add "(fault)" name injection to kernel probes 2022-10-26 12:34:32 +02:00
trace_probe_tmpl.h tracing/probes: Have process_fetch_insn() take a void * instead of pt_regs 2021-08-19 09:09:03 -04:00
trace_recursion_record.c tracing: Disable "other" permission bits in the tracefs files 2021-11-18 19:16:15 +01:00
trace_sched_switch.c
trace_sched_wakeup.c tracing: Change variable type as bool for clean-up 2021-06-30 09:19:14 -04:00
trace_selftest.c tracing: Fix various typos in comments 2021-03-23 14:08:18 -04:00
trace_selftest_dynamic.c
trace_seq.c tracing: Fix various typos in comments 2021-03-23 14:08:18 -04:00
trace_stack.c tracing: Disable "other" permission bits in the tracefs files 2021-11-18 19:16:15 +01:00
trace_stat.c tracing: Disable "other" permission bits in the tracefs files 2021-11-18 19:16:15 +01:00
trace_stat.h
trace_synth.h tracing: synth events: increase max fields count 2021-09-08 15:29:16 -04:00
trace_syscalls.c tracing: Make tp_printk work on syscall tracepoints 2022-06-14 18:36:14 +02:00
trace_uprobe.c tracing/uprobes: Check the return value of kstrdup() for tu->filename 2022-03-08 19:12:38 +01:00
tracing_map.c tracing: Fix a kmemleak false positive in tracing_map 2021-12-17 10:30:16 +01:00
tracing_map.h tracing: Fix some typos in comments 2020-11-10 20:39:40 -05:00